mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-22 18:32:45 +01:00
Add "extraTrustedSiteDirectives" as new admin policy
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1433 The new "extraTrustedSiteDirectives" policy is an array of strings, each of which is parsed as a trusted-site directive to append to a user's own set of trusted-site directives at launch time. The added trusted-site directives will be considered as part of the default set of directives by uBO.
This commit is contained in:
parent
ced4330d74
commit
b28acfccbc
@ -3,9 +3,17 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"adminSettings": {
|
||||
"title": "A valid JSON string compliant with uBO's backup format.",
|
||||
"title": "A valid JSON string compliant with uBO's backup format",
|
||||
"description": "All entries present will overwrite local settings.",
|
||||
"type": "string"
|
||||
},
|
||||
"extraTrustedSiteDirectives": {
|
||||
"title": "A list of trusted-site directives",
|
||||
"description": "Trusted-site directives to always add at launch time.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1417,13 +1417,13 @@ vAPI.commands = browser.commands;
|
||||
vAPI.adminStorage = (( ) => {
|
||||
if ( webext.storage.managed instanceof Object === false ) {
|
||||
return {
|
||||
getItem: function() {
|
||||
get: function() {
|
||||
return Promise.resolve();
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
getItem: async function(key) {
|
||||
get: async function(key) {
|
||||
let bin;
|
||||
try {
|
||||
bin = await webext.storage.managed.get(key);
|
||||
|
@ -133,11 +133,24 @@ const onVersionReady = function(lastVersion) {
|
||||
// Whitelist in memory.
|
||||
// Whitelist parser needs PSL to be ready.
|
||||
// gorhill 2014-12-15: not anymore
|
||||
//
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/1433
|
||||
// Allow admins to add their own trusted-site directives.
|
||||
|
||||
const onNetWhitelistReady = function(netWhitelistRaw) {
|
||||
const onNetWhitelistReady = function(netWhitelistRaw, adminExtra) {
|
||||
if ( typeof netWhitelistRaw === 'string' ) {
|
||||
netWhitelistRaw = netWhitelistRaw.split('\n');
|
||||
}
|
||||
// Append admin-controlled trusted-site directives
|
||||
if (
|
||||
Array.isArray(adminExtra.trustedSites) &&
|
||||
adminExtra.trustedSites.length !== 0
|
||||
) {
|
||||
for ( const directive of adminExtra.trustedSites ) {
|
||||
µb.netWhitelistDefault.push(directive);
|
||||
netWhitelistRaw.push(directive);
|
||||
}
|
||||
}
|
||||
µb.netWhitelist = µb.whitelistFromArray(netWhitelistRaw);
|
||||
µb.netWhitelistModifyTime = Date.now();
|
||||
};
|
||||
@ -190,7 +203,7 @@ const onCacheSettingsReady = async function(fetched) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
const onFirstFetchReady = function(fetched) {
|
||||
const onFirstFetchReady = function(fetched, adminExtra) {
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/507
|
||||
// Firefox-specific: somehow `fetched` is undefined under certain
|
||||
// circumstances even though we asked to load with default values.
|
||||
@ -202,7 +215,7 @@ const onFirstFetchReady = function(fetched) {
|
||||
fromFetch(µb.localSettings, fetched);
|
||||
onUserSettingsReady(fetched);
|
||||
fromFetch(µb.restoreBackupSettings, fetched);
|
||||
onNetWhitelistReady(fetched.netWhitelist);
|
||||
onNetWhitelistReady(fetched.netWhitelist, adminExtra);
|
||||
onVersionReady(fetched.version);
|
||||
};
|
||||
|
||||
@ -283,6 +296,11 @@ try {
|
||||
);
|
||||
log.info(`Backend storage for cache will be ${cacheBackend}`);
|
||||
|
||||
const adminExtra = {};
|
||||
adminExtra.trustedSites =
|
||||
await vAPI.adminStorage.get('extraTrustedSiteDirectives') || [];
|
||||
log.info(`Extra admin settings ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/1365
|
||||
// Wait for onCacheSettingsReady() to be fully ready.
|
||||
await Promise.all([
|
||||
@ -297,7 +315,7 @@ try {
|
||||
}),
|
||||
vAPI.storage.get(createDefaultProps()).then(fetched => {
|
||||
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
onFirstFetchReady(fetched);
|
||||
onFirstFetchReady(fetched, adminExtra);
|
||||
}),
|
||||
µb.loadPublicSuffixList().then(( ) => {
|
||||
log.info(`PSL ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
|
@ -1224,7 +1224,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||
µBlock.restoreAdminSettings = async function() {
|
||||
let data;
|
||||
try {
|
||||
const json = await vAPI.adminStorage.getItem('adminSettings');
|
||||
const json = await vAPI.adminStorage.get('adminSettings');
|
||||
if ( typeof json === 'string' && json !== '' ) {
|
||||
data = JSON.parse(json);
|
||||
} else if ( json instanceof Object ) {
|
||||
|
@ -70,7 +70,13 @@ CodeMirror.defineMode("ubo-whitelist-directives", function() {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return reHostnameExtractor.test(line) ? null : 'error';
|
||||
if ( reHostnameExtractor.test(line) === false ) {
|
||||
return 'error';
|
||||
}
|
||||
if ( whitelistDefaultSet.has(line.trim()) ) {
|
||||
return 'keyword';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user