зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1638099 - Unregister all extension service workers on extension shutdown if the app is not also shutting down. r=mixedpuppy
This patch introduces changes to parent/ext-backgroundPage.js and Extension's shutdown methods to make sure that all service workers registered by an extension are unregistered when the extension is shutting down, unless the application is also shutting down (in which case the registration is not unregistered because for the already installed extenson the previously activeWorker is expected to be still active across browser restarts). These changes prevent also to hit the issue that D119532 was triggering when an extension was reloaded and it does not need any of the changes to ContentPrincipal::AddonPolicy from D119531. Differential Revision: https://phabricator.services.mozilla.com/D119903
This commit is contained in:
Родитель
38acfa9c75
Коммит
4f6b894e7a
|
@ -394,24 +394,26 @@ var ExtensionAddonObserver = {
|
|||
);
|
||||
|
||||
// Clear all the registered service workers for the extension
|
||||
// principal.
|
||||
// principal (the one that may have been registered through the
|
||||
// manifest.json file and the ones that may have been registered
|
||||
// from an extension page through the service worker API).
|
||||
//
|
||||
// Any stored data would be cleared below (if the pref
|
||||
// "extensions.webextensions.keepStorageOnUninstall has not been
|
||||
// explicitly set to true, which is usually only done in
|
||||
// tests and by some extensions developers for testing purpose).
|
||||
if (WebExtensionPolicy.backgroundServiceWorkerEnabled) {
|
||||
// TODO: ServiceWorkerCleanUp may go away once Bug 1183245
|
||||
// is fixed, and so this may actually go away, replaced by
|
||||
// marking the registration as disabled or to be removed on
|
||||
// shutdown (where we do know if the extension is shutting
|
||||
// down because is being uninstalled) and then cleared from
|
||||
// the persisted serviceworker registration on the next
|
||||
// startup.
|
||||
AsyncShutdown.profileChangeTeardown.addBlocker(
|
||||
`Clear ServiceWorkers for ${addon.id}`,
|
||||
ServiceWorkerCleanUp.removeFromPrincipal(principal)
|
||||
);
|
||||
}
|
||||
//
|
||||
// TODO: ServiceWorkerCleanUp may go away once Bug 1183245
|
||||
// is fixed, and so this may actually go away, replaced by
|
||||
// marking the registration as disabled or to be removed on
|
||||
// shutdown (where we do know if the extension is shutting
|
||||
// down because is being uninstalled) and then cleared from
|
||||
// the persisted serviceworker registration on the next
|
||||
// startup.
|
||||
AsyncShutdown.profileChangeTeardown.addBlocker(
|
||||
`Clear ServiceWorkers for ${addon.id}`,
|
||||
ServiceWorkerCleanUp.removeFromPrincipal(principal)
|
||||
);
|
||||
|
||||
if (!Services.prefs.getBoolPref(LEAVE_STORAGE_PREF, false)) {
|
||||
// Clear browser.storage.local backends.
|
||||
|
@ -2837,6 +2839,20 @@ class Extension extends ExtensionData {
|
|||
|
||||
this.updatePermissions(reason);
|
||||
|
||||
// The service worker registrations related to the extensions are unregistered
|
||||
// only when the extension is not shutting down as part of the application
|
||||
// shutdown (a previously registered service worker is expected to stay
|
||||
// active across browser restarts), the service worker may have been
|
||||
// registered through the manifest.json background.service_worker property
|
||||
// or from an extension page through the service worker API if allowed
|
||||
// through the about:config pref.
|
||||
if (!isAppShutdown) {
|
||||
this.state = "Shutdown: ServiceWorkers";
|
||||
// TODO: ServiceWorkerCleanUp may go away once Bug 1183245 is fixed.
|
||||
await ServiceWorkerCleanUp.removeFromPrincipal(this.principal);
|
||||
this.state = "Shutdown: ServiceWorkers completed";
|
||||
}
|
||||
|
||||
if (!this.manifest) {
|
||||
this.state = "Shutdown: Complete: No manifest";
|
||||
this.policy.active = false;
|
||||
|
|
|
@ -129,11 +129,17 @@ class BackgroundWorker {
|
|||
);
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
if (this.registrationInfo) {
|
||||
shutdown(isAppShutdown) {
|
||||
// All service worker registrations related to the extensions will be unregistered
|
||||
// - when the extension is shutting down if the application is not also shutting down
|
||||
// shutdown (in which case a previously registered service worker is expected to stay
|
||||
// active across browser restarts).
|
||||
// - when the extension has been uninstalled
|
||||
if (!isAppShutdown && this.registrationInfo) {
|
||||
this.registrationInfo.forceShutdown();
|
||||
this.registrationInfo = null;
|
||||
}
|
||||
|
||||
this.registrationInfo = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,9 +226,9 @@ this.backgroundPage = class extends ExtensionAPI {
|
|||
});
|
||||
}
|
||||
|
||||
onShutdown() {
|
||||
onShutdown(isAppShutdown) {
|
||||
if (this.bgInstance) {
|
||||
this.bgInstance.shutdown();
|
||||
this.bgInstance.shutdown(isAppShutdown);
|
||||
this.bgInstance = null;
|
||||
} else {
|
||||
EventManager.clearPrimedListeners(this.extension, false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче