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

Side by Side Diff: background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Patch Set: Fixed typo in variable name Created March 20, 2015, 3:36 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 | chrome/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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 29 matching lines...) Expand all
40 this.isThirdParty = isThirdParty; 40 this.isThirdParty = isThirdParty;
41 this.extractHostFromFrame = extractHostFromFrame; 41 this.extractHostFromFrame = extractHostFromFrame;
42 } 42 }
43 with(require("icon")) 43 with(require("icon"))
44 { 44 {
45 this.updateIcon = updateIcon; 45 this.updateIcon = updateIcon;
46 this.startIconAnimation = startIconAnimation; 46 this.startIconAnimation = startIconAnimation;
47 this.stopIconAnimation = stopIconAnimation; 47 this.stopIconAnimation = stopIconAnimation;
48 } 48 }
49 var FilterStorage = require("filterStorage").FilterStorage; 49 var FilterStorage = require("filterStorage").FilterStorage;
50 var FilterNotifier = require("filterNotifier").FilterNotifier;
50 var ElemHide = require("elemHide").ElemHide; 51 var ElemHide = require("elemHide").ElemHide;
51 var defaultMatcher = require("matcher").defaultMatcher; 52 var defaultMatcher = require("matcher").defaultMatcher;
52 var Prefs = require("prefs").Prefs; 53 var Prefs = require("prefs").Prefs;
53 var Synchronizer = require("synchronizer").Synchronizer; 54 var Synchronizer = require("synchronizer").Synchronizer;
54 var Utils = require("utils").Utils; 55 var Utils = require("utils").Utils;
55 var NotificationStorage = require("notification").Notification; 56 var NotificationStorage = require("notification").Notification;
56 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; 57 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication;
57 var parseFilters = require("filterValidation").parseFilters; 58 var parseFilters = require("filterValidation").parseFilters;
58 var composeFilters = require("filterComposer").composeFilters; 59 var composeFilters = require("filterComposer").composeFilters;
59 60
60 // Chrome on Linux does not fully support chrome.notifications until version 35
61 // https://code.google.com/p/chromium/issues/detail?id=291485
62 var canUseChromeNotifications = require("info").platform == "chromium"
63 && "notifications" in chrome
64 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34);
65
66 var seenDataCorruption = false; 61 var seenDataCorruption = false;
67 var filterlistsReinitialized = false; 62 var filterlistsReinitialized = false;
68 require("filterNotifier").FilterNotifier.addListener(function(action) 63
64 function init()
69 { 65 {
70 if (action == "load") 66 var filtersLoaded = false;
67 var prefsLoaded = false;
68
69 var onProgress = function()
71 { 70 {
72 var addonVersion = require("info").addonVersion; 71 if (!filtersLoaded || !prefsLoaded)
73 var prevVersion = ext.storage.currentVersion; 72 return;
73
74 var info = require("info");
75 var previousVersion = Prefs.currentVersion;
74 76
75 // There are no filters stored so we need to reinitialize all filterlists 77 // There are no filters stored so we need to reinitialize all filterlists
76 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) 78 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0)
77 { 79 {
78 filterlistsReinitialized = true; 80 filterlistsReinitialized = true;
79 prevVersion = null; 81 previousVersion = null;
80 } 82 }
81 83
82 if (prevVersion != addonVersion || FilterStorage.firstRun) 84 if (previousVersion != info.addonVersion || FilterStorage.firstRun)
83 { 85 {
84 seenDataCorruption = prevVersion && FilterStorage.firstRun; 86 seenDataCorruption = previousVersion && FilterStorage.firstRun;
85 ext.storage.currentVersion = addonVersion; 87 Prefs.currentVersion = info.addonVersion;
86 addSubscription(prevVersion); 88 addSubscription(previousVersion);
87 } 89 }
88 90
89 if (canUseChromeNotifications) 91 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285
92 // So we reset the option for users updating from older versions.
93 if (previousVersion && Services.vc.compare(previousVersion, "1.8.8.1285") < 0)
94 Prefs.hidePlaceholders = true;
95
96 // Chrome on Linux does not fully support chrome.notifications until version 35
97 // https://code.google.com/p/chromium/issues/detail?id=291485
98 if (info.platform == "chromium" && "notifications" in chrome &&
99 (navigator.platform.indexOf("Linux") == -1 ||
100 Services.vc.compare(info.applicationVersion, "35") >= 0))
90 initChromeNotifications(); 101 initChromeNotifications();
91 initAntiAdblockNotification(); 102 initAntiAdblockNotification();
92 103
93 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285 104 // Update browser actions and context menus when whitelisting might have
94 // So we reset the option for users updating from older versions. 105 // changed. That is now when initally loading the filters and later when
95 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0) 106 // importing backups or saving filter changes.
96 Prefs.hidePlaceholders = true; 107 FilterNotifier.addListener(function(action)
97 } 108 {
109 if (action == "load" || action == "save")
110 refreshIconAndContextMenuForAllPages();
111 });
112 refreshIconAndContextMenuForAllPages();
113 };
98 114
99 // update browser actions when whitelisting might have changed, 115 var onFilterAction = function(action)
100 // due to loading filters or saving filter changes 116 {
101 if (action == "load" || action == "save") 117 if (action == "load")
102 refreshIconAndContextMenuForAllPages(); 118 {
103 }); 119 FilterNotifier.removeListener(onFilterAction);
120 filtersLoaded = true;
121 onProgress();
122 }
123 };
124
125 var onPrefsLoaded = function()
126 {
127 Prefs.onLoaded.removeListener(onPrefsLoaded);
128 prefsLoaded = true;
129 onProgress();
130 };
131
132 FilterNotifier.addListener(onFilterAction);
133 Prefs.onLoaded.addListener(onPrefsLoaded);
134 }
135 init();
104 136
105 // Special-case domains for which we cannot use style-based hiding rules. 137 // Special-case domains for which we cannot use style-based hiding rules.
106 // See http://crbug.com/68705. 138 // See http://crbug.com/68705.
107 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 139 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
108 140
109 var htmlPages = new ext.PageMap(); 141 var htmlPages = new ext.PageMap();
110
111 function removeDeprecatedOptions()
112 {
113 var deprecatedOptions = ["specialCaseYouTube", "experimental", "disableInlineT extAds"];
114 deprecatedOptions.forEach(function(option)
115 {
116 if (option in ext.storage)
117 delete ext.storage[option];
118 });
119 }
120
121 // Remove deprecated options before we do anything else.
122 removeDeprecatedOptions();
123
124 var activeNotification = null; 142 var activeNotification = null;
125 143
126 var contextMenuItem = { 144 var contextMenuItem = {
127 title: ext.i18n.getMessage("block_element"), 145 title: ext.i18n.getMessage("block_element"),
128 contexts: ["image", "video", "audio"], 146 contexts: ["image", "video", "audio"],
129 onclick: function(page) 147 onclick: function(page)
130 { 148 {
131 page.sendMessage({type: "clickhide-new-filter"}); 149 page.sendMessage({type: "clickhide-new-filter"});
132 } 150 }
133 }; 151 };
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 265
248 notifyUser(); 266 notifyUser();
249 } 267 }
250 }, false); 268 }, false);
251 request.send(null); 269 request.send(null);
252 } 270 }
253 else 271 else
254 notifyUser(); 272 notifyUser();
255 } 273 }
256 274
257 Prefs.addListener(function(name) 275 Prefs.onChanged.addListener(function(name)
258 { 276 {
259 if (name == "shouldShowBlockElementMenu") 277 if (name == "shouldShowBlockElementMenu")
260 refreshIconAndContextMenuForAllPages(); 278 refreshIconAndContextMenuForAllPages();
261 }); 279 });
262 280
263 function prepareNotificationIconAndPopup() 281 function prepareNotificationIconAndPopup()
264 { 282 {
265 var animateIcon = (activeNotification.type !== "question"); 283 var animateIcon = (activeNotification.type !== "question");
266 activeNotification.onClicked = function() 284 activeNotification.onClicked = function()
267 { 285 {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 page.sendMessage({type: "clickhide-deactivate"}); 605 page.sendMessage({type: "clickhide-deactivate"});
588 refreshIconAndContextMenu(page); 606 refreshIconAndContextMenu(page);
589 }); 607 });
590 608
591 setTimeout(function() 609 setTimeout(function()
592 { 610 {
593 var notificationToShow = NotificationStorage.getNextToShow(); 611 var notificationToShow = NotificationStorage.getNextToShow();
594 if (notificationToShow) 612 if (notificationToShow)
595 showNotification(notificationToShow); 613 showNotification(notificationToShow);
596 }, 3 * 60 * 1000); 614 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | chrome/ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld