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
115 virtual ~ExtraData() { }
118 ~WebURLRequest() { reset(); }
120 WebURLRequest() : m_private(0) { }
121 WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); }
122 WebURLRequest& operator=(const WebURLRequest& r)
128 explicit WebURLRequest(const WebURL& url) : m_private(0)
134 BLINK_PLATFORM_EXPORT void initialize();
135 BLINK_PLATFORM_EXPORT void reset();
136 BLINK_PLATFORM_EXPORT void assign(const WebURLRequest&);
138 BLINK_PLATFORM_EXPORT bool isNull() const;
140 BLINK_PLATFORM_EXPORT WebURL url() const;
141 BLINK_PLATFORM_EXPORT void setURL(const WebURL&);
143 // Used to implement third-party cookie blocking.
144 BLINK_PLATFORM_EXPORT WebURL firstPartyForCookies() const;
145 BLINK_PLATFORM_EXPORT void setFirstPartyForCookies(const WebURL&);
147 // Controls whether user name, password, and cookies may be sent with the
148 // request. (If false, this overrides allowCookies.)
149 BLINK_PLATFORM_EXPORT bool allowStoredCredentials() const;
150 BLINK_PLATFORM_EXPORT void setAllowStoredCredentials(bool);
152 BLINK_PLATFORM_EXPORT CachePolicy cachePolicy() const;
153 BLINK_PLATFORM_EXPORT void setCachePolicy(CachePolicy);
155 BLINK_PLATFORM_EXPORT WebString httpMethod() const;
156 BLINK_PLATFORM_EXPORT void setHTTPMethod(const WebString&);
158 BLINK_PLATFORM_EXPORT WebString httpHeaderField(const WebString& name) const;
159 // It's not possible to set the referrer header using this method. Use setHTTPReferrer instead.
160 BLINK_PLATFORM_EXPORT void setHTTPHeaderField(const WebString& name, const WebString& value);
161 BLINK_PLATFORM_EXPORT void setHTTPReferrer(const WebString& referrer, WebReferrerPolicy);
162 BLINK_PLATFORM_EXPORT void addHTTPHeaderField(const WebString& name, const WebString& value);
163 BLINK_PLATFORM_EXPORT void clearHTTPHeaderField(const WebString& name);
164 BLINK_PLATFORM_EXPORT void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const;
166 BLINK_PLATFORM_EXPORT WebHTTPBody httpBody() const;
167 BLINK_PLATFORM_EXPORT void setHTTPBody(const WebHTTPBody&);
169 // Controls whether upload progress events are generated when a request
171 BLINK_PLATFORM_EXPORT bool reportUploadProgress() const;
172 BLINK_PLATFORM_EXPORT void setReportUploadProgress(bool);
174 // Controls whether actual headers sent and received for request are
175 // collected and reported.
176 BLINK_PLATFORM_EXPORT bool reportRawHeaders() const;
177 BLINK_PLATFORM_EXPORT void setReportRawHeaders(bool);
179 BLINK_PLATFORM_EXPORT RequestContext requestContext() const;
180 BLINK_PLATFORM_EXPORT void setRequestContext(RequestContext);
182 BLINK_PLATFORM_EXPORT FrameType frameType() const;
183 BLINK_PLATFORM_EXPORT void setFrameType(FrameType);
185 BLINK_PLATFORM_EXPORT WebReferrerPolicy referrerPolicy() const;
187 // Adds an HTTP origin header if it is empty and the HTTP method of the
188 // request requires it.
189 BLINK_PLATFORM_EXPORT void addHTTPOriginIfNeeded(const WebString& origin);
191 // True if the request was user initiated.
192 BLINK_PLATFORM_EXPORT bool hasUserGesture() const;
193 BLINK_PLATFORM_EXPORT void setHasUserGesture(bool);
195 // A consumer controlled value intended to be used to identify the
197 BLINK_PLATFORM_EXPORT int requestorID() const;
198 BLINK_PLATFORM_EXPORT void setRequestorID(int);
200 // A consumer controlled value intended to be used to identify the
201 // process of the requestor.
202 BLINK_PLATFORM_EXPORT int requestorProcessID() const;
203 BLINK_PLATFORM_EXPORT void setRequestorProcessID(int);
205 // Allows the request to be matched up with its app cache host.
206 BLINK_PLATFORM_EXPORT int appCacheHostID() const;
207 BLINK_PLATFORM_EXPORT void setAppCacheHostID(int);
209 // If true, the response body will be downloaded to a file managed by the
210 // WebURLLoader. See WebURLResponse::downloadedFilePath.
211 BLINK_PLATFORM_EXPORT bool downloadToFile() const;
212 BLINK_PLATFORM_EXPORT void setDownloadToFile(bool);
214 // Extra data associated with the underlying resource request. Resource
215 // requests can be copied. If non-null, each copy of a resource requests
216 // holds a pointer to the extra data, and the extra data pointer will be
217 // deleted when the last resource request is destroyed. Setting the extra
218 // data pointer will cause the underlying resource request to be
219 // dissociated from any existing non-null extra data pointer.
220 BLINK_PLATFORM_EXPORT ExtraData* extraData() const;
221 BLINK_PLATFORM_EXPORT void setExtraData(ExtraData*);
223 BLINK_PLATFORM_EXPORT Priority priority() const;
224 BLINK_PLATFORM_EXPORT void setPriority(Priority);
227 BLINK_PLATFORM_EXPORT ResourceRequest& toMutableResourceRequest();
228 BLINK_PLATFORM_EXPORT const ResourceRequest& toResourceRequest() const;
232 BLINK_PLATFORM_EXPORT void assign(WebURLRequestPrivate*);
235 WebURLRequestPrivate* m_private;