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" |
11 #include "bindings/core/v8/ScriptState.h" | 11 #include "bindings/core/v8/ScriptState.h" |
12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
| 13 #include "core/dom/DOMTypedArray.h" |
13 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
14 #include "core/html/HTMLMediaElement.h" | 15 #include "core/html/HTMLMediaElement.h" |
15 #include "core/html/MediaKeyError.h" | 16 #include "core/html/MediaKeyError.h" |
16 #include "core/html/MediaKeyEvent.h" | 17 #include "core/html/MediaKeyEvent.h" |
17 #include "modules/encryptedmedia/MediaEncryptedEvent.h" | 18 #include "modules/encryptedmedia/MediaEncryptedEvent.h" |
18 #include "modules/encryptedmedia/MediaKeys.h" | 19 #include "modules/encryptedmedia/MediaKeys.h" |
19 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResult.h" | 20 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResult.h" |
20 #include "platform/ContentDecryptionModuleResult.h" | 21 #include "platform/ContentDecryptionModuleResult.h" |
21 #include "platform/Logging.h" | 22 #include "platform/Logging.h" |
22 #include "platform/RuntimeEnabledFeatures.h" | 23 #include "platform/RuntimeEnabledFeatures.h" |
23 #include "wtf/ArrayBuffer.h" | 24 #include "wtf/ArrayBuffer.h" |
24 #include "wtf/Functional.h" | 25 #include "wtf/Functional.h" |
25 #include "wtf/Uint8Array.h" | |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 | 28 |
29 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c
onst String& sessionId, WebMediaPlayer::MediaKeyException exception, ExceptionSt
ate& exceptionState) | 29 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c
onst String& sessionId, WebMediaPlayer::MediaKeyException exception, ExceptionSt
ate& exceptionState) |
30 { | 30 { |
31 switch (exception) { | 31 switch (exception) { |
32 case WebMediaPlayer::MediaKeyExceptionNoError: | 32 case WebMediaPlayer::MediaKeyExceptionNoError: |
33 return; | 33 return; |
34 case WebMediaPlayer::MediaKeyExceptionInvalidPlayerState: | 34 case WebMediaPlayer::MediaKeyExceptionInvalidPlayerState: |
35 exceptionState.throwDOMException(InvalidStateError, "The player is in an
invalid state."); | 35 exceptionState.throwDOMException(InvalidStateError, "The player is in an
invalid state."); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 // 2. Let promise be a new promise. Remaining steps done in handler. | 286 // 2. Let promise be a new promise. Remaining steps done in handler. |
287 return SetMediaKeysHandler::create(scriptState, element, mediaKeys); | 287 return SetMediaKeysHandler::create(scriptState, element, mediaKeys); |
288 } | 288 } |
289 | 289 |
290 // Create a MediaEncryptedEvent for WD EME. | 290 // Create a MediaEncryptedEvent for WD EME. |
291 static PassRefPtrWillBeRawPtr<Event> createEncryptedEvent(const String& initData
Type, const unsigned char* initData, unsigned initDataLength) | 291 static PassRefPtrWillBeRawPtr<Event> createEncryptedEvent(const String& initData
Type, const unsigned char* initData, unsigned initDataLength) |
292 { | 292 { |
293 MediaEncryptedEventInit initializer; | 293 MediaEncryptedEventInit initializer; |
294 initializer.initDataType = initDataType; | 294 initializer.initDataType = initDataType; |
295 initializer.initData = ArrayBuffer::create(initData, initDataLength); | 295 initializer.initData = DOMArrayBuffer::create(initData, initDataLength); |
296 initializer.bubbles = false; | 296 initializer.bubbles = false; |
297 initializer.cancelable = false; | 297 initializer.cancelable = false; |
298 | 298 |
299 return MediaEncryptedEvent::create(EventTypeNames::encrypted, initializer); | 299 return MediaEncryptedEvent::create(EventTypeNames::encrypted, initializer); |
300 } | 300 } |
301 | 301 |
302 // Create a 'needkey' MediaKeyEvent for v0.1b EME. | 302 // Create a 'needkey' MediaKeyEvent for v0.1b EME. |
303 static PassRefPtrWillBeRawPtr<Event> createWebkitNeedKeyEvent(const unsigned cha
r* initData, unsigned initDataLength) | 303 static PassRefPtrWillBeRawPtr<Event> createWebkitNeedKeyEvent(const unsigned cha
r* initData, unsigned initDataLength) |
304 { | 304 { |
305 MediaKeyEventInit webkitInitializer; | 305 MediaKeyEventInit webkitInitializer; |
306 webkitInitializer.keySystem = String(); | 306 webkitInitializer.keySystem = String(); |
307 webkitInitializer.sessionId = String(); | 307 webkitInitializer.sessionId = String(); |
308 webkitInitializer.initData = Uint8Array::create(initData, initDataLength); | 308 webkitInitializer.initData = DOMUint8Array::create(initData, initDataLength)
; |
309 webkitInitializer.bubbles = false; | 309 webkitInitializer.bubbles = false; |
310 webkitInitializer.cancelable = false; | 310 webkitInitializer.cancelable = false; |
311 | 311 |
312 return MediaKeyEvent::create(EventTypeNames::webkitneedkey, webkitInitialize
r); | 312 return MediaKeyEvent::create(EventTypeNames::webkitneedkey, webkitInitialize
r); |
313 } | 313 } |
314 | 314 |
315 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement&
element, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionStat
e& exceptionState) | 315 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement&
element, const String& keySystem, PassRefPtr<DOMUint8Array> initData, ExceptionS
tate& exceptionState) |
316 { | 316 { |
317 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web
MediaPlayer(), keySystem, initData, exceptionState); | 317 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web
MediaPlayer(), keySystem, initData, exceptionState); |
318 } | 318 } |
319 | 319 |
320 void HTMLMediaElementEncryptedMedia::generateKeyRequest(WebMediaPlayer* webMedia
Player, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionState
& exceptionState) | 320 void HTMLMediaElementEncryptedMedia::generateKeyRequest(WebMediaPlayer* webMedia
Player, const String& keySystem, PassRefPtr<DOMUint8Array> initData, ExceptionSt
ate& exceptionState) |
321 { | 321 { |
322 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); | 322 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); |
323 | 323 |
324 if (!setEmeMode(EmeModePrefixed)) { | 324 if (!setEmeMode(EmeModePrefixed)) { |
325 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr
efixed and unprefixed API not allowed."); | 325 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr
efixed and unprefixed API not allowed."); |
326 return; | 326 return; |
327 } | 327 } |
328 | 328 |
329 if (keySystem.isEmpty()) { | 329 if (keySystem.isEmpty()) { |
330 exceptionState.throwDOMException(SyntaxError, "The key system provided i
s empty."); | 330 exceptionState.throwDOMException(SyntaxError, "The key system provided i
s empty."); |
(...skipping 11 matching lines...) Expand all Loading... |
342 initDataPointer = initData->data(); | 342 initDataPointer = initData->data(); |
343 initDataLength = initData->length(); | 343 initDataLength = initData->length(); |
344 } | 344 } |
345 | 345 |
346 WebMediaPlayer::MediaKeyException result = webMediaPlayer->generateKeyReques
t(keySystem, initDataPointer, initDataLength); | 346 WebMediaPlayer::MediaKeyException result = webMediaPlayer->generateKeyReques
t(keySystem, initDataPointer, initDataLength); |
347 throwExceptionIfMediaKeyExceptionOccurred(keySystem, String(), result, excep
tionState); | 347 throwExceptionIfMediaKeyExceptionOccurred(keySystem, String(), result, excep
tionState); |
348 } | 348 } |
349 | 349 |
350 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement&
mediaElement, const String& keySystem, ExceptionState& exceptionState) | 350 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement&
mediaElement, const String& keySystem, ExceptionState& exceptionState) |
351 { | 351 { |
352 webkitGenerateKeyRequest(mediaElement, keySystem, Uint8Array::create(0), exc
eptionState); | 352 webkitGenerateKeyRequest(mediaElement, keySystem, DOMUint8Array::create(0),
exceptionState); |
353 } | 353 } |
354 | 354 |
355 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con
st String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initDat
a, const String& sessionId, ExceptionState& exceptionState) | 355 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con
st String& keySystem, PassRefPtr<DOMUint8Array> key, PassRefPtr<DOMUint8Array> i
nitData, const String& sessionId, ExceptionState& exceptionState) |
356 { | 356 { |
357 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer(
), keySystem, key, initData, sessionId, exceptionState); | 357 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer(
), keySystem, key, initData, sessionId, exceptionState); |
358 } | 358 } |
359 | 359 |
360 void HTMLMediaElementEncryptedMedia::addKey(WebMediaPlayer* webMediaPlayer, cons
t String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initData
, const String& sessionId, ExceptionState& exceptionState) | 360 void HTMLMediaElementEncryptedMedia::addKey(WebMediaPlayer* webMediaPlayer, cons
t String& keySystem, PassRefPtr<DOMUint8Array> key, PassRefPtr<DOMUint8Array> in
itData, const String& sessionId, ExceptionState& exceptionState) |
361 { | 361 { |
362 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); | 362 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); |
363 | 363 |
364 if (!setEmeMode(EmeModePrefixed)) { | 364 if (!setEmeMode(EmeModePrefixed)) { |
365 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr
efixed and unprefixed API not allowed."); | 365 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr
efixed and unprefixed API not allowed."); |
366 return; | 366 return; |
367 } | 367 } |
368 | 368 |
369 if (keySystem.isEmpty()) { | 369 if (keySystem.isEmpty()) { |
370 exceptionState.throwDOMException(SyntaxError, "The key system provided i
s empty."); | 370 exceptionState.throwDOMException(SyntaxError, "The key system provided i
s empty."); |
(...skipping 19 matching lines...) Expand all Loading... |
390 unsigned initDataLength = 0; | 390 unsigned initDataLength = 0; |
391 if (initData) { | 391 if (initData) { |
392 initDataPointer = initData->data(); | 392 initDataPointer = initData->data(); |
393 initDataLength = initData->length(); | 393 initDataLength = initData->length(); |
394 } | 394 } |
395 | 395 |
396 WebMediaPlayer::MediaKeyException result = webMediaPlayer->addKey(keySystem,
key->data(), key->length(), initDataPointer, initDataLength, sessionId); | 396 WebMediaPlayer::MediaKeyException result = webMediaPlayer->addKey(keySystem,
key->data(), key->length(), initDataPointer, initDataLength, sessionId); |
397 throwExceptionIfMediaKeyExceptionOccurred(keySystem, sessionId, result, exce
ptionState); | 397 throwExceptionIfMediaKeyExceptionOccurred(keySystem, sessionId, result, exce
ptionState); |
398 } | 398 } |
399 | 399 |
400 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& mediaElement
, const String& keySystem, PassRefPtr<Uint8Array> key, ExceptionState& exception
State) | 400 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& mediaElement
, const String& keySystem, PassRefPtr<DOMUint8Array> key, ExceptionState& except
ionState) |
401 { | 401 { |
402 webkitAddKey(mediaElement, keySystem, key, Uint8Array::create(0), String(),
exceptionState); | 402 webkitAddKey(mediaElement, keySystem, key, DOMUint8Array::create(0), String(
), exceptionState); |
403 } | 403 } |
404 | 404 |
405 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el
ement, const String& keySystem, const String& sessionId, ExceptionState& excepti
onState) | 405 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el
ement, const String& keySystem, const String& sessionId, ExceptionState& excepti
onState) |
406 { | 406 { |
407 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe
diaPlayer(), keySystem, sessionId, exceptionState); | 407 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe
diaPlayer(), keySystem, sessionId, exceptionState); |
408 } | 408 } |
409 | 409 |
410 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(WebMediaPlayer* webMediaPl
ayer, const String& keySystem, const String& sessionId, ExceptionState& exceptio
nState) | 410 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(WebMediaPlayer* webMediaPl
ayer, const String& keySystem, const String& sessionId, ExceptionState& exceptio
nState) |
411 { | 411 { |
412 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); | 412 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 element.scheduleEvent(event.release()); | 484 element.scheduleEvent(event.release()); |
485 } | 485 } |
486 | 486 |
487 void HTMLMediaElementEncryptedMedia::keyMessage(HTMLMediaElement& element, const
String& keySystem, const String& sessionId, const unsigned char* message, unsig
ned messageLength, const WebURL& defaultURL) | 487 void HTMLMediaElementEncryptedMedia::keyMessage(HTMLMediaElement& element, const
String& keySystem, const String& sessionId, const unsigned char* message, unsig
ned messageLength, const WebURL& defaultURL) |
488 { | 488 { |
489 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::mediaPlayerKeyMessage: sessi
onID=%s", sessionId.utf8().data()); | 489 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::mediaPlayerKeyMessage: sessi
onID=%s", sessionId.utf8().data()); |
490 | 490 |
491 MediaKeyEventInit initializer; | 491 MediaKeyEventInit initializer; |
492 initializer.keySystem = keySystem; | 492 initializer.keySystem = keySystem; |
493 initializer.sessionId = sessionId; | 493 initializer.sessionId = sessionId; |
494 initializer.message = Uint8Array::create(message, messageLength); | 494 initializer.message = DOMUint8Array::create(message, messageLength); |
495 initializer.defaultURL = KURL(defaultURL); | 495 initializer.defaultURL = KURL(defaultURL); |
496 initializer.bubbles = false; | 496 initializer.bubbles = false; |
497 initializer.cancelable = false; | 497 initializer.cancelable = false; |
498 | 498 |
499 RefPtrWillBeRawPtr<Event> event = MediaKeyEvent::create(EventTypeNames::webk
itkeymessage, initializer); | 499 RefPtrWillBeRawPtr<Event> event = MediaKeyEvent::create(EventTypeNames::webk
itkeymessage, initializer); |
500 event->setTarget(&element); | 500 event->setTarget(&element); |
501 element.scheduleEvent(event.release()); | 501 element.scheduleEvent(event.release()); |
502 } | 502 } |
503 | 503 |
504 void HTMLMediaElementEncryptedMedia::encrypted(HTMLMediaElement& element, const
String& initDataType, const unsigned char* initData, unsigned initDataLength) | 504 void HTMLMediaElementEncryptedMedia::encrypted(HTMLMediaElement& element, const
String& initDataType, const unsigned char* initData, unsigned initDataLength) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 return thisElement.contentDecryptionModule(); | 543 return thisElement.contentDecryptionModule(); |
544 } | 544 } |
545 | 545 |
546 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 546 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
547 { | 547 { |
548 visitor->trace(m_mediaKeys); | 548 visitor->trace(m_mediaKeys); |
549 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 549 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
550 } | 550 } |
551 | 551 |
552 } // namespace blink | 552 } // namespace blink |
OLD | NEW |