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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 PendingAction(ContentDecryptionModuleResult* result, PassRefPtr<DOMArrayBuff
er> data) | 73 PendingAction(ContentDecryptionModuleResult* result, PassRefPtr<DOMArrayBuff
er> data) |
74 : m_result(result) | 74 : m_result(result) |
75 , m_data(data) | 75 , m_data(data) |
76 { | 76 { |
77 } | 77 } |
78 | 78 |
79 const Member<ContentDecryptionModuleResult> m_result; | 79 const Member<ContentDecryptionModuleResult> m_result; |
80 const RefPtr<DOMArrayBuffer> m_data; | 80 const RefPtr<DOMArrayBuffer> m_data; |
81 }; | 81 }; |
82 | 82 |
83 MediaKeys::MediaKeys(ExecutionContext* context, const String& keySystem, const b
link::WebVector<blink::WebString>& supportedSessionTypes, PassOwnPtr<WebContentD
ecryptionModule> cdm) | 83 MediaKeys::MediaKeys(ExecutionContext* context, const String& keySystem, const b
link::WebVector<WebEncryptedMediaSessionType>& supportedSessionTypes, PassOwnPtr
<WebContentDecryptionModule> cdm) |
84 : ContextLifecycleObserver(context) | 84 : ContextLifecycleObserver(context) |
85 , m_keySystem(keySystem) | 85 , m_keySystem(keySystem) |
86 , m_supportedSessionTypes(supportedSessionTypes) | 86 , m_supportedSessionTypes(supportedSessionTypes) |
87 , m_cdm(cdm) | 87 , m_cdm(cdm) |
88 , m_timer(this, &MediaKeys::timerFired) | 88 , m_timer(this, &MediaKeys::timerFired) |
89 { | 89 { |
90 WTF_LOG(Media, "MediaKeys(%p)::MediaKeys", this); | 90 WTF_LOG(Media, "MediaKeys(%p)::MediaKeys", this); |
91 | 91 |
92 // Step 4.4 of MediaKeys::create(): | 92 // Step 4.4 of MediaKeys::create(): |
93 // 4.4.1 Set the keySystem attribute to keySystem. | 93 // 4.4.1 Set the keySystem attribute to keySystem. |
94 ASSERT(!m_keySystem.isEmpty()); | 94 ASSERT(!m_keySystem.isEmpty()); |
95 } | 95 } |
96 | 96 |
97 MediaKeys::~MediaKeys() | 97 MediaKeys::~MediaKeys() |
98 { | 98 { |
99 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); | 99 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); |
100 } | 100 } |
101 | 101 |
102 MediaKeySession* MediaKeys::createSession(ScriptState* scriptState, const String
& sessionType, ExceptionState& exceptionState) | 102 MediaKeySession* MediaKeys::createSession(ScriptState* scriptState, const String
& sessionTypeString, ExceptionState& exceptionState) |
103 { | 103 { |
104 WTF_LOG(Media, "MediaKeys(%p)::createSession", this); | 104 WTF_LOG(Media, "MediaKeys(%p)::createSession", this); |
105 | 105 |
106 // From http://w3c.github.io/encrypted-media/#createSession | 106 // From http://w3c.github.io/encrypted-media/#createSession |
107 | 107 |
108 // When this method is invoked, the user agent must run the following steps: | 108 // When this method is invoked, the user agent must run the following steps: |
109 // 1. If this object's persistent state allowed value is false and | 109 // 1. If this object's persistent state allowed value is false and |
110 // sessionType is not "temporary", throw a new DOMException whose name is | 110 // sessionType is not "temporary", throw a new DOMException whose name is |
111 // NotSupportedError. | 111 // NotSupportedError. |
112 // (Chromium ensures that only session types supported by the | 112 // (Chromium ensures that only session types supported by the |
113 // configuration are listed in supportedSessionTypes.) | 113 // configuration are listed in supportedSessionTypes.) |
114 // 2. If the Key System implementation represented by this object's cdm | 114 // 2. If the Key System implementation represented by this object's cdm |
115 // implementation value does not support sessionType, throw a new | 115 // implementation value does not support sessionType, throw a new |
116 // DOMException whose name is NotSupportedError. | 116 // DOMException whose name is NotSupportedError. |
117 bool found = false; | 117 WebEncryptedMediaSessionType sessionType = MediaKeySession::convertSessionTy
pe(sessionTypeString); |
118 for (size_t i = 0; i < m_supportedSessionTypes.size(); i++) { | 118 if (!sessionTypeSupported(sessionType)) |
119 if (m_supportedSessionTypes[i] == blink::WebString(sessionType)) { | |
120 found = true; | |
121 break; | |
122 } | |
123 } | |
124 if (!found) | |
125 exceptionState.throwDOMException(NotSupportedError, "Unsupported session
type."); | 119 exceptionState.throwDOMException(NotSupportedError, "Unsupported session
type."); |
126 | 120 |
127 // 3. Let session be a new MediaKeySession object, and initialize it as | 121 // 3. Let session be a new MediaKeySession object, and initialize it as |
128 // follows: | 122 // follows: |
129 // (Initialization is performed in the constructor.) | 123 // (Initialization is performed in the constructor.) |
130 // 4. Return session. | 124 // 4. Return session. |
131 return MediaKeySession::create(scriptState, this, sessionType); | 125 return MediaKeySession::create(scriptState, this, sessionType); |
132 } | 126 } |
133 | 127 |
134 ScriptPromise MediaKeys::setServerCertificate(ScriptState* scriptState, const DO
MArrayPiece& serverCertificate) | 128 ScriptPromise MediaKeys::setServerCertificate(ScriptState* scriptState, const DO
MArrayPiece& serverCertificate) |
(...skipping 24 matching lines...) Expand all Loading... |
159 | 153 |
160 // 5. Run the following steps asynchronously (documented in timerFired()). | 154 // 5. Run the following steps asynchronously (documented in timerFired()). |
161 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate(res
ult, serverCertificateBuffer.release())); | 155 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate(res
ult, serverCertificateBuffer.release())); |
162 if (!m_timer.isActive()) | 156 if (!m_timer.isActive()) |
163 m_timer.startOneShot(0, FROM_HERE); | 157 m_timer.startOneShot(0, FROM_HERE); |
164 | 158 |
165 // 6. Return promise. | 159 // 6. Return promise. |
166 return promise; | 160 return promise; |
167 } | 161 } |
168 | 162 |
| 163 bool MediaKeys::sessionTypeSupported(WebEncryptedMediaSessionType sessionType) |
| 164 { |
| 165 for (size_t i = 0; i < m_supportedSessionTypes.size(); i++) { |
| 166 if (m_supportedSessionTypes[i] == sessionType) |
| 167 return true; |
| 168 } |
| 169 |
| 170 return false; |
| 171 } |
| 172 |
169 void MediaKeys::timerFired(Timer<MediaKeys>*) | 173 void MediaKeys::timerFired(Timer<MediaKeys>*) |
170 { | 174 { |
171 ASSERT(m_pendingActions.size()); | 175 ASSERT(m_pendingActions.size()); |
172 | 176 |
173 // Swap the queue to a local copy to avoid problems if resolving promises | 177 // Swap the queue to a local copy to avoid problems if resolving promises |
174 // run synchronously. | 178 // run synchronously. |
175 HeapDeque<Member<PendingAction>> pendingActions; | 179 HeapDeque<Member<PendingAction>> pendingActions; |
176 pendingActions.swap(m_pendingActions); | 180 pendingActions.swap(m_pendingActions); |
177 | 181 |
178 while (!pendingActions.isEmpty()) { | 182 while (!pendingActions.isEmpty()) { |
(...skipping 25 matching lines...) Expand all Loading... |
204 | 208 |
205 void MediaKeys::contextDestroyed() | 209 void MediaKeys::contextDestroyed() |
206 { | 210 { |
207 ContextLifecycleObserver::contextDestroyed(); | 211 ContextLifecycleObserver::contextDestroyed(); |
208 | 212 |
209 // We don't need the CDM anymore. | 213 // We don't need the CDM anymore. |
210 m_cdm.clear(); | 214 m_cdm.clear(); |
211 } | 215 } |
212 | 216 |
213 } // namespace blink | 217 } // namespace blink |
OLD | NEW |