| Index: lib/adblockplus.js |
| =================================================================== |
| --- a/lib/adblockplus.js |
| +++ b/lib/adblockplus.js |
| @@ -357,30 +357,60 @@ |
| return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); |
| } |
| - function loadFile(file, successCallback, errorCallback) |
| - { |
| - var key = fileToKey(file); |
| - ext.storage.get([key], function(items) |
| - { |
| - var entry = items[key]; |
| - if (entry) |
| - { |
| - successCallback(entry); |
| - } |
| - else |
| - { |
| - errorCallback(new Error("File doesn't exist")); |
| - } |
| - }); |
| + function loadFile(file) |
| + { |
| + return new Promise(function(resolve, reject) |
| + { |
| + var key = fileToKey(file); |
| + ext.storage.get([key], function(items) |
| + { |
| + var entry = items[key]; |
| + if (!entry) |
| + { |
| + try |
| + { |
| + entry = JSON.parse(window.localStorage.getItem(key)); |
| + } |
| + catch (err) |
| + {} |
| + } |
| + if (entry) |
| + { |
| + resolve(entry); |
| + } |
| + else |
| + { |
| + reject(new Error("File doesn't exist")); |
| + } |
| + }); |
| + }.bind(this)); |
| } |
| function saveFile(file, data, callback) |
| { |
| - ext.storage.set(fileToKey(file), |
| - { |
| - content: data, |
| - lastModified: Date.now() |
| - }, callback); |
| + var entry = {}; |
| + var key = fileToKey(file); |
| + |
| + if (typeof browser == "undefined") |
| + { |
| + entry[key] = { |
| + lastModified: Date.now(), |
| + content: data |
| + }; |
| + ext.storage.set(entry, callback); |
| + } |
| + else |
| + { |
| + var processedData = LZString.compressToUTF16(JSON.stringify(data)); |
| + ext.storage.remove(key); |
| + entry[key] = { |
| + lastModified: Date.now(), |
| + content: processedData, |
| + compressed: true |
| + }; |
| + window.localStorage.setItem(key, JSON.stringify(entry[key])); |
| + setTimeout(callback, 0); |
| + } |
| } |
| exports.IO = { |
| resolveFilePath: function(path) |
| @@ -391,15 +421,21 @@ |
| { |
| function onLoaded(entry) |
| { |
| - for (var _loopIndex1 = 0; _loopIndex1 < entry.content.length; ++_loopIndex1) |
| - { |
| - var line = entry.content[_loopIndex1]; |
| - listener.process(line); |
| - } |
| - listener.process(null); |
| + if ("content" in entry) |
| + { |
| + if ("compressed" in entry) |
| + { |
| + entry.content = JSON.parse(LZString.decompressFromUTF16(entry.content)); |
| + } |
| + for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loopIndex15) |
| + { |
| + var line = entry.content[_loopIndex15]; |
| + listener.process(line); |
| + } |
| + } |
| callback(null); |
| } |
| - loadFile(file, onLoaded, callback); |
| + loadFile(file).then(onLoaded, callback); |
| }, |
| writeToFile: function(file, data, callback) |
| { |
| @@ -411,7 +447,7 @@ |
| { |
| saveFile(toFile, entry.content, callback); |
| } |
| - loadFile(fromFile, onLoaded, callback); |
| + loadFile(file).then(onLoaded, callback); |
| }, |
| renameFile: function(fromFile, newName, callback) |
| { |
| @@ -422,7 +458,7 @@ |
| ext.storage.set(keyPrefix + newName, entry, callback); |
| }); |
| } |
| - loadFile(fromFile, onLoaded, callback); |
| + loadFile(file).then(onLoaded, callback); |
| }, |
| removeFile: function(file, callback) |
| { |
| @@ -438,7 +474,7 @@ |
| lastModified: entry.lastModified |
| }); |
| } |
| - loadFile(file, onLoaded, callback); |
| + loadFile(file).then(onLoaded, callback); |
| } |
| }; |
| return exports; |