CrossOriginPreflightResultCache.h [plain text]
#ifndef CrossOriginPreflightResultCache_h
#define CrossOriginPreflightResultCache_h
#include "KURLHash.h"
#include "ResourceHandleTypes.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);
void empty();
private:
CrossOriginPreflightResultCache() { }
typedef HashMap<std::pair<String, KURL>, OwnPtr<CrossOriginPreflightResultCacheItem> > CrossOriginPreflightResultHashMap;
CrossOriginPreflightResultHashMap m_preflightHashMap;
};
}
#endif