| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h" | 5 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/V8ThrowException.h" |
| 9 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/ExecutionContext.h" | 11 #include "core/dom/ExecutionContext.h" |
| 11 #include "core/dom/ExecutionContextTask.h" | 12 #include "core/dom/ExecutionContextTask.h" |
| 12 #include "public/platform/WebString.h" | 13 #include "public/platform/WebString.h" |
| 13 #include "wtf/Assertions.h" | 14 #include "wtf/Assertions.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 ExceptionCode WebCdmExceptionToExceptionCode( | 18 ExceptionCode WebCdmExceptionToExceptionCode( |
| 18 WebContentDecryptionModuleException cdmException) { | 19 WebContentDecryptionModuleException cdmException) { |
| 19 switch (cdmException) { | 20 switch (cdmException) { |
| 21 case WebContentDecryptionModuleExceptionTypeError: |
| 22 return V8TypeError; |
| 20 case WebContentDecryptionModuleExceptionNotSupportedError: | 23 case WebContentDecryptionModuleExceptionNotSupportedError: |
| 21 return NotSupportedError; | 24 return NotSupportedError; |
| 22 case WebContentDecryptionModuleExceptionInvalidStateError: | 25 case WebContentDecryptionModuleExceptionInvalidStateError: |
| 23 return InvalidStateError; | 26 return InvalidStateError; |
| 24 case WebContentDecryptionModuleExceptionInvalidAccessError: | |
| 25 return InvalidAccessError; | |
| 26 case WebContentDecryptionModuleExceptionQuotaExceededError: | 27 case WebContentDecryptionModuleExceptionQuotaExceededError: |
| 27 return QuotaExceededError; | 28 return QuotaExceededError; |
| 28 case WebContentDecryptionModuleExceptionUnknownError: | 29 case WebContentDecryptionModuleExceptionUnknownError: |
| 29 return UnknownError; | 30 return UnknownError; |
| 30 case WebContentDecryptionModuleExceptionClientError: | |
| 31 case WebContentDecryptionModuleExceptionOutputError: | |
| 32 // Currently no matching DOMException for these 2 errors. | |
| 33 // FIXME: Update DOMException to handle these if actually added to | |
| 34 // the EME spec. | |
| 35 return UnknownError; | |
| 36 } | 31 } |
| 37 | 32 |
| 38 NOTREACHED(); | 33 NOTREACHED(); |
| 39 return UnknownError; | 34 return UnknownError; |
| 40 } | 35 } |
| 41 | 36 |
| 42 ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise( | 37 ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise( |
| 43 ScriptState* scriptState) | 38 ScriptState* scriptState) |
| 44 : m_resolver(ScriptPromiseResolver::create(scriptState)) {} | 39 : m_resolver(ScriptPromiseResolver::create(scriptState)) {} |
| 45 | 40 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 86 } |
| 92 | 87 |
| 93 ScriptPromise ContentDecryptionModuleResultPromise::promise() { | 88 ScriptPromise ContentDecryptionModuleResultPromise::promise() { |
| 94 return m_resolver->promise(); | 89 return m_resolver->promise(); |
| 95 } | 90 } |
| 96 | 91 |
| 97 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, | 92 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, |
| 98 const String& errorMessage) { | 93 const String& errorMessage) { |
| 99 DCHECK(isValidToFulfillPromise()); | 94 DCHECK(isValidToFulfillPromise()); |
| 100 | 95 |
| 101 m_resolver->reject(DOMException::create(code, errorMessage)); | 96 ScriptState::Scope scope(m_resolver->getScriptState()); |
| 97 v8::Isolate* isolate = m_resolver->getScriptState()->isolate(); |
| 98 m_resolver->reject( |
| 99 V8ThrowException::createDOMException(isolate, code, errorMessage)); |
| 102 m_resolver.clear(); | 100 m_resolver.clear(); |
| 103 } | 101 } |
| 104 | 102 |
| 105 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() | 103 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() |
| 106 const { | 104 const { |
| 107 return m_resolver->getExecutionContext(); | 105 return m_resolver->getExecutionContext(); |
| 108 } | 106 } |
| 109 | 107 |
| 110 bool ContentDecryptionModuleResultPromise::isValidToFulfillPromise() { | 108 bool ContentDecryptionModuleResultPromise::isValidToFulfillPromise() { |
| 111 // getExecutionContext() is no longer valid once the context is destroyed. | 109 // getExecutionContext() is no longer valid once the context is destroyed. |
| 112 // activeDOMObjectsAreStopped() is called to see if the context is in the | 110 // activeDOMObjectsAreStopped() is called to see if the context is in the |
| 113 // process of being destroyed. If it is, there is no need to fulfill this | 111 // process of being destroyed. If it is, there is no need to fulfill this |
| 114 // promise which is about to go away anyway. | 112 // promise which is about to go away anyway. |
| 115 return getExecutionContext() && | 113 return getExecutionContext() && |
| 116 !getExecutionContext()->activeDOMObjectsAreStopped(); | 114 !getExecutionContext()->activeDOMObjectsAreStopped(); |
| 117 } | 115 } |
| 118 | 116 |
| 119 DEFINE_TRACE(ContentDecryptionModuleResultPromise) { | 117 DEFINE_TRACE(ContentDecryptionModuleResultPromise) { |
| 120 visitor->trace(m_resolver); | 118 visitor->trace(m_resolver); |
| 121 ContentDecryptionModuleResult::trace(visitor); | 119 ContentDecryptionModuleResult::trace(visitor); |
| 122 } | 120 } |
| 123 | 121 |
| 124 } // namespace blink | 122 } // namespace blink |
| OLD | NEW |