summaryrefslogtreecommitdiffstats
path: root/WebCore/loader/MainResourceLoader.cpp
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
commit1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch)
tree4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebCore/loader/MainResourceLoader.cpp
parent9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff)
downloadexternal_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebCore/loader/MainResourceLoader.cpp')
-rw-r--r--WebCore/loader/MainResourceLoader.cpp78
1 files changed, 69 insertions, 9 deletions
diff --git a/WebCore/loader/MainResourceLoader.cpp b/WebCore/loader/MainResourceLoader.cpp
index c591c2f..079bd79 100644
--- a/WebCore/loader/MainResourceLoader.cpp
+++ b/WebCore/loader/MainResourceLoader.cpp
@@ -29,13 +29,20 @@
#include "config.h"
#include "MainResourceLoader.h"
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+#include "ApplicationCache.h"
+#include "ApplicationCacheGroup.h"
+#include "ApplicationCacheResource.h"
+#endif
#include "DocumentLoader.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "HTMLFormElement.h"
+#include "Page.h"
#include "ResourceError.h"
#include "ResourceHandle.h"
+#include "Settings.h"
// FIXME: More that is in common with SubresourceLoader should move up into ResourceLoader.
@@ -55,7 +62,7 @@ MainResourceLoader::~MainResourceLoader()
PassRefPtr<MainResourceLoader> MainResourceLoader::create(Frame* frame)
{
- return new MainResourceLoader(frame);
+ return adoptRef(new MainResourceLoader(frame));
}
void MainResourceLoader::receivedError(const ResourceError& error)
@@ -162,10 +169,7 @@ void MainResourceLoader::willSendRequest(ResourceRequest& newRequest, const Reso
if (newRequest.cachePolicy() == UseProtocolCachePolicy && isPostOrRedirectAfterPost(newRequest, redirectResponse))
newRequest.setCachePolicy(ReloadIgnoringCacheData);
- if (!newRequest.isNull()) {
- ResourceLoader::willSendRequest(newRequest, redirectResponse);
- setRequest(newRequest);
- }
+ ResourceLoader::willSendRequest(newRequest, redirectResponse);
// Don't set this on the first request. It is set when the main load was started.
m_documentLoader->setRequest(newRequest);
@@ -205,7 +209,9 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction contentPolicy,
case PolicyDownload:
frameLoader()->client()->download(m_handle.get(), request(), m_handle.get()->request(), r);
- receivedError(interruptionForPolicyChangeError());
+ // It might have gone missing
+ if (frameLoader())
+ receivedError(interruptionForPolicyChangeError());
return;
case PolicyIgnore:
@@ -262,7 +268,11 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction policy)
void MainResourceLoader::didReceiveResponse(const ResourceResponse& r)
{
+ // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
+ // See <rdar://problem/6304600> for more details.
+#if !PLATFORM(CF)
ASSERT(shouldLoadAsEmptyDocument(r.url()) || !defersLoading());
+#endif
if (m_loadingMultipartContent) {
frameLoader()->setupForReplaceByMIMEType(r.mimeType());
@@ -290,7 +300,12 @@ void MainResourceLoader::didReceiveData(const char* data, int length, long long
{
ASSERT(data);
ASSERT(length != 0);
+
+ // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
+ // See <rdar://problem/6304600> for more details.
+#if !PLATFORM(CF)
ASSERT(!defersLoading());
+#endif
// The additional processing can do anything including possibly removing the last
// reference to this object; one example of this is 3266216.
@@ -301,20 +316,41 @@ void MainResourceLoader::didReceiveData(const char* data, int length, long long
void MainResourceLoader::didFinishLoading()
{
+ // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
+ // See <rdar://problem/6304600> for more details.
+#if !PLATFORM(CF)
ASSERT(shouldLoadAsEmptyDocument(frameLoader()->activeDocumentLoader()->url()) || !defersLoading());
-
+#endif
+
// The additional processing can do anything including possibly removing the last
// reference to this object.
RefPtr<MainResourceLoader> protect(this);
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ RefPtr<DocumentLoader> dl = documentLoader();
+#endif
+
frameLoader()->finishedLoading();
ResourceLoader::didFinishLoading();
+
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ ApplicationCacheGroup* group = dl->candidateApplicationCacheGroup();
+ if (!group && dl->applicationCache() && !dl->mainResourceApplicationCache())
+ group = dl->applicationCache()->group();
+
+ if (group)
+ group->finishedLoadingMainResource(dl.get());
+#endif
}
void MainResourceLoader::didFail(const ResourceError& error)
{
+ // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
+ // See <rdar://problem/6304600> for more details.
+#if !PLATFORM(CF)
ASSERT(!defersLoading());
-
+#endif
+
receivedError(error);
}
@@ -385,12 +421,36 @@ bool MainResourceLoader::loadNow(ResourceRequest& r)
return false;
}
-bool MainResourceLoader::load(const ResourceRequest& r, const SubstituteData& substituteData)
+bool MainResourceLoader::load(const ResourceRequest& r, const SubstituteData& substituteData)
{
ASSERT(!m_handle);
m_substituteData = substituteData;
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ // Check if this request should be loaded from the application cache
+ if (!m_substituteData.isValid() && frameLoader()->frame()->settings() && frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) {
+ ASSERT(!m_applicationCache);
+
+ if (Page* page = frameLoader()->frame()->page()) {
+ if (frameLoader()->frame() == page->mainFrame())
+ m_applicationCache = ApplicationCacheGroup::cacheForMainRequest(r, m_documentLoader.get());
+ else
+ m_applicationCache = frameLoader()->documentLoader()->topLevelApplicationCache();
+ }
+
+ if (m_applicationCache) {
+ // Get the resource from the application cache.
+ // FIXME: If the resource does not exist, the load should fail.
+ if (ApplicationCacheResource* resource = m_applicationCache->resourceForRequest(r)) {
+ m_substituteData = SubstituteData(resource->data(),
+ resource->response().mimeType(),
+ resource->response().textEncodingName(), KURL());
+ }
+ }
+ }
+#endif
+
ResourceRequest request(r);
bool defer = defersLoading();
if (defer) {