#ifndef CrossOriginPreflightResultCache_h
#define CrossOriginPreflightResultCache_h
#include "core/fetch/ResourceLoaderOptions.h"
#include "platform/weborigin/KURLHash.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/text/StringHash.h"
namespace WebCore {
class HTTPHeaderMap;
class ResourceResponse;
class CrossOriginPreflightResultCacheItem {
WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCacheItem); WTF_MAKE_FAST_ALLOCATED;
public:
CrossOriginPreflightResultCacheItem(StoredCredentials credentials)
: m_absoluteExpiryTime(0)
, m_credentials(credentials)
{
}
bool parse(const ResourceResponse&, String& errorDescription);
bool allowsCrossOriginMethod(const String&, String& errorDescription) const;
bool allowsCrossOriginHeaders(const HTTPHeaderMap&, String& errorDescription) const;
bool allowsRequest(StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const;
private:
typedef HashSet<String, CaseFoldingHash> HeadersSet;
double m_absoluteExpiryTime;
StoredCredentials m_credentials;
HashSet<String> m_methods;
HeadersSet m_headers;
};
class CrossOriginPreflightResultCache {
WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCache); WTF_MAKE_FAST_ALLOCATED;
public:
static CrossOriginPreflightResultCache& shared();
void appendEntry(const String& origin, const KURL&, PassOwnPtr<CrossOriginPreflightResultCacheItem>);
bool canSkipPreflight(const String& origin, const KURL&, StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders);
private:
CrossOriginPreflightResultCache() { }
typedef HashMap<std::pair<String, KURL>, OwnPtr<CrossOriginPreflightResultCacheItem> > CrossOriginPreflightResultHashMap;
CrossOriginPreflightResultHashMap m_preflightHashMap;
};
}
#endif