Bug 1252998 - Use hosts instead of principals to delete ServiceWorkers in the SiteDataManager. r=baku

site.principals is not always guaranteed to contain elements, only if
the site has quota storage or AppCache. This patch simplifies the function
to use hosts instead.
This commit is contained in:
Johann Hofmann 2018-04-12 11:24:07 +02:00
Родитель 035f3a408e
Коммит 11d031b2f8
1 изменённых файлов: 12 добавлений и 20 удалений

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

@ -29,7 +29,8 @@ var SiteDataManager = {
// A Map of sites and their disk usage according to Quota Manager and appcache
// Key is host (group sites based on host across scheme, port, origin atttributes).
// Value is one object holding:
// - principals: instances of nsIPrincipal.
// - principals: instances of nsIPrincipal (only when the site has
// quota storage or AppCache).
// - persisted: the persistent-storage status.
// - quotaUsage: the usage of indexedDB and localStorage.
// - appCacheList: an array of app cache; instances of nsIApplicationCache
@ -314,14 +315,6 @@ var SiteDataManager = {
site.cookies = [];
},
_removeServiceWorkersForSites(sites) {
let promises = [];
sites.forEach(s => {
promises.push(ServiceWorkerCleanUp.removeFromHost(s.principals[0].URI.host));
});
return Promise.all(promises);
},
/**
* Removes all site data for the specified list of hosts.
*
@ -335,29 +328,24 @@ var SiteDataManager = {
this._updateAppCache();
let unknownHost = "";
let targetSites = new Map();
let promises = [];
for (let host of hosts) {
let site = this._sites.get(host);
if (site) {
// Clear localstorage.
Services.obs.notifyObservers(null, "browser:purge-domain-data", host);
this._removePermission(site);
this._removeAppCache(site);
this._removeCookies(site);
Services.obs.notifyObservers(null, "browser:purge-domain-data", host);
targetSites.set(host, site);
promises.push(ServiceWorkerCleanUp.removeFromHost(host));
promises.push(this._removeQuotaUsage(site));
} else {
unknownHost = host;
break;
}
}
if (targetSites.size > 0) {
await this._removeServiceWorkersForSites(targetSites);
let promises = [];
for (let [, site] of targetSites) {
promises.push(this._removeQuotaUsage(site));
}
await Promise.all(promises);
}
await Promise.all(promises);
if (unknownHost) {
throw `SiteDataManager: removing unknown site of ${unknownHost}`;
@ -421,6 +409,7 @@ var SiteDataManager = {
* Clears all site data, which currently means
* - Cookies
* - AppCache
* - LocalStorage
* - ServiceWorkers
* - Quota Managed Storage
* - persistent-storage permissions
@ -428,6 +417,9 @@ var SiteDataManager = {
* @returns a Promise that resolves with the cache size on disk in bytes
*/
async removeSiteData() {
// LocalStorage
Services.obs.notifyObservers(null, "extension:purge-localStorage");
Services.cookies.removeAll();
OfflineAppCacheHelper.clear();