diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index 464cbe7647d..d1592e3eaf4 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -43,7 +43,6 @@ #include "mozilla/net/NeckoParent.h" #include "mozilla/unused.h" #include "HttpChannelParentListener.h" -#include "nsHttpChannel.h" #include "nsHttpHandler.h" #include "nsNetUtil.h" #include "nsISupportsPriority.h" @@ -394,8 +393,11 @@ HttpChannelParent::RecvDocumentChannelCleanup() bool HttpChannelParent::RecvMarkOfflineCacheEntryAsForeign() { - nsHttpChannel *httpChan = static_cast(mChannel.get()); - httpChan->MarkOfflineCacheEntryAsForeign(); + if (mOfflineForeignMarker) { + mOfflineForeignMarker->MarkAsForeign(); + mOfflineForeignMarker = 0; + } + return true; } @@ -421,6 +423,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) bool loadedFromApplicationCache; chan->GetLoadedFromApplicationCache(&loadedFromApplicationCache); if (loadedFromApplicationCache) { + mOfflineForeignMarker = chan->GetOfflineCacheEntryAsForeignMarker(); nsCOMPtr appCache; chan->GetApplicationCache(getter_AddRefs(appCache)); nsCString appCacheGroupId; diff --git a/netwerk/protocol/http/HttpChannelParent.h b/netwerk/protocol/http/HttpChannelParent.h index 6cfc3a6bf3b..f061d56932c 100644 --- a/netwerk/protocol/http/HttpChannelParent.h +++ b/netwerk/protocol/http/HttpChannelParent.h @@ -49,6 +49,7 @@ #include "nsIParentRedirectingChannel.h" #include "nsIProgressEventSink.h" #include "nsITabParent.h" +#include "nsHttpChannel.h" using namespace mozilla::dom; @@ -128,6 +129,8 @@ private: nsCOMPtr mRedirectChannel; nsCOMPtr mRedirectCallback; + nsAutoPtr mOfflineForeignMarker; + // state for combining OnStatus/OnProgress with OnDataAvailable // into one IPDL call to child. nsresult mStoredStatus; diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index c2939d66c5b..5726536b8f8 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -5176,20 +5176,40 @@ nsHttpChannel::SetChooseApplicationCache(bool aChoose) return NS_OK; } -NS_IMETHODIMP -nsHttpChannel::MarkOfflineCacheEntryAsForeign() +nsHttpChannel::OfflineCacheEntryAsForeignMarker* +nsHttpChannel::GetOfflineCacheEntryAsForeignMarker() { if (!mApplicationCache) - return NS_ERROR_NOT_AVAILABLE; + return nsnull; nsresult rv; nsCAutoString cacheKey; rv = GenerateCacheKey(mPostID, cacheKey); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, nsnull); - rv = mApplicationCache->MarkEntry(cacheKey, - nsIApplicationCache::ITEM_FOREIGN); + return new OfflineCacheEntryAsForeignMarker(mApplicationCache, cacheKey); +} + +nsresult +nsHttpChannel::OfflineCacheEntryAsForeignMarker::MarkAsForeign() +{ + return mApplicationCache->MarkEntry(mCacheKey, + nsIApplicationCache::ITEM_FOREIGN); +} + +NS_IMETHODIMP +nsHttpChannel::MarkOfflineCacheEntryAsForeign() +{ + nsresult rv; + + nsAutoPtr marker( + GetOfflineCacheEntryAsForeignMarker()); + + if (!marker) + return NS_ERROR_NOT_AVAILABLE; + + rv = marker->MarkAsForeign(); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index dbebc043c0e..941bda80ac9 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -161,6 +161,23 @@ public: /* internal necko use only */ return NS_OK; } + // This allows cache entry to be marked as foreign even after channel itself + // is gone. Needed for e10s (see HttpChannelParent::RecvDocumentChannelCleanup) + class OfflineCacheEntryAsForeignMarker { + nsCOMPtr mApplicationCache; + nsCString mCacheKey; + public: + OfflineCacheEntryAsForeignMarker(nsIApplicationCache* appCache, + const nsCSubstring& key) + : mApplicationCache(appCache) + , mCacheKey(key) + {} + + nsresult MarkAsForeign(); + }; + + OfflineCacheEntryAsForeignMarker* GetOfflineCacheEntryAsForeignMarker(); + private: typedef nsresult (nsHttpChannel::*nsContinueRedirectionFunc)(nsresult result);