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 ResourceRequest_h |
| 29 #define ResourceRequest_h |
| 30 |
| 31 #include "platform/network/FormData.h" |
| 32 #include "platform/network/HTTPHeaderMap.h" |
| 33 #include "platform/network/ResourceLoadPriority.h" |
| 34 #include "weborigin/KURL.h" |
| 35 #include "wtf/OwnPtr.h" |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 enum ResourceRequestCachePolicy { |
| 40 UseProtocolCachePolicy, // normal load |
| 41 ReloadIgnoringCacheData, // reload |
| 42 ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale da
ta |
| 43 ReturnCacheDataDontLoad // results of a post - allow stale data and only us
e cache |
| 44 }; |
| 45 |
| 46 struct CrossThreadResourceRequestData; |
| 47 |
| 48 class PLATFORM_EXPORT ResourceRequest { |
| 49 WTF_MAKE_FAST_ALLOCATED; |
| 50 public: |
| 51 // The type of this ResourceRequest, based on how the resource will be used. |
| 52 enum TargetType { |
| 53 TargetIsMainFrame, |
| 54 TargetIsSubframe, |
| 55 TargetIsSubresource, // Resource is a generic subresource. (Generally a
specific type should be specified) |
| 56 TargetIsStyleSheet, |
| 57 TargetIsScript, |
| 58 TargetIsFont, |
| 59 TargetIsImage, |
| 60 TargetIsObject, |
| 61 TargetIsMedia, |
| 62 TargetIsWorker, |
| 63 TargetIsSharedWorker, |
| 64 TargetIsPrefetch, |
| 65 TargetIsFavicon, |
| 66 TargetIsXHR, |
| 67 TargetIsTextTrack, |
| 68 TargetIsUnspecified, |
| 69 }; |
| 70 |
| 71 class ExtraData : public RefCounted<ExtraData> { |
| 72 public: |
| 73 virtual ~ExtraData() { } |
| 74 }; |
| 75 |
| 76 ResourceRequest() |
| 77 { |
| 78 initialize(KURL(), UseProtocolCachePolicy); |
| 79 } |
| 80 |
| 81 ResourceRequest(const String& urlString) |
| 82 { |
| 83 initialize(KURL(ParsedURLString, urlString), UseProtocolCachePolicy); |
| 84 } |
| 85 |
| 86 ResourceRequest(const KURL& url) |
| 87 { |
| 88 initialize(url, UseProtocolCachePolicy); |
| 89 } |
| 90 |
| 91 ResourceRequest(const KURL& url, const String& referrer, ResourceRequestCach
ePolicy cachePolicy = UseProtocolCachePolicy) |
| 92 { |
| 93 initialize(url, cachePolicy); |
| 94 setHTTPReferrer(referrer); |
| 95 } |
| 96 |
| 97 static PassOwnPtr<ResourceRequest> adopt(PassOwnPtr<CrossThreadResourceReque
stData>); |
| 98 |
| 99 // Gets a copy of the data suitable for passing to another thread. |
| 100 PassOwnPtr<CrossThreadResourceRequestData> copyData() const; |
| 101 |
| 102 bool isNull() const; |
| 103 bool isEmpty() const; |
| 104 |
| 105 const KURL& url() const; |
| 106 void setURL(const KURL& url); |
| 107 |
| 108 void removeCredentials(); |
| 109 |
| 110 ResourceRequestCachePolicy cachePolicy() const; |
| 111 void setCachePolicy(ResourceRequestCachePolicy cachePolicy); |
| 112 |
| 113 double timeoutInterval() const; // May return 0 when using platform default. |
| 114 void setTimeoutInterval(double timeoutInterval); |
| 115 |
| 116 const KURL& firstPartyForCookies() const; |
| 117 void setFirstPartyForCookies(const KURL& firstPartyForCookies); |
| 118 |
| 119 const String& httpMethod() const; |
| 120 void setHTTPMethod(const String& httpMethod); |
| 121 |
| 122 const HTTPHeaderMap& httpHeaderFields() const; |
| 123 String httpHeaderField(const AtomicString& name) const; |
| 124 String httpHeaderField(const char* name) const; |
| 125 void setHTTPHeaderField(const AtomicString& name, const String& value); |
| 126 void setHTTPHeaderField(const char* name, const String& value); |
| 127 void addHTTPHeaderField(const AtomicString& name, const String& value); |
| 128 void addHTTPHeaderFields(const HTTPHeaderMap& headerFields); |
| 129 void clearHTTPHeaderField(const AtomicString& name); |
| 130 |
| 131 void clearHTTPAuthorization(); |
| 132 |
| 133 String httpContentType() const { return httpHeaderField("Content-Type"); } |
| 134 void setHTTPContentType(const String& httpContentType) { setHTTPHeaderField(
"Content-Type", httpContentType); } |
| 135 void clearHTTPContentType(); |
| 136 |
| 137 String httpReferrer() const { return httpHeaderField("Referer"); } |
| 138 void setHTTPReferrer(const String& httpReferrer) { setHTTPHeaderField("Refer
er", httpReferrer); } |
| 139 void clearHTTPReferrer(); |
| 140 |
| 141 String httpOrigin() const { return httpHeaderField("Origin"); } |
| 142 void setHTTPOrigin(const String& httpOrigin) { setHTTPHeaderField("Origin",
httpOrigin); } |
| 143 void clearHTTPOrigin(); |
| 144 |
| 145 String httpUserAgent() const { return httpHeaderField("User-Agent"); } |
| 146 void setHTTPUserAgent(const String& httpUserAgent) { setHTTPHeaderField("Use
r-Agent", httpUserAgent); } |
| 147 void clearHTTPUserAgent(); |
| 148 |
| 149 String httpAccept() const { return httpHeaderField("Accept"); } |
| 150 void setHTTPAccept(const String& httpAccept) { setHTTPHeaderField("Accept",
httpAccept); } |
| 151 void clearHTTPAccept(); |
| 152 |
| 153 FormData* httpBody() const; |
| 154 void setHTTPBody(PassRefPtr<FormData> httpBody); |
| 155 |
| 156 bool allowCookies() const; |
| 157 void setAllowCookies(bool allowCookies); |
| 158 |
| 159 ResourceLoadPriority priority() const; |
| 160 void setPriority(ResourceLoadPriority); |
| 161 |
| 162 bool isConditional() const; |
| 163 |
| 164 // Whether the associated ResourceHandleClient needs to be notified of |
| 165 // upload progress made for that resource. |
| 166 bool reportUploadProgress() const { return m_reportUploadProgress; } |
| 167 void setReportUploadProgress(bool reportUploadProgress) { m_reportUploadProg
ress = reportUploadProgress; } |
| 168 |
| 169 // Whether the timing information should be collected for the request. |
| 170 bool reportLoadTiming() const { return m_reportLoadTiming; } |
| 171 void setReportLoadTiming(bool reportLoadTiming) { m_reportLoadTiming = repor
tLoadTiming; } |
| 172 |
| 173 // Whether actual headers being sent/received should be collected and report
ed for the request. |
| 174 bool reportRawHeaders() const { return m_reportRawHeaders; } |
| 175 void setReportRawHeaders(bool reportRawHeaders) { m_reportRawHeaders = repor
tRawHeaders; } |
| 176 |
| 177 // Allows the request to be matched up with its requestor. |
| 178 int requestorID() const { return m_requestorID; } |
| 179 void setRequestorID(int requestorID) { m_requestorID = requestorID; } |
| 180 |
| 181 // The process id of the process from which this request originated. In |
| 182 // the case of out-of-process plugins, this allows to link back the |
| 183 // request to the plugin process (as it is processed through a render |
| 184 // view process). |
| 185 int requestorProcessID() const { return m_requestorProcessID; } |
| 186 void setRequestorProcessID(int requestorProcessID) { m_requestorProcessID =
requestorProcessID; } |
| 187 |
| 188 // Allows the request to be matched up with its app cache host. |
| 189 int appCacheHostID() const { return m_appCacheHostID; } |
| 190 void setAppCacheHostID(int id) { m_appCacheHostID = id; } |
| 191 |
| 192 // True if request was user initiated. |
| 193 bool hasUserGesture() const { return m_hasUserGesture; } |
| 194 void setHasUserGesture(bool hasUserGesture) { m_hasUserGesture = hasUserGest
ure; } |
| 195 |
| 196 // True if request should be downloaded to file. |
| 197 bool downloadToFile() const { return m_downloadToFile; } |
| 198 void setDownloadToFile(bool downloadToFile) { m_downloadToFile = downloadToF
ile; } |
| 199 |
| 200 // Extra data associated with this request. |
| 201 ExtraData* extraData() const { return m_extraData.get(); } |
| 202 void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData
; } |
| 203 |
| 204 // What this request is for. |
| 205 TargetType targetType() const { return m_targetType; } |
| 206 void setTargetType(TargetType type) { m_targetType = type; } |
| 207 |
| 208 static double defaultTimeoutInterval(); // May return 0 when using platform
default. |
| 209 static void setDefaultTimeoutInterval(double); |
| 210 |
| 211 static bool compare(const ResourceRequest&, const ResourceRequest&); |
| 212 |
| 213 private: |
| 214 void initialize(const KURL& url, ResourceRequestCachePolicy cachePolicy); |
| 215 |
| 216 KURL m_url; |
| 217 ResourceRequestCachePolicy m_cachePolicy; |
| 218 double m_timeoutInterval; // 0 is a magic value for platform default on plat
forms that have one. |
| 219 KURL m_firstPartyForCookies; |
| 220 AtomicString m_httpMethod; |
| 221 HTTPHeaderMap m_httpHeaderFields; |
| 222 RefPtr<FormData> m_httpBody; |
| 223 bool m_allowCookies : 1; |
| 224 bool m_reportUploadProgress : 1; |
| 225 bool m_reportLoadTiming : 1; |
| 226 bool m_reportRawHeaders : 1; |
| 227 bool m_hasUserGesture : 1; |
| 228 bool m_downloadToFile : 1; |
| 229 ResourceLoadPriority m_priority; |
| 230 int m_requestorID; |
| 231 int m_requestorProcessID; |
| 232 int m_appCacheHostID; |
| 233 RefPtr<ExtraData> m_extraData; |
| 234 TargetType m_targetType; |
| 235 |
| 236 static double s_defaultTimeoutInterval; |
| 237 }; |
| 238 |
| 239 bool equalIgnoringHeaderFields(const ResourceRequest&, const ResourceRequest&); |
| 240 |
| 241 inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { ret
urn ResourceRequest::compare(a, b); } |
| 242 inline bool operator!=(ResourceRequest& a, const ResourceRequest& b) { return !(
a == b); } |
| 243 |
| 244 struct CrossThreadResourceRequestData { |
| 245 WTF_MAKE_NONCOPYABLE(CrossThreadResourceRequestData); WTF_MAKE_FAST_ALLOCATE
D; |
| 246 public: |
| 247 CrossThreadResourceRequestData() { } |
| 248 KURL m_url; |
| 249 |
| 250 ResourceRequestCachePolicy m_cachePolicy; |
| 251 double m_timeoutInterval; |
| 252 KURL m_firstPartyForCookies; |
| 253 |
| 254 String m_httpMethod; |
| 255 OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders; |
| 256 RefPtr<FormData> m_httpBody; |
| 257 bool m_allowCookies; |
| 258 bool m_hasUserGesture; |
| 259 bool m_downloadToFile; |
| 260 ResourceLoadPriority m_priority; |
| 261 int m_requestorID; |
| 262 int m_requestorProcessID; |
| 263 int m_appCacheHostID; |
| 264 ResourceRequest::TargetType m_targetType; |
| 265 }; |
| 266 |
| 267 unsigned initializeMaximumHTTPConnectionCountPerHost(); |
| 268 |
| 269 } // namespace WebCore |
| 270 |
| 271 #endif // ResourceRequest_h |
OLD | NEW |