Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / public / platform / WebURLRequest.h
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
17  *
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.
29  */
30
31 #ifndef WebURLRequest_h
32 #define WebURLRequest_h
33
34 #include "WebCommon.h"
35 #include "WebHTTPBody.h"
36 #include "WebReferrerPolicy.h"
37
38 namespace blink {
39
40 class ResourceRequest;
41 class WebCString;
42 class WebHTTPBody;
43 class WebHTTPHeaderVisitor;
44 class WebString;
45 class WebURL;
46 class WebURLRequestPrivate;
47
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
56     };
57
58     enum Priority {
59         PriorityUnresolved = -1,
60         PriorityVeryLow,
61         PriorityLow,
62         PriorityMedium,
63         PriorityHigh,
64         PriorityVeryHigh,
65     };
66
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
103     };
104
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
111     };
112
113     enum FetchRequestMode {
114         FetchRequestModeSameOrigin,
115         FetchRequestModeNoCORS,
116         FetchRequestModeCORS,
117         FetchRequestModeCORSWithForcedPreflight
118     };
119
120     enum FetchCredentialsMode {
121         FetchCredentialsModeOmit,
122         FetchCredentialsModeSameOrigin,
123         FetchCredentialsModeInclude
124     };
125
126     class ExtraData {
127     public:
128         virtual ~ExtraData() { }
129     };
130
131     ~WebURLRequest() { reset(); }
132
133     WebURLRequest() : m_private(0) { }
134     WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); }
135     WebURLRequest& operator=(const WebURLRequest& r)
136     {
137         assign(r);
138         return *this;
139     }
140
141     explicit WebURLRequest(const WebURL& url) : m_private(0)
142     {
143         initialize();
144         setURL(url);
145     }
146
147     BLINK_PLATFORM_EXPORT void initialize();
148     BLINK_PLATFORM_EXPORT void reset();
149     BLINK_PLATFORM_EXPORT void assign(const WebURLRequest&);
150
151     BLINK_PLATFORM_EXPORT bool isNull() const;
152
153     BLINK_PLATFORM_EXPORT WebURL url() const;
154     BLINK_PLATFORM_EXPORT void setURL(const WebURL&);
155
156     // Used to implement third-party cookie blocking.
157     BLINK_PLATFORM_EXPORT WebURL firstPartyForCookies() const;
158     BLINK_PLATFORM_EXPORT void setFirstPartyForCookies(const WebURL&);
159
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);
164
165     BLINK_PLATFORM_EXPORT CachePolicy cachePolicy() const;
166     BLINK_PLATFORM_EXPORT void setCachePolicy(CachePolicy);
167
168     BLINK_PLATFORM_EXPORT WebString httpMethod() const;
169     BLINK_PLATFORM_EXPORT void setHTTPMethod(const WebString&);
170
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;
178
179     BLINK_PLATFORM_EXPORT WebHTTPBody httpBody() const;
180     BLINK_PLATFORM_EXPORT void setHTTPBody(const WebHTTPBody&);
181
182     // Controls whether upload progress events are generated when a request
183     // has a body.
184     BLINK_PLATFORM_EXPORT bool reportUploadProgress() const;
185     BLINK_PLATFORM_EXPORT void setReportUploadProgress(bool);
186
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);
191
192     BLINK_PLATFORM_EXPORT RequestContext requestContext() const;
193     BLINK_PLATFORM_EXPORT void setRequestContext(RequestContext);
194
195     BLINK_PLATFORM_EXPORT FrameType frameType() const;
196     BLINK_PLATFORM_EXPORT void setFrameType(FrameType);
197
198     BLINK_PLATFORM_EXPORT WebReferrerPolicy referrerPolicy() const;
199
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);
203
204     // True if the request was user initiated.
205     BLINK_PLATFORM_EXPORT bool hasUserGesture() const;
206     BLINK_PLATFORM_EXPORT void setHasUserGesture(bool);
207
208     // A consumer controlled value intended to be used to identify the
209     // requestor.
210     BLINK_PLATFORM_EXPORT int requestorID() const;
211     BLINK_PLATFORM_EXPORT void setRequestorID(int);
212
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);
217
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);
221
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);
226
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);
230
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);
234
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);
238
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*);
247
248     BLINK_PLATFORM_EXPORT Priority priority() const;
249     BLINK_PLATFORM_EXPORT void setPriority(Priority);
250
251 #if INSIDE_BLINK
252     BLINK_PLATFORM_EXPORT ResourceRequest& toMutableResourceRequest();
253     BLINK_PLATFORM_EXPORT const ResourceRequest& toResourceRequest() const;
254 #endif
255
256 protected:
257     BLINK_PLATFORM_EXPORT void assign(WebURLRequestPrivate*);
258
259 private:
260     WebURLRequestPrivate* m_private;
261 };
262
263 } // namespace blink
264
265 #endif