Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/rules.js

Issue 8450003: Reimplemented whitelist handling (Closed)
Left Patch Set: Created Sept. 25, 2012, 3:48 p.m.
Right Patch Set: Modifications only, different base revision Created Sept. 27, 2012, 2:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/content/tests/tests/suffixTreeManipulation.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 Cu.import("resource://gre/modules/Services.jsm"); 5 Cu.import("resource://gre/modules/Services.jsm");
6 Cu.import("resource://gre/modules/FileUtils.jsm"); 6 Cu.import("resource://gre/modules/FileUtils.jsm");
7 7
8 let {Prefs} = require("prefs"); 8 let {Prefs} = require("prefs");
9 9
10 let RULES_VERSION = 2; 10 let RULES_VERSION = 2;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 function addCustomRules() 90 function addCustomRules()
91 { 91 {
92 for (let domain in Prefs.whitelist) 92 for (let domain in Prefs.whitelist)
93 onWhitelistEntryAdded(domain); 93 onWhitelistEntryAdded(domain);
94 } 94 }
95 95
96 function onWhitelistEntryAdded(domain) 96 function onWhitelistEntryAdded(domain)
97 { 97 {
98 let reverse = Array.prototype.slice.call(domain).reverse().join(""); 98 let reverse = domain.split("").reverse().join("");
Thomas Greiner 2012/09/26 15:59:35 also in onWhitelistEntryAdded function
99 addSuffix(rules.domain, reverse, CUSTOM_RULE_PRIORITY); 99 addSuffix(rules.domain, reverse, CUSTOM_RULE_PRIORITY);
100 } 100 }
101 exports.onWhitelistEntryAdded = onWhitelistEntryAdded; 101 exports.onWhitelistEntryAdded = onWhitelistEntryAdded;
102 102
103 function onWhitelistEntryRemoved(domain) 103 function onWhitelistEntryRemoved(domain)
104 { 104 {
105 let reverse = Array.prototype.slice.call(domain).reverse().join(""); 105 let reverse = domain.split("").reverse().join("");
Thomas Greiner 2012/09/26 15:49:13 It looks less confusing if you do it this way: le
Wladimir Palant 2012/09/27 14:55:06 domain is a string - string.slice() returns anothe
106 removeSuffix(rules.domain, reverse, CUSTOM_RULE_PRIORITY); 106 removeSuffix(rules.domain, reverse, CUSTOM_RULE_PRIORITY);
107 } 107 }
108 exports.onWhitelistEntryRemoved = onWhitelistEntryRemoved; 108 exports.onWhitelistEntryRemoved = onWhitelistEntryRemoved;
109 109
110 function addSuffix(tree, suffix, priority) 110 function addSuffix(tree, suffix, priority)
111 { 111 {
112 if (suffix.length == 0) 112 if (suffix.length == 0)
113 { 113 {
114 // We are at the last character, just put our priority here 114 // We are at the last character, just put our priority here
115 tree[""] = " " + priority; 115 tree[""] = " " + priority;
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 bestSuggestionDistance = distance; 400 bestSuggestionDistance = distance;
401 bestSuggestionMatched = matchedLen; 401 bestSuggestionMatched = matchedLen;
402 bestSuggestionPriority = priority; 402 bestSuggestionPriority = priority;
403 } 403 }
404 } 404 }
405 if (bestSuggestion) 405 if (bestSuggestion)
406 return input.substr(0, input.length - bestSuggestionMatched) + bestSuggestio n; 406 return input.substr(0, input.length - bestSuggestionMatched) + bestSuggestio n;
407 else 407 else
408 return input; 408 return input;
409 } 409 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld