Left: | ||
Right: |
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 dataInJson = localStorage.getItem(key); | 363 var entry = localStorage.getItem(key); |
364 if (dataInJson != null) | 364 if (entry) |
kzar
2016/07/27 08:44:21
Perhaps just check if dataInJson is truthy like th
| |
365 successCallback(JSON.parse(dataInJson)); | 365 { |
366 successCallback(JSON.parse(entry)); | |
367 } | |
366 else | 368 else |
367 errorCallback(new Error("File doesn't exist")); | 369 { |
368 } | 370 // Also check the chrome.storage.local |
369 | 371 // We may have a init data there |
372 ext.storage.get([key], function(items) | |
373 { | |
374 var entry = items[key]; | |
375 if (entry) | |
376 successCallback(entry); | |
377 else | |
378 errorCallback(new Error("File doesn't exist")); | |
379 }); | |
380 } | |
381 } | |
370 function saveFile(file, data, callback) | 382 function saveFile(file, data, callback) |
371 { | 383 { |
372 try | 384 try |
373 { | 385 { |
374 localStorage.setItem(fileToKey(file), JSON.stringify({ | 386 localStorage.setItem(fileToKey(file), JSON.stringify({ |
kzar
2016/07/27 08:44:21
Nit: The indentation here looks kind of weird. How
| |
375 content: data, | 387 content: data, |
376 lastModified: Date.now() | 388 lastModified: Date.now() |
377 } | 389 })); |
378 )); | |
379 } | 390 } |
380 catch(error) | 391 catch(error) |
381 { | 392 { |
382 // QuotaExceededError can happen. Ignore silently | 393 // QuotaExceededError can happen. Notify the user and ignore |
kzar
2016/07/27 08:44:21
Maybe we should display an alert that asks the use
| |
394 var errorMessage = "Subscription storage is full. " + | |
395 "Please remove some subscriptions and try again."; | |
396 alert(errorMessage); | |
397 callback(new Error(errorMessage)); | |
398 return; | |
383 } | 399 } |
384 callback(); | 400 callback(); |
385 } | 401 } |
386 exports.IO = { | 402 exports.IO = { |
387 resolveFilePath: function(path) | 403 resolveFilePath: function(path) |
388 { | 404 { |
389 return new FakeFile(path); | 405 return new FakeFile(path); |
390 }, | 406 }, |
391 readFromFile: function(file, listener, callback) | 407 readFromFile: function(file, listener, callback) |
392 { | 408 { |
(...skipping 6145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6538 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6554 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
6539 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 6555 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); |
6540 } | 6556 } |
6541 if ("setUninstallURL" in chrome.runtime) | 6557 if ("setUninstallURL" in chrome.runtime) |
6542 { | 6558 { |
6543 Prefs.untilLoaded.then(setUninstallURL); | 6559 Prefs.untilLoaded.then(setUninstallURL); |
6544 Prefs.on("notificationdata", setUninstallURL); | 6560 Prefs.on("notificationdata", setUninstallURL); |
6545 } | 6561 } |
6546 return exports; | 6562 return exports; |
6547 })(); | 6563 })(); |
LEFT | RIGHT |