This commit is contained in:
gorhill 2015-10-21 11:53:03 -04:00
parent c036bd320f
commit 892913d185
7 changed files with 123 additions and 73 deletions

View File

@ -0,0 +1,10 @@
{
"type": "object",
"properties": {
"adminSettings": {
"title": "A valid JSON string compliant with uBO's backup format.",
"description": "All entries present will overwrite local settings.",
"type": "string"
}
}
}

View File

@ -66,5 +66,8 @@
"http://*/*",
"https://*/*"
],
"short_name": "uBlock₀"
"short_name": "uBlock₀",
"storage": {
"managed_schema": "managed_storage.json"
}
}

View File

@ -98,6 +98,19 @@ try {
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/531
// Storage area dedicated to admin settings. Read-only.
vAPI.adminStorage = {
getItem: function(key, callback) {
chrome.storage.managed.get(key, function(store) {
callback(store[key] || undefined);
});
}
};
/******************************************************************************/
})();
/******************************************************************************/

View File

@ -181,6 +181,20 @@ vAPI.localStorage.init('extensions.' + location.host + '.');
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/531
// Storage area dedicated to admin settings. Read-only.
vAPI.adminStorage = {
getItem: function(key, callback) {
if ( typeof callback !== 'function' ) {
return;
}
callback(vAPI.localStorage.getItem(key));
}
};
/******************************************************************************/
})();
/******************************************************************************/

View File

@ -247,32 +247,35 @@ var fromFetch = function(to, fetched) {
/******************************************************************************/
return function() {
// https://github.com/gorhill/uBlock/issues/531
µb.restoreAdminSettings();
// Forbid remote fetching of assets
µb.assets.remoteFetchBarrier += 1;
var onAdminSettingsRestored = function() {
// Forbid remote fetching of assets
µb.assets.remoteFetchBarrier += 1;
var fetchableProps = {
'compiledMagic': '',
'dynamicFilteringString': '',
'urlFilteringString': '',
'hostnameSwitchesString': '',
'lastRestoreFile': '',
'lastRestoreTime': 0,
'lastBackupFile': '',
'lastBackupTime': 0,
'netWhitelist': '',
'selfie': null,
'selfieMagic': '',
'version': '0.0.0.0'
var fetchableProps = {
'compiledMagic': '',
'dynamicFilteringString': '',
'urlFilteringString': '',
'hostnameSwitchesString': '',
'lastRestoreFile': '',
'lastRestoreTime': 0,
'lastBackupFile': '',
'lastBackupTime': 0,
'netWhitelist': '',
'selfie': null,
'selfieMagic': '',
'version': '0.0.0.0'
};
toFetch(µb.localSettings, fetchableProps);
toFetch(µb.userSettings, fetchableProps);
toFetch(µb.restoreBackupSettings, fetchableProps);
vAPI.storage.get(fetchableProps, onFirstFetchReady);
};
toFetch(µb.localSettings, fetchableProps);
toFetch(µb.userSettings, fetchableProps);
toFetch(µb.restoreBackupSettings, fetchableProps);
vAPI.storage.get(fetchableProps, onFirstFetchReady);
// https://github.com/gorhill/uBlock/issues/531
µb.restoreAdminSettings(onAdminSettingsRestored);
};
/******************************************************************************/

View File

@ -725,69 +725,76 @@
// necessarily present, i.e. administrators may removed entries which
// values are left to the user's choice.
µBlock.restoreAdminSettings = function() {
var data = null;
var json = vAPI.localStorage.getItem('adminSettings');
if ( typeof json === 'string' && json !== '' ) {
try {
data = JSON.parse(json);
} catch (ex) {
console.error(ex);
µBlock.restoreAdminSettings = function(callback) {
var onRead = function(json) {
var µb = µBlock;
var data;
if ( typeof json === 'string' && json !== '' ) {
try {
data = JSON.parse(json);
} catch (ex) {
console.error(ex);
}
}
}
if ( typeof data !== 'object' || data === null ) {
return;
}
if ( typeof data !== 'object' || data === null ) {
callback();
return;
}
var bin = {};
var binNotEmpty = false;
var bin = {};
var binNotEmpty = false;
if ( typeof data.userSettings === 'object' ) {
for ( var name in this.userSettings ) {
if ( this.userSettings.hasOwnProperty(name) === false ) {
continue;
if ( typeof data.userSettings === 'object' ) {
for ( var name in µb.userSettings ) {
if ( µb.userSettings.hasOwnProperty(name) === false ) {
continue;
}
if ( data.userSettings.hasOwnProperty(name) === false ) {
continue;
}
bin[name] = data.userSettings[name];
binNotEmpty = true;
}
if ( data.userSettings.hasOwnProperty(name) === false ) {
continue;
}
bin[name] = data.userSettings[name];
}
if ( typeof data.filterLists === 'object' ) {
bin.remoteBlacklists = data.filterLists;
binNotEmpty = true;
}
}
if ( typeof data.filterLists === 'object' ) {
bin.remoteBlacklists = data.filterLists;
binNotEmpty = true;
}
if ( typeof data.netWhitelist === 'string' ) {
bin.netWhitelist = data.netWhitelist;
binNotEmpty = true;
}
if ( typeof data.netWhitelist === 'string' ) {
bin.netWhitelist = data.netWhitelist;
binNotEmpty = true;
}
if ( typeof data.dynamicFilteringString === 'string' ) {
bin.dynamicFilteringString = data.dynamicFilteringString;
binNotEmpty = true;
}
if ( typeof data.dynamicFilteringString === 'string' ) {
bin.dynamicFilteringString = data.dynamicFilteringString;
binNotEmpty = true;
}
if ( typeof data.urlFilteringString === 'string' ) {
bin.urlFilteringString = data.urlFilteringString;
binNotEmpty = true;
}
if ( typeof data.urlFilteringString === 'string' ) {
bin.urlFilteringString = data.urlFilteringString;
binNotEmpty = true;
}
if ( typeof data.hostnameSwitchesString === 'string' ) {
bin.hostnameSwitchesString = data.hostnameSwitchesString;
binNotEmpty = true;
}
if ( typeof data.hostnameSwitchesString === 'string' ) {
bin.hostnameSwitchesString = data.hostnameSwitchesString;
binNotEmpty = true;
}
if ( binNotEmpty ) {
vAPI.storage.set(bin);
}
if ( binNotEmpty ) {
vAPI.storage.set(bin);
}
if ( typeof data.userFilters === 'string' ) {
µb.assets.put('assets/user/filters.txt', data.userFilters);
}
if ( typeof data.userFilters === 'string' ) {
this.assets.put('assets/user/filters.txt', data.userFilters);
}
callback();
};
vAPI.adminStorage.getItem('adminSettings', onRead);
};
/******************************************************************************/

View File

@ -22,7 +22,7 @@ cp src/*.html $DES/
cp platform/chromium/*.js $DES/js/
cp -R platform/chromium/img $DES/
cp platform/chromium/*.html $DES/
cp platform/chromium/manifest.json $DES/
cp platform/chromium/*.json $DES/
cp LICENSE.txt $DES/
if [ "$1" = all ]; then