| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * @fileOverview Content policy implementation, responsible for blocking things. | 19 * @fileOverview Content policy implementation, responsible for blocking things. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 "use strict"; | 22 "use strict"; |
| 23 | 23 |
| 24 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 24 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
| 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 {port} = require("messaging"); | |
| 28 let {Prefs} = require("prefs"); | 29 let {Prefs} = require("prefs"); |
| 29 let {FilterStorage} = require("filterStorage"); | 30 let {FilterStorage} = require("filterStorage"); |
| 30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); | 31 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); |
| 31 let {defaultMatcher} = require("matcher"); | 32 let {defaultMatcher} = require("matcher"); |
| 32 let {ElemHide} = require("elemHide"); | 33 let {ElemHide} = require("elemHide"); |
| 33 | 34 |
| 34 /** | 35 /** |
| 35 * Public policy checking functions and auxiliary objects | 36 * Public policy checking functions and auxiliary objects |
| 36 * @class | 37 * @class |
| 37 */ | 38 */ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 81 |
| 81 /** | 82 /** |
| 82 * Called on module startup, initializes various exported properties. | 83 * Called on module startup, initializes various exported properties. |
| 83 */ | 84 */ |
| 84 init: function() | 85 init: function() |
| 85 { | 86 { |
| 86 // whitelisted URL schemes | 87 // whitelisted URL schemes |
| 87 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) | 88 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
| 88 this.whitelistSchemes.add(scheme); | 89 this.whitelistSchemes.add(scheme); |
| 89 | 90 |
| 90 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.sho uldAllow(message)); | 91 port.on("shouldAllow", (message, sender) => this.shouldAllow(message)); |
|
Erik
2016/03/15 22:57:00
`(message, sender) => this.shouldAllow(message)` =
Wladimir Palant
2016/03/16 10:13:00
I'd rather name all parameters explicitly even if
Thomas Greiner
2016/03/16 10:59:11
Personally, I also prefer naming parameters explic
| |
| 91 | 92 |
| 92 // Generate class identifier used to collapse nodes and register | 93 // Generate class identifier used to collapse nodes and register |
| 93 // corresponding stylesheet. | 94 // corresponding stylesheet. |
| 94 let collapsedClass = ""; | 95 let collapsedClass = ""; |
| 95 let offset = "a".charCodeAt(0); | 96 let offset = "a".charCodeAt(0); |
| 96 for (let i = 0; i < 20; i++) | 97 for (let i = 0; i < 20; i++) |
| 97 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | 98 collapsedClass += String.fromCharCode(offset + Math.random() * 26); |
| 98 Utils.addChildMessageListener("AdblockPlus:GetCollapsedClass", () => collaps edClass); | 99 port.on("getCollapsedClass", (message, sender) => collapsedClass); |
|
Erik
2016/03/15 22:57:00
`(message, sender) => collapsedClass` => `() => co
| |
| 99 | 100 |
| 100 let collapseStyle = Services.io.newURI("data:text/css," + | 101 let collapseStyle = Services.io.newURI("data:text/css," + |
| 101 encodeURIComponent("." + collapsedClass + | 102 encodeURIComponent("." + collapsedClass + |
| 102 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null); | 103 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb azdummy) !important;}"), null, null); |
| 103 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET); | 104 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi ce.USER_SHEET); |
| 104 onShutdown.add(() => | 105 onShutdown.add(() => |
| 105 { | 106 { |
| 106 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); | 107 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); |
| 107 }); | 108 }); |
| 108 }, | 109 }, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 return (result instanceof WhitelistFilter ? result : null); | 267 return (result instanceof WhitelistFilter ? result : null); |
| 267 }, | 268 }, |
| 268 | 269 |
| 269 /** | 270 /** |
| 270 * Deletes nodes that were previously stored with a | 271 * Deletes nodes that were previously stored with a |
| 271 * RequestNotifier.storeNodesForEntries() call or similar. | 272 * RequestNotifier.storeNodesForEntries() call or similar. |
| 272 * @param {string} id unique ID of the nodes | 273 * @param {string} id unique ID of the nodes |
| 273 */ | 274 */ |
| 274 deleteNodes: function(id) | 275 deleteNodes: function(id) |
| 275 { | 276 { |
| 276 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] | 277 port.emit("deleteNodes", id); |
| 277 .getService(Ci.nsIMessageBroadcaster); | |
| 278 messageManager.broadcastAsyncMessage("AdblockPlus:DeleteNodes", id); | |
| 279 }, | 278 }, |
| 280 | 279 |
| 281 /** | 280 /** |
| 282 * Asynchronously re-checks filters for nodes given by an ID previously | 281 * Asynchronously re-checks filters for nodes given by an ID previously |
| 283 * returned by a RequestNotifier.storeNodesForEntries() call or similar. | 282 * returned by a RequestNotifier.storeNodesForEntries() call or similar. |
| 284 * @param {string} id unique ID of the nodes | 283 * @param {string} id unique ID of the nodes |
| 285 * @param {RequestEntry} entry | 284 * @param {RequestEntry} entry |
| 286 */ | 285 */ |
| 287 refilterNodes: function(id, entry) | 286 refilterNodes: function(id, entry) |
| 288 { | 287 { |
| 289 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] | 288 port.emit("refilterNodes", { |
| 290 .getService(Ci.nsIMessageBroadcaster); | |
| 291 messageManager.broadcastAsyncMessage("AdblockPlus:RefilterNodes", { | |
| 292 nodesID: id, | 289 nodesID: id, |
| 293 entry: entry | 290 entry: entry |
| 294 }); | 291 }); |
| 295 } | 292 } |
| 296 }; | 293 }; |
| 297 Policy.init(); | 294 Policy.init(); |
| 298 | 295 |
| 299 /** | 296 /** |
| 300 * Extracts the hostname from a URL (might return null). | 297 * Extracts the hostname from a URL (might return null). |
| 301 */ | 298 */ |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 { | 397 { |
| 401 // EffectiveTLDService throws on IP addresses, just compare the host name | 398 // EffectiveTLDService throws on IP addresses, just compare the host name |
| 402 let host = ""; | 399 let host = ""; |
| 403 try | 400 try |
| 404 { | 401 { |
| 405 host = uri.host; | 402 host = uri.host; |
| 406 } catch (e) {} | 403 } catch (e) {} |
| 407 return host != docDomain; | 404 return host != docDomain; |
| 408 } | 405 } |
| 409 } | 406 } |
| OLD | NEW |