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
37#if defined(WEBKIT_IMPLEMENTATION)
38namespace WebCore { class ResourceRequest; }
39#endif
40
41namespace WebKit {
42
43class WebCString;
44class WebHTTPBody;
45class WebHTTPHeaderVisitor;
46class WebString;
47class WebURL;
48class WebURLRequestPrivate;
49
50class WebURLRequest {
51public:
52    enum CachePolicy {
53        UseProtocolCachePolicy,  // normal load
54        ReloadIgnoringCacheData, // reload
55        ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale data
56        ReturnCacheDataDontLoad, // results of a post - allow stale data and only use cache
57    };
58
59    enum TargetType {
60        TargetIsMainFrame = 0,
61        TargetIsSubframe = 1,
62        TargetIsSubresource = 2,
63        TargetIsStyleSheet = 3,
64        TargetIsScript = 4,
65        TargetIsFontResource = 5,
66        TargetIsImage = 6,
67        TargetIsObject = 7,
68        TargetIsMedia = 8,
69        TargetIsWorker = 9,
70        TargetIsSharedWorker = 10,
71        TargetIsPrefetch = 11,
72        TargetIsFavicon = 12,
73    };
74
75    ~WebURLRequest() { reset(); }
76
77    WebURLRequest() : m_private(0) { }
78    WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); }
79    WebURLRequest& operator=(const WebURLRequest& r)
80    {
81        assign(r);
82        return *this;
83    }
84
85    explicit WebURLRequest(const WebURL& url) : m_private(0)
86    {
87        initialize();
88        setURL(url);
89    }
90
91    WEBKIT_API void initialize();
92    WEBKIT_API void reset();
93    WEBKIT_API void assign(const WebURLRequest&);
94
95    WEBKIT_API bool isNull() const;
96
97    WEBKIT_API WebURL url() const;
98    WEBKIT_API void setURL(const WebURL&);
99
100    // Used to implement third-party cookie blocking.
101    WEBKIT_API WebURL firstPartyForCookies() const;
102    WEBKIT_API void setFirstPartyForCookies(const WebURL&);
103
104    WEBKIT_API bool allowCookies() const;
105    WEBKIT_API void setAllowCookies(bool allowCookies);
106
107    // Controls whether user name, password, and cookies may be sent with the
108    // request. (If false, this overrides allowCookies.)
109    WEBKIT_API bool allowStoredCredentials() const;
110    WEBKIT_API void setAllowStoredCredentials(bool allowStoredCredentials);
111
112    WEBKIT_API CachePolicy cachePolicy() const;
113    WEBKIT_API void setCachePolicy(CachePolicy);
114
115    WEBKIT_API WebString httpMethod() const;
116    WEBKIT_API void setHTTPMethod(const WebString&);
117
118    WEBKIT_API WebString httpHeaderField(const WebString& name) const;
119    WEBKIT_API void setHTTPHeaderField(const WebString& name, const WebString& value);
120    WEBKIT_API void addHTTPHeaderField(const WebString& name, const WebString& value);
121    WEBKIT_API void clearHTTPHeaderField(const WebString& name);
122    WEBKIT_API void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const;
123
124    WEBKIT_API WebHTTPBody httpBody() const;
125    WEBKIT_API void setHTTPBody(const WebHTTPBody&);
126
127    // Controls whether upload progress events are generated when a request
128    // has a body.
129    WEBKIT_API bool reportUploadProgress() const;
130    WEBKIT_API void setReportUploadProgress(bool);
131
132    // Controls whether load timing info is collected for the request.
133    WEBKIT_API bool reportLoadTiming() const;
134    WEBKIT_API void setReportLoadTiming(bool);
135
136    // Controls whether actual headers sent and received for request are
137    // collected and reported.
138    WEBKIT_API bool reportRawHeaders() const;
139    WEBKIT_API void setReportRawHeaders(bool);
140
141    WEBKIT_API TargetType targetType() const;
142    WEBKIT_API void setTargetType(TargetType);
143
144    // True if the request was user initiated.
145    WEBKIT_API bool hasUserGesture() const;
146    WEBKIT_API void setHasUserGesture(bool);
147
148    // A consumer controlled value intended to be used to identify the
149    // requestor.
150    WEBKIT_API int requestorID() const;
151    WEBKIT_API void setRequestorID(int);
152
153    // A consumer controlled value intended to be used to identify the
154    // process of the requestor.
155    WEBKIT_API int requestorProcessID() const;
156    WEBKIT_API void setRequestorProcessID(int);
157
158    // Allows the request to be matched up with its app cache host.
159    WEBKIT_API int appCacheHostID() const;
160    WEBKIT_API void setAppCacheHostID(int id);
161
162    // If true, the response body will be downloaded to a file managed by the
163    // WebURLLoader.  See WebURLResponse::downloadedFilePath.
164    WEBKIT_API bool downloadToFile() const;
165    WEBKIT_API void setDownloadToFile(bool);
166
167#if defined(WEBKIT_IMPLEMENTATION)
168    WebCore::ResourceRequest& toMutableResourceRequest();
169    const WebCore::ResourceRequest& toResourceRequest() const;
170#endif
171
172protected:
173    void assign(WebURLRequestPrivate*);
174
175private:
176    WebURLRequestPrivate* m_private;
177};
178
179} // namespace WebKit
180
181#endif
182