| 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 "bindings/core/v8/ScriptState.h" |
| 9 #include "core/dom/DOMURL.h" | 9 #include "core/dom/DOMURL.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| 11 #include "core/fileapi/Blob.h" | 11 #include "core/fileapi/Blob.h" |
| 12 #include "core/frame/UseCounter.h" | 12 #include "core/frame/UseCounter.h" |
| 13 #include "core/html/PublicURLManager.h" | 13 #include "core/html/PublicURLManager.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 // static | 17 // static |
| 18 String URLFileAPI::createObjectURL(ScriptState* script_state, | 18 String URLFileAPI::createObjectURL(ScriptState* script_state, |
| 19 Blob* blob, | 19 Blob* blob, |
| 20 ExceptionState& exception_state) { | 20 ExceptionState& exception_state) { |
| 21 DCHECK(blob); | 21 DCHECK(blob); |
| 22 ExecutionContext* execution_context = script_state->GetExecutionContext(); | 22 ExecutionContext* execution_context = ExecutionContext::From(script_state); |
| 23 DCHECK(execution_context); | 23 DCHECK(execution_context); |
| 24 | 24 |
| 25 if (blob->isClosed()) { | 25 if (blob->isClosed()) { |
| 26 // 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 |
| 27 // without adding it to the store. | 27 // without adding it to the store. |
| 28 exception_state.ThrowDOMException( | 28 exception_state.ThrowDOMException( |
| 29 kInvalidStateError, | 29 kInvalidStateError, |
| 30 String(blob->IsFile() ? "File" : "Blob") + " has been closed."); | 30 String(blob->IsFile() ? "File" : "Blob") + " has been closed."); |
| 31 return String(); | 31 return String(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 UseCounter::Count(execution_context, UseCounter::kCreateObjectURLBlob); | 34 UseCounter::Count(execution_context, UseCounter::kCreateObjectURLBlob); |
| 35 return DOMURL::CreatePublicURL(execution_context, blob, blob->Uuid()); | 35 return DOMURL::CreatePublicURL(execution_context, blob, blob->Uuid()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 void URLFileAPI::revokeObjectURL(ScriptState* script_state, | 39 void URLFileAPI::revokeObjectURL(ScriptState* script_state, |
| 40 const String& url_string) { | 40 const String& url_string) { |
| 41 ExecutionContext* execution_context = script_state->GetExecutionContext(); | 41 ExecutionContext* execution_context = ExecutionContext::From(script_state); |
| 42 DCHECK(execution_context); | 42 DCHECK(execution_context); |
| 43 | 43 |
| 44 KURL url(KURL(), url_string); | 44 KURL url(KURL(), url_string); |
| 45 execution_context->RemoveURLFromMemoryCache(url); | 45 execution_context->RemoveURLFromMemoryCache(url); |
| 46 execution_context->GetPublicURLManager().Revoke(url); | 46 execution_context->GetPublicURLManager().Revoke(url); |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace blink | 49 } // namespace blink |
| OLD | NEW |