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& type, Uint8Array* initData, ExceptionState& exceptionState) |
ddorwin
2014/01/13 20:20:57
type is now contentType
xhwang
2014/01/14 04:04:11
Done.
| |
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 (type.isEmpty() || !initData || !initData->length()) { |
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 type or initDa ta provided is empty or null."); |
ddorwin
2014/01/13 20:20:57
I wonder what is the best practice for these strin
xhwang
2014/01/14 04:04:11
Done.
| |
92 // InvalidAccessError exception and abort these steps. | |
93 if ((type.isEmpty()) && (!initData || initData->length())) { | |
94 exceptionState.throwDOMException(InvalidAccessError, "The type provided is empty, but initData is not empty."); | |
95 return 0; | 92 return 0; |
96 } | 93 } |
97 | 94 |
98 // 1. If type contains a MIME type that is not supported or is not supported by the keySystem, | 95 // 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. | 96 // throw a NOT_SUPPORTED_ERR exception and abort these steps. |
100 ASSERT(!type.isEmpty()); | 97 if (!m_cdm->supportsMIMEType(type)) { |
101 if (type.isEmpty() || !m_cdm->supportsMIMEType(type)) { | |
102 exceptionState.throwDOMException(NotSupportedError, "The type provided ( '" + type + "') is unsupported."); | 98 exceptionState.throwDOMException(NotSupportedError, "The type provided ( '" + type + "') is unsupported."); |
103 return 0; | 99 return 0; |
104 } | 100 } |
105 | 101 |
106 // 2. Create a new MediaKeySession object. | 102 // 2. Create a new MediaKeySession object. |
107 RefPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get (), this); | 103 RefPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get (), this); |
108 // 2.1 Let the keySystem attribute be keySystem. | 104 // 2.1 Let the keySystem attribute be keySystem. |
109 ASSERT(!session->keySystem().isEmpty()); | 105 ASSERT(!session->keySystem().isEmpty()); |
110 // FIXME: 2.2 Let the state of the session be CREATED. | 106 // FIXME: 2.2 Let the state of the session be CREATED. |
111 | 107 |
112 // 3. Add the new object to an internal list of session objects. | 108 // 3. Add the new object to an internal list of session objects. |
113 m_sessions.append(session); | 109 m_sessions.append(session); |
114 | 110 |
115 // 4. Schedule a task to initialize the session, providing type, initData, a nd the new object. | 111 // 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. | 112 m_pendingInitializeNewSessionData.append(InitializeNewSessionData(session, t ype, initData)); |
117 // FIXME: |initData| may be 0. We need to add more check before we dereferen ce it. | 113 |
118 // Note that this may become obsolete when the FIXME on l.90 is fixed. | 114 if (!m_initializeNewSessionTimer.isActive()) |
119 session->initializeNewSession(type, initData); | 115 m_initializeNewSessionTimer.startOneShot(0); |
120 | 116 |
121 // 5. Return the new object to the caller. | 117 // 5. Return the new object to the caller. |
122 return session; | 118 return session; |
123 } | 119 } |
124 | 120 |
125 void MediaKeys::setMediaElement(HTMLMediaElement* element) | 121 void MediaKeys::setMediaElement(HTMLMediaElement* element) |
126 { | 122 { |
127 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_ mediaElement is not 0 | 123 // 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. | 124 // and remove the code that prevents the assert below in HTMLMediaElement. |
129 ASSERT(!m_mediaElement != !element); | 125 ASSERT(!m_mediaElement != !element); |
130 m_mediaElement = element; | 126 m_mediaElement = element; |
131 } | 127 } |
132 | 128 |
133 blink::WebContentDecryptionModule* MediaKeys::contentDecryptionModule() | 129 blink::WebContentDecryptionModule* MediaKeys::contentDecryptionModule() |
134 { | 130 { |
135 return m_cdm ? m_cdm->contentDecryptionModule() : 0; | 131 return m_cdm ? m_cdm->contentDecryptionModule() : 0; |
136 } | 132 } |
137 | 133 |
134 void MediaKeys::initializeNewSessionTimerFired(Timer<MediaKeys>*) | |
135 { | |
136 ASSERT(m_pendingInitializeNewSessionData.size()); | |
137 | |
138 while (!m_pendingInitializeNewSessionData.isEmpty()) { | |
139 InitializeNewSessionData data = m_pendingInitializeNewSessionData.takeFi rst(); | |
140 // FIXME: Refer to the spec to see what needs to be done in blink. | |
141 data.session->initializeNewSession(data.mimeType, *data.initData); | |
142 } | |
138 } | 143 } |
144 | |
145 } | |
OLD | NEW |