39 class HTTPHeaderMap;
40 class ResourceResponse;
41
42 class CrossOriginPreflightResultCacheItem {
43 WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCacheItem); WTF_MAKE_FAST_ALLOCATED;
44 public:
45 CrossOriginPreflightResultCacheItem(StoredCredentials credentials)
46 : m_absoluteExpiryTime(0)
47 , m_credentials(credentials)
48 {
49 }
50
51 bool parse(const ResourceResponse&, String& errorDescription);
52 bool allowsCrossOriginMethod(const String&, String& errorDescription) const;
53 bool allowsCrossOriginHeaders(const HTTPHeaderMap&, String& errorDescription) const;
54 bool allowsRequest(StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const;
55
56 private:
57 typedef HashSet<String, CaseFoldingHash> HeadersSet;
58
59 // FIXME: A better solution to holding onto the absolute expiration time might be
60 // to start a timer for the expiration delta that removes this from the cache when
61 // it fires.
62 double m_absoluteExpiryTime;
63 StoredCredentials m_credentials;
64 HashSet<String> m_methods;
65 HeadersSet m_headers;
66 };
67
68 class CrossOriginPreflightResultCache {
69 WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCache); WTF_MAKE_FAST_ALLOCATED;
70 public:
71 static CrossOriginPreflightResultCache& shared();
72
73 void appendEntry(const String& origin, const URL&, PassOwnPtr<CrossOriginPreflightResultCacheItem>);
74 bool canSkipPreflight(const String& origin, const URL&, StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders);
75
76 void empty();
77
78 private:
79 CrossOriginPreflightResultCache() { }
80
81 typedef HashMap<std::pair<String, URL>, OwnPtr<CrossOriginPreflightResultCacheItem>> CrossOriginPreflightResultHashMap;
82
83 CrossOriginPreflightResultHashMap m_preflightHashMap;
84 };
39class HTTPHeaderMap;
40class ResourceResponse;
41
42class CrossOriginPreflightResultCacheItem {
43 WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCacheItem); WTF_MAKE_FAST_ALLOCATED;
44public:
45 explicit CrossOriginPreflightResultCacheItem(StoredCredentials credentials)
46 : m_credentials(credentials)
47 {
48 }
49
50 bool parse(const ResourceResponse&, String& errorDescription);
51 bool allowsCrossOriginMethod(const String&, String& errorDescription) const;
52 bool allowsCrossOriginHeaders(const HTTPHeaderMap&, String& errorDescription) const;
53 bool allowsRequest(StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders) const;
54
55private:
56 // FIXME: A better solution to holding onto the absolute expiration time might be
57 // to start a timer for the expiration delta that removes this from the cache when
58 // it fires.
59 std::chrono::steady_clock::time_point m_absoluteExpiryTime;
60 StoredCredentials m_credentials;
61 HashSet<String> m_methods;
62 HashSet<String, CaseFoldingHash> m_headers;
63};
64
65class CrossOriginPreflightResultCache {
66 WTF_MAKE_NONCOPYABLE(CrossOriginPreflightResultCache); WTF_MAKE_FAST_ALLOCATED;
67
68public:
69 static CrossOriginPreflightResultCache& shared();
70
71 void appendEntry(const String& origin, const URL&, std::unique_ptr<CrossOriginPreflightResultCacheItem>);
72 bool canSkipPreflight(const String& origin, const URL&, StoredCredentials, const String& method, const HTTPHeaderMap& requestHeaders);
73
74 void empty();
75
76private:
77 friend NeverDestroyed<CrossOriginPreflightResultCache>;
78 CrossOriginPreflightResultCache();
79
80 HashMap<std::pair<String, URL>, std::unique_ptr<CrossOriginPreflightResultCacheItem>> m_preflightHashMap;
81};