| Left: | ||
| Right: | 
| 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) | 360 function loadFile(file, successCallback, errorCallback) | 
| 361 { | 361 { | 
| 362 return new Promise(function(resolve, reject) | 362 var key = fileToKey(file); | 
| 363 var entry = localStorage.getItem(key); | |
| 364 if (entry) | |
| 363 { | 365 { | 
| 364 var key = fileToKey(file); | 366 try | 
| 365 ext.storage.get([key], function(items) | |
| 366 { | 367 { | 
| 367 var entry = items[key]; | 368 entry = JSON.parse(entry); | 
| 368 if (!entry) | 369 } | 
| 369 { | 370 catch(err) | 
| 370 try | 371 { | 
| 371 { | 372 setTimeout(errorCallback(new Error("File is corrupted"))); | 
| 372 entry = JSON.parse(window.localStorage.getItem(key)); | 373 } | 
| 373 } | 374 setTimeout(successCallback(entry)); | 
| 
 
Sebastian Noack
2016/10/10 14:58:06
So if there is an entry in localStorage but it isn
 
kzar
2016/10/11 07:22:41
Whoops you're right, sorry I should have spotted t
 
Oleksandr
2016/10/11 13:52:53
Done.
 
 | |
| 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 = {}; | |
| 391 var key = fileToKey(file); | |
| 392 | |
| 393 if (typeof browser == "undefined") | |
| 394 { | |
| 395 entry[key] = { | |
| 396 lastModified: Date.now(), | |
| 397 content: data | |
| 398 }; | |
| 399 ext.storage.set(entry, callback); | |
| 400 } | 375 } | 
| 401 else | 376 else | 
| 402 { | 377 { | 
| 403 var processedData = LZString.compressToUTF16(JSON.stringify(data)); | 378 localforage.getItem(key, function(err, value) | 
| 404 ext.storage.remove(key); | 379 { | 
| 405 entry[key] = { | 380 if (err || !value) | 
| 
 
Sebastian Noack
2016/10/10 14:58:06
The check for !value seems to be wrong. So if an e
 
Oleksandr
2016/10/11 13:52:13
I don't think this is generally supported. This is
 
Sebastian Noack
2016/10/11 17:15:15
Alright, I missed that the value is an object not
 
Oleksandr
2016/10/11 19:45:54
It does break things if we remove this check. In c
 
 | |
| 406 lastModified: Date.now(), | 381 errorCallback(new Error("File doesn't exist")); | 
| 407 content: processedData, | 382 else | 
| 408 compressed: true | 383 successCallback(value); | 
| 409 }; | 384 }); | 
| 410 window.localStorage.setItem(key, JSON.stringify(entry[key])); | |
| 411 setTimeout(callback, 0); | |
| 412 } | 385 } | 
| 413 callback(); | 386 } | 
| 387 | |
| 388 function saveFile(file, data, callback) | |
| 389 { | |
| 390 var key = fileToKey(file); | |
| 391 var entry = { | |
| 392 lastModified: Date.now(), | |
| 393 content: data | |
| 394 }; | |
| 395 | |
| 396 localStorage.removeItem(key); | |
| 397 localforage.setItem(key, entry, callback); | |
| 414 } | 398 } | 
| 415 exports.IO = { | 399 exports.IO = { | 
| 416 resolveFilePath: function(path) | 400 resolveFilePath: function(path) | 
| 417 { | 401 { | 
| 418 return new FakeFile(path); | 402 return new FakeFile(path); | 
| 419 }, | 403 }, | 
| 420 readFromFile: function(file, listener, callback) | 404 readFromFile: function(file, listener, callback) | 
| 421 { | 405 { | 
| 422 function onLoaded(entry) | 406 function onLoaded(entry) | 
| 423 { | 407 { | 
| 424 if ("content" in entry) | 408 if ("content" in entry) | 
| 425 { | 409 { | 
| 426 if (entry["compressed"]) | |
| 427 { | |
| 428 entry.content = JSON.parse(LZString.decompressFromUTF16(entry.conten t)); | |
| 429 } | |
| 430 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) | 410 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) | 
| 431 { | 411 { | 
| 432 var line = entry.content[_loopIndex15]; | 412 var line = entry.content[_loopIndex15]; | 
| 433 listener.process(line); | 413 listener.process(line); | 
| 434 } | 414 } | 
| 435 } | 415 } | 
| 436 callback(null); | 416 callback(null); | 
| 437 } | 417 } | 
| 438 loadFile(file).then(onLoaded, callback); | 418 loadFile(file, onLoaded, callback); | 
| 439 }, | 419 }, | 
| 440 writeToFile: function(file, data, callback) | 420 writeToFile: function(file, data, callback) | 
| 441 { | 421 { | 
| 442 saveFile(file, data, callback); | 422 saveFile(file, data, callback); | 
| 443 }, | 423 }, | 
| 444 copyFile: function(fromFile, toFile, callback) | 424 copyFile: function(fromFile, toFile, callback) | 
| 445 { | 425 { | 
| 446 function onLoaded(entry) | 426 function onLoaded(entry) | 
| 447 { | 427 { | 
| 448 saveFile(toFile, entry.content, callback); | 428 saveFile(toFile, entry.content, callback); | 
| 449 } | 429 } | 
| 450 loadFile(file).then(onLoaded, callback); | 430 loadFile(file, onLoaded, callback); | 
| 451 }, | 431 }, | 
| 452 renameFile: function(fromFile, newName, callback) | 432 renameFile: function(fromFile, newName, callback) | 
| 453 { | 433 { | 
| 454 function onLoaded() | 434 function onLoaded() | 
| 455 { | 435 { | 
| 456 ext.storage.remove(fileToKey(fromFile), function() | 436 ext.storage.remove(fileToKey(fromFile), function() | 
| 457 { | 437 { | 
| 458 ext.storage.set(keyPrefix + newName, entry, callback); | 438 ext.storage.set(keyPrefix + newName, entry, callback); | 
| 459 }); | 439 }); | 
| 460 } | 440 } | 
| 461 loadFile(file).then(onLoaded, callback); | 441 loadFile(file, onLoaded, callback); | 
| 462 }, | 442 }, | 
| 463 removeFile: function(file, callback) | 443 removeFile: function(file, callback) | 
| 464 { | 444 { | 
| 465 ext.storage.remove(fileToKey(file), callback); | 445 ext.storage.remove(fileToKey(file), callback); | 
| 466 }, | 446 }, | 
| 467 statFile: function(file, callback) | 447 statFile: function(file, callback) | 
| 468 { | 448 { | 
| 469 function onLoaded(entry) | 449 function onLoaded(entry) | 
| 470 { | 450 { | 
| 471 callback(null, | 451 callback(null, | 
| 472 { | 452 { | 
| 473 exists: true, | 453 exists: true, | 
| 474 lastModified: entry.lastModified | 454 lastModified: entry.lastModified | 
| 475 }); | 455 }); | 
| 476 } | 456 } | 
| 477 loadFile(file).then(onLoaded, callback); | 457 loadFile(file, onLoaded, callback); | 
| 478 } | 458 } | 
| 479 }; | 459 }; | 
| 480 return exports; | 460 return exports; | 
| 481 })(); | 461 })(); | 
| 482 require.scopes["downloader"] = (function() | 462 require.scopes["downloader"] = (function() | 
| 483 { | 463 { | 
| 484 var exports = {}; | 464 var exports = {}; | 
| 485 var Utils = require("utils").Utils; | 465 var Utils = require("utils").Utils; | 
| 486 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; | 466 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; | 
| 487 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; | 467 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... | |
| 6576 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6556 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 
| 6577 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 6557 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 
| 6578 } | 6558 } | 
| 6579 if ("setUninstallURL" in chrome.runtime) | 6559 if ("setUninstallURL" in chrome.runtime) | 
| 6580 { | 6560 { | 
| 6581 Prefs.untilLoaded.then(setUninstallURL); | 6561 Prefs.untilLoaded.then(setUninstallURL); | 
| 6582 Prefs.on("notificationdata", setUninstallURL); | 6562 Prefs.on("notificationdata", setUninstallURL); | 
| 6583 } | 6563 } | 
| 6584 return exports; | 6564 return exports; | 
| 6585 })(); | 6565 })(); | 
| OLD | NEW |