| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 14 matching lines...) Expand all Loading... |
| 25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
| 26 | 26 |
| 27 let {Utils} = require("utils"); | 27 let {Utils} = require("utils"); |
| 28 let {Prefs} = require("prefs"); | 28 let {Prefs} = require("prefs"); |
| 29 let {FilterStorage} = require("filterStorage"); | 29 let {FilterStorage} = require("filterStorage"); |
| 30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); | 30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); |
| 31 let {defaultMatcher} = require("matcher"); | 31 let {defaultMatcher} = require("matcher"); |
| 32 let {ElemHide} = require("elemHide"); | 32 let {ElemHide} = require("elemHide"); |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Randomly generated class name, to be applied to collapsed nodes. | |
| 36 * @type string | |
| 37 */ | |
| 38 let collapsedClass = ""; | |
| 39 | |
| 40 /** | |
| 41 * Public policy checking functions and auxiliary objects | 35 * Public policy checking functions and auxiliary objects |
| 42 * @class | 36 * @class |
| 43 */ | 37 */ |
| 44 var Policy = exports.Policy = | 38 var Policy = exports.Policy = |
| 45 { | 39 { |
| 46 /** | 40 /** |
| 47 * Set of explicitly supported content types | 41 * Set of explicitly supported content types |
| 48 * @type Set.<string> | 42 * @type Set.<string> |
| 49 */ | 43 */ |
| 50 contentTypes: new Set([ | 44 contentTypes: new Set([ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 71 /** | 65 /** |
| 72 * Called on module startup, initializes various exported properties. | 66 * Called on module startup, initializes various exported properties. |
| 73 */ | 67 */ |
| 74 init: function() | 68 init: function() |
| 75 { | 69 { |
| 76 // whitelisted URL schemes | 70 // whitelisted URL schemes |
| 77 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 71 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
| 78 this.whitelistSchemes.add(scheme); | 72 this.whitelistSchemes.add(scheme); |
| 79 | 73 |
| 80 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", this.shouldAllow.bi
nd(this)); | 74 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", this.shouldAllow.bi
nd(this)); |
| 81 Utils.addChildMessageListener("AdblockPlus:GetCollapsedClass", () => collaps
edClass); | 75 |
| 82 | 76 // Generate class identifier used to collapse nodes and register |
| 83 // Generate class identifier used to collapse node and register correspondin
g | 77 // corresponding stylesheet. |
| 84 // stylesheet. | 78 let collapsedClass = ""; |
| 85 let offset = "a".charCodeAt(0); | 79 let offset = "a".charCodeAt(0); |
| 86 for (let i = 0; i < 20; i++) | 80 for (let i = 0; i < 20; i++) |
| 87 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | 81 collapsedClass += String.fromCharCode(offset + Math.random() * 26); |
| 82 Utils.addChildMessageListener("AdblockPlus:GetCollapsedClass", () => collaps
edClass); |
| 88 | 83 |
| 89 let collapseStyle = Services.io.newURI("data:text/css," + | 84 let collapseStyle = Services.io.newURI("data:text/css," + |
| 90 encodeURIComponent("." + collapsedClass + | 85 encodeURIComponent("." + collapsedClass + |
| 91 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb
azdummy) !important;}"), null, null); | 86 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb
azdummy) !important;}"), null, null); |
| 92 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi
ce.USER_SHEET); | 87 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi
ce.USER_SHEET); |
| 93 onShutdown.add(() => | 88 onShutdown.add(() => |
| 94 { | 89 { |
| 95 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService.
USER_SHEET); | 90 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService.
USER_SHEET); |
| 96 }); | 91 }); |
| 97 }, | 92 }, |
| 98 | 93 |
| 99 /** | 94 /** |
| 100 * Checks whether a node should be blocked, hides it if necessary | 95 * Checks whether a node should be blocked, hides it if necessary |
| 101 * @param contentType {String} | 96 * @param {Object} data request data |
| 102 * @param location {String} location of the request, filter key if contentType
is ELEMHIDE | 97 * @param {String} data.contentType |
| 103 * @param frames {Object[]} | 98 * @param {String} data.location location of the request, filter key if conte
ntType is ELEMHIDE |
| 104 * @param isPrivate {Boolean} true if the request belongs to a private browsi
ng window | 99 * @param {Object[]} data.frames |
| 100 * @param {Boolean} data.isPrivate true if the request belongs to a private b
rowsing window |
| 105 * @return {Object} An object containing properties block, collapse and hits | 101 * @return {Object} An object containing properties block, collapse and hits |
| 106 * indicating how this request should be handled. | 102 * indicating how this request should be handled. |
| 107 */ | 103 */ |
| 108 shouldAllow: function({contentType, location, frames, isPrivate}) | 104 shouldAllow: function({contentType, location, frames, isPrivate}) |
| 109 { | 105 { |
| 110 let hits = []; | 106 let hits = []; |
| 111 | 107 |
| 112 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi
lter) | 108 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi
lter) |
| 113 { | 109 { |
| 114 if (filter && !isPrivate) | 110 if (filter && !isPrivate) |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 { | 395 { |
| 400 // EffectiveTLDService throws on IP addresses, just compare the host name | 396 // EffectiveTLDService throws on IP addresses, just compare the host name |
| 401 let host = ""; | 397 let host = ""; |
| 402 try | 398 try |
| 403 { | 399 { |
| 404 host = uri.host; | 400 host = uri.host; |
| 405 } catch (e) {} | 401 } catch (e) {} |
| 406 return host != docDomain; | 402 return host != docDomain; |
| 407 } | 403 } |
| 408 } | 404 } |
| LEFT | RIGHT |