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

Delta Between Two Patch Sets: background.js

Issue 29333819: Issue 2375 - Implement "Blocking lists" section in new options page (Closed)
Left Patch Set: Created Jan. 18, 2016, 9:50 a.m.
Right Patch Set: Fixed the progress indicator and small fixes Created Feb. 4, 2016, 5:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « README.md ('k') | i18n.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-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 *
(...skipping 15 matching lines...) Expand all
29 data[parts[0]] = decodeURIComponent(parts[1]); 29 data[parts[0]] = decodeURIComponent(parts[1]);
30 } 30 }
31 } 31 }
32 } 32 }
33 33
34 var params = { 34 var params = {
35 blockedURLs: "", 35 blockedURLs: "",
36 seenDataCorruption: false, 36 seenDataCorruption: false,
37 filterlistsReinitialized: false, 37 filterlistsReinitialized: false,
38 addSubscription: false, 38 addSubscription: false,
39 filterError: false 39 filterError: false,
40 downloadStatus: "synchronize_ok"
40 }; 41 };
41 updateFromURL(params); 42 updateFromURL(params);
42 43
43 var modules = {}; 44 var modules = {};
44 global.require = function(module) 45 global.require = function(module)
45 { 46 {
46 return modules[module]; 47 return modules[module];
47 }; 48 };
48 49
49 modules.utils = { 50 modules.utils = {
(...skipping 14 matching lines...) Expand all
64 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org /exceptionrules.txt" 65 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org /exceptionrules.txt"
65 } 66 }
66 }; 67 };
67 68
68 modules.subscriptionClasses = { 69 modules.subscriptionClasses = {
69 Subscription: function(url) 70 Subscription: function(url)
70 { 71 {
71 this.url = url; 72 this.url = url;
72 this.title = "Subscription " + url; 73 this.title = "Subscription " + url;
73 this.disabled = false; 74 this.disabled = false;
74 this.lastDownload = 1234; 75 this._lastDownload = 1234;
75 this.downloadStatus = "synchronize_ok"; 76 this.homepage = "https://easylist.adblockplus.org/";
77 this.downloadStatus = params.downloadStatus;
76 }, 78 },
77 79
78 SpecialSubscription: function(url) 80 SpecialSubscription: function(url)
79 { 81 {
80 this.url = url; 82 this.url = url;
81 this.disabled = false; 83 this.disabled = false;
82 this.filters = knownFilters.slice(); 84 this.filters = knownFilters.slice();
83 } 85 }
84 }; 86 };
85 modules.subscriptionClasses.Subscription.fromURL = function(url) 87 modules.subscriptionClasses.Subscription.fromURL = function(url)
86 { 88 {
87 if (url in knownSubscriptions) 89 if (url in knownSubscriptions)
88 return knownSubscriptions[url]; 90 return knownSubscriptions[url];
89 91
90 if (/^https?:\/\//.test(url)) 92 if (/^https?:\/\//.test(url))
91 return new modules.subscriptionClasses.Subscription(url); 93 return new modules.subscriptionClasses.Subscription(url);
92 else 94 else
93 return new modules.subscriptionClasses.SpecialSubscription(url); 95 return new modules.subscriptionClasses.SpecialSubscription(url);
94 }; 96 };
95 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription; 97 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription;
98
99 modules.subscriptionClasses.Subscription.prototype =
100 {
101 get lastDownload()
102 {
103 return this._lastDownload;
104 },
105 set lastDownload(value)
106 {
107 this._lastDownload = value;
108 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.lastD ownload", this);
109 }
110 };
96 111
97 modules.filterStorage = { 112 modules.filterStorage = {
98 FilterStorage: { 113 FilterStorage: {
99 get subscriptions() 114 get subscriptions()
100 { 115 {
101 var subscriptions = []; 116 var subscriptions = [];
102 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) 117 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions)
103 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]); 118 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]);
104 return subscriptions; 119 return subscriptions;
105 }, 120 },
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 filters: text.split("\n") 197 filters: text.split("\n")
183 .filter(function(filter) {return !!filter;}) 198 .filter(function(filter) {return !!filter;})
184 .map(modules.filterClasses.Filter.fromText), 199 .map(modules.filterClasses.Filter.fromText),
185 errors: [] 200 errors: []
186 }; 201 };
187 } 202 }
188 }; 203 };
189 204
190 modules.synchronizer = { 205 modules.synchronizer = {
191 Synchronizer: { 206 Synchronizer: {
207 downloading: false,
Thomas Greiner 2016/02/04 20:23:46 Detail: Since this is a "private" property I'd sug
192 execute: function(subscription, manual) 208 execute: function(subscription, manual)
193 { 209 {
194 subscription.lastDownload = Date.now() / 1000; 210 subscription.lastDownload = 0;
195 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.upd ated", subscription); 211 modules.synchronizer.Synchronizer.downloading = true;
Thomas Greiner 2016/01/19 11:27:26 Since you added error messages as part of this rev
saroyanm 2016/01/22 09:55:03 Done.
212 setTimeout(function()
213 {
214 modules.synchronizer.Synchronizer.downloading = false;
215 subscription.lastDownload = Date.now() / 1000;
216 }, 500);
217 },
218 isExecuting: function(url)
219 {
220 return modules.synchronizer.Synchronizer.downloading;
196 } 221 }
197 } 222 }
198 }; 223 };
199 224
200 modules.matcher = { 225 modules.matcher = {
201 defaultMatcher: { 226 defaultMatcher: {
202 matchesAny: function(url, requestType, docDomain, thirdParty) 227 matchesAny: function(url, requestType, docDomain, thirdParty)
203 { 228 {
204 var blocked = params.blockedURLs.split(","); 229 var blocked = params.blockedURLs.split(",");
205 if (blocked.indexOf(url) >= 0) 230 if (blocked.indexOf(url) >= 0)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 312
288 var subscriptions = [ 313 var subscriptions = [
289 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 314 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
290 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 315 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
291 "https://easylist-downloads.adblockplus.org/fanboy-social.txt", 316 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
292 "~user~786254" 317 "~user~786254"
293 ]; 318 ];
294 var knownSubscriptions = Object.create(null); 319 var knownSubscriptions = Object.create(null);
295 for (var subscriptionUrl of subscriptions) 320 for (var subscriptionUrl of subscriptions)
296 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl); 321 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl);
322
Thomas Greiner 2016/02/04 20:23:45 Detail: This empty line has been added without tou
297 var customSubscription = knownSubscriptions["~user~786254"]; 323 var customSubscription = knownSubscriptions["~user~786254"];
298 324
299 global.seenDataCorruption = params.seenDataCorruption; 325 global.seenDataCorruption = params.seenDataCorruption;
300 global.filterlistsReinitialized = params.filterlistsReinitialized; 326 global.filterlistsReinitialized = params.filterlistsReinitialized;
301 327
302 if (params.addSubscription) 328 if (params.addSubscription)
303 { 329 {
304 // We don't know how long it will take for the page to fully load 330 // We don't know how long it will take for the page to fully load
305 // so we'll post the message after one second 331 // so we'll post the message after one second
306 setTimeout(function() 332 setTimeout(function()
307 { 333 {
308 window.postMessage({ 334 window.postMessage({
309 type: "message", 335 type: "message",
310 payload: { 336 payload: {
311 title: "Custom subscription", 337 title: "Custom subscription",
312 url: "http://example.com/custom.txt", 338 url: "http://example.com/custom.txt",
313 type: "add-subscription" 339 type: "add-subscription"
314 } 340 }
315 }, "*"); 341 }, "*");
316 }, 1000); 342 }, 1000);
317 } 343 }
318 })(this); 344 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld