| 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-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 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 data = {payload: data, frames: getFrames(senderWindow)}; | 34 data = {payload: data, frames: getFrames(senderWindow)}; |
| 35 if (typeof callback == "function") | 35 if (typeof callback == "function") |
| 36 port.emitWithResponse("cssPropertiesRequest", data).then(callback); | 36 port.emitWithResponse("cssPropertiesRequest", data).then(callback); |
| 37 else | 37 else |
| 38 port.emit("cssPropertiesRequest", data); | 38 port.emit("cssPropertiesRequest", data); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 function loadScript(script) | |
|
Thomas Greiner
2016/03/30 18:02:05
Detail: This function seems redundant since it's o
Wladimir Palant
2016/03/30 18:42:17
The idea was originally that this would be a gener
| |
| 45 { | |
| 46 Services.scriptloader.loadSubScript(script, scope); | |
| 47 } | |
| 48 | |
| 49 function addUserCSS(window, cssCode) | 44 function addUserCSS(window, cssCode) |
| 50 { | 45 { |
| 51 let uri = Services.io.newURI("data:text/css," + encodeURIComponent(cssCode), | 46 let uri = Services.io.newURI("data:text/css," + encodeURIComponent(cssCode), |
| 52 null, null); | 47 null, null); |
| 53 let utils = window.QueryInterface(Ci.nsIInterfaceRequestor) | 48 let utils = window.QueryInterface(Ci.nsIInterfaceRequestor) |
| 54 .getInterface(Ci.nsIDOMWindowUtils); | 49 .getInterface(Ci.nsIDOMWindowUtils); |
| 55 utils.loadSheet(uri, Ci.nsIDOMWindowUtils.USER_SHEET); | 50 utils.loadSheet(uri, Ci.nsIDOMWindowUtils.USER_SHEET); |
| 56 } | 51 } |
| 57 | 52 |
| 58 function initCSSPropertyFilters() | 53 function initCSSPropertyFilters() |
| 59 { | 54 { |
| 60 loadScript("chrome://adblockplus/content/cssProperties.js"); | 55 Services.scriptloader.loadSubScript( |
| 56 "chrome://adblockplus/content/cssProperties.js", scope); | |
| 61 | 57 |
| 62 let onContentWindow = (subject, topic, data) => | 58 let onContentWindow = (subject, topic, data) => |
| 63 { | 59 { |
| 64 if (!(subject instanceof Ci.nsIDOMWindow)) | 60 if (!(subject instanceof Ci.nsIDOMWindow)) |
| 65 return; | 61 return; |
| 66 | 62 |
| 67 let onReady = event => | 63 let onReady = event => |
| 68 { | 64 { |
| 69 subject.removeEventListener("DOMContentLoaded", onReady); | 65 subject.removeEventListener("DOMContentLoaded", onReady); |
| 70 let handler = new scope.CSSPropertyFilters(subject, selectors => | 66 let handler = new scope.CSSPropertyFilters(subject, selectors => |
| 71 { | 67 { |
| 72 if (selectors.length == 0) | 68 if (selectors.length == 0) |
| 73 return; | 69 return; |
| 74 | 70 |
| 75 addUserCSS(subject, selectors.map( | 71 addUserCSS(subject, selectors.map( |
| 76 selector => selector + "{display: none !important;}" | 72 selector => selector + "{display: none !important;}" |
| 77 ).join("\n")); | 73 ).join("\n")); |
| 78 }); | 74 }); |
| 79 | 75 |
| 80 // HACK: The content script just calls ext.backgroundPage.sendMessage | 76 // HACK: The content script just calls ext.backgroundPage.sendMessage |
| 81 // without indicating which window this is about. We'll store the window | 77 // without indicating which window this is about. We'll store the window |
| 82 // here because we know that messaging happens synchronously. | 78 // here because we know that messaging happens synchronously. |
|
Wladimir Palant
2016/03/18 15:25:24
This is rather ugly. While we made CSSPropertyFilt
Thomas Greiner
2016/03/30 18:02:05
Can't think of a better alternative than passing a
Wladimir Palant
2016/03/30 18:42:17
Yes, we'll need to fix this later.
| |
| 83 senderWindow = subject; | 79 senderWindow = subject; |
| 84 handler.load(() => handler.apply()); | 80 handler.load(() => handler.apply()); |
| 85 senderWindow = null; | 81 senderWindow = null; |
| 86 }; | 82 }; |
| 87 | 83 |
| 88 subject.addEventListener("DOMContentLoaded", onReady); | 84 subject.addEventListener("DOMContentLoaded", onReady); |
| 89 }; | 85 }; |
| 90 | 86 |
| 91 Services.obs.addObserver(onContentWindow, "content-document-global-created", | 87 Services.obs.addObserver(onContentWindow, "content-document-global-created", |
| 92 false); | 88 false); |
| 93 onShutdown.add(() => | 89 onShutdown.add(() => |
| 94 { | 90 { |
| 95 Services.obs.removeObserver(onContentWindow, | 91 Services.obs.removeObserver(onContentWindow, |
| 96 "content-document-global-created"); | 92 "content-document-global-created"); |
| 97 }); | 93 }); |
| 98 } | 94 } |
| 99 | 95 |
| 100 initCSSPropertyFilters(); | 96 initCSSPropertyFilters(); |
| 101 })(); | 97 })(); |
| LEFT | RIGHT |