summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--WebKit/Android.mk1
-rw-r--r--WebKit/android/WebCoreSupport/WebRequest.cpp96
-rw-r--r--WebKit/android/WebCoreSupport/WebRequest.h14
-rw-r--r--WebKit/android/WebCoreSupport/WebResourceRequest.cpp71
-rw-r--r--WebKit/android/WebCoreSupport/WebResourceRequest.h73
-rw-r--r--WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp39
6 files changed, 205 insertions, 89 deletions
diff --git a/WebKit/Android.mk b/WebKit/Android.mk
index 9edd064..032b71a 100644
--- a/WebKit/Android.mk
+++ b/WebKit/Android.mk
@@ -34,6 +34,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
android/WebCoreSupport/WebUrlLoaderClient.cpp \
android/WebCoreSupport/WebRequest.cpp \
android/WebCoreSupport/WebRequestContext.cpp \
+ android/WebCoreSupport/WebResourceRequest.cpp \
android/WebCoreSupport/WebResponse.cpp
else
LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp
index 33eee94..811cd3f 100644
--- a/WebKit/android/WebCoreSupport/WebRequest.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequest.cpp
@@ -27,14 +27,11 @@
#include "WebRequest.h"
#include "MainThread.h"
-#include "ResourceRequest.h"
#include "WebRequestContext.h"
-#include "text/CString.h"
+#include "WebResourceRequest.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>
@@ -52,9 +49,14 @@ namespace {
const int kInitialReadBufSize = 32768;
}
-WebRequest::WebRequest(WebUrlLoaderClient* loader, WebCore::ResourceRequest& resourceRequest)
- : m_urlLoader(loader), m_resourceRequest(resourceRequest), m_request(0)
+WebRequest::WebRequest(WebUrlLoaderClient* loader, WebResourceRequest webResourceRequest) : m_urlLoader(loader), m_request(0)
{
+ GURL gurl(webResourceRequest.url());
+ m_request = new URLRequest(gurl, this);
+
+ m_request->SetExtraRequestHeaders(webResourceRequest.requestHeaders());
+ m_request->set_referrer(webResourceRequest.referrer());
+ m_request->set_method(webResourceRequest.method());
}
WebRequest::~WebRequest()
@@ -69,89 +71,21 @@ void WebRequest::finish(bool /*success*/)
m_request = 0;
}
-void WebRequest::start()
+void WebRequest::AppendBytesToUpload(const char* bytes, int bytesLen)
{
- GURL gurl(m_resourceRequest.url().string().utf8().data());
+ m_request->AppendBytesToUpload(bytes, bytesLen);
+}
+void WebRequest::start()
+{
// Handle data urls before we send it off to the http stack
- if (gurl.SchemeIs("data"))
- return handleDataURL(gurl);
-
- m_request = new URLRequest(gurl, this);
-
- // Have to set uploads before start is called on the request
- 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);
+ if (m_request->url().SchemeIs("data"))
+ return handleDataURL(m_request->url());
- m_request->set_referrer(m_resourceRequest.httpReferrer().utf8().data());
- m_request->set_method(m_resourceRequest.httpMethod().utf8().data());
m_request->set_context(WebRequestContext::GetAndroidContext());
-
m_request->Start();
}
-void WebRequest::setUploadData(URLRequest* request)
-{
- const std::string& method = m_resourceRequest.httpMethod().utf8().data();
- if (method == "GET" || method == "HEAD")
- return;
-
- Vector<FormDataElement>::iterator iter;
- Vector<FormDataElement> elements = m_resourceRequest.httpBody()->elements();
- for (iter = elements.begin(); iter != elements.end(); iter++) {
- FormDataElement element = *iter;
- switch (element.m_type) {
- case FormDataElement::data:
- if (!element.m_data.isEmpty()) {
- // WebKit sometimes gives up empty data to append. These aren't
- // necessary so we just optimize those out here.
- int size = static_cast<int>(element.m_data.size());
- request->AppendBytesToUpload(element.m_data.data(), size);
- }
- break;
- case FormDataElement::encodedFile:
- if (element.m_fileLength == -1)
- continue; // TODO: Not supporting directories yet
- else {
- // TODO: Add fileuploads after Google log-in is fixed.
- // Chrome code is here: webkit/glue/weburlloader_impl.cc:391
- }
- break;
- // default:
- // TODO: should add the default back in with a warning
- }
- }
-}
-
void WebRequest::cancel()
{
if (m_request)
diff --git a/WebKit/android/WebCoreSupport/WebRequest.h b/WebKit/android/WebCoreSupport/WebRequest.h
index b106b46..2bd86d8 100644
--- a/WebKit/android/WebCoreSupport/WebRequest.h
+++ b/WebKit/android/WebCoreSupport/WebRequest.h
@@ -33,16 +33,18 @@
class MessageLoop;
-namespace WebCore {
-class ResourceRequest;
-}
-
namespace android {
+class WebResourceRequest;
+
// All methods in this class must be called on the io thread
class WebRequest : public URLRequest::Delegate, public base::RefCountedThreadSafe<WebRequest> {
public:
- WebRequest(WebUrlLoaderClient*, WebCore::ResourceRequest&);
+ WebRequest(WebUrlLoaderClient*, WebResourceRequest);
+
+ // Optional, but if used has to be called before start
+ void AppendBytesToUpload(const char* bytes, int bytesLen);
+
void start();
void cancel();
@@ -59,13 +61,11 @@ private:
friend class base::RefCountedThreadSafe<WebRequest>;
virtual ~WebRequest();
void handleDataURL(GURL);
- void setUploadData(URLRequest*);
void finish(bool success);
// Not owned
WebUrlLoaderClient* m_urlLoader;
- WebCore::ResourceRequest m_resourceRequest;
OwnPtr<URLRequest> m_request;
scoped_refptr<net::IOBuffer> m_networkBuffer;
};
diff --git a/WebKit/android/WebCoreSupport/WebResourceRequest.cpp b/WebKit/android/WebCoreSupport/WebResourceRequest.cpp
new file mode 100644
index 0000000..6248217
--- /dev/null
+++ b/WebKit/android/WebCoreSupport/WebResourceRequest.cpp
@@ -0,0 +1,71 @@
+/*
+ * 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 "WebResourceRequest.h"
+
+#include "ResourceRequest.h"
+
+#include <base/string_util.h>
+#include <wtf/text/CString.h>
+
+namespace android {
+
+WebResourceRequest::WebResourceRequest(WebCore::ResourceRequest& resourceRequest)
+{
+ // Set the request headers
+ net::HttpRequestHeaders requestHeaders;
+ const WebCore::HTTPHeaderMap& map = resourceRequest.httpHeaderFields();
+ for (WebCore::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_method = resourceRequest.httpMethod().utf8().data();
+ m_referrer = resourceRequest.httpReferrer().utf8().data();
+ m_url = resourceRequest.url().string().utf8().data();
+}
+
+} // namespace android
diff --git a/WebKit/android/WebCoreSupport/WebResourceRequest.h b/WebKit/android/WebCoreSupport/WebResourceRequest.h
new file mode 100644
index 0000000..4ed9a44
--- /dev/null
+++ b/WebKit/android/WebCoreSupport/WebResourceRequest.h
@@ -0,0 +1,73 @@
+/*
+ * 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 WebResourceRequest_h
+#define WebResourceRequest_h
+
+#include <net/http/http_request_headers.h>
+#include <string>
+
+namespace WebCore {
+class ResourceRequest;
+}
+
+namespace android {
+
+class WebResourceRequest {
+
+public:
+ WebResourceRequest(WebCore::ResourceRequest&);
+
+ const std::string& method()
+ {
+ return m_method;
+ }
+
+ const std::string& referrer()
+ {
+ return m_referrer;
+ }
+
+ const net::HttpRequestHeaders& requestHeaders()
+ {
+ return m_requestHeaders;
+ }
+
+ const std::string& url()
+ {
+ return m_url;
+ }
+
+private:
+ std::string m_method;
+ std::string m_referrer;
+ net::HttpRequestHeaders m_requestHeaders;
+ std::string m_url;
+};
+
+} // namespace android
+
+
+#endif
diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp
index 2237ff6..3785a1d 100644
--- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp
+++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp
@@ -31,6 +31,7 @@
#include "ResourceHandleClient.h"
#include "ResourceResponse.h"
#include "WebRequest.h"
+#include "WebResourceRequest.h"
#include <base/thread.h>
#include <net/base/io_buffer.h>
@@ -86,8 +87,44 @@ bool WebUrlLoaderClient::isActive() const
WebUrlLoaderClient::WebUrlLoaderClient(WebCore::ResourceHandle* resourceHandle, const WebCore::ResourceRequest& resourceRequest)
: m_resourceHandle(resourceHandle), m_resourceRequest(resourceRequest), m_cancelling(false)
{
- m_request = new WebRequest(this, m_resourceRequest);
+ WebResourceRequest webResourceRequest(m_resourceRequest);
+
+ m_request = new WebRequest(this, webResourceRequest);
m_request->AddRef(); // Matched by ReleaseSoon in destructor
+ base::Thread* thread = ioThread();
+
+ // Set uploads before start is called on the request
+ if (m_resourceRequest.httpBody() && !(webResourceRequest.method() == "GET" || webResourceRequest.method() == "HEAD")) {
+ Vector<FormDataElement>::iterator iter;
+ Vector<FormDataElement> elements = m_resourceRequest.httpBody()->elements();
+ for (iter = elements.begin(); iter != elements.end(); iter++) {
+ FormDataElement element = *iter;
+ switch (element.m_type) {
+ case FormDataElement::data:
+ if (!element.m_data.isEmpty()) {
+ // WebKit sometimes gives up empty data to append. These aren't
+ // necessary so we just optimize those out here.
+ int size = static_cast<int>(element.m_data.size());
+ // TODO: do we have to make a copy of this data?
+ base::Thread* thread = ioThread();
+ if (thread)
+ thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request, &WebRequest::AppendBytesToUpload, element.m_data.data(), size));
+ }
+ break;
+ case FormDataElement::encodedFile:
+ if (element.m_fileLength == -1)
+ continue; // TODO: Not supporting directories yet
+ else {
+ // TODO: Add fileuploads after Google log-in is fixed.
+ // Chrome code is here: webkit/glue/weburlloader_impl.cc:391
+ }
+ break;
+ default:
+ // TODO: Add a warning/DCHECK/assert here, should never happen
+ break;
+ }
+ }
+ }
}
bool WebUrlLoaderClient::start(bool /*sync*/)