Chromium Code Reviews| 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 #ifndef ContentDecryptionModuleResultPromise_h | 5 #ifndef ContentDecryptionModuleResultPromise_h |
| 6 #define ContentDecryptionModuleResultPromise_h | 6 #define ContentDecryptionModuleResultPromise_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/ContextLifecycleObserver.h" | |
| 9 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| 10 #include "platform/ContentDecryptionModuleResult.h" | 11 #include "platform/ContentDecryptionModuleResult.h" |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 14 ExceptionCode WebCdmExceptionToExceptionCode( | 15 ExceptionCode WebCdmExceptionToExceptionCode( |
| 15 WebContentDecryptionModuleException); | 16 WebContentDecryptionModuleException); |
| 16 | 17 |
| 17 // This class wraps the promise resolver to simplify creation of | 18 // This class wraps the promise resolver to simplify creation of |
| 18 // ContentDecryptionModuleResult objects. The default implementations of the | 19 // ContentDecryptionModuleResult objects. The default implementations of the |
| 19 // complete(), completeWithSession(), etc. methods will reject the promise | 20 // complete(), completeWithSession(), etc. methods will reject the promise |
| 20 // with an error. It needs to be subclassed and the appropriate complete() | 21 // with an error. It needs to be subclassed and the appropriate complete() |
| 21 // method overridden to resolve the promise as needed. | 22 // method overridden to resolve the promise as needed. |
| 22 class ContentDecryptionModuleResultPromise | 23 class ContentDecryptionModuleResultPromise |
| 23 : public ContentDecryptionModuleResult { | 24 : public ContentDecryptionModuleResult, |
| 25 public ContextLifecycleObserver { | |
| 26 USING_GARBAGE_COLLECTED_MIXIN(ContentDecryptionModuleResultPromise); | |
| 27 | |
| 24 public: | 28 public: |
| 25 ~ContentDecryptionModuleResultPromise() override; | 29 ~ContentDecryptionModuleResultPromise() override; |
| 26 | 30 |
| 27 // ContentDecryptionModuleResult implementation. | 31 // ContentDecryptionModuleResult implementation. |
| 28 void complete() override; | 32 void complete() override; |
| 29 void completeWithContentDecryptionModule( | 33 void completeWithContentDecryptionModule( |
| 30 WebContentDecryptionModule*) override; | 34 WebContentDecryptionModule*) override; |
| 31 void completeWithSession( | 35 void completeWithSession( |
| 32 WebContentDecryptionModuleResult::SessionStatus) override; | 36 WebContentDecryptionModuleResult::SessionStatus) override; |
| 33 void completeWithError(WebContentDecryptionModuleException, | 37 void completeWithError(WebContentDecryptionModuleException, |
| 34 unsigned long systemCode, | 38 unsigned long systemCode, |
| 35 const WebString&) override; | 39 const WebString&) override; |
| 36 | 40 |
| 41 // ContextLifecycleObserver implementation. | |
| 42 void contextDestroyed() override; | |
| 43 | |
| 37 // It is only valid to call this before completion. | 44 // It is only valid to call this before completion. |
| 38 ScriptPromise promise(); | 45 ScriptPromise promise(); |
| 39 | 46 |
| 40 DECLARE_VIRTUAL_TRACE(); | 47 DECLARE_VIRTUAL_TRACE(); |
| 41 | 48 |
| 42 protected: | 49 protected: |
| 43 explicit ContentDecryptionModuleResultPromise(ScriptState*); | 50 explicit ContentDecryptionModuleResultPromise(ScriptState*); |
| 44 | 51 |
| 45 // Resolves the promise with |value|. Used by subclasses to resolve the | 52 // Resolves the promise with |value|. Used by subclasses to resolve the |
| 46 // promise. | 53 // promise. |
| 47 template <typename... T> | 54 template <typename... T> |
| 48 void resolve(T... value) { | 55 void resolve(T... value) { |
| 56 if (!isValidToFulfillPromise()) | |
| 57 return; | |
| 58 | |
| 49 m_resolver->resolve(value...); | 59 m_resolver->resolve(value...); |
| 50 m_resolver.clear(); | 60 m_resolver.clear(); |
| 51 } | 61 } |
| 52 | 62 |
| 53 // Rejects the promise with a DOMException. This will post a task to | 63 // Rejects the promise with a DOMException. This will post a task to |
| 54 // actually reject the promise later on. | 64 // actually reject the promise later on. |
|
xhwang
2016/10/13 19:29:58
Update this comment.
jrummell
2016/10/14 00:03:31
Done.
| |
| 55 void reject(ExceptionCode, const String& errorMessage); | 65 void reject(ExceptionCode, const String& errorMessage); |
| 56 | 66 |
| 57 ExecutionContext* getExecutionContext() const; | 67 // Determine if it's OK to resolve/reject this promise. |
| 68 bool isValidToFulfillPromise(); | |
| 58 | 69 |
| 59 private: | 70 private: |
| 60 // Rejects the promise with a DOMException. | |
| 61 void rejectInternal(ExceptionCode, const String& errorMessage); | |
| 62 | |
| 63 Member<ScriptPromiseResolver> m_resolver; | 71 Member<ScriptPromiseResolver> m_resolver; |
| 64 }; | 72 }; |
| 65 | 73 |
| 66 } // namespace blink | 74 } // namespace blink |
| 67 | 75 |
| 68 #endif // ContentDecryptionModuleResultPromise_h | 76 #endif // ContentDecryptionModuleResultPromise_h |
| OLD | NEW |