ResourceResponseBase.h [plain text]
#ifndef ResourceResponseBase_h
#define ResourceResponseBase_h
#include "HTTPHeaderMap.h"
#include "KURL.h"
#include "ResourceLoadTiming.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h>
#if OS(SOLARIS)
#include <sys/time.h> // For time_t structure.
#endif
namespace WebCore {
class ResourceResponse;
struct CrossThreadResourceResponseData;
class ResourceResponseBase {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<ResourceResponse> adopt(PassOwnPtr<CrossThreadResourceResponseData>);
PassOwnPtr<CrossThreadResourceResponseData> copyData() const;
bool isNull() const { return m_isNull; }
bool isHTTP() const;
const KURL& url() const;
void setURL(const KURL& url);
const String& mimeType() const;
void setMimeType(const String& mimeType);
long long expectedContentLength() const;
void setExpectedContentLength(long long expectedContentLength);
const String& textEncodingName() const;
void setTextEncodingName(const String& name);
const String& suggestedFilename() const;
void setSuggestedFilename(const String&);
int httpStatusCode() const;
void setHTTPStatusCode(int);
const String& httpStatusText() const;
void setHTTPStatusText(const String&);
String httpHeaderField(const AtomicString& name) const;
String httpHeaderField(const char* name) const;
void setHTTPHeaderField(const AtomicString& name, const String& value);
void addHTTPHeaderField(const AtomicString& name, const String& value);
const HTTPHeaderMap& httpHeaderFields() const;
bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
bool isAttachment() 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>);
unsigned memoryUsage() const
{
return 1280;
}
static bool compare(const ResourceResponse&, const ResourceResponse&);
protected:
enum InitLevel {
Uninitialized,
CommonFieldsOnly,
CommonAndUncommonFields,
AllFields
};
ResourceResponseBase();
ResourceResponseBase(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename);
void lazyInit(InitLevel) const;
void platformLazyInit(InitLevel) { }
static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; }
KURL m_url;
String m_mimeType;
long long m_expectedContentLength;
String m_textEncodingName;
String m_suggestedFilename;
int m_httpStatusCode;
String m_httpStatusText;
HTTPHeaderMap m_httpHeaderFields;
bool m_wasCached : 1;
unsigned m_connectionID;
bool m_connectionReused : 1;
RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
bool m_isNull : 1;
private:
const ResourceResponse& asResourceResponse() const;
void parseCacheControlDirectives() const;
void updateHeaderParsedState(const AtomicString& name);
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;
};
inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) { return ResourceResponseBase::compare(a, b); }
inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) { return !(a == b); }
struct CrossThreadResourceResponseDataBase {
WTF_MAKE_NONCOPYABLE(CrossThreadResourceResponseDataBase); WTF_MAKE_FAST_ALLOCATED;
public:
CrossThreadResourceResponseDataBase() { }
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;
RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
};
}
#endif // ResourceResponseBase_h