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: Prevent first-run page from appearing Created Nov. 26, 2013, 8:48 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 | lib/filesystem/io.js » ('j') | lib/filesystem/io.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 <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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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 (prevVersion != addonVersion) 52 if (seenDataCorruption || prevVersion != addonVersion)
53 { 53 {
54 isFirstRun = !prevVersion; 54 isFirstRun = !prevVersion;
55 localStorage["currentVersion"] = addonVersion; 55 localStorage["currentVersion"] = addonVersion;
56 addSubscription(prevVersion); 56 addSubscription(prevVersion);
57 } 57 }
58 } 58 }
59 }); 59 });
60 60
61 // Special-case domains for which we cannot use style-based hiding rules. 61 // Special-case domains for which we cannot use style-based hiding rules.
62 // See http://crbug.com/68705. 62 // See http://crbug.com/68705.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 if (require("info").platform == "chromium") // TODO: Implement context menus f or Safari 141 if (require("info").platform == "chromium") // TODO: Implement context menus f or Safari
142 // Set context menu status according to whether current tab has whitelisted domain 142 // Set context menu status according to whether current tab has whitelisted domain
143 if (excluded) 143 if (excluded)
144 chrome.contextMenus.removeAll(); 144 chrome.contextMenus.removeAll();
145 else 145 else
146 showContextMenu(); 146 showContextMenu();
147 } 147 }
148 148
149 /** 149 /**
150 * Old versions stored filter data in the localStorage object, this will import 150 * Old versions for Opera stored patterns.ini in the localStorage object, this
151 * it into FilterStorage properly. 151 * will import it into FilterStorage properly.
152 */ 152 */
153 function importOldData() 153 function importOldData()
154 { 154 {
155 function addSubscription(url, title) 155 if ("patterns.ini" in localStorage)
156 { 156 {
157 try 157 FilterStorage.loadFromDisk(localStorage["patterns.ini"]);
158 { 158 seenDataCorruption = false;
159 var subscription = Subscription.fromURL(url);
160 if (subscription && !(subscription.url in FilterStorage.knownSubscriptions ))
161 {
162 if (title)
163 subscription.title = title;
164 FilterStorage.addSubscription(subscription);
165 Synchronizer.execute(subscription);
166 }
167 }
168 catch (e)
169 {
170 reportError(e);
171 }
172 }
173 159
174 // Import user-defined subscriptions 160 var remove = [];
175 if (typeof localStorage["userFilterURLs"] == "string")
176 {
177 try
178 {
179 var urls = JSON.parse(localStorage["userFilterURLs"]);
180 for (var key in urls)
181 addSubscription(urls[key]);
182 delete localStorage["userFilterURLs"];
183 }
184 catch (e)
185 {
186 reportError(e);
187 }
188 }
189
190 // Now import predefined subscriptions if enabled
191 if (typeof localStorage["filterFilesEnabled"] == "string")
192 {
193 try
194 {
195 var subscriptions = JSON.parse(localStorage["filterFilesEnabled"]);
196 if (subscriptions.korea)
197 subscriptions.easylist = true;
198 if (subscriptions.france)
199 {
200 addSubscription("https://easylist-downloads.adblockplus.org/liste_fr+eas ylist.txt", "Liste FR+EasyList");
201 subscriptions.easylist = false;
202 }
203 if (subscriptions.germany)
204 {
205 if (subscriptions.easylist)
206 addSubscription("https://easylist-downloads.adblockplus.org/easylistge rmany+easylist.txt", "EasyList Germany+EasyList");
207 else
208 addSubscription("https://easylist-downloads.adblockplus.org/easylistge rmany.txt", "EasyList Germany");
209 subscriptions.easylist = false;
210 }
211 if (subscriptions.china)
212 {
213 if (subscriptions.easylist)
214 addSubscription("https://easylist-downloads.adblockplus.org/chinalist+ easylist.txt", "ChinaList+EasyList");
215 else
216 addSubscription("http://adblock-chinalist.googlecode.com/svn/trunk/adb lock.txt", "ChinaList");
217 subscriptions.easylist = false;
218 }
219 if (subscriptions.russia)
220 {
221 if (subscriptions.easylist)
222 addSubscription("https://easylist-downloads.adblockplus.org/ruadlist+e asylist.txt", "RU AdList+EasyList");
223 else
224 addSubscription("https://ruadlist.googlecode.com/svn/trunk/advblock.tx t", "RU AdList");
225 subscriptions.easylist = false;
226 }
227 if (subscriptions.romania)
228 {
229 if (subscriptions.easylist)
230 addSubscription("https://easylist-downloads.adblockplus.org/rolist+eas ylist.txt", "ROList+EasyList");
231 else
232 addSubscription("http://www.zoso.ro/pages/rolist.txt", "ROList");
233 subscriptions.easylist = false;
234 }
235 if (subscriptions.easylist)
236 addSubscription("https://easylist-downloads.adblockplus.org/easylist.txt ", "EasyList");
237 if (subscriptions.fanboy)
238 addSubscription("https://secure.fanboy.co.nz/fanboy-adblock.txt", "Fanbo y's List");
239 if (subscriptions.fanboy_es)
240 addSubscription("https://secure.fanboy.co.nz/fanboy-espanol.txt", "Fanbo y's Espa\xF1ol/Portugu\xEAs");
241 if (subscriptions.italy)
242 addSubscription("http://mozilla.gfsolone.com/filtri.txt", "Xfiles");
243 if (subscriptions.poland)
244 addSubscription("http://www.niecko.pl/adblock/adblock.txt", "PLgeneral") ;
245 if (subscriptions.hungary)
246 addSubscription("http://pete.teamlupus.hu/hufilter.txt", "hufilter");
247 if (subscriptions.extras)
248 addSubscription("https://easylist-downloads.adblockplus.org/chrome_suppl ement.txt", "Recommended filters for Google Chrome");
249
250 delete localStorage["filterFilesEnabled"];
251 }
252 catch (e)
253 {
254 reportError(e);
255 }
256 }
257
258 // Import user filters
259 if(typeof localStorage["userFilters"] == "string")
260 {
261 try
262 {
263 var userFilters = JSON.parse(localStorage["userFilters"]);
264 for (var i = 0; i < userFilters.length; i++)
265 {
266 var filterText = userFilters[i];
267
268 // Skip useless default filters
269 if (filterText == "qux.us###annoying_AdDiv" || filterText == "qux.us##.a d_class")
270 continue;
271
272 var filter = Filter.fromText(filterText);
273 FilterStorage.addFilter(filter);
274 }
275 delete localStorage["userFilters"];
276 }
277 catch (e)
278 {
279 reportError(e);
280 }
281 }
282
283 // Import "excluded domains"
284 if(typeof localStorage["excludedDomains"] == "string")
285 {
286 try
287 {
288 var excludedDomains = JSON.parse(localStorage["excludedDomains"]);
289 for (var domain in excludedDomains)
290 {
291 var filterText = "@@||" + domain + "^$document";
292 var filter = Filter.fromText(filterText);
293 FilterStorage.addFilter(filter);
294 }
295 delete localStorage["excludedDomains"];
296 }
297 catch (e)
298 {
299 reportError(e);
300 }
301 }
302
303 // Delete downloaded subscription data
304 try
305 {
306 for (var key in localStorage) 161 for (var key in localStorage)
307 if (/^https?:/.test(key)) 162 if (key.indexOf("patterns.ini") == 0 || key.indexOf("patterns-backup") == 0)
308 delete localStorage[key]; 163 remove.push(key);
309 } 164 for (var i = 0; i < remove.length; i++)
310 catch (e) 165 delete localStorage[remove[i]];
311 {
312 reportError(e);
313 } 166 }
314 } 167 }
315 168
316 /** 169 /**
317 * This function is called on an extension update. It will add the default 170 * This function is called on an extension update. It will add the default
318 * filter subscription if necessary. 171 * filter subscription if necessary.
319 */ 172 */
320 function addSubscription(prevVersion) 173 function addSubscription(prevVersion)
321 { 174 {
322 // Make sure to remove "Recommended filters", no longer necessary 175 // Make sure to remove "Recommended filters", no longer necessary
323 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt"; 176 var toRemove = "https://easylist-downloads.adblockplus.org/chrome_supplement.t xt";
324 if (toRemove in FilterStorage.knownSubscriptions) 177 if (toRemove in FilterStorage.knownSubscriptions)
325 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ; 178 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[toRemove]) ;
326 179
327 // Add "acceptable ads" subscription for new users 180 // Add "acceptable ads" subscription for new users
328 var addAcceptable = !prevVersion; 181 var addAcceptable = !prevVersion || seenDataCorruption;
329 if (addAcceptable) 182 if (addAcceptable)
330 { 183 {
331 addAcceptable = !FilterStorage.subscriptions.some(function(subscription) 184 addAcceptable = !FilterStorage.subscriptions.some(function(subscription)
332 { 185 {
333 return subscription.url == Prefs.subscriptions_exceptionsurl; 186 return subscription.url == Prefs.subscriptions_exceptionsurl;
334 }); 187 });
335 } 188 }
336 189
337 // Don't add subscription if the user has a subscription already 190 // Don't add subscription if the user has a subscription already
338 var addSubscription = !FilterStorage.subscriptions.some(function(subscription) 191 var addSubscription = !FilterStorage.subscriptions.some(function(subscription)
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 tab.sendMessage({type: "clickhide-deactivate"}); 456 tab.sendMessage({type: "clickhide-deactivate"});
604 refreshIconAndContextMenu(tab); 457 refreshIconAndContextMenu(tab);
605 }); 458 });
606 459
607 setTimeout(function() 460 setTimeout(function()
608 { 461 {
609 var notificationToShow = Notification.getNextToShow(); 462 var notificationToShow = Notification.getNextToShow();
610 if (notificationToShow) 463 if (notificationToShow)
611 showNotification(notificationToShow); 464 showNotification(notificationToShow);
612 }, 3 * 60 * 1000); 465 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | lib/filesystem/io.js » ('j') | lib/filesystem/io.js » ('J')

Powered by Google App Engine
This is Rietveld