1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "public/platform/WebServiceWorkerRequest.h"
8 #include "platform/blob/BlobData.h"
9 #include "platform/weborigin/KURL.h"
10 #include "public/platform/WebHTTPHeaderVisitor.h"
11 #include "public/platform/WebURLRequest.h"
15 class WebServiceWorkerRequestPrivate
: public RefCounted
<WebServiceWorkerRequestPrivate
> {
17 WebServiceWorkerRequestPrivate()
18 : m_mode(WebURLRequest::FetchRequestModeNoCORS
)
19 , m_credentialsMode(WebURLRequest::FetchCredentialsModeOmit
)
20 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow
)
21 , m_requestContext(WebURLRequest::RequestContextUnspecified
)
22 , m_frameType(WebURLRequest::FrameTypeNone
)
28 HTTPHeaderMap m_headers
;
29 RefPtr
<BlobDataHandle
> blobDataHandle
;
31 WebURLRequest::FetchRequestMode m_mode
;
32 WebURLRequest::FetchCredentialsMode m_credentialsMode
;
33 WebURLRequest::FetchRedirectMode m_redirectMode
;
34 WebURLRequest::RequestContext m_requestContext
;
35 WebURLRequest::FrameType m_frameType
;
39 WebServiceWorkerRequest::WebServiceWorkerRequest()
40 : m_private(adoptRef(new WebServiceWorkerRequestPrivate
))
44 void WebServiceWorkerRequest::reset()
49 void WebServiceWorkerRequest::assign(const WebServiceWorkerRequest
& other
)
51 m_private
= other
.m_private
;
54 void WebServiceWorkerRequest::setURL(const WebURL
& url
)
56 m_private
->m_url
= url
;
59 WebURL
WebServiceWorkerRequest::url() const
61 return m_private
->m_url
;
64 void WebServiceWorkerRequest::setMethod(const WebString
& method
)
66 m_private
->m_method
= method
;
69 WebString
WebServiceWorkerRequest::method() const
71 return m_private
->m_method
;
74 void WebServiceWorkerRequest::setHeader(const WebString
& key
, const WebString
& value
)
76 if (equalIgnoringCase(key
, "referer"))
78 m_private
->m_headers
.set(key
, value
);
81 void WebServiceWorkerRequest::appendHeader(const WebString
& key
, const WebString
& value
)
83 if (equalIgnoringCase(key
, "referer"))
85 HTTPHeaderMap::AddResult result
= m_private
->m_headers
.add(key
, value
);
86 if (!result
.isNewEntry
)
87 result
.storedValue
->value
= result
.storedValue
->value
+ ", " + String(value
);
90 void WebServiceWorkerRequest::visitHTTPHeaderFields(WebHTTPHeaderVisitor
* headerVisitor
) const
92 for (HTTPHeaderMap::const_iterator i
= m_private
->m_headers
.begin(), end
= m_private
->m_headers
.end(); i
!= end
; ++i
)
93 headerVisitor
->visitHeader(i
->key
, i
->value
);
96 const HTTPHeaderMap
& WebServiceWorkerRequest::headers() const
98 return m_private
->m_headers
;
101 void WebServiceWorkerRequest::setBlob(const WebString
& uuid
, long long size
)
103 m_private
->blobDataHandle
= BlobDataHandle::create(uuid
, String(), size
);
106 PassRefPtr
<BlobDataHandle
> WebServiceWorkerRequest::blobDataHandle() const
108 return m_private
->blobDataHandle
;
111 void WebServiceWorkerRequest::setReferrer(const WebString
& referrer
, WebReferrerPolicy referrerPolicy
)
113 m_private
->m_referrer
= Referrer(referrer
, static_cast<ReferrerPolicy
>(referrerPolicy
));
116 WebURL
WebServiceWorkerRequest::referrerUrl() const
118 return KURL(ParsedURLString
, m_private
->m_referrer
.referrer
);
121 WebReferrerPolicy
WebServiceWorkerRequest::referrerPolicy() const
123 return static_cast<WebReferrerPolicy
>(m_private
->m_referrer
.referrerPolicy
);
126 const Referrer
& WebServiceWorkerRequest::referrer() const
128 return m_private
->m_referrer
;
131 void WebServiceWorkerRequest::setMode(WebURLRequest::FetchRequestMode mode
)
133 m_private
->m_mode
= mode
;
136 WebURLRequest::FetchRequestMode
WebServiceWorkerRequest::mode() const
138 return m_private
->m_mode
;
141 void WebServiceWorkerRequest::setCredentialsMode(WebURLRequest::FetchCredentialsMode credentialsMode
)
143 m_private
->m_credentialsMode
= credentialsMode
;
146 WebURLRequest::FetchCredentialsMode
WebServiceWorkerRequest::credentialsMode() const
148 return m_private
->m_credentialsMode
;
151 void WebServiceWorkerRequest::setRedirectMode(WebURLRequest::FetchRedirectMode redirectMode
)
153 m_private
->m_redirectMode
= redirectMode
;
156 WebURLRequest::FetchRedirectMode
WebServiceWorkerRequest::redirectMode() const
158 return m_private
->m_redirectMode
;
161 void WebServiceWorkerRequest::setRequestContext(WebURLRequest::RequestContext requestContext
)
163 m_private
->m_requestContext
= requestContext
;
166 WebURLRequest::RequestContext
WebServiceWorkerRequest::requestContext() const
168 return m_private
->m_requestContext
;
171 void WebServiceWorkerRequest::setFrameType(WebURLRequest::FrameType frameType
)
173 m_private
->m_frameType
= frameType
;
176 WebURLRequest::FrameType
WebServiceWorkerRequest::frameType() const
178 return m_private
->m_frameType
;
181 void WebServiceWorkerRequest::setIsReload(bool isReload
)
183 m_private
->m_isReload
= isReload
;
186 bool WebServiceWorkerRequest::isReload() const
188 return m_private
->m_isReload
;