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: Created Feb. 26, 2015, 12:59 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') | chrome/ext/background.js » ('J')
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 var canUseChromeNotifications = require("info").platform == "chromium" 66 var canUseChromeNotifications = require("info").platform == "chromium"
67 && "notifications" in chrome 67 && "notifications" in chrome
68 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34); 68 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34);
69 69
70 var seenDataCorruption = false; 70 var seenDataCorruption = false;
71 var filterlistsReinitialized = false; 71 var filterlistsReinitialized = false;
72 require("filterNotifier").FilterNotifier.addListener(function(action) 72 require("filterNotifier").FilterNotifier.addListener(function(action)
73 { 73 {
74 if (action == "load") 74 if (action == "load")
75 { 75 {
76 var addonVersion = require("info").addonVersion; 76 ext.storage.get(["currentVersion"], function(items)
77 var prevVersion = ext.storage.currentVersion; 77 {
78 var addonVersion = require("info").addonVersion;
79 var prevVersion = items.currentVersion;
78 80
79 // There are no filters stored so we need to reinitialize all filterlists 81 // There are no filters stored so we need to reinitialize all filterlists
80 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) 82 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0)
81 { 83 {
82 filterlistsReinitialized = true; 84 filterlistsReinitialized = true;
83 prevVersion = null; 85 prevVersion = null;
84 } 86 }
85 87
86 if (prevVersion != addonVersion || FilterStorage.firstRun) 88 if (prevVersion != addonVersion || FilterStorage.firstRun)
87 { 89 {
88 seenDataCorruption = prevVersion && FilterStorage.firstRun; 90 seenDataCorruption = prevVersion && FilterStorage.firstRun;
89 ext.storage.currentVersion = addonVersion; 91 ext.storage.set("currentVersion", addonVersion);
90 addSubscription(prevVersion); 92 addSubscription(prevVersion);
91 } 93 }
94
95 // The "Hide placeholders" option has been removed from the UI in 1.8.8.12 85
96 // So we reset the option for users updating from older versions.
97 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0)
98 Prefs.hidePlaceholders = true;
99 });
92 100
93 if (canUseChromeNotifications) 101 if (canUseChromeNotifications)
94 initChromeNotifications(); 102 initChromeNotifications();
95 initAntiAdblockNotification(); 103 initAntiAdblockNotification();
96
97 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285
98 // So we reset the option for users updating from older versions.
99 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0)
100 Prefs.hidePlaceholders = true;
101 } 104 }
102 105
103 // update browser actions when whitelisting might have changed, 106 // update browser actions when whitelisting might have changed,
104 // due to loading filters or saving filter changes 107 // due to loading filters or saving filter changes
105 if (action == "load" || action == "save") 108 if (action == "load" || action == "save")
106 refreshIconAndContextMenuForAllPages(); 109 refreshIconAndContextMenuForAllPages();
107 }); 110 });
108 111
109 // Special-case domains for which we cannot use style-based hiding rules. 112 // Special-case domains for which we cannot use style-based hiding rules.
110 // See http://crbug.com/68705. 113 // See http://crbug.com/68705.
111 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 114 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
112 115
113 var htmlPages = new ext.PageMap(); 116 var htmlPages = new ext.PageMap();
114
115 function removeDeprecatedOptions()
116 {
117 var deprecatedOptions = ["specialCaseYouTube", "experimental", "disableInlineT extAds"];
118 deprecatedOptions.forEach(function(option)
119 {
120 if (option in ext.storage)
121 delete ext.storage[option];
122 });
123 }
124
125 // Remove deprecated options before we do anything else.
126 removeDeprecatedOptions();
127
128 var activeNotification = null; 117 var activeNotification = null;
129 118
130 var contextMenuItem = { 119 var contextMenuItem = {
131 title: ext.i18n.getMessage("block_element"), 120 title: ext.i18n.getMessage("block_element"),
132 contexts: ["image", "video", "audio"], 121 contexts: ["image", "video", "audio"],
133 onclick: function(page) 122 onclick: function(page)
134 { 123 {
135 page.sendMessage({type: "clickhide-new-filter"}); 124 page.sendMessage({type: "clickhide-new-filter"});
136 } 125 }
137 }; 126 };
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 page.sendMessage({type: "clickhide-deactivate"}); 566 page.sendMessage({type: "clickhide-deactivate"});
578 refreshIconAndContextMenu(page); 567 refreshIconAndContextMenu(page);
579 }); 568 });
580 569
581 setTimeout(function() 570 setTimeout(function()
582 { 571 {
583 var notificationToShow = NotificationStorage.getNextToShow(); 572 var notificationToShow = NotificationStorage.getNextToShow();
584 if (notificationToShow) 573 if (notificationToShow)
585 showNotification(notificationToShow); 574 showNotification(notificationToShow);
586 }, 3 * 60 * 1000); 575 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | chrome/ext/background.js » ('j') | chrome/ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld