Chromium Code Reviews| Index: Source/modules/encryptedmedia/MediaKeySession.cpp |
| diff --git a/Source/modules/encryptedmedia/MediaKeySession.cpp b/Source/modules/encryptedmedia/MediaKeySession.cpp |
| index 54417cea2cccef7a985df4030b40b4afee349a95..d185c8a162425b117df179a13b5c4ca9d462523e 100644 |
| --- a/Source/modules/encryptedmedia/MediaKeySession.cpp |
| +++ b/Source/modules/encryptedmedia/MediaKeySession.cpp |
| @@ -36,9 +36,10 @@ |
| #include "core/events/Event.h" |
| #include "core/events/GenericEventQueue.h" |
| #include "core/html/MediaKeyError.h" |
| +#include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h" |
| #include "modules/encryptedmedia/MediaKeyMessageEvent.h" |
| #include "modules/encryptedmedia/MediaKeys.h" |
| -#include "modules/encryptedmedia/SimpleContentDecryptionModuleResult.h" |
| +#include "modules/encryptedmedia/SimpleContentDecryptionModuleResultPromise.h" |
| #include "platform/ContentDecryptionModuleResult.h" |
| #include "platform/ContentType.h" |
| #include "platform/Logging.h" |
| @@ -201,62 +202,37 @@ private: |
| // completeWithSession() will resolve the promise with void, while |
| // completeWithError() will reject the promise with an exception. complete() |
| // is not expected to be called, and will reject the promise. |
| -class NewSessionResult : public ContentDecryptionModuleResult { |
| +class NewSessionResult : public ContentDecryptionModuleResultPromise { |
|
ddorwin
2014/11/11 22:44:09
nit: If the base and Simple* are "...ResultPromise
jrummell
2014/11/11 23:30:11
Done.
|
| public: |
| NewSessionResult(ScriptState* scriptState, MediaKeySession* session) |
| - : m_resolver(ScriptPromiseResolver::create(scriptState)) |
| + : ContentDecryptionModuleResultPromise(scriptState) |
| , m_session(session) |
| { |
| - WTF_LOG(Media, "NewSessionResult(%p)", this); |
| } |
| virtual ~NewSessionResult() |
| { |
| - WTF_LOG(Media, "~NewSessionResult(%p)", this); |
| } |
| // ContentDecryptionModuleResult implementation. |
| - virtual void complete() override |
| - { |
| - ASSERT_NOT_REACHED(); |
| - completeWithDOMException(InvalidStateError, "Unexpected completion."); |
| - } |
| - |
| virtual void completeWithSession(WebContentDecryptionModuleResult::SessionStatus status) override |
| { |
| if (status != WebContentDecryptionModuleResult::NewSession) { |
| ASSERT_NOT_REACHED(); |
| - completeWithDOMException(InvalidStateError, "Unexpected completion."); |
| + reject(InvalidStateError, "Unexpected completion."); |
| } |
| m_session->finishGenerateRequest(); |
| - m_resolver->resolve(); |
| - m_resolver.clear(); |
| - } |
| - |
| - virtual void completeWithError(WebContentDecryptionModuleException exceptionCode, unsigned long systemCode, const WebString& errorMessage) override |
| - { |
| - completeWithDOMException(WebCdmExceptionToExceptionCode(exceptionCode), errorMessage); |
| + resolve(); |
| } |
| - // It is only valid to call this before completion. |
| - ScriptPromise promise() { return m_resolver->promise(); } |
| - |
| void trace(Visitor* visitor) |
| { |
| visitor->trace(m_session); |
| - ContentDecryptionModuleResult::trace(visitor); |
| + ContentDecryptionModuleResultPromise::trace(visitor); |
| } |
| private: |
| - // Reject the promise with a DOMException. |
| - void completeWithDOMException(ExceptionCode code, const String& errorMessage) |
| - { |
| - m_resolver->reject(DOMException::create(code, errorMessage)); |
| - m_resolver.clear(); |
| - } |
| - |
| - RefPtr<ScriptPromiseResolver> m_resolver; |
| Member<MediaKeySession> m_session; |
| }; |
| @@ -265,27 +241,19 @@ private: |
| // completeWithSession() will resolve the promise with true/false, while |
| // completeWithError() will reject the promise with an exception. complete() |
| // is not expected to be called, and will reject the promise. |
| -class LoadSessionResult : public ContentDecryptionModuleResult { |
| +class LoadSessionResult : public ContentDecryptionModuleResultPromise { |
| public: |
| LoadSessionResult(ScriptState* scriptState, MediaKeySession* session) |
| - : m_resolver(ScriptPromiseResolver::create(scriptState)) |
| + : ContentDecryptionModuleResultPromise(scriptState) |
| , m_session(session) |
| { |
| - WTF_LOG(Media, "LoadSessionResult(%p)", this); |
| } |
| virtual ~LoadSessionResult() |
| { |
| - WTF_LOG(Media, "~LoadSessionResult(%p)", this); |
| } |
| // ContentDecryptionModuleResult implementation. |
| - virtual void complete() override |
| - { |
| - ASSERT_NOT_REACHED(); |
| - completeWithDOMException(InvalidStateError, "Unexpected completion."); |
| - } |
| - |
| virtual void completeWithSession(WebContentDecryptionModuleResult::SessionStatus status) override |
| { |
| bool result = false; |
| @@ -300,38 +268,21 @@ public: |
| case WebContentDecryptionModuleResult::SessionAlreadyExists: |
| ASSERT_NOT_REACHED(); |
| - completeWithDOMException(InvalidStateError, "Unexpected completion."); |
| + reject(InvalidStateError, "Unexpected completion."); |
| return; |
| } |
| m_session->finishLoad(); |
| - m_resolver->resolve(result); |
| - m_resolver.clear(); |
| - } |
| - |
| - virtual void completeWithError(WebContentDecryptionModuleException exceptionCode, unsigned long systemCode, const WebString& errorMessage) override |
| - { |
| - completeWithDOMException(WebCdmExceptionToExceptionCode(exceptionCode), errorMessage); |
| + resolve(result); |
| } |
| - // It is only valid to call this before completion. |
| - ScriptPromise promise() { return m_resolver->promise(); } |
| - |
| void trace(Visitor* visitor) |
| { |
| visitor->trace(m_session); |
| - ContentDecryptionModuleResult::trace(visitor); |
| + ContentDecryptionModuleResultPromise::trace(visitor); |
| } |
| private: |
| - // Reject the promise with a DOMException. |
| - void completeWithDOMException(ExceptionCode code, const String& errorMessage) |
| - { |
| - m_resolver->reject(DOMException::create(code, errorMessage)); |
| - m_resolver.clear(); |
| - } |
| - |
| - RefPtr<ScriptPromiseResolver> m_resolver; |
| Member<MediaKeySession> m_session; |
| }; |
| @@ -582,7 +533,7 @@ ScriptPromise MediaKeySession::updateInternal(ScriptState* scriptState, PassRefP |
| // (Copied in the caller.) |
| // 3. Let promise be a new promise. |
| - SimpleContentDecryptionModuleResult* result = new SimpleContentDecryptionModuleResult(scriptState); |
| + SimpleContentDecryptionModuleResultPromise* result = new SimpleContentDecryptionModuleResultPromise(scriptState); |
| ScriptPromise promise = result->promise(); |
| // 4. Run the following steps asynchronously (documented in |
| @@ -619,7 +570,7 @@ ScriptPromise MediaKeySession::close(ScriptState* scriptState) |
| return ScriptPromise::cast(scriptState, ScriptValue()); |
| // 3. Let promise be a new promise. |
| - SimpleContentDecryptionModuleResult* result = new SimpleContentDecryptionModuleResult(scriptState); |
| + SimpleContentDecryptionModuleResultPromise* result = new SimpleContentDecryptionModuleResultPromise(scriptState); |
| ScriptPromise promise = result->promise(); |
| // 4. Run the following steps asynchronously (documented in |
| @@ -663,7 +614,7 @@ ScriptPromise MediaKeySession::remove(ScriptState* scriptState) |
| } |
| // 4. Let promise be a new promise. |
| - SimpleContentDecryptionModuleResult* result = new SimpleContentDecryptionModuleResult(scriptState); |
| + SimpleContentDecryptionModuleResultPromise* result = new SimpleContentDecryptionModuleResultPromise(scriptState); |
| ScriptPromise promise = result->promise(); |
| // 5. Run the following steps asynchronously (documented in |