#ifndef ResourceResponse_h
#define ResourceResponse_h
#include "platform/PlatformExport.h"
#include "platform/blob/BlobData.h"
#include "platform/network/HTTPHeaderMap.h"
#include "platform/network/ResourceLoadInfo.h"
#include "platform/network/ResourceLoadTiming.h"
#include "platform/weborigin/KURL.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/text/CString.h"
namespace WebCore {
struct CrossThreadResourceResponseData;
class PLATFORM_EXPORT ResourceResponse {
WTF_MAKE_FAST_ALLOCATED;
public:
enum HTTPVersion { Unknown, HTTP_0_9, HTTP_1_0, HTTP_1_1 };
class ExtraData : public RefCounted<ExtraData> {
public:
virtual ~ExtraData() { }
};
static PassOwnPtr<ResourceResponse> adopt(PassOwnPtr<CrossThreadResourceResponseData>);
PassOwnPtr<CrossThreadResourceResponseData> copyData() const;
ResourceResponse();
ResourceResponse(const KURL&, const AtomicString& mimeType, long long expectedLength, const AtomicString& textEncodingName, const String& filename);
bool isNull() const { return m_isNull; }
bool isHTTP() const;
const KURL& url() const;
void setURL(const KURL&);
const AtomicString& mimeType() const;
void setMimeType(const AtomicString&);
long long expectedContentLength() const;
void setExpectedContentLength(long long);
const AtomicString& textEncodingName() const;
void setTextEncodingName(const AtomicString&);
const String& suggestedFilename() const;
void setSuggestedFilename(const String&);
int httpStatusCode() const;
void setHTTPStatusCode(int);
const AtomicString& httpStatusText() const;
void setHTTPStatusText(const AtomicString&);
const AtomicString& httpHeaderField(const AtomicString& name) const;
const AtomicString& httpHeaderField(const char* name) const;
void setHTTPHeaderField(const AtomicString& name, const AtomicString& value);
void addHTTPHeaderField(const AtomicString& name, const AtomicString& value);
void clearHTTPHeaderField(const AtomicString& name);
const HTTPHeaderMap& httpHeaderFields() const;
bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
bool isAttachment() const;
void setLastModifiedDate(time_t);
time_t lastModifiedDate() const;
bool cacheControlContainsNoCache() const;
bool cacheControlContainsNoStore() const;
bool cacheControlContainsMustRevalidate() const;
bool hasCacheValidatorFields() const;
double cacheControlMaxAge() const;
double date() const;
double age() const;
double expires() const;
double lastModified() const;
unsigned connectionID() const;
void setConnectionID(unsigned);
bool connectionReused() const;
void setConnectionReused(bool);
bool wasCached() const;
void setWasCached(bool);
ResourceLoadTiming* resourceLoadTiming() const;
void setResourceLoadTiming(PassRefPtr<ResourceLoadTiming>);
PassRefPtr<ResourceLoadInfo> resourceLoadInfo() const;
void setResourceLoadInfo(PassRefPtr<ResourceLoadInfo>);
HTTPVersion httpVersion() const { return m_httpVersion; }
void setHTTPVersion(HTTPVersion version) { m_httpVersion = version; }
const CString& getSecurityInfo() const { return m_securityInfo; }
void setSecurityInfo(const CString& securityInfo) { m_securityInfo = securityInfo; }
long long appCacheID() const { return m_appCacheID; }
void setAppCacheID(long long id) { m_appCacheID = id; }
const KURL& appCacheManifestURL() const { return m_appCacheManifestURL; }
void setAppCacheManifestURL(const KURL& url) { m_appCacheManifestURL = url; }
bool wasFetchedViaSPDY() const { return m_wasFetchedViaSPDY; }
void setWasFetchedViaSPDY(bool value) { m_wasFetchedViaSPDY = value; }
bool wasNpnNegotiated() const { return m_wasNpnNegotiated; }
void setWasNpnNegotiated(bool value) { m_wasNpnNegotiated = value; }
bool wasAlternateProtocolAvailable() const
{
return m_wasAlternateProtocolAvailable;
}
void setWasAlternateProtocolAvailable(bool value)
{
m_wasAlternateProtocolAvailable = value;
}
bool wasFetchedViaProxy() const { return m_wasFetchedViaProxy; }
void setWasFetchedViaProxy(bool value) { m_wasFetchedViaProxy = value; }
bool isMultipartPayload() const { return m_isMultipartPayload; }
void setIsMultipartPayload(bool value) { m_isMultipartPayload = value; }
double responseTime() const { return m_responseTime; }
void setResponseTime(double responseTime) { m_responseTime = responseTime; }
const AtomicString& remoteIPAddress() const { return m_remoteIPAddress; }
void setRemoteIPAddress(const AtomicString& value) { m_remoteIPAddress = value; }
unsigned short remotePort() const { return m_remotePort; }
void setRemotePort(unsigned short value) { m_remotePort = value; }
const String& downloadedFilePath() const { return m_downloadedFilePath; }
void setDownloadedFilePath(const String&);
ExtraData* extraData() const { return m_extraData.get(); }
void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData; }
unsigned memoryUsage() const
{
return 1280;
}
static bool compare(const ResourceResponse&, const ResourceResponse&);
private:
void parseCacheControlDirectives() const;
void updateHeaderParsedState(const AtomicString& name);
KURL m_url;
AtomicString m_mimeType;
long long m_expectedContentLength;
AtomicString m_textEncodingName;
String m_suggestedFilename;
int m_httpStatusCode;
AtomicString m_httpStatusText;
HTTPHeaderMap m_httpHeaderFields;
time_t m_lastModifiedDate;
bool m_wasCached : 1;
unsigned m_connectionID;
bool m_connectionReused : 1;
RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
RefPtr<ResourceLoadInfo> m_resourceLoadInfo;
bool m_isNull : 1;
mutable bool m_haveParsedCacheControlHeader : 1;
mutable bool m_haveParsedAgeHeader : 1;
mutable bool m_haveParsedDateHeader : 1;
mutable bool m_haveParsedExpiresHeader : 1;
mutable bool m_haveParsedLastModifiedHeader : 1;
mutable bool m_cacheControlContainsNoCache : 1;
mutable bool m_cacheControlContainsNoStore : 1;
mutable bool m_cacheControlContainsMustRevalidate : 1;
mutable double m_cacheControlMaxAge;
mutable double m_age;
mutable double m_date;
mutable double m_expires;
mutable double m_lastModified;
CString m_securityInfo;
HTTPVersion m_httpVersion;
long long m_appCacheID;
KURL m_appCacheManifestURL;
bool m_isMultipartPayload;
bool m_wasFetchedViaSPDY;
bool m_wasNpnNegotiated;
bool m_wasAlternateProtocolAvailable;
bool m_wasFetchedViaProxy;
double m_responseTime;
AtomicString m_remoteIPAddress;
unsigned short m_remotePort;
String m_downloadedFilePath;
RefPtr<BlobDataHandle> m_downloadedFileHandle;
RefPtr<ExtraData> m_extraData;
};
inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) { return ResourceResponse::compare(a, b); }
inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) { return !(a == b); }
struct CrossThreadResourceResponseData {
WTF_MAKE_NONCOPYABLE(CrossThreadResourceResponseData); WTF_MAKE_FAST_ALLOCATED;
public:
CrossThreadResourceResponseData() { }
KURL m_url;
String m_mimeType;
long long m_expectedContentLength;
String m_textEncodingName;
String m_suggestedFilename;
int m_httpStatusCode;
String m_httpStatusText;
OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
time_t m_lastModifiedDate;
RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
CString m_securityInfo;
ResourceResponse::HTTPVersion m_httpVersion;
long long m_appCacheID;
KURL m_appCacheManifestURL;
bool m_isMultipartPayload;
bool m_wasFetchedViaSPDY;
bool m_wasNpnNegotiated;
bool m_wasAlternateProtocolAvailable;
bool m_wasFetchedViaProxy;
double m_responseTime;
String m_remoteIPAddress;
unsigned short m_remotePort;
String m_downloadedFilePath;
RefPtr<BlobDataHandle> m_downloadedFileHandle;
};
}
#endif