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

Side by Side Diff: background.js

Issue 5719985141841920: issue #331 - Remove localStorage to FileSystem migration code (Closed)
Patch Set: Created Aug. 14, 2014, 11:03 a.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 | no next file » | 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-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 var canUseChromeNotifications = require("info").platform == "chromium" 52 var canUseChromeNotifications = require("info").platform == "chromium"
53 && "notifications" in chrome 53 && "notifications" in chrome
54 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion) > 34); 54 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion) > 34);
55 55
56 var seenDataCorruption = false; 56 var seenDataCorruption = false;
57 var filterlistsReinitialized = false; 57 var filterlistsReinitialized = false;
58 require("filterNotifier").FilterNotifier.addListener(function(action) 58 require("filterNotifier").FilterNotifier.addListener(function(action)
59 { 59 {
60 if (action == "load") 60 if (action == "load")
61 { 61 {
62 var importingOldData = importOldData();
63
64 var addonVersion = require("info").addonVersion; 62 var addonVersion = require("info").addonVersion;
65 var prevVersion = ext.storage.currentVersion; 63 var prevVersion = ext.storage.currentVersion;
66 64
67 // There are no filters stored so we need to reinitialize all filterlists 65 // There are no filters stored so we need to reinitialize all filterlists
68 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) 66 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0)
69 { 67 {
70 filterlistsReinitialized = true; 68 filterlistsReinitialized = true;
71 prevVersion = null; 69 prevVersion = null;
72 } 70 }
73 71
74 if (prevVersion != addonVersion || FilterStorage.firstRun) 72 if (prevVersion != addonVersion || FilterStorage.firstRun)
75 { 73 {
76 seenDataCorruption = prevVersion && FilterStorage.firstRun; 74 seenDataCorruption = prevVersion && FilterStorage.firstRun;
77 ext.storage.currentVersion = addonVersion; 75 ext.storage.currentVersion = addonVersion;
78 if (!importingOldData) 76 addSubscription(prevVersion);
79 addSubscription(prevVersion);
80 } 77 }
81 78
82 if (canUseChromeNotifications) 79 if (canUseChromeNotifications)
83 initChromeNotifications(); 80 initChromeNotifications();
84 initAntiAdblockNotification(); 81 initAntiAdblockNotification();
85 } 82 }
86 83
87 // update browser actions when whitelisting might have changed, 84 // update browser actions when whitelisting might have changed,
88 // due to loading filters or saving filter changes 85 // due to loading filters or saving filter changes
89 if (action == "load" || action == "save") 86 if (action == "load" || action == "save")
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 143
147 function refreshIconAndContextMenuForAllPages() 144 function refreshIconAndContextMenuForAllPages()
148 { 145 {
149 ext.pages.query({}, function(pages) 146 ext.pages.query({}, function(pages)
150 { 147 {
151 pages.forEach(refreshIconAndContextMenu); 148 pages.forEach(refreshIconAndContextMenu);
152 }); 149 });
153 } 150 }
154 151
155 /** 152 /**
156 * Old versions for Opera stored patterns.ini in the localStorage object, this
157 * will import it into FilterStorage properly.
158 * @return {Boolean} true if data import is in progress
159 */
160 function importOldData()
161 {
162 if ("patterns.ini" in localStorage)
163 {
164 FilterStorage.loadFromDisk(localStorage["patterns.ini"]);
Wladimir Palant 2014/08/14 14:16:13 There is a hack in lib/filesystem/io.js, function
saroyanm 2014/08/14 16:09:54 Thanks Wladimir, My bad, I should check current re
165
166 var remove = [];
167 for (var key in localStorage)
168 if (key.indexOf("patterns.ini") == 0 || key.indexOf("patterns-backup") == 0)
169 remove.push(key);
170 for (var i = 0; i < remove.length; i++)
171 delete localStorage[remove[i]];
172
173 return true;
174 }
175 else
176 return false;
177 }
178
179 /**
180 * This function is called on an extension update. It will add the default 153 * This function is called on an extension update. It will add the default
181 * filter subscription if necessary. 154 * filter subscription if necessary.
182 */ 155 */
183 function addSubscription(prevVersion) 156 function addSubscription(prevVersion)
184 { 157 {
185 // Make sure to remove "Recommended filters", no longer necessary 158 // Make sure to remove "Recommended filters", no longer necessary
186 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt"; 159 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt";
187 if (toRemove in FilterStorage.knownSubscriptions) 160 if (toRemove in FilterStorage.knownSubscriptions)
188 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ; 161 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ;
189 162
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 page.sendMessage({type: "clickhide-deactivate"}); 580 page.sendMessage({type: "clickhide-deactivate"});
608 refreshIconAndContextMenu(page); 581 refreshIconAndContextMenu(page);
609 }); 582 });
610 583
611 setTimeout(function() 584 setTimeout(function()
612 { 585 {
613 var notificationToShow = Notification.getNextToShow(); 586 var notificationToShow = Notification.getNextToShow();
614 if (notificationToShow) 587 if (notificationToShow)
615 showNotification(notificationToShow); 588 showNotification(notificationToShow);
616 }, 3 * 60 * 1000); 589 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld