1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-20 01:12:38 +01:00

[mv3] Handle permissions being revoked while uBOL is disabled

This commit is contained in:
Raymond Hill 2022-10-18 08:48:31 -04:00
parent 8aa379ef9e
commit b4c63f6ae5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 36 additions and 17 deletions

View File

@ -50,7 +50,7 @@ import {
setFilteringMode,
getDefaultFilteringMode,
setDefaultFilteringMode,
syncWithDemotedOrigins,
syncWithBrowserPermissions,
} from './mode-manager.js';
/******************************************************************************/
@ -154,13 +154,15 @@ function hasOmnipotence() {
});
}
function onPermissionsRemoved(permissions) {
if ( permissions.origins?.includes('<all_urls>') ) {
async function onPermissionsRemoved() {
const beforeMode = await getDefaultFilteringMode();
const modified = await syncWithBrowserPermissions();
if ( modified === false ) { return; }
const afterMode = await getDefaultFilteringMode();
if ( beforeMode > 1 && afterMode <= 1 ) {
updateDynamicRules();
}
syncWithDemotedOrigins(permissions.origins).then(( ) => {
registerInjectables(permissions.origins);
});
registerInjectables();
}
/******************************************************************************/
@ -287,6 +289,9 @@ async function start() {
});
}
// Permissions may have been removed while the extension was disabled
await onPermissionsRemoved();
// Unsure whether the browser remembers correctly registered css/scripts
// after we quit the browser. For now uBOL will check unconditionally at
// launch time whether content css/scripts are properly registered.
@ -307,7 +312,9 @@ async function start() {
runtime.onMessage.addListener(onMessage);
browser.permissions.onRemoved.addListener(onPermissionsRemoved);
browser.permissions.onRemoved.addListener(
( ) => { onPermissionsRemoved(); }
);
if ( rulesetConfig.firstRun ) {
runtime.openOptionsPage();

View File

@ -25,7 +25,10 @@
/******************************************************************************/
import { dnr } from './ext.js';
import {
browser,
dnr,
} from './ext.js';
import {
hostnamesFromMatches,
@ -326,22 +329,31 @@ async function setDefaultFilteringMode(afterLevel) {
/******************************************************************************/
async function syncWithDemotedOrigins(demotedOrigins) {
const demotedHostnames = new Set(hostnamesFromMatches(demotedOrigins));
if ( demotedHostnames.has('all-urls') ) {
async function syncWithBrowserPermissions() {
const permissions = await browser.permissions.getAll();
const allowedHostnames = new Set(hostnamesFromMatches(permissions.origins || []));
const beforeMode = await getDefaultFilteringMode();
let modified = false;
if ( beforeMode > 1 && allowedHostnames.has('all-urls') === false ) {
await setDefaultFilteringMode(1);
modified = true;
}
const afterMode = await getDefaultFilteringMode();
if ( afterMode > 1 ) { return false; }
const filteringModes = await getFilteringModeDetails();
const { extendedSpecific, extendedGeneric } = filteringModes;
for ( const hn of extendedSpecific ) {
if ( demotedHostnames.has(hn) === false ) { continue; }
if ( allowedHostnames.has(hn) ) { continue; }
extendedSpecific.delete(hn);
modified = true;
}
for ( const hn of extendedGeneric ) {
if ( demotedHostnames.has(hn) === false ) { continue; }
if ( allowedHostnames.has(hn) ) { continue; }
extendedGeneric.delete(hn);
modified = true;
}
return setFilteringModeDetails(filteringModes);
await setFilteringModeDetails(filteringModes);
return modified;
}
/******************************************************************************/
@ -362,5 +374,5 @@ export {
setDefaultFilteringMode,
getFilteringModeDetails,
getAllTrustedSiteDirectives,
syncWithDemotedOrigins,
syncWithBrowserPermissions,
};

View File

@ -28,8 +28,8 @@
/******************************************************************************/
/// name no-windowOpen-if
/// alias no-windowopen-if
/// name no-windowopen-if
/// alias no-windowOpen-if
/// alias nowoif
/******************************************************************************/