#include "core/fetch/FetchUtils.h"
#include "core/loader/DocumentThreadableLoader.h"
#include "core/loader/DocumentThreadableLoaderClient.h"
-#include "core/xml/XMLHttpRequest.h"
#include "platform/Timer.h"
#include "platform/exported/WrappedResourceRequest.h"
#include "platform/exported/WrappedResourceResponse.h"
#include "web/WebLocalFrameImpl.h"
#include "wtf/HashSet.h"
#include "wtf/text/WTFString.h"
+#include <limits.h>
namespace blink {
// This class bridges the interface differences between WebCore and WebKit loader clients.
// It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient.
-class AssociatedURLLoader::ClientAdapter FINAL : public DocumentThreadableLoaderClient {
+class AssociatedURLLoader::ClientAdapter final : public DocumentThreadableLoaderClient {
WTF_MAKE_NONCOPYABLE(ClientAdapter);
public:
static PassOwnPtr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoaderClient*, const WebURLLoaderOptions&);
- virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) OVERRIDE;
- virtual void willSendRequest(ResourceRequest& /*newRequest*/, const ResourceResponse& /*redirectResponse*/) OVERRIDE;
-
- virtual void didReceiveResponse(unsigned long, const ResourceResponse&) OVERRIDE;
- virtual void didDownloadData(int /*dataLength*/) OVERRIDE;
- virtual void didReceiveData(const char*, int /*dataLength*/) OVERRIDE;
- virtual void didReceiveCachedMetadata(const char*, int /*dataLength*/) OVERRIDE;
- virtual void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) OVERRIDE;
- virtual void didFail(const ResourceError&) OVERRIDE;
- virtual void didFailRedirectCheck() OVERRIDE;
+ // ThreadableLoaderClient
+ void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) override;
+ void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<WebDataConsumerHandle>) override;
+ void didDownloadData(int /*dataLength*/) override;
+ void didReceiveData(const char*, unsigned /*dataLength*/) override;
+ void didReceiveCachedMetadata(const char*, int /*dataLength*/) override;
+ void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/) override;
+ void didFail(const ResourceError&) override;
+ void didFailRedirectCheck() override;
+ // DocumentThreadableLoaderClient
+ void willFollowRedirect(ResourceRequest& /*newRequest*/, const ResourceResponse& /*redirectResponse*/) override;
// Sets an error to be reported back to the client, asychronously.
void setDelayedError(const ResourceError&);
ASSERT(m_client);
}
-void AssociatedURLLoader::ClientAdapter::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
+void AssociatedURLLoader::ClientAdapter::willFollowRedirect(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
{
if (!m_client)
return;
m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent);
}
-void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const ResourceResponse& response)
+void AssociatedURLLoader::ClientAdapter::didReceiveResponse(unsigned long, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
{
+ ASSERT_UNUSED(handle, !handle);
if (!m_client)
return;
m_client->didDownloadData(m_loader, dataLength, -1);
}
-void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, int dataLength)
+void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, unsigned dataLength)
{
if (!m_client)
return;
+ RELEASE_ASSERT(dataLength <= static_cast<unsigned>(std::numeric_limits<int>::max()));
+
m_client->didReceiveData(m_loader, data, dataLength, -1);
}
void AssociatedURLLoader::ClientAdapter::didFailRedirectCheck()
{
- m_loader->cancel();
+ didFail(ResourceError());
}
void AssociatedURLLoader::ClientAdapter::setDelayedError(const ResourceError& error)
void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client)
{
+ ASSERT(!m_loader);
ASSERT(!m_client);
m_client = client;
WebString method = newRequest.httpMethod();
allowLoad = isValidHTTPToken(method) && FetchUtils::isUsefulMethod(method);
if (allowLoad) {
- newRequest.setHTTPMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(method));
+ newRequest.setHTTPMethod(FetchUtils::normalizeMethod(method));
HTTPRequestHeaderValidator validator;
newRequest.visitHTTPHeaderFields(&validator);
allowLoad = validator.isSafe();
Document* webcoreDocument = m_frameImpl->frame()->document();
ASSERT(webcoreDocument);
m_loader = DocumentThreadableLoader::create(*webcoreDocument, m_clientAdapter.get(), webcoreRequest, options, resourceLoaderOptions);
- } else {
+ }
+
+ if (!m_loader) {
// FIXME: return meaningful error codes.
m_clientAdapter->setDelayedError(ResourceError());
}