| 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-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, successCallback, errorCallback) | 360 function loadFile(file) |
| 361 { | 361 { |
| 362 return new Promise(function(resolve, reject) |
| 363 { |
| 364 var key = fileToKey(file); |
| 365 ext.storage.get([key], function(items) |
| 366 { |
| 367 var entry = items[key]; |
| 368 if (!entry) |
| 369 { |
| 370 try |
| 371 { |
| 372 entry = JSON.parse(window.localStorage.getItem(key)); |
| 373 } |
| 374 catch (err) |
| 375 {} |
| 376 } |
| 377 if (entry) |
| 378 { |
| 379 resolve(entry); |
| 380 } |
| 381 else |
| 382 { |
| 383 reject(new Error("File doesn't exist")); |
| 384 } |
| 385 }); |
| 386 }.bind(this)); |
| 387 } |
| 388 function saveFile(file, data, callback) |
| 389 { |
| 390 var entry = {}; |
| 362 var key = fileToKey(file); | 391 var key = fileToKey(file); |
| 363 var entry = localStorage.getItem(key); | 392 |
| 364 if (entry) | 393 if (typeof browser == "undefined") |
| 365 { | 394 { |
| 366 successCallback(JSON.parse(entry)); | 395 entry[key] = { |
| 396 lastModified: Date.now(), |
| 397 content: data |
| 398 }; |
| 399 ext.storage.set(entry, callback); |
| 367 } | 400 } |
| 368 else | 401 else |
| 369 { | 402 { |
| 370 // Also check the chrome.storage.local | 403 var processedData = LZString.compressToUTF16(JSON.stringify(data)); |
| 371 // We may have a init data there | 404 ext.storage.remove(key); |
| 372 ext.storage.get([key], function(items) | 405 entry[key] = { |
| 373 { | 406 lastModified: Date.now(), |
| 374 var entry = items[key]; | 407 content: processedData, |
| 375 if (entry) | 408 compressed: true |
| 376 successCallback(entry); | 409 }; |
| 377 else | 410 window.localStorage.setItem(key, JSON.stringify(entry[key])); |
| 378 errorCallback(new Error("File doesn't exist")); | 411 setTimeout(callback, 0); |
| 379 }); | |
| 380 } | |
| 381 } | |
| 382 function saveFile(file, data, callback) | |
| 383 { | |
| 384 try | |
| 385 { | |
| 386 localStorage.setItem(fileToKey(file), JSON.stringify({ | |
| 387 content: data, | |
| 388 lastModified: Date.now() | |
| 389 })); | |
| 390 } | |
| 391 catch(error) | |
| 392 { | |
| 393 // QuotaExceededError can happen. Notify the user and ignore | |
| 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; | |
| 399 } | 412 } |
| 400 callback(); | 413 callback(); |
| 401 } | 414 } |
| 402 exports.IO = { | 415 exports.IO = { |
| 403 resolveFilePath: function(path) | 416 resolveFilePath: function(path) |
| 404 { | 417 { |
| 405 return new FakeFile(path); | 418 return new FakeFile(path); |
| 406 }, | 419 }, |
| 407 readFromFile: function(file, listener, callback) | 420 readFromFile: function(file, listener, callback) |
| 408 { | 421 { |
| 409 function onLoaded(entry) | 422 function onLoaded(entry) |
| 410 { | 423 { |
| 411 for (var _loopIndex1 = 0; _loopIndex1 < entry.content.length; ++_loopInd
ex1) | 424 if ("content" in entry) |
| 412 { | 425 { |
| 413 var line = entry.content[_loopIndex1]; | 426 if (entry["compressed"]) |
| 414 listener.process(line); | 427 { |
| 428 entry.content = JSON.parse(LZString.decompressFromUTF16(entry.conten
t)); |
| 429 } |
| 430 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo
pIndex15) |
| 431 { |
| 432 var line = entry.content[_loopIndex15]; |
| 433 listener.process(line); |
| 434 } |
| 415 } | 435 } |
| 416 listener.process(null); | |
| 417 callback(null); | 436 callback(null); |
| 418 } | 437 } |
| 419 loadFile(file, onLoaded, callback); | 438 loadFile(file).then(onLoaded, callback); |
| 420 }, | 439 }, |
| 421 writeToFile: function(file, data, callback) | 440 writeToFile: function(file, data, callback) |
| 422 { | 441 { |
| 423 saveFile(file, data, callback); | 442 saveFile(file, data, callback); |
| 424 }, | 443 }, |
| 425 copyFile: function(fromFile, toFile, callback) | 444 copyFile: function(fromFile, toFile, callback) |
| 426 { | 445 { |
| 427 function onLoaded(entry) | 446 function onLoaded(entry) |
| 428 { | 447 { |
| 429 saveFile(toFile, entry.content, callback); | 448 saveFile(toFile, entry.content, callback); |
| 430 } | 449 } |
| 431 loadFile(fromFile, onLoaded, callback); | 450 loadFile(file).then(onLoaded, callback); |
| 432 }, | 451 }, |
| 433 renameFile: function(fromFile, newName, callback) | 452 renameFile: function(fromFile, newName, callback) |
| 434 { | 453 { |
| 435 function onLoaded() | 454 function onLoaded() |
| 436 { | 455 { |
| 437 ext.storage.remove(fileToKey(fromFile), function() | 456 ext.storage.remove(fileToKey(fromFile), function() |
| 438 { | 457 { |
| 439 ext.storage.set(keyPrefix + newName, entry, callback); | 458 ext.storage.set(keyPrefix + newName, entry, callback); |
| 440 }); | 459 }); |
| 441 } | 460 } |
| 442 loadFile(fromFile, onLoaded, callback); | 461 loadFile(file).then(onLoaded, callback); |
| 443 }, | 462 }, |
| 444 removeFile: function(file, callback) | 463 removeFile: function(file, callback) |
| 445 { | 464 { |
| 446 ext.storage.remove(fileToKey(file), callback); | 465 ext.storage.remove(fileToKey(file), callback); |
| 447 }, | 466 }, |
| 448 statFile: function(file, callback) | 467 statFile: function(file, callback) |
| 449 { | 468 { |
| 450 function onLoaded(entry) | 469 function onLoaded(entry) |
| 451 { | 470 { |
| 452 callback(null, | 471 callback(null, |
| 453 { | 472 { |
| 454 exists: true, | 473 exists: true, |
| 455 lastModified: entry.lastModified | 474 lastModified: entry.lastModified |
| 456 }); | 475 }); |
| 457 } | 476 } |
| 458 loadFile(file, onLoaded, callback); | 477 loadFile(file).then(onLoaded, callback); |
| 459 } | 478 } |
| 460 }; | 479 }; |
| 461 return exports; | 480 return exports; |
| 462 })(); | 481 })(); |
| 463 require.scopes["downloader"] = (function() | 482 require.scopes["downloader"] = (function() |
| 464 { | 483 { |
| 465 var exports = {}; | 484 var exports = {}; |
| 466 var Utils = require("utils").Utils; | 485 var Utils = require("utils").Utils; |
| 467 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; | 486 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; |
| 468 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; | 487 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; |
| (...skipping 6085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6554 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6573 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
| 6555 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); | 6574 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); |
| 6556 } | 6575 } |
| 6557 if ("setUninstallURL" in chrome.runtime) | 6576 if ("setUninstallURL" in chrome.runtime) |
| 6558 { | 6577 { |
| 6559 Prefs.untilLoaded.then(setUninstallURL); | 6578 Prefs.untilLoaded.then(setUninstallURL); |
| 6560 Prefs.on("notificationdata", setUninstallURL); | 6579 Prefs.on("notificationdata", setUninstallURL); |
| 6561 } | 6580 } |
| 6562 return exports; | 6581 return exports; |
| 6563 })(); | 6582 })(); |
| OLD | NEW |