| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/blob/BlobRegistry.h" | 31 #include "platform/blob/BlobRegistry.h" |
| 32 | 32 |
| 33 #include "platform/CrossThreadFunctional.h" | 33 #include "platform/CrossThreadFunctional.h" |
| 34 #include "platform/blob/BlobData.h" | 34 #include "platform/blob/BlobData.h" |
| 35 #include "platform/blob/BlobURL.h" | 35 #include "platform/blob/BlobURL.h" |
| 36 #include "platform/weborigin/SecurityOrigin.h" | 36 #include "platform/weborigin/SecurityOrigin.h" |
| 37 #include "platform/weborigin/SecurityOriginCache.h" | 37 #include "platform/weborigin/URLSecurityOriginMap.h" |
| 38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
| 39 #include "public/platform/WebBlobData.h" | 39 #include "public/platform/WebBlobData.h" |
| 40 #include "public/platform/WebBlobRegistry.h" | 40 #include "public/platform/WebBlobRegistry.h" |
| 41 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
| 42 #include "public/platform/WebTaskRunner.h" | 42 #include "public/platform/WebTaskRunner.h" |
| 43 #include "public/platform/WebTraceLocation.h" | 43 #include "public/platform/WebTraceLocation.h" |
| 44 #include "wtf/Assertions.h" | 44 #include "wtf/Assertions.h" |
| 45 #include "wtf/HashMap.h" | 45 #include "wtf/HashMap.h" |
| 46 #include "wtf/RefPtr.h" | 46 #include "wtf/RefPtr.h" |
| 47 #include "wtf/ThreadSpecific.h" | 47 #include "wtf/ThreadSpecific.h" |
| 48 #include "wtf/Threading.h" | 48 #include "wtf/Threading.h" |
| 49 #include "wtf/text/StringHash.h" | 49 #include "wtf/text/StringHash.h" |
| 50 #include "wtf/text/WTFString.h" | 50 #include "wtf/text/WTFString.h" |
| 51 #include <memory> | 51 #include <memory> |
| 52 | 52 |
| 53 namespace blink { | 53 namespace blink { |
| 54 | 54 |
| 55 class BlobOriginCache : public SecurityOriginCache { | 55 class BlobOriginMap : public URLSecurityOriginMap { |
| 56 public: | 56 public: |
| 57 BlobOriginCache(); | 57 BlobOriginMap(); |
| 58 SecurityOrigin* cachedOrigin(const KURL&) override; | 58 SecurityOrigin* getOrigin(const KURL&) override; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 static WebBlobRegistry* blobRegistry() | 61 static WebBlobRegistry* blobRegistry() |
| 62 { | 62 { |
| 63 return Platform::current()->blobRegistry(); | 63 return Platform::current()->blobRegistry(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 typedef HashMap<String, RefPtr<SecurityOrigin>> BlobURLOriginMap; | 66 typedef HashMap<String, RefPtr<SecurityOrigin>> BlobURLOriginMap; |
| 67 static ThreadSpecific<BlobURLOriginMap>& originMap() | 67 static ThreadSpecific<BlobURLOriginMap>& originMap() |
| 68 { | 68 { |
| 69 // We want to create the BlobOriginCache exactly once because it is shared b
y all the threads. | 69 // We want to create the BlobOriginMap exactly once because it is shared by |
| 70 DEFINE_THREAD_SAFE_STATIC_LOCAL(BlobOriginCache, cache, new BlobOriginCache)
; | 70 // all the threads. |
| 71 (void)cache; // BlobOriginCache's constructor does the interesting work. | 71 DEFINE_THREAD_SAFE_STATIC_LOCAL(BlobOriginMap, cache, new BlobOriginMap); |
| 72 (void)cache; // BlobOriginMap's constructor does the interesting work. |
| 72 | 73 |
| 73 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<BlobURLOriginMap>, map, new T
hreadSpecific<BlobURLOriginMap>); | 74 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<BlobURLOriginMap>, map, new T
hreadSpecific<BlobURLOriginMap>); |
| 74 return map; | 75 return map; |
| 75 } | 76 } |
| 76 | 77 |
| 77 static void saveToOriginMap(SecurityOrigin* origin, const KURL& url) | 78 static void saveToOriginMap(SecurityOrigin* origin, const KURL& url) |
| 78 { | 79 { |
| 79 // If the blob URL contains null origin, as in the context with unique | 80 // If the blob URL contains null origin, as in the context with unique |
| 80 // security origin or file URL, save the mapping between url and origin so | 81 // security origin or file URL, save the mapping between url and origin so |
| 81 // that the origin can be retrived when doing security origin check. | 82 // that the origin can be retrieved when doing security origin check. |
| 83 // |
| 84 // See the definition of the origin of a Blob URL in the File API spec. |
| 82 if (origin && BlobURL::getOrigin(url) == "null") | 85 if (origin && BlobURL::getOrigin(url) == "null") |
| 83 originMap()->add(url.getString(), origin); | 86 originMap()->add(url.getString(), origin); |
| 84 } | 87 } |
| 85 | 88 |
| 86 static void removeFromOriginMap(const KURL& url) | 89 static void removeFromOriginMap(const KURL& url) |
| 87 { | 90 { |
| 88 if (BlobURL::getOrigin(url) == "null") | 91 if (BlobURL::getOrigin(url) == "null") |
| 89 originMap()->remove(url.getString()); | 92 originMap()->remove(url.getString()); |
| 90 } | 93 } |
| 91 | 94 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 void BlobRegistry::unregisterStreamURL(const KURL& url) | 214 void BlobRegistry::unregisterStreamURL(const KURL& url) |
| 212 { | 215 { |
| 213 removeFromOriginMap(url); | 216 removeFromOriginMap(url); |
| 214 | 217 |
| 215 if (isMainThread()) | 218 if (isMainThread()) |
| 216 unregisterStreamURLTask(url); | 219 unregisterStreamURLTask(url); |
| 217 else | 220 else |
| 218 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&unregisterStreamURLTask, url)); | 221 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&unregisterStreamURLTask, url)); |
| 219 } | 222 } |
| 220 | 223 |
| 221 BlobOriginCache::BlobOriginCache() | 224 BlobOriginMap::BlobOriginMap() |
| 222 { | 225 { |
| 223 SecurityOrigin::setCache(this); | 226 SecurityOrigin::setMap(this); |
| 224 } | 227 } |
| 225 | 228 |
| 226 SecurityOrigin* BlobOriginCache::cachedOrigin(const KURL& url) | 229 SecurityOrigin* BlobOriginMap::getOrigin(const KURL& url) |
| 227 { | 230 { |
| 228 if (url.protocolIs("blob")) | 231 if (url.protocolIs("blob")) |
| 229 return originMap()->get(url.getString()); | 232 return originMap()->get(url.getString()); |
| 230 return 0; | 233 return 0; |
| 231 } | 234 } |
| 232 | 235 |
| 233 } // namespace blink | 236 } // namespace blink |
| OLD | NEW |