Bug 1047098 - "Clear Recent History" must always clean up QuotaManager data. r=janv, a=sledru
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 21 Sep 2017 21:32:00 +0200
changeset 669792 4fc491de353a5080ef9851f962e267c1ba85adbb
parent 669791 44dc794755b481f7b161d354d26caf7e83113134
child 669793 a98d099fc07906b36c63af613d8928a07abfee5e
push id81427
push userluca.greco@alcacoop.it
push dateMon, 25 Sep 2017 11:52:41 +0000
reviewersjanv, sledru
bugs1047098
milestone57.0
Bug 1047098 - "Clear Recent History" must always clean up QuotaManager data. r=janv, a=sledru
browser/base/content/sanitize.js
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -14,16 +14,21 @@ XPCOMUtils.defineLazyModuleGetters(this,
   FormHistory: "resource://gre/modules/FormHistory.jsm",
   Downloads: "resource://gre/modules/Downloads.jsm",
   DownloadsCommon: "resource:///modules/DownloadsCommon.jsm",
   TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm",
   console: "resource://gre/modules/Console.jsm",
   setTimeout: "resource://gre/modules/Timer.jsm",
 });
 
+
+XPCOMUtils.defineLazyServiceGetter(this, "quotaManagerService",
+                                   "@mozilla.org/dom/quota-manager-service;1",
+                                   "nsIQuotaManagerService");
+
 var {classes: Cc, interfaces: Ci} = Components;
 
 /**
  * A number of iterations after which to yield time back
  * to the system.
  */
 const YIELD_PERIOD = 10;
 
@@ -275,19 +280,43 @@ Sanitizer.prototype = {
         if (seenException) {
           throw seenException;
         }
       },
     },
 
     offlineApps: {
       async clear(range) {
+        // AppCache
         Components.utils.import("resource:///modules/offlineAppCache.jsm");
         // This doesn't wait for the cleanup to be complete.
         OfflineAppCacheHelper.clear();
+
+        // LocalStorage
+        Services.obs.notifyObservers(null, "extension:purge-localStorage");
+
+        // QuotaManager
+        let promises = [];
+        await new Promise(resolve => {
+          quotaManagerService.getUsage(request => {
+            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, true);
+                  req.callback = () => { r(); };
+                }));
+              }
+            }
+            resolve();
+          });
+        });
+
+        return Promise.all(promises);
       }
     },
 
     history: {
       async clear(range) {
         let seenException;
         let refObj = {};
         TelemetryStopwatch.start("FX_SANITIZE_HISTORY", refObj);