|
1 /* |
|
2 * Copyright (C) 2009 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
8 * * Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * * Redistributions in binary form must reproduce the above |
|
11 * copyright notice, this list of conditions and the following disclaimer |
|
12 * in the documentation and/or other materials provided with the |
|
13 * distribution. |
|
14 * * Neither the name of Google Inc. nor the names of its |
|
15 * contributors may be used to endorse or promote products derived from |
|
16 * this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 #include "config.h" |
|
32 #include "WebURLRequest.h" |
|
33 |
|
34 #include "ResourceRequest.h" |
|
35 |
|
36 #include "WebHTTPBody.h" |
|
37 #include "WebHTTPHeaderVisitor.h" |
|
38 #include "WebURL.h" |
|
39 #include "WebURLRequestPrivate.h" |
|
40 |
|
41 using namespace WebCore; |
|
42 |
|
43 namespace WebKit { |
|
44 |
|
45 // The standard implementation of WebURLRequestPrivate, which maintains |
|
46 // ownership of a ResourceRequest instance. |
|
47 class WebURLRequestPrivateImpl : public WebURLRequestPrivate { |
|
48 public: |
|
49 WebURLRequestPrivateImpl() |
|
50 { |
|
51 m_resourceRequest = &m_resourceRequestAllocation; |
|
52 } |
|
53 |
|
54 WebURLRequestPrivateImpl(const WebURLRequestPrivate* p) |
|
55 : m_resourceRequestAllocation(*p->m_resourceRequest) |
|
56 { |
|
57 m_resourceRequest = &m_resourceRequestAllocation; |
|
58 } |
|
59 |
|
60 virtual void dispose() { delete this; } |
|
61 |
|
62 ResourceRequest m_resourceRequestAllocation; |
|
63 }; |
|
64 |
|
65 void WebURLRequest::initialize() |
|
66 { |
|
67 assign(new WebURLRequestPrivateImpl()); |
|
68 } |
|
69 |
|
70 void WebURLRequest::reset() |
|
71 { |
|
72 assign(0); |
|
73 } |
|
74 |
|
75 void WebURLRequest::assign(const WebURLRequest& r) |
|
76 { |
|
77 if (&r != this) |
|
78 assign(r.m_private ? new WebURLRequestPrivateImpl(r.m_private) : 0); |
|
79 } |
|
80 |
|
81 bool WebURLRequest::isNull() const |
|
82 { |
|
83 return !m_private || m_private->m_resourceRequest->isNull(); |
|
84 } |
|
85 |
|
86 WebURL WebURLRequest::url() const |
|
87 { |
|
88 return m_private->m_resourceRequest->url(); |
|
89 } |
|
90 |
|
91 void WebURLRequest::setURL(const WebURL& url) |
|
92 { |
|
93 m_private->m_resourceRequest->setURL(url); |
|
94 } |
|
95 |
|
96 WebURL WebURLRequest::firstPartyForCookies() const |
|
97 { |
|
98 return m_private->m_resourceRequest->firstPartyForCookies(); |
|
99 } |
|
100 |
|
101 void WebURLRequest::setFirstPartyForCookies(const WebURL& firstPartyForCookies) |
|
102 { |
|
103 m_private->m_resourceRequest->setFirstPartyForCookies(firstPartyForCookies); |
|
104 } |
|
105 |
|
106 bool WebURLRequest::allowCookies() const |
|
107 { |
|
108 return m_private->m_resourceRequest->allowCookies(); |
|
109 } |
|
110 |
|
111 void WebURLRequest::setAllowCookies(bool allowCookies) |
|
112 { |
|
113 m_private->m_resourceRequest->setAllowCookies(allowCookies); |
|
114 } |
|
115 |
|
116 bool WebURLRequest::allowStoredCredentials() const |
|
117 { |
|
118 return m_private->m_allowStoredCredentials; |
|
119 } |
|
120 |
|
121 void WebURLRequest::setAllowStoredCredentials(bool allowStoredCredentials) |
|
122 { |
|
123 m_private->m_allowStoredCredentials = allowStoredCredentials; |
|
124 } |
|
125 |
|
126 WebURLRequest::CachePolicy WebURLRequest::cachePolicy() const |
|
127 { |
|
128 return static_cast<WebURLRequest::CachePolicy>( |
|
129 m_private->m_resourceRequest->cachePolicy()); |
|
130 } |
|
131 |
|
132 void WebURLRequest::setCachePolicy(CachePolicy cachePolicy) |
|
133 { |
|
134 m_private->m_resourceRequest->setCachePolicy( |
|
135 static_cast<ResourceRequestCachePolicy>(cachePolicy)); |
|
136 } |
|
137 |
|
138 WebString WebURLRequest::httpMethod() const |
|
139 { |
|
140 return m_private->m_resourceRequest->httpMethod(); |
|
141 } |
|
142 |
|
143 void WebURLRequest::setHTTPMethod(const WebString& httpMethod) |
|
144 { |
|
145 m_private->m_resourceRequest->setHTTPMethod(httpMethod); |
|
146 } |
|
147 |
|
148 WebString WebURLRequest::httpHeaderField(const WebString& name) const |
|
149 { |
|
150 return m_private->m_resourceRequest->httpHeaderField(name); |
|
151 } |
|
152 |
|
153 void WebURLRequest::setHTTPHeaderField(const WebString& name, const WebString& value) |
|
154 { |
|
155 m_private->m_resourceRequest->setHTTPHeaderField(name, value); |
|
156 } |
|
157 |
|
158 void WebURLRequest::addHTTPHeaderField(const WebString& name, const WebString& value) |
|
159 { |
|
160 m_private->m_resourceRequest->addHTTPHeaderField(name, value); |
|
161 } |
|
162 |
|
163 void WebURLRequest::clearHTTPHeaderField(const WebString& name) |
|
164 { |
|
165 // FIXME: Add a clearHTTPHeaderField method to ResourceRequest. |
|
166 const HTTPHeaderMap& map = m_private->m_resourceRequest->httpHeaderFields(); |
|
167 const_cast<HTTPHeaderMap*>(&map)->remove(name); |
|
168 } |
|
169 |
|
170 void WebURLRequest::visitHTTPHeaderFields(WebHTTPHeaderVisitor* visitor) const |
|
171 { |
|
172 const HTTPHeaderMap& map = m_private->m_resourceRequest->httpHeaderFields(); |
|
173 for (HTTPHeaderMap::const_iterator it = map.begin(); it != map.end(); ++it) |
|
174 visitor->visitHeader(it->first, it->second); |
|
175 } |
|
176 |
|
177 WebHTTPBody WebURLRequest::httpBody() const |
|
178 { |
|
179 return WebHTTPBody(m_private->m_resourceRequest->httpBody()); |
|
180 } |
|
181 |
|
182 void WebURLRequest::setHTTPBody(const WebHTTPBody& httpBody) |
|
183 { |
|
184 m_private->m_resourceRequest->setHTTPBody(httpBody); |
|
185 } |
|
186 |
|
187 bool WebURLRequest::reportUploadProgress() const |
|
188 { |
|
189 return m_private->m_resourceRequest->reportUploadProgress(); |
|
190 } |
|
191 |
|
192 void WebURLRequest::setReportUploadProgress(bool reportUploadProgress) |
|
193 { |
|
194 m_private->m_resourceRequest->setReportUploadProgress(reportUploadProgress); |
|
195 } |
|
196 |
|
197 bool WebURLRequest::reportLoadTiming() const |
|
198 { |
|
199 return m_private->m_resourceRequest->reportLoadTiming(); |
|
200 } |
|
201 |
|
202 void WebURLRequest::setReportLoadTiming(bool reportLoadTiming) |
|
203 { |
|
204 m_private->m_resourceRequest->setReportLoadTiming(reportLoadTiming); |
|
205 } |
|
206 |
|
207 WebURLRequest::TargetType WebURLRequest::targetType() const |
|
208 { |
|
209 return static_cast<TargetType>(m_private->m_resourceRequest->targetType()); |
|
210 } |
|
211 |
|
212 void WebURLRequest::setTargetType(TargetType targetType) |
|
213 { |
|
214 m_private->m_resourceRequest->setTargetType( |
|
215 static_cast<ResourceRequest::TargetType>(targetType)); |
|
216 } |
|
217 |
|
218 int WebURLRequest::requestorID() const |
|
219 { |
|
220 return m_private->m_resourceRequest->requestorID(); |
|
221 } |
|
222 |
|
223 void WebURLRequest::setRequestorID(int requestorID) |
|
224 { |
|
225 m_private->m_resourceRequest->setRequestorID(requestorID); |
|
226 } |
|
227 |
|
228 int WebURLRequest::requestorProcessID() const |
|
229 { |
|
230 return m_private->m_resourceRequest->requestorProcessID(); |
|
231 } |
|
232 |
|
233 void WebURLRequest::setRequestorProcessID(int requestorProcessID) |
|
234 { |
|
235 m_private->m_resourceRequest->setRequestorProcessID(requestorProcessID); |
|
236 } |
|
237 |
|
238 int WebURLRequest::appCacheHostID() const |
|
239 { |
|
240 return m_private->m_resourceRequest->appCacheHostID(); |
|
241 } |
|
242 |
|
243 void WebURLRequest::setAppCacheHostID(int appCacheHostID) |
|
244 { |
|
245 m_private->m_resourceRequest->setAppCacheHostID(appCacheHostID); |
|
246 } |
|
247 |
|
248 bool WebURLRequest::downloadToFile() const |
|
249 { |
|
250 return m_private->m_downloadToFile; |
|
251 } |
|
252 |
|
253 void WebURLRequest::setDownloadToFile(bool downloadToFile) |
|
254 { |
|
255 m_private->m_downloadToFile = downloadToFile; |
|
256 } |
|
257 |
|
258 ResourceRequest& WebURLRequest::toMutableResourceRequest() |
|
259 { |
|
260 ASSERT(m_private); |
|
261 ASSERT(m_private->m_resourceRequest); |
|
262 |
|
263 return *m_private->m_resourceRequest; |
|
264 } |
|
265 |
|
266 const ResourceRequest& WebURLRequest::toResourceRequest() const |
|
267 { |
|
268 ASSERT(m_private); |
|
269 ASSERT(m_private->m_resourceRequest); |
|
270 |
|
271 return *m_private->m_resourceRequest; |
|
272 } |
|
273 |
|
274 void WebURLRequest::assign(WebURLRequestPrivate* p) |
|
275 { |
|
276 // Subclasses may call this directly so a self-assignment check is needed |
|
277 // here as well as in the public assign method. |
|
278 if (m_private == p) |
|
279 return; |
|
280 if (m_private) |
|
281 m_private->dispose(); |
|
282 m_private = p; |
|
283 } |
|
284 |
|
285 } // namespace WebKit |