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 26 matching lines...) Expand all Loading... |
106 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), message); | 108 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), message); |
107 } | 109 } |
108 | 110 |
109 private: | 111 private: |
110 OwnPtr<SuccessCallback> m_successCallback; | 112 OwnPtr<SuccessCallback> m_successCallback; |
111 OwnPtr<FailureCallback> m_failureCallback; | 113 OwnPtr<FailureCallback> m_failureCallback; |
112 }; | 114 }; |
113 | 115 |
114 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle
ment& element, MediaKeys* mediaKeys) | 116 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle
ment& element, MediaKeys* mediaKeys) |
115 { | 117 { |
116 RefPtr<SetMediaKeysHandler> handler = adoptRef(new SetMediaKeysHandler(scrip
tState, element, mediaKeys)); | 118 RefPtrWillBeRawPtr<SetMediaKeysHandler> handler = adoptRefWillBeNoop(new Set
MediaKeysHandler(scriptState, element, mediaKeys)); |
117 handler->suspendIfNeeded(); | 119 handler->suspendIfNeeded(); |
118 handler->keepAliveWhilePending(); | 120 handler->keepAliveWhilePending(); |
119 return handler->promise(); | 121 return handler->promise(); |
120 } | 122 } |
121 | 123 |
122 SetMediaKeysHandler::SetMediaKeysHandler(ScriptState* scriptState, HTMLMediaElem
ent& element, MediaKeys* mediaKeys) | 124 SetMediaKeysHandler::SetMediaKeysHandler(ScriptState* scriptState, HTMLMediaElem
ent& element, MediaKeys* mediaKeys) |
123 : ScriptPromiseResolver(scriptState) | 125 : ScriptPromiseResolver(scriptState) |
124 , m_element(element) | 126 , m_element(element) |
125 , m_newMediaKeys(mediaKeys) | 127 , m_newMediaKeys(mediaKeys) |
126 , m_timer(this, &SetMediaKeysHandler::timerFired) | 128 , m_timer(this, &SetMediaKeysHandler::timerFired) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 229 |
228 // 3.3.2 If the preceding step failed, run the following steps: | 230 // 3.3.2 If the preceding step failed, run the following steps: |
229 // 3.3.2.1 Set the mediaKeys attribute to null. | 231 // 3.3.2.1 Set the mediaKeys attribute to null. |
230 thisElement.m_mediaKeys.clear(); | 232 thisElement.m_mediaKeys.clear(); |
231 | 233 |
232 // 3.3.2.2 Reject promise with a new DOMException whose name is the | 234 // 3.3.2.2 Reject promise with a new DOMException whose name is the |
233 // appropriate error name and that has an appropriate message. | 235 // appropriate error name and that has an appropriate message. |
234 reject(DOMException::create(code, errorMessage)); | 236 reject(DOMException::create(code, errorMessage)); |
235 } | 237 } |
236 | 238 |
| 239 void SetMediaKeysHandler::trace(Visitor* visitor) |
| 240 { |
| 241 visitor->trace(m_element); |
| 242 visitor->trace(m_newMediaKeys); |
| 243 ScriptPromiseResolver::trace(visitor); |
| 244 } |
| 245 |
237 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() | 246 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() |
238 : m_emeMode(EmeModeNotSelected) | 247 : m_emeMode(EmeModeNotSelected) |
239 { | 248 { |
240 } | 249 } |
241 | 250 |
242 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) | 251 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) |
243 | 252 |
244 const char* HTMLMediaElementEncryptedMedia::supplementName() | 253 const char* HTMLMediaElementEncryptedMedia::supplementName() |
245 { | 254 { |
246 return "HTMLMediaElementEncryptedMedia"; | 255 return "HTMLMediaElementEncryptedMedia"; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 return thisElement.contentDecryptionModule(); | 548 return thisElement.contentDecryptionModule(); |
540 } | 549 } |
541 | 550 |
542 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 551 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
543 { | 552 { |
544 visitor->trace(m_mediaKeys); | 553 visitor->trace(m_mediaKeys); |
545 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 554 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
546 } | 555 } |
547 | 556 |
548 } // namespace blink | 557 } // namespace blink |
OLD | NEW |