OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the Adblock Plus, | 2 * This file is part of the Adblock Plus, |
3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 delete this.keywordByFilter[filter.text]; | 101 delete this.keywordByFilter[filter.text]; |
102 }, | 102 }, |
103 | 103 |
104 /** | 104 /** |
105 * Chooses a keyword to be associated with the filter | 105 * Chooses a keyword to be associated with the filter |
106 * @param {String} text text representation of the filter | 106 * @param {String} text text representation of the filter |
107 * @return {String} keyword (might be empty string) | 107 * @return {String} keyword (might be empty string) |
108 */ | 108 */ |
109 findKeyword: function(filter) | 109 findKeyword: function(filter) |
110 { | 110 { |
111 // For donottrack filters use "donottrack" as keyword if nothing else matche
s | 111 let result = ""; |
112 let defaultResult = (filter.contentType & RegExpFilter.typeMap.DONOTTRACK ?
"donottrack" : ""); | |
113 | |
114 let text = filter.text; | 112 let text = filter.text; |
115 if (Filter.regexpRegExp.test(text)) | 113 if (Filter.regexpRegExp.test(text)) |
116 return defaultResult; | 114 return result; |
117 | 115 |
118 // Remove options | 116 // Remove options |
119 let match = Filter.optionsRegExp.exec(text); | 117 let match = Filter.optionsRegExp.exec(text); |
120 if (match) | 118 if (match) |
121 text = match.input.substr(0, match.index); | 119 text = match.input.substr(0, match.index); |
122 | 120 |
123 // Remove whitelist marker | 121 // Remove whitelist marker |
124 if (text.substr(0, 2) == "@@") | 122 if (text.substr(0, 2) == "@@") |
125 text = text.substr(2); | 123 text = text.substr(2); |
126 | 124 |
127 let candidates = text.toLowerCase().match(/[^a-z0-9%*][a-z0-9%]{3,}(?=[^a-z0
-9%*])/g); | 125 let candidates = text.toLowerCase().match(/[^a-z0-9%*][a-z0-9%]{3,}(?=[^a-z0
-9%*])/g); |
128 if (!candidates) | 126 if (!candidates) |
129 return defaultResult; | 127 return result; |
130 | 128 |
131 let hash = this.filterByKeyword; | 129 let hash = this.filterByKeyword; |
132 let result = defaultResult; | |
133 let resultCount = 0xFFFFFF; | 130 let resultCount = 0xFFFFFF; |
134 let resultLength = 0; | 131 let resultLength = 0; |
135 for (let i = 0, l = candidates.length; i < l; i++) | 132 for (let i = 0, l = candidates.length; i < l; i++) |
136 { | 133 { |
137 let candidate = candidates[i].substr(1); | 134 let candidate = candidates[i].substr(1); |
138 let count = (candidate in hash ? hash[candidate].length : 0); | 135 let count = (candidate in hash ? hash[candidate].length : 0); |
139 if (count < resultCount || (count == resultCount && candidate.length > res
ultLength)) | 136 if (count < resultCount || (count == resultCount && candidate.length > res
ultLength)) |
140 { | 137 { |
141 result = candidate; | 138 result = candidate; |
142 resultCount = count; | 139 resultCount = count; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 * @param {String} contentType content type identifier of the URL | 183 * @param {String} contentType content type identifier of the URL |
187 * @param {String} docDomain domain name of the document that loads the URL | 184 * @param {String} docDomain domain name of the document that loads the URL |
188 * @param {Boolean} thirdParty should be true if the URL is a third-party requ
est | 185 * @param {Boolean} thirdParty should be true if the URL is a third-party requ
est |
189 * @return {RegExpFilter} matching filter or null | 186 * @return {RegExpFilter} matching filter or null |
190 */ | 187 */ |
191 matchesAny: function(location, contentType, docDomain, thirdParty) | 188 matchesAny: function(location, contentType, docDomain, thirdParty) |
192 { | 189 { |
193 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); | 190 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
194 if (candidates === null) | 191 if (candidates === null) |
195 candidates = []; | 192 candidates = []; |
196 if (contentType == "DONOTTRACK") | 193 candidates.push(""); |
197 candidates.unshift("donottrack"); | |
198 else | |
199 candidates.push(""); | |
200 for (let i = 0, l = candidates.length; i < l; i++) | 194 for (let i = 0, l = candidates.length; i < l; i++) |
201 { | 195 { |
202 let substr = candidates[i]; | 196 let substr = candidates[i]; |
203 if (substr in this.filterByKeyword) | 197 if (substr in this.filterByKeyword) |
204 { | 198 { |
205 let result = this._checkEntryMatch(substr, location, contentType, docDom
ain, thirdParty); | 199 let result = this._checkEntryMatch(substr, location, contentType, docDom
ain, thirdParty); |
206 if (result) | 200 if (result) |
207 return result; | 201 return result; |
208 } | 202 } |
209 } | 203 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 /** | 368 /** |
375 * Optimized filter matching testing both whitelist and blacklist matchers | 369 * Optimized filter matching testing both whitelist and blacklist matchers |
376 * simultaneously. For parameters see Matcher.matchesAny(). | 370 * simultaneously. For parameters see Matcher.matchesAny(). |
377 * @see Matcher#matchesAny | 371 * @see Matcher#matchesAny |
378 */ | 372 */ |
379 matchesAnyInternal: function(location, contentType, docDomain, thirdParty) | 373 matchesAnyInternal: function(location, contentType, docDomain, thirdParty) |
380 { | 374 { |
381 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); | 375 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
382 if (candidates === null) | 376 if (candidates === null) |
383 candidates = []; | 377 candidates = []; |
384 if (contentType == "DONOTTRACK") | 378 candidates.push(""); |
385 candidates.unshift("donottrack"); | |
386 else | |
387 candidates.push(""); | |
388 | 379 |
389 let blacklistHit = null; | 380 let blacklistHit = null; |
390 for (let i = 0, l = candidates.length; i < l; i++) | 381 for (let i = 0, l = candidates.length; i < l; i++) |
391 { | 382 { |
392 let substr = candidates[i]; | 383 let substr = candidates[i]; |
393 if (substr in this.whitelist.filterByKeyword) | 384 if (substr in this.whitelist.filterByKeyword) |
394 { | 385 { |
395 let result = this.whitelist._checkEntryMatch(substr, location, contentTy
pe, docDomain, thirdParty); | 386 let result = this.whitelist._checkEntryMatch(substr, location, contentTy
pe, docDomain, thirdParty); |
396 if (result) | 387 if (result) |
397 return result; | 388 return result; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 else | 433 else |
443 return null; | 434 return null; |
444 } | 435 } |
445 } | 436 } |
446 | 437 |
447 /** | 438 /** |
448 * Shared CombinedMatcher instance that should usually be used. | 439 * Shared CombinedMatcher instance that should usually be used. |
449 * @type CombinedMatcher | 440 * @type CombinedMatcher |
450 */ | 441 */ |
451 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); | 442 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); |
OLD | NEW |