OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. | |
3 * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> | |
4 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | |
5 * | |
6 * Redistribution and use in source and binary forms, with or without | |
7 * modification, are permitted provided that the following conditions | |
8 * are met: | |
9 * 1. Redistributions of source code must retain the above copyright | |
10 * notice, this list of conditions and the following disclaimer. | |
11 * 2. Redistributions in binary form must reproduce the above copyright | |
12 * notice, this list of conditions and the following disclaimer in the | |
13 * documentation and/or other materials provided with the distribution. | |
14 * | |
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 #ifndef SKY_ENGINE_PLATFORM_NETWORK_RESOURCEREQUEST_H_ | |
29 #define SKY_ENGINE_PLATFORM_NETWORK_RESOURCEREQUEST_H_ | |
30 | |
31 #include "sky/engine/platform/network/FormData.h" | |
32 #include "sky/engine/platform/network/HTTPHeaderMap.h" | |
33 #include "sky/engine/platform/network/HTTPParsers.h" | |
34 #include "sky/engine/platform/network/ResourceLoadPriority.h" | |
35 #include "sky/engine/platform/weborigin/KURL.h" | |
36 #include "sky/engine/platform/weborigin/Referrer.h" | |
37 #include "sky/engine/public/platform/WebURLRequest.h" | |
38 #include "sky/engine/wtf/OwnPtr.h" | |
39 | |
40 namespace blink { | |
41 | |
42 enum ResourceRequestCachePolicy { | |
43 UseProtocolCachePolicy, // normal load | |
44 ReloadIgnoringCacheData, // reload | |
45 ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale da
ta | |
46 ReturnCacheDataDontLoad, // results of a post - allow stale data and only us
e cache | |
47 ReloadBypassingCache, // end-to-end reload | |
48 }; | |
49 | |
50 class PLATFORM_EXPORT ResourceRequest { | |
51 WTF_MAKE_FAST_ALLOCATED; | |
52 public: | |
53 class ExtraData : public RefCounted<ExtraData> { | |
54 public: | |
55 virtual ~ExtraData() { } | |
56 }; | |
57 | |
58 ResourceRequest() | |
59 { | |
60 initialize(KURL(), UseProtocolCachePolicy); | |
61 } | |
62 | |
63 ResourceRequest(const String& urlString) | |
64 { | |
65 initialize(KURL(ParsedURLString, urlString), UseProtocolCachePolicy); | |
66 } | |
67 | |
68 ResourceRequest(const KURL& url) | |
69 { | |
70 initialize(url, UseProtocolCachePolicy); | |
71 } | |
72 | |
73 ResourceRequest(const KURL& url, const Referrer& referrer, ResourceRequestCa
chePolicy cachePolicy = UseProtocolCachePolicy) | |
74 { | |
75 initialize(url, cachePolicy); | |
76 setHTTPReferrer(referrer); | |
77 } | |
78 | |
79 bool isNull() const; | |
80 bool isEmpty() const; | |
81 | |
82 const KURL& url() const; | |
83 void setURL(const KURL& url); | |
84 | |
85 void removeCredentials(); | |
86 | |
87 ResourceRequestCachePolicy cachePolicy() const; | |
88 void setCachePolicy(ResourceRequestCachePolicy cachePolicy); | |
89 | |
90 double timeoutInterval() const; // May return 0 when using platform default. | |
91 void setTimeoutInterval(double timeoutInterval); | |
92 | |
93 const AtomicString& httpMethod() const; | |
94 void setHTTPMethod(const AtomicString&); | |
95 | |
96 const HTTPHeaderMap& httpHeaderFields() const; | |
97 const AtomicString& httpHeaderField(const AtomicString& name) const; | |
98 const AtomicString& httpHeaderField(const char* name) const; | |
99 void setHTTPHeaderField(const AtomicString& name, const AtomicString& value)
; | |
100 void setHTTPHeaderField(const char* name, const AtomicString& value); | |
101 void addHTTPHeaderField(const AtomicString& name, const AtomicString& value)
; | |
102 void addHTTPHeaderFields(const HTTPHeaderMap& headerFields); | |
103 void clearHTTPHeaderField(const AtomicString& name); | |
104 | |
105 void clearHTTPAuthorization(); | |
106 | |
107 const AtomicString& httpContentType() const { return httpHeaderField("Conten
t-Type"); } | |
108 void setHTTPContentType(const AtomicString& httpContentType) { setHTTPHeader
Field("Content-Type", httpContentType); } | |
109 | |
110 const AtomicString& httpReferrer() const { return httpHeaderField("Referer")
; } | |
111 ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; } | |
112 void setHTTPReferrer(const Referrer& httpReferrer) { setHTTPHeaderField("Ref
erer", httpReferrer.referrer); m_referrerPolicy = httpReferrer.referrerPolicy; } | |
113 void clearHTTPReferrer(); | |
114 | |
115 const AtomicString& httpOrigin() const { return httpHeaderField("Origin"); } | |
116 void setHTTPOrigin(const AtomicString& httpOrigin) { setHTTPHeaderField("Ori
gin", httpOrigin); } | |
117 void clearHTTPOrigin(); | |
118 void addHTTPOriginIfNeeded(const AtomicString& origin); | |
119 | |
120 const AtomicString& httpAccept() const { return httpHeaderField("Accept"); } | |
121 void setHTTPAccept(const AtomicString& httpAccept) { setHTTPHeaderField("Acc
ept", httpAccept); } | |
122 | |
123 FormData* httpBody() const; | |
124 void setHTTPBody(PassRefPtr<FormData> httpBody); | |
125 | |
126 bool allowStoredCredentials() const; | |
127 void setAllowStoredCredentials(bool allowCredentials); | |
128 | |
129 ResourceLoadPriority priority() const; | |
130 void setPriority(ResourceLoadPriority, int intraPriorityValue = 0); | |
131 | |
132 bool isConditional() const; | |
133 | |
134 // Whether the associated ResourceHandleClient needs to be notified of | |
135 // upload progress made for that resource. | |
136 bool reportUploadProgress() const { return m_reportUploadProgress; } | |
137 void setReportUploadProgress(bool reportUploadProgress) { m_reportUploadProg
ress = reportUploadProgress; } | |
138 | |
139 // Whether actual headers being sent/received should be collected and report
ed for the request. | |
140 bool reportRawHeaders() const { return m_reportRawHeaders; } | |
141 void setReportRawHeaders(bool reportRawHeaders) { m_reportRawHeaders = repor
tRawHeaders; } | |
142 | |
143 // Allows the request to be matched up with its requestor. | |
144 int requestorID() const { return m_requestorID; } | |
145 void setRequestorID(int requestorID) { m_requestorID = requestorID; } | |
146 | |
147 // The process id of the process from which this request originated. In | |
148 // the case of out-of-process plugins, this allows to link back the | |
149 // request to the plugin process (as it is processed through a render | |
150 // view process). | |
151 int requestorProcessID() const { return m_requestorProcessID; } | |
152 void setRequestorProcessID(int requestorProcessID) { m_requestorProcessID =
requestorProcessID; } | |
153 | |
154 // True if request should be downloaded to file. | |
155 bool downloadToFile() const { return m_downloadToFile; } | |
156 void setDownloadToFile(bool downloadToFile) { m_downloadToFile = downloadToF
ile; } | |
157 | |
158 // Extra data associated with this request. | |
159 ExtraData* extraData() const { return m_extraData.get(); } | |
160 void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData
; } | |
161 | |
162 blink::WebURLRequest::RequestContext requestContext() const { return m_reque
stContext; } | |
163 void setRequestContext(blink::WebURLRequest::RequestContext context) { m_req
uestContext = context; } | |
164 | |
165 blink::WebURLRequest::FrameType frameType() const { return m_frameType; } | |
166 void setFrameType(blink::WebURLRequest::FrameType frameType) { m_frameType =
frameType; } | |
167 | |
168 bool cacheControlContainsNoCache() const; | |
169 bool cacheControlContainsNoStore() const; | |
170 bool hasCacheValidatorFields() const; | |
171 | |
172 static double defaultTimeoutInterval(); // May return 0 when using platform
default. | |
173 static void setDefaultTimeoutInterval(double); | |
174 | |
175 static bool compare(const ResourceRequest&, const ResourceRequest&); | |
176 | |
177 private: | |
178 void initialize(const KURL& url, ResourceRequestCachePolicy cachePolicy); | |
179 | |
180 const CacheControlHeader& cacheControlHeader() const; | |
181 | |
182 KURL m_url; | |
183 ResourceRequestCachePolicy m_cachePolicy; | |
184 double m_timeoutInterval; // 0 is a magic value for platform default on plat
forms that have one. | |
185 AtomicString m_httpMethod; | |
186 HTTPHeaderMap m_httpHeaderFields; | |
187 RefPtr<FormData> m_httpBody; | |
188 bool m_allowStoredCredentials : 1; | |
189 bool m_reportUploadProgress : 1; | |
190 bool m_reportRawHeaders : 1; | |
191 bool m_downloadToFile : 1; | |
192 ResourceLoadPriority m_priority; | |
193 int m_intraPriorityValue; | |
194 int m_requestorID; | |
195 int m_requestorProcessID; | |
196 RefPtr<ExtraData> m_extraData; | |
197 blink::WebURLRequest::RequestContext m_requestContext; | |
198 blink::WebURLRequest::FrameType m_frameType; | |
199 ReferrerPolicy m_referrerPolicy; | |
200 | |
201 mutable CacheControlHeader m_cacheControlHeaderCache; | |
202 | |
203 static double s_defaultTimeoutInterval; | |
204 }; | |
205 | |
206 bool equalIgnoringHeaderFields(const ResourceRequest&, const ResourceRequest&); | |
207 | |
208 inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { ret
urn ResourceRequest::compare(a, b); } | |
209 inline bool operator!=(ResourceRequest& a, const ResourceRequest& b) { return !(
a == b); } | |
210 | |
211 } // namespace blink | |
212 | |
213 #endif // SKY_ENGINE_PLATFORM_NETWORK_RESOURCEREQUEST_H_ | |
OLD | NEW |