Bug 1165256 - Make appcache fully work with OriginAttribues. r=jduell
authorHonza Bambas <honzab.moz@firemni.cz>
Mon, 18 Jan 2016 20:20:08 +0100
changeset 280872 56582e4322f60511d1c9044e4e9b5ad514ff28e7
parent 280871 403d9fc6a1363ddd3cf342e668ac395e399b0912
child 280873 b113b4874656564361235f0bf9978def26ef20b7
push id29922
push usercbook@mozilla.com
push dateThu, 21 Jan 2016 10:51:00 +0000
treeherdermozilla-central@977d78a8dd78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs1165256
milestone46.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 1165256 - Make appcache fully work with OriginAttribues. r=jduell
browser/base/content/test/general/browser_sanitizeDialog.js
dom/apps/Webapps.jsm
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
dom/offline/nsDOMOfflineResourceList.cpp
dom/tests/mochitest/ajax/offline/offlineTests.js
dom/tests/mochitest/ajax/offline/test_updateCheck.html
netwerk/base/moz.build
netwerk/base/nsIApplicationCacheService.idl
netwerk/cache/nsApplicationCacheService.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/cache/nsDiskCacheDeviceSQL.h
netwerk/cache2/AppCacheStorage.cpp
netwerk/cache2/OldWrappers.cpp
netwerk/test/unit/test_offlinecache_custom-directory.js
uriloader/prefetch/OfflineCacheUpdateChild.cpp
uriloader/prefetch/OfflineCacheUpdateChild.h
uriloader/prefetch/OfflineCacheUpdateGlue.cpp
uriloader/prefetch/OfflineCacheUpdateGlue.h
uriloader/prefetch/OfflineCacheUpdateParent.cpp
uriloader/prefetch/OfflineCacheUpdateParent.h
uriloader/prefetch/nsIOfflineCacheUpdate.idl
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsOfflineCacheUpdate.h
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
--- a/browser/base/content/test/general/browser_sanitizeDialog.js
+++ b/browser/base/content/test/general/browser_sanitizeDialog.js
@@ -549,17 +549,17 @@ add_task(function* test_offline_cache() 
 
   // Give www.example.com privileges to store offline data
   Services.perms.addFromPrincipal(principal, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
   Services.perms.addFromPrincipal(principal, "offline-app", Ci.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
 
   // Store something to the offline cache
   var appcacheserv = Cc["@mozilla.org/network/application-cache-service;1"]
                      .getService(Ci.nsIApplicationCacheService);
-  var appcachegroupid = appcacheserv.buildGroupID(makeURI(URL + "/manifest"), LoadContextInfo.default);
+  var appcachegroupid = appcacheserv.buildGroupIDForInfo(makeURI(URL + "/manifest"), LoadContextInfo.default);
   var appcache = appcacheserv.createApplicationCache(appcachegroupid);
   var storage = Services.cache2.appCacheStorage(LoadContextInfo.default, appcache);
 
   // Open the dialog
   let wh = new WindowHelper();
   wh.onload = function () {
     this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
     // Show details
--- a/dom/apps/Webapps.jsm
+++ b/dom/apps/Webapps.jsm
@@ -2046,17 +2046,17 @@ this.DOMApplicationRegistry = {
         },
         id: aApp.id
       });
       let appURI = NetUtil.newURI(aApp.origin, null, null);
       let principal =
         Services.scriptSecurityManager.createCodebasePrincipal(appURI,
                                                                {appId: aApp.localId});
       let cacheUpdate = updateSvc.scheduleAppUpdate(
-        appcacheURI, docURI, principal, aApp.localId, false, aProfileDir);
+        appcacheURI, docURI, principal, aProfileDir);
 
       // We save the download details for potential further usage like
       // cancelling it.
       let download = {
         cacheUpdate: cacheUpdate,
         appId: this._appIdForManifestURL(aApp.manifestURL),
         previousState: aIsUpdate ? "installed" : "pending"
       };
@@ -2200,17 +2200,17 @@ this.DOMApplicationRegistry = {
           new ManifestHelper(manifest, aData.origin, aData.manifestURL);
         debug("onlyCheckAppCache - launch updateSvc.checkForUpdate for " +
               helper.fullAppcachePath());
         let appURI = NetUtil.newURI(aApp.origin, null, null);
         let principal =
           Services.scriptSecurityManager.createCodebasePrincipal(appURI,
                                                                  {appId: aApp.localId});
         updateSvc.checkForUpdate(Services.io.newURI(helper.fullAppcachePath(), null, null),
-                                 principal, app.localId, false, updateObserver);
+                                 principal, updateObserver);
       });
       return;
     }
 
     // On xhr load request event
     function onload(xhr, oldManifest) {
       debug("Got http status=" + xhr.status + " for " + aData.manifestURL);
       let oldHash = app.manifestHash;
@@ -2474,18 +2474,17 @@ this.DOMApplicationRegistry = {
 
       let updateDeferred = Promise.defer();
       let appURI = NetUtil.newURI(aApp.origin, null, null);
       let principal =
         Services.scriptSecurityManager.createCodebasePrincipal(appURI,
                                                                {appId: aApp.localId});
 
       updateSvc.checkForUpdate(Services.io.newURI(manifest.fullAppcachePath(), null, null),
-                               principal, aApp.localId, false,
-                               (aSubject, aTopic, aData) => updateDeferred.resolve(aTopic));
+                               principal, (aSubject, aTopic, aData) => updateDeferred.resolve(aTopic));
 
       let topic = yield updateDeferred.promise;
 
       debug("updateHostedApp: updateSvc.checkForUpdate return for " +
             aApp.manifestURL + " - event is " + topic);
 
       let eventType =
         topic == "offline-cache-update-available" ? "downloadavailable"
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -2808,18 +2808,17 @@ ContentChild::RecvUnregisterSheet(const 
 
   return true;
 }
 
 POfflineCacheUpdateChild*
 ContentChild::AllocPOfflineCacheUpdateChild(const URIParams& manifestURI,
                                             const URIParams& documentURI,
                                             const PrincipalInfo& aLoadingPrincipalInfo,
-                                            const bool& stickDocument,
-                                            const TabId& aTabId)
+                                            const bool& stickDocument)
 {
   NS_RUNTIMEABORT("unused");
   return nullptr;
 }
 
 bool
 ContentChild::DeallocPOfflineCacheUpdateChild(POfflineCacheUpdateChild* actor)
 {
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -569,18 +569,17 @@ public:
 
   PBrowserOrId
   GetBrowserOrId(TabChild* aTabChild);
 
   virtual POfflineCacheUpdateChild*
   AllocPOfflineCacheUpdateChild(const URIParams& manifestURI,
                                 const URIParams& documentURI,
                                 const PrincipalInfo& aLoadingPrincipalInfo,
-                                const bool& stickDocument,
-                                const TabId& aTabId) override;
+                                const bool& stickDocument) override;
 
   virtual bool
   DeallocPOfflineCacheUpdateChild(POfflineCacheUpdateChild* offlineCacheUpdate) override;
 
   virtual PWebrtcGlobalChild* AllocPWebrtcGlobalChild() override;
 
   virtual bool DeallocPWebrtcGlobalChild(PWebrtcGlobalChild *aActor) override;
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -5241,38 +5241,30 @@ ContentParent::GetManagedTabContext()
   return Move(ContentProcessManager::GetSingleton()->
           GetTabContextByContentProcess(this->ChildID()));
 }
 
 mozilla::docshell::POfflineCacheUpdateParent*
 ContentParent::AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
                                               const URIParams& aDocumentURI,
                                               const PrincipalInfo& aLoadingPrincipalInfo,
-                                              const bool& aStickDocument,
-                                              const TabId& aTabId)
-{
-  TabContext tabContext;
-  if (!ContentProcessManager::GetSingleton()->
-    GetTabContextByProcessAndTabId(this->ChildID(), aTabId, &tabContext)) {
-    return nullptr;
-  }
+                                              const bool& aStickDocument)
+{
   RefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
-    new mozilla::docshell::OfflineCacheUpdateParent(
-      tabContext.OriginAttributesRef());
+        new mozilla::docshell::OfflineCacheUpdateParent();
   // Use this reference as the IPDL reference.
   return update.forget().take();
 }
 
 bool
 ContentParent::RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
                                                   const URIParams& aManifestURI,
                                                   const URIParams& aDocumentURI,
                                                   const PrincipalInfo& aLoadingPrincipal,
-                                                  const bool& aStickDocument,
-                                                  const TabId& aTabId)
+                                                  const bool& aStickDocument)
 {
   MOZ_ASSERT(aActor);
 
   RefPtr<mozilla::docshell::OfflineCacheUpdateParent> update =
     static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(aActor);
 
   nsresult rv = update->Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, aStickDocument);
   if (NS_FAILED(rv) && IsAlive()) {
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -452,26 +452,24 @@ public:
                                        const ContentParentId& aCpId) override;
 
   nsTArray<TabContext> GetManagedTabContext();
 
   virtual POfflineCacheUpdateParent*
   AllocPOfflineCacheUpdateParent(const URIParams& aManifestURI,
                                  const URIParams& aDocumentURI,
                                  const PrincipalInfo& aLoadingPrincipalInfo,
-                                 const bool& aStickDocument,
-                                 const TabId& aTabId) override;
+                                 const bool& aStickDocument) override;
 
   virtual bool
   RecvPOfflineCacheUpdateConstructor(POfflineCacheUpdateParent* aActor,
                                      const URIParams& aManifestURI,
                                      const URIParams& aDocumentURI,
                                      const PrincipalInfo& aLoadingPrincipal,
-                                     const bool& stickDocument,
-                                     const TabId& aTabId) override;
+                                     const bool& stickDocument) override;
 
   virtual bool
   DeallocPOfflineCacheUpdateParent(POfflineCacheUpdateParent* aActor) override;
 
   virtual bool RecvSetOfflinePermission(const IPC::Principal& principal) override;
 
   virtual bool RecvFinishShutdown() override;
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -1080,18 +1080,17 @@ parent:
      *   cache group update. But we must cache the document (identified by the
      *   documentURI). This argument will ensure that a previously uncached
      *   document will get cached and that we don't re-cache a document that
      *   has already been cached (stickDocument=false).
      * @param tabId
      *   To identify which tab owns the app.
      */
     POfflineCacheUpdate(URIParams manifestURI, URIParams documentURI,
-                        PrincipalInfo loadingPrincipal, bool stickDocument,
-                        TabId tabId);
+                        PrincipalInfo loadingPrincipal, bool stickDocument);
 
     /**
      * Sets "offline-app" permission for the principal.  Called when we hit
      * a web app with the manifest attribute in <html> and
      * offline-apps.allow_by_default is set to true.
      */
     SetOfflinePermission(Principal principal);
 
--- a/dom/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/offline/nsDOMOfflineResourceList.cpp
@@ -20,16 +20,17 @@
 #include "nsContentUtils.h"
 #include "nsIObserverService.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIWebNavigation.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/OfflineResourceListBinding.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/BasePrincipal.h"
 
 #include "nsXULAppAPI.h"
 #define IS_CHILD_PROCESS() \
     (GeckoProcessType_Default != XRE_GetProcessType())
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
@@ -808,26 +809,28 @@ nsDOMOfflineResourceList::CacheKeys()
 
   if (mCachedKeys)
     return NS_OK;
 
   nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetOwner());
   nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(window);
   nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
 
-  uint32_t appId = 0;
-  bool inBrowser = false;
+  nsAutoCString originSuffix;
   if (loadContext) {
-    loadContext->GetAppId(&appId);
-    loadContext->GetIsInBrowserElement(&inBrowser);
+    mozilla::DocShellOriginAttributes oa;
+    bool ok = loadContext->GetOriginAttributes(oa);
+    NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
+
+    oa.CreateSuffix(originSuffix);
   }
 
   nsAutoCString groupID;
-  mApplicationCacheService->BuildGroupIDForApp(
-      mManifestURI, appId, inBrowser, groupID);
+  mApplicationCacheService->BuildGroupIDForSuffix(
+      mManifestURI, originSuffix, groupID);
 
   nsCOMPtr<nsIApplicationCache> appCache;
   mApplicationCacheService->GetActiveCache(groupID,
                                            getter_AddRefs(appCache));
 
   if (!appCache) {
     return NS_ERROR_DOM_INVALID_STATE_ERR;
   }
--- a/dom/tests/mochitest/ajax/offline/offlineTests.js
+++ b/dom/tests/mochitest/ajax/offline/offlineTests.js
@@ -319,17 +319,17 @@ loadContextInfo: function()
 },
 
 getActiveCache: function(overload)
 {
   // Note that this is the current active cache in the cache stack, not the
   // one associated with this window.
   var serv = Cc["@mozilla.org/network/application-cache-service;1"]
              .getService(Ci.nsIApplicationCacheService);
-  var groupID = serv.buildGroupID(this.manifestURL(overload), this.loadContextInfo());
+  var groupID = serv.buildGroupIDForInfo(this.manifestURL(overload), this.loadContextInfo());
   return serv.getActiveCache(groupID);
 },
 
 getActiveStorage: function()
 {
   var cache = this.getActiveCache();
   if (!cache) {
     return null;
--- a/dom/tests/mochitest/ajax/offline/test_updateCheck.html
+++ b/dom/tests/mochitest/ajax/offline/test_updateCheck.html
@@ -29,31 +29,31 @@ var manifestURI = Cc["@mozilla.org/netwo
 var updateService = Cc['@mozilla.org/offlinecacheupdate-service;1']
                     .getService(Ci.nsIOfflineCacheUpdateService);
 
 var systemPrincipal = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal();
 
 function manifestCached()
 {
   // Run first check for an update
-  updateService.checkForUpdate(manifestURI, systemPrincipal, 0, false, {
+  updateService.checkForUpdate(manifestURI, systemPrincipal, {
     observe: function(subject, topic, data) {
       OfflineTest.is(topic, "offline-cache-update-unavailable", "No update avail");
 
       // Change the manifest content
       OfflineTest.setSJSState(manifest, "second");
 
       // Check we now get notification on update ready
-      updateService.checkForUpdate(manifestURI, systemPrincipal, 0, false, {
+      updateService.checkForUpdate(manifestURI, systemPrincipal, {
         observe: function(subject, topic, data) {
           OfflineTest.is(topic, "offline-cache-update-available", "Update avail (1)");
 
           // Do the check again.  We must get the same result.  Double check is here
           // to make sure we don't overwrite any data in the cache by the check it self.
-          updateService.checkForUpdate(manifestURI, systemPrincipal, 0, false, {
+          updateService.checkForUpdate(manifestURI, systemPrincipal, {
             observe: function(subject, topic, data) {
               OfflineTest.is(topic, "offline-cache-update-available", "Update avail (2)");
 
               // Update the manifest, invokes manifestUpdated()
               applicationCache.onupdateready = OfflineTest.priv(manifestUpdated);
               applicationCache.update();
             }
           });
@@ -61,17 +61,17 @@ function manifestCached()
       });
     }
   });
 }
 
 function manifestUpdated()
 {
   // Check for an update after manifest has been updated
-  updateService.checkForUpdate(manifestURI, systemPrincipal, 0, false, {
+  updateService.checkForUpdate(manifestURI, systemPrincipal, {
     observe: function(subject, topic, data) {
       OfflineTest.is(topic, "offline-cache-update-unavailable", "No update avail (2)");
 
       OfflineTest.teardownAndFinish();
     }
   });
 }
 
--- a/netwerk/base/moz.build
+++ b/netwerk/base/moz.build
@@ -162,16 +162,17 @@ EXPORTS += [
     'nsStreamListenerWrapper.h',
     'nsTemporaryFileInputStream.h',
     'nsURIHashKey.h',
     'nsURLHelper.h',
     'nsURLParsers.h',
 ]
 
 EXPORTS.mozilla += [
+    'LoadContextInfo.h',
     'LoadInfo.h',
     'LoadTainting.h',
 ]
 
 EXPORTS.mozilla.net += [
     'CaptivePortalService.h',
     'ChannelDiverterChild.h',
     'ChannelDiverterParent.h',
--- a/netwerk/base/nsIApplicationCacheService.idl
+++ b/netwerk/base/nsIApplicationCacheService.idl
@@ -10,32 +10,27 @@ interface nsIApplicationCache;
 interface nsIFile;
 interface nsIURI;
 interface nsILoadContextInfo;
 
 /**
  * The application cache service manages the set of application cache
  * groups.
  */
-[scriptable, uuid(03b41c3d-0816-4134-8b2e-4f5afbdb1f06)]
+[scriptable, uuid(b8b6546c-6cec-4bda-82df-08e006a97b56)]
 interface nsIApplicationCacheService : nsISupports
 {
     /**
      * Create group string identifying cache group according the manifest
-     * URL and the given load context.
+     * URL and the given principal.
      */
-    ACString buildGroupID(in nsIURI aManifestURL,
-                          in nsILoadContextInfo aLoadContextInfo);
-
-    /**
-     * Same as buildGroupID method, just doesn't require load context.
-     */
-    ACString buildGroupIDForApp(in nsIURI aManifestURL,
-                                in unsigned long aAppID,
-                                in boolean aInBrowser);
+    ACString buildGroupIDForInfo(in nsIURI aManifestURL,
+                                 in nsILoadContextInfo aLoadContextInfo);
+    ACString buildGroupIDForSuffix(in nsIURI aManifestURL,
+                                   in ACString aOriginSuffix);
 
     /**
      * Create a new, empty application cache for the given cache
      * group.
      */
     nsIApplicationCache createApplicationCache(in ACString group);
 
     /**
@@ -65,28 +60,25 @@ interface nsIApplicationCacheService : n
     nsIApplicationCache getActiveCache(in ACString group);
 
     /**
      * Deactivate the currently-active cache object for a cache group.
      */
     void deactivateGroup(in ACString group);
 
     /**
-     * Deletes some or all of an application's cache entries.  
-     *
-     * @param appId
-     *    The mozIApplication.localId of the application.
-     * 
-     * @param discardOnlyBrowserEntries 
-     *    If true, only entries marked as 'inBrowserElement' are deleted 
-     *    (this is used by browser applications to delete user browsing 
-     *    data/history.).  If false, *all* entries for the given appId are
-     *    deleted (this is used for application uninstallation).
+     * Evict offline cache entries, either all of them or those belonging
+     * to the given origin.
      */
-    void discardByAppId(in int32_t appID, in boolean discardOnlyBrowserEntries);
+    void evict(in nsILoadContextInfo aLoadContextInfo);
+
+    /**
+     * Delete caches whom origin attributes matches the given pattern.
+     */
+    void evictMatchingOriginAttributes(in AString aPattern);
 
     /**
      * Try to find the best application cache to serve a resource.
      */
     nsIApplicationCache chooseApplicationCache(in ACString key,
                                                [optional] in nsILoadContextInfo aLoadContextInfo);
 
     /**
--- a/netwerk/cache/nsApplicationCacheService.cpp
+++ b/netwerk/cache/nsApplicationCacheService.cpp
@@ -6,17 +6,18 @@
 #include "nsDiskCacheDeviceSQL.h"
 #include "nsCacheService.h"
 #include "nsApplicationCacheService.h"
 #include "nsCRT.h"
 #include "mozIApplicationClearPrivateDataParams.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsIObserverService.h"
-#include "nsILoadContextInfo.h"
+#include "nsIPrincipal.h"
+#include "mozilla/LoadContextInfo.h"
 
 using namespace mozilla;
 
 static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID);
 
 //-----------------------------------------------------------------------------
 // nsApplicationCacheService
 //-----------------------------------------------------------------------------
@@ -29,44 +30,45 @@ nsApplicationCacheService::nsApplication
     mCacheService = nsCacheService::GlobalInstance();
 }
 
 nsApplicationCacheService::~nsApplicationCacheService()
 {
 }
 
 NS_IMETHODIMP
-nsApplicationCacheService::BuildGroupID(nsIURI *aManifestURL,
-                                        nsILoadContextInfo *aLoadContextInfo,
-                                        nsACString &_result)
+nsApplicationCacheService::BuildGroupIDForInfo(
+    nsIURI *aManifestURL,
+    nsILoadContextInfo *aLoadContextInfo,
+    nsACString &_result)
 {
     nsresult rv;
 
-    mozilla::NeckoOriginAttributes const *oa = aLoadContextInfo
-        ? aLoadContextInfo->OriginAttributesPtr()
-        : nullptr;
+    nsAutoCString originSuffix;
+    if (aLoadContextInfo) {
+        aLoadContextInfo->OriginAttributesPtr()->CreateSuffix(originSuffix);
+    }
 
     rv = nsOfflineCacheDevice::BuildApplicationCacheGroupID(
-        aManifestURL, oa, _result);
+        aManifestURL, originSuffix, _result);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsApplicationCacheService::BuildGroupIDForApp(nsIURI *aManifestURL,
-                                              uint32_t aAppId,
-                                              bool aIsInBrowser,
-                                              nsACString &_result)
+nsApplicationCacheService::BuildGroupIDForSuffix(
+    nsIURI *aManifestURL,
+    nsACString const &aOriginSuffix,
+    nsACString &_result)
 {
-    NeckoOriginAttributes oa;
-    oa.mAppId = aAppId;
-    oa.mInBrowser = aIsInBrowser;
-    nsresult rv = nsOfflineCacheDevice::BuildApplicationCacheGroupID(
-        aManifestURL, &oa, _result);
+    nsresult rv;
+
+    rv = nsOfflineCacheDevice::BuildApplicationCacheGroupID(
+        aManifestURL, aOriginSuffix, _result);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsApplicationCacheService::CreateApplicationCache(const nsACString &group,
                                                   nsIApplicationCache **out)
@@ -159,25 +161,44 @@ nsApplicationCacheService::CacheOpportun
 
     RefPtr<nsOfflineCacheDevice> device;
     nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
     NS_ENSURE_SUCCESS(rv, rv);
     return device->CacheOpportunistically(cache, key);
 }
 
 NS_IMETHODIMP
-nsApplicationCacheService::DiscardByAppId(int32_t appID, bool isInBrowser)
+nsApplicationCacheService::Evict(nsILoadContextInfo *aInfo)
 {
     if (!mCacheService)
         return NS_ERROR_UNEXPECTED;
 
     RefPtr<nsOfflineCacheDevice> device;
     nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
     NS_ENSURE_SUCCESS(rv, rv);
-    return device->DiscardByAppId(appID, isInBrowser);
+    return device->Evict(aInfo);
+}
+
+NS_IMETHODIMP
+nsApplicationCacheService::EvictMatchingOriginAttributes(nsAString const &aPattern)
+{
+    if (!mCacheService)
+        return NS_ERROR_UNEXPECTED;
+
+    RefPtr<nsOfflineCacheDevice> device;
+    nsresult rv = mCacheService->GetOfflineDevice(getter_AddRefs(device));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    mozilla::OriginAttributesPattern pattern;
+    if (!pattern.Init(aPattern)) {
+        NS_ERROR("Could not parse OriginAttributesPattern JSON in clear-origin-data notification");
+        return NS_ERROR_FAILURE;
+    }
+
+    return device->Evict(pattern);
 }
 
 NS_IMETHODIMP
 nsApplicationCacheService::GetGroups(uint32_t *count,
                                      char ***keys)
 {
     if (!mCacheService)
         return NS_ERROR_UNEXPECTED;
@@ -211,44 +232,37 @@ namespace {
 class AppCacheClearDataObserver final : public nsIObserver {
 public:
     NS_DECL_ISUPPORTS
 
     // nsIObserver implementation.
     NS_IMETHODIMP
     Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData) override
     {
-        MOZ_ASSERT(!nsCRT::strcmp(aTopic, TOPIC_WEB_APP_CLEAR_DATA));
+        MOZ_ASSERT(!nsCRT::strcmp(aTopic, "clear-origin-data"));
 
-        uint32_t appId = NECKO_UNKNOWN_APP_ID;
-        bool browserOnly = false;
-        nsresult rv = NS_GetAppInfoFromClearDataNotification(aSubject, &appId,
-                                                             &browserOnly);
-        NS_ENSURE_SUCCESS(rv, rv);
+        nsresult rv;
 
         nsCOMPtr<nsIApplicationCacheService> cacheService =
             do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        return cacheService->DiscardByAppId(appId, browserOnly);
+        return cacheService->EvictMatchingOriginAttributes(nsDependentString(aData));
     }
 
 private:
     ~AppCacheClearDataObserver() {}
 };
 
 NS_IMPL_ISUPPORTS(AppCacheClearDataObserver, nsIObserver)
 
 } // namespace
 
 // Instantiates and registers AppCacheClearDataObserver for notifications
 void
 nsApplicationCacheService::AppClearDataObserverInit()
 {
   nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
   if (observerService) {
-    RefPtr<AppCacheClearDataObserver> obs
-      = new AppCacheClearDataObserver();
-    observerService->AddObserver(obs, TOPIC_WEB_APP_CLEAR_DATA,
-				 /*holdsWeak=*/ false);
+    RefPtr<AppCacheClearDataObserver> obs = new AppCacheClearDataObserver();
+    observerService->AddObserver(obs, "clear-origin-data", /*holdsWeak=*/ false);
   }
 }
-
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -43,16 +43,18 @@
 
 #include "nsICacheVisitor.h"
 #include "nsISeekableStream.h"
 
 #include "mozilla/Telemetry.h"
 
 #include "sqlite3.h"
 #include "mozilla/storage.h"
+#include "nsVariant.h"
+#include "mozilla/BasePrincipal.h"
 
 using namespace mozilla;
 using namespace mozilla::storage;
 using mozilla::NeckoOriginAttributes;
 
 static const char OFFLINE_CACHE_DEVICE_ID[] = { "offline" };
 
 #define LOG(args) CACHE_LOG_DEBUG(args)
@@ -1300,46 +1302,35 @@ GetGroupForCache(const nsCSubstring &cli
 {
   group.Assign(clientID);
   group.Truncate(group.FindChar('|'));
   NS_UnescapeURL(group);
 
   return NS_OK;
 }
 
-void
-AppendJARIdentifier(nsACString &_result, NeckoOriginAttributes const *aOriginAttributes)
-{
-  nsAutoCString suffix;
-  aOriginAttributes->CreateSuffix(suffix);
-  _result.Append('#');
-  _result.Append(suffix);
-}
-
 } // namespace
 
 // static
 nsresult
 nsOfflineCacheDevice::BuildApplicationCacheGroupID(nsIURI *aManifestURL,
-                                                   NeckoOriginAttributes const *aOriginAttributes,
+                                                   nsACString const &aOriginSuffix,
                                                    nsACString &_result)
 {
   nsCOMPtr<nsIURI> newURI;
   nsresult rv = aManifestURL->CloneIgnoringRef(getter_AddRefs(newURI));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoCString manifestSpec;
   rv = newURI->GetAsciiSpec(manifestSpec);
   NS_ENSURE_SUCCESS(rv, rv);
 
   _result.Assign(manifestSpec);
-
-  if (aOriginAttributes) {
-    AppendJARIdentifier(_result, aOriginAttributes);
-  }
+  _result.Append('#');
+  _result.Append(aOriginSuffix);
 
   return NS_OK;
 }
 
 nsresult
 nsOfflineCacheDevice::InitActiveCaches()
 {
   MutexAutoLock lock(mLock);
@@ -2400,65 +2391,166 @@ nsOfflineCacheDevice::DeactivateGroup(co
     mActiveCachesByGroup.Remove(group);
     active = nullptr;
   }
 
   return NS_OK;
 }
 
 nsresult
-nsOfflineCacheDevice::DiscardByAppId(int32_t appID, bool browserEntriesOnly)
+nsOfflineCacheDevice::Evict(nsILoadContextInfo *aInfo)
 {
+  NS_ENSURE_ARG(aInfo);
+
   nsresult rv;
 
+  mozilla::OriginAttributes const *oa = aInfo->OriginAttributesPtr();
+
+  if (oa->mAppId == NECKO_NO_APP_ID && oa->mInBrowser == false) {
+    nsCOMPtr<nsICacheService> serv = do_GetService(kCacheServiceCID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    return nsCacheService::GlobalInstance()->EvictEntriesInternal(nsICache::STORE_OFFLINE);
+  }
+
   nsAutoCString jaridsuffix;
-
   jaridsuffix.Append('%');
 
-  // TODO - this method should accept NeckoOriginAttributes* from outside instead.
-  // If passed null, we should then delegate to
-  // nsCacheService::GlobalInstance()->EvictEntriesInternal(nsICache::STORE_OFFLINE);
-
-  NeckoOriginAttributes oa;
-  oa.mAppId = appID;
-  oa.mInBrowser = browserEntriesOnly;
-  AppendJARIdentifier(jaridsuffix, &oa);
-
-  {
-    AutoResetStatement statement(mStatement_EnumerateApps);
-    rv = statement->BindUTF8StringByIndex(0, jaridsuffix);
+  nsAutoCString suffix;
+  oa->CreateSuffix(suffix);
+  jaridsuffix.Append('#');
+  jaridsuffix.Append(suffix);
+
+  AutoResetStatement statement(mStatement_EnumerateApps);
+  rv = statement->BindUTF8StringByIndex(0, jaridsuffix);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  bool hasRows;
+  rv = statement->ExecuteStep(&hasRows);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  while (hasRows) {
+    nsAutoCString group;
+    rv = statement->GetUTF8String(0, group);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    bool hasRows;
+    nsCString clientID;
+    rv = statement->GetUTF8String(1, clientID);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIRunnable> ev =
+      new nsOfflineCacheDiscardCache(this, group, clientID);
+
+    rv = nsCacheService::DispatchToCacheIOThread(ev);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     rv = statement->ExecuteStep(&hasRows);
     NS_ENSURE_SUCCESS(rv, rv);
-
-    while (hasRows) {
-      nsAutoCString group;
-      rv = statement->GetUTF8String(0, group);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      nsCString clientID;
-      rv = statement->GetUTF8String(1, clientID);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      nsCOMPtr<nsIRunnable> ev =
-        new nsOfflineCacheDiscardCache(this, group, clientID);
-
-      rv = nsCacheService::DispatchToCacheIOThread(ev);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = statement->ExecuteStep(&hasRows);
-      NS_ENSURE_SUCCESS(rv, rv);
+  }
+
+  return NS_OK;
+}
+
+namespace { // anon
+
+class OriginMatch final : public mozIStorageFunction
+{
+  ~OriginMatch() {}
+  mozilla::OriginAttributesPattern const mPattern;
+
+  NS_DECL_ISUPPORTS
+  NS_DECL_MOZISTORAGEFUNCTION
+  explicit OriginMatch(mozilla::OriginAttributesPattern const &aPattern)
+    : mPattern(aPattern) {}
+};
+
+NS_IMPL_ISUPPORTS(OriginMatch, mozIStorageFunction)
+
+NS_IMETHODIMP
+OriginMatch::OnFunctionCall(mozIStorageValueArray* aFunctionArguments, nsIVariant** aResult)
+{
+  nsresult rv;
+
+  nsAutoCString groupId;
+  rv = aFunctionArguments->GetUTF8String(0, groupId);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  int32_t hash = groupId.Find(NS_LITERAL_CSTRING("#"));
+  if (hash == kNotFound) {
+    // Just ignore...
+    return NS_OK;
+  }
+
+  ++hash;
+
+  nsDependentCSubstring suffix(groupId.BeginReading() + hash, groupId.Length() - hash);
+
+  mozilla::NeckoOriginAttributes oa;
+  bool ok = oa.PopulateFromSuffix(suffix);
+  NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
+
+  bool match = mPattern.Matches(oa);
+
+  RefPtr<nsVariant> outVar(new nsVariant());
+  rv = outVar->SetAsUint32(match ? 1 : 0);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  outVar.forget(aResult);
+  return NS_OK;
+}
+
+} // anon
+
+nsresult
+nsOfflineCacheDevice::Evict(mozilla::OriginAttributesPattern const &aPattern)
+{
+  nsresult rv;
+
+  nsCOMPtr<mozIStorageFunction> function1(new OriginMatch(aPattern));
+  rv = mDB->CreateFunction(NS_LITERAL_CSTRING("ORIGIN_MATCH"), 1, function1);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  class AutoRemoveFunc {
+  public:
+    mozIStorageConnection* mDB;
+    explicit AutoRemoveFunc(mozIStorageConnection* aDB) : mDB(aDB) {}
+    ~AutoRemoveFunc() {
+      mDB->RemoveFunction(NS_LITERAL_CSTRING("ORIGIN_MATCH"));
     }
-  }
-
-  if (!browserEntriesOnly) {
-    // If deleting app, delete any 'inBrowserElement' entries too
-    rv = DiscardByAppId(appID, true);
+  };
+  AutoRemoveFunc autoRemove(mDB);
+
+  nsCOMPtr<mozIStorageStatement> statement;
+  rv = mDB->CreateStatement(
+    NS_LITERAL_CSTRING("SELECT GroupID, ActiveClientID FROM moz_cache_groups WHERE ORIGIN_MATCH(GroupID);"),
+    getter_AddRefs(statement));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  AutoResetStatement statementScope(statement);
+
+  bool hasRows;
+  rv = statement->ExecuteStep(&hasRows);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  while (hasRows) {
+    nsAutoCString group;
+    rv = statement->GetUTF8String(0, group);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCString clientID;
+    rv = statement->GetUTF8String(1, clientID);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIRunnable> ev =
+      new nsOfflineCacheDiscardCache(this, group, clientID);
+
+    rv = nsCacheService::DispatchToCacheIOThread(ev);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = statement->ExecuteStep(&hasRows);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 bool
 nsOfflineCacheDevice::CanUseCache(nsIURI *keyURI,
@@ -2490,41 +2582,45 @@ nsOfflineCacheDevice::CanUseCache(nsIURI
   if (!NS_SecurityCompareURIs(keyURI, groupURI,
                               GetStrictFileOriginPolicy())) {
     return false;
   }
 
   // Check the groupID we found is equal to groupID based
   // on the load context demanding load from app cache.
   // This is check of extended origin.
+
+  nsAutoCString originSuffix;
+  loadContextInfo->OriginAttributesPtr()->CreateSuffix(originSuffix);
+
   nsAutoCString demandedGroupID;
-
-  const NeckoOriginAttributes *oa = loadContextInfo
-    ? loadContextInfo->OriginAttributesPtr()
-    : nullptr;
-  rv = BuildApplicationCacheGroupID(groupURI, oa, demandedGroupID);
+  rv = BuildApplicationCacheGroupID(groupURI, originSuffix, demandedGroupID);
   NS_ENSURE_SUCCESS(rv, false);
 
   if (groupID != demandedGroupID) {
     return false;
   }
 
   return true;
 }
 
 
 nsresult
 nsOfflineCacheDevice::ChooseApplicationCache(const nsACString &key,
                                              nsILoadContextInfo *loadContextInfo,
                                              nsIApplicationCache **out)
 {
+  NS_ENSURE_ARG(loadContextInfo);
+
+  nsresult rv;
+
   *out = nullptr;
 
   nsCOMPtr<nsIURI> keyURI;
-  nsresult rv = NS_NewURI(getter_AddRefs(keyURI), key);
+  rv = NS_NewURI(getter_AddRefs(keyURI), key);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // First try to find a matching cache entry.
   AutoResetStatement statement(mStatement_FindClient);
   rv = statement->BindUTF8StringByIndex(0, key);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasRows;
@@ -2695,16 +2791,17 @@ nsOfflineCacheDevice::AutoShutdown(nsIAp
 {
   if (!mAutoShutdown)
     return false;
 
   mAutoShutdown = false;
 
   Shutdown();
 
+  nsCOMPtr<nsICacheService> serv = do_GetService(kCacheServiceCID);
   RefPtr<nsCacheService> cacheService = nsCacheService::GlobalInstance();
   cacheService->RemoveCustomOfflineDevice(this);
 
   nsAutoCString clientID;
   aAppCache->GetClientID(clientID);
 
   MutexAutoLock lock(mLock);
   mCaches.Remove(clientID);
--- a/netwerk/cache/nsDiskCacheDeviceSQL.h
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.h
@@ -20,17 +20,18 @@
 #include "nsClassHashtable.h"
 #include "nsWeakReference.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 
 class nsIURI;
 class nsOfflineCacheDevice;
 class mozIStorageService;
-namespace mozilla { class NeckoOriginAttributes; }
+class nsILoadContextInfo;
+namespace mozilla { class OriginAttributesPattern; }
 
 class nsApplicationCacheNamespace final : public nsIApplicationCacheNamespace
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIAPPLICATIONCACHENAMESPACE
 
   nsApplicationCacheNamespace() : mItemType(0) {}
@@ -136,17 +137,17 @@ public:
                                      const nsACString &       key,
                                      bool *                 isOwned);
 
   nsresult                ClearKeysOwnedByDomain(const char *clientID,
                                                  const nsACString &ownerDomain);
   nsresult                EvictUnownedEntries(const char *clientID);
 
   static nsresult         BuildApplicationCacheGroupID(nsIURI *aManifestURL,
-                                                       mozilla::NeckoOriginAttributes const *aOriginAttributes,
+                                                       nsACString const &aOriginSuffix,
                                                        nsACString &_result);
 
   nsresult                ActivateCache(const nsCSubstring &group,
                                         const nsCSubstring &clientID);
   bool                    IsActiveCache(const nsCSubstring &group,
                                         const nsCSubstring &clientID);
   nsresult                CreateApplicationCache(const nsACString &group,
                                                  nsIApplicationCache **out);
@@ -163,17 +164,18 @@ public:
 
   nsresult                ChooseApplicationCache(const nsACString &key,
                                                  nsILoadContextInfo *loadContext,
                                                  nsIApplicationCache **out);
 
   nsresult                CacheOpportunistically(nsIApplicationCache* cache,
                                                  const nsACString &key);
 
-  nsresult                DiscardByAppId(int32_t appID, bool isInBrowser);
+  nsresult                Evict(nsILoadContextInfo *aInfo);
+  nsresult                Evict(mozilla::OriginAttributesPattern const &aPattern);
 
   nsresult                GetGroups(uint32_t *count,char ***keys);
 
   nsresult                GetGroupsTimeOrdered(uint32_t *count,
                                                char ***keys);
 
   bool                    IsLocked(const nsACString &key);
   void                    Lock(const nsACString &key);
--- a/netwerk/cache2/AppCacheStorage.cpp
+++ b/netwerk/cache2/AppCacheStorage.cpp
@@ -114,40 +114,25 @@ NS_IMETHODIMP AppCacheStorage::AsyncDoom
 
 NS_IMETHODIMP AppCacheStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallback)
 {
   if (!CacheStorageService::Self())
     return NS_ERROR_NOT_INITIALIZED;
 
   nsresult rv;
 
-  nsCOMPtr<nsIApplicationCacheService> appCacheService =
-    do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (!mAppCache) {
+    // Discard everything under this storage context
+    nsCOMPtr<nsIApplicationCacheService> appCacheService =
+      do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!mAppCache) {
-    // TODO - bug 1165256, have an API on nsIApplicationCacheService that takes
-    // optional OAs and decides internally what to do.
-    const NeckoOriginAttributes* oa = LoadInfo()->OriginAttributesPtr();
-    if (oa->mAppId == nsILoadContextInfo::NO_APP_ID && !oa->mInBrowser) {
-      // Clear everything.
-      nsCOMPtr<nsICacheService> serv =
-          do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = nsCacheService::GlobalInstance()->EvictEntriesInternal(nsICache::STORE_OFFLINE);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-    else {
-      // Clear app or inbrowser staff.
-      rv = appCacheService->DiscardByAppId(oa->mAppId, oa->mInBrowser);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-  }
-  else {
+    rv = appCacheService->Evict(LoadInfo());
+    NS_ENSURE_SUCCESS(rv, rv);
+  } else {
     // Discard the group
     RefPtr<_OldStorage> old = new _OldStorage(
       LoadInfo(), WriteToDisk(), LookupAppCache(), true, mAppCache);
     rv = old->AsyncEvictStorage(aCallback);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
   }
--- a/netwerk/cache2/OldWrappers.cpp
+++ b/netwerk/cache2/OldWrappers.cpp
@@ -990,81 +990,58 @@ NS_IMETHODIMP _OldStorage::AsyncDoomURI(
 
 NS_IMETHODIMP _OldStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallback)
 {
   LOG(("_OldStorage::AsyncEvictStorage"));
 
   nsresult rv;
 
   if (!mAppCache && mOfflineStorage) {
-    // TODO - bug 1165256, have an API on nsIApplicationCacheService that takes
-    // optional OAs and decides internally what to do.
-
-    // Special casing for pure offline storage
-    if (mLoadInfo->OriginAttributesPtr()->mAppId == nsILoadContextInfo::NO_APP_ID &&
-        !mLoadInfo->OriginAttributesPtr()->mInBrowser) {
+    nsCOMPtr<nsIApplicationCacheService> appCacheService =
+      do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
 
-      // Clear everything.
-      nsCOMPtr<nsICacheService> serv =
-          do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = nsCacheService::GlobalInstance()->EvictEntriesInternal(nsICache::STORE_OFFLINE);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-    else {
-      // Clear app or inbrowser staff.
-      nsCOMPtr<nsIApplicationCacheService> appCacheService =
-        do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
-      NS_ENSURE_SUCCESS(rv, rv);
+    rv = appCacheService->Evict(mLoadInfo);
+    NS_ENSURE_SUCCESS(rv, rv);
+  } else if (mAppCache) {
+    nsCOMPtr<nsICacheSession> session;
+    rv = GetCacheSession(EmptyCString(),
+                          mWriteToDisk, mLoadInfo, mAppCache,
+                          getter_AddRefs(session));
+    NS_ENSURE_SUCCESS(rv, rv);
 
-      rv = appCacheService->DiscardByAppId(mLoadInfo->OriginAttributesPtr()->mAppId,
-                                           mLoadInfo->OriginAttributesPtr()->mInBrowser);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-  }
-  else {
-    if (mAppCache) {
-      nsCOMPtr<nsICacheSession> session;
-      rv = GetCacheSession(EmptyCString(),
-                           mWriteToDisk, mLoadInfo, mAppCache,
-                           getter_AddRefs(session));
-      NS_ENSURE_SUCCESS(rv, rv);
+    rv = session->EvictEntries();
+    NS_ENSURE_SUCCESS(rv, rv);
+  } else {
+    // Oh, I'll be so happy when session names are gone...
+    nsCOMPtr<nsICacheSession> session;
+    rv = GetCacheSession(NS_LITERAL_CSTRING("http"),
+                          mWriteToDisk, mLoadInfo, mAppCache,
+                          getter_AddRefs(session));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = session->EvictEntries();
+    NS_ENSURE_SUCCESS(rv, rv);
 
-      rv = session->EvictEntries();
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-    else {
-      // Oh, I'll be so happy when session names are gone...
-      nsCOMPtr<nsICacheSession> session;
-      rv = GetCacheSession(NS_LITERAL_CSTRING("http"),
-                           mWriteToDisk, mLoadInfo, mAppCache,
-                           getter_AddRefs(session));
-      NS_ENSURE_SUCCESS(rv, rv);
+    rv = GetCacheSession(NS_LITERAL_CSTRING("wyciwyg"),
+                          mWriteToDisk, mLoadInfo, mAppCache,
+                          getter_AddRefs(session));
+    NS_ENSURE_SUCCESS(rv, rv);
 
-      rv = session->EvictEntries();
-      NS_ENSURE_SUCCESS(rv, rv);
+    rv = session->EvictEntries();
+    NS_ENSURE_SUCCESS(rv, rv);
 
-      rv = GetCacheSession(NS_LITERAL_CSTRING("wyciwyg"),
-                           mWriteToDisk, mLoadInfo, mAppCache,
-                           getter_AddRefs(session));
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = session->EvictEntries();
-      NS_ENSURE_SUCCESS(rv, rv);
+    // This clears any data from scheme other then http, wyciwyg or ftp
+    rv = GetCacheSession(EmptyCString(),
+                          mWriteToDisk, mLoadInfo, mAppCache,
+                          getter_AddRefs(session));
+    NS_ENSURE_SUCCESS(rv, rv);
 
-      // This clears any data from scheme other then http, wyciwyg or ftp
-      rv = GetCacheSession(EmptyCString(),
-                           mWriteToDisk, mLoadInfo, mAppCache,
-                           getter_AddRefs(session));
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = session->EvictEntries();
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
+    rv = session->EvictEntries();
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aCallback) {
     RefPtr<DoomCallbackSynchronizer> sync =
       new DoomCallbackSynchronizer(aCallback);
     rv = sync->Dispatch();
     NS_ENSURE_SUCCESS(rv, rv);
   }
--- a/netwerk/test/unit/test_offlinecache_custom-directory.js
+++ b/netwerk/test/unit/test_offlinecache_custom-directory.js
@@ -122,17 +122,16 @@ function run_test()
   ps.setComplexValue("browser.cache.offline.parent_directory", Ci.nsILocalFile, profileDir);
 
   var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].
            getService(Ci.nsIOfflineCacheUpdateService);
   var update = us.scheduleAppUpdate(
       make_uri("http://localhost:4444/manifest"),
       make_uri("http://localhost:4444/masterEntry"),
       systemPrincipal,
-      0 /* no AppID */, false /* not in browser*/,
       customDir);
 
   var expectedStates = [
       Ci.nsIOfflineCacheUpdateObserver.STATE_DOWNLOADING,
       Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMSTARTED,
       Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMPROGRESS,
       Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMCOMPLETED,
       Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED
--- a/uriloader/prefetch/OfflineCacheUpdateChild.cpp
+++ b/uriloader/prefetch/OfflineCacheUpdateChild.cpp
@@ -72,18 +72,16 @@ NS_IMPL_RELEASE(OfflineCacheUpdateChild)
 //-----------------------------------------------------------------------------
 // OfflineCacheUpdateChild <public>
 //-----------------------------------------------------------------------------
 
 OfflineCacheUpdateChild::OfflineCacheUpdateChild(nsIDOMWindow* aWindow)
     : mState(STATE_UNINITIALIZED)
     , mIsUpgrade(false)
     , mSucceeded(false)
-    , mAppID(NECKO_NO_APP_ID)
-    , mInBrowser(false)
     , mWindow(aWindow)
     , mByteProgress(0)
 {
 }
 
 OfflineCacheUpdateChild::~OfflineCacheUpdateChild()
 {
     LOG(("OfflineCacheUpdateChild::~OfflineCacheUpdateChild [%p]", this));
@@ -173,19 +171,17 @@ OfflineCacheUpdateChild::AssociateDocume
 // OfflineCacheUpdateChild::nsIOfflineCacheUpdate
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 OfflineCacheUpdateChild::Init(nsIURI *aManifestURI,
                               nsIURI *aDocumentURI,
                               nsIPrincipal *aLoadingPrincipal,
                               nsIDOMDocument *aDocument,
-                              nsIFile *aCustomProfileDir,
-                              uint32_t aAppID,
-                              bool aInBrowser)
+                              nsIFile *aCustomProfileDir)
 {
     nsresult rv;
 
     // Make sure the service has been initialized
     nsOfflineCacheUpdateService* service =
         nsOfflineCacheUpdateService::EnsureService();
     if (!service)
         return NS_ERROR_FAILURE;
@@ -217,19 +213,16 @@ OfflineCacheUpdateChild::Init(nsIURI *aM
     mDocumentURI = aDocumentURI;
     mLoadingPrincipal = aLoadingPrincipal;
 
     mState = STATE_INITIALIZED;
 
     if (aDocument)
         SetDocument(aDocument);
 
-    mAppID = aAppID;
-    mInBrowser = aInBrowser;
-
     return NS_OK;
 }
 
 NS_IMETHODIMP
 OfflineCacheUpdateChild::InitPartial(nsIURI *aManifestURI,
                                   const nsACString& clientID,
                                   nsIURI *aDocumentURI,
                                   nsIPrincipal *aLoadingPrincipal)
@@ -238,18 +231,16 @@ OfflineCacheUpdateChild::InitPartial(nsI
                   " on the child process");
     // For now leaving this method, we may discover we need it.
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 OfflineCacheUpdateChild::InitForUpdateCheck(nsIURI *aManifestURI,
                                             nsIPrincipal* aLoadingPrincipal,
-                                            uint32_t aAppID,
-                                            bool aInBrowser,
                                             nsIObserver *aObserver)
 {
     NS_NOTREACHED("Not expected to do only update checks"
                   " from the child process");
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
@@ -439,17 +430,17 @@ OfflineCacheUpdateChild::Schedule()
     // See also nsOfflineCacheUpdate::ScheduleImplicit.
     bool stickDocument = mDocument != nullptr; 
 
     // Need to addref ourself here, because the IPC stack doesn't hold
     // a reference to us. Will be released in RecvFinish() that identifies 
     // the work has been done.
     ContentChild::GetSingleton()->SendPOfflineCacheUpdateConstructor(
         this, manifestURI, documentURI, loadingPrincipalInfo,
-        stickDocument, child->GetTabId());
+        stickDocument);
 
     // ContentChild::DeallocPOfflineCacheUpdate will release this.
     NS_ADDREF_THIS();
 
     return NS_OK;
 }
 
 bool
--- a/uriloader/prefetch/OfflineCacheUpdateChild.h
+++ b/uriloader/prefetch/OfflineCacheUpdateChild.h
@@ -67,19 +67,16 @@ private:
 
     nsCString mUpdateDomain;
     nsCOMPtr<nsIURI> mManifestURI;
     nsCOMPtr<nsIURI> mDocumentURI;
     nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
 
     nsCOMPtr<nsIObserverService> mObserverService;
 
-    uint32_t mAppID;
-    bool mInBrowser;
-
     /* Clients watching this update for changes */
     nsCOMArray<nsIWeakReference> mWeakObservers;
     nsCOMArray<nsIOfflineCacheUpdateObserver> mObservers;
 
     /* Document that requested this update */
     nsCOMPtr<nsIDOMDocument> mDocument;
 
     /* Keep reference to the window that owns this update to call the
--- a/uriloader/prefetch/OfflineCacheUpdateGlue.cpp
+++ b/uriloader/prefetch/OfflineCacheUpdateGlue.cpp
@@ -94,24 +94,28 @@ OfflineCacheUpdateGlue::Schedule()
     return mUpdate->Schedule();
 }
 
 NS_IMETHODIMP
 OfflineCacheUpdateGlue::Init(nsIURI *aManifestURI,
                              nsIURI *aDocumentURI,
                              nsIPrincipal* aLoadingPrincipal,
                              nsIDOMDocument *aDocument,
-                             nsIFile *aCustomProfileDir,
-                             uint32_t aAppID,
-                             bool aInBrowser)
+                             nsIFile *aCustomProfileDir)
 {
+    nsresult rv;
+
+    nsAutoCString originSuffix;
+    rv = aLoadingPrincipal->GetOriginSuffix(originSuffix);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     nsOfflineCacheUpdateService* service =
         nsOfflineCacheUpdateService::EnsureService();
     if (service) {
-        service->FindUpdate(aManifestURI, aAppID, aInBrowser, aCustomProfileDir,
+        service->FindUpdate(aManifestURI, originSuffix, aCustomProfileDir,
                             getter_AddRefs(mUpdate));
         mCoalesced = !!mUpdate;
     }
 
     if (!EnsureUpdate())
         return NS_ERROR_NULL_POINTER;
 
     mDocumentURI = aDocumentURI;
@@ -121,17 +125,17 @@ OfflineCacheUpdateGlue::Init(nsIURI *aMa
         SetDocument(aDocument);
 
     if (mCoalesced) { // already initialized
         LOG(("OfflineCacheUpdateGlue %p coalesced with update %p", this, mUpdate.get()));
         return NS_OK;
     }
 
     return mUpdate->Init(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr,
-                         aCustomProfileDir, aAppID, aInBrowser);
+                         aCustomProfileDir);
 }
 
 void
 OfflineCacheUpdateGlue::SetDocument(nsIDOMDocument *aDocument)
 {
     // The design is one document for one cache update on the content process.
     NS_ASSERTION(!mDocument, 
                  "Setting more then a single document on an instance of OfflineCacheUpdateGlue");
--- a/uriloader/prefetch/OfflineCacheUpdateGlue.h
+++ b/uriloader/prefetch/OfflineCacheUpdateGlue.h
@@ -25,17 +25,17 @@ namespace docshell {
 #define NS_ADJUSTED_FORWARD_NSIOFFLINECACHEUPDATE(_to) \
   NS_IMETHOD GetStatus(uint16_t *aStatus) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetStatus(aStatus); } \
   NS_IMETHOD GetPartial(bool *aPartial) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetPartial(aPartial); } \
   NS_IMETHOD GetIsUpgrade(bool *aIsUpgrade) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIsUpgrade(aIsUpgrade); } \
   NS_IMETHOD GetUpdateDomain(nsACString & aUpdateDomain) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetUpdateDomain(aUpdateDomain); } \
   NS_IMETHOD GetManifestURI(nsIURI **aManifestURI) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetManifestURI(aManifestURI); } \
   NS_IMETHOD GetSucceeded(bool *aSucceeded) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetSucceeded(aSucceeded); } \
   NS_IMETHOD InitPartial(nsIURI *aManifestURI, const nsACString & aClientID, nsIURI *aDocumentURI, nsIPrincipal *aLoadingPrincipal) override { return !_to ? NS_ERROR_NULL_POINTER : _to->InitPartial(aManifestURI, aClientID, aDocumentURI, aLoadingPrincipal); } \
-  NS_IMETHOD InitForUpdateCheck(nsIURI *aManifestURI, nsIPrincipal* aLoadingPrincipal, uint32_t aAppID, bool aInBrowser, nsIObserver *aObserver) override { return !_to ? NS_ERROR_NULL_POINTER : _to->InitForUpdateCheck(aManifestURI, aLoadingPrincipal, aAppID, aInBrowser, aObserver); } \
+  NS_IMETHOD InitForUpdateCheck(nsIURI *aManifestURI, nsIPrincipal* aLoadingPrincipal, nsIObserver *aObserver) override { return !_to ? NS_ERROR_NULL_POINTER : _to->InitForUpdateCheck(aManifestURI, aLoadingPrincipal, aObserver); } \
   NS_IMETHOD AddDynamicURI(nsIURI *aURI) override { return !_to ? NS_ERROR_NULL_POINTER : _to->AddDynamicURI(aURI); } \
   NS_IMETHOD AddObserver(nsIOfflineCacheUpdateObserver *aObserver, bool aHoldWeak) override { return !_to ? NS_ERROR_NULL_POINTER : _to->AddObserver(aObserver, aHoldWeak); } \
   NS_IMETHOD RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver) override { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveObserver(aObserver); } \
   NS_IMETHOD GetByteProgress(uint64_t * _result) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetByteProgress(_result); } \
   NS_IMETHOD Cancel() override { return !_to ? NS_ERROR_NULL_POINTER : _to->Cancel(); }
 
 class OfflineCacheUpdateGlue final : public nsSupportsWeakReference
                                    , public nsIOfflineCacheUpdate
@@ -49,19 +49,17 @@ private:
 
 public:
     NS_ADJUSTED_FORWARD_NSIOFFLINECACHEUPDATE(EnsureUpdate())
     NS_IMETHOD Schedule(void) override;
     NS_IMETHOD Init(nsIURI *aManifestURI,
                     nsIURI *aDocumentURI,
                     nsIPrincipal* aLoadingPrincipal,
                     nsIDOMDocument *aDocument,
-                    nsIFile *aCustomProfileDir,
-                    uint32_t aAppID,
-                    bool aInBrowser) override;
+                    nsIFile *aCustomProfileDir) override;
 
     NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER
 
     OfflineCacheUpdateGlue();
 
     void SetDocument(nsIDOMDocument *aDocument);
 
 private:
--- a/uriloader/prefetch/OfflineCacheUpdateParent.cpp
+++ b/uriloader/prefetch/OfflineCacheUpdateParent.cpp
@@ -49,19 +49,19 @@ namespace docshell {
 NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent,
                   nsIOfflineCacheUpdateObserver,
                   nsILoadContext)
 
 //-----------------------------------------------------------------------------
 // OfflineCacheUpdateParent <public>
 //-----------------------------------------------------------------------------
 
-OfflineCacheUpdateParent::OfflineCacheUpdateParent(const DocShellOriginAttributes& aAttrs)
+
+OfflineCacheUpdateParent::OfflineCacheUpdateParent()
     : mIPCClosed(false)
-    , mOriginAttributes(aAttrs)
 {
     // Make sure the service has been initialized
     nsOfflineCacheUpdateService::EnsureService();
 
     LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
 }
 
 OfflineCacheUpdateParent::~OfflineCacheUpdateParent()
@@ -78,64 +78,61 @@ OfflineCacheUpdateParent::ActorDestroy(A
 nsresult
 OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
                                    const URIParams& aDocumentURI,
                                    const PrincipalInfo& aLoadingPrincipalInfo,
                                    const bool& stickDocument)
 {
     LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
 
+    nsresult rv;
+
     RefPtr<nsOfflineCacheUpdate> update;
     nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI);
     if (!manifestURI)
         return NS_ERROR_FAILURE;
 
+    mLoadingPrincipal = PrincipalInfoToPrincipal(aLoadingPrincipalInfo, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     nsOfflineCacheUpdateService* service =
         nsOfflineCacheUpdateService::EnsureService();
     if (!service)
         return NS_ERROR_FAILURE;
 
     bool offlinePermissionAllowed = false;
 
-    PrincipalOriginAttributes principalAttrs;
-    principalAttrs.InheritFromDocShellToDoc(mOriginAttributes, manifestURI);
-    nsCOMPtr<nsIPrincipal> principal =
-      BasePrincipal::CreateCodebasePrincipal(manifestURI, principalAttrs);
-
-    nsresult rv = service->OfflineAppAllowed(
-        principal, nullptr, &offlinePermissionAllowed);
+    rv = service->OfflineAppAllowed(
+        mLoadingPrincipal, nullptr, &offlinePermissionAllowed);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!offlinePermissionAllowed)
         return NS_ERROR_DOM_SECURITY_ERR;
 
     nsCOMPtr<nsIURI> documentURI = DeserializeURI(aDocumentURI);
     if (!documentURI)
         return NS_ERROR_FAILURE;
 
     if (!NS_SecurityCompareURIs(manifestURI, documentURI, false))
         return NS_ERROR_DOM_SECURITY_ERR;
 
-    // TODO: Bug 1197093 - add originAttributes to nsIOfflineCacheUpdate
+    nsAutoCString originSuffix;
+    rv = mLoadingPrincipal->GetOriginSuffix(originSuffix);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     service->FindUpdate(manifestURI,
-                        mOriginAttributes.mAppId,
-                        mOriginAttributes.mInBrowser,
+                        originSuffix,
                         nullptr,
                         getter_AddRefs(update));
     if (!update) {
         update = new nsOfflineCacheUpdate();
 
-        nsCOMPtr<nsIPrincipal> loadingPrincipal =
-          PrincipalInfoToPrincipal(aLoadingPrincipalInfo, &rv);
-        NS_ENSURE_SUCCESS(rv, rv);
-
         // Leave aDocument argument null. Only glues and children keep 
         // document instances.
-        rv = update->Init(manifestURI, documentURI, loadingPrincipal, nullptr, nullptr,
-                          mOriginAttributes.mAppId, mOriginAttributes.mInBrowser);
+        rv = update->Init(manifestURI, documentURI, mLoadingPrincipal, nullptr, nullptr);
         NS_ENSURE_SUCCESS(rv, rv);
 
         rv = update->Schedule();
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     update->AddObserver(this, false);
 
@@ -259,32 +256,35 @@ NS_IMETHODIMP
 OfflineCacheUpdateParent::SetRemoteTabs(bool aUseRemoteTabs)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 OfflineCacheUpdateParent::GetIsInBrowserElement(bool *aIsInBrowserElement)
 {
-    *aIsInBrowserElement = mOriginAttributes.mInBrowser;
-    return NS_OK;
+    NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED);
+    return mLoadingPrincipal->GetIsInBrowserElement(aIsInBrowserElement);
 }
 
 NS_IMETHODIMP
 OfflineCacheUpdateParent::GetAppId(uint32_t *aAppId)
 {
-    *aAppId = mOriginAttributes.mAppId;
-    return NS_OK;
+    NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED);
+    return mLoadingPrincipal->GetAppId(aAppId);
 }
 
 NS_IMETHODIMP
 OfflineCacheUpdateParent::GetOriginAttributes(JS::MutableHandleValue aAttrs)
 {
+    NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED);
+
     JSContext* cx = nsContentUtils::GetCurrentJSContext();
     MOZ_ASSERT(cx);
 
-    bool ok = ToJSValue(cx, mOriginAttributes, aAttrs);
-    NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
+    nsresult rv = mLoadingPrincipal->GetOriginAttributes(cx, aAttrs);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     return NS_OK;
 }
 
 } // namespace docshell
 } // namespace mozilla
--- a/uriloader/prefetch/OfflineCacheUpdateParent.h
+++ b/uriloader/prefetch/OfflineCacheUpdateParent.h
@@ -5,19 +5,22 @@
 
 #ifndef nsOfflineCacheUpdateParent_h
 #define nsOfflineCacheUpdateParent_h
 
 #include "mozilla/docshell/POfflineCacheUpdateParent.h"
 #include "mozilla/BasePrincipal.h"
 #include "nsIOfflineCacheUpdate.h"
 
+#include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsILoadContext.h"
 
+class nsIPrincipal;
+
 namespace mozilla {
 
 namespace ipc {
 class URIParams;
 } // namespace ipc
 
 namespace docshell {
 
@@ -40,23 +43,23 @@ public:
              const bool& stickDocument);
 
     void
     StopSendingMessagesToChild()
     {
       mIPCClosed = true;
     }
 
-    explicit OfflineCacheUpdateParent(const mozilla::DocShellOriginAttributes& aAttrs);
+    explicit OfflineCacheUpdateParent();
 
     virtual void ActorDestroy(ActorDestroyReason aWhy) override;
 private:
     ~OfflineCacheUpdateParent();
 
     bool mIPCClosed;
 
-    mozilla::DocShellOriginAttributes mOriginAttributes;
+    nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
 };
 
 } // namespace docshell
 } // namespace mozilla
 
 #endif
--- a/uriloader/prefetch/nsIOfflineCacheUpdate.idl
+++ b/uriloader/prefetch/nsIOfflineCacheUpdate.idl
@@ -53,17 +53,17 @@ interface nsIOfflineCacheUpdateObserver 
  * resources.
  *
  * It can be used to perform partial or complete updates.
  *
  * One update object will be updating at a time.  The active object will
  * load its items one by one, sending itemCompleted() to any registered
  * observers.
  */
-[scriptable, uuid(e9029838-3553-4192-a00b-f0f11073a6eb)]
+[scriptable, uuid(6e3e26ea-45b2-4db7-9e4a-93b965679298)]
 interface nsIOfflineCacheUpdate : nsISupports {
   /**
    * Fetch the status of the running update.  This will return a value
    * defined in nsIDOMOfflineResourceList.
    */
   readonly attribute unsigned short status;
 
   /**
@@ -103,19 +103,17 @@ interface nsIOfflineCacheUpdate : nsISup
    *        The page that is requesting the update.
    * @param aLoadingPrincipal
    *        The principal of the page that is requesting the update.
    */
   void init(in nsIURI aManifestURI,
             in nsIURI aDocumentURI,
             in nsIPrincipal aLoadingPrincipal,
             in nsIDOMDocument aDocument,
-            [optional] in nsIFile aCustomProfileDir,
-            [optional] in unsigned long aAppId,
-            [optional] in boolean aInBrowser);
+            [optional] in nsIFile aCustomProfileDir);
 
   /**
    * Initialize the update for partial processing. 
    *
    * @param aManifestURI
    *        The manifest URI of the related cache.
    * @param aClientID
    *        Client  ID of the cache to store resource to. This ClientID
@@ -129,32 +127,26 @@ interface nsIOfflineCacheUpdate : nsISup
                    in nsIURI aDocumentURI, in nsIPrincipal aPrincipal);
 
   /**
    * Initialize the update to only check whether there is an update
    * to the manifest available (if it has actually changed on the server).
    *
    * @param aManifestURI
    *        The manifest URI of the related cache.
-   * @param aAppID
-   *        Local ID of an app (optional) to check the cache update for.
-   * @param aInBrowser
-   *        Whether to check for a cache populated from browser element.
    * @param aObserver
    *        nsIObserver implementation that receives the result.
    *        When aTopic == "offline-cache-update-available" there is an update to
    *        to download. Update of the app cache will lead to a new version
    *        download.
    *        When aTopic == "offline-cache-update-unavailable" then there is no
    *        update available (the manifest has not changed on the server).
    */
   void initForUpdateCheck(in nsIURI aManifestURI,
                           in nsIPrincipal aLoadingPrincipal,
-                          in unsigned long aAppID,
-                          in boolean aInBrowser,
                           in nsIObserver aObserver);
 
   /**
    * Add a dynamic URI to the offline cache as part of the update.
    *
    * @param aURI
    *        The URI to add.
    */
@@ -194,17 +186,17 @@ interface nsIOfflineCacheUpdate : nsISup
   void cancel();
 
   /**
    * Return the number of bytes downloaded so far
    */
   readonly attribute uint64_t byteProgress;
 };
 
-[scriptable, uuid(a297a334-bcae-4779-a564-555593edc96b)]
+[scriptable, uuid(39aee0e8-9478-475d-8b62-7535293cae08)]
 interface nsIOfflineCacheUpdateService : nsISupports {
     /**
      * Constants for the offline-app permission.
      *
      * XXX: This isn't a great place for this, but it's really the only
      * private offline-app-related interface
      */
 
@@ -234,18 +226,16 @@ interface nsIOfflineCacheUpdateService :
      * Schedule a cache update for a given offline manifest using app cache
      * bound to the given appID+inBrowser flag.  If an existing update is
      * scheduled or running, that update will be returned. Otherwise a new
      * update will be scheduled.
      */
     nsIOfflineCacheUpdate scheduleAppUpdate(in nsIURI aManifestURI,
                                             in nsIURI aDocumentURI,
                                             in nsIPrincipal aLoadingPrincipal,
-                                            in unsigned long aAppID,
-                                            in boolean aInBrowser,
                                             in nsIFile aProfileDir);
 
     /**
      * Schedule a cache update for a manifest when the document finishes
      * loading.
      */
     void scheduleOnDocumentStop(in nsIURI aManifestURI,
                                 in nsIURI aDocumentURI,
@@ -260,18 +250,16 @@ interface nsIOfflineCacheUpdateService :
      * changed on the server (or not): a changed manifest means that an
      * update is available.
      *
      * For arguments see nsIOfflineCacheUpdate.initForUpdateCheck() method
      * description.
      */
     void checkForUpdate(in nsIURI aManifestURI,
                         in nsIPrincipal aLoadingPrincipal,
-                        in unsigned long aAppID,
-                        in boolean aInBrowser,
                         in nsIObserver aObserver);
 
     /**
      * Checks whether a principal should have access to the offline
      * cache.
      * @param aPrincipal
      *        The principal to check.
      * @param aPrefBranch
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -1158,18 +1158,16 @@ NS_IMPL_ISUPPORTS(nsOfflineCacheUpdate,
 
 nsOfflineCacheUpdate::nsOfflineCacheUpdate()
     : mState(STATE_UNINITIALIZED)
     , mAddedItems(false)
     , mPartialUpdate(false)
     , mOnlyCheckUpdate(false)
     , mSucceeded(true)
     , mObsolete(false)
-    , mAppID(NECKO_NO_APP_ID)
-    , mInBrowser(false)
     , mItemsInProgress(0)
     , mRescheduleCount(0)
     , mPinnedEntryRetriesCount(0)
     , mPinned(false)
     , mByteProgress(0)
 {
 }
 
@@ -1223,19 +1221,17 @@ nsOfflineCacheUpdate::InitInternal(nsIUR
     return NS_OK;
 }
 
 nsresult
 nsOfflineCacheUpdate::Init(nsIURI *aManifestURI,
                            nsIURI *aDocumentURI,
                            nsIPrincipal* aLoadingPrincipal,
                            nsIDOMDocument *aDocument,
-                           nsIFile *aCustomProfileDir,
-                           uint32_t aAppID,
-                           bool aInBrowser)
+                           nsIFile *aCustomProfileDir)
 {
     nsresult rv;
 
     // Make sure the service has been initialized
     nsOfflineCacheUpdateService* service =
         nsOfflineCacheUpdateService::EnsureService();
     if (!service)
         return NS_ERROR_FAILURE;
@@ -1244,22 +1240,24 @@ nsOfflineCacheUpdate::Init(nsIURI *aMani
 
     rv = InitInternal(aManifestURI, aLoadingPrincipal);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIApplicationCacheService> cacheService =
         do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
+    nsAutoCString originSuffix;
+    rv = aLoadingPrincipal->GetOriginSuffix(originSuffix);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     mDocumentURI = aDocumentURI;
 
     if (aCustomProfileDir) {
-        rv = cacheService->BuildGroupIDForApp(aManifestURI,
-                                              aAppID, aInBrowser,
-                                              mGroupID);
+        rv = cacheService->BuildGroupIDForSuffix(aManifestURI, originSuffix, mGroupID);
         NS_ENSURE_SUCCESS(rv, rv);
 
         // Create only a new offline application cache in the custom profile
         // This is a preload of a new cache.
 
         // XXX Custom updates don't support "updating" of an existing cache
         // in the custom profile at the moment.  This support can be, though,
         // simply added as well when needed.
@@ -1269,47 +1267,40 @@ nsOfflineCacheUpdate::Init(nsIURI *aMani
                                                         aCustomProfileDir,
                                                         kCustomProfileQuota,
                                                         getter_AddRefs(mApplicationCache));
         NS_ENSURE_SUCCESS(rv, rv);
 
         mCustomProfileDir = aCustomProfileDir;
     }
     else {
-        rv = cacheService->BuildGroupIDForApp(aManifestURI,
-                                              aAppID, aInBrowser,
-                                              mGroupID);
+        rv = cacheService->BuildGroupIDForSuffix(aManifestURI, originSuffix, mGroupID);
         NS_ENSURE_SUCCESS(rv, rv);
 
         rv = cacheService->GetActiveCache(mGroupID,
                                           getter_AddRefs(mPreviousApplicationCache));
         NS_ENSURE_SUCCESS(rv, rv);
 
         rv = cacheService->CreateApplicationCache(mGroupID,
                                                   getter_AddRefs(mApplicationCache));
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     rv = nsOfflineCacheUpdateService::OfflineAppPinnedForURI(aDocumentURI,
                                                              nullptr,
                                                              &mPinned);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    mAppID = aAppID;
-    mInBrowser = aInBrowser;
-
     mState = STATE_INITIALIZED;
     return NS_OK;
 }
 
 nsresult
 nsOfflineCacheUpdate::InitForUpdateCheck(nsIURI *aManifestURI,
                                          nsIPrincipal* aLoadingPrincipal,
-                                         uint32_t aAppID,
-                                         bool aInBrowser,
                                          nsIObserver *aObserver)
 {
     nsresult rv;
 
     // Make sure the service has been initialized
     nsOfflineCacheUpdateService* service =
         nsOfflineCacheUpdateService::EnsureService();
     if (!service)
@@ -1319,19 +1310,21 @@ nsOfflineCacheUpdate::InitForUpdateCheck
 
     rv = InitInternal(aManifestURI, aLoadingPrincipal);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIApplicationCacheService> cacheService =
         do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = cacheService->BuildGroupIDForApp(aManifestURI,
-                                          aAppID, aInBrowser,
-                                          mGroupID);
+    nsAutoCString originSuffix;
+    rv = aLoadingPrincipal->GetOriginSuffix(originSuffix);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = cacheService->BuildGroupIDForSuffix(aManifestURI, originSuffix, mGroupID);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = cacheService->GetActiveCache(mGroupID,
                                       getter_AddRefs(mPreviousApplicationCache));
     NS_ENSURE_SUCCESS(rv, rv);
 
     // To load the manifest properly using current app cache to satisfy and
     // also to compare the cached content hash value we have to set 'some'
@@ -1705,17 +1698,17 @@ nsOfflineCacheUpdate::ManifestCheckCompl
         // correct.
         FinishNoNotify();
 
         RefPtr<nsOfflineCacheUpdate> newUpdate =
             new nsOfflineCacheUpdate();
         // Leave aDocument argument null. Only glues and children keep
         // document instances.
         newUpdate->Init(mManifestURI, mDocumentURI, mLoadingPrincipal, nullptr,
-                        mCustomProfileDir, mAppID, mInBrowser);
+                        mCustomProfileDir);
 
         // In a rare case the manifest will not be modified on the next refetch
         // transfer all master document URIs to the new update to ensure that
         // all documents refering it will be properly cached.
         for (int32_t i = 0; i < mDocumentURIs.Count(); i++) {
             newUpdate->StickDocument(mDocumentURIs[i]);
         }
 
--- a/uriloader/prefetch/nsOfflineCacheUpdate.h
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.h
@@ -276,19 +276,16 @@ private:
 
     nsCString mUpdateDomain;
     nsCString mGroupID;
     nsCOMPtr<nsIURI> mManifestURI;
     nsCOMPtr<nsIURI> mDocumentURI;
     nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
     nsCOMPtr<nsIFile> mCustomProfileDir;
 
-    uint32_t mAppID;
-    bool mInBrowser;
-
     nsCOMPtr<nsIObserver> mUpdateAvailableObserver;
 
     nsCOMPtr<nsIApplicationCache> mApplicationCache;
     nsCOMPtr<nsIApplicationCache> mPreviousApplicationCache;
 
     nsCOMPtr<nsIObserverService> mObserverService;
 
     RefPtr<nsOfflineManifestItem> mManifestItem;
@@ -330,29 +327,26 @@ public:
     NS_DECL_NSIOBSERVER
 
     nsOfflineCacheUpdateService();
 
     nsresult Init();
 
     nsresult ScheduleUpdate(nsOfflineCacheUpdate *aUpdate);
     nsresult FindUpdate(nsIURI *aManifestURI,
-                        uint32_t aAppID,
-                        bool aInBrowser,
+                        nsACString const &aOriginSuffix,
                         nsIFile *aCustomProfileDir,
                         nsOfflineCacheUpdate **aUpdate);
 
     nsresult Schedule(nsIURI *aManifestURI,
                       nsIURI *aDocumentURI,
                       nsIPrincipal* aLoadingPrincipal,
                       nsIDOMDocument *aDocument,
                       nsIDOMWindow* aWindow,
                       nsIFile* aCustomProfileDir,
-                      uint32_t aAppID,
-                      bool aInBrowser,
                       nsIOfflineCacheUpdate **aUpdate);
 
     virtual nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate) override;
 
     /**
      * Returns the singleton nsOfflineCacheUpdateService without an addref, or
      * nullptr if the service couldn't be created.
      */
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -80,48 +80,16 @@ typedef mozilla::docshell::OfflineCacheU
 PRLogModuleInfo *gOfflineCacheUpdateLog;
 
 #undef LOG
 #define LOG(args) MOZ_LOG(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug, args)
 
 #undef LOG_ENABLED
 #define LOG_ENABLED() MOZ_LOG_TEST(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug)
 
-namespace {
-
-nsresult
-GetAppIDAndInBrowserFromWindow(nsIDOMWindow *aWindow,
-                               uint32_t *aAppId,
-                               bool *aInBrowser)
-{
-    *aAppId = NECKO_NO_APP_ID;
-    *aInBrowser = false;
-
-    if (!aWindow) {
-        return NS_OK;
-    }
-
-    nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(aWindow);
-    if (!loadContext) {
-        return NS_OK;
-    }
-
-    nsresult rv;
-
-    rv = loadContext->GetAppId(aAppId);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = loadContext->GetIsInBrowserElement(aInBrowser);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    return NS_OK;
-}
-
-} // namespace
-
 //-----------------------------------------------------------------------------
 // nsOfflineCachePendingUpdate
 //-----------------------------------------------------------------------------
 
 class nsOfflineCachePendingUpdate final : public nsIWebProgressListener
                                         , public nsSupportsWeakReference
 {
 public:
@@ -211,25 +179,19 @@ nsOfflineCachePendingUpdate::OnStateChan
         return NS_OK;
     }
 
     LOG(("nsOfflineCachePendingUpdate::OnStateChange [%p, doc=%p]",
          this, progressDoc.get()));
 
     // Only schedule the update if the document loaded successfully
     if (NS_SUCCEEDED(aStatus)) {
-        // Get extended origin attributes
-        uint32_t appId;
-        bool isInBrowserElement;
-        nsresult rv = GetAppIDAndInBrowserFromWindow(window, &appId, &isInBrowserElement);
-        NS_ENSURE_SUCCESS(rv, rv);
-
         nsCOMPtr<nsIOfflineCacheUpdate> update;
         mService->Schedule(mManifestURI, mDocumentURI, mLoadingPrincipal, updateDoc, window,
-                           nullptr, appId, isInBrowserElement, getter_AddRefs(update));
+                           nullptr, getter_AddRefs(update));
         if (mDidReleaseThis) {
             return NS_OK;
         }
     }
 
     aWebProgress->RemoveProgressListener(this);
     MOZ_ASSERT(!mDidReleaseThis);
     mDidReleaseThis = true;
@@ -478,31 +440,28 @@ nsOfflineCacheUpdateService::GetUpdate(u
         *aUpdate = nullptr;
     }
 
     return NS_OK;
 }
 
 nsresult
 nsOfflineCacheUpdateService::FindUpdate(nsIURI *aManifestURI,
-                                        uint32_t aAppID,
-                                        bool aInBrowser,
+                                        nsACString const &aOriginSuffix,
                                         nsIFile *aCustomProfileDir,
                                         nsOfflineCacheUpdate **aUpdate)
 {
     nsresult rv;
 
     nsCOMPtr<nsIApplicationCacheService> cacheService =
         do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoCString groupID;
-    rv = cacheService->BuildGroupIDForApp(aManifestURI,
-                                          aAppID, aInBrowser,
-                                          groupID);
+    rv = cacheService->BuildGroupIDForSuffix(aManifestURI, aOriginSuffix, groupID);
     NS_ENSURE_SUCCESS(rv, rv);
 
     RefPtr<nsOfflineCacheUpdate> update;
     for (uint32_t i = 0; i < mUpdates.Length(); i++) {
         update = mUpdates[i];
 
         bool partial;
         rv = update->GetPartial(&partial);
@@ -524,18 +483,16 @@ nsOfflineCacheUpdateService::FindUpdate(
 
 nsresult
 nsOfflineCacheUpdateService::Schedule(nsIURI *aManifestURI,
                                       nsIURI *aDocumentURI,
                                       nsIPrincipal* aLoadingPrincipal,
                                       nsIDOMDocument *aDocument,
                                       nsIDOMWindow* aWindow,
                                       nsIFile* aCustomProfileDir,
-                                      uint32_t aAppID,
-                                      bool aInBrowser,
                                       nsIOfflineCacheUpdate **aUpdate)
 {
     nsCOMPtr<nsIOfflineCacheUpdate> update;
     if (GeckoProcessType_Default != XRE_GetProcessType()) {
         update = new OfflineCacheUpdateChild(aWindow);
     }
     else {
         update = new OfflineCacheUpdateGlue();
@@ -547,17 +504,17 @@ nsOfflineCacheUpdateService::Schedule(ns
       // Ensure there is window.applicationCache object that is
       // responsible for association of the new applicationCache
       // with the corresponding document.  Just ignore the result.
       nsCOMPtr<nsIDOMOfflineResourceList> appCacheWindowObject =
           window->GetApplicationCache();
     }
 
     rv = update->Init(aManifestURI, aDocumentURI, aLoadingPrincipal, aDocument,
-                      aCustomProfileDir, aAppID, aInBrowser);
+                      aCustomProfileDir);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = update->Schedule();
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ADDREF(*aUpdate = update);
 
     return NS_OK;
@@ -565,54 +522,45 @@ nsOfflineCacheUpdateService::Schedule(ns
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI,
                                             nsIURI *aDocumentURI,
                                             nsIPrincipal* aLoadingPrincipal,
                                             nsIDOMWindow *aWindow,
                                             nsIOfflineCacheUpdate **aUpdate)
 {
-    // Get extended origin attributes
-    uint32_t appId;
-    bool isInBrowser;
-    nsresult rv = GetAppIDAndInBrowserFromWindow(aWindow, &appId, &isInBrowser);
-    NS_ENSURE_SUCCESS(rv, rv);
-
     return Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr, aWindow,
-                    nullptr, appId, isInBrowser, aUpdate);
+                    nullptr, aUpdate);
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateService::ScheduleAppUpdate(nsIURI *aManifestURI,
                                                nsIURI *aDocumentURI,
                                                nsIPrincipal* aLoadingPrincipal,
-                                               uint32_t aAppID, bool aInBrowser,
                                                nsIFile *aProfileDir,
                                                nsIOfflineCacheUpdate **aUpdate)
 {
     return Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr, nullptr,
-                    aProfileDir, aAppID, aInBrowser, aUpdate);
+                    aProfileDir, aUpdate);
 }
 
 NS_IMETHODIMP nsOfflineCacheUpdateService::CheckForUpdate(nsIURI *aManifestURI,
                                                           nsIPrincipal* aLoadingPrincipal,
-                                                          uint32_t aAppID,
-                                                          bool aInBrowser,
                                                           nsIObserver *aObserver)
 {
     if (GeckoProcessType_Default != XRE_GetProcessType()) {
         // Not intended to support this on child processes
         return NS_ERROR_NOT_IMPLEMENTED;
     }
 
     nsCOMPtr<nsIOfflineCacheUpdate> update = new OfflineCacheUpdateGlue();
 
     nsresult rv;
 
-    rv = update->InitForUpdateCheck(aManifestURI, aLoadingPrincipal, aAppID, aInBrowser, aObserver);
+    rv = update->InitForUpdateCheck(aManifestURI, aLoadingPrincipal, aObserver);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = update->Schedule();
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
 }