Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Side by Side Diff: Source/modules/encryptedmedia/MediaKeys.cpp

Issue 183943003: Verify MediaKeys parameter values consistently (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rename Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // From <http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#dom-media-keys-constructor>: 46 // 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: 47 // The MediaKeys(keySystem) constructor must run the following steps:
48 48
49 // 1. If keySystem is null or an empty string, throw an InvalidAccessError e xception and abort these steps. 49 // 1. If keySystem is null or an empty string, throw an InvalidAccessError e xception and abort these steps.
50 if (keySystem.isEmpty()) { 50 if (keySystem.isEmpty()) {
51 exceptionState.throwDOMException(InvalidAccessError, "The key system pro vided is invalid."); 51 exceptionState.throwDOMException(InvalidAccessError, "The key system pro vided is invalid.");
52 return nullptr; 52 return nullptr;
53 } 53 }
54 54
55 // 2. If keySystem is not one of the user agent's supported Key Systems, thr ow a NotSupportedError and abort these steps. 55 // 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)) { 56 if (!isKeySystemSupported(keySystem)) {
57 exceptionState.throwDOMException(NotSupportedError, "The '" + keySystem + "' key system is not supported."); 57 exceptionState.throwDOMException(NotSupportedError, "The '" + keySystem + "' key system is not supported.");
58 return nullptr; 58 return nullptr;
59 } 59 }
60 60
61 // 3. Let cdm be the content decryption module corresponding to keySystem. 61 // 3. Let cdm be the content decryption module corresponding to keySystem.
62 // 4. Load cdm if necessary. 62 // 4. Load cdm if necessary.
63 OwnPtr<ContentDecryptionModule> cdm = ContentDecryptionModule::create(keySys tem); 63 OwnPtr<ContentDecryptionModule> cdm = ContentDecryptionModule::create(keySys tem);
64 if (!cdm) { 64 if (!cdm) {
65 exceptionState.throwDOMException(NotSupportedError, "A content decryptio n module could not be loaded for the '" + keySystem + "' key system."); 65 exceptionState.throwDOMException(NotSupportedError, "A content decryptio n module could not be loaded for the '" + keySystem + "' key system.");
66 return nullptr; 66 return nullptr;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return nullptr; 101 return nullptr;
102 } 102 }
103 103
104 if (!initData || !initData->length()) { 104 if (!initData || !initData->length()) {
105 exceptionState.throwDOMException(InvalidAccessError, "The initData provi ded is null or empty."); 105 exceptionState.throwDOMException(InvalidAccessError, "The initData provi ded is null or empty.");
106 return nullptr; 106 return nullptr;
107 } 107 }
108 108
109 // 1. If type contains a MIME type that is not supported or is not supported by the keySystem, 109 // 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. 110 // throw a NOT_SUPPORTED_ERR exception and abort these steps.
111 if (!m_cdm->supportsMIMEType(contentType)) { 111 if (!isKeySystemSupportedWithContentType(m_keySystem, contentType)) {
112 exceptionState.throwDOMException(NotSupportedError, "The type provided ( '" + contentType + "') is unsupported."); 112 exceptionState.throwDOMException(NotSupportedError, "The type provided ( '" + contentType + "') is unsupported.");
113 return nullptr; 113 return nullptr;
114 } 114 }
115 115
116 // 2. Create a new MediaKeySession object. 116 // 2. Create a new MediaKeySession object.
117 RefPtrWillBeRawPtr<MediaKeySession> session = MediaKeySession::create(contex t, m_cdm.get(), m_weakFactory.createWeakPtr()); 117 RefPtrWillBeRawPtr<MediaKeySession> session = MediaKeySession::create(contex t, m_cdm.get(), m_weakFactory.createWeakPtr());
118 // 2.1 Let the keySystem attribute be keySystem. 118 // 2.1 Let the keySystem attribute be keySystem.
119 ASSERT(!session->keySystem().isEmpty()); 119 ASSERT(!session->keySystem().isEmpty());
120 // FIXME: 2.2 Let the state of the session be CREATED. 120 // FIXME: 2.2 Let the state of the session be CREATED.
121 121
(...skipping 12 matching lines...) Expand all
134 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy pe) 134 bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentTy pe)
135 { 135 {
136 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data( ), contentType.ascii().data()); 136 WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data( ), contentType.ascii().data());
137 137
138 // 1. If keySystem is null or an empty string, return false and abort these steps. 138 // 1. If keySystem is null or an empty string, return false and abort these steps.
139 if (keySystem.isEmpty()) 139 if (keySystem.isEmpty())
140 return false; 140 return false;
141 141
142 // 2. If keySystem contains an unrecognized or unsupported Key System, retur n false and abort 142 // 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. 143 // these steps. Key system string comparison is case-sensitive.
144 if (!MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, "", "")) 144 if (!isKeySystemSupported(keySystem))
145 return false; 145 return false;
146 146
147 // 3. If contentType is null or an empty string, return true and abort these steps. 147 // 3. If contentType is null or an empty string, return true and abort these steps.
148 if (contentType.isEmpty()) 148 if (contentType.isEmpty())
149 return true; 149 return true;
150 150
151 // 4. If the Key System specified by keySystem does not support decrypting t he container and/or 151 // 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. 152 // codec specified by contentType, return false and abort these steps.
153 return isKeySystemSupportedWithContentType(keySystem, contentType);
154 }
155
156 bool MediaKeys::isKeySystemSupported(const String& keySystem)
157 {
158 ASSERT(!keySystem.isEmpty());
159 return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, "", "" );
160 }
161
162 bool MediaKeys::isKeySystemSupportedWithContentType(const String& keySystem, con st String& contentType)
163 {
164 ASSERT(!keySystem.isEmpty());
165 ASSERT(!contentType.isEmpty());
acolwell GONE FROM CHROMIUM 2014/02/28 16:50:40 nit: I'm not sure there is a lot of value having 2
jrummell 2014/02/28 19:06:52 Done.
166
153 ContentType type(contentType); 167 ContentType type(contentType);
154 String codecs = type.parameter("codecs"); 168 String codecs = type.parameter("codecs");
155
156 return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, type.t ype(), codecs); 169 return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, type.t ype(), codecs);
157 } 170 }
158 171
159 void MediaKeys::setMediaElement(HTMLMediaElement* element) 172 void MediaKeys::setMediaElement(HTMLMediaElement* element)
160 { 173 {
161 // FIXME: Cause HTMLMediaElement::setMediaKeys() to throw an exception if m_ mediaElement is not 0 174 // 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. 175 // and remove the code that prevents the assert below in HTMLMediaElement.
163 ASSERT(!m_mediaElement != !element); 176 ASSERT(!m_mediaElement != !element);
164 m_mediaElement = element; 177 m_mediaElement = element;
165 } 178 }
(...skipping 26 matching lines...) Expand all
192 205
193 void MediaKeys::contextDestroyed() 206 void MediaKeys::contextDestroyed()
194 { 207 {
195 ContextLifecycleObserver::contextDestroyed(); 208 ContextLifecycleObserver::contextDestroyed();
196 209
197 // We don't need the CDM anymore. 210 // We don't need the CDM anymore.
198 m_cdm.clear(); 211 m_cdm.clear();
199 } 212 }
200 213
201 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698