| Left: | ||
| Right: |
| 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 15 matching lines...) Expand all Loading... | |
| 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 {objectMouseEventHander} = require("objectTabs"); | 32 let {objectMouseEventHander} = require("objectTabs"); |
| 33 let {ElemHide} = require("elemHide"); | 33 let {ElemHide} = require("elemHide"); |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Randomly generated class name, to be applied to collapsed nodes. | |
| 37 * @type string | |
| 38 */ | |
| 39 let collapsedClass = ""; | |
| 40 | |
| 41 /** | |
| 42 * Public policy checking functions and auxiliary objects | 36 * Public policy checking functions and auxiliary objects |
| 43 * @class | 37 * @class |
| 44 */ | 38 */ |
| 45 var Policy = exports.Policy = | 39 var Policy = exports.Policy = |
| 46 { | 40 { |
| 47 /** | 41 /** |
| 48 * Set of explicitly supported content types | 42 * Set of explicitly supported content types |
| 49 * @type Set.<string> | 43 * @type Set.<string> |
| 50 */ | 44 */ |
| 51 contentTypes: new Set([ | 45 contentTypes: new Set([ |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 72 /** | 66 /** |
| 73 * Called on module startup, initializes various exported properties. | 67 * Called on module startup, initializes various exported properties. |
| 74 */ | 68 */ |
| 75 init: function() | 69 init: function() |
| 76 { | 70 { |
| 77 // whitelisted URL schemes | 71 // whitelisted URL schemes |
| 78 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 72 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
| 79 this.whitelistSchemes.add(scheme); | 73 this.whitelistSchemes.add(scheme); |
| 80 | 74 |
| 81 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", this.shouldAllow.bi nd(this)); | 75 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", this.shouldAllow.bi nd(this)); |
| 82 Utils.addChildMessageListener("AdblockPlus:GetCollapsedClass", () => collaps edClass); | 76 |
| 83 | 77 // Generate class identifier used to collapse nodes and register |
| 84 // Generate class identifier used to collapse node and register correspondin g | 78 // corresponding stylesheet. |
| 85 // stylesheet. | 79 let collapsedClass = ""; |
| 86 let offset = "a".charCodeAt(0); | 80 let offset = "a".charCodeAt(0); |
| 87 for (let i = 0; i < 20; i++) | 81 for (let i = 0; i < 20; i++) |
| 88 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | 82 collapsedClass += String.fromCharCode(offset + Math.random() * 26); |
| 83 Utils.addChildMessageListener("AdblockPlus:GetCollapsedClass", () => collaps edClass); | |
| 89 | 84 |
| 90 let collapseStyle = Services.io.newURI("data:text/css," + | 85 let collapseStyle = Services.io.newURI("data:text/css," + |
| 91 encodeURIComponent("." + collapsedClass + | 86 encodeURIComponent("." + collapsedClass + |
| 92 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null); | 87 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null); |
| 93 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET); | 88 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET); |
| 94 onShutdown.add(() => | 89 onShutdown.add(() => |
| 95 { | 90 { |
| 96 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); | 91 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); |
| 97 }); | 92 }); |
| 98 }, | 93 }, |
| 99 | 94 |
| 100 /** | 95 /** |
| 101 * Checks whether a node should be blocked, hides it if necessary | 96 * Checks whether a node should be blocked, hides it if necessary |
| 102 * @param contentType {String} | 97 * @param {Object} data request data |
| 103 * @param location {String} | 98 * @param {String} data.contentType |
| 104 * @param fremes {Object[]} | 99 * @param {String} data.location location of the request, filter key if conte ntType is ELEMHIDE |
| 105 * @param isPrivate {Boolean} true if the request belongs to a private browsi ng window | 100 * @param {Object[]} data.frames |
| 101 * @param {Boolean} data.isPrivate true if the request belongs to a private b rowsing window | |
| 106 * @return {Object} An object containing properties block, collapse and hits | 102 * @return {Object} An object containing properties block, collapse and hits |
| 107 * indicating how this request should be handled. | 103 * indicating how this request should be handled. |
| 108 */ | 104 */ |
| 109 shouldAllow: function({contentType, location, frames, isPrivate}) | 105 shouldAllow: function({contentType, location, frames, isPrivate}) |
| 110 { | 106 { |
| 111 let hits = []; | 107 let hits = []; |
| 112 | 108 |
| 113 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter) | 109 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter) |
| 114 { | 110 { |
| 115 if (filter && !isPrivate) | 111 if (filter && !isPrivate) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 nogenericMatch); | 167 nogenericMatch); |
| 172 } | 168 } |
| 173 | 169 |
| 174 if (frame == testSitekeyFrame) | 170 if (frame == testSitekeyFrame) |
| 175 [testSitekey, testSitekeyFrame] = getSitekey(frames.slice(i + 1)); | 171 [testSitekey, testSitekeyFrame] = getSitekey(frames.slice(i + 1)); |
| 176 } | 172 } |
| 177 } | 173 } |
| 178 | 174 |
| 179 if (!match && contentType == "ELEMHIDE") | 175 if (!match && contentType == "ELEMHIDE") |
| 180 { | 176 { |
| 181 match = ElemHide.getFilterByKey(location); | 177 match = ElemHide.getFilterByKey(location); |
|
tschuster
2015/11/05 15:39:36
So this is better, but we should still document th
Wladimir Palant
2015/11/06 11:29:00
Done.
| |
| 182 location = match.text.replace(/^.*?#/, '#'); | 178 location = match.text.replace(/^.*?#/, '#'); |
| 183 | 179 |
| 184 if (!match.isActiveOnDomain(docDomain)) | 180 if (!match.isActiveOnDomain(docDomain)) |
| 185 return response(true, false); | 181 return response(true, false); |
| 186 | 182 |
| 187 let exception = ElemHide.getException(match, docDomain); | 183 let exception = ElemHide.getException(match, docDomain); |
| 188 if (exception) | 184 if (exception) |
| 189 { | 185 { |
| 190 addHit(null, contentType, docDomain, false, location, exception); | 186 addHit(null, contentType, docDomain, false, location, exception); |
| 191 return response(true, false); | 187 return response(true, false); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 if (!wnd || wnd.closed) | 399 if (!wnd || wnd.closed) |
| 404 return; | 400 return; |
| 405 | 401 |
| 406 if (entry.type == "OBJECT") | 402 if (entry.type == "OBJECT") |
| 407 { | 403 { |
| 408 node.removeEventListener("mouseover", objectMouseEventHander, true); | 404 node.removeEventListener("mouseover", objectMouseEventHander, true); |
| 409 node.removeEventListener("mouseout", objectMouseEventHander, true); | 405 node.removeEventListener("mouseout", objectMouseEventHander, true); |
| 410 } | 406 } |
| 411 Policy.processNode(wnd, node, entry.type, entry.location, true); | 407 Policy.processNode(wnd, node, entry.type, entry.location, true); |
| 412 } | 408 } |
| LEFT | RIGHT |