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-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 |
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 /** | 18 /** |
19 * @fileOverview Component synchronizing filter storage with Matcher instances a nd ElemHide. | 19 * @fileOverview Component synchronizing filter storage with Matcher instances a nd ElemHide. |
20 */ | 20 */ |
21 | 21 |
22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
23 Cu.import("resource://gre/modules/Services.jsm"); | 23 Cu.import("resource://gre/modules/Services.jsm"); |
24 | 24 |
25 let {FilterStorage} = require("filterStorage"); | 25 let {FilterStorage} = require("filterStorage"); |
26 let {FilterNotifier} = require("filterNotifier"); | 26 let {FilterNotifier} = require("filterNotifier"); |
27 let {ElemHide} = require("elemHide"); | 27 let {ElemHide} = require("elemHide"); |
28 let {CSSRules} = require("cssRules"); | |
28 let {defaultMatcher} = require("matcher"); | 29 let {defaultMatcher} = require("matcher"); |
29 let {ActiveFilter, RegExpFilter, ElemHideBase} = require("filterClasses"); | 30 let {ActiveFilter, RegExpFilter, ElemHideBase, CSSPropertyFilter} = |
31 require("filterClasses"); | |
Wladimir Palant
2015/11/05 12:46:19
Nit: While I couldn't find anything in our style g
Thomas Greiner
2015/11/25 11:20:00
Done. I looked through our code and unfortunately,
| |
30 let {Prefs} = require("prefs"); | 32 let {Prefs} = require("prefs"); |
31 | 33 |
32 /** | 34 /** |
33 * Value of the FilterListener.batchMode property. | 35 * Value of the FilterListener.batchMode property. |
34 * @type Boolean | 36 * @type Boolean |
35 */ | 37 */ |
36 let batchMode = false; | 38 let batchMode = false; |
37 | 39 |
38 /** | 40 /** |
39 * Increases on filter changes, filters will be saved if it exceeds 1. | 41 * Increases on filter changes, filters will be saved if it exceeds 1. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 let hasEnabled = false; | 151 let hasEnabled = false; |
150 for (let i = 0; i < filter.subscriptions.length; i++) | 152 for (let i = 0; i < filter.subscriptions.length; i++) |
151 if (!filter.subscriptions[i].disabled) | 153 if (!filter.subscriptions[i].disabled) |
152 hasEnabled = true; | 154 hasEnabled = true; |
153 if (!hasEnabled) | 155 if (!hasEnabled) |
154 return; | 156 return; |
155 | 157 |
156 if (filter instanceof RegExpFilter) | 158 if (filter instanceof RegExpFilter) |
157 defaultMatcher.add(filter); | 159 defaultMatcher.add(filter); |
158 else if (filter instanceof ElemHideBase) | 160 else if (filter instanceof ElemHideBase) |
159 ElemHide.add(filter); | 161 { |
162 if (filter instanceof CSSPropertyFilter) | |
163 CSSRules.add(filter); | |
164 else | |
165 ElemHide.add(filter); | |
166 } | |
160 } | 167 } |
161 | 168 |
162 /** | 169 /** |
163 * Notifies Matcher instances or ElemHide object about removal of a filter | 170 * Notifies Matcher instances or ElemHide object about removal of a filter |
164 * if necessary. | 171 * if necessary. |
165 * @param {Filter} filter filter that has been removed | 172 * @param {Filter} filter filter that has been removed |
166 */ | 173 */ |
167 function removeFilter(filter) | 174 function removeFilter(filter) |
168 { | 175 { |
169 if (!(filter instanceof ActiveFilter)) | 176 if (!(filter instanceof ActiveFilter)) |
170 return; | 177 return; |
171 | 178 |
172 if (!filter.disabled) | 179 if (!filter.disabled) |
173 { | 180 { |
174 let hasEnabled = false; | 181 let hasEnabled = false; |
175 for (let i = 0; i < filter.subscriptions.length; i++) | 182 for (let i = 0; i < filter.subscriptions.length; i++) |
176 if (!filter.subscriptions[i].disabled) | 183 if (!filter.subscriptions[i].disabled) |
177 hasEnabled = true; | 184 hasEnabled = true; |
178 if (hasEnabled) | 185 if (hasEnabled) |
179 return; | 186 return; |
180 } | 187 } |
181 | 188 |
182 if (filter instanceof RegExpFilter) | 189 if (filter instanceof RegExpFilter) |
183 defaultMatcher.remove(filter); | 190 defaultMatcher.remove(filter); |
184 else if (filter instanceof ElemHideBase) | 191 else if (filter instanceof ElemHideBase) |
185 ElemHide.remove(filter); | 192 { |
193 if (filter instanceof CSSPropertyFilter) | |
194 CSSRules.remove(filter); | |
195 else | |
196 ElemHide.remove(filter); | |
197 } | |
186 } | 198 } |
187 | 199 |
188 /** | 200 /** |
189 * Subscription change listener | 201 * Subscription change listener |
190 */ | 202 */ |
191 function onSubscriptionChange(action, subscription, newValue, oldValue) | 203 function onSubscriptionChange(action, subscription, newValue, oldValue) |
192 { | 204 { |
193 FilterListener.setDirty(1); | 205 FilterListener.setDirty(1); |
194 | 206 |
195 if (action != "added" && action != "removed" && action != "disabled" && action != "updated") | 207 if (action != "added" && action != "removed" && action != "disabled" && action != "updated") |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 * Generic notification listener | 269 * Generic notification listener |
258 */ | 270 */ |
259 function onGenericChange(action) | 271 function onGenericChange(action) |
260 { | 272 { |
261 if (action == "load") | 273 if (action == "load") |
262 { | 274 { |
263 isDirty = 0; | 275 isDirty = 0; |
264 | 276 |
265 defaultMatcher.clear(); | 277 defaultMatcher.clear(); |
266 ElemHide.clear(); | 278 ElemHide.clear(); |
279 CSSRules.clear(); | |
267 for (let subscription of FilterStorage.subscriptions) | 280 for (let subscription of FilterStorage.subscriptions) |
268 if (!subscription.disabled) | 281 if (!subscription.disabled) |
269 subscription.filters.forEach(addFilter); | 282 subscription.filters.forEach(addFilter); |
270 flushElemHide(); | 283 flushElemHide(); |
271 } | 284 } |
272 else if (action == "save") | 285 else if (action == "save") |
273 isDirty = 0; | 286 isDirty = 0; |
274 } | 287 } |
OLD | NEW |