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.
31 #ifndef WebURLRequest_h
32 #define WebURLRequest_h
34 #include "WebCommon.h"
35 #include "WebHTTPBody.h"
36 #include "WebReferrerPolicy.h"
40 class ResourceRequest;
43 class WebHTTPHeaderVisitor;
46 class WebURLRequestPrivate;
51 UseProtocolCachePolicy, // normal load
52 ReloadIgnoringCacheData, // reload
53 ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale data
54 ReturnCacheDataDontLoad, // results of a post - allow stale data and only use cache
55 ReloadBypassingCache, // end-to-end reload
59 PriorityUnresolved = -1,
67 // Corresponds to Fetch's "context": http://fetch.spec.whatwg.org/#concept-request-context
69 RequestContextUnspecified = 0,
72 RequestContextCSPReport,
73 RequestContextDownload,
75 RequestContextEventSource,
76 RequestContextFavicon,
81 RequestContextHyperlink,
84 RequestContextImageSet,
86 RequestContextInternal,
87 RequestContextLocation,
88 RequestContextManifest,
92 RequestContextPrefetch,
94 RequestContextServiceWorker,
95 RequestContextSharedWorker,
96 RequestContextSubresource,
100 RequestContextWorker,
101 RequestContextXMLHttpRequest,
105 // Corresponds to Fetch's "context frame type": http://fetch.spec.whatwg.org/#concept-request-context-frame-type
113 enum FetchRequestMode {
114 FetchRequestModeSameOrigin,
115 FetchRequestModeNoCORS,
116 FetchRequestModeCORS,
117 FetchRequestModeCORSWithForcedPreflight
120 enum FetchCredentialsMode {
121 FetchCredentialsModeOmit,
122 FetchCredentialsModeSameOrigin,
123 FetchCredentialsModeInclude
128 virtual ~ExtraData() { }
131 ~WebURLRequest() { reset(); }
133 WebURLRequest() : m_private(0) { }
134 WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); }
135 WebURLRequest& operator=(const WebURLRequest& r)
141 explicit WebURLRequest(const WebURL& url) : m_private(0)
147 BLINK_PLATFORM_EXPORT void initialize();
148 BLINK_PLATFORM_EXPORT void reset();
149 BLINK_PLATFORM_EXPORT void assign(const WebURLRequest&);
151 BLINK_PLATFORM_EXPORT bool isNull() const;
153 BLINK_PLATFORM_EXPORT WebURL url() const;
154 BLINK_PLATFORM_EXPORT void setURL(const WebURL&);
156 // Used to implement third-party cookie blocking.
157 BLINK_PLATFORM_EXPORT WebURL firstPartyForCookies() const;
158 BLINK_PLATFORM_EXPORT void setFirstPartyForCookies(const WebURL&);
160 // Controls whether user name, password, and cookies may be sent with the
161 // request. (If false, this overrides allowCookies.)
162 BLINK_PLATFORM_EXPORT bool allowStoredCredentials() const;
163 BLINK_PLATFORM_EXPORT void setAllowStoredCredentials(bool);
165 BLINK_PLATFORM_EXPORT CachePolicy cachePolicy() const;
166 BLINK_PLATFORM_EXPORT void setCachePolicy(CachePolicy);
168 BLINK_PLATFORM_EXPORT WebString httpMethod() const;
169 BLINK_PLATFORM_EXPORT void setHTTPMethod(const WebString&);
171 BLINK_PLATFORM_EXPORT WebString httpHeaderField(const WebString& name) const;
172 // It's not possible to set the referrer header using this method. Use setHTTPReferrer instead.
173 BLINK_PLATFORM_EXPORT void setHTTPHeaderField(const WebString& name, const WebString& value);
174 BLINK_PLATFORM_EXPORT void setHTTPReferrer(const WebString& referrer, WebReferrerPolicy);
175 BLINK_PLATFORM_EXPORT void addHTTPHeaderField(const WebString& name, const WebString& value);
176 BLINK_PLATFORM_EXPORT void clearHTTPHeaderField(const WebString& name);
177 BLINK_PLATFORM_EXPORT void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const;
179 BLINK_PLATFORM_EXPORT WebHTTPBody httpBody() const;
180 BLINK_PLATFORM_EXPORT void setHTTPBody(const WebHTTPBody&);
182 // Controls whether upload progress events are generated when a request
184 BLINK_PLATFORM_EXPORT bool reportUploadProgress() const;
185 BLINK_PLATFORM_EXPORT void setReportUploadProgress(bool);
187 // Controls whether actual headers sent and received for request are
188 // collected and reported.
189 BLINK_PLATFORM_EXPORT bool reportRawHeaders() const;
190 BLINK_PLATFORM_EXPORT void setReportRawHeaders(bool);
192 BLINK_PLATFORM_EXPORT RequestContext requestContext() const;
193 BLINK_PLATFORM_EXPORT void setRequestContext(RequestContext);
195 BLINK_PLATFORM_EXPORT FrameType frameType() const;
196 BLINK_PLATFORM_EXPORT void setFrameType(FrameType);
198 BLINK_PLATFORM_EXPORT WebReferrerPolicy referrerPolicy() const;
200 // Adds an HTTP origin header if it is empty and the HTTP method of the
201 // request requires it.
202 BLINK_PLATFORM_EXPORT void addHTTPOriginIfNeeded(const WebString& origin);
204 // True if the request was user initiated.
205 BLINK_PLATFORM_EXPORT bool hasUserGesture() const;
206 BLINK_PLATFORM_EXPORT void setHasUserGesture(bool);
208 // A consumer controlled value intended to be used to identify the
210 BLINK_PLATFORM_EXPORT int requestorID() const;
211 BLINK_PLATFORM_EXPORT void setRequestorID(int);
213 // A consumer controlled value intended to be used to identify the
214 // process of the requestor.
215 BLINK_PLATFORM_EXPORT int requestorProcessID() const;
216 BLINK_PLATFORM_EXPORT void setRequestorProcessID(int);
218 // Allows the request to be matched up with its app cache host.
219 BLINK_PLATFORM_EXPORT int appCacheHostID() const;
220 BLINK_PLATFORM_EXPORT void setAppCacheHostID(int);
222 // If true, the response body will be downloaded to a file managed by the
223 // WebURLLoader. See WebURLResponse::downloadedFilePath.
224 BLINK_PLATFORM_EXPORT bool downloadToFile() const;
225 BLINK_PLATFORM_EXPORT void setDownloadToFile(bool);
227 // True if the request should not be handled by the ServiceWorker.
228 BLINK_PLATFORM_EXPORT bool skipServiceWorker() const;
229 BLINK_PLATFORM_EXPORT void setSkipServiceWorker(bool);
231 // The request mode which will be passed to the ServiceWorker.
232 BLINK_PLATFORM_EXPORT FetchRequestMode fetchRequestMode() const;
233 BLINK_PLATFORM_EXPORT void setFetchRequestMode(FetchRequestMode);
235 // The credentials mode which will be passed to the ServiceWorker.
236 BLINK_PLATFORM_EXPORT FetchCredentialsMode fetchCredentialsMode() const;
237 BLINK_PLATFORM_EXPORT void setFetchCredentialsMode(FetchCredentialsMode);
239 // Extra data associated with the underlying resource request. Resource
240 // requests can be copied. If non-null, each copy of a resource requests
241 // holds a pointer to the extra data, and the extra data pointer will be
242 // deleted when the last resource request is destroyed. Setting the extra
243 // data pointer will cause the underlying resource request to be
244 // dissociated from any existing non-null extra data pointer.
245 BLINK_PLATFORM_EXPORT ExtraData* extraData() const;
246 BLINK_PLATFORM_EXPORT void setExtraData(ExtraData*);
248 BLINK_PLATFORM_EXPORT Priority priority() const;
249 BLINK_PLATFORM_EXPORT void setPriority(Priority);
252 BLINK_PLATFORM_EXPORT ResourceRequest& toMutableResourceRequest();
253 BLINK_PLATFORM_EXPORT const ResourceRequest& toResourceRequest() const;
257 BLINK_PLATFORM_EXPORT void assign(WebURLRequestPrivate*);
260 WebURLRequestPrivate* m_private;