mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-13 02:14:17 +01:00
this fixes #832
This commit is contained in:
parent
c036bd320f
commit
892913d185
7 changed files with 123 additions and 73 deletions
10
platform/chromium/managed_storage.json
Normal file
10
platform/chromium/managed_storage.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,5 +66,8 @@
|
||||||
"http://*/*",
|
"http://*/*",
|
||||||
"https://*/*"
|
"https://*/*"
|
||||||
],
|
],
|
||||||
"short_name": "uBlock₀"
|
"short_name": "uBlock₀",
|
||||||
|
"storage": {
|
||||||
|
"managed_schema": "managed_storage.json"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -247,32 +247,35 @@ var fromFetch = function(to, fetched) {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
// https://github.com/gorhill/uBlock/issues/531
|
|
||||||
µb.restoreAdminSettings();
|
|
||||||
|
|
||||||
// Forbid remote fetching of assets
|
var onAdminSettingsRestored = function() {
|
||||||
µb.assets.remoteFetchBarrier += 1;
|
// Forbid remote fetching of assets
|
||||||
|
µb.assets.remoteFetchBarrier += 1;
|
||||||
|
|
||||||
var fetchableProps = {
|
var fetchableProps = {
|
||||||
'compiledMagic': '',
|
'compiledMagic': '',
|
||||||
'dynamicFilteringString': '',
|
'dynamicFilteringString': '',
|
||||||
'urlFilteringString': '',
|
'urlFilteringString': '',
|
||||||
'hostnameSwitchesString': '',
|
'hostnameSwitchesString': '',
|
||||||
'lastRestoreFile': '',
|
'lastRestoreFile': '',
|
||||||
'lastRestoreTime': 0,
|
'lastRestoreTime': 0,
|
||||||
'lastBackupFile': '',
|
'lastBackupFile': '',
|
||||||
'lastBackupTime': 0,
|
'lastBackupTime': 0,
|
||||||
'netWhitelist': '',
|
'netWhitelist': '',
|
||||||
'selfie': null,
|
'selfie': null,
|
||||||
'selfieMagic': '',
|
'selfieMagic': '',
|
||||||
'version': '0.0.0.0'
|
'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);
|
// https://github.com/gorhill/uBlock/issues/531
|
||||||
toFetch(µb.userSettings, fetchableProps);
|
µb.restoreAdminSettings(onAdminSettingsRestored);
|
||||||
toFetch(µb.restoreBackupSettings, fetchableProps);
|
|
||||||
|
|
||||||
vAPI.storage.get(fetchableProps, onFirstFetchReady);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -725,69 +725,76 @@
|
||||||
// necessarily present, i.e. administrators may removed entries which
|
// necessarily present, i.e. administrators may removed entries which
|
||||||
// values are left to the user's choice.
|
// values are left to the user's choice.
|
||||||
|
|
||||||
µBlock.restoreAdminSettings = function() {
|
µBlock.restoreAdminSettings = function(callback) {
|
||||||
var data = null;
|
var onRead = function(json) {
|
||||||
var json = vAPI.localStorage.getItem('adminSettings');
|
var µb = µBlock;
|
||||||
if ( typeof json === 'string' && json !== '' ) {
|
var data;
|
||||||
try {
|
if ( typeof json === 'string' && json !== '' ) {
|
||||||
data = JSON.parse(json);
|
try {
|
||||||
} catch (ex) {
|
data = JSON.parse(json);
|
||||||
console.error(ex);
|
} catch (ex) {
|
||||||
|
console.error(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( typeof data !== 'object' || data === null ) {
|
if ( typeof data !== 'object' || data === null ) {
|
||||||
return;
|
callback();
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var bin = {};
|
var bin = {};
|
||||||
var binNotEmpty = false;
|
var binNotEmpty = false;
|
||||||
|
|
||||||
if ( typeof data.userSettings === 'object' ) {
|
if ( typeof data.userSettings === 'object' ) {
|
||||||
for ( var name in this.userSettings ) {
|
for ( var name in µb.userSettings ) {
|
||||||
if ( this.userSettings.hasOwnProperty(name) === false ) {
|
if ( µb.userSettings.hasOwnProperty(name) === false ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
if ( data.userSettings.hasOwnProperty(name) === false ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bin[name] = data.userSettings[name];
|
||||||
|
binNotEmpty = true;
|
||||||
}
|
}
|
||||||
if ( data.userSettings.hasOwnProperty(name) === false ) {
|
}
|
||||||
continue;
|
|
||||||
}
|
if ( typeof data.filterLists === 'object' ) {
|
||||||
bin[name] = data.userSettings[name];
|
bin.remoteBlacklists = data.filterLists;
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( typeof data.filterLists === 'object' ) {
|
if ( typeof data.netWhitelist === 'string' ) {
|
||||||
bin.remoteBlacklists = data.filterLists;
|
bin.netWhitelist = data.netWhitelist;
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof data.netWhitelist === 'string' ) {
|
if ( typeof data.dynamicFilteringString === 'string' ) {
|
||||||
bin.netWhitelist = data.netWhitelist;
|
bin.dynamicFilteringString = data.dynamicFilteringString;
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof data.dynamicFilteringString === 'string' ) {
|
if ( typeof data.urlFilteringString === 'string' ) {
|
||||||
bin.dynamicFilteringString = data.dynamicFilteringString;
|
bin.urlFilteringString = data.urlFilteringString;
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof data.urlFilteringString === 'string' ) {
|
if ( typeof data.hostnameSwitchesString === 'string' ) {
|
||||||
bin.urlFilteringString = data.urlFilteringString;
|
bin.hostnameSwitchesString = data.hostnameSwitchesString;
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof data.hostnameSwitchesString === 'string' ) {
|
if ( binNotEmpty ) {
|
||||||
bin.hostnameSwitchesString = data.hostnameSwitchesString;
|
vAPI.storage.set(bin);
|
||||||
binNotEmpty = true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( binNotEmpty ) {
|
if ( typeof data.userFilters === 'string' ) {
|
||||||
vAPI.storage.set(bin);
|
µb.assets.put('assets/user/filters.txt', data.userFilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof data.userFilters === 'string' ) {
|
callback();
|
||||||
this.assets.put('assets/user/filters.txt', data.userFilters);
|
};
|
||||||
}
|
|
||||||
|
vAPI.adminStorage.getItem('adminSettings', onRead);
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -22,7 +22,7 @@ cp src/*.html $DES/
|
||||||
cp platform/chromium/*.js $DES/js/
|
cp platform/chromium/*.js $DES/js/
|
||||||
cp -R platform/chromium/img $DES/
|
cp -R platform/chromium/img $DES/
|
||||||
cp platform/chromium/*.html $DES/
|
cp platform/chromium/*.html $DES/
|
||||||
cp platform/chromium/manifest.json $DES/
|
cp platform/chromium/*.json $DES/
|
||||||
cp LICENSE.txt $DES/
|
cp LICENSE.txt $DES/
|
||||||
|
|
||||||
if [ "$1" = all ]; then
|
if [ "$1" = all ]; then
|
||||||
|
|
Loading…
Reference in a new issue