#ifndef HTMLResourcePreloader_h
#define HTMLResourcePreloader_h
#include "core/fetch/FetchRequest.h"
#include "core/fetch/Resource.h"
#include "wtf/CurrentTime.h"
#include "wtf/text/TextPosition.h"
namespace WebCore {
class PreloadRequest {
public:
static PassOwnPtr<PreloadRequest> create(const String& initiatorName, const TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL, Resource::Type resourceType)
{
return adoptPtr(new PreloadRequest(initiatorName, initiatorPosition, resourceURL, baseURL, resourceType));
}
bool isSafeToSendToAnotherThread() const;
FetchRequest resourceRequest(Document*);
const String& charset() const { return m_charset; }
double discoveryTime() const { return m_discoveryTime; }
void setCharset(const String& charset) { m_charset = charset.isolatedCopy(); }
void setCrossOriginEnabled(StoredCredentials allowCredentials)
{
m_isCORSEnabled = true;
m_allowCredentials = allowCredentials;
}
Resource::Type resourceType() const { return m_resourceType; }
private:
PreloadRequest(const String& initiatorName, const TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL, Resource::Type resourceType)
: m_initiatorName(initiatorName)
, m_initiatorPosition(initiatorPosition)
, m_resourceURL(resourceURL.isolatedCopy())
, m_baseURL(baseURL.copy())
, m_resourceType(resourceType)
, m_isCORSEnabled(false)
, m_allowCredentials(DoNotAllowStoredCredentials)
, m_discoveryTime(monotonicallyIncreasingTime())
{
}
KURL completeURL(Document*);
String m_initiatorName;
TextPosition m_initiatorPosition;
String m_resourceURL;
KURL m_baseURL;
String m_charset;
Resource::Type m_resourceType;
bool m_isCORSEnabled;
StoredCredentials m_allowCredentials;
double m_discoveryTime;
};
typedef Vector<OwnPtr<PreloadRequest> > PreloadRequestStream;
class HTMLResourcePreloader {
WTF_MAKE_NONCOPYABLE(HTMLResourcePreloader); WTF_MAKE_FAST_ALLOCATED;
public:
explicit HTMLResourcePreloader(Document* document)
: m_document(document)
{
}
void takeAndPreload(PreloadRequestStream&);
void preload(PassOwnPtr<PreloadRequest>);
private:
Document* m_document;
};
}
#endif