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

Side by Side Diff: background.js

Issue 5923900886089728: Use FileSystem API to store data in Opera (Closed)
Patch Set: Better approach to prevent first-run page from appearing Created Nov. 26, 2013, 12:35 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 | lib/filesystem/io.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 <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 23 matching lines...) Expand all
34 var Synchronizer = require("synchronizer").Synchronizer; 34 var Synchronizer = require("synchronizer").Synchronizer;
35 var Utils = require("utils").Utils; 35 var Utils = require("utils").Utils;
36 var Notification = require("notification").Notification; 36 var Notification = require("notification").Notification;
37 37
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 var importingOldData = false;
44 require("filterNotifier").FilterNotifier.addListener(function(action) 45 require("filterNotifier").FilterNotifier.addListener(function(action)
45 { 46 {
46 if (action == "load") 47 if (action == "load")
47 { 48 {
48 importOldData(); 49 importOldData();
49 50
50 var addonVersion = require("info").addonVersion; 51 var addonVersion = require("info").addonVersion;
51 var prevVersion = localStorage["currentVersion"]; 52 var prevVersion = localStorage.currentVersion;
52 if (seenDataCorruption || prevVersion != addonVersion) 53 if (prevVersion != addonVersion)
53 { 54 {
54 isFirstRun = !prevVersion; 55 isFirstRun = !prevVersion;
55 localStorage["currentVersion"] = addonVersion; 56 localStorage.currentVersion = addonVersion;
56 addSubscription(prevVersion); 57 if (!importingOldData)
Thomas Greiner 2013/11/26 13:40:13 You're only using this variable for this check her
Wladimir Palant 2013/11/27 15:46:21 Done.
58 addSubscription(prevVersion);
57 } 59 }
58 } 60 }
59 }); 61 });
60 62
61 // Special-case domains for which we cannot use style-based hiding rules. 63 // Special-case domains for which we cannot use style-based hiding rules.
62 // See http://crbug.com/68705. 64 // See http://crbug.com/68705.
63 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 65 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
64 66
65 function removeDeprecatedOptions() 67 function removeDeprecatedOptions()
66 { 68 {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 149 }
148 150
149 /** 151 /**
150 * Old versions for Opera stored patterns.ini in the localStorage object, this 152 * Old versions for Opera stored patterns.ini in the localStorage object, this
151 * will import it into FilterStorage properly. 153 * will import it into FilterStorage properly.
152 */ 154 */
153 function importOldData() 155 function importOldData()
154 { 156 {
155 if ("patterns.ini" in localStorage) 157 if ("patterns.ini" in localStorage)
156 { 158 {
159 importingOldData = true;
157 FilterStorage.loadFromDisk(localStorage["patterns.ini"]); 160 FilterStorage.loadFromDisk(localStorage["patterns.ini"]);
158 seenDataCorruption = false;
159 161
160 var remove = []; 162 var remove = [];
161 for (var key in localStorage) 163 for (var key in localStorage)
162 if (key.indexOf("patterns.ini") == 0 || key.indexOf("patterns-backup") == 0) 164 if (key.indexOf("patterns.ini") == 0 || key.indexOf("patterns-backup") == 0)
163 remove.push(key); 165 remove.push(key);
164 for (var i = 0; i < remove.length; i++) 166 for (var i = 0; i < remove.length; i++)
165 delete localStorage[remove[i]]; 167 delete localStorage[remove[i]];
166 } 168 }
167 } 169 }
168 170
169 /** 171 /**
170 * This function is called on an extension update. It will add the default 172 * This function is called on an extension update. It will add the default
171 * filter subscription if necessary. 173 * filter subscription if necessary.
172 */ 174 */
173 function addSubscription(prevVersion) 175 function addSubscription(prevVersion)
174 { 176 {
175 // Make sure to remove "Recommended filters", no longer necessary 177 // Make sure to remove "Recommended filters", no longer necessary
176 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt"; 178 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt";
177 if (toRemove in FilterStorage.knownSubscriptions) 179 if (toRemove in FilterStorage.knownSubscriptions)
178 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ; 180 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ;
179 181
180 // Add "acceptable ads" subscription for new users 182 // Add "acceptable ads" subscription for new users
181 var addAcceptable = !prevVersion || seenDataCorruption; 183 var addAcceptable = !prevVersion;
182 if (addAcceptable) 184 if (addAcceptable)
183 { 185 {
184 addAcceptable = !FilterStorage.subscriptions.some(function(subscription) 186 addAcceptable = !FilterStorage.subscriptions.some(function(subscription)
185 { 187 {
186 return subscription.url == Prefs.subscriptions_exceptionsurl; 188 return subscription.url == Prefs.subscriptions_exceptionsurl;
187 }); 189 });
188 } 190 }
189 191
190 // Don't add subscription if the user has a subscription already 192 // Don't add subscription if the user has a subscription already
191 var addSubscription = !FilterStorage.subscriptions.some(function(subscription) 193 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"}); 458 tab.sendMessage({type: "clickhide-deactivate"});
457 refreshIconAndContextMenu(tab); 459 refreshIconAndContextMenu(tab);
458 }); 460 });
459 461
460 setTimeout(function() 462 setTimeout(function()
461 { 463 {
462 var notificationToShow = Notification.getNextToShow(); 464 var notificationToShow = Notification.getNextToShow();
463 if (notificationToShow) 465 if (notificationToShow)
464 showNotification(notificationToShow); 466 showNotification(notificationToShow);
465 }, 3 * 60 * 1000); 467 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | lib/filesystem/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld