summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 00:00:40 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 00:00:40 +0000
commit7941d41c1fcf138da497b58ee83d7c260fbce88b (patch)
tree82df4550c20093a1d6af4c9608d85750aca06259 /webkit
parent1e0f70402b410a9e274e8d23eeab236b43810a00 (diff)
downloadchromium_src-7941d41c1fcf138da497b58ee83d7c260fbce88b.zip
chromium_src-7941d41c1fcf138da497b58ee83d7c260fbce88b.tar.gz
chromium_src-7941d41c1fcf138da497b58ee83d7c260fbce88b.tar.bz2
Currently, there is no way to access or modify the upload data and/or complete
list of request headers associated with a WebRequest object. The intent is to access this information from WebViewDelegate::DispositionForNavigationAction(). Remove the HasFormData() method that checked for upload (form) data on the history item. The HasFormData() method is not currently being called from anywhere, so changes elsewhere are not required. Add HasUploadData(), GetUploadData() and SetUploadData() methods to test, get and set the underlying request upload data as a net::UploadData object. Add GetHttpHeaders() and SetHttpHeaders() methods to get and set all request headers using a map of values. Add the SetHttpHeaderValue() method to set the value for a particular request header. Patch by Marshall Greenblatt R=darin git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3497 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/weburlrequest.h31
-rw-r--r--webkit/glue/weburlrequest_impl.cc92
-rw-r--r--webkit/glue/weburlrequest_impl.h8
3 files changed, 125 insertions, 6 deletions
diff --git a/webkit/glue/weburlrequest.h b/webkit/glue/weburlrequest.h
index 9283376..5903bc2 100644
--- a/webkit/glue/weburlrequest.h
+++ b/webkit/glue/weburlrequest.h
@@ -5,6 +5,7 @@
#ifndef WEBKIT_GLUE_WEBURLREQUEST_H__
#define WEBKIT_GLUE_WEBURLREQUEST_H__
+#include <map>
#include <string>
#include "base/basictypes.h"
@@ -17,10 +18,16 @@ enum WebRequestCachePolicy {
WebRequestReturnCacheDataDontLoad
};
+namespace net {
+class UploadData;
+}
+
class GURL;
class WebRequest {
public:
+ typedef std::map<std::string, std::string> HeaderMap;
+
// Extra information that is associated with a request. The embedder derives
// from this REFERENCE COUNTED class to associated data with a request and
// get it back when the page loads.
@@ -71,6 +78,19 @@ class WebRequest {
// given header was not set in the request, the empty string is returned.
virtual std::wstring GetHttpHeaderValue(const std::wstring& field) const = 0;
+ // Set a value for a header in the request.
+ virtual void SetHttpHeaderValue(const std::wstring& field,
+ const std::wstring& value) = 0;
+
+ // Fills a map with all header name/value pairs set in the request.
+ virtual void GetHttpHeaders(HeaderMap* headers) const = 0;
+
+ // Sets the header name/value pairs for the request from a map. Values set
+ // using this method replace any pre-existing values with the same name.
+ // Passing in a blank value will result in a header with a blank value being
+ // sent as part of the request.
+ virtual void SetHttpHeaders(const HeaderMap& headers) = 0;
+
// Helper function for GetHeaderValue to retrieve the referrer. This
// referrer is generated automatically by WebKit when navigation events
// occur. If there was no referrer (for example, the browser instructed
@@ -94,8 +114,15 @@ class WebRequest {
virtual std::string GetSecurityInfo() const = 0;
virtual void SetSecurityInfo(const std::string& info) = 0;
- // Returns true if this request contains history state that has form data.
- virtual bool HasFormData() const = 0;
+ // Returns true if the request has upload data.
+ virtual bool HasUploadData() const = 0;
+
+ // Returns the request upload data. This object is temporary and should be
+ // deleted after use.
+ virtual void GetUploadData(net::UploadData* data) const = 0;
+
+ // Set the request upload data.
+ virtual void SetUploadData(const net::UploadData& data) = 0;
virtual ~WebRequest() { }
};
diff --git a/webkit/glue/weburlrequest_impl.cc b/webkit/glue/weburlrequest_impl.cc
index f39e13f..37aab8e 100644
--- a/webkit/glue/weburlrequest_impl.cc
+++ b/webkit/glue/weburlrequest_impl.cc
@@ -3,12 +3,21 @@
// found in the LICENSE file.
#include "config.h"
+
+#pragma warning(push, 0)
+#include "FormData.h"
+#include "HTTPHeaderMap.h"
+#include "ResourceRequest.h"
+#pragma warning(pop)
+
+#undef LOG
+#include "base/logging.h"
+#include "net/base/upload_data.h"
#include "webkit/glue/weburlrequest_impl.h"
#include "webkit/glue/glue_serialize.h"
#include "webkit/glue/glue_util.h"
using WebCore::FrameLoadRequest;
-using WebCore::ResourceRequest;
using WebCore::ResourceRequestCachePolicy;
using WebCore::String;
@@ -85,6 +94,40 @@ std::wstring WebRequestImpl::GetHttpHeaderValue(const std::wstring& field) const
webkit_glue::StdWStringToString(field)));
}
+void WebRequestImpl::SetHttpHeaderValue(const std::wstring& field,
+ const std::wstring& value) {
+ request_.resourceRequest().setHTTPHeaderField(
+ webkit_glue::StdWStringToString(field),
+ webkit_glue::StdWStringToString(value));
+}
+
+void WebRequestImpl::GetHttpHeaders(HeaderMap* headers) const {
+ headers->clear();
+
+ const WebCore::HTTPHeaderMap& map =
+ request_.resourceRequest().httpHeaderFields();
+ WebCore::HTTPHeaderMap::const_iterator end = map.end();
+ WebCore::HTTPHeaderMap::const_iterator it = map.begin();
+ for (; it != end; ++it) {
+ headers->insert(
+ std::make_pair(
+ webkit_glue::StringToStdString(it->first),
+ webkit_glue::StringToStdString(it->second)));
+ }
+}
+
+void WebRequestImpl::SetHttpHeaders(const HeaderMap& headers) {
+ WebCore::ResourceRequest& request = request_.resourceRequest();
+
+ HeaderMap::const_iterator end = headers.end();
+ HeaderMap::const_iterator it = headers.begin();
+ for (; it != end; ++it) {
+ request.setHTTPHeaderField(
+ webkit_glue::StdStringToString(it->first),
+ webkit_glue::StdStringToString(it->second));
+ }
+}
+
std::wstring WebRequestImpl::GetHttpReferrer() const {
return webkit_glue::StringToStdWString(
request_.resourceRequest().httpReferrer());
@@ -110,8 +153,51 @@ void WebRequestImpl::SetSecurityInfo(const std::string& value) {
webkit_glue::StdStringToCString(value));
}
-bool WebRequestImpl::HasFormData() const {
- return history_item() && history_item()->formData();
+bool WebRequestImpl::HasUploadData() const {
+ WebCore::FormData* formdata = request_.resourceRequest().httpBody();
+ return formdata && !formdata->isEmpty();
+}
+
+void WebRequestImpl::GetUploadData(net::UploadData* data) const {
+ WebCore::FormData* formdata = request_.resourceRequest().httpBody();
+ if (!formdata)
+ return;
+
+ const Vector<WebCore::FormDataElement>& elements = formdata->elements();
+ Vector<WebCore::FormDataElement>::const_iterator it = elements.begin();
+ for (; it != elements.end(); ++it) {
+ const WebCore::FormDataElement& element = (*it);
+ if (element.m_type == WebCore::FormDataElement::data) {
+ data->AppendBytes(element.m_data.data(), element.m_data.size());
+ } else if (element.m_type == WebCore::FormDataElement::encodedFile) {
+ data->AppendFile(webkit_glue::StringToStdWString(element.m_filename));
+ } else {
+ NOTREACHED();
+ }
+ }
+}
+
+void WebRequestImpl::SetUploadData(const net::UploadData& data)
+{
+ RefPtr<WebCore::FormData> formdata = WebCore::FormData::create();
+
+ const std::vector<net::UploadData::Element>& elements = data.elements();
+ std::vector<net::UploadData::Element>::const_iterator it = elements.begin();
+ for (UINT i = 0; it != elements.end(); ++it, ++i) {
+ const net::UploadData::Element& element = (*it);
+ if (element.type() == net::UploadData::TYPE_BYTES) {
+ formdata->appendData(
+ std::string(element.bytes().begin(), element.bytes().end()).c_str(),
+ element.bytes().size());
+ } else if (element.type() == net::UploadData::TYPE_FILE) {
+ formdata->appendFile(
+ webkit_glue::StdWStringToString(element.file_path()));
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ request_.resourceRequest().setHTTPBody(formdata);
}
// static
diff --git a/webkit/glue/weburlrequest_impl.h b/webkit/glue/weburlrequest_impl.h
index 8b33385..c7fd5ef 100644
--- a/webkit/glue/weburlrequest_impl.h
+++ b/webkit/glue/weburlrequest_impl.h
@@ -35,12 +35,18 @@ class WebRequestImpl : public WebRequest {
virtual std::wstring GetHttpMethod() const;
virtual void SetHttpMethod(const std::wstring& method);
virtual std::wstring GetHttpHeaderValue(const std::wstring& field) const;
+ virtual void SetHttpHeaderValue(const std::wstring& field,
+ const std::wstring& value);
+ virtual void GetHttpHeaders(HeaderMap* headers) const;
+ virtual void SetHttpHeaders(const HeaderMap& headers);
virtual std::wstring GetHttpReferrer() const;
virtual std::string GetHistoryState() const;
virtual void SetHistoryState(const std::string& value);
virtual std::string GetSecurityInfo() const;
virtual void SetSecurityInfo(const std::string& value);
- virtual bool HasFormData() const;
+ virtual bool HasUploadData() const;
+ virtual void GetUploadData(net::UploadData* data) const;
+ virtual void SetUploadData(const net::UploadData& data);
// WebRequestImpl
const WebCore::FrameLoadRequest& frame_load_request() const {