OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/fileapi/URLFileAPI.h" | 5 #include "core/fileapi/URLFileAPI.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "core/dom/DOMURL.h" | 8 #include "core/dom/DOMURL.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "core/fileapi/Blob.h" | 10 #include "core/fileapi/Blob.h" |
| 11 #include "core/frame/UseCounter.h" |
11 #include "core/html/PublicURLManager.h" | 12 #include "core/html/PublicURLManager.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
15 // static | 16 // static |
16 String URLFileAPI::createObjectURL(ExecutionContext* executionContext, Blob* blo
b, ExceptionState& exceptionState) | 17 String URLFileAPI::createObjectURL(ExecutionContext* executionContext, Blob* blo
b, ExceptionState& exceptionState) |
17 { | 18 { |
18 DCHECK(blob); | 19 DCHECK(blob); |
19 DCHECK(executionContext); | 20 DCHECK(executionContext); |
20 | 21 |
21 if (blob->isClosed()) { | 22 if (blob->isClosed()) { |
| 23 // TODO(jsbell): The spec doesn't throw, but rather returns a blob: URL |
| 24 // without adding it to the store. |
22 exceptionState.throwDOMException(InvalidStateError, String(blob->isFile(
) ? "File" : "Blob") + " has been closed."); | 25 exceptionState.throwDOMException(InvalidStateError, String(blob->isFile(
) ? "File" : "Blob") + " has been closed."); |
23 return String(); | 26 return String(); |
24 } | 27 } |
| 28 |
| 29 UseCounter::count(executionContext, UseCounter::CreateObjectURLBlob); |
25 return DOMURL::createPublicURL(executionContext, blob, blob->uuid()); | 30 return DOMURL::createPublicURL(executionContext, blob, blob->uuid()); |
26 } | 31 } |
27 | 32 |
28 // static | 33 // static |
29 void URLFileAPI::revokeObjectURL(ExecutionContext* executionContext, const Strin
g& urlString) | 34 void URLFileAPI::revokeObjectURL(ExecutionContext* executionContext, const Strin
g& urlString) |
30 { | 35 { |
31 DCHECK(executionContext); | 36 DCHECK(executionContext); |
32 | 37 |
33 KURL url(KURL(), urlString); | 38 KURL url(KURL(), urlString); |
34 executionContext->removeURLFromMemoryCache(url); | 39 executionContext->removeURLFromMemoryCache(url); |
35 executionContext->publicURLManager().revoke(url); | 40 executionContext->publicURLManager().revoke(url); |
36 } | 41 } |
37 | 42 |
38 } // namespace blink | 43 } // namespace blink |
OLD | NEW |