OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "core/loader/CrossOriginPreflightResultCache.h" | 28 #include "core/loader/CrossOriginPreflightResultCache.h" |
29 | 29 |
30 #include "core/fetch/CrossOriginAccessControl.h" | 30 #include "core/fetch/CrossOriginAccessControl.h" |
31 #include "platform/network/ResourceResponse.h" | 31 #include "platform/network/ResourceResponse.h" |
32 #include "wtf/CurrentTime.h" | 32 #include "wtf/CurrentTime.h" |
33 #include "wtf/MainThread.h" | 33 #include "wtf/MainThread.h" |
34 #include "wtf/StdLibExtras.h" | 34 #include "wtf/StdLibExtras.h" |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 using namespace std; | |
39 | |
40 // These values are at the discretion of the user agent. | 38 // These values are at the discretion of the user agent. |
41 static const unsigned defaultPreflightCacheTimeoutSeconds = 5; | 39 static const unsigned defaultPreflightCacheTimeoutSeconds = 5; |
42 static const unsigned maxPreflightCacheTimeoutSeconds = 600; // Should be short
enough to minimize the risk of using a poisoned cache after switching to a secur
e network. | 40 static const unsigned maxPreflightCacheTimeoutSeconds = 600; // Should be short
enough to minimize the risk of using a poisoned cache after switching to a secur
e network. |
43 | 41 |
44 static bool parseAccessControlMaxAge(const String& string, unsigned& expiryDelta
) | 42 static bool parseAccessControlMaxAge(const String& string, unsigned& expiryDelta
) |
45 { | 43 { |
46 // FIXME: this will not do the correct thing for a number starting with a '+
' | 44 // FIXME: this will not do the correct thing for a number starting with a '+
' |
47 bool ok = false; | 45 bool ok = false; |
48 expiryDelta = string.toUIntStrict(&ok); | 46 expiryDelta = string.toUIntStrict(&ok); |
49 return ok; | 47 return ok; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 CrossOriginPreflightResultCache& CrossOriginPreflightResultCache::shared() | 148 CrossOriginPreflightResultCache& CrossOriginPreflightResultCache::shared() |
151 { | 149 { |
152 DEFINE_STATIC_LOCAL(CrossOriginPreflightResultCache, cache, ()); | 150 DEFINE_STATIC_LOCAL(CrossOriginPreflightResultCache, cache, ()); |
153 ASSERT(isMainThread()); | 151 ASSERT(isMainThread()); |
154 return cache; | 152 return cache; |
155 } | 153 } |
156 | 154 |
157 void CrossOriginPreflightResultCache::appendEntry(const String& origin, const KU
RL& url, PassOwnPtr<CrossOriginPreflightResultCacheItem> preflightResult) | 155 void CrossOriginPreflightResultCache::appendEntry(const String& origin, const KU
RL& url, PassOwnPtr<CrossOriginPreflightResultCacheItem> preflightResult) |
158 { | 156 { |
159 ASSERT(isMainThread()); | 157 ASSERT(isMainThread()); |
160 m_preflightHashMap.set(make_pair(origin, url), preflightResult); | 158 m_preflightHashMap.set(std::make_pair(origin, url), preflightResult); |
161 } | 159 } |
162 | 160 |
163 bool CrossOriginPreflightResultCache::canSkipPreflight(const String& origin, con
st KURL& url, StoredCredentials includeCredentials, const String& method, const
HTTPHeaderMap& requestHeaders) | 161 bool CrossOriginPreflightResultCache::canSkipPreflight(const String& origin, con
st KURL& url, StoredCredentials includeCredentials, const String& method, const
HTTPHeaderMap& requestHeaders) |
164 { | 162 { |
165 ASSERT(isMainThread()); | 163 ASSERT(isMainThread()); |
166 CrossOriginPreflightResultHashMap::iterator cacheIt = m_preflightHashMap.fin
d(make_pair(origin, url)); | 164 CrossOriginPreflightResultHashMap::iterator cacheIt = m_preflightHashMap.fin
d(std::make_pair(origin, url)); |
167 if (cacheIt == m_preflightHashMap.end()) | 165 if (cacheIt == m_preflightHashMap.end()) |
168 return false; | 166 return false; |
169 | 167 |
170 if (cacheIt->value->allowsRequest(includeCredentials, method, requestHeaders
)) | 168 if (cacheIt->value->allowsRequest(includeCredentials, method, requestHeaders
)) |
171 return true; | 169 return true; |
172 | 170 |
173 m_preflightHashMap.remove(cacheIt); | 171 m_preflightHashMap.remove(cacheIt); |
174 return false; | 172 return false; |
175 } | 173 } |
176 | 174 |
177 void CrossOriginPreflightResultCache::empty() | 175 void CrossOriginPreflightResultCache::empty() |
178 { | 176 { |
179 ASSERT(isMainThread()); | 177 ASSERT(isMainThread()); |
180 m_preflightHashMap.clear(); | 178 m_preflightHashMap.clear(); |
181 } | 179 } |
182 | 180 |
183 } // namespace WebCore | 181 } // namespace WebCore |
OLD | NEW |