Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 function removeTrailingDots(string) | |
8 { | |
9 return string.replace(/\.+$/, ""); | |
10 } | |
11 | |
7 /** | 12 /** |
8 * Checks whether a request is third party for the given document, uses | 13 * Checks whether a request is third party for the given document, uses |
9 * information from the public suffix list to determine the effective domain | 14 * information from the public suffix list to determine the effective domain |
10 * name for the document. | 15 * name for the document. |
11 */ | 16 */ |
12 function isThirdParty(requestHost, documentHost) | 17 function isThirdParty(requestHost, documentHost) |
13 { | 18 { |
14 // Remove trailing dots | 19 requestHost = removeTrailingDots(requestHost); |
15 requestHost = requestHost.replace(/\.+$/, ""); | 20 documentHost = removeTrailingDots(documentHost); |
Felix Dahlke
2012/11/09 14:59:16
Bit of a nit pick, but how about having a function
Andrey Novikov
2012/11/12 09:33:12
Done.
| |
16 documentHost = documentHost.replace(/\.+$/, ""); | |
17 | 21 |
18 // Extract domain name - leave IP addresses unchanged, otherwise leave only ba se domain | 22 // Extract domain name - leave IP addresses unchanged, otherwise leave only ba se domain |
19 var documentDomain = getBaseDomain(documentHost); | 23 var documentDomain = getBaseDomain(documentHost); |
20 if (requestHost.length > documentDomain.length) | 24 if (requestHost.length > documentDomain.length) |
21 return (requestHost.substr(requestHost.length - documentDomain.length - 1) ! = "." + documentDomain); | 25 return (requestHost.substr(requestHost.length - documentDomain.length - 1) ! = "." + documentDomain); |
22 else | 26 else |
23 return (requestHost != documentDomain); | 27 return (requestHost != documentDomain); |
24 } | 28 } |
25 | 29 |
26 function reportError(exp) | 30 function reportError(exp) |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 if (file instanceof FakeInputStream) | 306 if (file instanceof FakeInputStream) |
303 this.lines = file.lines; | 307 this.lines = file.lines; |
304 else | 308 else |
305 this.lines = Android.fileRead(file.path).split(/\n/); | 309 this.lines = Android.fileRead(file.path).split(/\n/); |
306 }, | 310 }, |
307 readLine: function(line) | 311 readLine: function(line) |
308 { | 312 { |
309 if (this.currentIndex < this.lines.length) | 313 if (this.currentIndex < this.lines.length) |
310 line.value = this.lines[this.currentIndex]; | 314 line.value = this.lines[this.currentIndex]; |
311 this.currentIndex++; | 315 this.currentIndex++; |
312 return (this.currentIndex < this.lines.length); | 316 return (this.currentIndex < this.lines.length); |
Felix Dahlke
2012/11/09 14:59:16
This check is done twice, temp variable?
Andrey Novikov
2012/11/12 09:33:12
No, currentIndex is plusplused after first check.
Felix Dahlke
2012/11/13 07:53:14
OK, didn't notice.
| |
313 }, | 317 }, |
314 close: function() {}, | 318 close: function() {}, |
315 QueryInterface: function() | 319 QueryInterface: function() |
316 { | 320 { |
317 return this; | 321 return this; |
318 } | 322 } |
319 }; | 323 }; |
320 | 324 |
321 function FakeOutputStream() | 325 function FakeOutputStream() |
322 { | 326 { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 } | 526 } |
523 | 527 |
524 function stopInteractive() | 528 function stopInteractive() |
525 { | 529 { |
526 FilterNotifier.removeListener(onFilterChange); | 530 FilterNotifier.removeListener(onFilterChange); |
527 } | 531 } |
528 | 532 |
529 function matchesAny(url, query, reqHost, refHost, accept) | 533 function matchesAny(url, query, reqHost, refHost, accept) |
530 { | 534 { |
531 var contentType = null; | 535 var contentType = null; |
532 var thirdParty = false; | 536 var thirdParty = true; |
533 | 537 |
534 if (accept != "") | 538 if (accept != "") |
535 { | 539 { |
536 if (accept.indexOf("text/css") != -1) | 540 if (accept.indexOf("text/css") != -1) |
537 contentType = "STYLESHEET"; | 541 contentType = "STYLESHEET"; |
538 else if (accept.indexOf("image/*" != -1)) | 542 else if (accept.indexOf("image/*" != -1)) |
539 contentType = "IMAGE"; | 543 contentType = "IMAGE"; |
540 } | 544 } |
541 | 545 |
542 if (contentType == null) | 546 if (contentType == null) |
(...skipping 12 matching lines...) Expand all Loading... | |
555 contentType = "OTHER"; | 559 contentType = "OTHER"; |
556 | 560 |
557 if (refHost != "") | 561 if (refHost != "") |
558 { | 562 { |
559 thirdParty = isThirdParty(reqHost, refHost); | 563 thirdParty = isThirdParty(reqHost, refHost); |
560 } | 564 } |
561 | 565 |
562 if (query != "") | 566 if (query != "") |
563 url = url + "?" + query; | 567 url = url + "?" + query; |
564 | 568 |
565 return defaultMatcher.matchesAny(url, contentType, null, thirdParty) != null; | 569 var filter = defaultMatcher.matchesAny(url, contentType, null, thirdParty); |
570 | |
571 return (filter != null && !(filter instanceof WhitelistFilter)); | |
566 } | 572 } |
567 | 573 |
568 Android.load("XMLHttpRequest.jsm"); | 574 Android.load("XMLHttpRequest.jsm"); |
569 Android.load("FilterNotifier.jsm"); | 575 Android.load("FilterNotifier.jsm"); |
570 Android.load("FilterClasses.jsm"); | 576 Android.load("FilterClasses.jsm"); |
571 Android.load("SubscriptionClasses.jsm"); | 577 Android.load("SubscriptionClasses.jsm"); |
572 Android.load("FilterStorage.jsm"); | 578 Android.load("FilterStorage.jsm"); |
573 Android.load("FilterListener.jsm"); | 579 Android.load("FilterListener.jsm"); |
574 Android.load("Matcher.jsm"); | 580 Android.load("Matcher.jsm"); |
575 Android.load("ElemHide.jsm"); | 581 Android.load("ElemHide.jsm"); |
576 Android.load("Synchronizer.jsm"); | 582 Android.load("Synchronizer.jsm"); |
577 | 583 |
578 FilterListener.startup(); | 584 FilterListener.startup(); |
579 Synchronizer.startup(); | 585 Synchronizer.startup(); |
580 | 586 |
581 Android.load("publicSuffixList.js"); | 587 Android.load("publicSuffixList.js"); |
582 Android.load("punycode.js"); | 588 Android.load("punycode.js"); |
583 Android.load("basedomain.js"); | 589 Android.load("basedomain.js"); |
LEFT | RIGHT |