Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 let docDomain = getHostname(wndLocation); | 163 let docDomain = getHostname(wndLocation); |
164 let match = null; | 164 let match = null; |
165 if (!match && Prefs.enabled) | 165 if (!match && Prefs.enabled) |
166 { | 166 { |
167 let testWnd = wnd; | 167 let testWnd = wnd; |
168 let parentWndLocation = getWindowLocation(testWnd); | 168 let parentWndLocation = getWindowLocation(testWnd); |
169 while (true) | 169 while (true) |
170 { | 170 { |
171 let testWndLocation = parentWndLocation; | 171 let testWndLocation = parentWndLocation; |
172 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 172 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); |
173 match = Policy.isWhitelisted(testWndLocation, parentWndLocation); | |
174 | 173 |
175 if (!(match instanceof WhitelistFilter)) | 174 let siteKey = getSiteKey(node, testWnd); |
176 { | 175 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, siteKey ); |
Wladimir Palant
2014/08/01 10:50:21
The logic here seems wrong to me. I've extended th
Thomas Greiner
2014/08/11 17:18:15
Done.
| |
177 let keydata = (testWnd.document && testWnd.document.documentElement ? testWnd.document.documentElement.getAttribute("data-adblockkey") : null); | |
178 if (keydata && keydata.indexOf("_") >= 0) | |
179 { | |
180 let [key, signature] = keydata.split("_", 2); | |
181 let keyMatch = defaultMatcher.matchesByKey(testWndLocation, key.repl ace(/=/g, ""), docDomain); | |
182 if (keyMatch && Utils.crypto) | |
183 { | |
184 // Website specifies a key that we know but is the signature valid ? | |
185 let uri = Services.io.newURI(testWndLocation, null, null); | |
186 let params = [ | |
187 uri.path.replace(/#.*/, ""), // REQUEST_URI | |
188 uri.asciiHost, // HTTP_HOST | |
189 Utils.httpProtocol.userAgent // HTTP_USER_AGENT | |
190 ]; | |
191 if (Utils.verifySignature(key, signature, params.join("\0"))) | |
192 match = keyMatch; | |
193 } | |
194 } | |
195 } | |
196 | 176 |
197 if (match instanceof WhitelistFilter) | 177 if (match instanceof WhitelistFilter) |
198 { | 178 { |
199 FilterStorage.increaseHitCount(match, wnd); | 179 FilterStorage.increaseHitCount(match, wnd); |
200 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); | 180 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); |
201 return true; | 181 return true; |
202 } | 182 } |
203 | 183 |
204 if (testWnd.parent == testWnd) | 184 if (testWnd.parent == testWnd) |
205 break; | 185 break; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 FilterStorage.increaseHitCount(exception, wnd); | 233 FilterStorage.increaseHitCount(exception, wnd); |
254 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdP arty, locationText, exception); | 234 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdP arty, locationText, exception); |
255 return true; | 235 return true; |
256 } | 236 } |
257 } | 237 } |
258 | 238 |
259 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); | 239 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); |
260 | 240 |
261 if (!match && Prefs.enabled) | 241 if (!match && Prefs.enabled) |
262 { | 242 { |
263 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty); | 243 let docLocation = getWindowLocation(wnd); |
244 let siteKey = getSiteKey(node, wnd); | |
245 match = defaultMatcher.matchesAny(locationText, Policy.typeDescr[contentTy pe] || "", docDomain, thirdParty, docLocation, siteKey); | |
264 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) | 246 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) |
265 { | 247 { |
266 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); | 248 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); |
267 if (collapse || prefCollapse) | 249 if (collapse || prefCollapse) |
268 schedulePostProcess(node); | 250 schedulePostProcess(node); |
269 } | 251 } |
270 | 252 |
271 // Track mouse events for objects | 253 // Track mouse events for objects |
272 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) | 254 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) |
273 { | 255 { |
(...skipping 16 matching lines...) Expand all Loading... | |
290 * @return {Boolean} | 272 * @return {Boolean} |
291 */ | 273 */ |
292 isBlockableScheme: function(location) | 274 isBlockableScheme: function(location) |
293 { | 275 { |
294 return !(location.scheme in Policy.whitelistSchemes); | 276 return !(location.scheme in Policy.whitelistSchemes); |
295 }, | 277 }, |
296 | 278 |
297 /** | 279 /** |
298 * Checks whether a page is whitelisted. | 280 * Checks whether a page is whitelisted. |
299 * @param {String} url | 281 * @param {String} url |
300 * @param {String} [parentUrl] location of the parent page | 282 * @param {String} parentUrl location of the parent page |
283 * @param {String} siteKey public key provided on the page | |
301 * @return {Filter} filter that matched the URL or null if not whitelisted | 284 * @return {Filter} filter that matched the URL or null if not whitelisted |
302 */ | 285 */ |
303 isWhitelisted: function(url, parentUrl) | 286 isWhitelisted: function(url, parentUrl, siteKey) |
Wladimir Palant
2014/08/01 10:50:21
If you change the parameters here you probably wan
Thomas Greiner
2014/08/11 17:18:15
Done.
| |
304 { | 287 { |
305 if (!url) | 288 if (!url) |
306 return null; | 289 return null; |
307 | 290 |
308 // Do not apply exception rules to schemes on our whitelistschemes list. | 291 // Do not apply exception rules to schemes on our whitelistschemes list. |
309 let match = /^([\w\-]+):/.exec(url); | 292 let match = /^([\w\-]+):/.exec(url); |
310 if (match && match[1] in Policy.whitelistSchemes) | 293 if (match && match[1] in Policy.whitelistSchemes) |
311 return null; | 294 return null; |
312 | 295 |
313 if (!parentUrl) | 296 if (!parentUrl) |
314 parentUrl = url; | 297 parentUrl = url; |
Wladimir Palant
2014/08/01 10:50:21
If parentUrl is no longer optional then this code
Thomas Greiner
2014/08/11 17:18:15
Technically, it's still optional since it's only r
| |
315 | 298 |
316 // Ignore fragment identifier | 299 // Ignore fragment identifier |
317 let index = url.indexOf("#"); | 300 let index = url.indexOf("#"); |
318 if (index >= 0) | 301 if (index >= 0) |
319 url = url.substring(0, index); | 302 url = url.substring(0, index); |
320 | 303 |
321 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr l), false); | 304 let result = defaultMatcher.matchesAny(url, "DOCUMENT", getHostname(parentUr l), false, parentUrl, siteKey); |
322 return (result instanceof WhitelistFilter ? result : null); | 305 return (result instanceof WhitelistFilter ? result : null); |
323 }, | 306 }, |
324 | 307 |
325 /** | 308 /** |
326 * Checks whether the page loaded in a window is whitelisted. | 309 * Checks whether the page loaded in a window is whitelisted. |
327 * @param wnd {nsIDOMWindow} | 310 * @param wnd {nsIDOMWindow} |
328 * @return {Filter} matching exception rule or null if not whitelisted | 311 * @return {Filter} matching exception rule or null if not whitelisted |
329 */ | 312 */ |
330 isWindowWhitelisted: function(wnd) | 313 isWindowWhitelisted: function(wnd) |
331 { | 314 { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 { | 667 { |
685 return Utils.unwrapURL(url).host; | 668 return Utils.unwrapURL(url).host; |
686 } | 669 } |
687 catch(e) | 670 catch(e) |
688 { | 671 { |
689 return null; | 672 return null; |
690 } | 673 } |
691 } | 674 } |
692 | 675 |
693 /** | 676 /** |
677 * Retrieves the sitekey of a window. | |
678 */ | |
679 function getSiteKey(node, wnd) | |
Wladimir Palant
2014/08/01 10:50:21
Why pass in node parameter that isn't used?
Thomas Greiner
2014/08/11 17:18:15
Done.
| |
680 { | |
681 if (wnd.document && wnd.document.documentElement) | |
682 return wnd.document.documentElement.getAttribute("data-adblockkey"); | |
683 | |
684 return null; | |
685 } | |
686 | |
687 /** | |
694 * Retrieves the location of a window. | 688 * Retrieves the location of a window. |
695 * @param wnd {nsIDOMWindow} | 689 * @param wnd {nsIDOMWindow} |
696 * @return {String} window location or null on failure | 690 * @return {String} window location or null on failure |
697 */ | 691 */ |
698 function getWindowLocation(wnd) | 692 function getWindowLocation(wnd) |
699 { | 693 { |
700 if ("name" in wnd && wnd.name == "messagepane") | 694 if ("name" in wnd && wnd.name == "messagepane") |
701 { | 695 { |
702 // Thunderbird branch | 696 // Thunderbird branch |
703 try | 697 try |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 if (!wnd || wnd.closed) | 759 if (!wnd || wnd.closed) |
766 return; | 760 return; |
767 | 761 |
768 if (entry.type == Policy.type.OBJECT) | 762 if (entry.type == Policy.type.OBJECT) |
769 { | 763 { |
770 node.removeEventListener("mouseover", objectMouseEventHander, true); | 764 node.removeEventListener("mouseover", objectMouseEventHander, true); |
771 node.removeEventListener("mouseout", objectMouseEventHander, true); | 765 node.removeEventListener("mouseout", objectMouseEventHander, true); |
772 } | 766 } |
773 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; | 767 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; |
774 } | 768 } |
OLD | NEW |