Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebURLRequest.h
blobacfe12991ba38d8d60bfe55ed97bdde30be51089
1 /*
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
6 * met:
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.
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"
38 namespace blink {
40 class ResourceRequest;
41 class WebHTTPBody;
42 class WebHTTPHeaderVisitor;
43 class WebSecurityOrigin;
44 class WebString;
45 class WebURL;
46 class WebURLRequestPrivate;
48 class WebURLRequest {
49 public:
50 enum CachePolicy {
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
58 enum Priority {
59 PriorityUnresolved = -1,
60 PriorityVeryLow,
61 PriorityLow,
62 PriorityMedium,
63 PriorityHigh,
64 PriorityVeryHigh,
67 // Corresponds to Fetch's "context": http://fetch.spec.whatwg.org/#concept-request-context
68 enum RequestContext {
69 RequestContextUnspecified = 0,
70 RequestContextAudio,
71 RequestContextBeacon,
72 RequestContextCSPReport,
73 RequestContextDownload,
74 RequestContextEmbed,
75 RequestContextEventSource,
76 RequestContextFavicon,
77 RequestContextFetch,
78 RequestContextFont,
79 RequestContextForm,
80 RequestContextFrame,
81 RequestContextHyperlink,
82 RequestContextIframe,
83 RequestContextImage,
84 RequestContextImageSet,
85 RequestContextImport,
86 RequestContextInternal,
87 RequestContextLocation,
88 RequestContextManifest,
89 RequestContextObject,
90 RequestContextPing,
91 RequestContextPlugin,
92 RequestContextPrefetch,
93 RequestContextScript,
94 RequestContextServiceWorker,
95 RequestContextSharedWorker,
96 RequestContextSubresource,
97 RequestContextStyle,
98 RequestContextTrack,
99 RequestContextVideo,
100 RequestContextWorker,
101 RequestContextXMLHttpRequest,
102 RequestContextXSLT
105 // Corresponds to Fetch's "context frame type": http://fetch.spec.whatwg.org/#concept-request-context-frame-type
106 enum FrameType {
107 FrameTypeAuxiliary,
108 FrameTypeNested,
109 FrameTypeNone,
110 FrameTypeTopLevel
113 enum FetchRequestMode {
114 FetchRequestModeSameOrigin,
115 FetchRequestModeNoCORS,
116 FetchRequestModeCORS,
117 FetchRequestModeCORSWithForcedPreflight
120 enum FetchCredentialsMode {
121 FetchCredentialsModeOmit,
122 FetchCredentialsModeSameOrigin,
123 FetchCredentialsModeInclude
126 enum FetchRedirectMode {
127 FetchRedirectModeFollow,
128 FetchRedirectModeError,
129 FetchRedirectModeManual
132 // Used to report performance metrics timed from the UI action that
133 // triggered them (as opposed to navigation start time used in the
134 // Navigation Timing API).
135 enum InputToLoadPerfMetricReportPolicy {
136 NoReport, // Don't report metrics for this WebURLRequest.
137 ReportLink, // Report metrics with UI action link clicked.
138 ReportIntent, // Report metrics with UI action displayed intent.
141 class ExtraData {
142 public:
143 virtual ~ExtraData() { }
146 ~WebURLRequest() { reset(); }
148 WebURLRequest() : m_private(0) { }
149 WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); }
150 WebURLRequest& operator=(const WebURLRequest& r)
152 assign(r);
153 return *this;
156 explicit WebURLRequest(const WebURL& url) : m_private(0)
158 initialize();
159 setURL(url);
162 BLINK_PLATFORM_EXPORT void initialize();
163 BLINK_PLATFORM_EXPORT void reset();
164 BLINK_PLATFORM_EXPORT void assign(const WebURLRequest&);
166 BLINK_PLATFORM_EXPORT bool isNull() const;
168 BLINK_PLATFORM_EXPORT WebURL url() const;
169 BLINK_PLATFORM_EXPORT void setURL(const WebURL&);
171 // Used to implement third-party cookie blocking.
172 BLINK_PLATFORM_EXPORT WebURL firstPartyForCookies() const;
173 BLINK_PLATFORM_EXPORT void setFirstPartyForCookies(const WebURL&);
175 // The origin of the execution context which originated the request. Used to
176 // implement First-Party-Only cookie restrictions.
177 BLINK_PLATFORM_EXPORT WebSecurityOrigin requestorOrigin() const;
178 BLINK_PLATFORM_EXPORT void setRequestorOrigin(const WebSecurityOrigin&);
180 // Controls whether user name, password, and cookies may be sent with the
181 // request. (If false, this overrides allowCookies.)
182 BLINK_PLATFORM_EXPORT bool allowStoredCredentials() const;
183 BLINK_PLATFORM_EXPORT void setAllowStoredCredentials(bool);
185 BLINK_PLATFORM_EXPORT CachePolicy cachePolicy() const;
186 BLINK_PLATFORM_EXPORT void setCachePolicy(CachePolicy);
188 BLINK_PLATFORM_EXPORT WebString httpMethod() const;
189 BLINK_PLATFORM_EXPORT void setHTTPMethod(const WebString&);
191 BLINK_PLATFORM_EXPORT WebString httpHeaderField(const WebString& name) const;
192 // It's not possible to set the referrer header using this method. Use setHTTPReferrer instead.
193 BLINK_PLATFORM_EXPORT void setHTTPHeaderField(const WebString& name, const WebString& value);
194 BLINK_PLATFORM_EXPORT void setHTTPReferrer(const WebString& referrer, WebReferrerPolicy);
195 BLINK_PLATFORM_EXPORT void addHTTPHeaderField(const WebString& name, const WebString& value);
196 BLINK_PLATFORM_EXPORT void clearHTTPHeaderField(const WebString& name);
197 BLINK_PLATFORM_EXPORT void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const;
199 BLINK_PLATFORM_EXPORT WebHTTPBody httpBody() const;
200 BLINK_PLATFORM_EXPORT void setHTTPBody(const WebHTTPBody&);
202 // Controls whether upload progress events are generated when a request
203 // has a body.
204 BLINK_PLATFORM_EXPORT bool reportUploadProgress() const;
205 BLINK_PLATFORM_EXPORT void setReportUploadProgress(bool);
207 // Controls whether actual headers sent and received for request are
208 // collected and reported.
209 BLINK_PLATFORM_EXPORT bool reportRawHeaders() const;
210 BLINK_PLATFORM_EXPORT void setReportRawHeaders(bool);
212 BLINK_PLATFORM_EXPORT RequestContext requestContext() const;
213 BLINK_PLATFORM_EXPORT void setRequestContext(RequestContext);
215 BLINK_PLATFORM_EXPORT FrameType frameType() const;
216 BLINK_PLATFORM_EXPORT void setFrameType(FrameType);
218 BLINK_PLATFORM_EXPORT WebReferrerPolicy referrerPolicy() const;
220 // Adds an HTTP origin header if it is empty and the HTTP method of the
221 // request requires it.
222 BLINK_PLATFORM_EXPORT void addHTTPOriginIfNeeded(const WebString& origin);
224 // True if the request was user initiated.
225 BLINK_PLATFORM_EXPORT bool hasUserGesture() const;
226 BLINK_PLATFORM_EXPORT void setHasUserGesture(bool);
228 // A consumer controlled value intended to be used to identify the
229 // requestor.
230 BLINK_PLATFORM_EXPORT int requestorID() const;
231 BLINK_PLATFORM_EXPORT void setRequestorID(int);
233 // A consumer controlled value intended to be used to identify the
234 // process of the requestor.
235 BLINK_PLATFORM_EXPORT int requestorProcessID() const;
236 BLINK_PLATFORM_EXPORT void setRequestorProcessID(int);
238 // Allows the request to be matched up with its app cache host.
239 BLINK_PLATFORM_EXPORT int appCacheHostID() const;
240 BLINK_PLATFORM_EXPORT void setAppCacheHostID(int);
242 // If true, the response body will be downloaded to a file managed by the
243 // WebURLLoader. See WebURLResponse::downloadedFilePath.
244 BLINK_PLATFORM_EXPORT bool downloadToFile() const;
245 BLINK_PLATFORM_EXPORT void setDownloadToFile(bool);
247 // True if the requestor wants to receive the response body as a stream.
248 BLINK_PLATFORM_EXPORT bool useStreamOnResponse() const;
249 BLINK_PLATFORM_EXPORT void setUseStreamOnResponse(bool);
251 // True if the request should not be handled by the ServiceWorker.
252 BLINK_PLATFORM_EXPORT bool skipServiceWorker() const;
253 BLINK_PLATFORM_EXPORT void setSkipServiceWorker(bool);
255 // True if corresponding AppCache group should be resetted.
256 BLINK_PLATFORM_EXPORT bool shouldResetAppCache() const;
257 BLINK_PLATFORM_EXPORT void setShouldResetAppCache(bool);
259 // The request mode which will be passed to the ServiceWorker.
260 BLINK_PLATFORM_EXPORT FetchRequestMode fetchRequestMode() const;
261 BLINK_PLATFORM_EXPORT void setFetchRequestMode(FetchRequestMode);
263 // The credentials mode which will be passed to the ServiceWorker.
264 BLINK_PLATFORM_EXPORT FetchCredentialsMode fetchCredentialsMode() const;
265 BLINK_PLATFORM_EXPORT void setFetchCredentialsMode(FetchCredentialsMode);
267 // The redirect mode which is used in Fetch API.
268 BLINK_PLATFORM_EXPORT FetchRedirectMode fetchRedirectMode() const;
269 BLINK_PLATFORM_EXPORT void setFetchRedirectMode(FetchRedirectMode);
271 // Extra data associated with the underlying resource request. Resource
272 // requests can be copied. If non-null, each copy of a resource requests
273 // holds a pointer to the extra data, and the extra data pointer will be
274 // deleted when the last resource request is destroyed. Setting the extra
275 // data pointer will cause the underlying resource request to be
276 // dissociated from any existing non-null extra data pointer.
277 BLINK_PLATFORM_EXPORT ExtraData* extraData() const;
278 BLINK_PLATFORM_EXPORT void setExtraData(ExtraData*);
280 BLINK_PLATFORM_EXPORT Priority priority() const;
281 BLINK_PLATFORM_EXPORT void setPriority(Priority);
283 // PlzNavigate: whether the FrameLoader should try to send the request to
284 // the browser (if browser-side navigations are enabled).
285 // Note: WebURLRequests created by RenderFrameImpl::OnCommitNavigation must
286 // not be sent to the browser.
287 BLINK_PLATFORM_EXPORT bool checkForBrowserSideNavigation() const;
288 BLINK_PLATFORM_EXPORT void setCheckForBrowserSideNavigation(bool);
290 // This is used to report navigation metrics starting from the UI action
291 // that triggered the navigation (which can be different from the navigation
292 // start time used in the Navigation Timing API).
293 BLINK_PLATFORM_EXPORT double uiStartTime() const;
294 BLINK_PLATFORM_EXPORT void setUiStartTime(double);
295 BLINK_PLATFORM_EXPORT WebURLRequest::InputToLoadPerfMetricReportPolicy inputPerfMetricReportPolicy() const;
296 BLINK_PLATFORM_EXPORT void setInputPerfMetricReportPolicy(WebURLRequest::InputToLoadPerfMetricReportPolicy);
298 // Does the request originate from a SecurityContext hosted in a reserved
299 // (RFC1918) IP range?
300 BLINK_PLATFORM_EXPORT bool originatesFromReservedIPRange() const;
301 BLINK_PLATFORM_EXPORT void setOriginatesFromReservedIPRange(bool);
303 #if INSIDE_BLINK
304 BLINK_PLATFORM_EXPORT ResourceRequest& toMutableResourceRequest();
305 BLINK_PLATFORM_EXPORT const ResourceRequest& toResourceRequest() const;
306 #endif
308 protected:
309 BLINK_PLATFORM_EXPORT void assign(WebURLRequestPrivate*);
311 private:
312 WebURLRequestPrivate* m_private;
315 } // namespace blink
317 #endif