mirror of https://github.com/gorhill/uBlock.git
necessary changes for https://github.com/nikrolls/uBlock-Edge/pull/22
This commit is contained in:
parent
de587335bd
commit
3628de7a9d
|
@ -58,6 +58,7 @@ vAPI.app.restart = function() {
|
||||||
// chrome.storage.local.get(null, function(bin){ console.debug('%o', bin); });
|
// chrome.storage.local.get(null, function(bin){ console.debug('%o', bin); });
|
||||||
|
|
||||||
vAPI.storage = chrome.storage.local;
|
vAPI.storage = chrome.storage.local;
|
||||||
|
vAPI.cacheStorage = chrome.storage.local;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -618,6 +618,8 @@ vAPI.storage = (function() {
|
||||||
return api;
|
return api;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
vAPI.cacheStorage = vAPI.storage;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// This must be executed/setup early.
|
// This must be executed/setup early.
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
/* global YaMD5 */
|
/* global YaMD5 */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
File system structure:
|
File system structure:
|
||||||
|
@ -41,8 +43,6 @@ File system structure:
|
||||||
|
|
||||||
µBlock.assets = (function() {
|
µBlock.assets = (function() {
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var oneSecond = 1000;
|
var oneSecond = 1000;
|
||||||
|
@ -120,7 +120,7 @@ var cachedAssetsManager = (function() {
|
||||||
var currentVersion = vAPI.app.version;
|
var currentVersion = vAPI.app.version;
|
||||||
var lastVersion = store.extensionLastVersion || '0.0.0.0';
|
var lastVersion = store.extensionLastVersion || '0.0.0.0';
|
||||||
if ( currentVersion !== lastVersion ) {
|
if ( currentVersion !== lastVersion ) {
|
||||||
vAPI.storage.set({ 'extensionLastVersion': currentVersion });
|
vAPI.cacheStorage.set({ 'extensionLastVersion': currentVersion });
|
||||||
}
|
}
|
||||||
callback(entries);
|
callback(entries);
|
||||||
};
|
};
|
||||||
|
@ -138,9 +138,9 @@ var cachedAssetsManager = (function() {
|
||||||
}
|
}
|
||||||
entries = bin.cached_asset_entries || {};
|
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;
|
exports.entries = getEntries;
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ var cachedAssetsManager = (function() {
|
||||||
cbError(details);
|
cbError(details);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vAPI.storage.get(cachedContentPath, onLoaded);
|
vAPI.cacheStorage.get(cachedContentPath, onLoaded);
|
||||||
};
|
};
|
||||||
getEntries(onEntries);
|
getEntries(onEntries);
|
||||||
};
|
};
|
||||||
|
@ -221,7 +221,7 @@ var cachedAssetsManager = (function() {
|
||||||
}
|
}
|
||||||
entries[path] = Date.now();
|
entries[path] = Date.now();
|
||||||
bin.cached_asset_entries = entries;
|
bin.cached_asset_entries = entries;
|
||||||
vAPI.storage.set(bin, onSaved);
|
vAPI.cacheStorage.set(bin, onSaved);
|
||||||
};
|
};
|
||||||
getEntries(onEntries);
|
getEntries(onEntries);
|
||||||
};
|
};
|
||||||
|
@ -249,8 +249,8 @@ var cachedAssetsManager = (function() {
|
||||||
delete entries[path];
|
delete entries[path];
|
||||||
}
|
}
|
||||||
if ( keystoRemove.length ) {
|
if ( keystoRemove.length ) {
|
||||||
vAPI.storage.remove(keystoRemove);
|
vAPI.cacheStorage.remove(keystoRemove);
|
||||||
vAPI.storage.set({ 'cached_asset_entries': entries });
|
vAPI.cacheStorage.set({ 'cached_asset_entries': entries });
|
||||||
if ( typeof exports.onRemovedListener === 'function' ) {
|
if ( typeof exports.onRemovedListener === 'function' ) {
|
||||||
exports.onRemovedListener(removedItems);
|
exports.onRemovedListener(removedItems);
|
||||||
}
|
}
|
||||||
|
@ -1017,19 +1017,38 @@ var readExternalAsset = function(path, callback) {
|
||||||
// Cache --> whatever user saved
|
// Cache --> whatever user saved
|
||||||
|
|
||||||
var readUserAsset = function(path, callback) {
|
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) {
|
var onCachedContentLoaded = function(details) {
|
||||||
|
saveUserAsset(path, details.content);
|
||||||
//console.log('µBlock.assets/readUserAsset("%s")/onCachedContentLoaded()', path);
|
//console.log('µBlock.assets/readUserAsset("%s")/onCachedContentLoaded()', path);
|
||||||
callback({ 'path': path, 'content': details.content });
|
callback({ 'path': path, 'content': details.content });
|
||||||
};
|
};
|
||||||
|
|
||||||
var onCachedContentError = function() {
|
var onCachedContentError = function() {
|
||||||
|
saveUserAsset(path, '');
|
||||||
//console.log('µBlock.assets/readUserAsset("%s")/onCachedContentError()', path);
|
//console.log('µBlock.assets/readUserAsset("%s")/onCachedContentError()', path);
|
||||||
callback({ 'path': path, 'content': '' });
|
callback({ 'path': path, 'content': '' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var onLoaded = function(bin) {
|
||||||
|
var content = bin && bin[path];
|
||||||
|
if ( typeof content === 'string' ) {
|
||||||
|
callback({ 'path': path, 'content': content });
|
||||||
|
return;
|
||||||
|
}
|
||||||
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// Asset available only from the cache.
|
// Asset available only from the cache.
|
||||||
|
@ -1136,6 +1155,11 @@ exports.getLocal = readLocalFile;
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
exports.put = function(path, content, callback) {
|
exports.put = function(path, content, callback) {
|
||||||
|
if ( reIsUserPath.test(path) ) {
|
||||||
|
saveUserAsset(path, content, callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cachedAssetsManager.save(path, content, callback);
|
cachedAssetsManager.save(path, content, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1279,8 +1303,6 @@ return exports;
|
||||||
|
|
||||||
µBlock.assetUpdater = (function() {
|
µBlock.assetUpdater = (function() {
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var µb = µBlock;
|
var µb = µBlock;
|
||||||
|
|
|
@ -813,10 +813,12 @@ var restoreUserData = function(request) {
|
||||||
|
|
||||||
// If we are going to restore all, might as well wipe out clean local
|
// If we are going to restore all, might as well wipe out clean local
|
||||||
// storage
|
// storage
|
||||||
|
vAPI.cacheStorage.clear();
|
||||||
vAPI.storage.clear(onAllRemoved);
|
vAPI.storage.clear(onAllRemoved);
|
||||||
};
|
};
|
||||||
|
|
||||||
var resetUserData = function() {
|
var resetUserData = function() {
|
||||||
|
vAPI.cacheStorage.clear();
|
||||||
vAPI.storage.clear();
|
vAPI.storage.clear();
|
||||||
|
|
||||||
// Keep global counts, people can become quite attached to numbers
|
// Keep global counts, people can become quite attached to numbers
|
||||||
|
|
|
@ -767,7 +767,7 @@
|
||||||
cosmeticFilteringEngine: µb.cosmeticFilteringEngine.toSelfie()
|
cosmeticFilteringEngine: µb.cosmeticFilteringEngine.toSelfie()
|
||||||
};
|
};
|
||||||
|
|
||||||
vAPI.storage.set({ selfie: selfie });
|
vAPI.cacheStorage.set({ selfie: selfie });
|
||||||
};
|
};
|
||||||
|
|
||||||
var createAsync = function(after) {
|
var createAsync = function(after) {
|
||||||
|
@ -788,7 +788,7 @@
|
||||||
timer = null;
|
timer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
vAPI.storage.remove('selfie');
|
vAPI.cacheStorage.remove('selfie');
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue