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: Created Nov. 25, 2013, 7:39 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') | 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 129 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 {
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 158
174 // Import user-defined subscriptions 159 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) 160 for (var key in localStorage)
307 if (/^https?:/.test(key)) 161 if (key.indexOf("patterns.ini") == 0 || key.indexOf("patterns-backup") == 0)
308 delete localStorage[key]; 162 remove.push(key);
309 } 163 for (var i = 0; i < remove.length; i++)
310 catch (e) 164 delete localStorage[remove[i]];
311 {
312 reportError(e);
313 } 165 }
314 } 166 }
315 167
316 /** 168 /**
317 * This function is called on an extension update. It will add the default 169 * This function is called on an extension update. It will add the default
318 * filter subscription if necessary. 170 * filter subscription if necessary.
319 */ 171 */
320 function addSubscription(prevVersion) 172 function addSubscription(prevVersion)
321 { 173 {
322 // Make sure to remove "Recommended filters", no longer necessary 174 // Make sure to remove "Recommended filters", no longer necessary
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 tab.sendMessage({type: "clickhide-deactivate"}); 455 tab.sendMessage({type: "clickhide-deactivate"});
604 refreshIconAndContextMenu(tab); 456 refreshIconAndContextMenu(tab);
605 }); 457 });
606 458
607 setTimeout(function() 459 setTimeout(function()
608 { 460 {
609 var notificationToShow = Notification.getNextToShow(); 461 var notificationToShow = Notification.getNextToShow();
610 if (notificationToShow) 462 if (notificationToShow)
611 showNotification(notificationToShow); 463 showNotification(notificationToShow);
612 }, 3 * 60 * 1000); 464 }, 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