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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 require.scopes["io"] = (function() | 350 require.scopes["io"] = (function() |
351 { | 351 { |
352 var exports = {}; | 352 var exports = {}; |
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) | 360 function loadFile(file, successCallback, errorCallback) |
361 { | 361 { |
362 return new Promise(function(resolve, reject) | 362 var key = fileToKey(file); |
363 { | 363 // Make sure we do not have subscriptions in localStorage from older version
s first |
364 var key = fileToKey(file); | 364 var entry = localStorage.getItem(key); |
365 ext.storage.get([key], function(items) | 365 if (typeof entry == "string") |
366 { | 366 { |
367 var entry = items[key]; | 367 try |
368 if (entry) | 368 { |
369 { | 369 entry = JSON.parse(entry); |
370 resolve(entry); | 370 } |
371 } | 371 catch(err) |
372 else | 372 { |
373 { | 373 setTimeout(errorCallback(new Error("File is corrupted"))); |
374 entry = localforage.getItem(key, function(err, value) | 374 return; |
375 { | 375 } |
376 if (err || !value) | 376 setTimeout(successCallback(entry)); |
377 reject(new Error("File doesn't exist")); | 377 return; |
378 else | 378 } |
379 resolve(value); | 379 // Now try to read from IndexedDB |
380 }); | 380 localforage.getItem(key, function(err, value) |
381 } | 381 { |
382 }); | 382 if (err || !value) |
383 }.bind(this)); | 383 errorCallback(new Error("File doesn't exist")); |
384 } | 384 else |
| 385 successCallback(value); |
| 386 }); |
| 387 } |
| 388 |
385 function saveFile(file, data, callback) | 389 function saveFile(file, data, callback) |
386 { | 390 { |
387 var key = fileToKey(file); | 391 var key = fileToKey(file); |
388 var entry = { | 392 var entry = { |
389 lastModified: Date.now(), | 393 lastModified: Date.now(), |
390 content: data | 394 content: data |
391 }; | 395 }; |
392 | 396 |
393 ext.storage.remove(key); | 397 localStorage.removeItem(key); |
394 localforage.setItem(key, entry, callback); | 398 localforage.setItem(key, entry, callback); |
395 } | 399 } |
396 exports.IO = { | 400 exports.IO = { |
397 resolveFilePath: function(path) | 401 resolveFilePath: function(path) |
398 { | 402 { |
399 return new FakeFile(path); | 403 return new FakeFile(path); |
400 }, | 404 }, |
401 readFromFile: function(file, listener, callback) | 405 readFromFile: function(file, listener, callback) |
402 { | 406 { |
403 function onLoaded(entry) | 407 function onLoaded(entry) |
404 { | 408 { |
405 if ("content" in entry) | 409 if ("content" in entry) |
406 { | 410 { |
407 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo
pIndex15) | 411 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo
pIndex15) |
408 { | 412 { |
409 var line = entry.content[_loopIndex15]; | 413 var line = entry.content[_loopIndex15]; |
410 listener.process(line); | 414 listener.process(line); |
411 } | 415 } |
412 } | 416 } |
413 callback(null); | 417 callback(null); |
414 } | 418 } |
415 loadFile(file).then(onLoaded, callback); | 419 loadFile(file, onLoaded, callback); |
416 }, | 420 }, |
417 writeToFile: function(file, data, callback) | 421 writeToFile: function(file, data, callback) |
418 { | 422 { |
419 saveFile(file, data, callback); | 423 saveFile(file, data, callback); |
420 }, | 424 }, |
421 copyFile: function(fromFile, toFile, callback) | 425 copyFile: function(fromFile, toFile, callback) |
422 { | 426 { |
423 function onLoaded(entry) | 427 function onLoaded(entry) |
424 { | 428 { |
425 saveFile(toFile, entry.content, callback); | 429 saveFile(toFile, entry.content, callback); |
426 } | 430 } |
427 loadFile(file).then(onLoaded, callback); | 431 loadFile(file, onLoaded, callback); |
428 }, | 432 }, |
429 renameFile: function(fromFile, newName, callback) | 433 renameFile: function(fromFile, newName, callback) |
430 { | 434 { |
431 function onLoaded() | 435 function onLoaded() |
432 { | 436 { |
433 ext.storage.remove(fileToKey(fromFile), function() | 437 ext.storage.remove(fileToKey(fromFile), function() |
434 { | 438 { |
435 ext.storage.set(keyPrefix + newName, entry, callback); | 439 ext.storage.set(keyPrefix + newName, entry, callback); |
436 }); | 440 }); |
437 } | 441 } |
438 loadFile(file).then(onLoaded, callback); | 442 loadFile(file, onLoaded, callback); |
439 }, | 443 }, |
440 removeFile: function(file, callback) | 444 removeFile: function(file, callback) |
441 { | 445 { |
442 ext.storage.remove(fileToKey(file), callback); | 446 ext.storage.remove(fileToKey(file), callback); |
443 }, | 447 }, |
444 statFile: function(file, callback) | 448 statFile: function(file, callback) |
445 { | 449 { |
446 function onLoaded(entry) | 450 function onLoaded(entry) |
447 { | 451 { |
448 callback(null, | 452 callback(null, |
449 { | 453 { |
450 exists: true, | 454 exists: true, |
451 lastModified: entry.lastModified | 455 lastModified: entry.lastModified |
452 }); | 456 }); |
453 } | 457 } |
454 loadFile(file).then(onLoaded, callback); | 458 loadFile(file, onLoaded, callback); |
455 } | 459 } |
456 }; | 460 }; |
457 return exports; | 461 return exports; |
458 })(); | 462 })(); |
459 require.scopes["downloader"] = (function() | 463 require.scopes["downloader"] = (function() |
460 { | 464 { |
461 var exports = {}; | 465 var exports = {}; |
462 var Utils = require("utils").Utils; | 466 var Utils = require("utils").Utils; |
463 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; | 467 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; |
464 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; | 468 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; |
(...skipping 6088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6553 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6557 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
6554 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); | 6558 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); |
6555 } | 6559 } |
6556 if ("setUninstallURL" in chrome.runtime) | 6560 if ("setUninstallURL" in chrome.runtime) |
6557 { | 6561 { |
6558 Prefs.untilLoaded.then(setUninstallURL); | 6562 Prefs.untilLoaded.then(setUninstallURL); |
6559 Prefs.on("notificationdata", setUninstallURL); | 6563 Prefs.on("notificationdata", setUninstallURL); |
6560 } | 6564 } |
6561 return exports; | 6565 return exports; |
6562 })(); | 6566 })(); |
LEFT | RIGHT |