Chromium Code Reviews| Index: third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h |
| diff --git a/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h b/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h |
| index 104d15b4004d1686527843e6945961a750445c07..07972488a70fb865a7eac7ae6f9163e6749a2b73 100644 |
| --- a/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h |
| +++ b/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h |
| @@ -6,6 +6,7 @@ |
| #define ContentDecryptionModuleResultPromise_h |
| #include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "core/dom/ContextLifecycleObserver.h" |
| #include "core/dom/ExceptionCode.h" |
| #include "platform/ContentDecryptionModuleResult.h" |
| @@ -20,7 +21,10 @@ ExceptionCode WebCdmExceptionToExceptionCode( |
| // with an error. It needs to be subclassed and the appropriate complete() |
| // method overridden to resolve the promise as needed. |
| class ContentDecryptionModuleResultPromise |
| - : public ContentDecryptionModuleResult { |
| + : public ContentDecryptionModuleResult, |
| + public ContextLifecycleObserver { |
| + USING_GARBAGE_COLLECTED_MIXIN(ContentDecryptionModuleResultPromise); |
| + |
| public: |
| ~ContentDecryptionModuleResultPromise() override; |
| @@ -34,6 +38,9 @@ class ContentDecryptionModuleResultPromise |
| unsigned long systemCode, |
| const WebString&) override; |
| + // ContextLifecycleObserver implementation. |
| + void contextDestroyed() override; |
| + |
| // It is only valid to call this before completion. |
| ScriptPromise promise(); |
| @@ -46,6 +53,12 @@ class ContentDecryptionModuleResultPromise |
| // promise. |
| template <typename... T> |
| void resolve(T... value) { |
| + if (m_contextDestroyed || |
| + getExecutionContext()->activeDOMObjectsAreStopped()) { |
|
jrummell
2016/10/10 21:06:15
I included activeDOMObjectsAreStopped() since cont
|
| + m_resolver.clear(); |
| + return; |
| + } |
| + |
| m_resolver->resolve(value...); |
| m_resolver.clear(); |
| } |
| @@ -54,13 +67,11 @@ class ContentDecryptionModuleResultPromise |
| // actually reject the promise later on. |
| void reject(ExceptionCode, const String& errorMessage); |
| - ExecutionContext* getExecutionContext() const; |
| - |
| private: |
| - // Rejects the promise with a DOMException. |
| - void rejectInternal(ExceptionCode, const String& errorMessage); |
| - |
| Member<ScriptPromiseResolver> m_resolver; |
| + |
| + // Set once the Context is destroyed. |
| + bool m_contextDestroyed; |
| }; |
| } // namespace blink |