diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 276a5d627..b540cb3c7 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -58,6 +58,7 @@ vAPI.app.restart = function() { // chrome.storage.local.get(null, function(bin){ console.debug('%o', bin); }); vAPI.storage = chrome.storage.local; +vAPI.cacheStorage = chrome.storage.local; /******************************************************************************/ /******************************************************************************/ diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 188ab1a6d..4a5b32c7e 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -618,6 +618,8 @@ vAPI.storage = (function() { return api; })(); +vAPI.cacheStorage = vAPI.storage; + /******************************************************************************/ // This must be executed/setup early. diff --git a/src/js/assets.js b/src/js/assets.js index db5414630..f993fbbd2 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -21,6 +21,8 @@ /* global YaMD5 */ +'use strict'; + /******************************************************************************* File system structure: @@ -41,8 +43,6 @@ File system structure: µBlock.assets = (function() { -'use strict'; - /******************************************************************************/ var oneSecond = 1000; @@ -120,7 +120,7 @@ var cachedAssetsManager = (function() { var currentVersion = vAPI.app.version; var lastVersion = store.extensionLastVersion || '0.0.0.0'; if ( currentVersion !== lastVersion ) { - vAPI.storage.set({ 'extensionLastVersion': currentVersion }); + vAPI.cacheStorage.set({ 'extensionLastVersion': currentVersion }); } callback(entries); }; @@ -138,9 +138,9 @@ var cachedAssetsManager = (function() { } entries = bin.cached_asset_entries || {}; } - vAPI.storage.get('extensionLastVersion', onLastVersionRead); + vAPI.cacheStorage.get('extensionLastVersion', onLastVersionRead); }; - vAPI.storage.get('cached_asset_entries', onLoaded); + vAPI.cacheStorage.get('cached_asset_entries', onLoaded); }; exports.entries = getEntries; @@ -179,7 +179,7 @@ var cachedAssetsManager = (function() { cbError(details); return; } - vAPI.storage.get(cachedContentPath, onLoaded); + vAPI.cacheStorage.get(cachedContentPath, onLoaded); }; getEntries(onEntries); }; @@ -221,7 +221,7 @@ var cachedAssetsManager = (function() { } entries[path] = Date.now(); bin.cached_asset_entries = entries; - vAPI.storage.set(bin, onSaved); + vAPI.cacheStorage.set(bin, onSaved); }; getEntries(onEntries); }; @@ -249,8 +249,8 @@ var cachedAssetsManager = (function() { delete entries[path]; } if ( keystoRemove.length ) { - vAPI.storage.remove(keystoRemove); - vAPI.storage.set({ 'cached_asset_entries': entries }); + vAPI.cacheStorage.remove(keystoRemove); + vAPI.cacheStorage.set({ 'cached_asset_entries': entries }); if ( typeof exports.onRemovedListener === 'function' ) { exports.onRemovedListener(removedItems); } @@ -1017,17 +1017,36 @@ var readExternalAsset = function(path, callback) { // Cache --> whatever user saved var readUserAsset = function(path, callback) { + // TODO: remove when confident all users no longer have their custom + // filters saved into vAPI.cacheStorage. var onCachedContentLoaded = function(details) { + saveUserAsset(path, details.content); //console.log('µBlock.assets/readUserAsset("%s")/onCachedContentLoaded()', path); callback({ 'path': path, 'content': details.content }); }; var onCachedContentError = function() { + saveUserAsset(path, ''); //console.log('µBlock.assets/readUserAsset("%s")/onCachedContentError()', path); callback({ 'path': path, 'content': '' }); }; - cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError); + var onLoaded = function(bin) { + var content = bin && bin[path]; + if ( typeof content === 'string' ) { + callback({ 'path': path, 'content': content }); + return; + } + cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError); + }; + + vAPI.storage.get(path, onLoaded); +}; + +var saveUserAsset = function(path, content, callback) { + var bin = {}; + bin[path] = content; + vAPI.storage.set(bin, callback); }; /******************************************************************************/ @@ -1136,6 +1155,11 @@ exports.getLocal = readLocalFile; /******************************************************************************/ exports.put = function(path, content, callback) { + if ( reIsUserPath.test(path) ) { + saveUserAsset(path, content, callback); + return; + } + cachedAssetsManager.save(path, content, callback); }; @@ -1279,8 +1303,6 @@ return exports; µBlock.assetUpdater = (function() { -'use strict'; - /******************************************************************************/ var µb = µBlock; diff --git a/src/js/messaging.js b/src/js/messaging.js index b5b441bf2..654c71f28 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -813,10 +813,12 @@ var restoreUserData = function(request) { // If we are going to restore all, might as well wipe out clean local // storage + vAPI.cacheStorage.clear(); vAPI.storage.clear(onAllRemoved); }; var resetUserData = function() { + vAPI.cacheStorage.clear(); vAPI.storage.clear(); // Keep global counts, people can become quite attached to numbers diff --git a/src/js/storage.js b/src/js/storage.js index c31aa1e3d..edb238976 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -767,7 +767,7 @@ cosmeticFilteringEngine: µb.cosmeticFilteringEngine.toSelfie() }; - vAPI.storage.set({ selfie: selfie }); + vAPI.cacheStorage.set({ selfie: selfie }); }; var createAsync = function(after) { @@ -788,7 +788,7 @@ timer = null; } - vAPI.storage.remove('selfie'); + vAPI.cacheStorage.remove('selfie'); }; return {