| 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 23 matching lines...) Expand all Loading... |
| 34 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" | 34 #include "modules/encryptedmedia/MediaKeyMessageEvent.h" |
| 35 #include "platform/ContentType.h" | 35 #include "platform/ContentType.h" |
| 36 #include "platform/Logging.h" | 36 #include "platform/Logging.h" |
| 37 #include "platform/MIMETypeRegistry.h" | 37 #include "platform/MIMETypeRegistry.h" |
| 38 #include "platform/UUID.h" | 38 #include "platform/UUID.h" |
| 39 #include "platform/drm/ContentDecryptionModule.h" | 39 #include "platform/drm/ContentDecryptionModule.h" |
| 40 #include "wtf/HashSet.h" | 40 #include "wtf/HashSet.h" |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 static bool isKeySystemSupportedWithContentType(const String& keySystem, const S
tring& contentType) |
| 45 { |
| 46 ASSERT(!keySystem.isEmpty()); |
| 47 |
| 48 ContentType type(contentType); |
| 49 String codecs = type.parameter("codecs"); |
| 50 return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, type.t
ype(), codecs); |
| 51 } |
| 52 |
| 44 PassRefPtrWillBeRawPtr<MediaKeys> MediaKeys::create(ExecutionContext* context, c
onst String& keySystem, ExceptionState& exceptionState) | 53 PassRefPtrWillBeRawPtr<MediaKeys> MediaKeys::create(ExecutionContext* context, c
onst String& keySystem, ExceptionState& exceptionState) |
| 45 { | 54 { |
| 46 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-media-keys-constructor>: | 55 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#dom-media-keys-constructor>: |
| 47 // The MediaKeys(keySystem) constructor must run the following steps: | 56 // The MediaKeys(keySystem) constructor must run the following steps: |
| 48 | 57 |
| 49 // 1. If keySystem is null or an empty string, throw an InvalidAccessError e
xception and abort these steps. | 58 // 1. If keySystem is null or an empty string, throw an InvalidAccessError e
xception and abort these steps. |
| 50 if (keySystem.isEmpty()) { | 59 if (keySystem.isEmpty()) { |
| 51 exceptionState.throwDOMException(InvalidAccessError, "The key system pro
vided is invalid."); | 60 exceptionState.throwDOMException(InvalidAccessError, "The key system pro
vided is invalid."); |
| 52 return nullptr; | 61 return nullptr; |
| 53 } | 62 } |
| 54 | 63 |
| 55 // 2. If keySystem is not one of the user agent's supported Key Systems, thr
ow a NotSupportedError and abort these steps. | 64 // 2. If keySystem is not one of the user agent's supported Key Systems, thr
ow a NotSupportedError and abort these steps. |
| 56 if (!ContentDecryptionModule::supportsKeySystem(keySystem)) { | 65 if (!isKeySystemSupportedWithContentType(keySystem, "")) { |
| 57 exceptionState.throwDOMException(NotSupportedError, "The '" + keySystem
+ "' key system is not supported."); | 66 exceptionState.throwDOMException(NotSupportedError, "The '" + keySystem
+ "' key system is not supported."); |
| 58 return nullptr; | 67 return nullptr; |
| 59 } | 68 } |
| 60 | 69 |
| 61 // 3. Let cdm be the content decryption module corresponding to keySystem. | 70 // 3. Let cdm be the content decryption module corresponding to keySystem. |
| 62 // 4. Load cdm if necessary. | 71 // 4. Load cdm if necessary. |
| 63 OwnPtr<ContentDecryptionModule> cdm = ContentDecryptionModule::create(keySys
tem); | 72 OwnPtr<ContentDecryptionModule> cdm = ContentDecryptionModule::create(keySys
tem); |
| 64 if (!cdm) { | 73 if (!cdm) { |
| 65 exceptionState.throwDOMException(NotSupportedError, "A content decryptio
n module could not be loaded for the '" + keySystem + "' key system."); | 74 exceptionState.throwDOMException(NotSupportedError, "A content decryptio
n module could not be loaded for the '" + keySystem + "' key system."); |
| 66 return nullptr; | 75 return nullptr; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return nullptr; | 110 return nullptr; |
| 102 } | 111 } |
| 103 | 112 |
| 104 if (!initData || !initData->length()) { | 113 if (!initData || !initData->length()) { |
| 105 exceptionState.throwDOMException(InvalidAccessError, "The initData provi
ded is null or empty."); | 114 exceptionState.throwDOMException(InvalidAccessError, "The initData provi
ded is null or empty."); |
| 106 return nullptr; | 115 return nullptr; |
| 107 } | 116 } |
| 108 | 117 |
| 109 // 1. If type contains a MIME type that is not supported or is not supported
by the keySystem, | 118 // 1. If type contains a MIME type that is not supported or is not supported
by the keySystem, |
| 110 // throw a NOT_SUPPORTED_ERR exception and abort these steps. | 119 // throw a NOT_SUPPORTED_ERR exception and abort these steps. |
| 111 if (!m_cdm->supportsMIMEType(contentType)) { | 120 if (!isKeySystemSupportedWithContentType(m_keySystem, contentType)) { |
| 112 exceptionState.throwDOMException(NotSupportedError, "The type provided (
'" + contentType + "') is unsupported."); | 121 exceptionState.throwDOMException(NotSupportedError, "The type provided (
'" + contentType + "') is unsupported."); |
| 113 return nullptr; | 122 return nullptr; |
| 114 } | 123 } |
| 115 | 124 |
| 116 // 2. Create a new MediaKeySession object. | 125 // 2. Create a new MediaKeySession object. |
| 117 RefPtrWillBeRawPtr<MediaKeySession> session = MediaKeySession::create(contex
t, m_cdm.get(), m_weakFactory.createWeakPtr()); | 126 RefPtrWillBeRawPtr<MediaKeySession> session = MediaKeySession::create(contex
t, m_cdm.get(), m_weakFactory.createWeakPtr()); |
| 118 // 2.1 Let the keySystem attribute be keySystem. | 127 // 2.1 Let the keySystem attribute be keySystem. |
| 119 ASSERT(!session->keySystem().isEmpty()); | 128 ASSERT(!session->keySystem().isEmpty()); |
| 120 // FIXME: 2.2 Let the state of the session be CREATED. | 129 // FIXME: 2.2 Let the state of the session be CREATED. |
| 121 | 130 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy
pe) | 143 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy
pe) |
| 135 { | 144 { |
| 136 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data(
), contentType.ascii().data()); | 145 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data(
), contentType.ascii().data()); |
| 137 | 146 |
| 138 // 1. If keySystem is null or an empty string, return false and abort these
steps. | 147 // 1. If keySystem is null or an empty string, return false and abort these
steps. |
| 139 if (keySystem.isEmpty()) | 148 if (keySystem.isEmpty()) |
| 140 return false; | 149 return false; |
| 141 | 150 |
| 142 // 2. If keySystem contains an unrecognized or unsupported Key System, retur
n false and abort | 151 // 2. If keySystem contains an unrecognized or unsupported Key System, retur
n false and abort |
| 143 // these steps. Key system string comparison is case-sensitive. | 152 // these steps. Key system string comparison is case-sensitive. |
| 144 if (!MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, "", "")) | 153 if (!isKeySystemSupportedWithContentType(keySystem, "")) |
| 145 return false; | 154 return false; |
| 146 | 155 |
| 147 // 3. If contentType is null or an empty string, return true and abort these
steps. | 156 // 3. If contentType is null or an empty string, return true and abort these
steps. |
| 148 if (contentType.isEmpty()) | 157 if (contentType.isEmpty()) |
| 149 return true; | 158 return true; |
| 150 | 159 |
| 151 // 4. If the Key System specified by keySystem does not support decrypting t
he container and/or | 160 // 4. If the Key System specified by keySystem does not support decrypting t
he container and/or |
| 152 // codec specified by contentType, return false and abort these steps. | 161 // codec specified by contentType, return false and abort these steps. |
| 153 ContentType type(contentType); | 162 return isKeySystemSupportedWithContentType(keySystem, contentType); |
| 154 String codecs = type.parameter("codecs"); | |
| 155 | |
| 156 return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, type.t
ype(), codecs); | |
| 157 } | 163 } |
| 158 | 164 |
| 159 void MediaKeys::setMediaElement(HTMLMediaElement* element) | 165 void MediaKeys::setMediaElement(HTMLMediaElement* element) |
| 160 { | 166 { |
| 161 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_
mediaElement is not 0 | 167 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_
mediaElement is not 0 |
| 162 // and remove the code that prevents the assert below in HTMLMediaElement. | 168 // and remove the code that prevents the assert below in HTMLMediaElement. |
| 163 ASSERT(!m_mediaElement != !element); | 169 ASSERT(!m_mediaElement != !element); |
| 164 m_mediaElement = element; | 170 m_mediaElement = element; |
| 165 } | 171 } |
| 166 | 172 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 192 | 198 |
| 193 void MediaKeys::contextDestroyed() | 199 void MediaKeys::contextDestroyed() |
| 194 { | 200 { |
| 195 ContextLifecycleObserver::contextDestroyed(); | 201 ContextLifecycleObserver::contextDestroyed(); |
| 196 | 202 |
| 197 // We don't need the CDM anymore. | 203 // We don't need the CDM anymore. |
| 198 m_cdm.clear(); | 204 m_cdm.clear(); |
| 199 } | 205 } |
| 200 | 206 |
| 201 } | 207 } |
| OLD | NEW |