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 { | 20 { |
21 var ext = ext || require("ext_background"); | 21 if (typeof ext == "undefined") |
| 22 window.ext = require("ext_background"); |
22 | 23 |
23 const {port} = require("messaging"); | 24 const {port} = require("messaging"); |
24 const {Prefs} = require("prefs"); | 25 const {Prefs} = require("prefs"); |
25 const {Utils} = require("utils"); | 26 const {Utils} = require("utils"); |
26 const {FilterStorage} = require("filterStorage"); | 27 const {FilterStorage} = require("filterStorage"); |
27 const {FilterNotifier} = require("filterNotifier"); | 28 const {FilterNotifier} = require("filterNotifier"); |
28 const {defaultMatcher} = require("matcher"); | 29 const {defaultMatcher} = require("matcher"); |
29 const {ElemHideEmulation} = require("elemHideEmulation"); | 30 const {ElemHideEmulation} = require("elemHideEmulation"); |
30 const {Notification: NotificationStorage} = require("notification"); | 31 const {Notification: NotificationStorage} = require("notification"); |
31 | 32 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 obj.isDownloading = Synchronizer.isExecuting(subscription.url); | 72 obj.isDownloading = Synchronizer.isExecuting(subscription.url); |
72 return obj; | 73 return obj; |
73 } | 74 } |
74 | 75 |
75 let convertFilter = convertObject.bind(null, ["text"]); | 76 let convertFilter = convertObject.bind(null, ["text"]); |
76 | 77 |
77 let changeListeners = new ext.PageMap(); | 78 let changeListeners = new ext.PageMap(); |
78 let listenedPreferences = Object.create(null); | 79 let listenedPreferences = Object.create(null); |
79 let listenedFilterChanges = Object.create(null); | 80 let listenedFilterChanges = Object.create(null); |
80 let messageTypes = { | 81 let messageTypes = { |
81 "app": "app.respond", | 82 app: "app.respond", |
82 "filter": "filters.respond", | 83 filter: "filters.respond", |
83 "pref": "prefs.respond", | 84 pref: "prefs.respond", |
84 "subscription": "subscriptions.respond" | 85 subscription: "subscriptions.respond" |
85 }; | 86 }; |
86 | 87 |
87 function sendMessage(type, action) | 88 function sendMessage(type, action, ...args) |
88 { | 89 { |
89 let pages = changeListeners.keys(); | 90 let pages = changeListeners.keys(); |
90 if (pages.length == 0) | 91 if (pages.length == 0) |
91 return; | 92 return; |
92 | 93 |
93 let args = []; | 94 for (let i = 0; i < args.length; i++) |
94 for (let i = 2; i < arguments.length; i++) | |
95 { | 95 { |
96 let arg = arguments[i]; | 96 let arg = args[i]; |
97 if (arg instanceof Subscription) | 97 if (arg instanceof Subscription) |
98 args.push(convertSubscription(arg)); | 98 args[i] = convertSubscription(arg); |
99 else if (arg instanceof Filter) | 99 else if (arg instanceof Filter) |
100 args.push(convertFilter(arg)); | 100 args[i] = convertFilter(arg); |
101 else | |
102 args.push(arg); | |
103 } | 101 } |
104 | 102 |
105 for (let page of pages) | 103 for (let page of pages) |
106 { | 104 { |
107 let filters = changeListeners.get(page); | 105 let filters = changeListeners.get(page); |
108 let actions = filters[type]; | 106 let actions = filters[type]; |
109 if (actions && actions.indexOf(action) != -1) | 107 if (actions && actions.indexOf(action) != -1) |
110 { | 108 { |
111 page.sendMessage({ | 109 page.sendMessage({ |
112 type: messageTypes[type], | 110 type: messageTypes[type], |
113 action: action, | 111 action, |
114 args: args | 112 args |
115 }); | 113 }); |
116 } | 114 } |
117 } | 115 } |
118 } | 116 } |
119 | 117 |
120 function addFilterListeners(type, actions) | 118 function addFilterListeners(type, actions, ...args) |
121 { | 119 { |
122 for (let action of actions) | 120 for (let action of actions) |
123 { | 121 { |
124 let name; | 122 let name; |
125 if (type == "filter" && action == "loaded") | 123 if (type == "filter" && action == "loaded") |
126 name = "load"; | 124 name = "load"; |
127 else | 125 else |
128 name = type + "." + action; | 126 name = type + "." + action; |
129 | 127 |
130 if (!(name in listenedFilterChanges)) | 128 if (!(name in listenedFilterChanges)) |
131 { | 129 { |
132 listenedFilterChanges[name] = null; | 130 listenedFilterChanges[name] = null; |
133 FilterNotifier.on(name, function() | 131 FilterNotifier.on(name, () => |
134 { | 132 { |
135 let args = [type, action]; | 133 sendMessage(type, action, ...args); |
136 for (let arg of arguments) | |
137 args.push(arg); | |
138 sendMessage.apply(null, args); | |
139 }); | 134 }); |
140 } | 135 } |
141 } | 136 } |
142 } | 137 } |
143 | 138 |
144 function getListenerFilters(page) | 139 function getListenerFilters(page) |
145 { | 140 { |
146 let listenerFilters = changeListeners.get(page); | 141 let listenerFilters = changeListeners.get(page); |
147 if (!listenerFilters) | 142 if (!listenerFilters) |
148 { | 143 { |
149 listenerFilters = Object.create(null); | 144 listenerFilters = Object.create(null); |
150 changeListeners.set(page, listenerFilters); | 145 changeListeners.set(page, listenerFilters); |
151 } | 146 } |
152 return listenerFilters; | 147 return listenerFilters; |
153 } | 148 } |
154 | 149 |
155 port.on("app.get", (message, sender) => | 150 port.on("app.get", (message, sender) => |
156 { | 151 { |
157 if (message.what == "issues") | 152 if (message.what == "issues") |
158 { | 153 { |
159 let subscriptionInit = tryRequire("subscriptionInit"); | 154 let subscriptionInit = tryRequire("subscriptionInit"); |
160 return { | 155 return { |
161 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali
zed : false | 156 filterlistsReinitialized: subscriptionInit |
| 157 ? subscriptionInit.reinitialized : false |
162 }; | 158 }; |
163 } | 159 } |
164 | 160 |
165 if (message.what == "doclink") | 161 if (message.what == "doclink") |
166 return Utils.getDocLink(message.link); | 162 return Utils.getDocLink(message.link); |
167 | 163 |
168 if (message.what == "localeInfo") | 164 if (message.what == "localeInfo") |
169 { | 165 { |
170 let bidiDir; | 166 let bidiDir; |
171 if ("chromeRegistry" in Utils) | 167 if ("chromeRegistry" in Utils) |
172 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr
"; | 168 { |
| 169 let isRtl = Utils.chromeRegistry.isLocaleRTL("adblockplus"); |
| 170 bidiDir = isRtl ? "rtl" : "ltr"; |
| 171 } |
173 else | 172 else |
| 173 { |
174 bidiDir = ext.i18n.getMessage("@@bidi_dir"); | 174 bidiDir = ext.i18n.getMessage("@@bidi_dir"); |
| 175 } |
175 | 176 |
176 return {locale: Utils.appLocale, bidiDir: bidiDir}; | 177 return {locale: Utils.appLocale, bidiDir}; |
177 } | 178 } |
178 | 179 |
179 if (message.what == "features") | 180 if (message.what == "features") |
180 { | 181 { |
181 return { | 182 return { |
182 devToolsPanel: info.platform == "chromium" | 183 devToolsPanel: info.platform == "chromium" |
183 }; | 184 }; |
184 } | 185 } |
185 | 186 |
186 return info[message.what]; | 187 return info[message.what]; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 { | 223 { |
223 if (message.what == "elemhideemulation") | 224 if (message.what == "elemhideemulation") |
224 { | 225 { |
225 let filters = []; | 226 let filters = []; |
226 const {checkWhitelisted} = require("whitelisting"); | 227 const {checkWhitelisted} = require("whitelisting"); |
227 | 228 |
228 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, | 229 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, |
229 RegExpFilter.typeMap.DOCUMENT | | 230 RegExpFilter.typeMap.DOCUMENT | |
230 RegExpFilter.typeMap.ELEMHIDE)) | 231 RegExpFilter.typeMap.ELEMHIDE)) |
231 { | 232 { |
232 let hostname = sender.frame.url.hostname; | 233 let {hostname} = sender.frame.url; |
233 filters = ElemHideEmulation.getRulesForDomain(hostname); | 234 filters = ElemHideEmulation.getRulesForDomain(hostname); |
234 filters = filters.map(filter => | 235 filters = filters.map(filter => |
235 { | 236 { |
236 return { | 237 return { |
237 selector: filter.selector, | 238 selector: filter.selector, |
238 text: filter.text | 239 text: filter.text |
239 }; | 240 }; |
240 }); | 241 }); |
241 } | 242 } |
242 return filters; | 243 return filters; |
(...skipping 30 matching lines...) Expand all Loading... |
273 return errors; | 274 return errors; |
274 | 275 |
275 for (let subscription of FilterStorage.subscriptions) | 276 for (let subscription of FilterStorage.subscriptions) |
276 { | 277 { |
277 if (!(subscription instanceof SpecialSubscription)) | 278 if (!(subscription instanceof SpecialSubscription)) |
278 continue; | 279 continue; |
279 | 280 |
280 for (let j = subscription.filters.length - 1; j >= 0; j--) | 281 for (let j = subscription.filters.length - 1; j >= 0; j--) |
281 { | 282 { |
282 let filter = subscription.filters[j]; | 283 let filter = subscription.filters[j]; |
283 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) | 284 if (/^@@\|\|([^/:]+)\^\$document$/.test(filter.text)) |
284 continue; | 285 continue; |
285 | 286 |
286 if (!(filter.text in seenFilter)) | 287 if (!(filter.text in seenFilter)) |
287 FilterStorage.removeFilter(filter); | 288 FilterStorage.removeFilter(filter); |
288 } | 289 } |
289 } | 290 } |
290 | 291 |
291 return errors; | 292 return errors; |
292 }); | 293 }); |
293 | 294 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 ext.showOptions(() => | 353 ext.showOptions(() => |
353 { | 354 { |
354 sendMessage("app", "addSubscription", subscription); | 355 sendMessage("app", "addSubscription", subscription); |
355 }); | 356 }); |
356 } | 357 } |
357 else | 358 else |
358 { | 359 { |
359 subscription.disabled = false; | 360 subscription.disabled = false; |
360 FilterStorage.addSubscription(subscription); | 361 FilterStorage.addSubscription(subscription); |
361 | 362 |
362 if (subscription instanceof DownloadableSubscription && !subscription.last
Download) | 363 if (subscription instanceof DownloadableSubscription && |
| 364 !subscription.lastDownload) |
363 Synchronizer.execute(subscription); | 365 Synchronizer.execute(subscription); |
364 } | 366 } |
365 }); | 367 }); |
366 | 368 |
367 port.on("subscriptions.get", (message, sender) => | 369 port.on("subscriptions.get", (message, sender) => |
368 { | 370 { |
369 let subscriptions = FilterStorage.subscriptions.filter(s => | 371 let subscriptions = FilterStorage.subscriptions.filter(s => |
370 { | 372 { |
371 if (message.ignoreDisabled && s.disabled) | 373 if (message.ignoreDisabled && s.disabled) |
372 return false; | 374 return false; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 subscription.title = message.title; | 411 subscription.title = message.title; |
410 subscription.homepage = message.homepage; | 412 subscription.homepage = message.homepage; |
411 FilterStorage.addSubscription(subscription); | 413 FilterStorage.addSubscription(subscription); |
412 if (!subscription.lastDownload) | 414 if (!subscription.lastDownload) |
413 Synchronizer.execute(subscription); | 415 Synchronizer.execute(subscription); |
414 } | 416 } |
415 }); | 417 }); |
416 | 418 |
417 port.on("subscriptions.update", (message, sender) => | 419 port.on("subscriptions.update", (message, sender) => |
418 { | 420 { |
419 let subscriptions = message.url ? [Subscription.fromURL(message.url)] : | 421 let subscriptions = message.url ? [Subscription.fromURL(message.url)] |
420 FilterStorage.subscriptions; | 422 : FilterStorage.subscriptions; |
421 for (let subscription of subscriptions) | 423 for (let subscription of subscriptions) |
422 { | 424 { |
423 if (subscription instanceof DownloadableSubscription) | 425 if (subscription instanceof DownloadableSubscription) |
424 Synchronizer.execute(subscription, true); | 426 Synchronizer.execute(subscription, true); |
425 } | 427 } |
426 }); | 428 }); |
427 } | 429 } |
OLD | NEW |