| 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 */ | |
| 38 let collapsedClass = ""; | |
| 39 | |
| 40 /** | |
| 41 * Public policy checking functions and auxiliary objects | 36 * Public policy checking functions and auxiliary objects |
| 42 * @class | 37 * @class |
| 43 */ | 38 */ |
| 44 var Policy = exports.Policy = | 39 var Policy = exports.Policy = |
| 45 { | 40 { |
| 46 /** | 41 /** |
| 47 * Set of explicitly supported content types | 42 * Set of explicitly supported content types |
| 48 * @type Set | 43 * @type Set |
| 49 */ | 44 */ |
| 50 contentTypes: new Set([ | 45 contentTypes: new Set([ |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 77 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 72 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
| 78 this.whitelistSchemes.add(scheme); | 73 this.whitelistSchemes.add(scheme); |
| 79 | 74 |
| 80 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] | 75 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] |
| 81 .getService(Ci.nsIMessageListenerManager) | 76 .getService(Ci.nsIMessageListenerManager) |
| 82 .QueryInterface(Ci.nsIMessageBroadcaster); | 77 .QueryInterface(Ci.nsIMessageBroadcaster); |
| 83 let handler = (message => this.shouldAllow(message.data)); | 78 let handler = (message => this.shouldAllow(message.data)); |
| 84 messageManager.addMessageListener("AdblockPlus:ShouldAllow", handler); | 79 messageManager.addMessageListener("AdblockPlus:ShouldAllow", handler); |
| 85 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:Shoul dAllow", handler)); | 80 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:Shoul dAllow", handler)); |
| 86 | 81 |
| 82 // Generate class identifier used to collapse nodes and register | |
| 83 // corresponding stylesheet. | |
| 84 let collapsedClass = ""; | |
| 85 let offset = "a".charCodeAt(0); | |
| 86 for (let i = 0; i < 20; i++) | |
| 87 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | |
| 88 | |
| 87 let handler2 = () => collapsedClass; | 89 let handler2 = () => collapsedClass; |
| 88 messageManager.addMessageListener("AdblockPlus:GetCollapsedClass", handler2) ; | 90 messageManager.addMessageListener("AdblockPlus:GetCollapsedClass", handler2) ; |
| 89 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:GetCo llapsedClass", handler2)); | 91 onShutdown.add(() => messageManager.removeMessageListener("AdblockPlus:GetCo llapsedClass", handler2)); |
| 90 | |
| 91 // Generate class identifier used to collapse node and register correspondin g | |
| 92 // stylesheet. | |
| 93 let offset = "a".charCodeAt(0); | |
| 94 for (let i = 0; i < 20; i++) | |
| 95 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | |
| 96 | 92 |
| 97 let collapseStyle = Services.io.newURI("data:text/css," + | 93 let collapseStyle = Services.io.newURI("data:text/css," + |
| 98 encodeURIComponent("." + collapsedClass + | 94 encodeURIComponent("." + collapsedClass + |
| 99 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null); | 95 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null); |
| 100 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET); | 96 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET); |
| 101 onShutdown.add(() => | 97 onShutdown.add(() => |
| 102 { | 98 { |
| 103 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); | 99 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); |
| 104 }); | 100 }); |
| 105 }, | 101 }, |
| 106 | 102 |
| 107 /** | 103 /** |
| 108 * Checks whether a node should be blocked, hides it if necessary | 104 * Checks whether a node should be blocked, hides it if necessary |
| 109 * @param contentType {String} | 105 * @param {Object} data request data |
|
Thomas Greiner
2015/11/11 16:52:33
The documentation of the parameters is no longer a
Wladimir Palant
2015/11/11 17:43:26
Done.
| |
| 110 * @param location {String} | 106 * @param {String} data.contentType |
| 111 * @param frames {Object[]} | 107 * @param {String} data.location |
| 112 * @param isPrivate {Boolean} true if the request belongs to a private browsi ng window | 108 * @param {Object[]} data.frames |
| 113 * @return {Object} An object containing properties block, collapse and hits | 109 * @param {Boolean} data.isPrivate true if the request belongs to a private b rowsing window |
| 110 * @return {Object} An object containing properties allow, collapse and hits | |
| 114 * indicating how this request should be handled. | 111 * indicating how this request should be handled. |
| 115 */ | 112 */ |
| 116 shouldAllow: function({contentType, location, frames, isPrivate}) | 113 shouldAllow: function({contentType, location, frames, isPrivate}) |
| 117 { | 114 { |
| 118 let hits = []; | 115 let hits = []; |
| 119 | 116 |
| 120 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter) | 117 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter) |
| 121 { | 118 { |
| 122 if (filter && !isPrivate) | 119 if (filter && !isPrivate) |
| 123 FilterStorage.increaseHitCount(filter); | 120 FilterStorage.increaseHitCount(filter); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 { | 184 { |
| 188 match = location; | 185 match = location; |
| 189 location = match.text.replace(/^.*?#/, '#'); | 186 location = match.text.replace(/^.*?#/, '#'); |
| 190 | 187 |
| 191 if (!match.isActiveOnDomain(docDomain)) | 188 if (!match.isActiveOnDomain(docDomain)) |
| 192 return response(true, false); | 189 return response(true, false); |
| 193 | 190 |
| 194 let exception = ElemHide.getException(match, docDomain); | 191 let exception = ElemHide.getException(match, docDomain); |
| 195 if (exception) | 192 if (exception) |
| 196 { | 193 { |
| 197 addHit(null, contentType, docDomain, false, location, exception); | 194 addHit(null, contentType, docDomain, false, location, exception); |
|
Thomas Greiner
2015/11/11 16:52:33
Detail: Isn't it more common to use `-1` for a non
Wladimir Palant
2015/11/11 17:43:25
That's what I had initially but frameIndex: -1 doe
Thomas Greiner
2015/11/11 18:07:32
Makes sense then, I agree.
| |
| 198 return response(true, false); | 195 return response(true, false); |
| 199 } | 196 } |
| 200 | 197 |
| 201 if (nogeneric && match.isGeneric()) | 198 if (nogeneric && match.isGeneric()) |
| 202 return response(true, false); | 199 return response(true, false); |
| 203 } | 200 } |
| 204 | 201 |
| 205 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location, docDomain)); | 202 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location, docDomain)); |
| 206 let collapse = false; | 203 let collapse = false; |
| 207 if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentTy pe)) | 204 if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentTy pe)) |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 if (!wnd || wnd.closed) | 407 if (!wnd || wnd.closed) |
| 411 return; | 408 return; |
| 412 | 409 |
| 413 if (entry.type == "OBJECT") | 410 if (entry.type == "OBJECT") |
| 414 { | 411 { |
| 415 node.removeEventListener("mouseover", objectMouseEventHander, true); | 412 node.removeEventListener("mouseover", objectMouseEventHander, true); |
| 416 node.removeEventListener("mouseout", objectMouseEventHander, true); | 413 node.removeEventListener("mouseout", objectMouseEventHander, true); |
| 417 } | 414 } |
| 418 Policy.processNode(wnd, node, entry.type, entry.location, true); | 415 Policy.processNode(wnd, node, entry.type, entry.location, true); |
| 419 } | 416 } |
| LEFT | RIGHT |