Bug 1165217 - Use nsIPrincipal instead of nsIURI/appId/inBrowser for nsIQuotaManager, r=janv
authorMichael Layzell <michael@thelayzells.com>
Fri, 03 Jul 2015 17:36:28 -0400
changeset 258313 a460f643b9120908ddc5e730a92d15c8065d427a
parent 258312 08dd09256e7ea12571813b159c82a04c61bb090c
child 258314 89cd1c55f918e69cba6ca2b8b04fe2cc8fafda67
push id63880
push usermichael@thelayzells.com
push dateWed, 19 Aug 2015 00:24:56 +0000
treeherdermozilla-inbound@89cd1c55f918 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1165217
milestone43.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 1165217 - Use nsIPrincipal instead of nsIURI/appId/inBrowser for nsIQuotaManager, r=janv
browser/base/content/pageinfo/permissions.js
dom/indexedDB/test/bug839193.js
dom/indexedDB/test/unit/test_idle_maintenance.js
dom/indexedDB/test/unit/xpcshell-head-parent-process.js
dom/quota/QuotaManager.cpp
dom/quota/QuotaManager.h
dom/quota/nsIQuotaManager.idl
dom/quota/nsIUsageCallback.idl
dom/system/gonk/tests/xpcshell.ini
testing/specialpowers/content/SpecialPowersObserverAPI.js
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/browser/base/content/pageinfo/permissions.js
+++ b/browser/base/content/pageinfo/permissions.js
@@ -183,43 +183,51 @@ function initIndexedDBRow()
 {
   let row = document.getElementById("perm-indexedDB-row");
   let extras = document.getElementById("perm-indexedDB-extras");
 
   row.appendChild(extras);
 
   var quotaManager = Components.classes["@mozilla.org/dom/quota/manager;1"]
                                .getService(nsIQuotaManager);
+  let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
+                            .getService(Components.interfaces.nsIScriptSecurityManager)
+                            .createCodebasePrincipal(gPermURI, {});
   gUsageRequest =
-    quotaManager.getUsageForURI(gPermURI, onIndexedDBUsageCallback);
+    quotaManager.getUsageForPrincipal(principal, onIndexedDBUsageCallback);
 
   var status = document.getElementById("indexedDBStatus");
   var button = document.getElementById("indexedDBClear");
 
   status.value = "";
   status.setAttribute("hidden", "true");
   button.setAttribute("hidden", "true");
 }
 
 function onIndexedDBClear()
 {
+  let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
+                            .getService(Components.interfaces.nsIScriptSecurityManager)
+                            .createCodebasePrincipal(gPermURI, {});
+
   Components.classes["@mozilla.org/dom/quota/manager;1"]
             .getService(nsIQuotaManager)
-            .clearStoragesForURI(gPermURI);
+            .clearStoragesForPrincipal(principal);
 
   Components.classes["@mozilla.org/serviceworkers/manager;1"]
             .getService(Components.interfaces.nsIServiceWorkerManager)
             .removeAndPropagate(gPermURI.host);
 
   SitePermissions.remove(gPermURI, "indexedDB");
   initIndexedDBRow();
 }
 
-function onIndexedDBUsageCallback(uri, usage, fileUsage)
+function onIndexedDBUsageCallback(principal, usage, fileUsage)
 {
+  let uri = principal.URI;
   if (!uri.equals(gPermURI)) {
     throw new Error("Callback received for bad URI: " + uri);
   }
 
   if (usage) {
     if (!("DownloadUtils" in window)) {
       Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
     }
--- a/dom/indexedDB/test/bug839193.js
+++ b/dom/indexedDB/test/bug839193.js
@@ -1,23 +1,26 @@
 /* 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/. */
 
 const nsIQuotaManager = Components.interfaces.nsIQuotaManager;
 
 let gURI = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI("http://localhost", null, null);
 
-function onUsageCallback(uri, usage, fileUsage) {}
+function onUsageCallback(principal, usage, fileUsage) {}
 
 function onLoad()
 {
   var quotaManager = Components.classes["@mozilla.org/dom/quota/manager;1"]
                                .getService(nsIQuotaManager);
-  var quotaRequest = quotaManager.getUsageForURI(gURI, onUsageCallback);
+  let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
+                            .getService(Components.interfaces.nsIScriptSecurityManager)
+                            .createCodebasePrincipal(gURI, {});
+  var quotaRequest = quotaManager.getUsageForPrincipal(principal, onUsageCallback);
   quotaRequest.cancel();
   Components.classes["@mozilla.org/observer-service;1"]
             .getService(Components.interfaces.nsIObserverService)
             .notifyObservers(window, "bug839193-loaded", null);
 }
 
 function onUnload()
 {
--- a/dom/indexedDB/test/unit/test_idle_maintenance.js
+++ b/dom/indexedDB/test/unit/test_idle_maintenance.js
@@ -87,17 +87,17 @@ function testSteps()
     }
   }
   yield undefined;
 
   info("Getting usage before maintenance");
 
   let usageBeforeMaintenance;
 
-  quotaManager.getUsageForURI(uri, (url, usage) => {
+  quotaManager.getUsageForPrincipal(principal, (principal, usage) => {
     ok(usage > 0, "Usage is non-zero");
     usageBeforeMaintenance = usage;
     continueToNextStep();
   });
   yield undefined;
 
   info("Sending fake 'idle-daily' notification to QuotaManager");
 
@@ -113,17 +113,17 @@ function testSteps()
   // shutting down in the middle of maintenance.
   setTimeout(continueToNextStep, 10000);
   yield undefined;
 
   info("Getting usage after maintenance");
 
   let usageAfterMaintenance;
 
-  quotaManager.getUsageForURI(uri, (url, usage) => {
+  quotaManager.getUsageForPrincipal(principal, (principal, usage) => {
     ok(usage > 0, "Usage is non-zero");
     usageAfterMaintenance = usage;
     continueToNextStep();
   });
   yield undefined;
 
   info("Usage before: " + usageBeforeMaintenance + ". " +
        "Usage after: " + usageAfterMaintenance);
--- a/dom/indexedDB/test/unit/xpcshell-head-parent-process.js
+++ b/dom/indexedDB/test/unit/xpcshell-head-parent-process.js
@@ -254,17 +254,20 @@ function resetOrClearAllDatabases(callba
       SpecialPowers.clearUserPref(quotaPref);
     }
     throw e;
   }
 
   let uri = Cc["@mozilla.org/network/io-service;1"]
               .getService(Ci.nsIIOService)
               .newURI("http://foo.com", null, null);
-  quotaManager.getUsageForURI(uri, function(usage, fileUsage) {
+  let principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
+                    .getService(Ci.nsIScriptSecurityManager)
+                    .createCodebasePrincipal(uri, {});
+  quotaManager.getUsageForPrincipal(principal, function(principal, usage, fileUsage) {
     callback();
   });
 }
 
 function resetAllDatabases(callback) {
   resetOrClearAllDatabases(callback, false);
 }
 
--- a/dom/quota/QuotaManager.cpp
+++ b/dom/quota/QuotaManager.cpp
@@ -22,16 +22,17 @@
 #include "nsITimer.h"
 #include "nsIURI.h"
 #include "nsIUsageCallback.h"
 #include "nsPIDOMWindow.h"
 
 #include <algorithm>
 #include "GeckoProfiler.h"
 #include "mozilla/Atomics.h"
+#include "mozilla/BasePrincipal.h"
 #include "mozilla/CondVar.h"
 #include "mozilla/dom/PContent.h"
 #include "mozilla/dom/asmjscache/AsmJSCache.h"
 #include "mozilla/dom/cache/QuotaClient.h"
 #include "mozilla/dom/indexedDB/ActorsParent.h"
 #include "mozilla/IntegerRange.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/LazyIdleThread.h"
@@ -664,30 +665,26 @@ private:
 
 class GetUsageOp
   : public NormalOriginOperationBase
   , public nsIQuotaRequest
 {
   UsageInfo mUsageInfo;
 
   const nsCString mGroup;
-  nsCOMPtr<nsIURI> mURI;
+  nsCOMPtr<nsIPrincipal> mPrincipal;
   nsCOMPtr<nsIUsageCallback> mCallback;
-  const uint32_t mAppId;
   const bool mIsApp;
-  const bool mInMozBrowserOnly;
 
 public:
   GetUsageOp(const nsACString& aGroup,
              const nsACString& aOrigin,
              bool aIsApp,
-             nsIURI* aURI,
-             nsIUsageCallback* aCallback,
-             uint32_t aAppId,
-             bool aInMozBrowserOnly);
+             nsIPrincipal* aPrincipal,
+             nsIUsageCallback* aCallback);
 
 private:
   ~GetUsageOp()
   { }
 
   nsresult
   AddToUsage(QuotaManager* aQuotaManager,
              PersistenceType aPersistenceType);
@@ -3399,42 +3396,16 @@ QuotaManager::GetStorageId(PersistenceTy
   str.Append('*');
   str.Append(aOrigin);
   str.Append('*');
   str.AppendInt(aClientType);
 
   aDatabaseId = str;
 }
 
-// static
-nsresult
-QuotaManager::GetInfoFromURI(nsIURI* aURI,
-                             uint32_t aAppId,
-                             bool aInMozBrowser,
-                             nsACString* aGroup,
-                             nsACString* aOrigin,
-                             bool* aIsApp)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aURI);
-
-  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
-  NS_ENSURE_TRUE(secMan, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIPrincipal> principal;
-  nsresult rv = secMan->GetAppCodebasePrincipal(aURI, aAppId, aInMozBrowser,
-                                                getter_AddRefs(principal));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = GetInfoFromPrincipal(principal, aGroup, aOrigin, aIsApp);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
-}
-
 static nsresult
 TryGetInfoForAboutURI(nsIPrincipal* aPrincipal,
                       nsACString& aGroup,
                       nsACString& aASCIIOrigin,
                       bool* aIsApp)
 {
   NS_ASSERTION(aPrincipal, "Don't hand me a null principal!");
 
@@ -3704,46 +3675,37 @@ QuotaManager::GetDirectoryMetadata(nsIFi
     *aIsApp = isApp;
   }
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(QuotaManager, nsIQuotaManager, nsIObserver)
 
 NS_IMETHODIMP
-QuotaManager::GetUsageForURI(nsIURI* aURI,
-                             nsIUsageCallback* aCallback,
-                             uint32_t aAppId,
-                             bool aInMozBrowserOnly,
-                             uint8_t aOptionalArgCount,
-                             nsIQuotaRequest** _retval)
+QuotaManager::GetUsageForPrincipal(nsIPrincipal* aPrincipal,
+                                   nsIUsageCallback* aCallback,
+                                   nsIQuotaRequest** _retval)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
-  NS_ENSURE_ARG_POINTER(aURI);
+  NS_ENSURE_ARG_POINTER(aPrincipal);
   NS_ENSURE_ARG_POINTER(aCallback);
 
   // This only works from the main process.
   NS_ENSURE_TRUE(XRE_IsParentProcess(), NS_ERROR_NOT_AVAILABLE);
 
-  if (!aOptionalArgCount) {
-    aAppId = nsIScriptSecurityManager::NO_APP_ID;
-  }
-
   // Figure out which origin we're dealing with.
   nsCString group;
   nsCString origin;
   bool isApp;
-  nsresult rv = GetInfoFromURI(aURI, aAppId, aInMozBrowserOnly, &group, &origin,
-                               &isApp);
+  nsresult rv = GetInfoFromPrincipal(aPrincipal, &group, &origin, &isApp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsRefPtr<GetUsageOp> op =
-    new GetUsageOp(group, origin, isApp, aURI, aCallback, aAppId,
-                   aInMozBrowserOnly);
+    new GetUsageOp(group, origin, isApp, aPrincipal, aCallback);
 
   op->RunImmediately();
 
   op.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -3759,48 +3721,43 @@ QuotaManager::Clear()
   nsRefPtr<ResetOrClearOp> op = new ResetOrClearOp(/* aClear */ true);
 
   op->RunImmediately();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-QuotaManager::ClearStoragesForURI(nsIURI* aURI,
-                                  uint32_t aAppId,
-                                  bool aInMozBrowserOnly,
-                                  const nsACString& aPersistenceType,
-                                  uint8_t aOptionalArgCount)
+QuotaManager::ClearStoragesForPrincipal(nsIPrincipal* aPrincipal,
+                                        const nsACString& aPersistenceType)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
-  NS_ENSURE_ARG_POINTER(aURI);
+  NS_ENSURE_ARG_POINTER(aPrincipal);
 
   Nullable<PersistenceType> persistenceType;
   nsresult rv =
     NullablePersistenceTypeFromText(aPersistenceType, &persistenceType);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return NS_ERROR_INVALID_ARG;
   }
 
   // This only works from the main process.
   NS_ENSURE_TRUE(XRE_IsParentProcess(), NS_ERROR_NOT_AVAILABLE);
 
-  if (!aOptionalArgCount) {
-    aAppId = nsIScriptSecurityManager::NO_APP_ID;
-  }
-
   // Figure out which origin we're dealing with.
   nsCString origin;
-  rv = GetInfoFromURI(aURI, aAppId, aInMozBrowserOnly, nullptr, &origin,
-                      nullptr);
+  rv = GetInfoFromPrincipal(aPrincipal, nullptr, &origin, nullptr);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  const mozilla::OriginAttributes& attrs =
+    mozilla::BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
+
   nsAutoCString pattern;
-  GetOriginPatternString(aAppId, aInMozBrowserOnly, origin, pattern);
+  GetOriginPatternString(attrs.mAppId, attrs.mInBrowser, origin, pattern);
 
   nsRefPtr<OriginClearOp> op =
     new OriginClearOp(persistenceType, OriginScope::FromPattern(pattern));
 
   op->RunImmediately();
 
   return NS_OK;
 }
@@ -4620,34 +4577,30 @@ SaveOriginAccessTimeOp::DoDirectoryWork(
   }
 
   return NS_OK;
 }
 
 GetUsageOp::GetUsageOp(const nsACString& aGroup,
                        const nsACString& aOrigin,
                        bool aIsApp,
-                       nsIURI* aURI,
-                       nsIUsageCallback* aCallback,
-                       uint32_t aAppId,
-                       bool aInMozBrowserOnly)
+                       nsIPrincipal* aPrincipal,
+                       nsIUsageCallback* aCallback)
   : NormalOriginOperationBase(Nullable<PersistenceType>(),
                               OriginScope::FromOrigin(aOrigin),
                               /* aExclusive */ false)
   , mGroup(aGroup)
-  , mURI(aURI)
+  , mPrincipal(aPrincipal)
   , mCallback(aCallback)
-  , mAppId(aAppId)
   , mIsApp(aIsApp)
-  , mInMozBrowserOnly(aInMozBrowserOnly)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!aGroup.IsEmpty());
   MOZ_ASSERT(!aOrigin.IsEmpty());
-  MOZ_ASSERT(aURI);
+  MOZ_ASSERT(aPrincipal);
   MOZ_ASSERT(aCallback);
 }
 
 nsresult
 GetUsageOp::AddToUsage(QuotaManager* aQuotaManager,
                        PersistenceType aPersistenceType)
 {
   AssertIsOnIOThread();
@@ -4772,22 +4725,21 @@ GetUsageOp::SendResults()
 
   // Call the callback unless we were canceled.
   if (!mUsageInfo.Canceled()) {
     // XXX Implement better error reporting here, bug 1170019.
     if (NS_FAILED(mResultCode)) {
       mUsageInfo.ResetUsage();
     }
 
-    mCallback->OnUsageResult(mURI, mUsageInfo.TotalUsage(), mUsageInfo.FileUsage(), mAppId,
-                             mInMozBrowserOnly);
+    mCallback->OnUsageResult(mPrincipal, mUsageInfo.TotalUsage(), mUsageInfo.FileUsage());
   }
 
   // Clean up.
-  mURI = nullptr;
+  mPrincipal = nullptr;
   mCallback = nullptr;
 }
 
 NS_IMPL_ISUPPORTS_INHERITED(GetUsageOp,
                             NormalOriginOperationBase,
                             nsIQuotaRequest)
 
 NS_IMETHODIMP
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -302,24 +302,16 @@ public:
 
   static void
   GetStorageId(PersistenceType aPersistenceType,
                const nsACString& aOrigin,
                Client::Type aClientType,
                nsACString& aDatabaseId);
 
   static nsresult
-  GetInfoFromURI(nsIURI* aURI,
-                 uint32_t aAppId,
-                 bool aInMozBrowser,
-                 nsACString* aGroup,
-                 nsACString* aOrigin,
-                 bool* aIsApp);
-
-  static nsresult
   GetInfoFromPrincipal(nsIPrincipal* aPrincipal,
                        nsACString* aGroup,
                        nsACString* aOrigin,
                        bool* aIsApp);
 
   static nsresult
   GetInfoFromWindow(nsPIDOMWindow* aWindow,
                     nsACString* aGroup,
--- a/dom/quota/nsIQuotaManager.idl
+++ b/dom/quota/nsIQuotaManager.idl
@@ -2,62 +2,56 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "nsISupports.idl"
 
 interface nsIQuotaRequest;
-interface nsIURI;
+interface nsIPrincipal;
 interface nsIUsageCallback;
 
-[scriptable, builtinclass, uuid(2968fcd5-1872-4ddc-8c16-62b27e357f31)]
+[scriptable, builtinclass, uuid(101cf53c-e7f3-4723-9f43-a23a85c8eda0)]
 interface nsIQuotaManager : nsISupports
 {
   /**
    * Schedules an asynchronous callback that will return the total amount of
    * disk space being used by storages for the given origin.
    *
-   * @param aURI
-   *        The URI whose usage is being queried.
+   * @param aPrincipal
+   *        A principal for the origin whose usage is being queried.
    * @param aCallback
    *        The callback that will be called when the usage is available.
    */
-  [optional_argc]
   nsIQuotaRequest
-  getUsageForURI(in nsIURI aURI,
-                 in nsIUsageCallback aCallback,
-                 [optional] in unsigned long aAppId,
-                 [optional] in boolean aInMozBrowserOnly);
+  getUsageForPrincipal(in nsIPrincipal aPrincipal,
+                       in nsIUsageCallback aCallback);
 
   /**
    * Removes all storages. The files may not be deleted immediately depending
    * on prohibitive concurrent operations.
    * Be careful, this removes *all* the data that has ever been stored!
    *
    * If the dom.quotaManager.testing preference is not true the call will be
    * a no-op.
    */
   void
   clear();
 
   /**
    * Removes all storages stored for the given URI. The files may not be
    * deleted immediately depending on prohibitive concurrent operations.
    *
-   * @param aURI
-   *        The URI whose storages are to be cleared.
+   * @param aPrincipal
+   *        A principal for the origin whose storages are to be cleared.
    */
-  [optional_argc]
   void
-  clearStoragesForURI(in nsIURI aURI,
-                      [optional] in unsigned long aAppId,
-                      [optional] in boolean aInMozBrowserOnly,
-                      [optional] in ACString aPersistenceType);
+  clearStoragesForPrincipal(in nsIPrincipal aPrincipal,
+                            [optional] in ACString aPersistenceType);
 
   /**
    * Resets quota and storage management. This can be used to force
    * reinitialization of the temp storage, for example when the pref for
    * overriding the temp storage limit has changed.
    * Be carefull, this invalidates all live storages!
    *
    * If the dom.quotaManager.testing preference is not true the call will be
--- a/dom/quota/nsIUsageCallback.idl
+++ b/dom/quota/nsIUsageCallback.idl
@@ -1,20 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "nsISupports.idl"
 
-interface nsIURI;
+interface nsIPrincipal;
 
-[scriptable, function, uuid(7b0f9928-0ddc-42c7-b9f2-6b2308b90b18)]
+[scriptable, function, uuid(54b9f44f-533f-41ee-8fa8-86cc978125f0)]
 interface nsIUsageCallback : nsISupports
 {
-  void
-  onUsageResult(in nsIURI aURI,
-                in unsigned long long aUsage,
-                in unsigned long long aFileUsage,
-                in unsigned long aAppId,
-                in boolean aInMozBrowserOnly);
+  void onUsageResult(in nsIPrincipal aPrincipal,
+                     in unsigned long long aUsage,
+                     in unsigned long long aFileUsage);
 };
--- a/dom/system/gonk/tests/xpcshell.ini
+++ b/dom/system/gonk/tests/xpcshell.ini
@@ -29,13 +29,14 @@ skip-if = true
 [test_ril_worker_ruim.js]
 [test_ril_worker_cw.js]
 [test_ril_worker_clir.js]
 [test_ril_worker_clip.js]
 [test_ril_worker_ssn.js]
 [test_ril_worker_voiceprivacy.js]
 [test_ril_worker_ecm.js]
 [test_ril_worker_stk.js]
+requesttimeoutfactor = 2
 [test_ril_worker_barring_password.js]
 [test_ril_worker_cdma_info_rec.js]
 [test_ril_system_messenger.js]
 # header_helpers.js is not needed for test_ril_system_messenger.js
 head =
--- a/testing/specialpowers/content/SpecialPowersObserverAPI.js
+++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js
@@ -500,49 +500,41 @@ SpecialPowersObserverAPI.prototype = {
                          .messageManager;
         let msg = aMessage.data;
         let op = msg.op;
 
         if (op != 'clear' && op != 'getUsage' && op != 'reset') {
           throw new SpecialPowersError('Invalid operation for SPQuotaManager');
         }
 
-        let uri = this._getURI(msg.uri);
+        let secMan = Services.scriptSecurityManager;
+        let principal = secMan.createCodebasePrincipal(this._getURI(msg.uri), {
+          appId: msg.appId,
+          inBrowser: msg.inBrowser,
+        });
 
         if (op == 'clear') {
-          if (('inBrowser' in msg) && msg.inBrowser !== undefined) {
-            qm.clearStoragesForURI(uri, msg.appId, msg.inBrowser);
-          } else if (('appId' in msg) && msg.appId !== undefined) {
-            qm.clearStoragesForURI(uri, msg.appId);
-          } else {
-            qm.clearStoragesForURI(uri);
-          }
+          qm.clearStoragesForPrincipal(principal);
         } else if (op == 'reset') {
           qm.reset();
         }
 
-        // We always use the getUsageForURI callback even if we're clearing
-        // since we know that clear and getUsageForURI are synchronized by the
+        // We always use the getUsageForPrincipal callback even if we're clearing
+        // since we know that clear and getUsageForPrincipal are synchronized by the
         // QuotaManager.
-        let callback = function(uri, usage, fileUsage) {
+        let callback = function(principal, usage, fileUsage) {
           let reply = { id: msg.id };
           if (op == 'getUsage') {
             reply.usage = usage;
             reply.fileUsage = fileUsage;
           }
           mm.sendAsyncMessage(aMessage.name, reply);
         };
 
-        if (('inBrowser' in msg) && msg.inBrowser !== undefined) {
-          qm.getUsageForURI(uri, callback, msg.appId, msg.inBrowser);
-        } else if (('appId' in msg) && msg.appId !== undefined) {
-          qm.getUsageForURI(uri, callback, msg.appId);
-        } else {
-          qm.getUsageForURI(uri, callback);
-        }
+        qm.getUsageForPrincipal(principal, callback);
 
         return undefined;	// See comment at the beginning of this function.
       }
 
       case "SPPeriodicServiceWorkerUpdates": {
         // We could just dispatch a generic idle-daily notification here, but
         // this is better since it avoids invoking other idle daily observers
         // at the cost of hard-coding the usage of PeriodicServiceWorkerUpdater.
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -155,18 +155,20 @@ this.ForgetAboutSite = {
     // delete data from both HTTP and HTTPS sites
     let caUtils = {};
     let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                        getService(Ci.mozIJSSubScriptLoader);
     scriptLoader.loadSubScript("chrome://global/content/contentAreaUtils.js",
                                caUtils);
     let httpURI = caUtils.makeURI("http://" + aDomain);
     let httpsURI = caUtils.makeURI("https://" + aDomain);
-    qm.clearStoragesForURI(httpURI);
-    qm.clearStoragesForURI(httpsURI);
+    let httpPrincipal = Services.scriptSecurityManager.createCodebasePrincipal(httpURI, {});
+    let httpsPrincipal = Services.scriptSecurityManager.createCodebasePrincipal(httpsURI, {});
+    qm.clearStoragesForPrincipal(httpPrincipal);
+    qm.clearStoragesForPrincipal(httpsPrincipal);
 
     function onContentPrefsRemovalFinished() {
       // Everybody else (including extensions)
       Services.obs.notifyObservers(null, "browser:purge-domain-data", aDomain);
     }
 
     // Content Preferences
     let cps2 = Cc["@mozilla.org/content-pref/service;1"].