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: Removed menu item and fixed new linter error Created Aug. 28, 2017, 1:12 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 | « 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 let index = categories.indexOf(category); 129 let index = categories.indexOf(category);
129 if (index == -1) 130 if (index == -1)
130 categories.push(category); 131 categories.push(category);
131 else 132 else
132 categories.splice(index, 1); 133 categories.splice(index, 1);
133 modules.prefs.Prefs.notifications_ignoredcategories = categories; 134 modules.prefs.Prefs.notifications_ignoredcategories = categories;
134 } 135 }
135 } 136 }
136 }; 137 };
137 138
139 let subscriptionServer = "https://easylist-downloads.adblockplus.org";
140 let subscriptionDetails = {
141 [`${subscriptionServer}/easylistgermany+easylist.txt`]: {
142 title: "EasyList Germany+EasyList",
143 installed: true
144 },
145 [`${subscriptionServer}/exceptionrules.txt`]: {
146 title: "Allow non-intrusive advertising",
147 installed: true
148 },
149 [`${subscriptionServer}/exceptionrules-privacy.txt`]: {
150 title: "Allow only nonintrusive ads that are privacy-friendly"
151 },
152 [`${subscriptionServer}/fanboy-social.txt`]: {
153 title: "Fanboy's Social Blocking List",
154 installed: true
155 },
156 [`${subscriptionServer}/antiadblockfilters.txt`]: {
157 title: "Adblock Warning Removal List",
158 installed: true,
159 disabled: true
160 },
161 "~user~786254": {
162 installed: true
163 }
164 };
165
138 function Subscription(url) 166 function Subscription(url)
139 { 167 {
140 this.url = url; 168 this.url = url;
141 this._disabled = false; 169 this._disabled = false;
142 this._lastDownload = 1234; 170 this._lastDownload = 1234;
143 this.homepage = "https://easylist.adblockplus.org/"; 171 this.homepage = "https://easylist.adblockplus.org/";
144 this.downloadStatus = params.downloadStatus; 172 this.downloadStatus = params.downloadStatus;
145 173
146 if (subscriptions[this.url] && subscriptions[this.url].title) 174 let details = subscriptionDetails[this.url];
175 if (details)
147 { 176 {
148 this.title = subscriptions[this.url].title; 177 this.disabled = !!details.disabled;
149 } 178 this.title = details.title || "";
150 if (this.url == prefs.subscriptions_exceptionsurl_privacy)
151 {
152 this.title = "Allow only nonintrusive ads that are privacy-friendly";
153 } 179 }
154 } 180 }
155 Subscription.prototype = 181 Subscription.prototype =
156 { 182 {
157 get disabled() 183 get disabled()
158 { 184 {
159 return this._disabled; 185 return this._disabled;
160 }, 186 },
161 set disabled(value) 187 set disabled(value)
162 { 188 {
163 this._disabled = value; 189 this._disabled = value;
164 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this); 190 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this);
165 }, 191 },
166 get lastDownload() 192 get lastDownload()
167 { 193 {
168 return this._lastDownload; 194 return this._lastDownload;
169 }, 195 },
170 set lastDownload(value) 196 set lastDownload(value)
171 { 197 {
172 this._lastDownload = value; 198 this._lastDownload = value;
173 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload", 199 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload",
174 this); 200 this);
175 } 201 }
176 }; 202 };
177 Subscription.fromURL = function(url) 203 Subscription.fromURL = function(url)
178 { 204 {
179 if (url in knownSubscriptions) 205 if (url in knownSubscriptions)
180 return knownSubscriptions[url]; 206 return knownSubscriptions[url];
181 207
182 if (/^https?:\/\//.test(url)) 208 if (/^https?:\/\//.test(url))
183 return new modules.subscriptionClasses.Subscription(url); 209 return new modules.subscriptionClasses.Subscription(url);
184 return new modules.subscriptionClasses.SpecialSubscription(url); 210 return new modules.subscriptionClasses.SpecialSubscription(url);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 244
219 addSubscription(subscription) 245 addSubscription(subscription)
220 { 246 {
221 let {fromURL} = Subscription; 247 let {fromURL} = Subscription;
222 let {FilterStorage} = modules.filterStorage; 248 let {FilterStorage} = modules.filterStorage;
223 249
224 if (!(subscription.url in FilterStorage.knownSubscriptions)) 250 if (!(subscription.url in FilterStorage.knownSubscriptions))
225 { 251 {
226 knownSubscriptions[subscription.url] = fromURL(subscription.url); 252 knownSubscriptions[subscription.url] = fromURL(subscription.url);
227 modules.filterNotifier.FilterNotifier.emit("subscription.added", 253 modules.filterNotifier.FilterNotifier.emit("subscription.added",
228 subscription); 254 subscription);
229 } 255 }
230 }, 256 },
231 257
232 removeSubscription(subscription) 258 removeSubscription(subscription)
233 { 259 {
234 let {FilterStorage} = modules.filterStorage; 260 let {FilterStorage} = modules.filterStorage;
235 261
236 if (subscription.url in FilterStorage.knownSubscriptions) 262 if (subscription.url in FilterStorage.knownSubscriptions)
237 { 263 {
238 delete knownSubscriptions[subscription.url]; 264 delete knownSubscriptions[subscription.url];
239 modules.filterNotifier.FilterNotifier.emit("subscription.removed", 265 modules.filterNotifier.FilterNotifier.emit("subscription.removed",
240 subscription); 266 subscription);
241 } 267 }
242 }, 268 },
243 269
244 addFilter(filter) 270 addFilter(filter)
245 { 271 {
246 for (let customFilter of customSubscription.filters) 272 for (let customFilter of customSubscription.filters)
247 { 273 {
248 if (customFilter.text == filter.text) 274 if (customFilter.text == filter.text)
249 return; 275 return;
250 } 276 }
251 customSubscription.filters.push(filter); 277 customSubscription.filters.push(filter);
252 modules.filterNotifier.FilterNotifier.emit("filter.added", filter); 278 modules.filterNotifier.FilterNotifier.emit("filter.added", filter);
253 }, 279 },
254 280
255 removeFilter(filter) 281 removeFilter(filter)
256 { 282 {
257 for (let i = 0; i < customSubscription.filters.length; i++) 283 for (let i = 0; i < customSubscription.filters.length; i++)
258 { 284 {
259 if (customSubscription.filters[i].text == filter.text) 285 if (customSubscription.filters[i].text == filter.text)
260 { 286 {
261 customSubscription.filters.splice(i, 1); 287 customSubscription.filters.splice(i, 1);
262 modules.filterNotifier.FilterNotifier.emit("filter.removed", 288 modules.filterNotifier.FilterNotifier.emit("filter.removed",
263 filter); 289 filter);
264 return; 290 return;
265 } 291 }
266 } 292 }
267 } 293 }
268 } 294 }
269 }; 295 };
270 296
271 function Filter(text) 297 function Filter(text)
272 { 298 {
273 this.text = text; 299 this.text = text;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 "###Werbung_Sky", 467 "###Werbung_Sky",
442 "###Werbung_Wide", 468 "###Werbung_Wide",
443 "###__ligatus_placeholder__", 469 "###__ligatus_placeholder__",
444 "###ad-bereich1-08", 470 "###ad-bereich1-08",
445 "###ad-bereich1-superbanner", 471 "###ad-bereich1-superbanner",
446 "###ad-bereich2-08", 472 "###ad-bereich2-08",
447 "###ad-bereich2-skyscrapper" 473 "###ad-bereich2-skyscrapper"
448 ]; 474 ];
449 let knownFilters = filters.map(modules.filterClasses.Filter.fromText); 475 let knownFilters = filters.map(modules.filterClasses.Filter.fromText);
450 476
451 let subscriptions = { 477 let knownSubscriptions = Object.create(null);
452 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt": { 478 for (let url in subscriptionDetails)
453 title: "EasyList Germany+EasyList" 479 {
454 }, 480 if (!subscriptionDetails[url].installed)
455 "https://easylist-downloads.adblockplus.org/exceptionrules.txt": { 481 continue;
456 title: "Allow non-intrusive advertising"
457 },
458 "https://easylist-downloads.adblockplus.org/fanboy-social.txt": {
459 title: "Fanboy's Social Blocking List",
460 type: "social"
461 },
462 "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt": {
463 title: "Adblock Warning Removal List"
464 },
465 "~user~78625": {
466 title: "My filter list"
467 }
468 };
469 482
470 let knownSubscriptions = Object.create(null); 483 knownSubscriptions[url] =
471 for (let subscriptionUrl in subscriptions) 484 modules.subscriptionClasses.Subscription.fromURL(url);
472 {
473 knownSubscriptions[subscriptionUrl] =
474 modules.subscriptionClasses.Subscription.fromURL(subscriptionUrl);
475 } 485 }
476 let customSubscription = knownSubscriptions["~user~78625"]; 486 let customSubscription = knownSubscriptions["~user~786254"];
477 487
478 if (params.addSubscription) 488 if (params.addSubscription)
479 { 489 {
480 // We don't know how long it will take for the page to fully load 490 // We don't know how long it will take for the page to fully load
481 // so we'll post the message after one second 491 // so we'll post the message after one second
482 setTimeout(() => 492 setTimeout(() =>
483 { 493 {
484 window.postMessage({ 494 window.postMessage({
485 type: "message", 495 type: "message",
486 payload: { 496 payload: {
487 title: "Custom subscription", 497 title: "Custom subscription",
488 url: "http://example.com/custom.txt", 498 url: "http://example.com/custom.txt",
489 confirm: true, 499 confirm: true,
490 type: "subscriptions.add" 500 type: "subscriptions.add"
491 } 501 }
492 }, "*"); 502 }, "*");
493 }, 1000); 503 }, 1000);
494 } 504 }
495 505
506 if (params.showPageOptions)
507 {
508 // We don't know how long it will take for the page to fully load
509 // so we'll post the message after one second
510 setTimeout(() =>
511 {
512 let host = "example.com";
513 let isWhitelisted = customSubscription.filters
514 .some((filter) => filter.text == `@@||${host}^$document`);
515 window.postMessage({
516 type: "message",
517 payload: {
518 type: "app.open",
519 what: "options",
520 action: "showPageOptions",
521 args: [
522 {
523 host,
524 whitelisted: isWhitelisted
525 }
526 ]
527 }
528 }, "*");
529 }, 1000);
530 }
531
496 ext.devtools.onCreated.addListener((panel) => 532 ext.devtools.onCreated.addListener((panel) =>
497 { 533 {
498 // blocked request 534 // blocked request
499 panel.sendMessage({ 535 panel.sendMessage({
500 type: "add-record", 536 type: "add-record",
501 request: { 537 request: {
502 url: "http://adserver.example.com/ad_banner.png", 538 url: "http://adserver.example.com/ad_banner.png",
503 type: "IMAGE", 539 type: "IMAGE",
504 docDomain: "example.com" 540 docDomain: "example.com"
505 }, 541 },
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 }, 599 },
564 filter: { 600 filter: {
565 text: "||example.com/some-annoying-popup$popup", 601 text: "||example.com/some-annoying-popup$popup",
566 whitelisted: false, 602 whitelisted: false,
567 userDefined: true, 603 userDefined: true,
568 subscription: null 604 subscription: null
569 } 605 }
570 }); 606 });
571 }); 607 });
572 }()); 608 }());
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