Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 39 return; | 39 return; |
| 40 case WebMediaPlayer::MediaKeyExceptionInvalidAccess: | 40 case WebMediaPlayer::MediaKeyExceptionInvalidAccess: |
| 41 exceptionState.throwDOMException(InvalidAccessError, "The session ID pro vided ('" + sessionId + "') is invalid."); | 41 exceptionState.throwDOMException(InvalidAccessError, "The session ID pro vided ('" + sessionId + "') is invalid."); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 | 44 |
| 45 ASSERT_NOT_REACHED(); | 45 ASSERT_NOT_REACHED(); |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Checks to see if the current media src is allowed access to |element|'s | |
| 50 // origin. Based on !HTMLVideoElement::wouldTaintOrigin(). | |
| 51 static bool canAccessData(HTMLMediaElement& element) | |
|
sandersd (OOO until July 31)
2015/02/03 22:31:59
I would prefer that there is only one copy of this
jrummell
2015/02/04 23:28:37
Done.
| |
| 52 { | |
| 53 // If this HTMLMediaElement is mixed content, then not allowed. | |
| 54 if (!element.hasSingleSecurityOrigin()) | |
| 55 return false; | |
| 56 | |
| 57 // If CORS check passed, then we are good. | |
| 58 if (element.webMediaPlayer() && element.webMediaPlayer()->didPassCORSAccessC heck()) | |
| 59 return true; | |
| 60 | |
| 61 // Must be based on whether HTMLMediaElement could request the current src. | |
| 62 return element.executionContext()->securityOrigin()->canRequest(element.curr entSrc()); | |
| 63 } | |
| 64 | |
| 49 // This class allows MediaKeys to be set asynchronously. | 65 // This class allows MediaKeys to be set asynchronously. |
| 50 class SetMediaKeysHandler : public ScriptPromiseResolver { | 66 class SetMediaKeysHandler : public ScriptPromiseResolver { |
| 51 WTF_MAKE_NONCOPYABLE(SetMediaKeysHandler); | 67 WTF_MAKE_NONCOPYABLE(SetMediaKeysHandler); |
| 52 | 68 |
| 53 public: | 69 public: |
| 54 static ScriptPromise create(ScriptState*, HTMLMediaElement&, MediaKeys*); | 70 static ScriptPromise create(ScriptState*, HTMLMediaElement&, MediaKeys*); |
| 55 virtual ~SetMediaKeysHandler(); | 71 virtual ~SetMediaKeysHandler(); |
| 56 | 72 |
| 57 virtual void trace(Visitor*) override; | 73 virtual void trace(Visitor*) override; |
| 58 | 74 |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 event->setTarget(&element); | 524 event->setTarget(&element); |
| 509 element.scheduleEvent(event.release()); | 525 element.scheduleEvent(event.release()); |
| 510 } | 526 } |
| 511 | 527 |
| 512 void HTMLMediaElementEncryptedMedia::encrypted(HTMLMediaElement& element, const String& initDataType, const unsigned char* initData, unsigned initDataLength) | 528 void HTMLMediaElementEncryptedMedia::encrypted(HTMLMediaElement& element, const String& initDataType, const unsigned char* initData, unsigned initDataLength) |
| 513 { | 529 { |
| 514 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::encrypted: initDataType=%s", initDataType.utf8().data()); | 530 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::encrypted: initDataType=%s", initDataType.utf8().data()); |
| 515 | 531 |
| 516 if (RuntimeEnabledFeatures::encryptedMediaEnabled()) { | 532 if (RuntimeEnabledFeatures::encryptedMediaEnabled()) { |
| 517 // Send event for WD EME. | 533 // Send event for WD EME. |
| 518 // FIXME: Check origin before providing initData. http://crbug.com/41823 3. | 534 RefPtrWillBeRawPtr<Event> event; |
| 519 RefPtrWillBeRawPtr<Event> event = createEncryptedEvent(initDataType, ini tData, initDataLength); | 535 if (canAccessData(element)) { |
| 536 event = createEncryptedEvent(initDataType, initData, initDataLength) ; | |
| 537 } else { | |
| 538 // Current page is not allowed to see content from the media file, | |
| 539 // so don't return the initData. However, they still get an event. | |
| 540 event = createEncryptedEvent(emptyString(), nullptr, 0); | |
| 541 } | |
| 542 | |
| 520 event->setTarget(&element); | 543 event->setTarget(&element); |
| 521 element.scheduleEvent(event.release()); | 544 element.scheduleEvent(event.release()); |
| 522 } | 545 } |
| 523 | 546 |
| 524 if (RuntimeEnabledFeatures::prefixedEncryptedMediaEnabled()) { | 547 if (RuntimeEnabledFeatures::prefixedEncryptedMediaEnabled()) { |
| 525 // Send event for v0.1b EME. | 548 // Send event for v0.1b EME. |
| 526 RefPtrWillBeRawPtr<Event> event = createWebkitNeedKeyEvent(initData, ini tDataLength); | 549 RefPtrWillBeRawPtr<Event> event = createWebkitNeedKeyEvent(initData, ini tDataLength); |
| 527 event->setTarget(&element); | 550 event->setTarget(&element); |
| 528 element.scheduleEvent(event.release()); | 551 element.scheduleEvent(event.release()); |
| 529 } | 552 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 551 return thisElement.contentDecryptionModule(); | 574 return thisElement.contentDecryptionModule(); |
| 552 } | 575 } |
| 553 | 576 |
| 554 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 577 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
| 555 { | 578 { |
| 556 visitor->trace(m_mediaKeys); | 579 visitor->trace(m_mediaKeys); |
| 557 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 580 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
| 558 } | 581 } |
| 559 | 582 |
| 560 } // namespace blink | 583 } // namespace blink |
| OLD | NEW |