summaryrefslogtreecommitdiffstats
path: root/WebKit/chromium/src/ResourceHandle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/chromium/src/ResourceHandle.cpp')
-rw-r--r--WebKit/chromium/src/ResourceHandle.cpp86
1 files changed, 70 insertions, 16 deletions
diff --git a/WebKit/chromium/src/ResourceHandle.cpp b/WebKit/chromium/src/ResourceHandle.cpp
index bf6910f..83e0017 100644
--- a/WebKit/chromium/src/ResourceHandle.cpp
+++ b/WebKit/chromium/src/ResourceHandle.cpp
@@ -31,8 +31,10 @@
#include "config.h"
#include "ResourceHandle.h"
+#include "ChromiumBridge.h"
#include "ResourceHandleClient.h"
#include "ResourceRequest.h"
+#include "SharedBuffer.h"
#include "WebKit.h"
#include "WebKitClient.h"
@@ -56,6 +58,7 @@ public:
: m_request(request)
, m_owner(0)
, m_client(client)
+ , m_state(ConnectionStateNew)
{
}
@@ -70,17 +73,36 @@ public:
WebURLLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
virtual void didReceiveResponse(WebURLLoader*, const WebURLResponse&);
virtual void didReceiveData(WebURLLoader*, const char* data, int dataLength);
- virtual void didFinishLoading(WebURLLoader*);
+ virtual void didReceiveCachedMetadata(WebURLLoader*, const char* data, int dataLength);
+ virtual void didFinishLoading(WebURLLoader*, double finishTime);
virtual void didFail(WebURLLoader*, const WebURLError&);
+ enum ConnectionState {
+ ConnectionStateNew,
+ ConnectionStateStarted,
+ ConnectionStateReceivedResponse,
+ ConnectionStateReceivingData,
+ ConnectionStateFinishedLoading,
+ ConnectionStateCanceled,
+ ConnectionStateFailed,
+ };
+
ResourceRequest m_request;
ResourceHandle* m_owner;
ResourceHandleClient* m_client;
OwnPtr<WebURLLoader> m_loader;
+
+ // Used for sanity checking to make sure we don't experience illegal state
+ // transitions.
+ ConnectionState m_state;
};
void ResourceHandleInternal::start()
{
+ if (m_state != ConnectionStateNew)
+ CRASH();
+ m_state = ConnectionStateStarted;
+
m_loader.set(webKitClient()->createURLLoader());
ASSERT(m_loader.get());
@@ -91,6 +113,7 @@ void ResourceHandleInternal::start()
void ResourceHandleInternal::cancel()
{
+ m_state = ConnectionStateCanceled;
m_loader->cancel();
// Do not make any further calls to the client.
@@ -127,6 +150,12 @@ void ResourceHandleInternal::didReceiveResponse(WebURLLoader*, const WebURLRespo
{
ASSERT(m_client);
ASSERT(!response.isNull());
+ bool isMultipart = response.isMultipartPayload();
+ bool isValidStateTransition = (m_state == ConnectionStateStarted || m_state == ConnectionStateReceivedResponse);
+ // In the case of multipart loads, calls to didReceiveData & didReceiveResponse can be interleaved.
+ if (!isMultipart && !isValidStateTransition)
+ CRASH();
+ m_state = ConnectionStateReceivedResponse;
m_client->didReceiveResponse(m_owner, response.toResourceResponse());
}
@@ -134,6 +163,9 @@ void ResourceHandleInternal::didReceiveData(
WebURLLoader*, const char* data, int dataLength)
{
ASSERT(m_client);
+ if (m_state != ConnectionStateReceivedResponse && m_state != ConnectionStateReceivingData)
+ CRASH();
+ m_state = ConnectionStateReceivingData;
// FIXME(yurys): it looks like lengthReceived is always the same as
// dataLength and that the latter parameter can be eliminated.
@@ -141,15 +173,28 @@ void ResourceHandleInternal::didReceiveData(
m_client->didReceiveData(m_owner, data, dataLength, dataLength);
}
-void ResourceHandleInternal::didFinishLoading(WebURLLoader*)
+void ResourceHandleInternal::didReceiveCachedMetadata(WebURLLoader*, const char* data, int dataLength)
+{
+ ASSERT(m_client);
+ if (m_state != ConnectionStateReceivedResponse && m_state != ConnectionStateReceivingData)
+ CRASH();
+
+ m_client->didReceiveCachedMetadata(m_owner, data, dataLength);
+}
+
+void ResourceHandleInternal::didFinishLoading(WebURLLoader*, double finishTime)
{
ASSERT(m_client);
- m_client->didFinishLoading(m_owner);
+ if (m_state != ConnectionStateReceivedResponse && m_state != ConnectionStateReceivingData)
+ CRASH();
+ m_state = ConnectionStateFinishedLoading;
+ m_client->didFinishLoading(m_owner, finishTime);
}
void ResourceHandleInternal::didFail(WebURLLoader*, const WebURLError& error)
{
ASSERT(m_client);
+ m_state = ConnectionStateFailed;
m_client->didFail(m_owner, error);
}
@@ -158,8 +203,7 @@ void ResourceHandleInternal::didFail(WebURLLoader*, const WebURLError& error)
ResourceHandle::ResourceHandle(const ResourceRequest& request,
ResourceHandleClient* client,
bool defersLoading,
- bool shouldContentSniff,
- bool mightDownloadFromHandle)
+ bool shouldContentSniff)
: d(new ResourceHandleInternal(request, client))
{
d->m_owner = this;
@@ -167,23 +211,22 @@ ResourceHandle::ResourceHandle(const ResourceRequest& request,
// FIXME: Figure out what to do with the bool params.
}
-PassRefPtr<ResourceHandle> ResourceHandle::create(const ResourceRequest& request,
+PassRefPtr<ResourceHandle> ResourceHandle::create(NetworkingContext* context,
+ const ResourceRequest& request,
ResourceHandleClient* client,
- Frame* deprecated,
bool defersLoading,
- bool shouldContentSniff,
- bool mightDownloadFromHandle)
+ bool shouldContentSniff)
{
RefPtr<ResourceHandle> newHandle = adoptRef(new ResourceHandle(
- request, client, defersLoading, shouldContentSniff, mightDownloadFromHandle));
+ request, client, defersLoading, shouldContentSniff));
- if (newHandle->start(deprecated))
+ if (newHandle->start(context))
return newHandle.release();
return 0;
}
-const ResourceRequest& ResourceHandle::request() const
+ResourceRequest& ResourceHandle::firstRequest()
{
return d->m_request;
}
@@ -203,12 +246,17 @@ void ResourceHandle::setDefersLoading(bool value)
d->setDefersLoading(value);
}
-bool ResourceHandle::start(Frame* deprecated)
+bool ResourceHandle::start(NetworkingContext* context)
{
d->start();
return true;
}
+bool ResourceHandle::hasAuthenticationChallenge() const
+{
+ return false;
+}
+
void ResourceHandle::clearAuthentication()
{
}
@@ -240,12 +288,12 @@ bool ResourceHandle::supportsBufferedData()
}
// static
-void ResourceHandle::loadResourceSynchronously(const ResourceRequest& request,
+void ResourceHandle::loadResourceSynchronously(NetworkingContext* context,
+ const ResourceRequest& request,
StoredCredentials storedCredentials,
ResourceError& error,
ResourceResponse& response,
- Vector<char>& data,
- Frame* deprecated)
+ Vector<char>& data)
{
OwnPtr<WebURLLoader> loader(webKitClient()->createURLLoader());
ASSERT(loader.get());
@@ -279,4 +327,10 @@ bool ResourceHandle::willLoadFromCache(ResourceRequest& request, Frame*)
return true;
}
+// static
+void ResourceHandle::cacheMetadata(const ResourceResponse& response, const Vector<char>& data)
+{
+ ChromiumBridge::cacheMetadata(response.url(), response.responseTime(), data);
+}
+
} // namespace WebCore