OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 delete overrides[pref]; | 246 delete overrides[pref]; |
247 | 247 |
248 Prefs.onChanged._dispatch(pref); | 248 Prefs.onChanged._dispatch(pref); |
249 } | 249 } |
250 } | 250 } |
251 }); | 251 }); |
252 | 252 |
253 Prefs.onLoaded._dispatch(); | 253 Prefs.onLoaded._dispatch(); |
254 }; | 254 }; |
255 | 255 |
256 // Migrate preferences for users updating from old versions. | 256 ext.storage.get(prefs.map(prefToKey), function(items) |
257 // TODO: Remove the migration code after a few releases. | 257 { |
258 ext.storage.migratePrefs({ | 258 for (let key in items) |
259 map: function(key, value) | 259 overrides[keyToPref(key)] = items[key]; |
260 { | |
261 if (key in defaults || key == "stats_total") | |
262 { | |
263 if (key != "currentVersion") | |
264 { | |
265 try | |
266 { | |
267 value = JSON.parse(value); | |
268 } | |
269 catch (e) | |
270 { | |
271 return null; | |
272 } | |
273 } | |
274 | 260 |
275 if (key == "stats_total") | 261 localLoaded = true; |
276 { | 262 checkLoaded(); |
277 key = "blocked_total"; | |
278 value = value.blocked; | |
279 } | |
280 | |
281 return {key: prefToKey(key), value: value}; | |
282 } | |
283 | |
284 return null; | |
285 }, | |
286 | |
287 done: function() | |
288 { | |
289 ext.storage.get(prefs.map(prefToKey), function(items) | |
290 { | |
291 for (let key in items) | |
292 overrides[keyToPref(key)] = items[key]; | |
293 | |
294 localLoaded = true; | |
295 checkLoaded(); | |
296 }); | |
297 } | |
298 }); | 263 }); |
299 | 264 |
300 if (require("info").platform == "chromium" && "managed" in chrome.storage) | 265 if (require("info").platform == "chromium" && "managed" in chrome.storage) |
301 { | 266 { |
302 chrome.storage.managed.get(null, function(items) | 267 chrome.storage.managed.get(null, function(items) |
303 { | 268 { |
304 // Opera doesn't support chrome.storage.managed, but instead simply | 269 // Opera doesn't support chrome.storage.managed, but instead simply |
305 // removing the API, Opera sets chrome.runtime.lastError when using it. | 270 // removing the API, Opera sets chrome.runtime.lastError when using it. |
306 // So we have to retrieve that error, to prevent it from showing up | 271 // So we have to retrieve that error, to prevent it from showing up |
307 // in the console. | 272 // in the console. |
308 chrome.runtime.lastError; | 273 chrome.runtime.lastError; |
309 | 274 |
310 for (let key in items) | 275 for (let key in items) |
311 defaults[key] = items[key]; | 276 defaults[key] = items[key]; |
312 | 277 |
313 managedLoaded = true; | 278 managedLoaded = true; |
314 checkLoaded(); | 279 checkLoaded(); |
315 }); | 280 }); |
316 } | 281 } |
317 else | 282 else |
318 { | 283 { |
319 managedLoaded = true; | 284 managedLoaded = true; |
320 checkLoaded(); | 285 checkLoaded(); |
321 } | 286 } |
322 } | 287 } |
323 | 288 |
324 init(); | 289 init(); |
OLD | NEW |