Bug 1443379 - Stop pretending cacheKey can be anything other than uint32_t, r=smaug
authorNika Layzell <nika@thelayzells.com>
Mon, 05 Mar 2018 22:19:42 -0500
changeset 412758 0fd1326c744bbf71cce464674593683c81d7835b
parent 412757 7ae896b5ad633c584e7f2ad56013605c813adf72
child 412759 b044c550a87505347b4b9cd93ccfffb7fd0dc291
push id33818
push userapavel@mozilla.com
push dateWed, 11 Apr 2018 14:36:40 +0000
treeherdermozilla-central@cfe6399e142c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1443379
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1443379 - Stop pretending cacheKey can be anything other than uint32_t, r=smaug
browser/components/shell/nsMacShellService.cpp
devtools/server/actors/source.js
devtools/shared/DevToolsUtils.js
devtools/shared/gcli/commands/screenshot.js
docshell/base/nsDocShell.cpp
docshell/shistory/nsISHEntry.idl
docshell/shistory/nsSHEntry.cpp
docshell/shistory/nsSHEntryShared.cpp
docshell/shistory/nsSHEntryShared.h
dom/base/nsContentAreaDragDrop.cpp
dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
dom/webbrowserpersist/nsIWebBrowserPersist.idl
dom/webbrowserpersist/nsWebBrowserPersist.cpp
dom/webbrowserpersist/nsWebBrowserPersist.h
netwerk/base/nsICacheInfoChannel.idl
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/HttpChannelChild.h
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/InterceptedHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.cpp
toolkit/components/browser/nsWebBrowser.cpp
toolkit/components/downloads/test/unit/head.js
toolkit/content/contentAreaUtils.js
toolkit/modules/sessionstore/SessionHistory.jsm
toolkit/mozapps/extensions/LightweightThemeManager.jsm
--- a/browser/components/shell/nsMacShellService.cpp
+++ b/browser/components/shell/nsMacShellService.cpp
@@ -150,17 +150,17 @@ nsMacShellService::SetDesktopBackground(
 
   nsCOMPtr<nsILoadContext> loadContext;
   nsCOMPtr<nsISupports> container = content->OwnerDoc()->GetContainer();
   nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
   if (docShell) {
     loadContext = do_QueryInterface(docShell);
   }
 
-  return wbp->SaveURI(imageURI, nullptr,
+  return wbp->SaveURI(imageURI, 0,
                       docURI, content->OwnerDoc()->GetReferrerPolicy(),
                       nullptr, nullptr,
                       mBackgroundFile, loadContext);
 }
 
 NS_IMETHODIMP
 nsMacShellService::OnProgressChange(nsIWebProgress* aWebProgress,
                                     nsIRequest* aRequest,
--- a/devtools/server/actors/source.js
+++ b/devtools/server/actors/source.js
@@ -399,20 +399,16 @@ let SourceActor = ActorClassWithSpec(sou
         let channel = webNav.currentDocumentChannel;
         principal = channel.loadInfo.loadingPrincipal;
 
         // Retrieve the cacheKey in order to load POST requests from cache
         // Note that chrome:// URLs don't support this interface.
         if (loadFromCache &&
           webNav.currentDocumentChannel instanceof Ci.nsICacheInfoChannel) {
           cacheKey = webNav.currentDocumentChannel.cacheKey;
-          assert(
-            cacheKey,
-            "Could not fetch the cacheKey from the related document."
-          );
         }
       }
 
       let sourceFetched = fetch(this.url, {
         principal,
         cacheKey,
         loadFromCache
       });
--- a/devtools/shared/DevToolsUtils.js
+++ b/devtools/shared/DevToolsUtils.js
@@ -509,17 +509,17 @@ DevToolsUtils.defineLazyGetter(this, "Ne
  * without relying on caching when we can (not for eval, etc.):
  * http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/
  */
 function mainThreadFetch(urlIn, aOptions = { loadFromCache: true,
                                              policy: Ci.nsIContentPolicy.TYPE_OTHER,
                                              window: null,
                                              charset: null,
                                              principal: null,
-                                             cacheKey: null }) {
+                                             cacheKey: 0 }) {
   // Create a channel.
   let url = urlIn.split(" -> ").pop();
   let channel;
   try {
     channel = newChannelForURL(url, aOptions);
   } catch (ex) {
     return promise.reject(ex);
   }
@@ -527,17 +527,17 @@ function mainThreadFetch(urlIn, aOptions
   // Set the channel options.
   channel.loadFlags = aOptions.loadFromCache
     ? channel.LOAD_FROM_CACHE
     : channel.LOAD_BYPASS_CACHE;
 
   // When loading from cache, the cacheKey allows us to target a specific
   // SHEntry and offer ways to restore POST requests from cache.
   if (aOptions.loadFromCache &&
-      aOptions.cacheKey && channel instanceof Ci.nsICacheInfoChannel) {
+      aOptions.cacheKey != 0 && channel instanceof Ci.nsICacheInfoChannel) {
     channel.cacheKey = aOptions.cacheKey;
   }
 
   if (aOptions.window) {
     // Respect private browsing.
     channel.loadGroup = aOptions.window.QueryInterface(Ci.nsIInterfaceRequestor)
                           .getInterface(Ci.nsIWebNavigation)
                           .QueryInterface(Ci.nsIDocumentLoader)
--- a/devtools/shared/gcli/commands/screenshot.js
+++ b/devtools/shared/gcli/commands/screenshot.js
@@ -575,17 +575,17 @@ var saveToFile = Task.async(function* (c
           null,
           null,
           null,
           persist,
           isPrivate);
   let listener = new DownloadListener(window, tr);
   persist.progressListener = listener;
   persist.savePrivacyAwareURI(sourceURI,
-                              null,
+                              0,
                               document.documentURIObject,
                               Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
                               null,
                               null,
                               targetFileURI,
                               isPrivate);
 
   try {
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -10001,32 +10001,32 @@ nsDocShell::InternalLoad(nsIURI* aURI,
       // It also makes OnNewURI(...) set LOCATION_CHANGE_SAME_DOCUMENT
       // flag on firing onLocationChange(...).
       // Anyway, aCloneSHChildren param is simply reflecting
       // doShortCircuitedLoad in this scope.
       OnNewURI(aURI, nullptr, newURITriggeringPrincipal, newURIPrincipalToInherit,
                mLoadType, true, true, true);
 
       nsCOMPtr<nsIInputStream> postData;
-      nsCOMPtr<nsISupports> cacheKey;
+      uint32_t cacheKey = 0;
 
       bool scrollRestorationIsManual = false;
       if (mOSHE) {
         /* save current position of scroller(s) (bug 59774) */
         mOSHE->SetScrollPosition(cx, cy);
         mOSHE->GetScrollRestorationIsManual(&scrollRestorationIsManual);
         // Get the postdata and page ident from the current page, if
         // the new load is being done via normal means.  Note that
         // "normal means" can be checked for just by checking for
         // LOAD_CMD_NORMAL, given the loadType and allowScroll check
         // above -- it filters out some LOAD_CMD_NORMAL cases that we
         // wouldn't want here.
         if (aLoadType & LOAD_CMD_NORMAL) {
           mOSHE->GetPostData(getter_AddRefs(postData));
-          mOSHE->GetCacheKey(getter_AddRefs(cacheKey));
+          mOSHE->GetCacheKey(&cacheKey);
 
           // Link our new SHEntry to the old SHEntry's back/forward
           // cache data, since the two SHEntries correspond to the
           // same document.
           if (mLSHE) {
             if (!aSHEntry) {
               // If we're not doing a history load, scroll restoration
               // should be inherited from the previous session history entry.
@@ -10052,17 +10052,17 @@ nsDocShell::InternalLoad(nsIURI* aURI,
         // anchor page, so that any history load of the anchor
         // page will restore the appropriate postData.
         if (postData) {
           mOSHE->SetPostData(postData);
         }
 
         // Make sure we won't just repost without hitting the
         // cache first
-        if (cacheKey) {
+        if (cacheKey != 0) {
           mOSHE->SetCacheKey(cacheKey);
         }
       }
 
       /* Restore the original LSHE if we were loading something
        * while short-circuited load was initiated.
        */
       SetHistoryEntry(&mLSHE, oldLSHE);
@@ -10885,22 +10885,22 @@ nsDocShell::DoURILoad(nsIURI* aURI,
     // save true referrer for those who need it (e.g. xpinstall whitelisting)
     // Currently only http and ftp channels support this.
     props->SetPropertyAsInterface(NS_LITERAL_STRING("docshell.internalReferrer"),
                                   aReferrerURI);
   }
 
   nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(channel));
   /* Get the cache Key from SH */
-  nsCOMPtr<nsISupports> cacheKey;
+  uint32_t cacheKey = 0;
   if (cacheChannel) {
     if (mLSHE) {
-      mLSHE->GetCacheKey(getter_AddRefs(cacheKey));
+      mLSHE->GetCacheKey(&cacheKey);
     } else if (mOSHE) {  // for reload cases
-      mOSHE->GetCacheKey(getter_AddRefs(cacheKey));
+      mOSHE->GetCacheKey(&cacheKey);
     }
   }
 
   // figure out if we need to set the post data stream on the channel...
   if (aPostData) {
     nsCOMPtr<nsIFormPOSTActionChannel> postChannel(do_QueryInterface(channel));
     if (postChannel) {
       // XXX it's a bit of a hack to rewind the postdata stream here but
@@ -10917,17 +10917,17 @@ nsDocShell::DoURILoad(nsIURI* aURI,
       postChannel->SetUploadStream(aPostData, EmptyCString(), aPostDataLength);
     }
 
     /* If there is a valid postdata *and* it is a History Load,
      * set up the cache key on the channel, to retrieve the
      * data *only* from the cache. If it is a normal reload, the
      * cache is free to go to the server for updated postdata.
      */
-    if (cacheChannel && cacheKey) {
+    if (cacheChannel && cacheKey != 0) {
       if (mLoadType == LOAD_HISTORY ||
           mLoadType == LOAD_RELOAD_CHARSET_CHANGE) {
         cacheChannel->SetCacheKey(cacheKey);
         uint32_t loadFlags;
         if (NS_SUCCEEDED(channel->GetLoadFlags(&loadFlags))) {
           channel->SetLoadFlags(
             loadFlags | nsICachingChannel::LOAD_ONLY_FROM_CACHE);
         }
@@ -10942,17 +10942,17 @@ nsDocShell::DoURILoad(nsIURI* aURI,
      * New cache may use it creatively on CGI pages with GET
      * method and even on those that say "no-cache"
      */
     if (mLoadType == LOAD_HISTORY ||
         mLoadType == LOAD_RELOAD_NORMAL ||
         mLoadType == LOAD_RELOAD_CHARSET_CHANGE ||
         mLoadType == LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE ||
         mLoadType == LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE) {
-      if (cacheChannel && cacheKey) {
+      if (cacheChannel && cacheKey != 0) {
         cacheChannel->SetCacheKey(cacheKey);
       }
     }
   }
 
   if (httpChannel) {
     if (aHeadersData) {
       rv = AddHeadersToChannel(aHeadersData, httpChannel);
@@ -11512,20 +11512,20 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsICh
    * see bug 90098
    */
   if (aChannel && IsForceReloadType(aLoadType)) {
     MOZ_ASSERT(!updateSHistory || IsFrame(),
                "We shouldn't be updating session history for forced"
                " reloads unless we're in a newly created iframe!");
 
     nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(aChannel));
-    nsCOMPtr<nsISupports> cacheKey;
+    uint32_t cacheKey = 0;
     // Get the Cache Key and store it in SH.
     if (cacheChannel) {
-      cacheChannel->GetCacheKey(getter_AddRefs(cacheKey));
+      cacheChannel->GetCacheKey(&cacheKey);
     }
     // If we already have a loading history entry, store the new cache key
     // in it.  Otherwise, since we're doing a reload and won't be updating
     // our history entry, store the cache key in our current history entry.
     if (mLSHE) {
       mLSHE->SetCacheKey(cacheKey);
     } else if (mOSHE) {
       mOSHE->SetCacheKey(cacheKey);
@@ -12086,30 +12086,30 @@ nsDocShell::AddToSessionHistory(nsIURI* 
 
   // Get the post data & referrer
   nsCOMPtr<nsIInputStream> inputStream;
   nsCOMPtr<nsIURI> originalURI;
   nsCOMPtr<nsIURI> resultPrincipalURI;
   bool loadReplace = false;
   nsCOMPtr<nsIURI> referrerURI;
   uint32_t referrerPolicy = mozilla::net::RP_Unset;
-  nsCOMPtr<nsISupports> cacheKey;
+  uint32_t cacheKey = 0;
   nsCOMPtr<nsIPrincipal> triggeringPrincipal = aTriggeringPrincipal;
   nsCOMPtr<nsIPrincipal> principalToInherit = aPrincipalToInherit;
   bool expired = false;
   bool discardLayoutState = false;
   nsCOMPtr<nsICacheInfoChannel> cacheChannel;
   if (aChannel) {
     cacheChannel = do_QueryInterface(aChannel);
 
     /* If there is a caching channel, get the Cache Key and store it
      * in SH.
      */
     if (cacheChannel) {
-      cacheChannel->GetCacheKey(getter_AddRefs(cacheKey));
+      cacheChannel->GetCacheKey(&cacheKey);
     }
     nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
 
     // Check if the httpChannel is hiding under a multipartChannel
     if (!httpChannel) {
       GetHttpChannel(aChannel, getter_AddRefs(httpChannel));
     }
     if (httpChannel) {
--- a/docshell/shistory/nsISHEntry.idl
+++ b/docshell/shistory/nsISHEntry.idl
@@ -163,17 +163,17 @@ interface nsISHEntry : nsISupports
 
     /**
      * An ID to help identify this entry from others during
      * subframe navigation
      */
     attribute unsigned long ID;
 
     /** attribute to set and get the cache key for the entry */
-    attribute nsISupports cacheKey;
+    attribute unsigned long cacheKey;
 
     /** attribute to indicate whether layoutHistoryState should be saved */
     attribute boolean saveLayoutStateFlag;
 
     /** attribute to indicate whether the page is already expired in cache */
     attribute boolean expirationStatus;
 
     /**
@@ -198,17 +198,17 @@ interface nsISHEntry : nsISupports
     /** Set/Get scrollers' positon in anchored pages */
     void setScrollPosition(in long x, in long y);
     void getScrollPosition(out long x, out long y);
 
     /** Additional ways to create an entry */
     [noscript] void create(in nsIURI URI, in AString title,
                            in nsIInputStream inputStream,
                            in nsILayoutHistoryState layoutHistoryState,
-                           in nsISupports cacheKey, in ACString contentType,
+                           in unsigned long cacheKey, in ACString contentType,
                            in nsIPrincipal triggeringPrincipal,
                            in nsIPrincipal principalToInherit,
                            in nsIDRef docshellID,
                            in boolean dynamicCreation);
 
     nsISHEntry clone();
 
     /** Attribute that indicates if this entry is for a subframe navigation */
--- a/docshell/shistory/nsSHEntry.cpp
+++ b/docshell/shistory/nsSHEntry.cpp
@@ -371,25 +371,24 @@ nsSHEntry::GetIsSubFrame(bool* aFlag)
 NS_IMETHODIMP
 nsSHEntry::SetIsSubFrame(bool aFlag)
 {
   mShared->mIsFrameNavigation = aFlag;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsSHEntry::GetCacheKey(nsISupports** aResult)
+nsSHEntry::GetCacheKey(uint32_t* aResult)
 {
   *aResult = mShared->mCacheKey;
-  NS_IF_ADDREF(*aResult);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsSHEntry::SetCacheKey(nsISupports* aCacheKey)
+nsSHEntry::SetCacheKey(uint32_t aCacheKey)
 {
   mShared->mCacheKey = aCacheKey;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSHEntry::GetSaveLayoutStateFlag(bool* aFlag)
 {
@@ -435,17 +434,17 @@ nsSHEntry::SetContentType(const nsACStri
   mShared->mContentType = aContentType;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSHEntry::Create(nsIURI* aURI, const nsAString& aTitle,
                   nsIInputStream* aInputStream,
                   nsILayoutHistoryState* aLayoutHistoryState,
-                  nsISupports* aCacheKey, const nsACString& aContentType,
+                  uint32_t aCacheKey, const nsACString& aContentType,
                   nsIPrincipal* aTriggeringPrincipal,
                   nsIPrincipal* aPrincipalToInherit,
                   const nsID& aDocShellID,
                   bool aDynamicCreation)
 {
   MOZ_ASSERT(aTriggeringPrincipal,
              "need a valid triggeringPrincipal to create a session history entry");
 
--- a/docshell/shistory/nsSHEntryShared.cpp
+++ b/docshell/shistory/nsSHEntryShared.cpp
@@ -32,16 +32,17 @@ uint64_t gSHEntrySharedID = 0;
 
 void
 nsSHEntryShared::Shutdown()
 {
 }
 
 nsSHEntryShared::nsSHEntryShared()
   : mDocShellID({0})
+  , mCacheKey(0)
   , mLastTouched(0)
   , mID(gSHEntrySharedID++)
   , mViewerBounds(0, 0, 0, 0)
   , mIsFrameNavigation(false)
   , mSaveLayoutState(true)
   , mSticky(true)
   , mDynamicallyCreated(false)
   , mExpired(false)
--- a/docshell/shistory/nsSHEntryShared.h
+++ b/docshell/shistory/nsSHEntryShared.h
@@ -68,17 +68,17 @@ private:
   // These members are copied by nsSHEntryShared::Duplicate().  If you add a
   // member here, be sure to update the Duplicate() implementation.
   nsID mDocShellID;
   nsCOMArray<nsIDocShellTreeItem> mChildShells;
   nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
   nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
   nsCString mContentType;
 
-  nsCOMPtr<nsISupports> mCacheKey;
+  uint32_t mCacheKey;
   uint32_t mLastTouched;
 
   // These members aren't copied by nsSHEntryShared::Duplicate() because
   // they're specific to a particular content viewer.
   uint64_t mID;
   nsCOMPtr<nsIContentViewer> mContentViewer;
   nsCOMPtr<nsIDocument> mDocument;
   nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
--- a/dom/base/nsContentAreaDragDrop.cpp
+++ b/dom/base/nsContentAreaDragDrop.cpp
@@ -160,17 +160,17 @@ nsContentAreaDragDropDataProvider::SaveU
   nsCOMPtr<nsIWebBrowserPersist> persist =
     do_CreateInstance("@mozilla.org/embedding/browser/nsWebBrowserPersist;1",
                       &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   persist->SetPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION);
 
   // referrer policy can be anything since the referrer is nullptr
-  return persist->SavePrivacyAwareURI(inSourceURI, nullptr, nullptr,
+  return persist->SavePrivacyAwareURI(inSourceURI, 0, nullptr,
                                       mozilla::net::RP_Unset,
                                       nullptr, nullptr,
                                       inDestFile, isPrivate);
 }
 
 /*
  * Check if the provided filename extension is valid for the MIME type and
  * return the MIME type's primary extension.
--- a/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
+++ b/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
@@ -163,33 +163,22 @@ WebBrowserPersistLocalDocument::GetConte
         aCD.SetIsVoid(true);
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebBrowserPersistLocalDocument::GetCacheKey(uint32_t* aKey)
 {
+    *aKey = 0;
     nsCOMPtr<nsISHEntry> history = GetHistory();
-    if (!history) {
-        *aKey = 0;
-        return NS_OK;
+    if (history) {
+        history->GetCacheKey(aKey);
     }
-    nsCOMPtr<nsISupports> abstractKey;
-    nsresult rv = history->GetCacheKey(getter_AddRefs(abstractKey));
-    if (NS_WARN_IF(NS_FAILED(rv)) || !abstractKey) {
-        *aKey = 0;
-        return NS_OK;
-    }
-    nsCOMPtr<nsISupportsPRUint32> u32 = do_QueryInterface(abstractKey);
-    if (NS_WARN_IF(!u32)) {
-        *aKey = 0;
-        return NS_OK;
-    }
-    return u32->GetData(aKey);
+    return NS_OK;
 }
 
 NS_IMETHODIMP
 WebBrowserPersistLocalDocument::GetPostData(nsIInputStream** aStream)
 {
     nsCOMPtr<nsISHEntry> history = GetHistory();
     if (!history) {
         *aStream = nullptr;
--- a/dom/webbrowserpersist/nsIWebBrowserPersist.idl
+++ b/dom/webbrowserpersist/nsIWebBrowserPersist.idl
@@ -112,20 +112,17 @@ interface nsIWebBrowserPersist : nsICanc
   attribute nsIWebProgressListener progressListener;
 
   /**
    * Save the specified URI to file.
    *
    * @param aURI       URI to save to file. Some implementations of this interface
    *                   may also support <CODE>nullptr</CODE> to imply the currently
    *                   loaded URI.
-   * @param aCacheKey  An object representing the URI in the cache or
-   *                   <CODE>nullptr</CODE>.  This can be a necko cache key,
-   *                   an nsIWebPageDescriptor, or the currentDescriptor of an
-   *                   nsIWebPageDescriptor.
+   * @param aCacheKey  The necko cache key integer.
    * @param aReferrer  The referrer URI to pass with an HTTP request or
    *                   <CODE>nullptr</CODE>.
    * @param aReferrerPolicy  The referrer policy for when and what to send via
    *                   HTTP Referer header.  Ignored if aReferrer is
    *                   <CODE>nullptr</CODE>.  Taken from REFERRER_POLICY
    *                   constants in nsIHttpChannel.
    * @param aPostData  Post data to pass with an HTTP request or
    *                   <CODE>nullptr</CODE>.
@@ -141,29 +138,29 @@ interface nsIWebBrowserPersist : nsICanc
    *                   window or document)
    *
    * @see nsIFile
    * @see nsIURI
    * @see nsIInputStream
    *
    * @throws NS_ERROR_INVALID_ARG One or more arguments was invalid.
    */
-  void saveURI(in nsIURI aURI, in nsISupports aCacheKey,
+  void saveURI(in nsIURI aURI, in unsigned long aCacheKey,
       in nsIURI aReferrer, in unsigned long aReferrerPolicy,
       in nsIInputStream aPostData,
       in string aExtraHeaders, in nsISupports aFile,
       in nsILoadContext aPrivacyContext);
 
   /**
    * @param aIsPrivate Treat the save operation as private (ie. with
    *                   regards to networking operations and persistence
    *                   of intermediate data, etc.)
    * @see saveURI for all other parameter descriptions
    */
-  void savePrivacyAwareURI(in nsIURI aURI, in nsISupports aCacheKey,
+  void savePrivacyAwareURI(in nsIURI aURI, in unsigned long aCacheKey,
       in nsIURI aReferrer, in unsigned long aReferrerPolicy,
       in nsIInputStream aPostData,
       in string aExtraHeaders, in nsISupports aFile,
       in boolean aIsPrivate);
 
   /**
    * Save a channel to a file. It must not be opened yet.
    * @see saveURI
--- a/dom/webbrowserpersist/nsWebBrowserPersist.cpp
+++ b/dom/webbrowserpersist/nsWebBrowserPersist.cpp
@@ -408,28 +408,28 @@ NS_IMETHODIMP nsWebBrowserPersist::SetPr
 {
     mProgressListener = aProgressListener;
     mProgressListener2 = do_QueryInterface(aProgressListener);
     mEventSink = do_GetInterface(aProgressListener);
     return NS_OK;
 }
 
 NS_IMETHODIMP nsWebBrowserPersist::SaveURI(
-    nsIURI *aURI, nsISupports *aCacheKey,
+    nsIURI *aURI, uint32_t aCacheKey,
     nsIURI *aReferrer, uint32_t aReferrerPolicy,
     nsIInputStream *aPostData, const char *aExtraHeaders,
     nsISupports *aFile, nsILoadContext* aPrivacyContext)
 {
     return SavePrivacyAwareURI(aURI, aCacheKey, aReferrer, aReferrerPolicy,
                                aPostData, aExtraHeaders, aFile,
                                aPrivacyContext && aPrivacyContext->UsePrivateBrowsing());
 }
 
 NS_IMETHODIMP nsWebBrowserPersist::SavePrivacyAwareURI(
-    nsIURI *aURI, nsISupports *aCacheKey,
+    nsIURI *aURI, uint32_t aCacheKey,
     nsIURI *aReferrer, uint32_t aReferrerPolicy,
     nsIInputStream *aPostData, const char *aExtraHeaders,
     nsISupports *aFile, bool aIsPrivate)
 {
     NS_ENSURE_TRUE(mFirstAndOnlyUse, NS_ERROR_FAILURE);
     mFirstAndOnlyUse = false; // Stop people from reusing this object!
 
     nsCOMPtr<nsIURI> fileAsURI;
@@ -626,17 +626,17 @@ nsWebBrowserPersist::SerializeNextFile()
             }
             rv = AppendPathToURI(fileAsURI, data->mFilename, fileAsURI);
             if (NS_WARN_IF(NS_FAILED(rv))) {
                 break;
             }
 
             // The Referrer Policy doesn't matter here since the referrer is
             // nullptr.
-            rv = SaveURIInternal(uri, nullptr, nullptr,
+            rv = SaveURIInternal(uri, 0, nullptr,
                                  mozilla::net::RP_Unset, nullptr, nullptr,
                                  fileAsURI, true, mIsPrivate);
             // If SaveURIInternal fails, then it will have called EndDownload,
             // which means that |data| is no longer valid memory. We MUST bail.
             if (NS_WARN_IF(NS_FAILED(rv))) {
                 break;
             }
 
@@ -1323,17 +1323,17 @@ nsWebBrowserPersist::AppendPathToURI(nsI
     AppendUTF16toUTF8(aPath, newPath);
 
     return NS_MutateURI(aURI)
              .SetPathQueryRef(newPath)
              .Finalize(aOutURI);
 }
 
 nsresult nsWebBrowserPersist::SaveURIInternal(
-    nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer,
+    nsIURI *aURI, uint32_t aCacheKey, nsIURI *aReferrer,
     uint32_t aReferrerPolicy, nsIInputStream *aPostData,
     const char *aExtraHeaders, nsIURI *aFile,
     bool aCalcFileExt, bool aIsPrivate)
 {
     NS_ENSURE_ARG_POINTER(aURI);
     NS_ENSURE_ARG_POINTER(aFile);
 
     nsresult rv = NS_OK;
@@ -1345,46 +1345,16 @@ nsresult nsWebBrowserPersist::SaveURIInt
     {
         loadFlags |= nsIRequest::LOAD_BYPASS_CACHE;
     }
     else if (mPersistFlags & PERSIST_FLAGS_FROM_CACHE)
     {
         loadFlags |= nsIRequest::LOAD_FROM_CACHE;
     }
 
-    // Extract the cache key
-    nsCOMPtr<nsISupports> cacheKey;
-    if (aCacheKey)
-    {
-        // Test if the cache key is actually a web page descriptor (docshell)
-        // or session history entry.
-        nsCOMPtr<nsISHEntry> shEntry = do_QueryInterface(aCacheKey);
-        if (!shEntry)
-        {
-            nsCOMPtr<nsIWebPageDescriptor> webPageDescriptor =
-                do_QueryInterface(aCacheKey);
-            if (webPageDescriptor)
-            {
-                nsCOMPtr<nsISupports> currentDescriptor;
-                webPageDescriptor->GetCurrentDescriptor(getter_AddRefs(currentDescriptor));
-                shEntry = do_QueryInterface(currentDescriptor);
-            }
-        }
-
-        if (shEntry)
-        {
-            shEntry->GetCacheKey(getter_AddRefs(cacheKey));
-        }
-        else
-        {
-            // Assume a plain cache key
-            cacheKey = aCacheKey;
-        }
-    }
-
     // Open a channel to the URI
     nsCOMPtr<nsIChannel> inputChannel;
     rv = NS_NewChannel(getter_AddRefs(inputChannel),
                        aURI,
                        nsContentUtils::GetSystemPrincipal(),
                        nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                        nsIContentPolicy::TYPE_OTHER,
                        nullptr,  // aPerformanceStorage
@@ -1447,19 +1417,18 @@ nsresult nsWebBrowserPersist::SaveURIInt
                 NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel");
                 // Attach the postdata to the http channel
                 uploadChannel->SetUploadStream(aPostData, EmptyCString(), -1);
             }
         }
 
         // Cache key
         nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(httpChannel));
-        if (cacheChannel && cacheKey)
-        {
-            cacheChannel->SetCacheKey(cacheKey);
+        if (cacheChannel && aCacheKey != 0) {
+            cacheChannel->SetCacheKey(aCacheKey);
         }
 
         // Headers
         if (aExtraHeaders)
         {
             nsAutoCString oneHeader;
             nsAutoCString headerName;
             nsAutoCString headerValue;
--- a/dom/webbrowserpersist/nsWebBrowserPersist.h
+++ b/dom/webbrowserpersist/nsWebBrowserPersist.h
@@ -52,17 +52,17 @@ public:
     NS_DECL_NSIREQUESTOBSERVER
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSIPROGRESSEVENTSINK
 
 // Private members
 private:
     virtual ~nsWebBrowserPersist();
     nsresult SaveURIInternal(
-        nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer,
+        nsIURI *aURI, uint32_t aCacheKey, nsIURI *aReferrer,
         uint32_t aReferrerPolicy, nsIInputStream *aPostData,
         const char *aExtraHeaders, nsIURI *aFile,
         bool aCalcFileExt, bool aIsPrivate);
     nsresult SaveChannelInternal(
         nsIChannel *aChannel, nsIURI *aFile, bool aCalcFileExt);
     nsresult SaveDocumentInternal(
         nsIWebBrowserPersistDocument *aDocument,
         nsIURI *aFile,
--- a/netwerk/base/nsICacheInfoChannel.idl
+++ b/netwerk/base/nsICacheInfoChannel.idl
@@ -46,33 +46,32 @@ interface nsICacheInfoChannel : nsISuppo
    * one nsICacheInfochannel matches the main data from another one.
    *
    * Note: NS_ERROR_NOT_AVAILABLE is thrown when a nsICacheInfoChannel has no
    * valid corresponding nsICacheEntry.
    */
   uint64_t getCacheEntryId();
 
   /**
-   * Set/get the cache key... uniquely identifies the data in the cache
-   * for this channel.  Holding a reference to this key does NOT prevent
-   * the cached data from being removed.
+   * Set/get the cache key. This integer uniquely identifies the data in
+   * the cache for this channel.
    *
    * A cache key retrieved from a particular instance of nsICacheInfoChannel
    * could be set on another instance of nsICacheInfoChannel provided the
-   * underlying implementations are compatible and provided the new 
+   * underlying implementations are compatible and provided the new
    * channel instance was created with the same URI.  The implementation of
    * nsICacheInfoChannel would be expected to use the cache entry identified
    * by the cache token.  Depending on the value of nsIRequest::loadFlags,
    * the cache entry may be validated, overwritten, or simply read.
    *
-   * The cache key may be NULL indicating that the URI of the channel is
-   * sufficient to locate the same cache entry.  Setting a NULL cache key
+   * The cache key may be 0 indicating that the URI of the channel is
+   * sufficient to locate the same cache entry.  Setting a 0 cache key
    * is likewise valid.
    */
-  attribute nsISupports cacheKey;
+  attribute unsigned long cacheKey;
 
   /**
    * Tells the channel to behave as if the LOAD_FROM_CACHE flag has been set,
    * but without affecting the loads for the entire loadGroup in case of this
    * channel being the default load group's channel.
    */
   attribute boolean allowStaleCacheContent;
 
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -156,16 +156,17 @@ InterceptStreamListener::Cleanup()
 
 //-----------------------------------------------------------------------------
 // HttpChannelChild
 //-----------------------------------------------------------------------------
 
 HttpChannelChild::HttpChannelChild()
   : HttpAsyncAborter<HttpChannelChild>(this)
   , NeckoTargetHolder(nullptr)
+  , mCacheKey(0)
   , mSynthesizedStreamLength(0)
   , mIsFromCache(false)
   , mCacheEntryAvailable(false)
   , mCacheEntryId(0)
   , mAltDataCacheEntryAvailable(false)
   , mCacheFetchCount(0)
   , mCacheExpirationTime(nsICacheEntry::NO_EXPIRATION_TIME)
   , mSendResumeAt(false)
@@ -221,17 +222,16 @@ HttpChannelChild::ReleaseMainThreadOnlyR
 {
   if (NS_IsMainThread()) {
       // Already on main thread, let dtor to
       // take care of releasing references
       return;
   }
 
   nsTArray<nsCOMPtr<nsISupports>> arrayToRelease;
-  arrayToRelease.AppendElement(mCacheKey.forget());
   arrayToRelease.AppendElement(mRedirectChannelChild.forget());
 
   // To solve multiple inheritence of nsISupports in InterceptStreamListener
   nsCOMPtr<nsIStreamListener> listener = mInterceptListener.forget();
   arrayToRelease.AppendElement(listener.forget());
 
   arrayToRelease.AppendElement(mInterceptedRedirectListener.forget());
   arrayToRelease.AppendElement(mInterceptedRedirectContext.forget());
@@ -647,30 +647,17 @@ HttpChannelChild::OnStartRequest(const n
                              prevController.ref().PrincipalInfo() == aController.ref().PrincipalInfo()));
     }
   }
 
   mAfterOnStartRequestBegun = true;
 
   AutoEventEnqueuer ensureSerialDispatch(mEventQ);
 
-  nsresult rv;
-  nsCOMPtr<nsISupportsPRUint32> container =
-    do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
-    Cancel(rv);
-    return;
-  }
-
-  rv = container->SetData(cacheKey);
-  if (NS_FAILED(rv)) {
-    Cancel(rv);
-    return;
-  }
-  mCacheKey = container;
+  mCacheKey = cacheKey;
 
   // replace our request headers with what actually got sent in the parent
   mRequestHead.SetHeaders(requestHeaders);
 
   // Note: this is where we would notify "http-on-examine-response" observers.
   // We have deliberately disabled this for child processes (see bug 806753)
   //
   // gHttpHandler->OnExamineResponse(this);
@@ -2730,29 +2717,17 @@ HttpChannelChild::ContinueAsyncOpen()
   openArgs.chooseApplicationCache() = mChooseApplicationCache;
   openArgs.appCacheClientID() = appCacheClientId;
   openArgs.allowSpdy() = mAllowSpdy;
   openArgs.allowAltSvc() = mAllowAltSvc;
   openArgs.beConservative() = mBeConservative;
   openArgs.tlsFlags() = mTlsFlags;
   openArgs.initialRwin() = mInitialRwin;
 
-  uint32_t cacheKey = 0;
-  if (mCacheKey) {
-    nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(mCacheKey);
-    if (!container) {
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-
-    nsresult rv = container->GetData(&cacheKey);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-  openArgs.cacheKey() = cacheKey;
+  openArgs.cacheKey() = mCacheKey;
 
   openArgs.blockAuthPrompt() = mBlockAuthPrompt;
 
   openArgs.allowStaleCacheContent() = mAllowStaleCacheContent;
 
   openArgs.contentTypeHint() = mContentTypeHint;
 
   nsresult rv = mozilla::ipc::LoadInfoToLoadInfoArgs(mLoadInfo, &openArgs.loadInfo());
@@ -3043,27 +3018,27 @@ HttpChannelChild::GetCacheEntryId(uint64
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   *aCacheEntryId = mCacheEntryId;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-HttpChannelChild::GetCacheKey(nsISupports **cacheKey)
+HttpChannelChild::GetCacheKey(uint32_t *cacheKey)
 {
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->GetCacheKey(cacheKey);
   }
 
-  NS_IF_ADDREF(*cacheKey = mCacheKey);
+  *cacheKey = mCacheKey;
   return NS_OK;
 }
 NS_IMETHODIMP
-HttpChannelChild::SetCacheKey(nsISupports *cacheKey)
+HttpChannelChild::SetCacheKey(uint32_t cacheKey)
 {
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->SetCacheKey(cacheKey);
   }
 
   ENSURE_CALLED_BEFORE_ASYNC_OPEN();
 
   mCacheKey = cacheKey;
--- a/netwerk/protocol/http/HttpChannelChild.h
+++ b/netwerk/protocol/http/HttpChannelChild.h
@@ -191,17 +191,17 @@ protected:
   already_AddRefed<nsIEventTarget> GetNeckoTarget() override;
 
   virtual mozilla::ipc::IPCResult RecvLogBlockedCORSRequest(const nsString& aMessage) override;
   NS_IMETHOD LogBlockedCORSRequest(const nsAString & aMessage) override;
 
 private:
   // this section is for main-thread-only object
   // all the references need to be proxy released on main thread.
-  nsCOMPtr<nsISupports> mCacheKey;
+  uint32_t mCacheKey;
   nsCOMPtr<nsIChildChannel> mRedirectChannelChild;
   RefPtr<InterceptStreamListener> mInterceptListener;
   // Needed to call AsyncOpen in FinishInterceptedRedirect
   nsCOMPtr<nsIStreamListener> mInterceptedRedirectListener;
   nsCOMPtr<nsISupports> mInterceptedRedirectContext;
 
   // Proxy release all members above on main thread.
   void ReleaseMainThreadOnlyReferences();
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -676,31 +676,20 @@ HttpChannelParent::DoAsyncOpen(  const U
     }
   } else if (!ServiceWorkerParentInterceptEnabled()) {
     nsLoadFlags newLoadFlags;
     httpChannel->GetLoadFlags(&newLoadFlags);
     newLoadFlags |= nsIChannel::LOAD_BYPASS_SERVICE_WORKER;
     httpChannel->SetLoadFlags(newLoadFlags);
   }
 
-  nsCOMPtr<nsISupportsPRUint32> cacheKey =
-    do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
-    return SendFailedAsyncOpen(rv);
-  }
-
-  rv = cacheKey->SetData(aCacheKey);
-  if (NS_FAILED(rv)) {
-    return SendFailedAsyncOpen(rv);
-  }
-
   nsCOMPtr<nsICacheInfoChannel> cacheChannel =
     do_QueryInterface(static_cast<nsIChannel*>(httpChannel.get()));
   if (cacheChannel) {
-    cacheChannel->SetCacheKey(cacheKey);
+    cacheChannel->SetCacheKey(aCacheKey);
     cacheChannel->PreferAlternativeDataType(aPreferredAlternativeType);
 
     cacheChannel->SetAllowStaleCacheContent(aAllowStaleCacheContent);
 
     // This is to mark that the results are going to the content process.
     if (httpChannelImpl) {
       httpChannelImpl->SetAltDataForChild(true);
     }
@@ -1503,38 +1492,26 @@ HttpChannelParent::OnStartRequest(nsIReq
   bool applyConversion = true;
   Unused << chan->GetApplyConversion(&applyConversion);
   chan->SetApplyConversion(false);
 
   // Keep the cache entry for future use in RecvSetCacheTokenCachedCharset().
   // It could be already released by nsHttpChannel at that time.
   nsCOMPtr<nsISupports> cacheEntry;
   nsresult channelStatus = NS_OK;
-  uint32_t cacheKeyValue = 0;
+  uint32_t cacheKey = 0;
   nsAutoCString altDataType;
 
   if (httpChannelImpl) {
     httpChannelImpl->GetCacheToken(getter_AddRefs(cacheEntry));
     mCacheEntry = do_QueryInterface(cacheEntry);
 
     httpChannelImpl->GetStatus(&channelStatus);
 
-    nsCOMPtr<nsISupports> cacheKey;
-    httpChannelImpl->GetCacheKey(getter_AddRefs(cacheKey));
-    if (cacheKey) {
-      nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(cacheKey);
-      if (!container) {
-        return NS_ERROR_ILLEGAL_VALUE;
-      }
-
-      nsresult rv = container->GetData(&cacheKeyValue);
-      if (NS_FAILED(rv)) {
-        return rv;
-      }
-    }
+    httpChannelImpl->GetCacheKey(&cacheKey);
 
     httpChannelImpl->GetAlternativeDataType(altDataType);
   }
 
   nsCString secInfoSerialization;
   UpdateAndSerializeSecurityInfo(secInfoSerialization);
 
   uint8_t redirectCount = 0;
@@ -1574,17 +1551,17 @@ HttpChannelParent::OnStartRequest(nsIReq
                           loadInfoForwarderArg,
                           isFromCache,
                           mCacheEntry ? true : false,
                           cacheEntryId,
                           fetchCount, expirationTime,
                           cachedCharset, secInfoSerialization,
                           chan->GetSelfAddr(), chan->GetPeerAddr(),
                           redirectCount,
-                          cacheKeyValue,
+                          cacheKey,
                           altDataType,
                           altDataLen,
                           ipcController,
                           applyConversion))
   {
     rv = NS_ERROR_UNEXPECTED;
   }
   requestHead->Exit();
--- a/netwerk/protocol/http/InterceptedHttpChannel.cpp
+++ b/netwerk/protocol/http/InterceptedHttpChannel.cpp
@@ -1325,26 +1325,26 @@ InterceptedHttpChannel::OpenAlternativeO
 {
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->OpenAlternativeOutputStream(type, _retval);
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-InterceptedHttpChannel::GetCacheKey(nsISupports **key)
+InterceptedHttpChannel::GetCacheKey(uint32_t* key)
 {
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->GetCacheKey(key);
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-InterceptedHttpChannel::SetCacheKey(nsISupports *key)
+InterceptedHttpChannel::SetCacheKey(uint32_t key)
 {
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->SetCacheKey(key);
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 } // namespace net
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -7924,56 +7924,34 @@ nsHttpChannel::GetOfflineCacheToken(nsIS
 
 NS_IMETHODIMP
 nsHttpChannel::SetOfflineCacheToken(nsISupports *token)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-nsHttpChannel::GetCacheKey(nsISupports **key)
-{
-    nsresult rv;
+nsHttpChannel::GetCacheKey(uint32_t* key)
+{
     NS_ENSURE_ARG_POINTER(key);
 
     LOG(("nsHttpChannel::GetCacheKey [this=%p]\n", this));
 
-    *key = nullptr;
-
-    nsCOMPtr<nsISupportsPRUint32> container =
-        do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
-
-    if (!container)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    rv = container->SetData(mPostID);
-    if (NS_FAILED(rv)) return rv;
-
-    return CallQueryInterface(container.get(), key);
+    *key = mPostID;
+    return NS_OK;
 }
 
 NS_IMETHODIMP
-nsHttpChannel::SetCacheKey(nsISupports *key)
-{
-    nsresult rv;
-
-    LOG(("nsHttpChannel::SetCacheKey [this=%p key=%p]\n", this, key));
+nsHttpChannel::SetCacheKey(uint32_t key)
+{
+    LOG(("nsHttpChannel::SetCacheKey [this=%p key=%u]\n", this, key));
 
     ENSURE_CALLED_BEFORE_CONNECT();
 
-    if (!key)
-        mPostID = 0;
-    else {
-        // extract the post id
-        nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(key, &rv);
-        if (NS_FAILED(rv)) return rv;
-
-        rv = container->GetData(&mPostID);
-        if (NS_FAILED(rv)) return rv;
-    }
+    mPostID = key;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHttpChannel::GetCacheOnlyMetadata(bool *aOnlyMetadata)
 {
     NS_ENSURE_ARG(aOnlyMetadata);
     *aOnlyMetadata = mCacheOnlyMetadata;
--- a/toolkit/components/browser/nsWebBrowser.cpp
+++ b/toolkit/components/browser/nsWebBrowser.cpp
@@ -981,32 +981,32 @@ NS_IMETHODIMP
 nsWebBrowser::SetProgressListener(nsIWebProgressListener* aProgressListener)
 {
   mProgressListener = aProgressListener;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWebBrowser::SaveURI(nsIURI* aURI,
-                      nsISupports* aCacheKey,
+                      uint32_t aCacheKey,
                       nsIURI* aReferrer,
                       uint32_t aReferrerPolicy,
                       nsIInputStream* aPostData,
                       const char* aExtraHeaders,
                       nsISupports* aFile,
                       nsILoadContext* aPrivacyContext)
 {
   return SavePrivacyAwareURI(
     aURI, aCacheKey, aReferrer, aReferrerPolicy, aPostData, aExtraHeaders,
     aFile, aPrivacyContext && aPrivacyContext->UsePrivateBrowsing());
 }
 
 NS_IMETHODIMP
 nsWebBrowser::SavePrivacyAwareURI(nsIURI* aURI,
-                                  nsISupports* aCacheKey,
+                                  uint32_t aCacheKey,
                                   nsIURI* aReferrer,
                                   uint32_t aReferrerPolicy,
                                   nsIInputStream* aPostData,
                                   const char* aExtraHeaders,
                                   nsISupports* aFile,
                                   bool aIsPrivate)
 {
   if (mPersist) {
--- a/toolkit/components/downloads/test/unit/head.js
+++ b/toolkit/components/downloads/test/unit/head.js
@@ -294,17 +294,17 @@ function promiseStartLegacyDownload(aSou
       // Initialize the components so they reference each other.  This will cause
       // the Download object to be created and added to the public downloads.
       transfer.init(sourceURI, NetUtil.newURI(targetFile), null, mimeInfo, null,
                     null, persist, isPrivate);
       persist.progressListener = transfer;
 
       // Start the actual download process.
       persist.savePrivacyAwareURI(
-        sourceURI, null, referrer, Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
+        sourceURI, 0, referrer, Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
         null, null, targetFile, isPrivate);
     }).catch(do_report_unexpected_exception);
 
   });
 }
 
 /**
  * Starts a new download using the nsIHelperAppService interface, and controls
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -186,22 +186,22 @@ function saveBrowser(aBrowser, aSkipProm
 // case "save as" modes that serialize the document's DOM are
 // unavailable.  This is a temporary measure for the "Save Frame As"
 // command (bug 1141337) and pre-e10s add-ons.
 function saveDocument(aDocument, aSkipPrompt) {
   if (!aDocument)
     throw "Must have a document when calling saveDocument";
 
   let contentDisposition = null;
-  let cacheKeyInt = null;
+  let cacheKey = 0;
 
   if (aDocument instanceof Ci.nsIWebBrowserPersistDocument) {
     // nsIWebBrowserPersistDocument exposes these directly.
     contentDisposition = aDocument.contentDisposition;
-    cacheKeyInt = aDocument.cacheKey;
+    cacheKey = aDocument.cacheKey;
   } else if (aDocument instanceof Ci.nsIDOMDocument) {
     // Otherwise it's an actual nsDocument (and possibly a CPOW).
     // We want to use cached data because the document is currently visible.
     let ifreq =
       aDocument.defaultView
                .QueryInterface(Ci.nsIInterfaceRequestor);
 
     try {
@@ -214,35 +214,22 @@ function saveDocument(aDocument, aSkipPr
 
     try {
       let shEntry =
         ifreq.getInterface(Ci.nsIWebNavigation)
              .QueryInterface(Ci.nsIWebPageDescriptor)
              .currentDescriptor
              .QueryInterface(Ci.nsISHEntry);
 
-      let cacheKey = shEntry.cacheKey
-                            .QueryInterface(Ci.nsISupportsPRUint32)
-                            .data;
-      // cacheKey might be a CPOW, which can't be passed to native
-      // code, but the data attribute is just a number.
-      cacheKeyInt = cacheKey.data;
+      cacheKey = shEntry.cacheKey;
     } catch (ex) {
       // We might not find it in the cache.  Oh, well.
     }
   }
 
-  // Convert the cacheKey back into an XPCOM object.
-  let cacheKey = null;
-  if (cacheKeyInt) {
-    cacheKey = Cc["@mozilla.org/supports-PRUint32;1"]
-      .createInstance(Ci.nsISupportsPRUint32);
-    cacheKey.data = cacheKeyInt;
-  }
-
   internalSave(aDocument.documentURI, aDocument, null, contentDisposition,
                aDocument.contentType, false, null, null,
                aDocument.referrer ? makeURI(aDocument.referrer) : null,
                aDocument, aSkipPrompt, cacheKey);
 }
 
 function DownloadListener(win, transfer) {
   function makeClosure(name) {
@@ -359,17 +346,17 @@ function internalSave(aURL, aDocument, a
   forbidCPOW(aReferrer, "internalSave", "aReferrer");
   forbidCPOW(aCacheKey, "internalSave", "aCacheKey");
   // Allow aInitiatingDocument to be a CPOW.
 
   if (aSkipPrompt == undefined)
     aSkipPrompt = false;
 
   if (aCacheKey == undefined)
-    aCacheKey = null;
+    aCacheKey = 0;
 
   // Note: aDocument == null when this code is used by save-link-as...
   var saveMode = GetSaveModeForContentType(aContentType, aDocument);
 
   var file, sourceURI, saveAsType;
   // Find the URI object for aURL and the FileName/Extension to use when saving.
   // FileName/Extension will be ignored if aChosenData supplied.
   if (aChosenData) {
@@ -449,17 +436,17 @@ function internalSave(aURL, aDocument, a
 
 /**
  * internalPersist: Creates a 'Persist' object (which will perform the saving
  *  in the background) and then starts it.
  *
  * @param persistArgs.sourceURI
  *        The nsIURI of the document being saved
  * @param persistArgs.sourceCacheKey [optional]
- *        If set will be passed to saveURI
+ *        If set will be passed to savePrivacyAwareURI
  * @param persistArgs.sourceDocument [optional]
  *        The document to be saved, or null if not saving a complete document
  * @param persistArgs.sourceReferrer
  *        Required and used only when persistArgs.sourceDocument is NOT present,
  *        the nsIURI of the referrer to use, or null if no referrer should be
  *        sent.
  * @param persistArgs.sourcePostData
  *        Required and used only when persistArgs.sourceDocument is NOT present,
--- a/toolkit/modules/sessionstore/SessionHistory.jsm
+++ b/toolkit/modules/sessionstore/SessionHistory.jsm
@@ -133,23 +133,17 @@ var SessionHistoryInternal = {
    */
   serializeEntry(shEntry) {
     let entry = { url: shEntry.URI.displaySpec, title: shEntry.title };
 
     if (shEntry.isSubFrame) {
       entry.subframe = true;
     }
 
-    let cacheKey = shEntry.cacheKey;
-    if (cacheKey && cacheKey instanceof Ci.nsISupportsPRUint32 &&
-        cacheKey.data != 0) {
-      // XXXbz would be better to have cache keys implement
-      // nsISerializable or something.
-      entry.cacheKey = cacheKey.data;
-    }
+    entry.cacheKey = shEntry.cacheKey;
     entry.ID = shEntry.ID;
     entry.docshellUUID = shEntry.docshellID.toString();
 
     // We will include the property only if it's truthy to save a couple of
     // bytes when the resulting object is stringified and saved to disk.
     if (shEntry.referrerURI) {
       entry.referrer = shEntry.referrerURI.spec;
       entry.referrerPolicy = shEntry.referrerPolicy;
@@ -386,20 +380,17 @@ var SessionHistoryInternal = {
       shEntry.loadReplace = entry.loadReplace2;
     }
     if (entry.isSrcdocEntry)
       shEntry.srcdocData = entry.srcdocData;
     if (entry.baseURI)
       shEntry.baseURI = Utils.makeURI(entry.baseURI);
 
     if (entry.cacheKey) {
-      var cacheKey = Cc["@mozilla.org/supports-PRUint32;1"].
-                     createInstance(Ci.nsISupportsPRUint32);
-      cacheKey.data = entry.cacheKey;
-      shEntry.cacheKey = cacheKey;
+      shEntry.cacheKey = entry.cacheKey;
     }
 
     if (entry.ID) {
       // get a new unique ID for this frame (since the one from the last
       // start might already be in use)
       var id = idMap[entry.ID] || 0;
       if (!id) {
         for (id = Date.now(); id in idMap.used; id++);
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -854,17 +854,17 @@ function _persistImage(sourceURL, localF
     Ci.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
     Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION |
     (PERSIST_BYPASS_CACHE ?
        Ci.nsIWebBrowserPersist.PERSIST_FLAGS_BYPASS_CACHE :
        Ci.nsIWebBrowserPersist.PERSIST_FLAGS_FROM_CACHE);
 
   persist.progressListener = new _persistProgressListener(successCallback);
 
-  persist.saveURI(sourceURI, null,
+  persist.saveURI(sourceURI, 0,
                   null, Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
                   null, null, targetURI, null);
 }
 
 function _persistProgressListener(successCallback) {
   this.onLocationChange = function() {};
   this.onProgressChange = function() {};
   this.onStatusChange   = function() {};