| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "modules/encryptedmedia/MediaKeys.h" | 27 #include "modules/encryptedmedia/MediaKeys.h" |
| 28 | 28 |
| 29 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
| 30 #include "core/events/ThreadLocalEventNames.h" | 30 #include "core/events/ThreadLocalEventNames.h" |
| 31 #include "core/html/HTMLMediaElement.h" | 31 #include "core/html/HTMLMediaElement.h" |
| 32 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" | 32 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" |
| 33 #include "modules/encryptedmedia/MediaKeySession.h" | |
| 34 #include "platform/UUID.h" | 33 #include "platform/UUID.h" |
| 35 #include "platform/drm/ContentDecryptionModule.h" | 34 #include "platform/drm/ContentDecryptionModule.h" |
| 36 #include "wtf/HashSet.h" | 35 #include "wtf/HashSet.h" |
| 37 | 36 |
| 38 namespace WebCore { | 37 namespace WebCore { |
| 39 | 38 |
| 40 PassRefPtr<MediaKeys> MediaKeys::create(const String& keySystem, ExceptionState&
exceptionState) | 39 PassRefPtr<MediaKeys> MediaKeys::create(const String& keySystem, ExceptionState&
exceptionState) |
| 41 { | 40 { |
| 42 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-media-keys-constructor>: | 41 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-media-keys-constructor>: |
| 43 // The MediaKeys(keySystem) constructor must run the following steps: | 42 // The MediaKeys(keySystem) constructor must run the following steps: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 // 5. Create a new MediaKeys object. | 64 // 5. Create a new MediaKeys object. |
| 66 // 5.1 Let the keySystem attribute be keySystem. | 65 // 5.1 Let the keySystem attribute be keySystem. |
| 67 // 6. Return the new object to the caller. | 66 // 6. Return the new object to the caller. |
| 68 return adoptRef(new MediaKeys(keySystem, cdm.release())); | 67 return adoptRef(new MediaKeys(keySystem, cdm.release())); |
| 69 } | 68 } |
| 70 | 69 |
| 71 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<ContentDecryptionModule
> cdm) | 70 MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<ContentDecryptionModule
> cdm) |
| 72 : m_mediaElement(0) | 71 : m_mediaElement(0) |
| 73 , m_keySystem(keySystem) | 72 , m_keySystem(keySystem) |
| 74 , m_cdm(cdm) | 73 , m_cdm(cdm) |
| 74 , m_initializeNewSessionTimer(this, &MediaKeys::initializeNewSessionTimerFir
ed) |
| 75 { | 75 { |
| 76 ScriptWrappable::init(this); | 76 ScriptWrappable::init(this); |
| 77 } | 77 } |
| 78 | 78 |
| 79 MediaKeys::~MediaKeys() | 79 MediaKeys::~MediaKeys() |
| 80 { | 80 { |
| 81 // FIXME: Make sure MediaKeySessions are torn down correctly. | 81 // FIXME: Make sure MediaKeySessions are torn down correctly. |
| 82 } | 82 } |
| 83 | 83 |
| 84 PassRefPtr<MediaKeySession> MediaKeys::createSession(ExecutionContext* context,
const String& type, Uint8Array* initData, ExceptionState& exceptionState) | 84 PassRefPtr<MediaKeySession> MediaKeys::createSession(ExecutionContext* context,
const String& contentType, Uint8Array* initData, ExceptionState& exceptionState) |
| 85 { | 85 { |
| 86 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-createsession>: | 86 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-createsession>: |
| 87 // The createSession(type, initData) method must run the following steps: | 87 // The createSession(type, initData) method must run the following steps: |
| 88 // Note: The contents of initData are container-specific Initialization Data
. | 88 // Note: The contents of initData are container-specific Initialization Data
. |
| 89 | 89 |
| 90 // FIXME: Follow the latest spec to check |type| and |initData|. | 90 if (contentType.isEmpty()) { |
| 91 // If type is null or an empty string and initData is not null or an empty s
tring, throw an | 91 exceptionState.throwDOMException(InvalidAccessError, "The contentType pr
ovided ('" + contentType + "') is empty."); |
| 92 // InvalidAccessError exception and abort these steps. | 92 return 0; |
| 93 if ((type.isEmpty()) && (!initData || initData->length())) { | 93 } |
| 94 exceptionState.throwDOMException(InvalidAccessError, "The type provided
is empty, but initData is not empty."); | 94 |
| 95 if (!initData || !initData->length()) { |
| 96 exceptionState.throwDOMException(InvalidAccessError, "The initData provi
ded is null or empty."); |
| 95 return 0; | 97 return 0; |
| 96 } | 98 } |
| 97 | 99 |
| 98 // 1. If type contains a MIME type that is not supported or is not supported
by the keySystem, | 100 // 1. If type contains a MIME type that is not supported or is not supported
by the keySystem, |
| 99 // throw a NOT_SUPPORTED_ERR exception and abort these steps. | 101 // throw a NOT_SUPPORTED_ERR exception and abort these steps. |
| 100 ASSERT(!type.isEmpty()); | 102 if (!m_cdm->supportsMIMEType(contentType)) { |
| 101 if (type.isEmpty() || !m_cdm->supportsMIMEType(type)) { | 103 exceptionState.throwDOMException(NotSupportedError, "The type provided (
'" + contentType + "') is unsupported."); |
| 102 exceptionState.throwDOMException(NotSupportedError, "The type provided (
'" + type + "') is unsupported."); | |
| 103 return 0; | 104 return 0; |
| 104 } | 105 } |
| 105 | 106 |
| 106 // 2. Create a new MediaKeySession object. | 107 // 2. Create a new MediaKeySession object. |
| 107 RefPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get
(), this); | 108 RefPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get
(), this); |
| 108 // 2.1 Let the keySystem attribute be keySystem. | 109 // 2.1 Let the keySystem attribute be keySystem. |
| 109 ASSERT(!session->keySystem().isEmpty()); | 110 ASSERT(!session->keySystem().isEmpty()); |
| 110 // FIXME: 2.2 Let the state of the session be CREATED. | 111 // FIXME: 2.2 Let the state of the session be CREATED. |
| 111 | 112 |
| 112 // 3. Add the new object to an internal list of session objects. | 113 // 3. Add the new object to an internal list of session objects. |
| 113 m_sessions.append(session); | 114 m_sessions.append(session); |
| 114 | 115 |
| 115 // 4. Schedule a task to initialize the session, providing type, initData, a
nd the new object. | 116 // 4. Schedule a task to initialize the session, providing type, initData, a
nd the new object. |
| 116 // FIXME: The spec says "schedule a task". We should move the timer here. | 117 m_pendingInitializeNewSessionData.append(InitializeNewSessionData(session, c
ontentType, initData)); |
| 117 // FIXME: |initData| may be 0. We need to add more check before we dereferen
ce it. | 118 |
| 118 // Note that this may become obsolete when the FIXME on l.90 is fixed. | 119 if (!m_initializeNewSessionTimer.isActive()) |
| 119 session->initializeNewSession(type, initData); | 120 m_initializeNewSessionTimer.startOneShot(0); |
| 120 | 121 |
| 121 // 5. Return the new object to the caller. | 122 // 5. Return the new object to the caller. |
| 122 return session; | 123 return session; |
| 123 } | 124 } |
| 124 | 125 |
| 125 void MediaKeys::setMediaElement(HTMLMediaElement* element) | 126 void MediaKeys::setMediaElement(HTMLMediaElement* element) |
| 126 { | 127 { |
| 127 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_
mediaElement is not 0 | 128 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_
mediaElement is not 0 |
| 128 // and remove the code that prevents the assert below in HTMLMediaElement. | 129 // and remove the code that prevents the assert below in HTMLMediaElement. |
| 129 ASSERT(!m_mediaElement != !element); | 130 ASSERT(!m_mediaElement != !element); |
| 130 m_mediaElement = element; | 131 m_mediaElement = element; |
| 131 } | 132 } |
| 132 | 133 |
| 133 blink::WebContentDecryptionModule* MediaKeys::contentDecryptionModule() | 134 blink::WebContentDecryptionModule* MediaKeys::contentDecryptionModule() |
| 134 { | 135 { |
| 135 return m_cdm ? m_cdm->contentDecryptionModule() : 0; | 136 return m_cdm ? m_cdm->contentDecryptionModule() : 0; |
| 136 } | 137 } |
| 137 | 138 |
| 139 void MediaKeys::initializeNewSessionTimerFired(Timer<MediaKeys>*) |
| 140 { |
| 141 ASSERT(m_pendingInitializeNewSessionData.size()); |
| 142 |
| 143 while (!m_pendingInitializeNewSessionData.isEmpty()) { |
| 144 InitializeNewSessionData data = m_pendingInitializeNewSessionData.takeFi
rst(); |
| 145 // FIXME: Refer to the spec to see what needs to be done in blink. |
| 146 data.session->initializeNewSession(data.contentType, *data.initData); |
| 147 } |
| 138 } | 148 } |
| 149 |
| 150 } |
| OLD | NEW |