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