diff options
author | Steve Block <steveblock@google.com> | 2011-05-25 19:08:45 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-08 13:51:31 +0100 |
commit | 2bde8e466a4451c7319e3a072d118917957d6554 (patch) | |
tree | 28f4a1b869a513e565c7760d0e6a06e7cf1fe95a /Source/WebKit/chromium/src/AssociatedURLLoader.cpp | |
parent | 6939c99b71d9372d14a0c74a772108052e8c48c8 (diff) | |
download | external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.zip external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.gz external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.bz2 |
Merge WebKit at r82507: Initial merge by git
Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e
Diffstat (limited to 'Source/WebKit/chromium/src/AssociatedURLLoader.cpp')
-rw-r--r-- | Source/WebKit/chromium/src/AssociatedURLLoader.cpp | 189 |
1 files changed, 146 insertions, 43 deletions
diff --git a/Source/WebKit/chromium/src/AssociatedURLLoader.cpp b/Source/WebKit/chromium/src/AssociatedURLLoader.cpp index 34a4055..1ca9900 100644 --- a/Source/WebKit/chromium/src/AssociatedURLLoader.cpp +++ b/Source/WebKit/chromium/src/AssociatedURLLoader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2010, 2011 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -31,103 +31,206 @@ #include "config.h" #include "AssociatedURLLoader.h" +#include "DocumentThreadableLoader.h" +#include "DocumentThreadableLoaderClient.h" +#include "SubresourceLoader.h" #include "WebApplicationCacheHost.h" #include "WebDataSource.h" #include "WebFrameImpl.h" #include "WebKit.h" #include "WebKitClient.h" +#include "WebURLError.h" +#include "WebURLLoaderClient.h" #include "WebURLRequest.h" +#include "WrappedResourceRequest.h" +#include "WrappedResourceResponse.h" + +using namespace WebCore; +using namespace WebKit; +using namespace WTF; namespace WebKit { -AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl) - : m_frameImpl(frameImpl), - m_realLoader(webKitClient()->createURLLoader()), - m_realClient(0) +// This class bridges the interface differences between WebCore and WebKit loader clients. +// It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient. +class AssociatedURLLoader::ClientAdapter : public DocumentThreadableLoaderClient { +public: + static PassOwnPtr<ClientAdapter> create(AssociatedURLLoader*, WebURLLoaderClient*, bool /*downloadToFile*/); + + virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/); + virtual void willSendRequest(ResourceRequest& /*newRequest*/, const ResourceResponse& /*redirectResponse*/); + + virtual void didReceiveResponse(const ResourceResponse&); + virtual void didReceiveData(const char*, int /*dataLength*/); + virtual void didReceiveCachedMetadata(const char*, int /*dataLength*/); + virtual void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/); + virtual void didFail(const ResourceError&); + + virtual bool isDocumentThreadableLoaderClient() { return true; } + + // This method stops loading and releases the DocumentThreadableLoader as early as possible. + void clearClient() { m_client = 0; } + +private: + ClientAdapter(AssociatedURLLoader*, WebURLLoaderClient*, bool /*downloadToFile*/); + + AssociatedURLLoader* m_loader; + WebURLLoaderClient* m_client; + unsigned long m_downloadLength; + bool m_downloadToFile; +}; + +PassOwnPtr<AssociatedURLLoader::ClientAdapter> AssociatedURLLoader::ClientAdapter::create(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile) { + return adoptPtr(new ClientAdapter(loader, client, downloadToFile)); } -AssociatedURLLoader::~AssociatedURLLoader() +AssociatedURLLoader::ClientAdapter::ClientAdapter(AssociatedURLLoader* loader, WebURLLoaderClient* client, bool downloadToFile) + : m_loader(loader) + , m_client(client) + , m_downloadLength(0) + , m_downloadToFile(downloadToFile) { + ASSERT(m_loader); + ASSERT(m_client); } -void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data) +void AssociatedURLLoader::ClientAdapter::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse) { - ASSERT(!m_realClient); - - WebURLRequest requestCopy(request); - prepareRequest(requestCopy); + if (!m_client) + return; - m_realLoader->loadSynchronously(requestCopy, response, error, data); + WrappedResourceRequest wrappedNewRequest(newRequest); + WrappedResourceResponse wrappedRedirectResponse(redirectResponse); + m_client->willSendRequest(m_loader, wrappedNewRequest, wrappedRedirectResponse); } -void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client) +void AssociatedURLLoader::ClientAdapter::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) { - ASSERT(!m_realClient); + if (!m_client) + return; - WebURLRequest requestCopy(request); - prepareRequest(requestCopy); + m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent); +} - m_realClient = client; - m_realLoader->loadAsynchronously(requestCopy, this); +void AssociatedURLLoader::ClientAdapter::didReceiveResponse(const ResourceResponse& response) +{ + WrappedResourceResponse wrappedResponse(response); + m_client->didReceiveResponse(m_loader, wrappedResponse); } -void AssociatedURLLoader::cancel() +void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, int dataLength) { - m_realLoader->cancel(); + if (!m_client) + return; + + // FIXME(vsevik): add -1 to params once migrated. + m_client->didReceiveData(m_loader, data, dataLength); + m_downloadLength += dataLength; } -void AssociatedURLLoader::setDefersLoading(bool defersLoading) +void AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata(const char* data, int lengthReceived) { - m_realLoader->setDefersLoading(defersLoading); + if (!m_client) + return; + + m_client->didReceiveCachedMetadata(m_loader, data, lengthReceived); } -void AssociatedURLLoader::prepareRequest(WebURLRequest& request) +void AssociatedURLLoader::ClientAdapter::didFinishLoading(unsigned long identifier, double finishTime) { - WebApplicationCacheHost* applicationCacheHost = m_frameImpl->dataSource()->applicationCacheHost(); - if (applicationCacheHost) - applicationCacheHost->willStartSubResourceRequest(request); - m_frameImpl->dispatchWillSendRequest(request); + if (!m_client) + return; + + if (m_downloadToFile) { + int downloadLength = m_downloadLength <= INT_MAX ? m_downloadLength : INT_MAX; + m_client->didDownloadData(m_loader, downloadLength); + // While the client could have cancelled, continue, since the load finished. + } + + m_client->didFinishLoading(m_loader, finishTime); } -void AssociatedURLLoader::willSendRequest(WebURLLoader*, WebURLRequest& newRequest, const WebURLResponse& redirectResponse) +void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error) { - m_realClient->willSendRequest(this, newRequest, redirectResponse); + if (!m_client) + return; + + WebURLError webError(error); + m_client->didFail(m_loader, webError); } -void AssociatedURLLoader::didSendData(WebURLLoader*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent) +AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl) + : m_frameImpl(frameImpl) + , m_client(0) { - m_realClient->didSendData(this, bytesSent, totalBytesToBeSent); + ASSERT(m_frameImpl); + + m_options.sniffContent = false; + m_options.allowCredentials = true; + m_options.forcePreflight = false; + m_options.crossOriginRequestPolicy = AllowCrossOriginRequests; // TODO(bbudge) Default should be DenyCrossOriginRequests, but this would break some tests. } -void AssociatedURLLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& response) +AssociatedURLLoader::AssociatedURLLoader(PassRefPtr<WebFrameImpl> frameImpl, const WebURLLoaderOptions& options) + : m_frameImpl(frameImpl) + , m_options(options) + , m_client(0) { - m_realClient->didReceiveResponse(this, response); + ASSERT(m_frameImpl); } -void AssociatedURLLoader::didDownloadData(WebURLLoader*, int dataLength) +AssociatedURLLoader::~AssociatedURLLoader() { - m_realClient->didDownloadData(this, dataLength); + if (m_clientAdapter) + m_clientAdapter->clearClient(); } -void AssociatedURLLoader::didReceiveData(WebURLLoader*, const char* data, int dataLength) +#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, webcore_name) \ + COMPILE_ASSERT(static_cast<int>(WebKit::webkit_name) == static_cast<int>(WebCore::webcore_name), mismatching_enums) + +COMPILE_ASSERT_MATCHING_ENUM(DenyCrossOriginRequests, DenyCrossOriginRequests); +COMPILE_ASSERT_MATCHING_ENUM(UseAccessControl, UseAccessControl); +COMPILE_ASSERT_MATCHING_ENUM(AllowCrossOriginRequests, AllowCrossOriginRequests); + +void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, WebURLResponse& response, WebURLError& error, WebData& data) { - m_realClient->didReceiveData(this, data, dataLength); + ASSERT(0); // Synchronous loading is not supported. } -void AssociatedURLLoader::didReceiveCachedMetadata(WebURLLoader*, const char* data, int dataLength) +void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, WebURLLoaderClient* client) { - m_realClient->didReceiveCachedMetadata(this, data, dataLength); + ASSERT(!m_client); + + m_client = client; + ASSERT(m_client); + + ThreadableLoaderOptions options; + options.sendLoadCallbacks = true; // Always send callbacks. + options.sniffContent = m_options.sniffContent; + options.allowCredentials = m_options.allowCredentials; + options.forcePreflight = m_options.forcePreflight; + options.crossOriginRequestPolicy = static_cast<WebCore::CrossOriginRequestPolicy>(m_options.crossOriginRequestPolicy); + + const ResourceRequest& webcoreRequest = request.toResourceRequest(); + Document* webcoreDocument = m_frameImpl->frame()->document(); + m_clientAdapter = ClientAdapter::create(this, m_client, request.downloadToFile()); + + m_loader = DocumentThreadableLoader::create(webcoreDocument, m_clientAdapter.get(), webcoreRequest, options); } -void AssociatedURLLoader::didFinishLoading(WebURLLoader*, double finishTime) +void AssociatedURLLoader::cancel() { - m_realClient->didFinishLoading(this, finishTime); + if (m_loader) { + m_clientAdapter->clearClient(); + m_loader->cancel(); + } } -void AssociatedURLLoader::didFail(WebURLLoader*, const WebURLError& error) +void AssociatedURLLoader::setDefersLoading(bool defersLoading) { - m_realClient->didFail(this, error); + if (m_loader) + m_loader->setDefersLoading(defersLoading); } } // namespace WebKit |