| 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 "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/ExecutionContext.h" |
| 11 #include "core/dom/ExecutionContextTask.h" |
| 10 #include "public/platform/WebString.h" | 12 #include "public/platform/WebString.h" |
| 11 #include "wtf/Assertions.h" | 13 #include "wtf/Assertions.h" |
| 12 | 14 |
| 13 namespace blink { | 15 namespace blink { |
| 14 | 16 |
| 15 ExceptionCode WebCdmExceptionToExceptionCode(WebContentDecryptionModuleException
cdmException) | 17 ExceptionCode WebCdmExceptionToExceptionCode(WebContentDecryptionModuleException
cdmException) |
| 16 { | 18 { |
| 17 switch (cdmException) { | 19 switch (cdmException) { |
| 18 case WebContentDecryptionModuleExceptionNotSupportedError: | 20 case WebContentDecryptionModuleExceptionNotSupportedError: |
| 19 return NotSupportedError; | 21 return NotSupportedError; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 reject(WebCdmExceptionToExceptionCode(exceptionCode), errorString); | 80 reject(WebCdmExceptionToExceptionCode(exceptionCode), errorString); |
| 79 } | 81 } |
| 80 | 82 |
| 81 ScriptPromise ContentDecryptionModuleResultPromise::promise() | 83 ScriptPromise ContentDecryptionModuleResultPromise::promise() |
| 82 { | 84 { |
| 83 return m_resolver->promise(); | 85 return m_resolver->promise(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, const Stri
ng& errorMessage) | 88 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, const Stri
ng& errorMessage) |
| 87 { | 89 { |
| 90 // Reject the promise asynchronously. This avoids problems when gc is |
| 91 // destroying objects that result in unfulfilled promises being rejected. |
| 92 // (Resolving promises is still done synchronously as there may be events |
| 93 // already posted that need to happen only after the promise is resolved.) |
| 94 // TODO(jrummell): Make resolving a promise asynchronous as well (including |
| 95 // making sure events still happen after the promise is resolved). |
| 96 getExecutionContext()->postTask(BLINK_FROM_HERE, |
| 97 createSameThreadTask(&ContentDecryptionModuleResultPromise::rejectIntern
al, this, code, errorMessage)); |
| 98 } |
| 99 |
| 100 void ContentDecryptionModuleResultPromise::rejectInternal(ExceptionCode code, co
nst String& errorMessage) |
| 101 { |
| 88 m_resolver->reject(DOMException::create(code, errorMessage)); | 102 m_resolver->reject(DOMException::create(code, errorMessage)); |
| 89 m_resolver.clear(); | 103 m_resolver.clear(); |
| 90 } | 104 } |
| 91 | 105 |
| 92 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() co
nst | 106 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() co
nst |
| 93 { | 107 { |
| 94 return m_resolver->getExecutionContext(); | 108 return m_resolver->getExecutionContext(); |
| 95 } | 109 } |
| 96 | 110 |
| 97 DEFINE_TRACE(ContentDecryptionModuleResultPromise) | 111 DEFINE_TRACE(ContentDecryptionModuleResultPromise) |
| 98 { | 112 { |
| 99 visitor->trace(m_resolver); | 113 visitor->trace(m_resolver); |
| 100 ContentDecryptionModuleResult::trace(visitor); | 114 ContentDecryptionModuleResult::trace(visitor); |
| 101 } | 115 } |
| 102 | 116 |
| 103 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |