mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02: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",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"adminSettings": {
|
"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.",
|
"description": "All entries present will overwrite local settings.",
|
||||||
"type": "string"
|
"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 = (( ) => {
|
vAPI.adminStorage = (( ) => {
|
||||||
if ( webext.storage.managed instanceof Object === false ) {
|
if ( webext.storage.managed instanceof Object === false ) {
|
||||||
return {
|
return {
|
||||||
getItem: function() {
|
get: function() {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
getItem: async function(key) {
|
get: async function(key) {
|
||||||
let bin;
|
let bin;
|
||||||
try {
|
try {
|
||||||
bin = await webext.storage.managed.get(key);
|
bin = await webext.storage.managed.get(key);
|
||||||
|
@ -133,11 +133,24 @@ const onVersionReady = function(lastVersion) {
|
|||||||
// Whitelist in memory.
|
// Whitelist in memory.
|
||||||
// Whitelist parser needs PSL to be ready.
|
// Whitelist parser needs PSL to be ready.
|
||||||
// gorhill 2014-12-15: not anymore
|
// 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' ) {
|
if ( typeof netWhitelistRaw === 'string' ) {
|
||||||
netWhitelistRaw = netWhitelistRaw.split('\n');
|
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.netWhitelist = µb.whitelistFromArray(netWhitelistRaw);
|
||||||
µb.netWhitelistModifyTime = Date.now();
|
µ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
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/507
|
||||||
// Firefox-specific: somehow `fetched` is undefined under certain
|
// Firefox-specific: somehow `fetched` is undefined under certain
|
||||||
// circumstances even though we asked to load with default values.
|
// circumstances even though we asked to load with default values.
|
||||||
@ -202,7 +215,7 @@ const onFirstFetchReady = function(fetched) {
|
|||||||
fromFetch(µb.localSettings, fetched);
|
fromFetch(µb.localSettings, fetched);
|
||||||
onUserSettingsReady(fetched);
|
onUserSettingsReady(fetched);
|
||||||
fromFetch(µb.restoreBackupSettings, fetched);
|
fromFetch(µb.restoreBackupSettings, fetched);
|
||||||
onNetWhitelistReady(fetched.netWhitelist);
|
onNetWhitelistReady(fetched.netWhitelist, adminExtra);
|
||||||
onVersionReady(fetched.version);
|
onVersionReady(fetched.version);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -283,6 +296,11 @@ try {
|
|||||||
);
|
);
|
||||||
log.info(`Backend storage for cache will be ${cacheBackend}`);
|
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
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1365
|
||||||
// Wait for onCacheSettingsReady() to be fully ready.
|
// Wait for onCacheSettingsReady() to be fully ready.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@ -297,7 +315,7 @@ try {
|
|||||||
}),
|
}),
|
||||||
vAPI.storage.get(createDefaultProps()).then(fetched => {
|
vAPI.storage.get(createDefaultProps()).then(fetched => {
|
||||||
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
|
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||||
onFirstFetchReady(fetched);
|
onFirstFetchReady(fetched, adminExtra);
|
||||||
}),
|
}),
|
||||||
µb.loadPublicSuffixList().then(( ) => {
|
µb.loadPublicSuffixList().then(( ) => {
|
||||||
log.info(`PSL ready ${Date.now()-vAPI.T0} ms after launch`);
|
log.info(`PSL ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||||
|
@ -1224,7 +1224,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
µBlock.restoreAdminSettings = async function() {
|
µBlock.restoreAdminSettings = async function() {
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
const json = await vAPI.adminStorage.getItem('adminSettings');
|
const json = await vAPI.adminStorage.get('adminSettings');
|
||||||
if ( typeof json === 'string' && json !== '' ) {
|
if ( typeof json === 'string' && json !== '' ) {
|
||||||
data = JSON.parse(json);
|
data = JSON.parse(json);
|
||||||
} else if ( json instanceof Object ) {
|
} else if ( json instanceof Object ) {
|
||||||
|
@ -70,7 +70,13 @@ CodeMirror.defineMode("ubo-whitelist-directives", function() {
|
|||||||
}
|
}
|
||||||
return null;
|
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