Bug 443023: Associate documents with their caches after an initial update. r=honzab, r+sr=biesi

This commit is contained in:
Dave Camp 2008-11-04 02:20:27 -08:00
Родитель dea763c065
Коммит b63345b178
3 изменённых файлов: 72 добавлений и 12 удалений

Просмотреть файл

@ -56,7 +56,14 @@ function manifestUpdated()
OfflineTest.checkCache("https://localhost:8888/MochiKit/packed.js", false);
OfflineTest.checkCache("bad:/uri/invalid", false);
applicationCache.swapCache();
OfflineTest.is(applicationCache.status, 1, "Cache status should be 1 (CACHED)");
try {
applicationCache.swapCache();
OfflineTest.ok(false, "application.swapCache() should fail after initial update.");
} catch(ex) {
OfflineTest.ok(true, "application.swapCache() should fail after initial update.");
}
// XXX: make sure that the previous version went away after the swapCache().

Просмотреть файл

@ -40,6 +40,7 @@
#include "nsCPrefetchService.h"
#include "nsCURILoader.h"
#include "nsIApplicationCacheContainer.h"
#include "nsIApplicationCacheChannel.h"
#include "nsIApplicationCacheService.h"
#include "nsICache.h"
@ -1438,6 +1439,29 @@ nsOfflineCacheUpdate::NotifyCompleted(nsOfflineCacheUpdateItem *aItem)
return NS_OK;
}
nsresult
nsOfflineCacheUpdate::AssociateDocument(nsIDOMDocument *aDocument)
{
// Check that the document that requested this update was
// previously associated with an application cache. If not, it
// should be associated with the new one.
nsCOMPtr<nsIApplicationCacheContainer> container =
do_QueryInterface(aDocument);
if (!container)
return NS_OK;
nsCOMPtr<nsIApplicationCache> existingCache;
nsresult rv = container->GetApplicationCache(getter_AddRefs(existingCache));
NS_ENSURE_SUCCESS(rv, rv);
if (!existingCache) {
rv = container->SetApplicationCache(mApplicationCache);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult
nsOfflineCacheUpdate::Finish()
{
@ -1465,6 +1489,10 @@ nsOfflineCacheUpdate::Finish()
NotifyError();
mSucceeded = PR_FALSE;
}
for (PRInt32 i = 0; i < mDocuments.Count(); i++) {
AssociateDocument(mDocuments[i]);
}
}
if (!mSucceeded) {
@ -1912,11 +1940,11 @@ nsOfflineCacheUpdateService::GetUpdate(PRUint32 aIndex,
return NS_OK;
}
NS_IMETHODIMP
nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIOfflineCacheUpdate **aUpdate)
nsresult
nsOfflineCacheUpdateService::Schedule(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIDOMDocument *aDocument,
nsIOfflineCacheUpdate **aUpdate)
{
// Check for existing updates
nsresult rv;
@ -1938,6 +1966,8 @@ nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI,
PRBool equals;
rv = manifestURI->Equals(aManifestURI, &equals);
if (equals) {
if (aDocument)
update->AddDocument(aDocument);
NS_ADDREF(*aUpdate = update);
return NS_OK;
}
@ -1953,6 +1983,9 @@ nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI,
rv = update->Init(aManifestURI, aDocumentURI);
NS_ENSURE_SUCCESS(rv, rv);
if (aDocument)
update->AddDocument(aDocument);
rv = update->Schedule();
NS_ENSURE_SUCCESS(rv, rv);
@ -1961,6 +1994,14 @@ nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI,
return NS_OK;
}
NS_IMETHODIMP
nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIOfflineCacheUpdate **aUpdate)
{
return Schedule(aManifestURI, aDocumentURI, nsnull, aUpdate);
}
//-----------------------------------------------------------------------------
// nsOfflineCacheUpdateService::nsIObserver
//-----------------------------------------------------------------------------
@ -2017,15 +2058,14 @@ nsOfflineCacheUpdateService::OnStateChange(nsIWebProgress* aWebProgress,
LOG(("nsOfflineCacheUpdateService::OnStateChange [%p, doc=%p]",
this, doc.get()));
PendingUpdate *pendingUpdate;
if (mDocUpdates.Get(doc, &pendingUpdate)) {
// Only schedule the update if the document loaded successfull
// Only schedule the update if the document loaded successfully
if (NS_SUCCEEDED(aStatus)) {
nsCOMPtr<nsIOfflineCacheUpdate> update;
ScheduleUpdate(pendingUpdate->mManifestURI,
pendingUpdate->mDocumentURI,
getter_AddRefs(update));
Schedule(pendingUpdate->mManifestURI,
pendingUpdate->mDocumentURI,
doc, getter_AddRefs(update));
}
mDocUpdates.Remove(doc);
}

Просмотреть файл

@ -217,6 +217,10 @@ public:
void LoadCompleted();
void AddDocument(nsIDOMDocument *aDocument) {
mDocuments.AppendObject(aDocument);
};
private:
nsresult HandleManifest(PRBool *aDoUpdate);
nsresult AddURI(nsIURI *aURI, PRUint32 aItemType);
@ -236,6 +240,7 @@ private:
nsresult NotifyDownloading();
nsresult NotifyStarted(nsOfflineCacheUpdateItem *aItem);
nsresult NotifyCompleted(nsOfflineCacheUpdateItem *aItem);
nsresult AssociateDocument(nsIDOMDocument *aDocument);
nsresult Finish();
enum {
@ -270,6 +275,9 @@ private:
/* Clients watching this update for changes */
nsCOMArray<nsIWeakReference> mWeakObservers;
nsCOMArray<nsIOfflineCacheUpdateObserver> mObservers;
/* Documents that requested this update */
nsCOMArray<nsIDOMDocument> mDocuments;
};
class nsOfflineCacheUpdateService : public nsIOfflineCacheUpdateService
@ -289,6 +297,11 @@ public:
nsresult Init();
nsresult Schedule(nsOfflineCacheUpdate *aUpdate);
nsresult Schedule(nsIURI *aManifestURI,
nsIURI *aDocumentURI,
nsIDOMDocument *aDocument,
nsIOfflineCacheUpdate **aUpdate);
nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate);
/**
@ -299,7 +312,7 @@ public:
/** Addrefs and returns the singleton nsOfflineCacheUpdateService. */
static nsOfflineCacheUpdateService *GetInstance();
private:
nsresult ProcessNextUpdate();