OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ContentDecryptionModuleResultPromise_h |
| 6 #define ContentDecryptionModuleResultPromise_h |
| 7 |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "platform/ContentDecryptionModuleResult.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 ExceptionCode WebCdmExceptionToExceptionCode(WebContentDecryptionModuleException
); |
| 15 |
| 16 // This class wraps the promise resolver to simplify creation of |
| 17 // ContentDecryptionModuleResult objects. The default implementations of the |
| 18 // complete(), completeWithSession(), etc. methods will reject the promise |
| 19 // with an error. It needs to be subclassed and the appropriate complete() |
| 20 // method overridden to resolve the promise as needed. |
| 21 class ContentDecryptionModuleResultPromise : public ContentDecryptionModuleResul
t { |
| 22 public: |
| 23 virtual ~ContentDecryptionModuleResultPromise(); |
| 24 |
| 25 // ContentDecryptionModuleResult implementation. |
| 26 virtual void complete() override; |
| 27 virtual void completeWithSession(WebContentDecryptionModuleResult::SessionSt
atus) override; |
| 28 virtual void completeWithError(WebContentDecryptionModuleException, unsigned
long systemCode, const WebString&) final; |
| 29 |
| 30 // It is only valid to call this before completion. |
| 31 ScriptPromise promise(); |
| 32 |
| 33 virtual void trace(Visitor*); |
| 34 |
| 35 protected: |
| 36 explicit ContentDecryptionModuleResultPromise(ScriptState*); |
| 37 |
| 38 // Resolves the promise with |value|. Used by subclasses to resolve the |
| 39 // promise. |
| 40 template <typename... T> |
| 41 void resolve(T... value) |
| 42 { |
| 43 m_resolver->resolve(value...); |
| 44 m_resolver.clear(); |
| 45 } |
| 46 |
| 47 // Rejects the promise with a DOMException. |
| 48 void reject(ExceptionCode, const String& errorMessage); |
| 49 |
| 50 ExecutionContext* executionContext() const; |
| 51 |
| 52 private: |
| 53 RefPtr<ScriptPromiseResolver> m_resolver; |
| 54 }; |
| 55 |
| 56 } // namespace blink |
| 57 |
| 58 #endif // ContentDecryptionModuleResultPromise_h |
OLD | NEW |