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" | |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
11 #include "bindings/core/v8/ScriptState.h" | |
12 #include "core/dom/DOMException.h" | |
9 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
10 #include "core/html/HTMLMediaElement.h" | 14 #include "core/html/HTMLMediaElement.h" |
11 #include "core/html/MediaKeyError.h" | 15 #include "core/html/MediaKeyError.h" |
12 #include "core/html/MediaKeyEvent.h" | 16 #include "core/html/MediaKeyEvent.h" |
13 #include "modules/encryptedmedia/MediaKeyNeededEvent.h" | 17 #include "modules/encryptedmedia/MediaKeyNeededEvent.h" |
14 #include "modules/encryptedmedia/MediaKeys.h" | 18 #include "modules/encryptedmedia/MediaKeys.h" |
19 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResult.h" | |
20 #include "platform/ContentDecryptionModuleResult.h" | |
15 #include "platform/Logging.h" | 21 #include "platform/Logging.h" |
16 #include "platform/RuntimeEnabledFeatures.h" | 22 #include "platform/RuntimeEnabledFeatures.h" |
17 #include "wtf/Uint8Array.h" | 23 #include "wtf/Uint8Array.h" |
18 | 24 |
19 namespace blink { | 25 namespace blink { |
20 | 26 |
21 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c onst String& sessionId, blink::WebMediaPlayer::MediaKeyException exception, Exce ptionState& exceptionState) | 27 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c onst String& sessionId, blink::WebMediaPlayer::MediaKeyException exception, Exce ptionState& exceptionState) |
22 { | 28 { |
23 switch (exception) { | 29 switch (exception) { |
24 case blink::WebMediaPlayer::MediaKeyExceptionNoError: | 30 case blink::WebMediaPlayer::MediaKeyExceptionNoError: |
25 return; | 31 return; |
26 case blink::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState: | 32 case blink::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState: |
27 exceptionState.throwDOMException(InvalidStateError, "The player is in an invalid state."); | 33 exceptionState.throwDOMException(InvalidStateError, "The player is in an invalid state."); |
28 return; | 34 return; |
29 case blink::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported: | 35 case blink::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported: |
30 exceptionState.throwDOMException(NotSupportedError, "The key system prov ided ('" + keySystem +"') is not supported."); | 36 exceptionState.throwDOMException(NotSupportedError, "The key system prov ided ('" + keySystem +"') is not supported."); |
31 return; | 37 return; |
32 case blink::WebMediaPlayer::MediaKeyExceptionInvalidAccess: | 38 case blink::WebMediaPlayer::MediaKeyExceptionInvalidAccess: |
33 exceptionState.throwDOMException(InvalidAccessError, "The session ID pro vided ('" + sessionId + "') is invalid."); | 39 exceptionState.throwDOMException(InvalidAccessError, "The session ID pro vided ('" + sessionId + "') is invalid."); |
34 return; | 40 return; |
35 } | 41 } |
36 | 42 |
37 ASSERT_NOT_REACHED(); | 43 ASSERT_NOT_REACHED(); |
38 return; | 44 return; |
39 } | 45 } |
40 | 46 |
47 // This class allows MediaKeys to be set asynchronously. | |
48 class SetMediaKeysHandler : public ScriptPromiseResolver { | |
49 WTF_MAKE_NONCOPYABLE(SetMediaKeysHandler); | |
50 | |
51 public: | |
52 static ScriptPromise create(ScriptState*, HTMLMediaElement&, MediaKeys*); | |
53 virtual ~SetMediaKeysHandler(); | |
54 | |
55 void completeWithDOMException(ExceptionCode, const String& errorMessage); | |
ddorwin
2014/08/08 02:50:51
Is completeWithDOMException the terminology used e
jrummell
2014/08/08 23:15:12
ContentDecryptionModuleResult uses completeWith...
| |
56 void timerFired(Timer<SetMediaKeysHandler>*); | |
57 void proceedToNextStage(); | |
58 | |
59 private: | |
60 enum Stage { | |
61 Starting, | |
62 Clearing, | |
63 Setting | |
64 }; | |
65 SetMediaKeysHandler(ScriptState*, HTMLMediaElement&, MediaKeys*); | |
66 | |
67 RawPtrWillBeMember<HTMLMediaElement> m_element; | |
68 Persistent<MediaKeys> m_mediaKeys; | |
69 | |
70 Stage m_stage; | |
71 Timer<SetMediaKeysHandler> m_timer; | |
72 }; | |
73 | |
74 // Represents the result used when setContentDecryptionModule() is called. | |
ddorwin
2014/08/08 02:50:52
It seems there must be a cleaner way of handling t
jrummell
2014/08/08 23:15:12
How about this?
| |
75 // Needed as SetMediaKeysHandler may need to call setContentDecryptionModule() | |
76 // multiple times, and not resolve the promise until the very end. Any errors | |
ddorwin
2014/08/08 02:50:51
What does until the very end mean? Each setMK shou
jrummell
2014/08/08 23:15:13
Removed.
| |
77 // that happen will reject the promise immediately. | |
ddorwin
2014/08/08 02:50:51
But not if a worker is not provided. I think this
jrummell
2014/08/08 23:15:12
Acknowledged.
| |
78 // | |
79 // This class can be used without specifying a worker to call. Useful when | |
ddorwin
2014/08/08 02:50:51
Replace "worker".
jrummell
2014/08/08 23:15:12
Done.
| |
80 // calling setContentDecryptionModule() while tearing down a player. | |
ddorwin
2014/08/08 02:50:51
*Not specifying is* useful when... ?
Do we even n
jrummell
2014/08/08 23:15:12
Removed.
| |
81 class SetContentDecryptionModuleResult FINAL : public ContentDecryptionModuleRes ult { | |
82 public: | |
83 explicit SetContentDecryptionModuleResult(SetMediaKeysHandler* worker) | |
84 : m_worker(worker) | |
ddorwin
2014/08/08 02:50:51
change var names too
jrummell
2014/08/08 23:15:12
Done.
| |
85 { | |
86 } | |
87 | |
88 // ContentDecryptionModuleResult implementation. | |
89 virtual void complete() OVERRIDE | |
90 { | |
91 if (m_worker) | |
92 m_worker->proceedToNextStage(); | |
93 } | |
94 | |
95 virtual void completeWithSession(blink::WebContentDecryptionModuleResult::Se ssionStatus status) OVERRIDE | |
96 { | |
97 ASSERT_NOT_REACHED(); | |
98 if (m_worker) | |
99 m_worker->completeWithDOMException(InvalidStateError, "Unexpected co mpletion."); | |
100 } | |
101 | |
102 virtual void completeWithError(blink::WebContentDecryptionModuleException co de, unsigned long systemCode, const blink::WebString& message) OVERRIDE | |
103 { | |
104 if (m_worker) | |
105 m_worker->completeWithDOMException(WebCdmExceptionToExceptionCode(co de), message); | |
106 } | |
107 | |
108 private: | |
109 SetMediaKeysHandler* m_worker; | |
110 }; | |
111 | |
112 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle ment& element, MediaKeys* mediaKeys) | |
113 { | |
114 RefPtr<SetMediaKeysHandler> worker = adoptRef(new SetMediaKeysHandler(script State, element, mediaKeys)); | |
115 worker->suspendIfNeeded(); | |
116 worker->keepAliveWhilePending(); | |
117 return worker->promise(); | |
118 } | |
119 | |
120 SetMediaKeysHandler::SetMediaKeysHandler(ScriptState* scriptState, HTMLMediaElem ent& element, MediaKeys* mediaKeys) | |
121 : ScriptPromiseResolver(scriptState) | |
122 , m_element(element) | |
123 , m_mediaKeys(mediaKeys) | |
124 , m_stage(Starting) | |
125 , m_timer(this, &SetMediaKeysHandler::timerFired) | |
126 { | |
127 WTF_LOG(Media, "SetMediaKeysHandler::SetMediaKeysHandler"); | |
128 | |
129 // 3. Complete setting this asynchronously. | |
ddorwin
2014/08/08 02:50:51
nit: Run the remaining steps asynchronously?
jrummell
2014/08/08 23:15:12
Done.
| |
130 m_timer.startOneShot(0, FROM_HERE); | |
131 } | |
132 | |
133 SetMediaKeysHandler::~SetMediaKeysHandler() | |
134 { | |
135 } | |
136 | |
137 void SetMediaKeysHandler::completeWithDOMException(ExceptionCode code, const Str ing& errorMessage) | |
138 { | |
139 reject(DOMException::create(code, errorMessage)); | |
140 } | |
141 | |
142 void SetMediaKeysHandler::timerFired(Timer<SetMediaKeysHandler>*) | |
143 { | |
144 ASSERT(m_stage == Starting); | |
145 proceedToNextStage(); | |
ddorwin
2014/08/08 02:50:51
I assume this can only be called in Starting from
jrummell
2014/08/08 23:15:12
Done.
| |
146 } | |
147 | |
148 void SetMediaKeysHandler::proceedToNextStage() | |
149 { | |
150 WTF_LOG(Media, "SetMediaKeysHandler::proceedToNextStage(%d)", m_stage); | |
151 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | |
152 | |
153 switch (m_stage) { | |
154 case Starting: | |
155 // 3.1 If mediaKeys is not null, it is already in use by another media | |
156 // element, and the user agent is unable to use it with this element , | |
157 // reject promise with a new DOMException whose name is | |
158 // "QuotaExceededError". (Currently no restrictions on using the sam e | |
ddorwin
2014/08/08 02:50:52
What is the purpose of the statement in ()?
jrummell
2014/08/08 23:15:12
Just to note why there is no code for this step.
| |
159 // MediaKeys with multiple media elements.) | |
160 // 3.2 If the mediaKeys attribute is not null, run the following steps: | |
161 m_stage = Clearing; | |
162 if (thisElement.m_mediaKeys) { | |
163 // 3.2.1 If the user agent or CDM do not support removing the | |
164 // association, return a promise rejected with a new DOMExcept ion | |
165 // whose name is "NotSupportedError". | |
166 // 3.2.2 If the association cannot currently be removed (i.e. during | |
167 // playback), return a promise rejected with a new DOMExceptio n | |
168 // whose name is "InvalidStateError". | |
169 if (m_element->isPlaying()) { | |
ddorwin
2014/08/08 02:50:51
Note that "playback" could also mean load has occu
jrummell
2014/08/08 23:15:12
isPlaying() is the only function I could find. How
| |
170 completeWithDOMException(InvalidStateError, "The existing MediaK eys object cannot be removed at this time."); | |
ddorwin
2014/08/08 02:50:51
... removed while playing?
jrummell
2014/08/08 23:15:12
Sure. I think the error message is from the older
| |
171 return; | |
172 } | |
173 | |
174 // 3.2.3 Stop using the CDM instance represented by the mediaKeys | |
175 // attribute to decrypt media data and remove the association | |
176 // with the media element. | |
177 // 3.2.4 If the preceding step failed, reject promise with a new | |
178 // DOMException whose name is the appropriate error name and | |
179 // that has an appropriate message. | |
180 if (m_element->webMediaPlayer()) { | |
181 ContentDecryptionModuleResult* result = new SetContentDecryption ModuleResult(this); | |
182 m_element->webMediaPlayer()->setContentDecryptionModule(nullptr, result->result()); | |
183 | |
184 // Don't do anything more until SetContentDecryptionModuleResult | |
ddorwin
2014/08/08 02:50:51
...until |result| is resolved?
jrummell
2014/08/08 23:15:12
Done.
| |
185 // finishes (and calls back to proceedToNextStage()). | |
186 return; | |
187 } | |
188 } | |
189 | |
190 // MediaKeys not currently set or no player connected. Continue to next | |
191 // stage. | |
192 | |
193 case Clearing: | |
194 // Successfully cleared MediaKeys, so drop reference to previous value. | |
195 thisElement.m_mediaKeys.clear(); | |
ddorwin
2014/08/08 02:50:51
Technically, the JS attribute is not supposed to b
jrummell
2014/08/08 23:15:11
Done this way in case setContentDecryptionModule()
| |
196 | |
197 // 3.3 If mediaKeys is not null, run the following steps: | |
198 m_stage = Setting; | |
199 if (m_mediaKeys) { | |
ddorwin
2014/08/08 02:50:51
This name is confusing (see 195). Maybe m_newMedia
jrummell
2014/08/08 23:15:12
Done.
| |
200 // 3.3.1 Associate the CDM instance represented by mediaKeys with th e | |
ddorwin
2014/08/08 02:50:51
These are large blocks, which would be good in fun
jrummell
2014/08/08 23:15:12
Acknowledged.
| |
201 // media element for decrypting media data. | |
202 // 3.3.2 If the preceding step failed, run the following steps: | |
203 // 3.3.2.1 Set the mediaKeys attribute to null. | |
ddorwin
2014/08/08 02:50:52
This is handled above. We should note that. But ma
jrummell
2014/08/08 23:15:12
Acknowledged.
| |
204 // 3.3.2.2 Reject promise with a new DOMException whose name is the | |
205 // appropriate error name and that has an appropriate messag e. | |
206 // 3.3.3 Run the Attempt to Resume Playback If Necessary algorithm o n | |
207 // the media element. The user agent may choose to skip this | |
208 // step if it knows resuming will fail (i.e. mediaKeys has no | |
209 // sessions). | |
210 if (m_element->webMediaPlayer()) { | |
211 ContentDecryptionModuleResult* result = new SetContentDecryption ModuleResult(this); | |
212 m_element->webMediaPlayer()->setContentDecryptionModule(m_mediaK eys->contentDecryptionModule(), result->result()); | |
213 | |
214 // Don't do anything more until SetContentDecryptionModuleResult | |
ddorwin
2014/08/08 02:50:52
ditto
jrummell
2014/08/08 23:15:12
Done.
| |
215 // finishes (and calls back to proceedToNextStage()). | |
216 return; | |
217 } | |
218 } | |
219 // MediaKeys doesn't need to be set on the player, so continue on to | |
220 // next stage. | |
221 | |
222 case Setting: | |
223 // 3.4 Set the mediaKeys attribute to mediaKeys. | |
224 thisElement.m_mediaKeys = m_mediaKeys; | |
225 | |
226 // 3.5 Resolve promise with undefined. | |
227 resolve(); | |
228 return; | |
229 } | |
230 } | |
231 | |
41 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() | 232 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() |
42 : m_emeMode(EmeModeNotSelected) | 233 : m_emeMode(EmeModeNotSelected) |
43 { | 234 { |
44 } | 235 } |
45 | 236 |
46 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) | 237 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) |
47 | 238 |
48 const char* HTMLMediaElementEncryptedMedia::supplementName() | 239 const char* HTMLMediaElementEncryptedMedia::supplementName() |
49 { | 240 { |
50 return "HTMLMediaElementEncryptedMedia"; | 241 return "HTMLMediaElementEncryptedMedia"; |
51 } | 242 } |
52 | 243 |
53 HTMLMediaElementEncryptedMedia& HTMLMediaElementEncryptedMedia::from(HTMLMediaEl ement& element) | 244 HTMLMediaElementEncryptedMedia& HTMLMediaElementEncryptedMedia::from(HTMLMediaEl ement& element) |
54 { | 245 { |
55 HTMLMediaElementEncryptedMedia* supplement = static_cast<HTMLMediaElementEnc ryptedMedia*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supplementNa me())); | 246 HTMLMediaElementEncryptedMedia* supplement = static_cast<HTMLMediaElementEnc ryptedMedia*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supplementNa me())); |
56 if (!supplement) { | 247 if (!supplement) { |
57 supplement = new HTMLMediaElementEncryptedMedia(); | 248 supplement = new HTMLMediaElementEncryptedMedia(); |
58 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); | 249 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); |
59 } | 250 } |
60 return *supplement; | 251 return *supplement; |
61 } | 252 } |
62 | 253 |
63 bool HTMLMediaElementEncryptedMedia::setEmeMode(EmeMode emeMode, ExceptionState& exceptionState) | 254 bool HTMLMediaElementEncryptedMedia::setEmeMode(EmeMode emeMode) |
64 { | 255 { |
65 if (m_emeMode != EmeModeNotSelected && m_emeMode != emeMode) { | 256 if (m_emeMode != EmeModeNotSelected && m_emeMode != emeMode) |
66 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
67 return false; | 257 return false; |
68 } | 258 |
69 m_emeMode = emeMode; | 259 m_emeMode = emeMode; |
70 return true; | 260 return true; |
71 } | 261 } |
72 | 262 |
73 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule() | 263 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule() |
74 { | 264 { |
75 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; | 265 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; |
76 } | 266 } |
77 | 267 |
78 MediaKeys* HTMLMediaElementEncryptedMedia::mediaKeys(HTMLMediaElement& element) | 268 MediaKeys* HTMLMediaElementEncryptedMedia::mediaKeys(HTMLMediaElement& element) |
79 { | 269 { |
80 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 270 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
81 return thisElement.m_mediaKeys.get(); | 271 return thisElement.m_mediaKeys.get(); |
82 } | 272 } |
83 | 273 |
84 void HTMLMediaElementEncryptedMedia::setMediaKeysInternal(HTMLMediaElement& elem ent, MediaKeys* mediaKeys) | 274 ScriptPromise HTMLMediaElementEncryptedMedia::setMediaKeys(ScriptState* scriptSt ate, HTMLMediaElement& element, MediaKeys* mediaKeys) |
85 { | 275 { |
86 if (m_mediaKeys == mediaKeys) | 276 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
87 return; | 277 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::setMediaKeys current(%p), ne w(%p)", thisElement.m_mediaKeys.get(), mediaKeys); |
88 | 278 |
89 ASSERT(m_emeMode == EmeModeUnprefixed); | 279 if (!thisElement.setEmeMode(EmeModeUnprefixed)) |
90 m_mediaKeys = mediaKeys; | 280 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Mixed use of EME prefixed and unprefixed API not allo wed.")); |
91 | 281 |
92 // If a player is connected, tell it that the CDM has changed. | 282 // 1. If mediaKeys and the mediaKeys attribute are the same object, return |
93 if (element.webMediaPlayer()) | 283 // a promise resolved with undefined. |
94 element.webMediaPlayer()->setContentDecryptionModule(contentDecryptionMo dule()); | 284 if (thisElement.m_mediaKeys == mediaKeys) |
95 } | 285 return ScriptPromise::cast(scriptState, V8ValueTraits<V8UndefinedType>:: toV8Value(V8UndefinedType(), scriptState->context()->Global(), scriptState->isol ate())); |
96 | 286 |
97 void HTMLMediaElementEncryptedMedia::setMediaKeys(HTMLMediaElement& element, Med iaKeys* mediaKeys, ExceptionState& exceptionState) | 287 // 2. Let promise be a new promise. Remaining steps done in worker. |
ddorwin
2014/08/08 02:50:52
handler
jrummell
2014/08/08 23:15:12
Done.
| |
98 { | 288 return SetMediaKeysHandler::create(scriptState, element, mediaKeys); |
99 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::setMediaKeys"); | |
100 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | |
101 | |
102 if (!thisElement.setEmeMode(EmeModeUnprefixed, exceptionState)) | |
103 return; | |
104 | |
105 thisElement.setMediaKeysInternal(element, mediaKeys); | |
106 } | 289 } |
107 | 290 |
108 // Create a MediaKeyNeededEvent for WD EME. | 291 // Create a MediaKeyNeededEvent for WD EME. |
109 static PassRefPtrWillBeRawPtr<Event> createNeedKeyEvent(const String& contentTyp e, const unsigned char* initData, unsigned initDataLength) | 292 static PassRefPtrWillBeRawPtr<Event> createNeedKeyEvent(const String& contentTyp e, const unsigned char* initData, unsigned initDataLength) |
110 { | 293 { |
111 MediaKeyNeededEventInit initializer; | 294 MediaKeyNeededEventInit initializer; |
112 initializer.contentType = contentType; | 295 initializer.contentType = contentType; |
113 initializer.initData = Uint8Array::create(initData, initDataLength); | 296 initializer.initData = Uint8Array::create(initData, initDataLength); |
114 initializer.bubbles = false; | 297 initializer.bubbles = false; |
115 initializer.cancelable = false; | 298 initializer.cancelable = false; |
(...skipping 16 matching lines...) Expand all Loading... | |
132 | 315 |
133 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement& element, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionStat e& exceptionState) | 316 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement& element, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionStat e& exceptionState) |
134 { | 317 { |
135 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web MediaPlayer(), keySystem, initData, exceptionState); | 318 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web MediaPlayer(), keySystem, initData, exceptionState); |
136 } | 319 } |
137 | 320 |
138 void HTMLMediaElementEncryptedMedia::generateKeyRequest(blink::WebMediaPlayer* w ebMediaPlayer, const String& keySystem, PassRefPtr<Uint8Array> initData, Excepti onState& exceptionState) | 321 void HTMLMediaElementEncryptedMedia::generateKeyRequest(blink::WebMediaPlayer* w ebMediaPlayer, const String& keySystem, PassRefPtr<Uint8Array> initData, Excepti onState& exceptionState) |
139 { | 322 { |
140 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); | 323 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); |
141 | 324 |
142 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 325 if (!setEmeMode(EmeModePrefixed)) { |
326 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
143 return; | 327 return; |
328 } | |
144 | 329 |
145 if (keySystem.isEmpty()) { | 330 if (keySystem.isEmpty()) { |
146 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 331 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
147 return; | 332 return; |
148 } | 333 } |
149 | 334 |
150 if (!webMediaPlayer) { | 335 if (!webMediaPlayer) { |
151 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); | 336 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); |
152 return; | 337 return; |
153 } | 338 } |
(...skipping 16 matching lines...) Expand all Loading... | |
170 | 355 |
171 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con st String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initDat a, const String& sessionId, ExceptionState& exceptionState) | 356 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con st String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initDat a, const String& sessionId, ExceptionState& exceptionState) |
172 { | 357 { |
173 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer( ), keySystem, key, initData, sessionId, exceptionState); | 358 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer( ), keySystem, key, initData, sessionId, exceptionState); |
174 } | 359 } |
175 | 360 |
176 void HTMLMediaElementEncryptedMedia::addKey(blink::WebMediaPlayer* webMediaPlaye r, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> i nitData, const String& sessionId, ExceptionState& exceptionState) | 361 void HTMLMediaElementEncryptedMedia::addKey(blink::WebMediaPlayer* webMediaPlaye r, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> i nitData, const String& sessionId, ExceptionState& exceptionState) |
177 { | 362 { |
178 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); | 363 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); |
179 | 364 |
180 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 365 if (!setEmeMode(EmeModePrefixed)) { |
366 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
181 return; | 367 return; |
368 } | |
182 | 369 |
183 if (keySystem.isEmpty()) { | 370 if (keySystem.isEmpty()) { |
184 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 371 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
185 return; | 372 return; |
186 } | 373 } |
187 | 374 |
188 if (!key) { | 375 if (!key) { |
189 exceptionState.throwDOMException(SyntaxError, "The key provided is inval id."); | 376 exceptionState.throwDOMException(SyntaxError, "The key provided is inval id."); |
190 return; | 377 return; |
191 } | 378 } |
(...skipping 26 matching lines...) Expand all Loading... | |
218 | 405 |
219 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el ement, const String& keySystem, const String& sessionId, ExceptionState& excepti onState) | 406 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el ement, const String& keySystem, const String& sessionId, ExceptionState& excepti onState) |
220 { | 407 { |
221 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe diaPlayer(), keySystem, sessionId, exceptionState); | 408 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe diaPlayer(), keySystem, sessionId, exceptionState); |
222 } | 409 } |
223 | 410 |
224 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(blink::WebMediaPlayer* web MediaPlayer, const String& keySystem, const String& sessionId, ExceptionState& e xceptionState) | 411 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(blink::WebMediaPlayer* web MediaPlayer, const String& keySystem, const String& sessionId, ExceptionState& e xceptionState) |
225 { | 412 { |
226 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); | 413 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); |
227 | 414 |
228 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 415 if (!setEmeMode(EmeModePrefixed)) { |
416 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
229 return; | 417 return; |
418 } | |
230 | 419 |
231 if (keySystem.isEmpty()) { | 420 if (keySystem.isEmpty()) { |
232 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 421 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
233 return; | 422 return; |
234 } | 423 } |
235 | 424 |
236 if (!webMediaPlayer) { | 425 if (!webMediaPlayer) { |
237 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); | 426 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); |
238 return; | 427 return; |
239 } | 428 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 | 523 |
335 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) | 524 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) |
336 { | 525 { |
337 #if ENABLE(OILPAN) | 526 #if ENABLE(OILPAN) |
338 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co m/378229 | 527 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co m/378229 |
339 if (element.isFinalizing()) | 528 if (element.isFinalizing()) |
340 return; | 529 return; |
341 #endif | 530 #endif |
342 | 531 |
343 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 532 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
344 thisElement.setMediaKeysInternal(element, 0); | 533 if (!thisElement.m_mediaKeys) |
534 return; | |
535 | |
536 ASSERT(thisElement.m_emeMode == EmeModeUnprefixed); | |
537 thisElement.m_mediaKeys.clear(); | |
538 | |
539 // If a player is connected, tell it that the CDM has changed. | |
540 if (element.webMediaPlayer()) { | |
ddorwin
2014/08/08 02:50:51
Won't this always be false in this function? (I se
jrummell
2014/08/08 23:15:11
Converted to an ASSERT, which doesn't fire in any
| |
541 SetContentDecryptionModuleResult* result = new SetContentDecryptionModul eResult(0); | |
542 element.webMediaPlayer()->setContentDecryptionModule(thisElement.content DecryptionModule(), result->result()); | |
543 } | |
345 } | 544 } |
346 | 545 |
347 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule(HTMLMediaElement& element) | 546 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule(HTMLMediaElement& element) |
348 { | 547 { |
349 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 548 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
350 return thisElement.contentDecryptionModule(); | 549 return thisElement.contentDecryptionModule(); |
351 } | 550 } |
352 | 551 |
353 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 552 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
354 { | 553 { |
355 visitor->trace(m_mediaKeys); | 554 visitor->trace(m_mediaKeys); |
356 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 555 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
357 } | 556 } |
358 | 557 |
359 } // namespace blink | 558 } // namespace blink |
OLD | NEW |