| 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 "bindings/core/v8/ScriptState.h" |
| 8 #include "core/dom/DOMURL.h" | 9 #include "core/dom/DOMURL.h" |
| 9 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/fileapi/Blob.h" | 11 #include "core/fileapi/Blob.h" |
| 11 #include "core/frame/UseCounter.h" | 12 #include "core/frame/UseCounter.h" |
| 12 #include "core/html/PublicURLManager.h" | 13 #include "core/html/PublicURLManager.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 // static | 17 // static |
| 17 String URLFileAPI::createObjectURL(ExecutionContext* executionContext, | 18 String URLFileAPI::createObjectURL(ScriptState* scriptState, |
| 18 Blob* blob, | 19 Blob* blob, |
| 19 ExceptionState& exceptionState) { | 20 ExceptionState& exceptionState) { |
| 20 DCHECK(blob); | 21 DCHECK(blob); |
| 22 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 21 DCHECK(executionContext); | 23 DCHECK(executionContext); |
| 22 | 24 |
| 23 if (blob->isClosed()) { | 25 if (blob->isClosed()) { |
| 24 // TODO(jsbell): The spec doesn't throw, but rather returns a blob: URL | 26 // TODO(jsbell): The spec doesn't throw, but rather returns a blob: URL |
| 25 // without adding it to the store. | 27 // without adding it to the store. |
| 26 exceptionState.throwDOMException( | 28 exceptionState.throwDOMException( |
| 27 InvalidStateError, | 29 InvalidStateError, |
| 28 String(blob->isFile() ? "File" : "Blob") + " has been closed."); | 30 String(blob->isFile() ? "File" : "Blob") + " has been closed."); |
| 29 return String(); | 31 return String(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 UseCounter::count(executionContext, UseCounter::CreateObjectURLBlob); | 34 UseCounter::count(executionContext, UseCounter::CreateObjectURLBlob); |
| 33 return DOMURL::createPublicURL(executionContext, blob, blob->uuid()); | 35 return DOMURL::createPublicURL(executionContext, blob, blob->uuid()); |
| 34 } | 36 } |
| 35 | 37 |
| 36 // static | 38 // static |
| 37 void URLFileAPI::revokeObjectURL(ExecutionContext* executionContext, | 39 void URLFileAPI::revokeObjectURL(ScriptState* scriptState, |
| 38 const String& urlString) { | 40 const String& urlString) { |
| 41 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 39 DCHECK(executionContext); | 42 DCHECK(executionContext); |
| 40 | 43 |
| 41 KURL url(KURL(), urlString); | 44 KURL url(KURL(), urlString); |
| 42 executionContext->removeURLFromMemoryCache(url); | 45 executionContext->removeURLFromMemoryCache(url); |
| 43 executionContext->publicURLManager().revoke(url); | 46 executionContext->publicURLManager().revoke(url); |
| 44 } | 47 } |
| 45 | 48 |
| 46 } // namespace blink | 49 } // namespace blink |
| OLD | NEW |