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-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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // Generate class identifier used to collapse node and register correspondin
g | 94 // Generate class identifier used to collapse node and register correspondin
g |
95 // stylesheet. | 95 // stylesheet. |
96 let offset = "a".charCodeAt(0); | 96 let offset = "a".charCodeAt(0); |
97 for (let i = 0; i < 20; i++) | 97 for (let i = 0; i < 20; i++) |
98 collapsedClass += String.fromCharCode(offset + Math.random() * 26); | 98 collapsedClass += String.fromCharCode(offset + Math.random() * 26); |
99 | 99 |
100 let collapseStyle = Services.io.newURI("data:text/css," + | 100 let collapseStyle = Services.io.newURI("data:text/css," + |
101 encodeURIComponent("." + collapsedClass + | 101 encodeURIComponent("." + collapsedClass + |
102 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb
azdummy) !important;}"), null, null); | 102 "{-moz-binding: url(chrome://global/content/bindings/general.xml#foobarb
azdummy) !important;}"), null, null); |
103 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi
ce.USER_SHEET); | 103 Utils.styleService.loadAndRegisterSheet(collapseStyle, Ci.nsIStyleSheetServi
ce.USER_SHEET); |
104 onShutdown.add(function() | 104 onShutdown.add(() => |
105 { | 105 { |
106 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService.
USER_SHEET); | 106 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService.
USER_SHEET); |
107 }); | 107 }); |
108 }, | 108 }, |
109 | 109 |
110 /** | 110 /** |
111 * Checks whether a node should be blocked, hides it if necessary | 111 * Checks whether a node should be blocked, hides it if necessary |
112 * @param wnd {nsIDOMWindow} | 112 * @param wnd {nsIDOMWindow} |
113 * @param node {nsIDOMElement} | 113 * @param node {nsIDOMElement} |
114 * @param contentType {String} | 114 * @param contentType {String} |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 return !match || match instanceof WhitelistFilter; | 253 return !match || match instanceof WhitelistFilter; |
254 }, | 254 }, |
255 | 255 |
256 /** | 256 /** |
257 * Checks whether the location's scheme is blockable. | 257 * Checks whether the location's scheme is blockable. |
258 * @param location {nsIURI} | 258 * @param location {nsIURI} |
259 * @return {Boolean} | 259 * @return {Boolean} |
260 */ | 260 */ |
261 isBlockableScheme: function(location) | 261 isBlockableScheme: function(location) |
262 { | 262 { |
263 return !Policy.whitelistSchemes.has(location.scheme); | 263 return !this.whitelistSchemes.has(location.scheme); |
264 }, | 264 }, |
265 | 265 |
266 /** | 266 /** |
267 * Checks whether a page is whitelisted. | 267 * Checks whether a page is whitelisted. |
268 * @param {String} url | 268 * @param {String} url |
269 * @param {String} [parentUrl] location of the parent page | 269 * @param {String} [parentUrl] location of the parent page |
270 * @param {String} [sitekey] public key provided on the page | 270 * @param {String} [sitekey] public key provided on the page |
271 * @return {Filter} filter that matched the URL or null if not whitelisted | 271 * @return {Filter} filter that matched the URL or null if not whitelisted |
272 */ | 272 */ |
273 isWhitelisted: function(url, parentUrl, sitekey) | 273 isWhitelisted: function(url, parentUrl, sitekey) |
274 { | 274 { |
275 if (!url) | 275 if (!url) |
276 return null; | 276 return null; |
277 | 277 |
278 // Do not apply exception rules to schemes on our whitelistschemes list. | 278 // Do not apply exception rules to schemes on our whitelistschemes list. |
279 let match = /^([\w\-]+):/.exec(url); | 279 let match = /^([\w\-]+):/.exec(url); |
280 if (match && Policy.whitelistSchemes.has(match[1])) | 280 if (match && this.whitelistSchemes.has(match[1])) |
281 return null; | 281 return null; |
282 | 282 |
283 if (!parentUrl) | 283 if (!parentUrl) |
284 parentUrl = url; | 284 parentUrl = url; |
285 | 285 |
286 // Ignore fragment identifier | 286 // Ignore fragment identifier |
287 let index = url.indexOf("#"); | 287 let index = url.indexOf("#"); |
288 if (index >= 0) | 288 if (index >= 0) |
289 url = url.substring(0, index); | 289 url = url.substring(0, index); |
290 | 290 |
291 let result = defaultMatcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, g
etHostname(parentUrl), false, sitekey); | 291 let result = defaultMatcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, g
etHostname(parentUrl), false, sitekey); |
292 return (result instanceof WhitelistFilter ? result : null); | 292 return (result instanceof WhitelistFilter ? result : null); |
293 }, | 293 }, |
294 | 294 |
295 /** | 295 /** |
296 * Checks whether the page loaded in a window is whitelisted for indication in
the UI. | 296 * Checks whether the page loaded in a window is whitelisted for indication in
the UI. |
297 * @param wnd {nsIDOMWindow} | 297 * @param wnd {nsIDOMWindow} |
298 * @return {Filter} matching exception rule or null if not whitelisted | 298 * @return {Filter} matching exception rule or null if not whitelisted |
299 */ | 299 */ |
300 isWindowWhitelisted: function(wnd) | 300 isWindowWhitelisted: function(wnd) |
301 { | 301 { |
302 return Policy.isWhitelisted(getWindowLocation(wnd)); | 302 return this.isWhitelisted(getWindowLocation(wnd)); |
303 }, | 303 }, |
304 | 304 |
305 /** | 305 /** |
306 * Asynchronously re-checks filters for given nodes. | 306 * Asynchronously re-checks filters for given nodes. |
307 * @param {Node[]} nodes | 307 * @param {Node[]} nodes |
308 * @param {RequestEntry} entry | 308 * @param {RequestEntry} entry |
309 */ | 309 */ |
310 refilterNodes: function(nodes, entry) | 310 refilterNodes: function(nodes, entry) |
311 { | 311 { |
312 // Ignore nodes that have been blocked already | 312 // Ignore nodes that have been blocked already |
(...skipping 24 matching lines...) Expand all Loading... |
337 { | 337 { |
338 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | 338 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
339 registrar.registerFactory(this.classID, this.classDescription, this.contract
ID, this); | 339 registrar.registerFactory(this.classID, this.classDescription, this.contract
ID, this); |
340 | 340 |
341 let catMan = Utils.categoryManager; | 341 let catMan = Utils.categoryManager; |
342 for (let category of this.xpcom_categories) | 342 for (let category of this.xpcom_categories) |
343 catMan.addCategoryEntry(category, this.contractID, this.contractID, false,
true); | 343 catMan.addCategoryEntry(category, this.contractID, this.contractID, false,
true); |
344 | 344 |
345 Services.obs.addObserver(this, "content-document-global-created", true); | 345 Services.obs.addObserver(this, "content-document-global-created", true); |
346 | 346 |
347 onShutdown.add(function() | 347 onShutdown.add(() => |
348 { | 348 { |
349 Services.obs.removeObserver(this, "content-document-global-created"); | 349 Services.obs.removeObserver(this, "content-document-global-created"); |
350 | 350 |
351 for (let category of this.xpcom_categories) | 351 for (let category of this.xpcom_categories) |
352 catMan.deleteCategoryEntry(category, this.contractID, false); | 352 catMan.deleteCategoryEntry(category, this.contractID, false); |
353 | 353 |
354 registrar.unregisterFactory(this.classID, this); | 354 registrar.unregisterFactory(this.classID, this); |
355 }.bind(this)); | 355 }); |
356 }, | 356 }, |
357 | 357 |
358 // | 358 // |
359 // nsISupports interface implementation | 359 // nsISupports interface implementation |
360 // | 360 // |
361 | 361 |
362 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver, | 362 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver, |
363 Ci.nsIChannelEventSink, Ci.nsIFactory, Ci.nsISupportsWeakReference]), | 363 Ci.nsIChannelEventSink, Ci.nsIFactory, Ci.nsISupportsWeakReference]), |
364 | 364 |
365 // | 365 // |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 if (!wnd || wnd.closed) | 678 if (!wnd || wnd.closed) |
679 return; | 679 return; |
680 | 680 |
681 if (entry.type == "OBJECT") | 681 if (entry.type == "OBJECT") |
682 { | 682 { |
683 node.removeEventListener("mouseover", objectMouseEventHander, true); | 683 node.removeEventListener("mouseover", objectMouseEventHander, true); |
684 node.removeEventListener("mouseout", objectMouseEventHander, true); | 684 node.removeEventListener("mouseout", objectMouseEventHander, true); |
685 } | 685 } |
686 Policy.processNode(wnd, node, entry.type, entry.location, true); | 686 Policy.processNode(wnd, node, entry.type, entry.location, true); |
687 } | 687 } |
OLD | NEW |