From 433cb50458e6e49498a8564e030c5a0fcf0d880f Mon Sep 17 00:00:00 2001 From: Honza Bambas Date: Wed, 1 May 2013 18:57:58 +0200 Subject: [PATCH] Bug 730424 - window.applicationCache.status not getting updated when resources finish loading, r=michal --- dom/src/offline/nsDOMOfflineResourceList.cpp | 15 +++++++++++++++ dom/src/offline/nsDOMOfflineResourceList.h | 1 + .../prefetch/nsOfflineCacheUpdateService.cpp | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/dom/src/offline/nsDOMOfflineResourceList.cpp b/dom/src/offline/nsDOMOfflineResourceList.cpp index b5f4aede45b6..88b8d259a87f 100644 --- a/dom/src/offline/nsDOMOfflineResourceList.cpp +++ b/dom/src/offline/nsDOMOfflineResourceList.cpp @@ -86,6 +86,7 @@ nsDOMOfflineResourceList::nsDOMOfflineResourceList(nsIURI *aManifestURI, , mManifestURI(aManifestURI) , mDocumentURI(aDocumentURI) , mExposeCacheUpdateStatus(true) + , mDontSetDocumentCache(false) , mStatus(nsIDOMOfflineResourceList::IDLE) , mCachedKeys(nullptr) , mCachedKeysCount(0) @@ -449,6 +450,10 @@ nsDOMOfflineResourceList::Update() window, getter_AddRefs(update)); NS_ENSURE_SUCCESS(rv, rv); + // Since we are invoking the cache update, cache on the document must not + // be updated until swapCache() method is called on applicationCache object. + mDontSetDocumentCache = true; + return NS_OK; } @@ -620,6 +625,15 @@ NS_IMETHODIMP nsDOMOfflineResourceList::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache) { mAvailableApplicationCache = aApplicationCache; + + if (!mDontSetDocumentCache) { + nsCOMPtr appCacheContainer = + GetDocumentAppCacheContainer(); + + if (appCacheContainer) + appCacheContainer->SetApplicationCache(aApplicationCache); + } + return NS_OK; } @@ -718,6 +732,7 @@ nsDOMOfflineResourceList::UpdateCompleted(nsIOfflineCacheUpdate *aUpdate) mCacheUpdate->RemoveObserver(this); mCacheUpdate = nullptr; + mDontSetDocumentCache = false; if (NS_SUCCEEDED(rv) && succeeded && !partial) { if (isUpgrade) { diff --git a/dom/src/offline/nsDOMOfflineResourceList.h b/dom/src/offline/nsDOMOfflineResourceList.h index 03b5bdad0147..acbe24d995bc 100644 --- a/dom/src/offline/nsDOMOfflineResourceList.h +++ b/dom/src/offline/nsDOMOfflineResourceList.h @@ -79,6 +79,7 @@ private: nsCOMPtr mAvailableApplicationCache; nsCOMPtr mCacheUpdate; bool mExposeCacheUpdateStatus; + bool mDontSetDocumentCache; uint16_t mStatus; // The set of dynamic keys for this application cache object. diff --git a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp index d66fc4776f7c..fc76eaabac31 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp @@ -502,6 +502,14 @@ nsOfflineCacheUpdateService::Schedule(nsIURI *aManifestURI, nsresult rv; + if (aWindow) { + // Ensure there is window.applicationCache object that is + // responsible for association of the new applicationCache + // with the corresponding document. Just ignore the result. + nsCOMPtr appCacheWindowObject; + aWindow->GetApplicationCache(getter_AddRefs(appCacheWindowObject)); + } + rv = update->Init(aManifestURI, aDocumentURI, aDocument, aCustomProfileDir, aAppID, aInBrowser); NS_ENSURE_SUCCESS(rv, rv);