2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "public/platform/WebURLRequest.h"
34 #include "platform/exported/WebURLRequestPrivate.h"
35 #include "platform/network/ResourceRequest.h"
36 #include "public/platform/WebHTTPBody.h"
37 #include "public/platform/WebHTTPHeaderVisitor.h"
38 #include "public/platform/WebSecurityOrigin.h"
39 #include "public/platform/WebURL.h"
45 class ExtraDataContainer
: public ResourceRequest::ExtraData
{
47 static PassRefPtr
<ExtraDataContainer
> create(WebURLRequest::ExtraData
* extraData
) { return adoptRef(new ExtraDataContainer(extraData
)); }
49 ~ExtraDataContainer() override
{}
51 WebURLRequest::ExtraData
* extraData() const { return m_extraData
.get(); }
54 explicit ExtraDataContainer(WebURLRequest::ExtraData
* extraData
)
55 : m_extraData(adoptPtr(extraData
))
59 OwnPtr
<WebURLRequest::ExtraData
> m_extraData
;
64 // The standard implementation of WebURLRequestPrivate, which maintains
65 // ownership of a ResourceRequest instance.
66 class WebURLRequestPrivateImpl
: public WebURLRequestPrivate
{
68 WebURLRequestPrivateImpl()
70 m_resourceRequest
= &m_resourceRequestAllocation
;
73 WebURLRequestPrivateImpl(const WebURLRequestPrivate
* p
)
74 : m_resourceRequestAllocation(*p
->m_resourceRequest
)
76 m_resourceRequest
= &m_resourceRequestAllocation
;
79 virtual void dispose() { delete this; }
82 virtual ~WebURLRequestPrivateImpl() { }
84 ResourceRequest m_resourceRequestAllocation
;
87 void WebURLRequest::initialize()
89 assign(new WebURLRequestPrivateImpl());
92 void WebURLRequest::reset()
97 void WebURLRequest::assign(const WebURLRequest
& r
)
100 assign(r
.m_private
? new WebURLRequestPrivateImpl(r
.m_private
) : 0);
103 bool WebURLRequest::isNull() const
105 return !m_private
|| m_private
->m_resourceRequest
->isNull();
108 WebURL
WebURLRequest::url() const
110 return m_private
->m_resourceRequest
->url();
113 void WebURLRequest::setURL(const WebURL
& url
)
115 m_private
->m_resourceRequest
->setURL(url
);
118 WebURL
WebURLRequest::firstPartyForCookies() const
120 return m_private
->m_resourceRequest
->firstPartyForCookies();
123 void WebURLRequest::setFirstPartyForCookies(const WebURL
& firstPartyForCookies
)
125 m_private
->m_resourceRequest
->setFirstPartyForCookies(firstPartyForCookies
);
128 WebSecurityOrigin
WebURLRequest::requestorOrigin() const
130 return m_private
->m_resourceRequest
->requestorOrigin();
133 void WebURLRequest::setRequestorOrigin(const WebSecurityOrigin
& requestorOrigin
)
135 m_private
->m_resourceRequest
->setRequestorOrigin(requestorOrigin
);
138 bool WebURLRequest::allowStoredCredentials() const
140 return m_private
->m_resourceRequest
->allowStoredCredentials();
143 void WebURLRequest::setAllowStoredCredentials(bool allowStoredCredentials
)
145 m_private
->m_resourceRequest
->setAllowStoredCredentials(allowStoredCredentials
);
148 WebURLRequest::CachePolicy
WebURLRequest::cachePolicy() const
150 return static_cast<WebURLRequest::CachePolicy
>(
151 m_private
->m_resourceRequest
->cachePolicy());
154 void WebURLRequest::setCachePolicy(CachePolicy cachePolicy
)
156 m_private
->m_resourceRequest
->setCachePolicy(
157 static_cast<ResourceRequestCachePolicy
>(cachePolicy
));
160 WebString
WebURLRequest::httpMethod() const
162 return m_private
->m_resourceRequest
->httpMethod();
165 void WebURLRequest::setHTTPMethod(const WebString
& httpMethod
)
167 m_private
->m_resourceRequest
->setHTTPMethod(httpMethod
);
170 WebString
WebURLRequest::httpHeaderField(const WebString
& name
) const
172 return m_private
->m_resourceRequest
->httpHeaderField(name
);
175 void WebURLRequest::setHTTPHeaderField(const WebString
& name
, const WebString
& value
)
177 RELEASE_ASSERT(!equalIgnoringCase(name
, "referer"));
178 m_private
->m_resourceRequest
->setHTTPHeaderField(name
, value
);
181 void WebURLRequest::setHTTPReferrer(const WebString
& referrer
, WebReferrerPolicy referrerPolicy
)
183 m_private
->m_resourceRequest
->setHTTPReferrer(Referrer(referrer
, static_cast<ReferrerPolicy
>(referrerPolicy
)));
186 void WebURLRequest::addHTTPHeaderField(const WebString
& name
, const WebString
& value
)
188 m_private
->m_resourceRequest
->addHTTPHeaderField(name
, value
);
191 void WebURLRequest::clearHTTPHeaderField(const WebString
& name
)
193 m_private
->m_resourceRequest
->clearHTTPHeaderField(name
);
196 void WebURLRequest::visitHTTPHeaderFields(WebHTTPHeaderVisitor
* visitor
) const
198 const HTTPHeaderMap
& map
= m_private
->m_resourceRequest
->httpHeaderFields();
199 for (HTTPHeaderMap::const_iterator it
= map
.begin(); it
!= map
.end(); ++it
)
200 visitor
->visitHeader(it
->key
, it
->value
);
203 WebHTTPBody
WebURLRequest::httpBody() const
205 return WebHTTPBody(m_private
->m_resourceRequest
->httpBody());
208 void WebURLRequest::setHTTPBody(const WebHTTPBody
& httpBody
)
210 m_private
->m_resourceRequest
->setHTTPBody(httpBody
);
213 bool WebURLRequest::reportUploadProgress() const
215 return m_private
->m_resourceRequest
->reportUploadProgress();
218 void WebURLRequest::setReportUploadProgress(bool reportUploadProgress
)
220 m_private
->m_resourceRequest
->setReportUploadProgress(reportUploadProgress
);
223 void WebURLRequest::setReportRawHeaders(bool reportRawHeaders
)
225 m_private
->m_resourceRequest
->setReportRawHeaders(reportRawHeaders
);
228 bool WebURLRequest::reportRawHeaders() const
230 return m_private
->m_resourceRequest
->reportRawHeaders();
233 WebURLRequest::RequestContext
WebURLRequest::requestContext() const
235 return m_private
->m_resourceRequest
->requestContext();
238 WebURLRequest::FrameType
WebURLRequest::frameType() const
240 return m_private
->m_resourceRequest
->frameType();
243 WebReferrerPolicy
WebURLRequest::referrerPolicy() const
245 return static_cast<WebReferrerPolicy
>(m_private
->m_resourceRequest
->referrerPolicy());
248 void WebURLRequest::addHTTPOriginIfNeeded(const WebString
& origin
)
250 m_private
->m_resourceRequest
->addHTTPOriginIfNeeded(origin
);
253 bool WebURLRequest::hasUserGesture() const
255 return m_private
->m_resourceRequest
->hasUserGesture();
258 void WebURLRequest::setHasUserGesture(bool hasUserGesture
)
260 m_private
->m_resourceRequest
->setHasUserGesture(hasUserGesture
);
263 void WebURLRequest::setRequestContext(RequestContext requestContext
)
265 m_private
->m_resourceRequest
->setRequestContext(requestContext
);
268 void WebURLRequest::setFrameType(FrameType frameType
)
270 m_private
->m_resourceRequest
->setFrameType(frameType
);
273 int WebURLRequest::requestorID() const
275 return m_private
->m_resourceRequest
->requestorID();
278 void WebURLRequest::setRequestorID(int requestorID
)
280 m_private
->m_resourceRequest
->setRequestorID(requestorID
);
283 int WebURLRequest::requestorProcessID() const
285 return m_private
->m_resourceRequest
->requestorProcessID();
288 void WebURLRequest::setRequestorProcessID(int requestorProcessID
)
290 m_private
->m_resourceRequest
->setRequestorProcessID(requestorProcessID
);
293 int WebURLRequest::appCacheHostID() const
295 return m_private
->m_resourceRequest
->appCacheHostID();
298 void WebURLRequest::setAppCacheHostID(int appCacheHostID
)
300 m_private
->m_resourceRequest
->setAppCacheHostID(appCacheHostID
);
303 bool WebURLRequest::downloadToFile() const
305 return m_private
->m_resourceRequest
->downloadToFile();
308 void WebURLRequest::setDownloadToFile(bool downloadToFile
)
310 m_private
->m_resourceRequest
->setDownloadToFile(downloadToFile
);
313 bool WebURLRequest::useStreamOnResponse() const
315 return m_private
->m_resourceRequest
->useStreamOnResponse();
318 void WebURLRequest::setUseStreamOnResponse(bool useStreamOnResponse
)
320 m_private
->m_resourceRequest
->setUseStreamOnResponse(useStreamOnResponse
);
323 bool WebURLRequest::skipServiceWorker() const
325 return m_private
->m_resourceRequest
->skipServiceWorker();
328 void WebURLRequest::setSkipServiceWorker(bool skipServiceWorker
)
330 m_private
->m_resourceRequest
->setSkipServiceWorker(skipServiceWorker
);
333 bool WebURLRequest::shouldResetAppCache() const
335 return m_private
->m_resourceRequest
->shouldResetAppCache();
338 void WebURLRequest::setShouldResetAppCache(bool setShouldResetAppCache
)
340 m_private
->m_resourceRequest
->setShouldResetAppCache(setShouldResetAppCache
);
343 WebURLRequest::FetchRequestMode
WebURLRequest::fetchRequestMode() const
345 return m_private
->m_resourceRequest
->fetchRequestMode();
348 void WebURLRequest::setFetchRequestMode(WebURLRequest::FetchRequestMode mode
)
350 return m_private
->m_resourceRequest
->setFetchRequestMode(mode
);
353 WebURLRequest::FetchCredentialsMode
WebURLRequest::fetchCredentialsMode() const
355 return m_private
->m_resourceRequest
->fetchCredentialsMode();
358 void WebURLRequest::setFetchCredentialsMode(WebURLRequest::FetchCredentialsMode mode
)
360 return m_private
->m_resourceRequest
->setFetchCredentialsMode(mode
);
363 WebURLRequest::FetchRedirectMode
WebURLRequest::fetchRedirectMode() const
365 return m_private
->m_resourceRequest
->fetchRedirectMode();
368 void WebURLRequest::setFetchRedirectMode(WebURLRequest::FetchRedirectMode redirect
)
370 return m_private
->m_resourceRequest
->setFetchRedirectMode(redirect
);
373 WebURLRequest::ExtraData
* WebURLRequest::extraData() const
375 RefPtr
<ResourceRequest::ExtraData
> data
= m_private
->m_resourceRequest
->extraData();
378 return static_cast<ExtraDataContainer
*>(data
.get())->extraData();
381 void WebURLRequest::setExtraData(WebURLRequest::ExtraData
* extraData
)
383 m_private
->m_resourceRequest
->setExtraData(ExtraDataContainer::create(extraData
));
386 ResourceRequest
& WebURLRequest::toMutableResourceRequest()
389 ASSERT(m_private
->m_resourceRequest
);
391 return *m_private
->m_resourceRequest
;
394 WebURLRequest::Priority
WebURLRequest::priority() const
396 return static_cast<WebURLRequest::Priority
>(
397 m_private
->m_resourceRequest
->priority());
400 void WebURLRequest::setPriority(WebURLRequest::Priority priority
)
402 m_private
->m_resourceRequest
->setPriority(
403 static_cast<ResourceLoadPriority
>(priority
));
406 bool WebURLRequest::checkForBrowserSideNavigation() const
408 return m_private
->m_resourceRequest
->checkForBrowserSideNavigation();
411 void WebURLRequest::setCheckForBrowserSideNavigation(bool check
)
413 m_private
->m_resourceRequest
->setCheckForBrowserSideNavigation(check
);
416 double WebURLRequest::uiStartTime() const
418 return m_private
->m_resourceRequest
->uiStartTime();
421 void WebURLRequest::setUiStartTime(double time
)
423 m_private
->m_resourceRequest
->setUIStartTime(time
);
426 bool WebURLRequest::originatesFromReservedIPRange() const
428 return m_private
->m_resourceRequest
->originatesFromReservedIPRange();
431 void WebURLRequest::setOriginatesFromReservedIPRange(bool value
)
433 m_private
->m_resourceRequest
->setOriginatesFromReservedIPRange(value
);
436 WebURLRequest::InputToLoadPerfMetricReportPolicy
WebURLRequest::inputPerfMetricReportPolicy() const
438 return static_cast<WebURLRequest::InputToLoadPerfMetricReportPolicy
>(
439 m_private
->m_resourceRequest
->inputPerfMetricReportPolicy());
442 void WebURLRequest::setInputPerfMetricReportPolicy(
443 WebURLRequest::InputToLoadPerfMetricReportPolicy policy
)
445 m_private
->m_resourceRequest
->setInputPerfMetricReportPolicy(
446 static_cast<blink::InputToLoadPerfMetricReportPolicy
>(policy
));
449 const ResourceRequest
& WebURLRequest::toResourceRequest() const
452 ASSERT(m_private
->m_resourceRequest
);
454 return *m_private
->m_resourceRequest
;
457 void WebURLRequest::assign(WebURLRequestPrivate
* p
)
459 // Subclasses may call this directly so a self-assignment check is needed
460 // here as well as in the public assign method.
464 m_private
->dispose();