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

Side by Side Diff: lib/prefs.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Rebased Created March 17, 2017, 12:41 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 | « lib/popupBlocker.js ('k') | lib/requestBlocker.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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 * @type {string} 109 * @type {string}
110 */ 110 */
111 defaults.notificationurl = "https://notification.adblockplus.org/notification.js on"; 111 defaults.notificationurl = "https://notification.adblockplus.org/notification.js on";
112 /** 112 /**
113 * The total number of requests blocked by the extension. 113 * The total number of requests blocked by the extension.
114 * 114 *
115 * @type {number} 115 * @type {number}
116 */ 116 */
117 defaults.blocked_total = 0; 117 defaults.blocked_total = 0;
118 /** 118 /**
119 * Whether to show a badge in the toolbar icon indicating the number of blocked ads. 119 * Whether to show a badge in the toolbar icon indicating the number
120 * of blocked ads.
120 * 121 *
121 * @type {boolean} 122 * @type {boolean}
122 */ 123 */
123 defaults.show_statsinicon = true; 124 defaults.show_statsinicon = true;
124 /** 125 /**
125 * Whether to show the number of blocked ads in the popup. 126 * Whether to show the number of blocked ads in the popup.
126 * 127 *
127 * @type {boolean} 128 * @type {boolean}
128 */ 129 */
129 defaults.show_statsinpopup = true; 130 defaults.show_statsinpopup = true;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 }, 254 },
254 enumerable: true 255 enumerable: true
255 }); 256 });
256 } 257 }
257 258
258 function init() 259 function init()
259 { 260 {
260 let prefs = Object.keys(defaults); 261 let prefs = Object.keys(defaults);
261 prefs.forEach(addPreference); 262 prefs.forEach(addPreference);
262 263
263 let localLoaded = new Promise(resolve => { 264 let localLoaded = new Promise(resolve =>
265 {
264 ext.storage.get(prefs.map(prefToKey), items => 266 ext.storage.get(prefs.map(prefToKey), items =>
265 { 267 {
266 for (let key in items) 268 for (let key in items)
267 overrides[keyToPref(key)] = items[key]; 269 overrides[keyToPref(key)] = items[key];
268 270
269 resolve(); 271 resolve();
270 }); 272 });
271 }); 273 });
272 274
273 let managedLoaded = new Promise(resolve => { 275 let managedLoaded = new Promise(resolve =>
276 {
274 if (require("info").platform == "chromium" && "managed" in chrome.storage) 277 if (require("info").platform == "chromium" && "managed" in chrome.storage)
275 { 278 {
276 chrome.storage.managed.get(null, items => 279 chrome.storage.managed.get(null, items =>
277 { 280 {
278 // Opera doesn't support chrome.storage.managed, but instead simply 281 // Opera doesn't support chrome.storage.managed, but instead simply
279 // removing the API, Opera sets chrome.runtime.lastError when using it. 282 // removing the API, Opera sets chrome.runtime.lastError when using it.
280 // So we have to retrieve that error, to prevent it from showing up 283 // So we have to retrieve that error, to prevent it from showing up
281 // in the console. 284 // in the console.
282 chrome.runtime.lastError; 285 chrome.runtime.lastError;
283 286
284 for (let key in items) 287 for (let key in items)
285 defaults[key] = items[key]; 288 defaults[key] = items[key];
286 289
287 resolve(); 290 resolve();
288 }); 291 });
289 } 292 }
290 else 293 else
291 {
292 resolve(); 294 resolve();
293 }
294 }); 295 });
295 296
296 function onLoaded() 297 function onLoaded()
297 { 298 {
298 ext.storage.onChanged.addListener(changes => 299 ext.storage.onChanged.addListener(changes =>
299 { 300 {
300 for (let key in changes) 301 for (let key in changes)
301 { 302 {
302 let pref = keyToPref(key); 303 let pref = keyToPref(key);
303 if (pref && pref in defaults) 304 if (pref && pref in defaults)
304 { 305 {
305 let change = changes[key]; 306 let change = changes[key];
306 if ("newValue" in change && change.newValue != defaults[pref]) 307 if ("newValue" in change && change.newValue != defaults[pref])
307 overrides[pref] = change.newValue; 308 overrides[pref] = change.newValue;
308 else 309 else
309 delete overrides[pref]; 310 delete overrides[pref];
310 311
311 eventEmitter.emit(pref); 312 eventEmitter.emit(pref);
312 } 313 }
313 } 314 }
314 }); 315 });
315 } 316 }
316 317
317 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); 318 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded);
318 } 319 }
319 320
320 init(); 321 init();
OLDNEW
« no previous file with comments | « lib/popupBlocker.js ('k') | lib/requestBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld