| 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, and initialize it as |
| 255 // (Copied in the caller.) | 208 // follows: |
| 256 // 6. Let promise be a new promise. | 209 // (Initialization is performed in the constructor.) |
| 257 // 7. Asynchronously create and initialize the session. | 210 // 3. Return session. |
| 258 // 8. Return promise. | 211 return MediaKeySession::create(scriptState, this, sessionType); |
| 259 return MediaKeySession::create(scriptState, this, initDataType, initData, se
ssionType); | |
| 260 } | 212 } |
| 261 | 213 |
| 262 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy
pe) | 214 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy
pe) |
| 263 { | 215 { |
| 264 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data(
), contentType.ascii().data()); | 216 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data(
), contentType.ascii().data()); |
| 265 | 217 |
| 266 // 1. If keySystem is an empty string, return false and abort these steps. | 218 // 1. If keySystem is an empty string, return false and abort these steps. |
| 267 if (keySystem.isEmpty()) | 219 if (keySystem.isEmpty()) |
| 268 return false; | 220 return false; |
| 269 | 221 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 292 | 244 |
| 293 void MediaKeys::contextDestroyed() | 245 void MediaKeys::contextDestroyed() |
| 294 { | 246 { |
| 295 ContextLifecycleObserver::contextDestroyed(); | 247 ContextLifecycleObserver::contextDestroyed(); |
| 296 | 248 |
| 297 // We don't need the CDM anymore. | 249 // We don't need the CDM anymore. |
| 298 m_cdm.clear(); | 250 m_cdm.clear(); |
| 299 } | 251 } |
| 300 | 252 |
| 301 } // namespace blink | 253 } // namespace blink |
| OLD | NEW |