| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" | 6 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 // This class allows MediaKeys to be set asynchronously. | 49 // This class allows MediaKeys to be set asynchronously. |
| 50 class SetMediaKeysHandler : public ScriptPromiseResolver { | 50 class SetMediaKeysHandler : public ScriptPromiseResolver { |
| 51 WTF_MAKE_NONCOPYABLE(SetMediaKeysHandler); | 51 WTF_MAKE_NONCOPYABLE(SetMediaKeysHandler); |
| 52 | 52 |
| 53 public: | 53 public: |
| 54 static ScriptPromise create(ScriptState*, HTMLMediaElement&, MediaKeys*); | 54 static ScriptPromise create(ScriptState*, HTMLMediaElement&, MediaKeys*); |
| 55 virtual ~SetMediaKeysHandler(); | 55 virtual ~SetMediaKeysHandler(); |
| 56 | 56 |
| 57 virtual void trace(Visitor*) override; |
| 58 |
| 57 private: | 59 private: |
| 58 SetMediaKeysHandler(ScriptState*, HTMLMediaElement&, MediaKeys*); | 60 SetMediaKeysHandler(ScriptState*, HTMLMediaElement&, MediaKeys*); |
| 59 void timerFired(Timer<SetMediaKeysHandler>*); | 61 void timerFired(Timer<SetMediaKeysHandler>*); |
| 60 | 62 |
| 61 void clearExistingMediaKeys(); | 63 void clearExistingMediaKeys(); |
| 62 void setNewMediaKeys(); | 64 void setNewMediaKeys(); |
| 63 void finish(); | 65 void finish(); |
| 64 | 66 |
| 65 void reportSetFailed(ExceptionCode, const String& errorMessage); | 67 void reportSetFailed(ExceptionCode, const String& errorMessage); |
| 66 | 68 |
| 67 // Keep media element alive until promise is fulfilled | 69 // Keep media element alive until promise is fulfilled |
| 68 RefPtrWillBePersistent<HTMLMediaElement> m_element; | 70 RefPtrWillBeMember<HTMLMediaElement> m_element; |
| 69 Persistent<MediaKeys> m_newMediaKeys; | 71 PersistentWillBeMember<MediaKeys> m_newMediaKeys; |
| 70 Timer<SetMediaKeysHandler> m_timer; | 72 Timer<SetMediaKeysHandler> m_timer; |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 typedef Function<void()> SuccessCallback; | 75 typedef Function<void()> SuccessCallback; |
| 74 typedef Function<void(ExceptionCode, const String&)> FailureCallback; | 76 typedef Function<void(ExceptionCode, const String&)> FailureCallback; |
| 75 | 77 |
| 76 // Represents the result used when setContentDecryptionModule() is called. | 78 // Represents the result used when setContentDecryptionModule() is called. |
| 77 // Calls |success| if result is resolved, |failure| is result is rejected. | 79 // Calls |success| if result is resolved, |failure| is result is rejected. |
| 78 class SetContentDecryptionModuleResult final : public ContentDecryptionModuleRes
ult { | 80 class SetContentDecryptionModuleResult final : public ContentDecryptionModuleRes
ult { |
| 79 public: | 81 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), message); | 102 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), message); |
| 101 } | 103 } |
| 102 | 104 |
| 103 private: | 105 private: |
| 104 OwnPtr<SuccessCallback> m_successCallback; | 106 OwnPtr<SuccessCallback> m_successCallback; |
| 105 OwnPtr<FailureCallback> m_failureCallback; | 107 OwnPtr<FailureCallback> m_failureCallback; |
| 106 }; | 108 }; |
| 107 | 109 |
| 108 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle
ment& element, MediaKeys* mediaKeys) | 110 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle
ment& element, MediaKeys* mediaKeys) |
| 109 { | 111 { |
| 110 RefPtr<SetMediaKeysHandler> handler = adoptRef(new SetMediaKeysHandler(scrip
tState, element, mediaKeys)); | 112 RefPtrWillBeRawPtr<SetMediaKeysHandler> handler = adoptRefWillBeNoop(new Set
MediaKeysHandler(scriptState, element, mediaKeys)); |
| 111 handler->suspendIfNeeded(); | 113 handler->suspendIfNeeded(); |
| 112 handler->keepAliveWhilePending(); | 114 handler->keepAliveWhilePending(); |
| 113 return handler->promise(); | 115 return handler->promise(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 SetMediaKeysHandler::SetMediaKeysHandler(ScriptState* scriptState, HTMLMediaElem
ent& element, MediaKeys* mediaKeys) | 118 SetMediaKeysHandler::SetMediaKeysHandler(ScriptState* scriptState, HTMLMediaElem
ent& element, MediaKeys* mediaKeys) |
| 117 : ScriptPromiseResolver(scriptState) | 119 : ScriptPromiseResolver(scriptState) |
| 118 , m_element(element) | 120 , m_element(element) |
| 119 , m_newMediaKeys(mediaKeys) | 121 , m_newMediaKeys(mediaKeys) |
| 120 , m_timer(this, &SetMediaKeysHandler::timerFired) | 122 , m_timer(this, &SetMediaKeysHandler::timerFired) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 223 |
| 222 // 3.3.2 If the preceding step failed, run the following steps: | 224 // 3.3.2 If the preceding step failed, run the following steps: |
| 223 // 3.3.2.1 Set the mediaKeys attribute to null. | 225 // 3.3.2.1 Set the mediaKeys attribute to null. |
| 224 thisElement.m_mediaKeys.clear(); | 226 thisElement.m_mediaKeys.clear(); |
| 225 | 227 |
| 226 // 3.3.2.2 Reject promise with a new DOMException whose name is the | 228 // 3.3.2.2 Reject promise with a new DOMException whose name is the |
| 227 // appropriate error name and that has an appropriate message. | 229 // appropriate error name and that has an appropriate message. |
| 228 reject(DOMException::create(code, errorMessage)); | 230 reject(DOMException::create(code, errorMessage)); |
| 229 } | 231 } |
| 230 | 232 |
| 233 void SetMediaKeysHandler::trace(Visitor* visitor) |
| 234 { |
| 235 visitor->trace(m_element); |
| 236 visitor->trace(m_newMediaKeys); |
| 237 ScriptPromiseResolver::trace(visitor); |
| 238 } |
| 239 |
| 231 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() | 240 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() |
| 232 : m_emeMode(EmeModeNotSelected) | 241 : m_emeMode(EmeModeNotSelected) |
| 233 { | 242 { |
| 234 } | 243 } |
| 235 | 244 |
| 236 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) | 245 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) |
| 237 | 246 |
| 238 const char* HTMLMediaElementEncryptedMedia::supplementName() | 247 const char* HTMLMediaElementEncryptedMedia::supplementName() |
| 239 { | 248 { |
| 240 return "HTMLMediaElementEncryptedMedia"; | 249 return "HTMLMediaElementEncryptedMedia"; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 return thisElement.contentDecryptionModule(); | 552 return thisElement.contentDecryptionModule(); |
| 544 } | 553 } |
| 545 | 554 |
| 546 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 555 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
| 547 { | 556 { |
| 548 visitor->trace(m_mediaKeys); | 557 visitor->trace(m_mediaKeys); |
| 549 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 558 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
| 550 } | 559 } |
| 551 | 560 |
| 552 } // namespace blink | 561 } // namespace blink |
| OLD | NEW |