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

Delta Between Two Patch Sets: background.js

Issue 5923900886089728: Use FileSystem API to store data in Opera (Closed)
Left Patch Set: Prevent first-run page from appearing Created Nov. 26, 2013, 8:48 a.m.
Right Patch Set: Fixed remaining comment Created Nov. 27, 2013, 3:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 27 matching lines...) Expand all
38 // Some types cannot be distinguished 38 // Some types cannot be distinguished
39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
40 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; 40 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER;
41 41
42 var isFirstRun = false; 42 var isFirstRun = false;
43 var seenDataCorruption = false; 43 var seenDataCorruption = false;
44 require("filterNotifier").FilterNotifier.addListener(function(action) 44 require("filterNotifier").FilterNotifier.addListener(function(action)
45 { 45 {
46 if (action == "load") 46 if (action == "load")
47 { 47 {
48 importOldData(); 48 var importingOldData = importOldData();
49 49
50 var addonVersion = require("info").addonVersion; 50 var addonVersion = require("info").addonVersion;
51 var prevVersion = localStorage["currentVersion"]; 51 var prevVersion = localStorage.currentVersion;
52 if (seenDataCorruption || prevVersion != addonVersion) 52 if (prevVersion != addonVersion)
53 { 53 {
54 isFirstRun = !prevVersion; 54 isFirstRun = !prevVersion;
55 localStorage["currentVersion"] = addonVersion; 55 localStorage.currentVersion = addonVersion;
56 addSubscription(prevVersion); 56 if (!importingOldData)
57 addSubscription(prevVersion);
57 } 58 }
58 } 59 }
59 }); 60 });
60 61
61 // Special-case domains for which we cannot use style-based hiding rules. 62 // Special-case domains for which we cannot use style-based hiding rules.
62 // See http://crbug.com/68705. 63 // See http://crbug.com/68705.
63 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 64 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
64 65
65 function removeDeprecatedOptions() 66 function removeDeprecatedOptions()
66 { 67 {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Set context menu status according to whether current tab has whitelisted domain 143 // Set context menu status according to whether current tab has whitelisted domain
143 if (excluded) 144 if (excluded)
144 chrome.contextMenus.removeAll(); 145 chrome.contextMenus.removeAll();
145 else 146 else
146 showContextMenu(); 147 showContextMenu();
147 } 148 }
148 149
149 /** 150 /**
150 * Old versions for Opera stored patterns.ini in the localStorage object, this 151 * Old versions for Opera stored patterns.ini in the localStorage object, this
151 * will import it into FilterStorage properly. 152 * will import it into FilterStorage properly.
153 * @return {Boolean} true if data import is in progress
152 */ 154 */
153 function importOldData() 155 function importOldData()
154 { 156 {
155 if ("patterns.ini" in localStorage) 157 if ("patterns.ini" in localStorage)
156 { 158 {
157 FilterStorage.loadFromDisk(localStorage["patterns.ini"]); 159 FilterStorage.loadFromDisk(localStorage["patterns.ini"]);
158 seenDataCorruption = false;
159 160
160 var remove = []; 161 var remove = [];
161 for (var key in localStorage) 162 for (var key in localStorage)
162 if (key.indexOf("patterns.ini") == 0 || key.indexOf("patterns-backup") == 0) 163 if (key.indexOf("patterns.ini") == 0 || key.indexOf("patterns-backup") == 0)
163 remove.push(key); 164 remove.push(key);
164 for (var i = 0; i < remove.length; i++) 165 for (var i = 0; i < remove.length; i++)
165 delete localStorage[remove[i]]; 166 delete localStorage[remove[i]];
166 } 167
168 return true;
169 }
170 else
171 return false;
167 } 172 }
168 173
169 /** 174 /**
170 * This function is called on an extension update. It will add the default 175 * This function is called on an extension update. It will add the default
171 * filter subscription if necessary. 176 * filter subscription if necessary.
172 */ 177 */
173 function addSubscription(prevVersion) 178 function addSubscription(prevVersion)
174 { 179 {
175 // Make sure to remove "Recommended filters", no longer necessary 180 // Make sure to remove "Recommended filters", no longer necessary
176 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt"; 181 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt";
177 if (toRemove in FilterStorage.knownSubscriptions) 182 if (toRemove in FilterStorage.knownSubscriptions)
178 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ; 183 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ;
179 184
180 // Add "acceptable ads" subscription for new users 185 // Add "acceptable ads" subscription for new users
181 var addAcceptable = !prevVersion || seenDataCorruption; 186 var addAcceptable = !prevVersion;
182 if (addAcceptable) 187 if (addAcceptable)
183 { 188 {
184 addAcceptable = !FilterStorage.subscriptions.some(function(subscription) 189 addAcceptable = !FilterStorage.subscriptions.some(function(subscription)
185 { 190 {
186 return subscription.url == Prefs.subscriptions_exceptionsurl; 191 return subscription.url == Prefs.subscriptions_exceptionsurl;
187 }); 192 });
188 } 193 }
189 194
190 // Don't add subscription if the user has a subscription already 195 // Don't add subscription if the user has a subscription already
191 var addSubscription = !FilterStorage.subscriptions.some(function(subscription) 196 var addSubscription = !FilterStorage.subscriptions.some(function(subscription)
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 tab.sendMessage({type: "clickhide-deactivate"}); 461 tab.sendMessage({type: "clickhide-deactivate"});
457 refreshIconAndContextMenu(tab); 462 refreshIconAndContextMenu(tab);
458 }); 463 });
459 464
460 setTimeout(function() 465 setTimeout(function()
461 { 466 {
462 var notificationToShow = Notification.getNextToShow(); 467 var notificationToShow = Notification.getNextToShow();
463 if (notificationToShow) 468 if (notificationToShow)
464 showNotification(notificationToShow); 469 showNotification(notificationToShow);
465 }, 3 * 60 * 1000); 470 }, 3 * 60 * 1000);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld