LEFT | RIGHT |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 var keyPrefix = "file:"; | 353 var keyPrefix = "file:"; |
354 | 354 |
355 function fileToKey(file) | 355 function fileToKey(file) |
356 { | 356 { |
357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); | 357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); |
358 } | 358 } |
359 | 359 |
360 function loadFile(file, successCallback, errorCallback) | 360 function loadFile(file, successCallback, errorCallback) |
361 { | 361 { |
362 var key = fileToKey(file); | 362 var key = fileToKey(file); |
| 363 // Make sure we do not have subscriptions in localStorage from older version
s first |
363 var entry = localStorage.getItem(key); | 364 var entry = localStorage.getItem(key); |
364 if (entry) | 365 if (typeof entry == "string") |
365 { | 366 { |
366 try | 367 try |
367 { | 368 { |
368 setTimeout(successCallback(JSON.parse(entry))); | 369 entry = JSON.parse(entry); |
369 } | 370 } |
370 catch(err) | 371 catch(err) |
371 { | 372 { |
372 setTimeout(errorCallback(new Error("File is corrupted"))); | 373 setTimeout(errorCallback(new Error("File is corrupted"))); |
373 } | 374 return; |
374 } | 375 } |
375 else | 376 setTimeout(successCallback(entry)); |
376 { | 377 return; |
377 localforage.getItem(key, function(err, value) | 378 } |
378 { | 379 // Now try to read from IndexedDB |
379 if (err || !value) | 380 localforage.getItem(key, function(err, value) |
380 errorCallback(new Error("File doesn't exist")); | 381 { |
381 else | 382 if (err || !value) |
382 successCallback(value); | 383 errorCallback(new Error("File doesn't exist")); |
383 }); | 384 else |
384 } | 385 successCallback(value); |
| 386 }); |
385 } | 387 } |
386 | 388 |
387 function saveFile(file, data, callback) | 389 function saveFile(file, data, callback) |
388 { | 390 { |
389 var key = fileToKey(file); | 391 var key = fileToKey(file); |
390 var entry = { | 392 var entry = { |
391 lastModified: Date.now(), | 393 lastModified: Date.now(), |
392 content: data | 394 content: data |
393 }; | 395 }; |
394 | 396 |
(...skipping 6160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6555 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6557 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
6556 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); | 6558 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); |
6557 } | 6559 } |
6558 if ("setUninstallURL" in chrome.runtime) | 6560 if ("setUninstallURL" in chrome.runtime) |
6559 { | 6561 { |
6560 Prefs.untilLoaded.then(setUninstallURL); | 6562 Prefs.untilLoaded.then(setUninstallURL); |
6561 Prefs.on("notificationdata", setUninstallURL); | 6563 Prefs.on("notificationdata", setUninstallURL); |
6562 } | 6564 } |
6563 return exports; | 6565 return exports; |
6564 })(); | 6566 })(); |
LEFT | RIGHT |