| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include <memory> | 51 #include <memory> |
| 52 | 52 |
| 53 namespace blink { | 53 namespace blink { |
| 54 | 54 |
| 55 class BlobOriginMap : public URLSecurityOriginMap { | 55 class BlobOriginMap : public URLSecurityOriginMap { |
| 56 public: | 56 public: |
| 57 BlobOriginMap(); | 57 BlobOriginMap(); |
| 58 SecurityOrigin* getOrigin(const KURL&) override; | 58 SecurityOrigin* getOrigin(const KURL&) override; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 static WebBlobRegistry* blobRegistry() | 61 static WebBlobRegistry* getBlobRegistry() |
| 62 { | 62 { |
| 63 return Platform::current()->blobRegistry(); | 63 return Platform::current()->getBlobRegistry(); |
| 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 BlobOriginMap exactly once because it is shared by | 69 // We want to create the BlobOriginMap exactly once because it is shared by |
| 70 // all the threads. | 70 // all the threads. |
| 71 DEFINE_THREAD_SAFE_STATIC_LOCAL(BlobOriginMap, cache, new BlobOriginMap); | 71 DEFINE_THREAD_SAFE_STATIC_LOCAL(BlobOriginMap, cache, new BlobOriginMap); |
| 72 (void)cache; // BlobOriginMap's constructor does the interesting work. | 72 (void)cache; // BlobOriginMap's constructor does the interesting work. |
| 73 | 73 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 static void removeFromOriginMap(const KURL& url) | 89 static void removeFromOriginMap(const KURL& url) |
| 90 { | 90 { |
| 91 if (BlobURL::getOrigin(url) == "null") | 91 if (BlobURL::getOrigin(url) == "null") |
| 92 originMap()->remove(url.getString()); | 92 originMap()->remove(url.getString()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void BlobRegistry::registerBlobData(const String& uuid, std::unique_ptr<BlobData
> data) | 95 void BlobRegistry::registerBlobData(const String& uuid, std::unique_ptr<BlobData
> data) |
| 96 { | 96 { |
| 97 blobRegistry()->registerBlobData(uuid, WebBlobData(std::move(data))); | 97 getBlobRegistry()->registerBlobData(uuid, WebBlobData(std::move(data))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void BlobRegistry::addBlobDataRef(const String& uuid) | 100 void BlobRegistry::addBlobDataRef(const String& uuid) |
| 101 { | 101 { |
| 102 blobRegistry()->addBlobDataRef(uuid); | 102 getBlobRegistry()->addBlobDataRef(uuid); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void BlobRegistry::removeBlobDataRef(const String& uuid) | 105 void BlobRegistry::removeBlobDataRef(const String& uuid) |
| 106 { | 106 { |
| 107 blobRegistry()->removeBlobDataRef(uuid); | 107 getBlobRegistry()->removeBlobDataRef(uuid); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void BlobRegistry::registerPublicBlobURL(SecurityOrigin* origin, const KURL& url
, PassRefPtr<BlobDataHandle> handle) | 110 void BlobRegistry::registerPublicBlobURL(SecurityOrigin* origin, const KURL& url
, PassRefPtr<BlobDataHandle> handle) |
| 111 { | 111 { |
| 112 saveToOriginMap(origin, url); | 112 saveToOriginMap(origin, url); |
| 113 blobRegistry()->registerPublicBlobURL(url, handle->uuid()); | 113 getBlobRegistry()->registerPublicBlobURL(url, handle->uuid()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void BlobRegistry::revokePublicBlobURL(const KURL& url) | 116 void BlobRegistry::revokePublicBlobURL(const KURL& url) |
| 117 { | 117 { |
| 118 removeFromOriginMap(url); | 118 removeFromOriginMap(url); |
| 119 blobRegistry()->revokePublicBlobURL(url); | 119 getBlobRegistry()->revokePublicBlobURL(url); |
| 120 } | 120 } |
| 121 | 121 |
| 122 static void registerStreamURLTask(const KURL& url, const String& type) | 122 static void registerStreamURLTask(const KURL& url, const String& type) |
| 123 { | 123 { |
| 124 if (WebBlobRegistry* registry = blobRegistry()) | 124 if (WebBlobRegistry* registry = getBlobRegistry()) |
| 125 registry->registerStreamURL(url, type); | 125 registry->registerStreamURL(url, type); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void BlobRegistry::registerStreamURL(const KURL& url, const String& type) | 128 void BlobRegistry::registerStreamURL(const KURL& url, const String& type) |
| 129 { | 129 { |
| 130 if (isMainThread()) | 130 if (isMainThread()) |
| 131 registerStreamURLTask(url, type); | 131 registerStreamURLTask(url, type); |
| 132 else | 132 else |
| 133 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(®isterStreamURLTask, url, type)); | 133 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(®isterStreamURLTask, url, type)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 static void registerStreamURLFromTask(const KURL& url, const KURL& srcURL) | 136 static void registerStreamURLFromTask(const KURL& url, const KURL& srcURL) |
| 137 { | 137 { |
| 138 if (WebBlobRegistry* registry = blobRegistry()) | 138 if (WebBlobRegistry* registry = getBlobRegistry()) |
| 139 registry->registerStreamURL(url, srcURL); | 139 registry->registerStreamURL(url, srcURL); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void BlobRegistry::registerStreamURL(SecurityOrigin* origin, const KURL& url, co
nst KURL& srcURL) | 142 void BlobRegistry::registerStreamURL(SecurityOrigin* origin, const KURL& url, co
nst KURL& srcURL) |
| 143 { | 143 { |
| 144 saveToOriginMap(origin, url); | 144 saveToOriginMap(origin, url); |
| 145 | 145 |
| 146 if (isMainThread()) | 146 if (isMainThread()) |
| 147 registerStreamURLFromTask(url, srcURL); | 147 registerStreamURLFromTask(url, srcURL); |
| 148 else | 148 else |
| 149 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(®isterStreamURLFromTask, url, srcURL)); | 149 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(®isterStreamURLFromTask, url, srcURL)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 static void addDataToStreamTask(const KURL& url, PassRefPtr<RawData> streamData) | 152 static void addDataToStreamTask(const KURL& url, PassRefPtr<RawData> streamData) |
| 153 { | 153 { |
| 154 if (WebBlobRegistry* registry = blobRegistry()) | 154 if (WebBlobRegistry* registry = getBlobRegistry()) |
| 155 registry->addDataToStream(url, streamData->data(), streamData->length())
; | 155 registry->addDataToStream(url, streamData->data(), streamData->length())
; |
| 156 } | 156 } |
| 157 | 157 |
| 158 void BlobRegistry::addDataToStream(const KURL& url, PassRefPtr<RawData> streamDa
ta) | 158 void BlobRegistry::addDataToStream(const KURL& url, PassRefPtr<RawData> streamDa
ta) |
| 159 { | 159 { |
| 160 if (isMainThread()) | 160 if (isMainThread()) |
| 161 addDataToStreamTask(url, std::move(streamData)); | 161 addDataToStreamTask(url, std::move(streamData)); |
| 162 else | 162 else |
| 163 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&addDataToStreamTask, url, streamData)); | 163 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&addDataToStreamTask, url, streamData)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 static void flushStreamTask(const KURL& url) | 166 static void flushStreamTask(const KURL& url) |
| 167 { | 167 { |
| 168 if (WebBlobRegistry* registry = blobRegistry()) | 168 if (WebBlobRegistry* registry = getBlobRegistry()) |
| 169 registry->flushStream(url); | 169 registry->flushStream(url); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void BlobRegistry::flushStream(const KURL& url) | 172 void BlobRegistry::flushStream(const KURL& url) |
| 173 { | 173 { |
| 174 if (isMainThread()) | 174 if (isMainThread()) |
| 175 flushStreamTask(url); | 175 flushStreamTask(url); |
| 176 else | 176 else |
| 177 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&flushStreamTask, url)); | 177 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&flushStreamTask, url)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 static void finalizeStreamTask(const KURL& url) | 180 static void finalizeStreamTask(const KURL& url) |
| 181 { | 181 { |
| 182 if (WebBlobRegistry* registry = blobRegistry()) | 182 if (WebBlobRegistry* registry = getBlobRegistry()) |
| 183 registry->finalizeStream(url); | 183 registry->finalizeStream(url); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void BlobRegistry::finalizeStream(const KURL& url) | 186 void BlobRegistry::finalizeStream(const KURL& url) |
| 187 { | 187 { |
| 188 if (isMainThread()) | 188 if (isMainThread()) |
| 189 finalizeStreamTask(url); | 189 finalizeStreamTask(url); |
| 190 else | 190 else |
| 191 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&finalizeStreamTask, url)); | 191 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&finalizeStreamTask, url)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 static void abortStreamTask(const KURL& url) | 194 static void abortStreamTask(const KURL& url) |
| 195 { | 195 { |
| 196 if (WebBlobRegistry* registry = blobRegistry()) | 196 if (WebBlobRegistry* registry = getBlobRegistry()) |
| 197 registry->abortStream(url); | 197 registry->abortStream(url); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void BlobRegistry::abortStream(const KURL& url) | 200 void BlobRegistry::abortStream(const KURL& url) |
| 201 { | 201 { |
| 202 if (isMainThread()) | 202 if (isMainThread()) |
| 203 abortStreamTask(url); | 203 abortStreamTask(url); |
| 204 else | 204 else |
| 205 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&abortStreamTask, url)); | 205 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, crossThreadBind(&abortStreamTask, url)); |
| 206 } | 206 } |
| 207 | 207 |
| 208 static void unregisterStreamURLTask(const KURL& url) | 208 static void unregisterStreamURLTask(const KURL& url) |
| 209 { | 209 { |
| 210 if (WebBlobRegistry* registry = blobRegistry()) | 210 if (WebBlobRegistry* registry = getBlobRegistry()) |
| 211 registry->unregisterStreamURL(url); | 211 registry->unregisterStreamURL(url); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void BlobRegistry::unregisterStreamURL(const KURL& url) | 214 void BlobRegistry::unregisterStreamURL(const KURL& url) |
| 215 { | 215 { |
| 216 removeFromOriginMap(url); | 216 removeFromOriginMap(url); |
| 217 | 217 |
| 218 if (isMainThread()) | 218 if (isMainThread()) |
| 219 unregisterStreamURLTask(url); | 219 unregisterStreamURLTask(url); |
| 220 else | 220 else |
| 221 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)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 BlobOriginMap::BlobOriginMap() | 224 BlobOriginMap::BlobOriginMap() |
| 225 { | 225 { |
| 226 SecurityOrigin::setMap(this); | 226 SecurityOrigin::setMap(this); |
| 227 } | 227 } |
| 228 | 228 |
| 229 SecurityOrigin* BlobOriginMap::getOrigin(const KURL& url) | 229 SecurityOrigin* BlobOriginMap::getOrigin(const KURL& url) |
| 230 { | 230 { |
| 231 if (url.protocolIs("blob")) | 231 if (url.protocolIs("blob")) |
| 232 return originMap()->get(url.getString()); | 232 return originMap()->get(url.getString()); |
| 233 return 0; | 233 return 0; |
| 234 } | 234 } |
| 235 | 235 |
| 236 } // namespace blink | 236 } // namespace blink |
| OLD | NEW |