blob: b4416f90f16be76f26ee7903f7304561444220cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "base/compiler_specific.h"
MSVC_PUSH_WARNING_LEVEL(0);
#include "FormData.h"
#include "HTTPHeaderMap.h"
#include "ResourceRequest.h"
MSVC_POP_WARNING();
#undef LOG
#include "base/logging.h"
#include "googleurl/src/gurl.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::ResourceRequestCachePolicy;
using WebCore::String;
// WebRequest -----------------------------------------------------------------
WebRequestImpl::WebRequestImpl() {
}
WebRequestImpl::WebRequestImpl(const GURL& url)
: request_(FrameLoadRequest(webkit_glue::GURLToKURL(url))) {
}
WebRequestImpl::WebRequestImpl(const WebCore::ResourceRequest& request)
: request_(FrameLoadRequest(request)) {
}
WebRequestImpl::WebRequestImpl(const WebCore::FrameLoadRequest& request)
: request_(request) {
}
WebRequest* WebRequestImpl::Clone() const {
return new WebRequestImpl(*this);
}
void WebRequestImpl::SetExtraData(ExtraData* extra) {
extra_data_ = extra;
}
WebRequest::ExtraData* WebRequestImpl::GetExtraData() const {
return extra_data_.get();
}
GURL WebRequestImpl::GetURL() const {
return webkit_glue::KURLToGURL(request_.resourceRequest().url());
}
void WebRequestImpl::SetURL(const GURL& url) {
request_.resourceRequest().setURL(webkit_glue::GURLToKURL(url));
}
GURL WebRequestImpl::GetMainDocumentURL() const {
return webkit_glue::KURLToGURL(request_.resourceRequest().mainDocumentURL());
}
void WebRequestImpl::SetMainDocumentURL(const GURL& url) {
request_.resourceRequest().setMainDocumentURL(webkit_glue::GURLToKURL(url));
}
WebRequestCachePolicy WebRequestImpl::GetCachePolicy() const {
// WebRequestCachePolicy mirrors ResourceRequestCachePolicy
return static_cast<WebRequestCachePolicy>(
request_.resourceRequest().cachePolicy());
}
void WebRequestImpl::SetCachePolicy(WebRequestCachePolicy policy) {
// WebRequestCachePolicy mirrors ResourceRequestCachePolicy
request_.resourceRequest().setCachePolicy(
static_cast<WebCore::ResourceRequestCachePolicy>(policy));
}
std::string WebRequestImpl::GetHttpMethod() const {
return webkit_glue::StringToStdString(
request_.resourceRequest().httpMethod());
}
void WebRequestImpl::SetHttpMethod(const std::string& method) {
request_.resourceRequest().setHTTPMethod(
webkit_glue::StdStringToString(method));
}
std::string WebRequestImpl::GetHttpHeaderValue(const std::string& field) const {
return webkit_glue::StringToStdString(
request_.resourceRequest().httpHeaderField(
webkit_glue::StdStringToString(field)));
}
void WebRequestImpl::SetHttpHeaderValue(const std::string& field,
const std::string& value) {
request_.resourceRequest().setHTTPHeaderField(
webkit_glue::StdStringToString(field),
webkit_glue::StdStringToString(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::string WebRequestImpl::GetHttpReferrer() const {
return webkit_glue::StringToStdString(
request_.resourceRequest().httpReferrer());
}
std::string WebRequestImpl::GetHistoryState() const {
std::string value;
webkit_glue::HistoryItemToString(history_item_, &value);
return value;
}
void WebRequestImpl::SetHistoryState(const std::string& value) {
history_item_ = webkit_glue::HistoryItemFromString(value);
}
std::string WebRequestImpl::GetSecurityInfo() const {
return webkit_glue::CStringToStdString(
request_.resourceRequest().securityInfo());
}
void WebRequestImpl::SetSecurityInfo(const std::string& value) {
request_.resourceRequest().setSecurityInfo(
webkit_glue::StdStringToCString(value));
}
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 (; it != elements.end(); ++it) {
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
WebRequest* WebRequest::Create(const GURL& url) {
return new WebRequestImpl(url);
}
|