Bug 1415342 - Part 2 - Copy offlineApps sanitizing code from desktop implementation. r=esawin
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 12 Apr 2018 20:49:50 +0200
changeset 468050 6ed0756634261ff6ab8287dc5e0ecf5b0ee0acaa
parent 468049 40e13ce2180caa7e73ca3f9be1937a10dfd4a2e8
child 468051 78ea2b0c5f65c7a644ce05051f490b801d01815e
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1415342
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1415342 - Part 2 - Copy offlineApps sanitizing code from desktop implementation. r=esawin This is a straight copy-and-paste of the non-range-based desktop code in Sanitizer.jsm. MozReview-Commit-ID: 71r8LO4xzYF
mobile/android/modules/Sanitizer.jsm
--- a/mobile/android/modules/Sanitizer.jsm
+++ b/mobile/android/modules/Sanitizer.jsm
@@ -10,20 +10,26 @@ ChromeUtils.import("resource://gre/modul
 XPCOMUtils.defineLazyModuleGetters(this, {
   Accounts: "resource://gre/modules/Accounts.jsm",
   DownloadIntegration: "resource://gre/modules/DownloadIntegration.jsm",
   Downloads: "resource://gre/modules/Downloads.jsm",
   EventDispatcher: "resource://gre/modules/Messaging.jsm",
   FormHistory: "resource://gre/modules/FormHistory.jsm",
   OfflineAppCacheHelper: "resource://gre/modules/offlineAppCache.jsm",
   OS: "resource://gre/modules/osfile.jsm",
+  ServiceWorkerCleanUp: "resource://gre/modules/ServiceWorkerCleanUp.jsm",
   Task: "resource://gre/modules/Task.jsm",
   TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm",
 });
 
+XPCOMUtils.defineLazyServiceGetters(this, {
+  quotaManagerService: ["@mozilla.org/dom/quota-manager-service;1", "nsIQuotaManagerService"],
+});
+
+
 var EXPORTED_SYMBOLS = ["Sanitizer"];
 
 function Sanitizer() {}
 Sanitizer.prototype = {
   clearItem: function(aItemName, startTime) {
     // Only a subset of items support deletion with startTime.
     // Those who do not will be rejected with error message.
     if (typeof startTime != "undefined") {
@@ -141,24 +147,53 @@ Sanitizer.prototype = {
       }),
 
       get canClear() {
         return true;
       }
     },
 
     offlineApps: {
-      clear: function() {
-        return new Promise(function(resolve, reject) {
-          // AppCache
-          // This doesn't wait for the cleanup to be complete.
-          OfflineAppCacheHelper.clear();
+      async clear() {
+        // AppCache
+        // This doesn't wait for the cleanup to be complete.
+        OfflineAppCacheHelper.clear();
+
+        // LocalStorage
+        Services.obs.notifyObservers(null, "extension:purge-localStorage");
+
+        // ServiceWorkers
+        await ServiceWorkerCleanUp.removeAll();
 
-          resolve();
+        // QuotaManager
+        let promises = [];
+        await new Promise(resolve => {
+          quotaManagerService.getUsage(request => {
+            if (request.resultCode != Cr.NS_OK) {
+              // We are probably shutting down. We don't want to propagate the
+              // error, rejecting the promise.
+              resolve();
+              return;
+            }
+
+            for (let item of request.result) {
+              let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin(item.origin);
+              let uri = principal.URI;
+              if (uri.scheme == "http" || uri.scheme == "https" || uri.scheme == "file") {
+                promises.push(new Promise(r => {
+                  let req = quotaManagerService.clearStoragesForPrincipal(principal, null, false);
+                  req.callback = () => { r(); };
+                }));
+              }
+            }
+            resolve();
+          });
         });
+
+        return Promise.all(promises);
       },
 
       get canClear() {
           return true;
       }
     },
 
     history: {