| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // Step 4.4 of MediaKeys::create(): | 183 // Step 4.4 of MediaKeys::create(): |
| 197 // 4.4.1 Set the keySystem attribute to keySystem. | 184 // 4.4.1 Set the keySystem attribute to keySystem. |
| 198 ASSERT(!m_keySystem.isEmpty()); | 185 ASSERT(!m_keySystem.isEmpty()); |
| 199 } | 186 } |
| 200 | 187 |
| 201 MediaKeys::~MediaKeys() | 188 MediaKeys::~MediaKeys() |
| 202 { | 189 { |
| 203 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); | 190 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); |
| 204 } | 191 } |
| 205 | 192 |
| 206 ScriptPromise MediaKeys::createSession(ScriptState* scriptState, const String& i
nitDataType, ArrayBuffer* initData, const String& sessionType) | 193 MediaKeySession* MediaKeys::createSession(ScriptState* scriptState, const String
& sessionType) |
| 207 { | 194 { |
| 208 RefPtr<ArrayBuffer> initDataCopy = ArrayBuffer::create(initData->data(), ini
tData->byteLength()); | 195 WTF_LOG(Media, "MediaKeys(%p)::createSession", this); |
| 209 return createSessionInternal(scriptState, initDataType, initDataCopy.release
(), sessionType); | |
| 210 } | |
| 211 | |
| 212 ScriptPromise MediaKeys::createSession(ScriptState* scriptState, const String& i
nitDataType, ArrayBufferView* initData, const String& sessionType) | |
| 213 { | |
| 214 RefPtr<ArrayBuffer> initDataCopy = ArrayBuffer::create(initData->baseAddress
(), initData->byteLength()); | |
| 215 return createSessionInternal(scriptState, initDataType, initDataCopy.release
(), sessionType); | |
| 216 } | |
| 217 | |
| 218 ScriptPromise MediaKeys::createSessionInternal(ScriptState* scriptState, const S
tring& initDataType, PassRefPtr<ArrayBuffer> initData, const String& sessionType
) | |
| 219 { | |
| 220 WTF_LOG(Media, "MediaKeys(%p)::createSession(%s, %d)", this, initDataType.as
cii().data(), initData->byteLength()); | |
| 221 | 196 |
| 222 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-createsession>: | 197 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-createsession>: |
| 223 // The createSession(initDataType, initData, sessionType) method creates a | 198 // The createSession(sessionType) method returns a new MediaKeySession |
| 224 // new MediaKeySession object for the initData. It must run the following st
eps: | 199 // object. It must run the following steps: |
| 225 | 200 // 1. If sessionType is not supported by the content decryption module |
| 226 // 1. If initDataType is an empty string, return a promise rejected with a | 201 // corresponding to the keySystem, throw a DOMException whose name is |
| 227 // new DOMException whose name is "InvalidAccessError". | 202 // "NotSupportedError". |
| 228 if (initDataType.isEmpty()) { | |
| 229 return createRejectedPromise(scriptState, InvalidAccessError, "The initD
ataType parameter is empty."); | |
| 230 } | |
| 231 | |
| 232 // 2. If initData is an empty array, return a promise rejected with a new | |
| 233 // DOMException whose name is"InvalidAccessError". | |
| 234 if (!initData->byteLength()) { | |
| 235 return createRejectedPromise(scriptState, InvalidAccessError, "The initD
ata parameter is empty."); | |
| 236 } | |
| 237 | |
| 238 // 3. If initDataType is not an initialization data type supported by the | |
| 239 // content decryption module corresponding to the keySystem, return a | |
| 240 // promise rejected with a new DOMException whose name is | |
| 241 // "NotSupportedError". String comparison is case-sensitive. | |
| 242 if (!isKeySystemSupportedWithInitDataType(m_keySystem, initDataType)) { | |
| 243 return createRejectedPromise(scriptState, NotSupportedError, "The initia
lization data type '" + initDataType + "' is not supported by the key system."); | |
| 244 } | |
| 245 | |
| 246 // 4. If sessionType is not supported by the content decryption module | |
| 247 // corresponding to the keySystem, return a promise rejected with a new | |
| 248 // DOMException whose name is "NotSupportedError". | |
| 249 // Since this is typed by the IDL, we should not see any invalid values. | |
| 250 // FIXME: Check whether sessionType is actually supported by the CDM. | 203 // FIXME: Check whether sessionType is actually supported by the CDM. |
| 251 ASSERT(sessionType == kTemporary || sessionType == kPersistent); | 204 ASSERT(sessionType == kTemporary || sessionType == kPersistent); |
| 252 | 205 |
| 253 // 5. Let init data be a copy of the contents of the initData parameter. | 206 // 2. Let session be a new MediaKeySession object, and initialize it as |
| 254 // (Copied in the caller.) | 207 // follows: |
| 255 // 6. Let promise be a new promise. | 208 // (Initialization is performed in the constructor.) |
| 256 // 7. Asynchronously create and initialize the session. | 209 // 3. Return session. |
| 257 // 8. Return promise. | 210 return MediaKeySession::create(scriptState, this, sessionType); |
| 258 return MediaKeySession::create(scriptState, this, initDataType, initData, se
ssionType); | |
| 259 } | 211 } |
| 260 | 212 |
| 261 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy
pe) | 213 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy
pe) |
| 262 { | 214 { |
| 263 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data(
), contentType.ascii().data()); | 215 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data(
), contentType.ascii().data()); |
| 264 | 216 |
| 265 // 1. If keySystem is an empty string, return false and abort these steps. | 217 // 1. If keySystem is an empty string, return false and abort these steps. |
| 266 if (keySystem.isEmpty()) | 218 if (keySystem.isEmpty()) |
| 267 return false; | 219 return false; |
| 268 | 220 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 291 | 243 |
| 292 void MediaKeys::contextDestroyed() | 244 void MediaKeys::contextDestroyed() |
| 293 { | 245 { |
| 294 ContextLifecycleObserver::contextDestroyed(); | 246 ContextLifecycleObserver::contextDestroyed(); |
| 295 | 247 |
| 296 // We don't need the CDM anymore. | 248 // We don't need the CDM anymore. |
| 297 m_cdm.clear(); | 249 m_cdm.clear(); |
| 298 } | 250 } |
| 299 | 251 |
| 300 } // namespace blink | 252 } // namespace blink |
| OLD | NEW |