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

Side by Side Diff: background.js

Issue 29488575: Issue 5384 - Introduced dedicated mobile options page (Closed)
Patch Set: Fixed linter errors Created Aug. 28, 2017, 11:17 a.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 | « README.md ('k') | ext/background.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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 } 67 }
68 } 68 }
69 69
70 let params = { 70 let params = {
71 blockedURLs: "", 71 blockedURLs: "",
72 filterlistsReinitialized: false, 72 filterlistsReinitialized: false,
73 addSubscription: false, 73 addSubscription: false,
74 filterError: false, 74 filterError: false,
75 downloadStatus: "synchronize_ok", 75 downloadStatus: "synchronize_ok",
76 showNotificationUI: false 76 showNotificationUI: false,
77 showPageOptions: false
77 }; 78 };
78 updateFromURL(params); 79 updateFromURL(params);
79 80
80 let modules = {}; 81 let modules = {};
81 window.require = function(module) 82 window.require = function(module)
82 { 83 {
83 return modules[module]; 84 return modules[module];
84 }; 85 };
85 86
86 modules.utils = { 87 modules.utils = {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this); 155 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this);
155 }, 156 },
156 get lastDownload() 157 get lastDownload()
157 { 158 {
158 return this._lastDownload; 159 return this._lastDownload;
159 }, 160 },
160 set lastDownload(value) 161 set lastDownload(value)
161 { 162 {
162 this._lastDownload = value; 163 this._lastDownload = value;
163 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload", 164 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload",
164 this); 165 this);
165 } 166 }
166 }; 167 };
167 Subscription.fromURL = function(url) 168 Subscription.fromURL = function(url)
168 { 169 {
169 if (url in knownSubscriptions) 170 if (url in knownSubscriptions)
170 return knownSubscriptions[url]; 171 return knownSubscriptions[url];
171 172
172 if (/^https?:\/\//.test(url)) 173 if (/^https?:\/\//.test(url))
173 return new modules.subscriptionClasses.Subscription(url); 174 return new modules.subscriptionClasses.Subscription(url);
174 return new modules.subscriptionClasses.SpecialSubscription(url); 175 return new modules.subscriptionClasses.SpecialSubscription(url);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 209
209 addSubscription(subscription) 210 addSubscription(subscription)
210 { 211 {
211 let {fromURL} = Subscription; 212 let {fromURL} = Subscription;
212 let {FilterStorage} = modules.filterStorage; 213 let {FilterStorage} = modules.filterStorage;
213 214
214 if (!(subscription.url in FilterStorage.knownSubscriptions)) 215 if (!(subscription.url in FilterStorage.knownSubscriptions))
215 { 216 {
216 knownSubscriptions[subscription.url] = fromURL(subscription.url); 217 knownSubscriptions[subscription.url] = fromURL(subscription.url);
217 modules.filterNotifier.FilterNotifier.emit("subscription.added", 218 modules.filterNotifier.FilterNotifier.emit("subscription.added",
218 subscription); 219 subscription);
219 } 220 }
220 }, 221 },
221 222
222 removeSubscription(subscription) 223 removeSubscription(subscription)
223 { 224 {
224 let {FilterStorage} = modules.filterStorage; 225 let {FilterStorage} = modules.filterStorage;
225 226
226 if (subscription.url in FilterStorage.knownSubscriptions) 227 if (subscription.url in FilterStorage.knownSubscriptions)
227 { 228 {
228 delete knownSubscriptions[subscription.url]; 229 delete knownSubscriptions[subscription.url];
229 modules.filterNotifier.FilterNotifier.emit("subscription.removed", 230 modules.filterNotifier.FilterNotifier.emit("subscription.removed",
230 subscription); 231 subscription);
231 } 232 }
232 }, 233 },
233 234
234 addFilter(filter) 235 addFilter(filter)
235 { 236 {
236 for (let customFilter of customSubscription.filters) 237 for (let customFilter of customSubscription.filters)
237 { 238 {
238 if (customFilter.text == filter.text) 239 if (customFilter.text == filter.text)
239 return; 240 return;
240 } 241 }
241 customSubscription.filters.push(filter); 242 customSubscription.filters.push(filter);
242 modules.filterNotifier.FilterNotifier.emit("filter.added", filter); 243 modules.filterNotifier.FilterNotifier.emit("filter.added", filter);
243 }, 244 },
244 245
245 removeFilter(filter) 246 removeFilter(filter)
246 { 247 {
247 for (let i = 0; i < customSubscription.filters.length; i++) 248 for (let i = 0; i < customSubscription.filters.length; i++)
248 { 249 {
249 if (customSubscription.filters[i].text == filter.text) 250 if (customSubscription.filters[i].text == filter.text)
250 { 251 {
251 customSubscription.filters.splice(i, 1); 252 customSubscription.filters.splice(i, 1);
252 modules.filterNotifier.FilterNotifier.emit("filter.removed", 253 modules.filterNotifier.FilterNotifier.emit("filter.removed",
253 filter); 254 filter);
254 return; 255 return;
255 } 256 }
256 } 257 }
257 } 258 }
258 } 259 }
259 }; 260 };
260 261
261 function Filter(text) 262 function Filter(text)
262 { 263 {
263 this.text = text; 264 this.text = text;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 "###Werbung_Sky", 432 "###Werbung_Sky",
432 "###Werbung_Wide", 433 "###Werbung_Wide",
433 "###__ligatus_placeholder__", 434 "###__ligatus_placeholder__",
434 "###ad-bereich1-08", 435 "###ad-bereich1-08",
435 "###ad-bereich1-superbanner", 436 "###ad-bereich1-superbanner",
436 "###ad-bereich2-08", 437 "###ad-bereich2-08",
437 "###ad-bereich2-skyscrapper" 438 "###ad-bereich2-skyscrapper"
438 ]; 439 ];
439 let knownFilters = filters.map(modules.filterClasses.Filter.fromText); 440 let knownFilters = filters.map(modules.filterClasses.Filter.fromText);
440 441
442 let subscriptionServer = "https://easylist-downloads.adblockplus.org";
441 let subscriptions = [ 443 let subscriptions = [
442 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 444 {
443 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 445 title: "EasyList Germany+EasyList",
444 "https://easylist-downloads.adblockplus.org/fanboy-social.txt", 446 url: `${subscriptionServer}/easylistgermany+easylist.txt`
445 "~user~786254" 447 },
448 {
449 title: "Allow non-intrusive advertising",
450 url: `${subscriptionServer}/exceptionrules.txt`
451 },
452 {
453 title: "Fanboy's Social Blocking List",
454 url: `${subscriptionServer}/fanboy-social.txt`
455 },
456 {
457 title: null,
458 url: "~user~786254"
459 }
446 ]; 460 ];
447 let knownSubscriptions = Object.create(null); 461 let knownSubscriptions = Object.create(null);
448 for (let subscriptionUrl of subscriptions) 462 for (let {title, url} of subscriptions)
449 { 463 {
450 knownSubscriptions[subscriptionUrl] = 464 let subscription =
451 modules.subscriptionClasses.Subscription.fromURL(subscriptionUrl); 465 modules.subscriptionClasses.Subscription.fromURL(url);
466 subscription.title = title;
467 knownSubscriptions[url] = subscription;
452 } 468 }
453 let customSubscription = knownSubscriptions["~user~786254"]; 469 let customSubscription = knownSubscriptions["~user~786254"];
454 470
455 if (params.addSubscription) 471 if (params.addSubscription)
456 { 472 {
457 // We don't know how long it will take for the page to fully load 473 // We don't know how long it will take for the page to fully load
458 // so we'll post the message after one second 474 // so we'll post the message after one second
459 setTimeout(() => 475 setTimeout(() =>
460 { 476 {
461 window.postMessage({ 477 window.postMessage({
462 type: "message", 478 type: "message",
463 payload: { 479 payload: {
464 title: "Custom subscription", 480 title: "Custom subscription",
465 url: "http://example.com/custom.txt", 481 url: "http://example.com/custom.txt",
466 confirm: true, 482 confirm: true,
467 type: "subscriptions.add" 483 type: "subscriptions.add"
468 } 484 }
469 }, "*"); 485 }, "*");
470 }, 1000); 486 }, 1000);
471 } 487 }
472 488
489 if (params.showPageOptions)
490 {
491 // We don't know how long it will take for the page to fully load
492 // so we'll post the message after one second
493 setTimeout(() =>
494 {
495 let host = "example.com";
496 let isWhitelisted = customSubscription.filters
497 .some((filter) => filter.text == `@@||${host}^$document`);
498 window.postMessage({
499 type: "message",
500 payload: {
501 type: "app.open",
502 what: "options",
503 action: "showPageOptions",
504 args: [
505 {
506 host,
507 whitelisted: isWhitelisted
508 }
509 ]
510 }
511 }, "*");
512 }, 1000);
513 }
514
473 ext.devtools.onCreated.addListener((panel) => 515 ext.devtools.onCreated.addListener((panel) =>
474 { 516 {
475 // blocked request 517 // blocked request
476 panel.sendMessage({ 518 panel.sendMessage({
477 type: "add-record", 519 type: "add-record",
478 request: { 520 request: {
479 url: "http://adserver.example.com/ad_banner.png", 521 url: "http://adserver.example.com/ad_banner.png",
480 type: "IMAGE", 522 type: "IMAGE",
481 docDomain: "example.com" 523 docDomain: "example.com"
482 }, 524 },
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 }, 582 },
541 filter: { 583 filter: {
542 text: "||example.com/some-annoying-popup$popup", 584 text: "||example.com/some-annoying-popup$popup",
543 whitelisted: false, 585 whitelisted: false,
544 userDefined: true, 586 userDefined: true,
545 subscription: null 587 subscription: null
546 } 588 }
547 }); 589 });
548 }); 590 });
549 }()); 591 }());
OLDNEW
« no previous file with comments | « README.md ('k') | ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld