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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 358 } |
359 | 359 |
360 function loadFile(file) | 360 function loadFile(file) |
361 { | 361 { |
362 return new Promise(function(resolve, reject) | 362 return new Promise(function(resolve, reject) |
363 { | 363 { |
364 var key = fileToKey(file); | 364 var key = fileToKey(file); |
365 ext.storage.get([key], function(items) | 365 ext.storage.get([key], function(items) |
366 { | 366 { |
367 var entry = items[key]; | 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) | 368 if (entry) |
378 { | 369 { |
379 resolve(entry); | 370 resolve(entry); |
380 } | 371 } |
381 else | 372 else |
382 { | 373 { |
383 reject(new Error("File doesn't exist")); | 374 entry = localforage.getItem(key, function(err, value) |
| 375 { |
| 376 if (err || !value) |
| 377 reject(new Error("File doesn't exist")); |
| 378 else |
| 379 resolve(value); |
| 380 }); |
384 } | 381 } |
385 }); | 382 }); |
386 }.bind(this)); | 383 }.bind(this)); |
387 } | 384 } |
388 function saveFile(file, data, callback) | 385 function saveFile(file, data, callback) |
389 { | 386 { |
390 var entry = {}; | |
391 var key = fileToKey(file); | 387 var key = fileToKey(file); |
| 388 var entry = { |
| 389 lastModified: Date.now(), |
| 390 content: data |
| 391 }; |
392 | 392 |
393 if (typeof browser == "undefined") | 393 ext.storage.remove(key); |
394 { | 394 localforage.setItem(key, entry, callback); |
395 entry[key] = { | |
396 lastModified: Date.now(), | |
397 content: data | |
398 }; | |
399 ext.storage.set(entry, callback); | |
400 } | |
401 else | |
402 { | |
403 var processedData = LZString.compressToUTF16(JSON.stringify(data)); | |
404 ext.storage.remove(key); | |
405 entry[key] = { | |
406 lastModified: Date.now(), | |
407 content: processedData, | |
408 compressed: true | |
409 }; | |
410 window.localStorage.setItem(key, JSON.stringify(entry[key])); | |
411 setTimeout(callback, 0); | |
412 } | |
413 callback(); | |
414 } | 395 } |
415 exports.IO = { | 396 exports.IO = { |
416 resolveFilePath: function(path) | 397 resolveFilePath: function(path) |
417 { | 398 { |
418 return new FakeFile(path); | 399 return new FakeFile(path); |
419 }, | 400 }, |
420 readFromFile: function(file, listener, callback) | 401 readFromFile: function(file, listener, callback) |
421 { | 402 { |
422 function onLoaded(entry) | 403 function onLoaded(entry) |
423 { | 404 { |
424 if ("content" in entry) | 405 if ("content" in entry) |
425 { | 406 { |
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) | 407 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo
pIndex15) |
431 { | 408 { |
432 var line = entry.content[_loopIndex15]; | 409 var line = entry.content[_loopIndex15]; |
433 listener.process(line); | 410 listener.process(line); |
434 } | 411 } |
435 } | 412 } |
436 callback(null); | 413 callback(null); |
437 } | 414 } |
438 loadFile(file).then(onLoaded, callback); | 415 loadFile(file).then(onLoaded, callback); |
439 }, | 416 }, |
(...skipping 6136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6576 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6553 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
6577 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); | 6554 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc
h.join("&")); |
6578 } | 6555 } |
6579 if ("setUninstallURL" in chrome.runtime) | 6556 if ("setUninstallURL" in chrome.runtime) |
6580 { | 6557 { |
6581 Prefs.untilLoaded.then(setUninstallURL); | 6558 Prefs.untilLoaded.then(setUninstallURL); |
6582 Prefs.on("notificationdata", setUninstallURL); | 6559 Prefs.on("notificationdata", setUninstallURL); |
6583 } | 6560 } |
6584 return exports; | 6561 return exports; |
6585 })(); | 6562 })(); |
OLD | NEW |