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: Addressed comment Created March 16, 2015, 12:53 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 var canUseChromeNotifications = require("info").platform == "chromium" 62 var canUseChromeNotifications = require("info").platform == "chromium"
63 && "notifications" in chrome 63 && "notifications" in chrome
64 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34); 64 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34);
65 65
66 var seenDataCorruption = false; 66 var seenDataCorruption = false;
67 var filterlistsReinitialized = false; 67 var filterlistsReinitialized = false;
68 require("filterNotifier").FilterNotifier.addListener(function(action) 68 require("filterNotifier").FilterNotifier.addListener(function(action)
69 { 69 {
70 if (action == "load") 70 if (action == "load")
71 { 71 {
72 var addonVersion = require("info").addonVersion; 72 ext.storage.get(["currentVersion"], function(items)
73 var prevVersion = ext.storage.currentVersion; 73 {
74 var addonVersion = require("info").addonVersion;
75 var prevVersion = items.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 prevVersion = null;
80 } 82 }
81 83
82 if (prevVersion != addonVersion || FilterStorage.firstRun) 84 if (prevVersion != addonVersion || FilterStorage.firstRun)
83 { 85 {
84 seenDataCorruption = prevVersion && FilterStorage.firstRun; 86 seenDataCorruption = prevVersion && FilterStorage.firstRun;
85 ext.storage.currentVersion = addonVersion; 87 ext.storage.set("currentVersion", addonVersion);
86 addSubscription(prevVersion); 88 addSubscription(prevVersion);
87 } 89 }
90
91 // The "Hide placeholders" option has been removed from the UI in 1.8.8.12 85
92 // So we reset the option for users updating from older versions.
93 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0)
94 Prefs.hidePlaceholders = true;
95 });
88 96
89 if (canUseChromeNotifications) 97 if (canUseChromeNotifications)
90 initChromeNotifications(); 98 initChromeNotifications();
91 initAntiAdblockNotification(); 99 initAntiAdblockNotification();
92
93 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285
94 // So we reset the option for users updating from older versions.
95 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0)
96 Prefs.hidePlaceholders = true;
97 } 100 }
98 101
99 // update browser actions when whitelisting might have changed, 102 // update browser actions when whitelisting might have changed,
100 // due to loading filters or saving filter changes 103 // due to loading filters or saving filter changes
101 if (action == "load" || action == "save") 104 if (action == "load" || action == "save")
102 refreshIconAndContextMenuForAllPages(); 105 refreshIconAndContextMenuForAllPages();
103 }); 106 });
104 107
105 // Special-case domains for which we cannot use style-based hiding rules. 108 // Special-case domains for which we cannot use style-based hiding rules.
106 // See http://crbug.com/68705. 109 // See http://crbug.com/68705.
107 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 110 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
108 111
109 var htmlPages = new ext.PageMap(); 112 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; 113 var activeNotification = null;
125 114
126 var contextMenuItem = { 115 var contextMenuItem = {
127 title: ext.i18n.getMessage("block_element"), 116 title: ext.i18n.getMessage("block_element"),
128 contexts: ["image", "video", "audio"], 117 contexts: ["image", "video", "audio"],
129 onclick: function(page) 118 onclick: function(page)
130 { 119 {
131 page.sendMessage({type: "clickhide-new-filter"}); 120 page.sendMessage({type: "clickhide-new-filter"});
132 } 121 }
133 }; 122 };
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 page.sendMessage({type: "clickhide-deactivate"}); 576 page.sendMessage({type: "clickhide-deactivate"});
588 refreshIconAndContextMenu(page); 577 refreshIconAndContextMenu(page);
589 }); 578 });
590 579
591 setTimeout(function() 580 setTimeout(function()
592 { 581 {
593 var notificationToShow = NotificationStorage.getNextToShow(); 582 var notificationToShow = NotificationStorage.getNextToShow();
594 if (notificationToShow) 583 if (notificationToShow)
595 showNotification(notificationToShow); 584 showNotification(notificationToShow);
596 }, 3 * 60 * 1000); 585 }, 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