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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 60 |
61 static bool isKeySystemSupportedWithContentType(const String& keySystem, const S tring& contentType) | 61 static bool isKeySystemSupportedWithContentType(const String& keySystem, const S tring& contentType) |
62 { | 62 { |
63 ASSERT(!keySystem.isEmpty()); | 63 ASSERT(!keySystem.isEmpty()); |
64 | 64 |
65 ContentType type(contentType); | 65 ContentType type(contentType); |
66 String codecs = type.parameter("codecs"); | 66 String codecs = type.parameter("codecs"); |
67 return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, type.t ype(), codecs); | 67 return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, type.t ype(), codecs); |
68 } | 68 } |
69 | 69 |
70 static bool isKeySystemSupportedWithInitDataType(const String& keySystem, const String& initDataType) | |
71 { | |
72 // FIXME: initDataType != contentType. Implement this properly. | |
73 // http://crbug.com/385874. | |
74 String contentType = initDataType; | |
75 if (initDataType == "webm") { | |
76 contentType = "video/webm"; | |
77 } else if (initDataType == "cenc") { | |
78 contentType = "video/mp4"; | |
79 } | |
80 return isKeySystemSupportedWithContentType(keySystem, contentType); | |
81 } | |
82 | |
83 static ScriptPromise createRejectedPromise(ScriptState* scriptState, ExceptionCo de error, const String& errorMessage) | 70 static ScriptPromise createRejectedPromise(ScriptState* scriptState, ExceptionCo de error, const String& errorMessage) |
84 { | 71 { |
85 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(error, errorMessage)); | 72 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(error, errorMessage)); |
86 } | 73 } |
87 | 74 |
88 // This class allows a MediaKeys object to be created asynchronously. | 75 // This class allows a MediaKeys object to be created asynchronously. |
89 class MediaKeysInitializer : public ScriptPromiseResolver { | 76 class MediaKeysInitializer : public ScriptPromiseResolver { |
90 WTF_MAKE_NONCOPYABLE(MediaKeysInitializer); | 77 WTF_MAKE_NONCOPYABLE(MediaKeysInitializer); |
91 | 78 |
92 public: | 79 public: |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 // Step 4.4 of MediaKeys::create(): | 184 // Step 4.4 of MediaKeys::create(): |
198 // 4.4.1 Set the keySystem attribute to keySystem. | 185 // 4.4.1 Set the keySystem attribute to keySystem. |
199 ASSERT(!m_keySystem.isEmpty()); | 186 ASSERT(!m_keySystem.isEmpty()); |
200 } | 187 } |
201 | 188 |
202 MediaKeys::~MediaKeys() | 189 MediaKeys::~MediaKeys() |
203 { | 190 { |
204 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); | 191 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); |
205 } | 192 } |
206 | 193 |
207 ScriptPromise MediaKeys::createSession(ScriptState* scriptState, const String& i nitDataType, ArrayBuffer* initData, const String& sessionType) | 194 MediaKeySession* MediaKeys::createSession(ScriptState* scriptState, const String & sessionType) |
208 { | 195 { |
209 RefPtr<ArrayBuffer> initDataCopy = ArrayBuffer::create(initData->data(), ini tData->byteLength()); | 196 WTF_LOG(Media, "MediaKeys(%p)::createSession", this); |
210 return createSessionInternal(scriptState, initDataType, initDataCopy.release (), sessionType); | |
211 } | |
212 | |
213 ScriptPromise MediaKeys::createSession(ScriptState* scriptState, const String& i nitDataType, ArrayBufferView* initData, const String& sessionType) | |
214 { | |
215 RefPtr<ArrayBuffer> initDataCopy = ArrayBuffer::create(initData->baseAddress (), initData->byteLength()); | |
216 return createSessionInternal(scriptState, initDataType, initDataCopy.release (), sessionType); | |
217 } | |
218 | |
219 ScriptPromise MediaKeys::createSessionInternal(ScriptState* scriptState, const S tring& initDataType, PassRefPtr<ArrayBuffer> initData, const String& sessionType ) | |
220 { | |
221 WTF_LOG(Media, "MediaKeys(%p)::createSession(%s, %d)", this, initDataType.as cii().data(), initData->byteLength()); | |
222 | 197 |
223 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-createsession>: | 198 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-createsession>: |
224 // The createSession(initDataType, initData, sessionType) method creates a | 199 // The createSession(sessionType) method returns a new MediaKeySession |
225 // new MediaKeySession object for the initData. It must run the following st eps: | 200 // object. It must run the following steps: |
226 | 201 // 1. If sessionType is not supported by the content decryption module |
227 // 1. If initDataType is an empty string, return a promise rejected with a | 202 // corresponding to the keySystem, throw a DOMException whose name is |
228 // new DOMException whose name is "InvalidAccessError". | 203 // "NotSupportedError". |
229 if (initDataType.isEmpty()) { | |
230 return createRejectedPromise(scriptState, InvalidAccessError, "The initD ataType parameter is empty."); | |
231 } | |
232 | |
233 // 2. If initData is an empty array, return a promise rejected with a new | |
234 // DOMException whose name is"InvalidAccessError". | |
235 if (!initData->byteLength()) { | |
236 return createRejectedPromise(scriptState, InvalidAccessError, "The initD ata parameter is empty."); | |
237 } | |
238 | |
239 // 3. If initDataType is not an initialization data type supported by the | |
240 // content decryption module corresponding to the keySystem, return a | |
241 // promise rejected with a new DOMException whose name is | |
242 // "NotSupportedError". String comparison is case-sensitive. | |
243 if (!isKeySystemSupportedWithInitDataType(m_keySystem, initDataType)) { | |
244 return createRejectedPromise(scriptState, NotSupportedError, "The initia lization data type '" + initDataType + "' is not supported by the key system."); | |
245 } | |
246 | |
247 // 4. If sessionType is not supported by the content decryption module | |
248 // corresponding to the keySystem, return a promise rejected with a new | |
249 // DOMException whose name is "NotSupportedError". | |
250 // Since this is typed by the IDL, we should not see any invalid values. | |
251 // FIXME: Check whether sessionType is actually supported by the CDM. | 204 // FIXME: Check whether sessionType is actually supported by the CDM. |
252 ASSERT(sessionType == kTemporary || sessionType == kPersistent); | 205 ASSERT(sessionType == kTemporary || sessionType == kPersistent); |
253 | 206 |
254 // 5. Let init data be a copy of the contents of the initData parameter. | 207 // 2. Let session be a new MediaKeySession object. |
ddorwin
2014/09/09 17:35:03
..., and initialize it as follows:
(Initialization
jrummell
2014/09/09 19:56:00
Done.
| |
255 // (Copied in the caller.) | 208 // 3. Return session. |
256 // 6. Let promise be a new promise. | 209 return MediaKeySession::create(scriptState, this, sessionType); |
257 // 7. Asynchronously create and initialize the session. | |
258 // 8. Return promise. | |
259 return MediaKeySession::create(scriptState, this, initDataType, initData, se ssionType); | |
260 } | 210 } |
261 | 211 |
262 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy pe) | 212 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy pe) |
263 { | 213 { |
264 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data( ), contentType.ascii().data()); | 214 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data( ), contentType.ascii().data()); |
265 | 215 |
266 // 1. If keySystem is an empty string, return false and abort these steps. | 216 // 1. If keySystem is an empty string, return false and abort these steps. |
267 if (keySystem.isEmpty()) | 217 if (keySystem.isEmpty()) |
268 return false; | 218 return false; |
269 | 219 |
(...skipping 22 matching lines...) Expand all Loading... | |
292 | 242 |
293 void MediaKeys::contextDestroyed() | 243 void MediaKeys::contextDestroyed() |
294 { | 244 { |
295 ContextLifecycleObserver::contextDestroyed(); | 245 ContextLifecycleObserver::contextDestroyed(); |
296 | 246 |
297 // We don't need the CDM anymore. | 247 // We don't need the CDM anymore. |
298 m_cdm.clear(); | 248 m_cdm.clear(); |
299 } | 249 } |
300 | 250 |
301 } // namespace blink | 251 } // namespace blink |
OLD | NEW |