| 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 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 (function() | 20 (function() |
| 21 { | 21 { |
| 22 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 22 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
| 23 | 23 |
| 24 let {port} = require("messaging"); | 24 let {port} = require("messaging"); |
| 25 let {getFrames} = require("child/utils"); | 25 let {getFrames, isPrivate} = require("child/utils"); |
| 26 let {RequestNotifier} = require("child/requestNotifier"); | |
| 26 | 27 |
| 27 function getFilters(window, callback) | 28 function getFilters(window, callback) |
| 28 { | 29 { |
| 29 let message = { | 30 let message = { |
| 30 frames: getFrames(window), | 31 frames: getFrames(window), |
| 31 payload: { | 32 payload: { |
| 32 type: "filters.get", | 33 type: "filters.get", |
| 33 what: "cssproperties" | 34 what: "cssproperties" |
| 34 } | 35 } |
| 35 }; | 36 }; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 53 | 54 |
| 54 let onContentWindow = (subject, topic, data) => | 55 let onContentWindow = (subject, topic, data) => |
| 55 { | 56 { |
| 56 if (!(subject instanceof Ci.nsIDOMWindow)) | 57 if (!(subject instanceof Ci.nsIDOMWindow)) |
| 57 return; | 58 return; |
| 58 | 59 |
| 59 let onReady = event => | 60 let onReady = event => |
| 60 { | 61 { |
| 61 subject.removeEventListener("load", onReady); | 62 subject.removeEventListener("load", onReady); |
| 62 let handler = new scope.CSSPropertyFilters( | 63 let handler = new scope.CSSPropertyFilters( |
| 63 subject, getFilters.bind(null, subject), selectors => | 64 subject, getFilters.bind(null, subject), (selectors, filters) => |
| 64 { | 65 { |
| 65 if (selectors.length == 0) | 66 if (selectors.length == 0) |
| 66 return; | 67 return; |
| 67 | 68 |
| 68 addUserCSS(subject, selectors.map( | 69 addUserCSS(subject, selectors.map( |
| 69 selector => selector + "{display: none !important;}" | 70 selector => selector + "{display: none !important;}" |
| 70 ).join("\n")); | 71 ).join("\n")); |
| 72 | |
| 73 if (!isPrivate(subject)) | |
| 74 port.emit("addHits", filters); | |
| 75 | |
| 76 let docDomain = null; | |
| 77 try | |
| 78 { | |
| 79 // We are calling getFrames() here because it will consider | |
| 80 // "inheritance" for about:blank and data: frames. | |
| 81 docDomain = new URL(getFrames(subject)[0].location).hostname; | |
| 82 } | |
| 83 catch (e) | |
| 84 { | |
| 85 // Invalid URL? | |
|
saroyanm
2016/06/10 08:55:11
Detail: I'm not sure if this comment provides any
Wladimir Palant
2016/06/10 14:59:54
Well, eslint objects to empty catch clauses. In fa
| |
| 86 } | |
| 87 | |
| 88 for (let filter of filters) | |
| 89 { | |
| 90 RequestNotifier.addNodeData(subject.document, subject.top, { | |
| 91 contentType: "ELEMHIDE", | |
| 92 docDomain: docDomain, | |
| 93 thirdParty: false, | |
| 94 // TODO: Show the actual matching selector here? | |
|
saroyanm
2016/06/10 08:55:11
Detail: Feels like you forgot "TODO" Smth, or mayb
Wladimir Palant
2016/06/10 14:59:54
No, I meant to have this TODO comment here. Addres
saroyanm
2016/06/10 17:00:24
Acknowledged.
| |
| 95 location: filter.replace(/^.*?##/, ""), | |
|
saroyanm
2016/06/10 08:55:12
Why do we remove the URL part from the filter to a
Wladimir Palant
2016/06/10 14:59:54
hit.location is normally the address that the filt
saroyanm
2016/06/10 17:00:24
Acknowledged.
| |
| 96 filter: filter, | |
| 97 filterType: "cssproperty" | |
| 98 }); | |
| 99 } | |
| 71 } | 100 } |
| 72 ); | 101 ); |
| 73 | 102 |
| 74 handler.load(() => handler.apply()); | 103 handler.load(() => handler.apply()); |
| 75 }; | 104 }; |
| 76 | 105 |
| 77 subject.addEventListener("load", onReady); | 106 subject.addEventListener("load", onReady); |
| 78 }; | 107 }; |
| 79 | 108 |
| 80 Services.obs.addObserver(onContentWindow, "content-document-global-created", | 109 Services.obs.addObserver(onContentWindow, "content-document-global-created", |
| 81 false); | 110 false); |
| 82 onShutdown.add(() => | 111 onShutdown.add(() => |
| 83 { | 112 { |
| 84 Services.obs.removeObserver(onContentWindow, | 113 Services.obs.removeObserver(onContentWindow, |
| 85 "content-document-global-created"); | 114 "content-document-global-created"); |
| 86 }); | 115 }); |
| 87 } | 116 } |
| 88 | 117 |
| 89 initCSSPropertyFilters(); | 118 initCSSPropertyFilters(); |
| 90 })(); | 119 })(); |
| OLD | NEW |