| 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/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 14 #include "core/html/HTMLMediaElement.h" | 14 #include "core/html/HTMLMediaElement.h" |
| 15 #include "core/html/MediaKeyError.h" | 15 #include "core/html/MediaKeyError.h" |
| 16 #include "core/html/MediaKeyEvent.h" | 16 #include "core/html/MediaKeyEvent.h" |
| 17 #include "modules/encryptedmedia/MediaEncryptedEvent.h" | 17 #include "modules/encryptedmedia/MediaKeyNeededEvent.h" |
| 18 #include "modules/encryptedmedia/MediaKeys.h" | 18 #include "modules/encryptedmedia/MediaKeys.h" |
| 19 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResult.h" | 19 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResult.h" |
| 20 #include "platform/ContentDecryptionModuleResult.h" | 20 #include "platform/ContentDecryptionModuleResult.h" |
| 21 #include "platform/Logging.h" | 21 #include "platform/Logging.h" |
| 22 #include "platform/RuntimeEnabledFeatures.h" | 22 #include "platform/RuntimeEnabledFeatures.h" |
| 23 #include "wtf/ArrayBuffer.h" | |
| 24 #include "wtf/Functional.h" | 23 #include "wtf/Functional.h" |
| 25 #include "wtf/Uint8Array.h" | 24 #include "wtf/Uint8Array.h" |
| 26 | 25 |
| 27 namespace blink { | 26 namespace blink { |
| 28 | 27 |
| 29 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c
onst String& sessionId, WebMediaPlayer::MediaKeyException exception, ExceptionSt
ate& exceptionState) | 28 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c
onst String& sessionId, WebMediaPlayer::MediaKeyException exception, ExceptionSt
ate& exceptionState) |
| 30 { | 29 { |
| 31 switch (exception) { | 30 switch (exception) { |
| 32 case WebMediaPlayer::MediaKeyExceptionNoError: | 31 case WebMediaPlayer::MediaKeyExceptionNoError: |
| 33 return; | 32 return; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 279 |
| 281 // 1. If mediaKeys and the mediaKeys attribute are the same object, return | 280 // 1. If mediaKeys and the mediaKeys attribute are the same object, return |
| 282 // a promise resolved with undefined. | 281 // a promise resolved with undefined. |
| 283 if (thisElement.m_mediaKeys == mediaKeys) | 282 if (thisElement.m_mediaKeys == mediaKeys) |
| 284 return ScriptPromise::cast(scriptState, V8ValueTraits<V8UndefinedType>::
toV8Value(V8UndefinedType(), scriptState->context()->Global(), scriptState->isol
ate())); | 283 return ScriptPromise::cast(scriptState, V8ValueTraits<V8UndefinedType>::
toV8Value(V8UndefinedType(), scriptState->context()->Global(), scriptState->isol
ate())); |
| 285 | 284 |
| 286 // 2. Let promise be a new promise. Remaining steps done in handler. | 285 // 2. Let promise be a new promise. Remaining steps done in handler. |
| 287 return SetMediaKeysHandler::create(scriptState, element, mediaKeys); | 286 return SetMediaKeysHandler::create(scriptState, element, mediaKeys); |
| 288 } | 287 } |
| 289 | 288 |
| 290 // Create a MediaEncryptedEvent for WD EME. | 289 // Create a MediaKeyNeededEvent for WD EME. |
| 291 static PassRefPtrWillBeRawPtr<Event> createEncryptedEvent(const String& initData
Type, const unsigned char* initData, unsigned initDataLength) | 290 static PassRefPtrWillBeRawPtr<Event> createNeedKeyEvent(const String& contentTyp
e, const unsigned char* initData, unsigned initDataLength) |
| 292 { | 291 { |
| 293 MediaEncryptedEventInit initializer; | 292 MediaKeyNeededEventInit initializer; |
| 294 initializer.initDataType = initDataType; | 293 initializer.contentType = contentType; |
| 295 initializer.initData = ArrayBuffer::create(initData, initDataLength); | 294 initializer.initData = Uint8Array::create(initData, initDataLength); |
| 296 initializer.bubbles = false; | 295 initializer.bubbles = false; |
| 297 initializer.cancelable = false; | 296 initializer.cancelable = false; |
| 298 | 297 |
| 299 return MediaEncryptedEvent::create(EventTypeNames::encrypted, initializer); | 298 return MediaKeyNeededEvent::create(EventTypeNames::needkey, initializer); |
| 300 } | 299 } |
| 301 | 300 |
| 302 // Create a 'needkey' MediaKeyEvent for v0.1b EME. | 301 // Create a 'needkey' MediaKeyEvent for v0.1b EME. |
| 303 static PassRefPtrWillBeRawPtr<Event> createWebkitNeedKeyEvent(const unsigned cha
r* initData, unsigned initDataLength) | 302 static PassRefPtrWillBeRawPtr<Event> createWebkitNeedKeyEvent(const String& cont
entType, const unsigned char* initData, unsigned initDataLength) |
| 304 { | 303 { |
| 305 MediaKeyEventInit webkitInitializer; | 304 MediaKeyEventInit webkitInitializer; |
| 306 webkitInitializer.keySystem = String(); | 305 webkitInitializer.keySystem = String(); |
| 307 webkitInitializer.sessionId = String(); | 306 webkitInitializer.sessionId = String(); |
| 308 webkitInitializer.initData = Uint8Array::create(initData, initDataLength); | 307 webkitInitializer.initData = Uint8Array::create(initData, initDataLength); |
| 309 webkitInitializer.bubbles = false; | 308 webkitInitializer.bubbles = false; |
| 310 webkitInitializer.cancelable = false; | 309 webkitInitializer.cancelable = false; |
| 311 | 310 |
| 312 return MediaKeyEvent::create(EventTypeNames::webkitneedkey, webkitInitialize
r); | 311 return MediaKeyEvent::create(EventTypeNames::webkitneedkey, webkitInitialize
r); |
| 313 } | 312 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 initializer.message = Uint8Array::create(message, messageLength); | 493 initializer.message = Uint8Array::create(message, messageLength); |
| 495 initializer.defaultURL = KURL(defaultURL); | 494 initializer.defaultURL = KURL(defaultURL); |
| 496 initializer.bubbles = false; | 495 initializer.bubbles = false; |
| 497 initializer.cancelable = false; | 496 initializer.cancelable = false; |
| 498 | 497 |
| 499 RefPtrWillBeRawPtr<Event> event = MediaKeyEvent::create(EventTypeNames::webk
itkeymessage, initializer); | 498 RefPtrWillBeRawPtr<Event> event = MediaKeyEvent::create(EventTypeNames::webk
itkeymessage, initializer); |
| 500 event->setTarget(&element); | 499 event->setTarget(&element); |
| 501 element.scheduleEvent(event.release()); | 500 element.scheduleEvent(event.release()); |
| 502 } | 501 } |
| 503 | 502 |
| 504 void HTMLMediaElementEncryptedMedia::encrypted(HTMLMediaElement& element, const
String& initDataType, const unsigned char* initData, unsigned initDataLength) | 503 void HTMLMediaElementEncryptedMedia::keyNeeded(HTMLMediaElement& element, const
String& contentType, const unsigned char* initData, unsigned initDataLength) |
| 505 { | 504 { |
| 506 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::encrypted: initDataType=%s",
initDataType.utf8().data()); | 505 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::mediaPlayerKeyNeeded: conten
tType=%s", contentType.utf8().data()); |
| 507 | 506 |
| 508 if (RuntimeEnabledFeatures::encryptedMediaEnabled()) { | 507 if (RuntimeEnabledFeatures::encryptedMediaEnabled()) { |
| 509 // Send event for WD EME. | 508 // Send event for WD EME. |
| 510 // FIXME: Check origin before providing initData. http://crbug.com/41823
3. | 509 RefPtrWillBeRawPtr<Event> event = createNeedKeyEvent(contentType, initDa
ta, initDataLength); |
| 511 RefPtrWillBeRawPtr<Event> event = createEncryptedEvent(initDataType, ini
tData, initDataLength); | |
| 512 event->setTarget(&element); | 510 event->setTarget(&element); |
| 513 element.scheduleEvent(event.release()); | 511 element.scheduleEvent(event.release()); |
| 514 } | 512 } |
| 515 | 513 |
| 516 if (RuntimeEnabledFeatures::prefixedEncryptedMediaEnabled()) { | 514 if (RuntimeEnabledFeatures::prefixedEncryptedMediaEnabled()) { |
| 517 // Send event for v0.1b EME. | 515 // Send event for v0.1b EME. |
| 518 RefPtrWillBeRawPtr<Event> event = createWebkitNeedKeyEvent(initData, ini
tDataLength); | 516 RefPtrWillBeRawPtr<Event> event = createWebkitNeedKeyEvent(contentType,
initData, initDataLength); |
| 519 event->setTarget(&element); | 517 event->setTarget(&element); |
| 520 element.scheduleEvent(event.release()); | 518 element.scheduleEvent(event.release()); |
| 521 } | 519 } |
| 522 } | 520 } |
| 523 | 521 |
| 524 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) | 522 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) |
| 525 { | 523 { |
| 526 #if ENABLE(OILPAN) | 524 #if ENABLE(OILPAN) |
| 527 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co
m/378229 | 525 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co
m/378229 |
| 528 if (element.isFinalizing()) | 526 if (element.isFinalizing()) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 543 return thisElement.contentDecryptionModule(); | 541 return thisElement.contentDecryptionModule(); |
| 544 } | 542 } |
| 545 | 543 |
| 546 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 544 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
| 547 { | 545 { |
| 548 visitor->trace(m_mediaKeys); | 546 visitor->trace(m_mediaKeys); |
| 549 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 547 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
| 550 } | 548 } |
| 551 | 549 |
| 552 } // namespace blink | 550 } // namespace blink |
| OLD | NEW |