Bug 1693621 - Only clear temporary block permissions on user reload. r=johannh

Differential Revision: https://phabricator.services.mozilla.com/D106496
This commit is contained in:
Paul Zuehlcke 2021-03-12 10:06:15 +00:00
Родитель c08d590590
Коммит 5d2d56e536
5 изменённых файлов: 50 добавлений и 17 удалений

Просмотреть файл

@ -3539,7 +3539,7 @@ function BrowserReloadWithFlags(reloadFlags) {
// This is done here because we only want to reset // This is done here because we only want to reset
// permissions on user reload. // permissions on user reload.
for (let tab of unchangedRemoteness) { for (let tab of unchangedRemoteness) {
SitePermissions.clearTemporaryPermissions(tab.linkedBrowser); SitePermissions.clearTemporaryBlockPermissions(tab.linkedBrowser);
// Also reset DOS mitigations for the basic auth prompt on reload. // Also reset DOS mitigations for the basic auth prompt on reload.
delete tab.linkedBrowser.authPromptAbuseCounter; delete tab.linkedBrowser.authPromptAbuseCounter;
} }

Просмотреть файл

@ -4361,7 +4361,7 @@
let browser = this.getBrowserForTab(aTab); let browser = this.getBrowserForTab(aTab);
// Reset temporary permissions on the current tab. This is done here // Reset temporary permissions on the current tab. This is done here
// because we only want to reset permissions on user reload. // because we only want to reset permissions on user reload.
SitePermissions.clearTemporaryPermissions(browser); SitePermissions.clearTemporaryBlockPermissions(browser);
// Also reset DOS mitigations for the basic auth prompt on reload. // Also reset DOS mitigations for the basic auth prompt on reload.
delete browser.authPromptAbuseCounter; delete browser.authPromptAbuseCounter;
gIdentityHandler.hidePopup(); gIdentityHandler.hidePopup();

Просмотреть файл

@ -2391,7 +2391,7 @@ class UrlbarInput {
browser.currentURI && browser.currentURI &&
url === browser.currentURI.spec url === browser.currentURI.spec
) { ) {
this.window.SitePermissions.clearTemporaryPermissions(browser); this.window.SitePermissions.clearTemporaryBlockPermissions(browser);
} }
} }

Просмотреть файл

@ -240,21 +240,54 @@ const TemporaryPermissions = {
// Clears all permissions for the specified browser. // Clears all permissions for the specified browser.
// Unlike other methods, this does NOT clear only for // Unlike other methods, this does NOT clear only for
// the currentURI but the whole browser state. // the currentURI but the whole browser state.
clear(browser) {
let entry = this._stateByBrowser.get(browser);
this._stateByBrowser.delete(browser);
/**
* Clear temporary permissions for the specified browser. Unlike other
* methods, this does NOT clear only for the currentURI but the whole browser
* state.
* @param {Browser} browser - Browser to clear permissions for.
* @param {Number} [filterState] - Only clear permissions with the given state
* value. Defaults to all permissions.
*/
clear(browser, filterState = null) {
let entry = this._stateByBrowser.get(browser);
if (!entry?.uriToPerm) { if (!entry?.uriToPerm) {
return; return;
} }
Object.values(entry.uriToPerm).forEach(permissions => {
Object.values(permissions).forEach(({ expireTimeout }) => { let { uriToPerm } = entry;
Object.entries(uriToPerm).forEach(([uriKey, permissions]) => {
Object.entries(permissions).forEach(
([permId, { state, expireTimeout }]) => {
// We need to explicitly check for null or undefined here, because the
// permission state may be 0.
if (filterState != null) {
if (state != filterState) {
// Skip permission entry if it doesn't match the filter.
return;
}
delete permissions[permId];
}
// For the clear-all case we remove the entire browser entry, so we
// only need to clear the timeouts.
if (!expireTimeout) { if (!expireTimeout) {
return; return;
} }
clearTimeout(expireTimeout); clearTimeout(expireTimeout);
}
);
// If there are no more permissions, remove the entry from the URI map.
if (filterState != null && !Object.keys(permissions).length) {
delete uriToPerm[uriKey];
}
}); });
});
// We're either clearing all permissions or only the permissions with state
// == filterState. If we have a filter, we can only clean up the browser if
// there are no permission entries left in the map.
if (filterState == null || !Object.keys(uriToPerm).length) {
this._stateByBrowser.delete(browser);
}
}, },
// Copies the temporary permission state of one browser // Copies the temporary permission state of one browser
@ -866,13 +899,13 @@ var SitePermissions = {
}, },
/** /**
* Clears all permissions that were temporarily saved. * Clears all block permissions that were temporarily saved.
* *
* @param {Browser} browser * @param {Browser} browser
* The browser object to clear. * The browser object to clear.
*/ */
clearTemporaryPermissions(browser) { clearTemporaryBlockPermissions(browser) {
TemporaryPermissions.clear(browser); TemporaryPermissions.clear(browser, SitePermissions.BLOCK);
}, },
/** /**

Просмотреть файл

@ -77,7 +77,7 @@ add_task(async function testTemporaryPermissionTabURLs() {
); );
} }
SitePermissions.clearTemporaryPermissions(browser); SitePermissions.clearTemporaryBlockPermissions(browser);
} }
for (let principal of different) { for (let principal of different) {
@ -126,7 +126,7 @@ add_task(async function testTemporaryPermissionTabURLs() {
} }
} }
SitePermissions.clearTemporaryPermissions(browser); SitePermissions.clearTemporaryBlockPermissions(browser);
} }
}); });
}); });