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 22 matching lines...) Expand all Loading... | |
73 */ | 68 */ |
74 init: function() | 69 init: function() |
75 { | 70 { |
76 // whitelisted URL schemes | 71 // whitelisted URL schemes |
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 => JSON.stringify(this.shouldAllow(message.data))); | 78 let handler = (message => this.shouldAllow(message.data)); |
tschuster
2015/11/07 12:29:03
Why is that necessary? Message listeners should be
Wladimir Palant
2015/11/07 18:57:32
I don't know why but without stringification it do
Wladimir Palant
2015/11/09 10:59:21
I tried this again and removing stringification do
| |
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)); |
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); | |
86 | 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 |
110 * @param location {String} | 106 * @param {String} data.contentType |
111 * @param fremes {Object[]} | 107 * @param {String} data.location |
tschuster
2015/11/07 12:29:03
typo: frames
Wladimir Palant
2015/11/07 18:57:32
Yes, I noticed and fixed this when I added descrip
Wladimir Palant
2015/11/09 10:59:21
Done.
| |
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 14 matching lines...) Expand all Loading... | |
138 | 135 |
139 // Interpret unknown types as "other" | 136 // Interpret unknown types as "other" |
140 if (!this.contentTypes.has(contentType)) | 137 if (!this.contentTypes.has(contentType)) |
141 contentType = "OTHER"; | 138 contentType = "OTHER"; |
142 | 139 |
143 let wndLocation = frames[0].location; | 140 let wndLocation = frames[0].location; |
144 let docDomain = getHostname(wndLocation); | 141 let docDomain = getHostname(wndLocation); |
145 let match = null; | 142 let match = null; |
146 let [sitekey, sitekeyFrame] = getSitekey(frames); | 143 let [sitekey, sitekeyFrame] = getSitekey(frames); |
147 let nogeneric = false; | 144 let nogeneric = false; |
148 if (!match && Prefs.enabled) | 145 if (!match && Prefs.enabled) |
tschuster
2015/11/07 12:29:03
nit: match can't be true here.
Wladimir Palant
2015/11/07 18:57:32
Yes, and neither in the next if block. The origina
| |
149 { | 146 { |
150 let testSitekey = sitekey; | 147 let testSitekey = sitekey; |
151 let testSitekeyFrame = sitekeyFrame; | 148 let testSitekeyFrame = sitekeyFrame; |
152 for (let i = 0; i < frames.length; i++) | 149 for (let i = 0; i < frames.length; i++) |
153 { | 150 { |
154 let frame = frames[i]; | 151 let frame = frames[i]; |
155 let testWndLocation = frame.location; | 152 let testWndLocation = frame.location; |
156 let parentWndLocation = frames[Math.min(i + 1, frames.length - 1)].locat ion; | 153 let parentWndLocation = frames[Math.min(i + 1, frames.length - 1)].locat ion; |
157 let parentDocDomain = getHostname(parentWndLocation); | 154 let parentDocDomain = getHostname(parentWndLocation); |
158 | 155 |
(...skipping 251 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 |