Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: background.js

Issue 29339034: Issue 3869 - Use the new FilterNotifier API (Closed)
Patch Set: Unsupport *.listen with null Created March 24, 2016, 2:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | messageResponder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 { 43 {
44 var listeners = this._listeners[name]; 44 var listeners = this._listeners[name];
45 if (listeners) 45 if (listeners)
46 { 46 {
47 for (var i = 0; i < listeners.length; i++) 47 for (var i = 0; i < listeners.length; i++)
48 listeners[i].apply(null, Array.prototype.slice.call(arguments, 1)); 48 listeners[i].apply(null, Array.prototype.slice.call(arguments, 1));
49 } 49 }
50 } 50 }
51 }; 51 };
52 52
53 function Notifier()
54 {
55 this._eventEmitter = new EventEmitter();
56 }
57 Notifier.prototype = {
58 addListener: function(listener)
59 {
60 var listeners = this._eventEmitter._listeners[""];
61 if (!listeners || listener.indexOf(listener) == -1)
62 this._eventEmitter.on("", listener);
63 },
64 removeListener: function(listener)
65 {
66 this._eventEmitter.off("", listener);
67 },
68 triggerListeners: function()
69 {
70 var args = Array.prototype.slice.apply(arguments);
71 args.unshift("");
72 this._eventEmitter.emit.apply(this._eventEmitter, args);
73 }
74 };
75
76 function updateFromURL(data) 53 function updateFromURL(data)
77 { 54 {
78 if (window.location.search) 55 if (window.location.search)
79 { 56 {
80 var params = window.location.search.substr(1).split("&"); 57 var params = window.location.search.substr(1).split("&");
81 for (var i = 0; i < params.length; i++) 58 for (var i = 0; i < params.length; i++)
82 { 59 {
83 var parts = params[i].split("=", 2); 60 var parts = params[i].split("=", 2);
84 if (parts.length == 2 && parts[0] in data) 61 if (parts.length == 2 && parts[0] in data)
85 data[parts[0]] = decodeURIComponent(parts[1]); 62 data[parts[0]] = decodeURIComponent(parts[1]);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 modules.prefs.Prefs.notifications_ignoredcategories = categories; 132 modules.prefs.Prefs.notifications_ignoredcategories = categories;
156 } 133 }
157 } 134 }
158 }; 135 };
159 136
160 modules.subscriptionClasses = { 137 modules.subscriptionClasses = {
161 Subscription: function(url) 138 Subscription: function(url)
162 { 139 {
163 this.url = url; 140 this.url = url;
164 this.title = "Subscription " + url; 141 this.title = "Subscription " + url;
165 this.disabled = false; 142 this._disabled = false;
166 this._lastDownload = 1234; 143 this._lastDownload = 1234;
167 this.homepage = "https://easylist.adblockplus.org/"; 144 this.homepage = "https://easylist.adblockplus.org/";
168 this.downloadStatus = params.downloadStatus; 145 this.downloadStatus = params.downloadStatus;
169 }, 146 },
170 147
171 SpecialSubscription: function(url) 148 SpecialSubscription: function(url)
172 { 149 {
173 this.url = url; 150 this.url = url;
174 this.disabled = false; 151 this.disabled = false;
175 this.filters = knownFilters.slice(); 152 this.filters = knownFilters.slice();
176 } 153 }
177 }; 154 };
178 modules.subscriptionClasses.Subscription.fromURL = function(url) 155 modules.subscriptionClasses.Subscription.fromURL = function(url)
179 { 156 {
180 if (url in knownSubscriptions) 157 if (url in knownSubscriptions)
181 return knownSubscriptions[url]; 158 return knownSubscriptions[url];
182 159
183 if (/^https?:\/\//.test(url)) 160 if (/^https?:\/\//.test(url))
184 return new modules.subscriptionClasses.Subscription(url); 161 return new modules.subscriptionClasses.Subscription(url);
185 else 162 else
186 return new modules.subscriptionClasses.SpecialSubscription(url); 163 return new modules.subscriptionClasses.SpecialSubscription(url);
187 }; 164 };
188 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription; 165 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription;
189 166
190 modules.subscriptionClasses.Subscription.prototype = 167 modules.subscriptionClasses.Subscription.prototype =
191 { 168 {
169 get disabled()
170 {
171 return this._disabled;
172 },
173 set disabled(value)
174 {
175 this._disabled = value;
176 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this);
177 },
192 get lastDownload() 178 get lastDownload()
193 { 179 {
194 return this._lastDownload; 180 return this._lastDownload;
195 }, 181 },
196 set lastDownload(value) 182 set lastDownload(value)
197 { 183 {
198 this._lastDownload = value; 184 this._lastDownload = value;
199 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.lastD ownload", this); 185 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload", th is);
200 } 186 }
201 }; 187 };
202 188
189
203 modules.filterStorage = { 190 modules.filterStorage = {
204 FilterStorage: { 191 FilterStorage: {
205 get subscriptions() 192 get subscriptions()
206 { 193 {
207 var subscriptions = []; 194 var subscriptions = [];
208 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) 195 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions)
209 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]); 196 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]);
210 return subscriptions; 197 return subscriptions;
211 }, 198 },
212 199
213 get knownSubscriptions() 200 get knownSubscriptions()
214 { 201 {
215 return knownSubscriptions; 202 return knownSubscriptions;
216 }, 203 },
217 204
218 addSubscription: function(subscription) 205 addSubscription: function(subscription)
219 { 206 {
220 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc riptions)) 207 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc riptions))
221 { 208 {
222 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub scription.fromURL(subscription.url); 209 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub scription.fromURL(subscription.url);
223 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a dded", subscription); 210 modules.filterNotifier.FilterNotifier.emit("subscription.added", subsc ription);
224 } 211 }
225 }, 212 },
226 213
227 removeSubscription: function(subscription) 214 removeSubscription: function(subscription)
228 { 215 {
229 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri ptions) 216 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri ptions)
230 { 217 {
231 delete knownSubscriptions[subscription.url]; 218 delete knownSubscriptions[subscription.url];
232 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r emoved", subscription); 219 modules.filterNotifier.FilterNotifier.emit("subscription.removed", sub scription);
233 } 220 }
234 }, 221 },
235 222
236 addFilter: function(filter) 223 addFilter: function(filter)
237 { 224 {
238 for (var i = 0; i < customSubscription.filters.length; i++) 225 for (var i = 0; i < customSubscription.filters.length; i++)
239 { 226 {
240 if (customSubscription.filters[i].text == filter.text) 227 if (customSubscription.filters[i].text == filter.text)
241 return; 228 return;
242 } 229 }
243 customSubscription.filters.push(filter); 230 customSubscription.filters.push(filter);
244 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", f ilter); 231 modules.filterNotifier.FilterNotifier.emit("filter.added", filter);
245 }, 232 },
246 233
247 removeFilter: function(filter) 234 removeFilter: function(filter)
248 { 235 {
249 for (var i = 0; i < customSubscription.filters.length; i++) 236 for (var i = 0; i < customSubscription.filters.length; i++)
250 { 237 {
251 if (customSubscription.filters[i].text == filter.text) 238 if (customSubscription.filters[i].text == filter.text)
252 { 239 {
253 customSubscription.filters.splice(i, 1); 240 customSubscription.filters.splice(i, 1);
254 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov ed", filter); 241 modules.filterNotifier.FilterNotifier.emit("filter.removed", filter) ;
255 return; 242 return;
256 } 243 }
257 } 244 }
258 } 245 }
259 } 246 }
260 }; 247 };
261 248
262 modules.filterClasses = { 249 modules.filterClasses = {
263 BlockingFilter: function() {}, 250 BlockingFilter: function() {},
264 Filter: function(text) 251 Filter: function(text)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 315 }
329 }; 316 };
330 317
331 modules.cssRules = { 318 modules.cssRules = {
332 CSSRules: { 319 CSSRules: {
333 getRulesForDomain: function(domain) { } 320 getRulesForDomain: function(domain) { }
334 } 321 }
335 }; 322 };
336 323
337 modules.filterNotifier = { 324 modules.filterNotifier = {
338 FilterNotifier: new Notifier() 325 FilterNotifier: new EventEmitter()
339 }; 326 };
340 327
341 modules.info = { 328 modules.info = {
342 platform: "gecko", 329 platform: "gecko",
343 platformVersion: "34.0", 330 platformVersion: "34.0",
344 application: "firefox", 331 application: "firefox",
345 applicationVersion: "34.0", 332 applicationVersion: "34.0",
346 addonName: "adblockplus", 333 addonName: "adblockplus",
347 addonVersion: "2.6.7" 334 addonVersion: "2.6.7"
348 }; 335 };
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 479
493 if (params.safariContentBlocker) 480 if (params.safariContentBlocker)
494 { 481 {
495 global.safari = { 482 global.safari = {
496 extension: { 483 extension: {
497 setContentBlocker: function() {} 484 setContentBlocker: function() {}
498 } 485 }
499 }; 486 };
500 } 487 }
501 })(this); 488 })(this);
OLDNEW
« no previous file with comments | « no previous file | messageResponder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld