Upstream version 9.38.198.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     class ExtraData {
114     public:
115         virtual ~ExtraData() { }
116     };
117
118     ~WebURLRequest() { reset(); }
119
120     WebURLRequest() : m_private(0) { }
121     WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); }
122     WebURLRequest& operator=(const WebURLRequest& r)
123     {
124         assign(r);
125         return *this;
126     }
127
128     explicit WebURLRequest(const WebURL& url) : m_private(0)
129     {
130         initialize();
131         setURL(url);
132     }
133
134     BLINK_PLATFORM_EXPORT void initialize();
135     BLINK_PLATFORM_EXPORT void reset();
136     BLINK_PLATFORM_EXPORT void assign(const WebURLRequest&);
137
138     BLINK_PLATFORM_EXPORT bool isNull() const;
139
140     BLINK_PLATFORM_EXPORT WebURL url() const;
141     BLINK_PLATFORM_EXPORT void setURL(const WebURL&);
142
143     // Used to implement third-party cookie blocking.
144     BLINK_PLATFORM_EXPORT WebURL firstPartyForCookies() const;
145     BLINK_PLATFORM_EXPORT void setFirstPartyForCookies(const WebURL&);
146
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);
151
152     BLINK_PLATFORM_EXPORT CachePolicy cachePolicy() const;
153     BLINK_PLATFORM_EXPORT void setCachePolicy(CachePolicy);
154
155     BLINK_PLATFORM_EXPORT WebString httpMethod() const;
156     BLINK_PLATFORM_EXPORT void setHTTPMethod(const WebString&);
157
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;
165
166     BLINK_PLATFORM_EXPORT WebHTTPBody httpBody() const;
167     BLINK_PLATFORM_EXPORT void setHTTPBody(const WebHTTPBody&);
168
169     // Controls whether upload progress events are generated when a request
170     // has a body.
171     BLINK_PLATFORM_EXPORT bool reportUploadProgress() const;
172     BLINK_PLATFORM_EXPORT void setReportUploadProgress(bool);
173
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);
178
179     BLINK_PLATFORM_EXPORT RequestContext requestContext() const;
180     BLINK_PLATFORM_EXPORT void setRequestContext(RequestContext);
181
182     BLINK_PLATFORM_EXPORT FrameType frameType() const;
183     BLINK_PLATFORM_EXPORT void setFrameType(FrameType);
184
185     BLINK_PLATFORM_EXPORT WebReferrerPolicy referrerPolicy() const;
186
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);
190
191     // True if the request was user initiated.
192     BLINK_PLATFORM_EXPORT bool hasUserGesture() const;
193     BLINK_PLATFORM_EXPORT void setHasUserGesture(bool);
194
195     // A consumer controlled value intended to be used to identify the
196     // requestor.
197     BLINK_PLATFORM_EXPORT int requestorID() const;
198     BLINK_PLATFORM_EXPORT void setRequestorID(int);
199
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);
204
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);
208
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);
213
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*);
222
223     BLINK_PLATFORM_EXPORT Priority priority() const;
224     BLINK_PLATFORM_EXPORT void setPriority(Priority);
225
226 #if INSIDE_BLINK
227     BLINK_PLATFORM_EXPORT ResourceRequest& toMutableResourceRequest();
228     BLINK_PLATFORM_EXPORT const ResourceRequest& toResourceRequest() const;
229 #endif
230
231 protected:
232     BLINK_PLATFORM_EXPORT void assign(WebURLRequestPrivate*);
233
234 private:
235     WebURLRequestPrivate* m_private;
236 };
237
238 } // namespace blink
239
240 #endif