summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-08-06 04:53:09 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-08-06 04:53:09 -0700
commit68b7926085db91b432eb5ea0fa68b7665f02e09b (patch)
treeeaca28be701bfa6e7498a9fe598fb34312613d26
parent801a2989520f3f9b66e1f1dca6ca9a89226f0684 (diff)
parent9de447de54fcb62a01a3338bb4d2f4d1716f522d (diff)
downloadexternal_webkit-68b7926085db91b432eb5ea0fa68b7665f02e09b.zip
external_webkit-68b7926085db91b432eb5ea0fa68b7665f02e09b.tar.gz
external_webkit-68b7926085db91b432eb5ea0fa68b7665f02e09b.tar.bz2
Merge "Moving all webcore handling to the webcore thread."
-rw-r--r--WebKit/Android.mk3
-rw-r--r--WebKit/android/WebCoreSupport/WebRequest.cpp75
-rw-r--r--WebKit/android/WebCoreSupport/WebRequest.h5
-rw-r--r--WebKit/android/WebCoreSupport/WebResponse.cpp88
-rw-r--r--WebKit/android/WebCoreSupport/WebResponse.h66
-rw-r--r--WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp37
-rw-r--r--WebKit/android/WebCoreSupport/WebUrlLoaderClient.h22
7 files changed, 232 insertions, 64 deletions
diff --git a/WebKit/Android.mk b/WebKit/Android.mk
index 3303370..9edd064 100644
--- a/WebKit/Android.mk
+++ b/WebKit/Android.mk
@@ -33,7 +33,8 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
android/WebCoreSupport/WebUrlLoader.cpp \
android/WebCoreSupport/WebUrlLoaderClient.cpp \
android/WebCoreSupport/WebRequest.cpp \
- android/WebCoreSupport/WebRequestContext.cpp
+ android/WebCoreSupport/WebRequestContext.cpp \
+ android/WebCoreSupport/WebResponse.cpp
else
LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
android/WebCoreSupport/ResourceLoaderAndroid.cpp
diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp
index 81846d5..33eee94 100644
--- a/WebKit/android/WebCoreSupport/WebRequest.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequest.cpp
@@ -24,18 +24,19 @@
*/
#include "config.h"
-
#include "WebRequest.h"
#include "MainThread.h"
#include "ResourceRequest.h"
#include "WebRequestContext.h"
-
-#include "net/base/data_url.h"
-#include "net/base/io_buffer.h"
-#include "net/url_request/url_request.h"
#include "text/CString.h"
+#include <base/string_util.h>
+#include <net/base/data_url.h>
+#include <net/base/io_buffer.h>
+#include <net/http/http_request_headers.h>
+#include <net/http/http_response_headers.h>
+#include <net/url_request/url_request.h>
#include <string>
// TODO:
@@ -45,8 +46,6 @@
// - Check the string conversion work for more than the general case
// - Add network throttle needed by Android plugins
-using namespace WebCore;
-
namespace android {
namespace {
@@ -84,6 +83,36 @@ void WebRequest::start()
if (m_resourceRequest.httpBody())
setUploadData(m_request.get());
+ // Set the request headers
+ net::HttpRequestHeaders requestHeaders;
+ const HTTPHeaderMap& map = m_resourceRequest.httpHeaderFields();
+ for (HTTPHeaderMap::const_iterator it = map.begin(); it != map.end(); ++it) {
+ const std::string& nameUtf8 = it->first.string().utf8().data();
+
+ // Skip over referrer headers found in the header map because we already
+ // pulled it out as a separate parameter. We likewise prune the UA since
+ // that will be added back by the network layer.
+ if (LowerCaseEqualsASCII(nameUtf8, "referer") || LowerCaseEqualsASCII(nameUtf8, "user-agent"))
+ continue;
+
+ // The next comment does not match what is happening in code since the load flags are not implemented
+ // (http://b/issue?id=2889880)
+ // TODO: Check this is correct when load flags are implemented and working.
+
+ // Skip over "Cache-Control: max-age=0" header if the corresponding
+ // load flag is already specified. FrameLoader sets both the flag and
+ // the extra header -- the extra header is redundant since our network
+ // implementation will add the necessary headers based on load flags.
+ // See http://code.google.com/p/chromium/issues/detail?id=3434.
+ const std::string& valueUtf8 = it->second.utf8().data();
+ if (LowerCaseEqualsASCII(nameUtf8, "cache-control") && LowerCaseEqualsASCII(valueUtf8, "max-age=0"))
+ continue;
+
+ requestHeaders.SetHeader(nameUtf8, valueUtf8);
+ }
+ m_request->SetExtraRequestHeaders(requestHeaders);
+
+ m_request->set_referrer(m_resourceRequest.httpReferrer().utf8().data());
m_request->set_method(m_resourceRequest.httpMethod().utf8().data());
m_request->set_context(WebRequestContext::GetAndroidContext());
@@ -139,10 +168,8 @@ void WebRequest::handleDataURL(GURL url)
if (net::DataURL::Parse(url, &mimeType, &charset, data.get())) {
// PopulateURLResponse from chrome implementation
// weburlloader_impl.cc
- WebCore::ResourceResponse* resourceResponse = new WebCore::ResourceResponse(m_resourceRequest.url(), mimeType.c_str(), data->size(), charset.c_str(), "");
- resourceResponse->setHTTPStatusCode(200); // Do they always succeed?
-
- LoaderData* loaderResponse = new LoaderData(m_urlLoader, resourceResponse);
+ WebResponse webResponse(url.spec(), mimeType, data->size(), charset, 200);
+ LoaderData* loaderResponse = new LoaderData(m_urlLoader, webResponse);
callOnMainThread(WebUrlLoaderClient::didReceiveResponse, loaderResponse);
if (!data->empty()) {
@@ -176,16 +203,9 @@ void WebRequest::handleDataURL(GURL url)
void WebRequest::OnReceivedRedirect(URLRequest* newRequest, const GURL& newUrl, bool* deferRedirect)
{
if (newRequest && newRequest->status().is_success()) {
- KURL kurl(WebCore::ParsedURLString, newUrl.spec().c_str());
- std::string mime;
- std::string encoding;
- newRequest->GetMimeType(&mime);
- newRequest->GetCharset(&encoding);
- long long length = newRequest->GetExpectedContentSize();
- WebCore::ResourceResponse* resourceResponse = new WebCore::ResourceResponse(kurl, mime.c_str(), length, encoding.c_str(), "");
-
- resourceResponse->setHTTPStatusCode(newRequest->GetResponseCode());
- LoaderData* ld = new LoaderData(m_urlLoader, resourceResponse);
+ WebResponse webResponse(newRequest);
+ webResponse.setUrl(newUrl.spec());
+ LoaderData* ld = new LoaderData(m_urlLoader, webResponse);
callOnMainThread(WebUrlLoaderClient::willSendRequest, ld);
} else {
// why would this happen? And what to do?
@@ -218,17 +238,8 @@ void WebRequest::OnAuthRequired(URLRequest* request, net::AuthChallengeInfo* aut
void WebRequest::OnResponseStarted(URLRequest* request)
{
if (request && request->status().is_success()) {
- KURL kurl(WebCore::ParsedURLString, request->url().spec().c_str());
- std::string mime;
- std::string encoding;
- request->GetMimeType(&mime);
- request->GetCharset(&encoding);
- long long int length = request->GetExpectedContentSize();
- WebCore::ResourceResponse* resourceResponse = new WebCore::ResourceResponse(kurl, mime.c_str(), length, encoding.c_str(), "");
-
- resourceResponse->setHTTPStatusCode(request->GetResponseCode());
- LoaderData* loaderData = new LoaderData(m_urlLoader, resourceResponse);
-
+ WebResponse webResponse(request);
+ LoaderData* loaderData = new LoaderData(m_urlLoader, webResponse);
callOnMainThread(WebUrlLoaderClient::didReceiveResponse, loaderData);
// Start reading the response
diff --git a/WebKit/android/WebCoreSupport/WebRequest.h b/WebKit/android/WebCoreSupport/WebRequest.h
index 5e1d92c..b106b46 100644
--- a/WebKit/android/WebCoreSupport/WebRequest.h
+++ b/WebKit/android/WebCoreSupport/WebRequest.h
@@ -27,8 +27,9 @@
#define WebRequest_h
#include "WebUrlLoaderClient.h"
-#include "net/base/io_buffer.h"
-#include "net/url_request/url_request.h"
+
+#include <net/base/io_buffer.h>
+#include <net/url_request/url_request.h>
class MessageLoop;
diff --git a/WebKit/android/WebCoreSupport/WebResponse.cpp b/WebKit/android/WebCoreSupport/WebResponse.cpp
new file mode 100644
index 0000000..6fc48e9
--- /dev/null
+++ b/WebKit/android/WebCoreSupport/WebResponse.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebResponse.h"
+
+#include "ResourceResponse.h"
+
+namespace android {
+
+WebResponse::WebResponse(URLRequest* request)
+ : m_httpStatusCode(0)
+{
+ m_url = request->url().spec();
+ request->GetMimeType(&m_mime);
+ request->GetCharset(&m_encoding);
+ m_length = request->GetExpectedContentSize();
+
+ net::HttpResponseHeaders* responseHeaders = request->response_headers();
+ if (!responseHeaders)
+ return;
+
+ m_httpStatusCode = responseHeaders->response_code();
+ m_httpStatusText = responseHeaders->GetStatusText();
+
+ std::string value;
+ std::string name;
+ void* iter = 0;
+ while (responseHeaders->EnumerateHeaderLines(&iter, &name, &value))
+ m_headerFields[name] = value;
+}
+
+WebResponse::WebResponse(const std::string &url, const std::string &mimeType, const long long length, const std::string &encoding, const int httpStatusCode)
+ : m_encoding(encoding)
+ , m_httpStatusCode(httpStatusCode)
+ , m_length(length)
+ , m_mime(mimeType)
+ , m_url(url)
+{
+}
+
+WebCore::ResourceResponse WebResponse::createResourceResponse()
+{
+ WebCore::ResourceResponse resourceResponse(url(), m_mime.c_str(), m_length, m_encoding.c_str(), "");
+ resourceResponse.setHTTPStatusCode(m_httpStatusCode);
+ resourceResponse.setHTTPStatusText(m_httpStatusText.c_str());
+
+ std::map<std::string, std::string>::const_iterator it;
+ for (it = m_headerFields.begin(); it != m_headerFields.end(); ++it)
+ resourceResponse.setHTTPHeaderField(it->first.c_str(), it->second.c_str());
+
+ return resourceResponse;
+}
+
+WebCore::KURL WebResponse::url()
+{
+ WebCore::KURL kurl(WebCore::ParsedURLString, m_url.c_str());
+ return kurl;
+}
+
+void WebResponse::setUrl(std::string url)
+{
+ m_url = url;
+}
+
+} // namespace android
diff --git a/WebKit/android/WebCoreSupport/WebResponse.h b/WebKit/android/WebCoreSupport/WebResponse.h
new file mode 100644
index 0000000..3112b2a
--- /dev/null
+++ b/WebKit/android/WebCoreSupport/WebResponse.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebResponse_h
+#define WebResponse_h
+
+#include "KURL.h"
+
+#include <map>
+#include <net/url_request/url_request.h>
+#include <string>
+
+namespace WebCore {
+class ResourceResponse;
+}
+
+namespace android {
+
+class WebResponse {
+
+public:
+ WebResponse() {}
+ WebResponse(URLRequest*);
+ WebResponse(const std::string &url, const std::string &mimeType, const long long length, const std::string &encoding, const int httpStatusCode);
+ WebCore::KURL url();
+ void setUrl(std::string);
+
+ // Only use on the WebCore thread!
+ WebCore::ResourceResponse createResourceResponse();
+
+private:
+ std::string m_encoding;
+ int m_httpStatusCode;
+ std::string m_httpStatusText;
+ long long m_length;
+ std::string m_mime;
+ std::string m_url;
+
+ std::map<std::string, std::string> m_headerFields;
+};
+
+} // namespace android
+
+#endif
diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp
index 4bb743b..2237ff6 100644
--- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp
+++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp
@@ -24,7 +24,6 @@
*/
#include "config.h"
-
#include "WebUrlLoaderClient.h"
#include "OwnPtr.h"
@@ -33,15 +32,15 @@
#include "ResourceResponse.h"
#include "WebRequest.h"
-#include "base/thread.h"
-#include "net/base/io_buffer.h"
+#include <base/thread.h>
+#include <net/base/io_buffer.h>
namespace android {
LoaderData::~LoaderData()
{
- if (m_buffer)
- m_buffer->Release();
+ if (buffer)
+ buffer->Release();
}
base::Thread* WebUrlLoaderClient::ioThread()
@@ -123,27 +122,28 @@ void WebUrlLoaderClient::finish()
void WebUrlLoaderClient::didReceiveResponse(void* data)
{
OwnPtr<LoaderData> loaderData(static_cast<LoaderData*>(data));
- const WebUrlLoaderClient* loader = loaderData->m_loader;
- ResourceResponse* resourceResponse = loaderData->m_resourceResponse.get();
+ const WebUrlLoaderClient* loader = loaderData->loader;
+ WebResponse webResponse = loaderData->webResponse;
if (!loader->isActive())
return;
- loader->m_resourceHandle->client()->didReceiveResponse(loader->m_resourceHandle.get(), *resourceResponse);
+ loader->m_resourceHandle->client()->didReceiveResponse(loader->m_resourceHandle.get(), webResponse.createResourceResponse());
}
// static - on main thread
void WebUrlLoaderClient::didReceiveData(void* data)
{
OwnPtr<LoaderData> loaderData(static_cast<LoaderData*>(data));
- const WebUrlLoaderClient* loader = loaderData->m_loader;
- net::IOBuffer* buf = loaderData->m_buffer;
+ const WebUrlLoaderClient* loader = loaderData->loader;
+ net::IOBuffer* buf = loaderData->buffer;
if (!loader->isActive())
return;
+ // didReceiveData will take a copy of the data
if (loader->m_resourceHandle && loader->m_resourceHandle->client())
- loader->m_resourceHandle->client()->didReceiveData(loader->m_resourceHandle.get(), buf->data(), loaderData->m_size, loaderData->m_size);
+ loader->m_resourceHandle->client()->didReceiveData(loader->m_resourceHandle.get(), buf->data(), loaderData->size, loaderData->size);
}
// static - on main thread
@@ -151,12 +151,13 @@ void WebUrlLoaderClient::didReceiveData(void* data)
void WebUrlLoaderClient::didReceiveDataUrl(void* data)
{
OwnPtr<LoaderData> ld(static_cast<LoaderData*>(data));
- const WebUrlLoaderClient* loader = ld->m_loader;
+ const WebUrlLoaderClient* loader = ld->loader;
if (!loader->isActive())
return;
- std::string* str = ld->m_string.get();
+ std::string* str = ld->string.get();
+ // didReceiveData will take a copy of the data
loader->m_resourceHandle->client()->didReceiveData(loader->m_resourceHandle.get(), str->data(), str->size(), str->size());
}
@@ -169,21 +170,21 @@ void WebUrlLoaderClient::didFail(void* data)
void WebUrlLoaderClient::willSendRequest(void* data)
{
OwnPtr<LoaderData> loaderData(static_cast<LoaderData*>(data));
- const WebUrlLoaderClient* loader = loaderData->m_loader;
+ const WebUrlLoaderClient* loader = loaderData->loader;
if (!loader->isActive())
return;
- WebCore::ResourceResponse* resourceResponse = loaderData->m_resourceResponse.get();
- OwnPtr<WebCore::ResourceRequest> resourceRequest(new WebCore::ResourceRequest(resourceResponse->url()));
- loader->m_resourceHandle->client()->willSendRequest(loader->m_resourceHandle.get(), *resourceRequest, *resourceResponse);
+ WebResponse webResponse = loaderData->webResponse;
+ OwnPtr<WebCore::ResourceRequest> resourceRequest(new WebCore::ResourceRequest(webResponse.url()));
+ loader->m_resourceHandle->client()->willSendRequest(loader->m_resourceHandle.get(), *resourceRequest, webResponse.createResourceResponse());
}
// static - on main thread
void WebUrlLoaderClient::didFinishLoading(void* data)
{
OwnPtr<LoaderData> loaderData(static_cast<LoaderData*>(data));
- WebUrlLoaderClient* loader = loaderData->m_loader;
+ WebUrlLoaderClient* loader = loaderData->loader;
if (loader->isActive())
loader->m_resourceHandle->client()->didFinishLoading(loader->m_resourceHandle.get());
diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h
index df463a4..084b6a0 100644
--- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h
+++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h
@@ -27,9 +27,10 @@
#define WebUrlLoaderClient_h
#include "RefCounted.h"
+#include "WebResponse.h"
#include "WebUrlLoader.h"
-#include "base/ref_counted.h"
+#include <base/ref_counted.h>
#include <string>
namespace base {
@@ -47,7 +48,6 @@ class WebRequest;
// This class handles communication between the IO thread where loading happens
// and the webkit main thread.
// TODO:
-// - Corner case where this gets deleted before UrlRequestAndroid
// - Implement didFail
// - Implement sync requests
// - Implement downloadFile
@@ -89,25 +89,25 @@ private:
// A struct to send more than one thing in a void*, needed for callOnMainThread
struct LoaderData {
- net::IOBuffer* m_buffer;
- WebUrlLoaderClient* m_loader;
- OwnPtr<WebCore::ResourceResponse*> m_resourceResponse;
- const int m_size;
- OwnPtr<std::string*> m_string;
+ net::IOBuffer* buffer;
+ WebUrlLoaderClient* loader;
+ WebResponse webResponse;
+ const int size;
+ OwnPtr<std::string*> string;
- LoaderData(WebUrlLoaderClient* l) : m_buffer(0), m_loader(l), m_resourceResponse(0), m_size(0), m_string(0)
+ LoaderData(WebUrlLoaderClient* l) : buffer(0), loader(l), size(0)
{
}
- LoaderData(WebUrlLoaderClient* l, std::string* s) : m_buffer(0), m_loader(l), m_resourceResponse(0), m_size(0), m_string(s)
+ LoaderData(WebUrlLoaderClient* l, std::string* s) : buffer(0), loader(l), size(0), string(s)
{
}
- LoaderData(WebUrlLoaderClient* l, WebCore::ResourceResponse* r) : m_buffer(0), m_loader(l), m_resourceResponse(r), m_size(0), m_string(0)
+ LoaderData(WebUrlLoaderClient* l, WebResponse r) : buffer(0), loader(l), webResponse(r), size(0)
{
}
- LoaderData(WebUrlLoaderClient* l, net::IOBuffer* b, const int s) : m_buffer(b), m_loader(l), m_resourceResponse(0), m_size(s), m_string(0)
+ LoaderData(WebUrlLoaderClient* l, net::IOBuffer* b, const int s) : buffer(b), loader(l), size(s)
{
}