mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 04:39:03 +02:00
The idea of this patch is to try to not use oberver mechanism as possible. To achieve that, it introduces deleteByOriginAttributes() to cleaners. Different from other methods, it would only be executed if it's implemented from a cleaner. It doesn't remove oberver mechanism entirely since some cleaners are still using that for other deleteByXXX() functions. So, it only applies removing stuff to PushService, QuotaManagerService, ServiceWorkerManager, nsPermissionManager, nsApplicationCacheService, and nsCookieService. Since the original issue is related to QuotaManagerService, it adds xpcshell test under the dom/quota/test/unit/ to ensure the behavior won't be changed accidentally in the future. Differential Revision: https://phabricator.services.mozilla.com/D33758 --HG-- extra : moz-landing-system : lando
94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
);
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(
|
|
this,
|
|
"serviceWorkerManager",
|
|
"@mozilla.org/serviceworkers/manager;1",
|
|
"nsIServiceWorkerManager"
|
|
);
|
|
|
|
if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
|
|
throw new Error(
|
|
"ServiceWorkerCleanUp.jsm can only be used in the parent process"
|
|
);
|
|
}
|
|
|
|
this.EXPORTED_SYMBOLS = ["ServiceWorkerCleanUp"];
|
|
|
|
function unregisterServiceWorker(aSW) {
|
|
return new Promise(resolve => {
|
|
let unregisterCallback = {
|
|
unregisterSucceeded: resolve,
|
|
unregisterFailed: resolve, // We don't care about failures.
|
|
QueryInterface: ChromeUtils.generateQI([
|
|
Ci.nsIServiceWorkerUnregisterCallback,
|
|
]),
|
|
};
|
|
serviceWorkerManager.propagateUnregister(
|
|
aSW.principal,
|
|
unregisterCallback,
|
|
aSW.scope
|
|
);
|
|
});
|
|
}
|
|
|
|
this.ServiceWorkerCleanUp = {
|
|
removeFromHost(aHost) {
|
|
let promises = [];
|
|
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
|
|
for (let i = 0; i < serviceWorkers.length; i++) {
|
|
let sw = serviceWorkers.queryElementAt(
|
|
i,
|
|
Ci.nsIServiceWorkerRegistrationInfo
|
|
);
|
|
if (sw.principal.URI.host == aHost) {
|
|
promises.push(unregisterServiceWorker(sw));
|
|
}
|
|
}
|
|
return Promise.all(promises);
|
|
},
|
|
|
|
removeFromPrincipal(aPrincipal) {
|
|
let promises = [];
|
|
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
|
|
for (let i = 0; i < serviceWorkers.length; i++) {
|
|
let sw = serviceWorkers.queryElementAt(
|
|
i,
|
|
Ci.nsIServiceWorkerRegistrationInfo
|
|
);
|
|
if (sw.principal.equals(aPrincipal)) {
|
|
promises.push(unregisterServiceWorker(sw));
|
|
}
|
|
}
|
|
return Promise.all(promises);
|
|
},
|
|
|
|
removeFromOriginAttributes(aOriginAttributesString) {
|
|
serviceWorkerManager.removeRegistrationsByOriginAttributes(
|
|
aOriginAttributesString
|
|
);
|
|
return Promise.resolve();
|
|
},
|
|
|
|
removeAll() {
|
|
let promises = [];
|
|
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
|
|
for (let i = 0; i < serviceWorkers.length; i++) {
|
|
let sw = serviceWorkers.queryElementAt(
|
|
i,
|
|
Ci.nsIServiceWorkerRegistrationInfo
|
|
);
|
|
promises.push(unregisterServiceWorker(sw));
|
|
}
|
|
return Promise.all(promises);
|
|
},
|
|
};
|