#ifndef ResourceRequest_h
#define ResourceRequest_h
#include "platform/network/FormData.h"
#include "platform/network/HTTPHeaderMap.h"
#include "platform/network/ResourceLoadPriority.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/Referrer.h"
#include "wtf/OwnPtr.h"
namespace WebCore {
enum ResourceRequestCachePolicy {
UseProtocolCachePolicy,
ReloadIgnoringCacheData,
ReturnCacheDataElseLoad,
ReturnCacheDataDontLoad
};
struct CrossThreadResourceRequestData;
class PLATFORM_EXPORT ResourceRequest {
WTF_MAKE_FAST_ALLOCATED;
public:
enum TargetType {
TargetIsMainFrame,
TargetIsSubframe,
TargetIsSubresource,
TargetIsStyleSheet,
TargetIsScript,
TargetIsFont,
TargetIsImage,
TargetIsObject,
TargetIsMedia,
TargetIsWorker,
TargetIsSharedWorker,
TargetIsPrefetch,
TargetIsFavicon,
TargetIsXHR,
TargetIsTextTrack,
TargetIsPing,
TargetIsServiceWorker,
TargetIsUnspecified,
};
class ExtraData : public RefCounted<ExtraData> {
public:
virtual ~ExtraData() { }
};
ResourceRequest()
{
initialize(KURL(), UseProtocolCachePolicy);
}
ResourceRequest(const String& urlString)
{
initialize(KURL(ParsedURLString, urlString), UseProtocolCachePolicy);
}
ResourceRequest(const KURL& url)
{
initialize(url, UseProtocolCachePolicy);
}
ResourceRequest(const KURL& url, const Referrer& referrer, ResourceRequestCachePolicy cachePolicy = UseProtocolCachePolicy)
{
initialize(url, cachePolicy);
setHTTPReferrer(referrer);
}
static PassOwnPtr<ResourceRequest> adopt(PassOwnPtr<CrossThreadResourceRequestData>);
PassOwnPtr<CrossThreadResourceRequestData> copyData() const;
bool isNull() const;
bool isEmpty() const;
const KURL& url() const;
void setURL(const KURL& url);
void removeCredentials();
ResourceRequestCachePolicy cachePolicy() const;
void setCachePolicy(ResourceRequestCachePolicy cachePolicy);
double timeoutInterval() const;
void setTimeoutInterval(double timeoutInterval);
const KURL& firstPartyForCookies() const;
void setFirstPartyForCookies(const KURL& firstPartyForCookies);
const AtomicString& httpMethod() const;
void setHTTPMethod(const AtomicString&);
const HTTPHeaderMap& httpHeaderFields() const;
const AtomicString& httpHeaderField(const AtomicString& name) const;
const AtomicString& httpHeaderField(const char* name) const;
void setHTTPHeaderField(const AtomicString& name, const AtomicString& value);
void setHTTPHeaderField(const char* name, const AtomicString& value);
void addHTTPHeaderField(const AtomicString& name, const AtomicString& value);
void addHTTPHeaderFields(const HTTPHeaderMap& headerFields);
void clearHTTPHeaderField(const AtomicString& name);
void clearHTTPAuthorization();
const AtomicString& httpContentType() const { return httpHeaderField("Content-Type"); }
void setHTTPContentType(const AtomicString& httpContentType) { setHTTPHeaderField("Content-Type", httpContentType); }
void clearHTTPContentType();
const AtomicString& httpReferrer() const { return httpHeaderField("Referer"); }
ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
void setHTTPReferrer(const Referrer& httpReferrer) { setHTTPHeaderField("Referer", httpReferrer.referrer); m_referrerPolicy = httpReferrer.referrerPolicy; }
void clearHTTPReferrer();
const AtomicString& httpOrigin() const { return httpHeaderField("Origin"); }
void setHTTPOrigin(const AtomicString& httpOrigin) { setHTTPHeaderField("Origin", httpOrigin); }
void clearHTTPOrigin();
const AtomicString& httpUserAgent() const { return httpHeaderField("User-Agent"); }
void setHTTPUserAgent(const AtomicString& httpUserAgent) { setHTTPHeaderField("User-Agent", httpUserAgent); }
void clearHTTPUserAgent();
const AtomicString& httpAccept() const { return httpHeaderField("Accept"); }
void setHTTPAccept(const AtomicString& httpAccept) { setHTTPHeaderField("Accept", httpAccept); }
void clearHTTPAccept();
FormData* httpBody() const;
void setHTTPBody(PassRefPtr<FormData> httpBody);
bool allowStoredCredentials() const;
void setAllowStoredCredentials(bool allowCredentials);
ResourceLoadPriority priority() const;
void setPriority(ResourceLoadPriority, int intraPriorityValue = 0);
bool isConditional() const;
bool reportUploadProgress() const { return m_reportUploadProgress; }
void setReportUploadProgress(bool reportUploadProgress) { m_reportUploadProgress = reportUploadProgress; }
bool reportLoadTiming() const { return m_reportLoadTiming; }
void setReportLoadTiming(bool reportLoadTiming) { m_reportLoadTiming = reportLoadTiming; }
bool reportRawHeaders() const { return m_reportRawHeaders; }
void setReportRawHeaders(bool reportRawHeaders) { m_reportRawHeaders = reportRawHeaders; }
int requestorID() const { return m_requestorID; }
void setRequestorID(int requestorID) { m_requestorID = requestorID; }
int requestorProcessID() const { return m_requestorProcessID; }
void setRequestorProcessID(int requestorProcessID) { m_requestorProcessID = requestorProcessID; }
int appCacheHostID() const { return m_appCacheHostID; }
void setAppCacheHostID(int id) { m_appCacheHostID = id; }
bool hasUserGesture() const { return m_hasUserGesture; }
void setHasUserGesture(bool hasUserGesture) { m_hasUserGesture = hasUserGesture; }
bool downloadToFile() const { return m_downloadToFile; }
void setDownloadToFile(bool downloadToFile) { m_downloadToFile = downloadToFile; }
ExtraData* extraData() const { return m_extraData.get(); }
void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData; }
TargetType targetType() const { return m_targetType; }
void setTargetType(TargetType type) { m_targetType = type; }
static double defaultTimeoutInterval();
static void setDefaultTimeoutInterval(double);
static bool compare(const ResourceRequest&, const ResourceRequest&);
private:
void initialize(const KURL& url, ResourceRequestCachePolicy cachePolicy);
KURL m_url;
ResourceRequestCachePolicy m_cachePolicy;
double m_timeoutInterval;
KURL m_firstPartyForCookies;
AtomicString m_httpMethod;
HTTPHeaderMap m_httpHeaderFields;
RefPtr<FormData> m_httpBody;
bool m_allowStoredCredentials : 1;
bool m_reportUploadProgress : 1;
bool m_reportLoadTiming : 1;
bool m_reportRawHeaders : 1;
bool m_hasUserGesture : 1;
bool m_downloadToFile : 1;
ResourceLoadPriority m_priority;
int m_intraPriorityValue;
int m_requestorID;
int m_requestorProcessID;
int m_appCacheHostID;
RefPtr<ExtraData> m_extraData;
TargetType m_targetType;
ReferrerPolicy m_referrerPolicy;
static double s_defaultTimeoutInterval;
};
bool equalIgnoringHeaderFields(const ResourceRequest&, const ResourceRequest&);
inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { return ResourceRequest::compare(a, b); }
inline bool operator!=(ResourceRequest& a, const ResourceRequest& b) { return !(a == b); }
struct CrossThreadResourceRequestData {
WTF_MAKE_NONCOPYABLE(CrossThreadResourceRequestData); WTF_MAKE_FAST_ALLOCATED;
public:
CrossThreadResourceRequestData() { }
KURL m_url;
ResourceRequestCachePolicy m_cachePolicy;
double m_timeoutInterval;
KURL m_firstPartyForCookies;
String m_httpMethod;
OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
RefPtr<FormData> m_httpBody;
bool m_allowStoredCredentials;
bool m_reportUploadProgress;
bool m_hasUserGesture;
bool m_downloadToFile;
ResourceLoadPriority m_priority;
int m_intraPriorityValue;
int m_requestorID;
int m_requestorProcessID;
int m_appCacheHostID;
ResourceRequest::TargetType m_targetType;
ReferrerPolicy m_referrerPolicy;
};
unsigned initializeMaximumHTTPConnectionCountPerHost();
}
#endif