| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | |
| 3 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions | |
| 7 * are met: | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * | |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 25 */ | |
| 26 | |
| 27 #ifndef ResourceResponse_h | |
| 28 #define ResourceResponse_h | |
| 29 | |
| 30 #include "core/platform/network/ResourceLoadInfo.h" | |
| 31 #include "core/platform/network/ResourceLoadTiming.h" | |
| 32 #include "platform/blob/BlobData.h" | |
| 33 #include "platform/network/HTTPHeaderMap.h" | |
| 34 #include "weborigin/KURL.h" | |
| 35 #include "wtf/PassOwnPtr.h" | |
| 36 #include "wtf/RefPtr.h" | |
| 37 #include "wtf/text/CString.h" | |
| 38 | |
| 39 namespace WebCore { | |
| 40 | |
| 41 struct CrossThreadResourceResponseData; | |
| 42 | |
| 43 class ResourceResponse { | |
| 44 WTF_MAKE_FAST_ALLOCATED; | |
| 45 public: | |
| 46 enum HTTPVersion { Unknown, HTTP_0_9, HTTP_1_0, HTTP_1_1 }; | |
| 47 | |
| 48 class ExtraData : public RefCounted<ExtraData> { | |
| 49 public: | |
| 50 virtual ~ExtraData() { } | |
| 51 }; | |
| 52 | |
| 53 static PassOwnPtr<ResourceResponse> adopt(PassOwnPtr<CrossThreadResourceResp
onseData>); | |
| 54 | |
| 55 // Gets a copy of the data suitable for passing to another thread. | |
| 56 PassOwnPtr<CrossThreadResourceResponseData> copyData() const; | |
| 57 | |
| 58 ResourceResponse(); | |
| 59 ResourceResponse(const KURL&, const AtomicString& mimeType, long long expect
edLength, const AtomicString& textEncodingName, const String& filename); | |
| 60 | |
| 61 bool isNull() const { return m_isNull; } | |
| 62 bool isHTTP() const; | |
| 63 | |
| 64 const KURL& url() const; | |
| 65 void setURL(const KURL&); | |
| 66 | |
| 67 const AtomicString& mimeType() const; | |
| 68 void setMimeType(const AtomicString&); | |
| 69 | |
| 70 long long expectedContentLength() const; | |
| 71 void setExpectedContentLength(long long); | |
| 72 | |
| 73 const AtomicString& textEncodingName() const; | |
| 74 void setTextEncodingName(const AtomicString&); | |
| 75 | |
| 76 // FIXME: Should compute this on the fly. | |
| 77 // There should not be a setter exposed, as suggested file name is determine
d based on other headers in a manner that WebCore does not necessarily know abou
t. | |
| 78 const String& suggestedFilename() const; | |
| 79 void setSuggestedFilename(const String&); | |
| 80 | |
| 81 int httpStatusCode() const; | |
| 82 void setHTTPStatusCode(int); | |
| 83 | |
| 84 const AtomicString& httpStatusText() const; | |
| 85 void setHTTPStatusText(const AtomicString&); | |
| 86 | |
| 87 String httpHeaderField(const AtomicString& name) const; | |
| 88 String httpHeaderField(const char* name) const; | |
| 89 void setHTTPHeaderField(const AtomicString& name, const String& value); | |
| 90 void addHTTPHeaderField(const AtomicString& name, const String& value); | |
| 91 void clearHTTPHeaderField(const AtomicString& name); | |
| 92 const HTTPHeaderMap& httpHeaderFields() const; | |
| 93 | |
| 94 bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace";
} | |
| 95 | |
| 96 bool isAttachment() const; | |
| 97 | |
| 98 // FIXME: These are used by PluginStream on some platforms. Calculations may
differ from just returning plain Last-Modified header. | |
| 99 // Leaving it for now but this should go away in favor of generic solution. | |
| 100 void setLastModifiedDate(time_t); | |
| 101 time_t lastModifiedDate() const; | |
| 102 | |
| 103 // These functions return parsed values of the corresponding response header
s. | |
| 104 // NaN means that the header was not present or had invalid value. | |
| 105 bool cacheControlContainsNoCache() const; | |
| 106 bool cacheControlContainsNoStore() const; | |
| 107 bool cacheControlContainsMustRevalidate() const; | |
| 108 bool hasCacheValidatorFields() const; | |
| 109 double cacheControlMaxAge() const; | |
| 110 double date() const; | |
| 111 double age() const; | |
| 112 double expires() const; | |
| 113 double lastModified() const; | |
| 114 | |
| 115 unsigned connectionID() const; | |
| 116 void setConnectionID(unsigned); | |
| 117 | |
| 118 bool connectionReused() const; | |
| 119 void setConnectionReused(bool); | |
| 120 | |
| 121 bool wasCached() const; | |
| 122 void setWasCached(bool); | |
| 123 | |
| 124 ResourceLoadTiming* resourceLoadTiming() const; | |
| 125 void setResourceLoadTiming(PassRefPtr<ResourceLoadTiming>); | |
| 126 | |
| 127 PassRefPtr<ResourceLoadInfo> resourceLoadInfo() const; | |
| 128 void setResourceLoadInfo(PassRefPtr<ResourceLoadInfo>); | |
| 129 | |
| 130 HTTPVersion httpVersion() const { return m_httpVersion; } | |
| 131 void setHTTPVersion(HTTPVersion version) { m_httpVersion = version; } | |
| 132 | |
| 133 const CString& getSecurityInfo() const { return m_securityInfo; } | |
| 134 void setSecurityInfo(const CString& securityInfo) { m_securityInfo = securit
yInfo; } | |
| 135 | |
| 136 long long appCacheID() const { return m_appCacheID; } | |
| 137 void setAppCacheID(long long id) { m_appCacheID = id; } | |
| 138 | |
| 139 const KURL& appCacheManifestURL() const { return m_appCacheManifestURL; } | |
| 140 void setAppCacheManifestURL(const KURL& url) { m_appCacheManifestURL = url;
} | |
| 141 | |
| 142 bool wasFetchedViaSPDY() const { return m_wasFetchedViaSPDY; } | |
| 143 void setWasFetchedViaSPDY(bool value) { m_wasFetchedViaSPDY = value; } | |
| 144 | |
| 145 bool wasNpnNegotiated() const { return m_wasNpnNegotiated; } | |
| 146 void setWasNpnNegotiated(bool value) { m_wasNpnNegotiated = value; } | |
| 147 | |
| 148 bool wasAlternateProtocolAvailable() const | |
| 149 { | |
| 150 return m_wasAlternateProtocolAvailable; | |
| 151 } | |
| 152 void setWasAlternateProtocolAvailable(bool value) | |
| 153 { | |
| 154 m_wasAlternateProtocolAvailable = value; | |
| 155 } | |
| 156 | |
| 157 bool wasFetchedViaProxy() const { return m_wasFetchedViaProxy; } | |
| 158 void setWasFetchedViaProxy(bool value) { m_wasFetchedViaProxy = value; } | |
| 159 | |
| 160 bool isMultipartPayload() const { return m_isMultipartPayload; } | |
| 161 void setIsMultipartPayload(bool value) { m_isMultipartPayload = value; } | |
| 162 | |
| 163 double responseTime() const { return m_responseTime; } | |
| 164 void setResponseTime(double responseTime) { m_responseTime = responseTime; } | |
| 165 | |
| 166 const AtomicString& remoteIPAddress() const { return m_remoteIPAddress; } | |
| 167 void setRemoteIPAddress(const AtomicString& value) { m_remoteIPAddress = val
ue; } | |
| 168 | |
| 169 unsigned short remotePort() const { return m_remotePort; } | |
| 170 void setRemotePort(unsigned short value) { m_remotePort = value; } | |
| 171 | |
| 172 const String& downloadedFilePath() const { return m_downloadedFilePath; } | |
| 173 void setDownloadedFilePath(const String&); | |
| 174 | |
| 175 // Extra data associated with this response. | |
| 176 ExtraData* extraData() const { return m_extraData.get(); } | |
| 177 void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData
; } | |
| 178 | |
| 179 // The ResourceResponse subclass may "shadow" this method to provide platfor
m-specific memory usage information | |
| 180 unsigned memoryUsage() const | |
| 181 { | |
| 182 // average size, mostly due to URL and Header Map strings | |
| 183 return 1280; | |
| 184 } | |
| 185 | |
| 186 static bool compare(const ResourceResponse&, const ResourceResponse&); | |
| 187 | |
| 188 private: | |
| 189 void parseCacheControlDirectives() const; | |
| 190 void updateHeaderParsedState(const AtomicString& name); | |
| 191 | |
| 192 KURL m_url; | |
| 193 AtomicString m_mimeType; | |
| 194 long long m_expectedContentLength; | |
| 195 AtomicString m_textEncodingName; | |
| 196 String m_suggestedFilename; | |
| 197 int m_httpStatusCode; | |
| 198 AtomicString m_httpStatusText; | |
| 199 HTTPHeaderMap m_httpHeaderFields; | |
| 200 time_t m_lastModifiedDate; | |
| 201 bool m_wasCached : 1; | |
| 202 unsigned m_connectionID; | |
| 203 bool m_connectionReused : 1; | |
| 204 RefPtr<ResourceLoadTiming> m_resourceLoadTiming; | |
| 205 RefPtr<ResourceLoadInfo> m_resourceLoadInfo; | |
| 206 | |
| 207 bool m_isNull : 1; | |
| 208 | |
| 209 mutable bool m_haveParsedCacheControlHeader : 1; | |
| 210 mutable bool m_haveParsedAgeHeader : 1; | |
| 211 mutable bool m_haveParsedDateHeader : 1; | |
| 212 mutable bool m_haveParsedExpiresHeader : 1; | |
| 213 mutable bool m_haveParsedLastModifiedHeader : 1; | |
| 214 | |
| 215 mutable bool m_cacheControlContainsNoCache : 1; | |
| 216 mutable bool m_cacheControlContainsNoStore : 1; | |
| 217 mutable bool m_cacheControlContainsMustRevalidate : 1; | |
| 218 mutable double m_cacheControlMaxAge; | |
| 219 | |
| 220 mutable double m_age; | |
| 221 mutable double m_date; | |
| 222 mutable double m_expires; | |
| 223 mutable double m_lastModified; | |
| 224 | |
| 225 // An opaque value that contains some information regarding the security of | |
| 226 // the connection for this request, such as SSL connection info (empty | |
| 227 // string if not over HTTPS). | |
| 228 CString m_securityInfo; | |
| 229 | |
| 230 // HTTP version used in the response, if known. | |
| 231 HTTPVersion m_httpVersion; | |
| 232 | |
| 233 // The id of the appcache this response was retrieved from, or zero if | |
| 234 // the response was not retrieved from an appcache. | |
| 235 long long m_appCacheID; | |
| 236 | |
| 237 // The manifest url of the appcache this response was retrieved from, if any
. | |
| 238 // Note: only valid for main resource responses. | |
| 239 KURL m_appCacheManifestURL; | |
| 240 | |
| 241 // Set to true if this is part of a multipart response. | |
| 242 bool m_isMultipartPayload; | |
| 243 | |
| 244 // Was the resource fetched over SPDY. See http://dev.chromium.org/spdy | |
| 245 bool m_wasFetchedViaSPDY; | |
| 246 | |
| 247 // Was the resource fetched over a channel which used TLS/Next-Protocol-Nego
tiation (also SPDY related). | |
| 248 bool m_wasNpnNegotiated; | |
| 249 | |
| 250 // Was the resource fetched over a channel which specified "Alternate-Protoc
ol" | |
| 251 // (e.g.: Alternate-Protocol: 443:npn-spdy/1). | |
| 252 bool m_wasAlternateProtocolAvailable; | |
| 253 | |
| 254 // Was the resource fetched over an explicit proxy (HTTP, SOCKS, etc). | |
| 255 bool m_wasFetchedViaProxy; | |
| 256 | |
| 257 // The time at which the response headers were received. For cached | |
| 258 // responses, this time could be "far" in the past. | |
| 259 double m_responseTime; | |
| 260 | |
| 261 // Remote IP address of the socket which fetched this resource. | |
| 262 AtomicString m_remoteIPAddress; | |
| 263 | |
| 264 // Remote port number of the socket which fetched this resource. | |
| 265 unsigned short m_remotePort; | |
| 266 | |
| 267 // The downloaded file path if the load streamed to a file. | |
| 268 String m_downloadedFilePath; | |
| 269 | |
| 270 // The handle to the downloaded file to ensure the underlying file will not | |
| 271 // be deleted. | |
| 272 RefPtr<BlobDataHandle> m_downloadedFileHandle; | |
| 273 | |
| 274 // ExtraData associated with the response. | |
| 275 RefPtr<ExtraData> m_extraData; | |
| 276 }; | |
| 277 | |
| 278 inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) { r
eturn ResourceResponse::compare(a, b); } | |
| 279 inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) { r
eturn !(a == b); } | |
| 280 | |
| 281 struct CrossThreadResourceResponseData { | |
| 282 WTF_MAKE_NONCOPYABLE(CrossThreadResourceResponseData); WTF_MAKE_FAST_ALLOCAT
ED; | |
| 283 public: | |
| 284 CrossThreadResourceResponseData() { } | |
| 285 KURL m_url; | |
| 286 String m_mimeType; | |
| 287 long long m_expectedContentLength; | |
| 288 String m_textEncodingName; | |
| 289 String m_suggestedFilename; | |
| 290 int m_httpStatusCode; | |
| 291 String m_httpStatusText; | |
| 292 OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders; | |
| 293 time_t m_lastModifiedDate; | |
| 294 RefPtr<ResourceLoadTiming> m_resourceLoadTiming; | |
| 295 CString m_securityInfo; | |
| 296 ResourceResponse::HTTPVersion m_httpVersion; | |
| 297 long long m_appCacheID; | |
| 298 KURL m_appCacheManifestURL; | |
| 299 bool m_isMultipartPayload; | |
| 300 bool m_wasFetchedViaSPDY; | |
| 301 bool m_wasNpnNegotiated; | |
| 302 bool m_wasAlternateProtocolAvailable; | |
| 303 bool m_wasFetchedViaProxy; | |
| 304 double m_responseTime; | |
| 305 String m_remoteIPAddress; | |
| 306 unsigned short m_remotePort; | |
| 307 String m_downloadedFilePath; | |
| 308 RefPtr<BlobDataHandle> m_downloadedFileHandle; | |
| 309 }; | |
| 310 | |
| 311 } // namespace WebCore | |
| 312 | |
| 313 #endif // ResourceResponse_h | |
| OLD | NEW |