Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webencryptedmediaclient_impl.h" | 5 #include "webencryptedmediaclient_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "media/base/key_systems.h" | 11 #include "media/base/key_systems.h" |
| 12 #include "media/base/media_permission.h" | 12 #include "media/base/media_permission.h" |
| 13 #include "media/blink/webcontentdecryptionmodule_impl.h" | 13 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 14 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h" | 14 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h" |
| 15 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
| 16 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" | 16 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" |
| 17 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" | 17 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 | 20 |
| 21 namespace media { | 21 namespace media { |
| 22 | 22 |
| 23 // These names are used by UMA. | 23 // These names are used by UMA. |
| 24 const char kKeySystemSupportUMAPrefix[] = | 24 const char kKeySystemSupportUMAPrefix[] = |
| 25 "Media.EME.RequestMediaKeySystemAccess."; | 25 "Media.EME.RequestMediaKeySystemAccess."; |
| 26 | 26 |
| 27 // TODO(jrummell): Convert to an enum. http://crbug.com/418239 | |
| 28 const char kTemporarySessionType[] = "temporary"; | |
| 29 const char kPersistentLicenseSessionType[] = "persistent-license"; | |
| 30 const char kPersistentReleaseMessageSessionType[] = | |
| 31 "persistent-release-message"; | |
| 32 | |
| 27 static bool IsSupportedContentType( | 33 static bool IsSupportedContentType( |
| 28 const std::string& key_system, | 34 const std::string& key_system, |
| 29 const std::string& mime_type, | 35 const std::string& mime_type, |
| 30 const std::string& codecs) { | 36 const std::string& codecs) { |
| 31 // Per RFC 6838, "Both top-level type and subtype names are case-insensitive." | 37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
| 32 // TODO(sandersd): Check that |container| matches the capability: | 38 // parameters can be rejected. http://crbug.com/417561 |
| 33 // - audioCapabilitys: audio/mp4 or audio/webm. | 39 // TODO(sandersd): Pass in the media type (audio or video) and check that the |
| 34 // - videoCapabilitys: video/mp4 or video/webm. | 40 // container type matches. http://crbug.com/457384 |
| 35 // http://crbug.com/457384. | |
| 36 std::string container = base::StringToLowerASCII(mime_type); | 41 std::string container = base::StringToLowerASCII(mime_type); |
| 37 | 42 |
| 38 // Check that |codecs| are supported as specified (e.g. "mp4a.40.2"). | 43 // Check that |codecs| are supported by the CDM. This check does not handle |
| 44 // extended codecs, so extended codec information is stripped. | |
| 45 // TODO(sandersd): Reject codecs that do not match the media type. | |
| 46 // http://crbug.com/457386 | |
| 39 std::vector<std::string> codec_vector; | 47 std::vector<std::string> codec_vector; |
| 48 net::ParseCodecString(codecs, &codec_vector, true); | |
| 49 if (!IsSupportedKeySystemWithMediaMimeType(container, codec_vector, | |
| 50 key_system)) { | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 // Check that |codecs| are supported by Chrome. This is done primarily to | |
| 55 // validate extended codecs, but it also ensures that the CDM cannot support | |
| 56 // codecs that Chrome does not (which would be bad because it would require | |
| 57 // considering the accumulated configuration, and could affect whether secure | |
| 58 // decode is required). | |
| 59 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 | |
| 60 codec_vector.clear(); | |
| 40 net::ParseCodecString(codecs, &codec_vector, false); | 61 net::ParseCodecString(codecs, &codec_vector, false); |
| 41 if (!net::AreSupportedMediaCodecs(codec_vector)) | 62 return net::AreSupportedMediaCodecs(codec_vector); |
| 42 return false; | 63 } |
| 43 | 64 |
| 44 // IsSupportedKeySystemWithMediaMimeType() only works with base codecs | 65 static bool GetSupportedCapabilities( |
| 45 // (e.g. "mp4a"), so reparse |codecs| to get the base only. | 66 const std::string& key_system, |
| 46 codec_vector.clear(); | 67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
| 47 net::ParseCodecString(codecs, &codec_vector, true); | 68 capabilities, |
| 48 return IsSupportedKeySystemWithMediaMimeType(container, codec_vector, | 69 std::vector<blink::WebMediaKeySystemMediaCapability>* |
| 49 key_system); | 70 media_type_capabilities) { |
| 71 // From https://w3c.github.io/encrypted-media/#get-supported-capabilities-for- media-type | |
| 72 // 1. Let accumulated capabilities be partial configuration. | |
| 73 // (Skipped as there are no configuration-based codec restrictions.) | |
| 74 // 2. Let media type capabilities be empty. (Done by caller.) | |
|
ddorwin
2015/02/19 04:23:42
nit: You can remove the () part now that you have
sandersd (OOO until July 31)
2015/02/19 21:08:35
Done.
| |
| 75 DCHECK_EQ(media_type_capabilities->size(), 0); | |
| 76 // 3. For each value in capabilities: | |
| 77 for (size_t i = 0; i < capabilities.size(); i++) { | |
| 78 // 3.1. Let contentType be the value's contentType member. | |
| 79 // 3.2. Let robustness be the value's robustness member. | |
| 80 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; | |
| 81 // 3.3. If contentType is the empty string, return null. | |
| 82 if (capability.mimeType.isEmpty()) | |
| 83 return false; | |
| 84 // 3.4-3.11. (Implemented by IsSupportedContentType().) | |
| 85 if (!base::IsStringASCII(capability.mimeType) || | |
| 86 !base::IsStringASCII(capability.codecs) || | |
| 87 !IsSupportedContentType(key_system, | |
| 88 base::UTF16ToASCII(capability.mimeType), | |
| 89 base::UTF16ToASCII(capability.codecs))) { | |
| 90 continue; | |
| 91 } | |
| 92 // 3.12. If robustness is not the empty string, run the following steps: | |
| 93 // (Robustness is not supported.) | |
| 94 // TODO(sandersd): Implement robustness. http://crbug.com/442586 | |
| 95 if (!capability.robustness.isEmpty()) | |
| 96 continue; | |
|
ddorwin
2015/02/19 04:23:42
Can we log a console info message here to say it's
sandersd (OOO until July 31)
2015/02/19 21:08:36
Done.
| |
| 97 // 3.13. If the user agent and implementation do not support playback of | |
| 98 // encrypted media data as specified by configuration, including all | |
| 99 // media types, in combination with accumulated capabilities, | |
| 100 // continue to the next iteration. | |
| 101 // (Skipped as there are no configuration-based codec restrictions.) | |
| 102 // 3.14. Add configuration to media type capabilities. | |
| 103 media_type_capabilities->push_back(capability); | |
| 104 // 3.15. Add configuration to accumulated capabilities. | |
| 105 // (Skipped as there are no configuration-based codec restrictions.) | |
| 106 } | |
| 107 // 4. If media type capabilities is empty, return null. | |
| 108 // 5. Return media type capabilities. | |
| 109 return !media_type_capabilities->empty(); | |
| 110 } | |
| 111 | |
| 112 static EmeFeatureRequirement ConvertRequirement( | |
| 113 blink::WebMediaKeySystemConfiguration::Requirement requirement) { | |
| 114 switch (requirement) { | |
| 115 case blink::WebMediaKeySystemConfiguration::Requirement::Required: | |
| 116 return EME_FEATURE_REQUIRED; | |
| 117 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: | |
| 118 return EME_FEATURE_OPTIONAL; | |
| 119 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | |
| 120 return EME_FEATURE_NOT_ALLOWED; | |
| 121 } | |
| 122 | |
| 123 NOTREACHED(); | |
| 124 return EME_FEATURE_NOT_ALLOWED; | |
| 50 } | 125 } |
| 51 | 126 |
| 52 static bool GetSupportedConfiguration( | 127 static bool GetSupportedConfiguration( |
| 53 const std::string& key_system, | 128 const std::string& key_system, |
| 54 const blink::WebMediaKeySystemConfiguration& candidate, | 129 const blink::WebMediaKeySystemConfiguration& candidate, |
| 55 const blink::WebSecurityOrigin& security_origin, | 130 const blink::WebSecurityOrigin& security_origin, |
| 56 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { | 131 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
| 132 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | |
| 133 // 1. Let accumulated configuration be empty. (Done by caller.) | |
| 134 // 2. If candidate configuration's initDataTypes attribute is not empty, run | |
| 135 // the following steps: | |
| 57 if (!candidate.initDataTypes.isEmpty()) { | 136 if (!candidate.initDataTypes.isEmpty()) { |
| 58 std::vector<blink::WebString> init_data_types; | 137 // 2.1. Let supported types be empty. |
| 138 std::vector<blink::WebString> supported_types; | |
| 59 | 139 |
| 140 // 2.2. For each value in candidate configuration's initDataTypes attribute: | |
| 60 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { | 141 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { |
| 142 // 2.2.1. Let initDataType be the value. | |
| 61 const blink::WebString& init_data_type = candidate.initDataTypes[i]; | 143 const blink::WebString& init_data_type = candidate.initDataTypes[i]; |
| 144 // 2.2.2. If initDataType is the empty string, return null. | |
| 62 if (init_data_type.isEmpty()) | 145 if (init_data_type.isEmpty()) |
| 63 return false; | 146 return false; |
| 147 // 2.2.3. If the implementation supports generating requests based on | |
| 148 // initDataType, add initDataType to supported types. String | |
| 149 // comparison is case-sensitive. | |
| 64 if (base::IsStringASCII(init_data_type) && | 150 if (base::IsStringASCII(init_data_type) && |
| 65 IsSupportedKeySystemWithInitDataType( | 151 IsSupportedKeySystemWithInitDataType( |
| 66 key_system, base::UTF16ToASCII(init_data_type))) { | 152 key_system, base::UTF16ToASCII(init_data_type))) { |
| 67 init_data_types.push_back(init_data_type); | 153 supported_types.push_back(init_data_type); |
| 68 } | 154 } |
| 69 } | 155 } |
| 70 | 156 |
| 71 if (init_data_types.empty()) | 157 // 2.3. If supported types is empty, return null. |
| 158 if (supported_types.empty()) | |
| 72 return false; | 159 return false; |
| 73 | 160 |
| 74 accumulated_configuration->initDataTypes = init_data_types; | 161 // 2.4. Add supported types to accumulated configuration. |
| 162 accumulated_configuration->initDataTypes = supported_types; | |
| 75 } | 163 } |
| 76 | 164 |
| 77 // TODO(sandersd): Implement distinctiveIdentifier and persistentState checks. | 165 // 3. Follow the steps for the value of candidate configuration's |
| 78 if (candidate.distinctiveIdentifier != | 166 // distinctiveIdentifier attribute from the following list: |
| 79 blink::WebMediaKeySystemConfiguration::Requirement::Optional || | 167 // - "required": If the implementation does not support a persistent |
| 80 candidate.persistentState != | 168 // Distinctive Identifier in combination with accumulated configuration, |
| 81 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 169 // return null. |
| 170 // - "optional": Continue. | |
| 171 // - "not-allowed": If the implementation requires a Distinctive | |
|
ddorwin
2015/02/19 04:23:42
Since we can't enforce this, I think we need to al
sandersd (OOO until July 31)
2015/02/19 21:08:35
That is done implicitly when CDMs declare ALWAYS_E
ddorwin
2015/02/19 23:03:57
We don't seem to be enforcing this assumption in k
sandersd (OOO until July 31)
2015/02/20 00:17:12
KeySystems does this explicitly:
case EME_FEA
| |
| 172 // Identifier in combination with accumulated configuration, return | |
| 173 // null. | |
| 174 EmeFeatureRequirement requirement; | |
| 175 requirement = ConvertRequirement(candidate.distinctiveIdentifier); | |
|
ddorwin
2015/02/19 04:23:42
EmeFeatureRequirement requirement =
ConvertReq
sandersd (OOO until July 31)
2015/02/19 21:08:35
Done.
| |
| 176 if (!IsDistinctiveIdentifierSupported(key_system, requirement, true)) | |
|
ddorwin
2015/02/19 04:23:42
There should be a comment for this "true". For exa
sandersd (OOO until July 31)
2015/02/19 21:08:35
Done.
| |
| 82 return false; | 177 return false; |
| 178 | |
| 179 // 4. Add the value of the candidate configuration's distinctiveIdentifier | |
| 180 // attribute to accumulated configuration. | |
| 181 accumulated_configuration->distinctiveIdentifier = | |
| 182 candidate.distinctiveIdentifier; | |
| 183 | |
| 184 // 5. Follow the steps for the value of candidate configuration's | |
| 185 // persistentState attribute from the following list: | |
| 186 // - "required": If the implementation does not support persisting state | |
| 187 // in combination with accumulated configuration, return null. | |
| 188 // - "optional": Continue. | |
| 189 // - "not-allowed": If the implementation requires persisting state in | |
|
ddorwin
2015/02/19 04:23:42
ditto about rejecting.
sandersd (OOO until July 31)
2015/02/19 21:08:35
Acknowledged.
| |
| 190 // combination with accumulated configuration, return null. | |
| 191 requirement = ConvertRequirement(candidate.persistentState); | |
| 192 if (!IsPersistentStateSupported(key_system, requirement, true)) | |
|
ddorwin
2015/02/19 04:23:42
ditto
sandersd (OOO until July 31)
2015/02/19 21:08:35
Done.
| |
| 193 return false; | |
| 194 | |
| 195 // 6. Add the value of the candidate configuration's persistentState | |
| 196 // attribute to accumulated configuration. | |
| 197 accumulated_configuration->persistentState = candidate.persistentState; | |
| 198 | |
| 199 // 7. If candidate configuration's videoCapabilities attribute is not empty, | |
| 200 // run the following steps: | |
| 201 if (!candidate.videoCapabilities.isEmpty()) { | |
| 202 // 7.1. Let video capabilities be the result of executing the Get Supported | |
| 203 // Capabilities for Media Type algorithm on Video, candidate | |
| 204 // configuration's videoCapabilities attribute, and accumulated | |
| 205 // configuration. | |
| 206 // 7.2. If video capabilities is null, return null. | |
| 207 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | |
| 208 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, | |
| 209 &video_capabilities)) { | |
| 210 return false; | |
| 211 } | |
| 212 | |
| 213 // 7.3. Add video capabilities to accumulated configuration. | |
| 214 accumulated_configuration->videoCapabilities = video_capabilities; | |
| 83 } | 215 } |
| 84 | 216 |
| 217 // 8. If candidate configuration's audioCapabilities attribute is not empty, | |
| 218 // run the following steps: | |
| 85 if (!candidate.audioCapabilities.isEmpty()) { | 219 if (!candidate.audioCapabilities.isEmpty()) { |
| 220 // 8.1. Let audio capabilities be the result of executing the Get Supported | |
| 221 // Capabilities for Media Type algorithm on Audio, candidate | |
| 222 // configuration's audioCapabilities attribute, and accumulated | |
| 223 // configuration. | |
| 224 // 8.2. If audio capabilities is null, return null. | |
| 86 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | 225 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
| 87 | 226 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, |
| 88 for (size_t i = 0; i < candidate.audioCapabilities.size(); i++) { | 227 &audio_capabilities)) { |
| 89 const blink::WebMediaKeySystemMediaCapability& capabilities = | 228 return false; |
| 90 candidate.audioCapabilities[i]; | |
| 91 if (capabilities.mimeType.isEmpty()) | |
| 92 return false; | |
| 93 if (!base::IsStringASCII(capabilities.mimeType) || | |
| 94 !base::IsStringASCII(capabilities.codecs) || | |
| 95 !IsSupportedContentType( | |
| 96 key_system, base::UTF16ToASCII(capabilities.mimeType), | |
| 97 base::UTF16ToASCII(capabilities.codecs))) { | |
| 98 continue; | |
| 99 } | |
| 100 // TODO(sandersd): Support robustness. | |
| 101 if (!capabilities.robustness.isEmpty()) | |
| 102 continue; | |
| 103 audio_capabilities.push_back(capabilities); | |
| 104 } | 229 } |
| 105 | 230 |
| 106 if (audio_capabilities.empty()) | 231 // 8.3. Add audio capabilities to accumulated configuration. |
| 107 return false; | |
| 108 | |
| 109 accumulated_configuration->audioCapabilities = audio_capabilities; | 232 accumulated_configuration->audioCapabilities = audio_capabilities; |
| 110 } | 233 } |
| 111 | 234 |
| 112 if (!candidate.videoCapabilities.isEmpty()) { | 235 // 9. If accumulated configuration's distinctiveIdentifier value is |
| 113 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | 236 // "optional", follow the steps for the first matching condition from the |
| 114 | 237 // following list: |
| 115 for (size_t i = 0; i < candidate.videoCapabilities.size(); i++) { | 238 // - If the implementation requires a Distinctive Identifier for any of |
| 116 const blink::WebMediaKeySystemMediaCapability& capabilities = | 239 // the combinations in accumulated configuration, change accumulated |
| 117 candidate.videoCapabilities[i]; | 240 // configuration's distinctiveIdentifier value to "required". |
| 118 if (capabilities.mimeType.isEmpty()) | 241 // - Otherwise, change accumulated configuration's distinctiveIdentifier |
| 119 return false; | 242 // value to "not-allowed". |
| 120 if (!base::IsStringASCII(capabilities.mimeType) || | 243 // (Without robustness support, capabilities do not affect this.) |
| 121 !base::IsStringASCII(capabilities.codecs) || | 244 // TODO(sandersd): Implement robustness. http://crbug.com/442586 |
| 122 !IsSupportedContentType( | 245 if (accumulated_configuration->distinctiveIdentifier == |
| 123 key_system, base::UTF16ToASCII(capabilities.mimeType), | 246 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| 124 base::UTF16ToASCII(capabilities.codecs))) { | 247 if (IsDistinctiveIdentifierSupported(key_system, EME_FEATURE_NOT_ALLOWED, |
| 125 continue; | 248 true)) { |
|
ddorwin
2015/02/19 04:23:42
Explain "true" here too.
sandersd (OOO until July 31)
2015/02/19 21:08:35
It doesn't actually make any difference, so it's h
| |
| 126 } | 249 accumulated_configuration->distinctiveIdentifier = |
| 127 // TODO(sandersd): Support robustness. | 250 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
| 128 if (!capabilities.robustness.isEmpty()) | 251 } else { |
| 129 continue; | 252 accumulated_configuration->distinctiveIdentifier = |
| 130 video_capabilities.push_back(capabilities); | 253 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 131 } | 254 } |
| 132 | |
| 133 if (video_capabilities.empty()) | |
| 134 return false; | |
| 135 | |
| 136 accumulated_configuration->videoCapabilities = video_capabilities; | |
| 137 } | 255 } |
| 138 | 256 |
| 139 // TODO(sandersd): Prompt for distinctive identifiers and/or persistent state | 257 // 10. If accumulated configuration's persistentState value is "optional", |
| 140 // if required. Make sure that future checks are silent. | 258 // follow the steps for the first matching condition from the following |
| 141 // http://crbug.com/446263. | 259 // list: |
| 260 // - If the implementation requires persisting state for any of the | |
| 261 // combinations in accumulated configuration, change accumulated | |
| 262 // configuration's persistentState value to "required". | |
| 263 // - Otherwise, change accumulated configuration's persistentState value | |
| 264 // to "not-allowed". | |
| 265 if (accumulated_configuration->persistentState == | |
| 266 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | |
| 267 if (IsPersistentStateSupported(key_system, EME_FEATURE_NOT_ALLOWED, true)) { | |
|
ddorwin
2015/02/19 04:23:42
ditto
sandersd (OOO until July 31)
2015/02/19 21:08:35
Acknowledged.
| |
| 268 accumulated_configuration->persistentState = | |
| 269 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
| 270 } else { | |
| 271 accumulated_configuration->persistentState = | |
| 272 blink::WebMediaKeySystemConfiguration::Requirement::Required; | |
| 273 } | |
| 274 } | |
| 275 | |
| 276 // 11. If implementation in the configuration specified by the combination of | |
| 277 // the values in accumulated configuration is not supported or not allowed | |
| 278 // in the origin, return null. | |
| 279 // TODO(sandersd): Implement prompting. http://crbug.com/446263 | |
|
ddorwin
2015/02/19 04:23:42
// For now, pass "false" for |is_permission_grante
sandersd (OOO until July 31)
2015/02/19 21:08:36
Done.
| |
| 280 requirement = | |
| 281 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); | |
| 282 if (!IsDistinctiveIdentifierSupported(key_system, requirement, false)) | |
| 283 return false; | |
| 284 | |
| 285 requirement = ConvertRequirement(accumulated_configuration->persistentState); | |
| 286 if (!IsPersistentStateSupported(key_system, requirement, false)) | |
| 287 return false; | |
| 288 | |
| 289 // 12. Return accumulated configuration. | |
| 290 // (As an extra step, we record the available session types so that | |
| 291 // createSession() can be synchronous.) | |
| 292 std::vector<blink::WebString> session_types; | |
| 293 session_types.push_back(kTemporarySessionType); | |
| 294 if (accumulated_configuration->persistentState == | |
| 295 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | |
| 296 if (IsPersistentLicenseSupported(key_system, false)) | |
| 297 session_types.push_back(kPersistentLicenseSessionType); | |
| 298 if (IsPersistentReleaseMessageSupported(key_system, false)) | |
| 299 session_types.push_back(kPersistentReleaseMessageSessionType); | |
| 300 } | |
| 301 accumulated_configuration->sessionTypes = session_types; | |
| 142 | 302 |
| 143 return true; | 303 return true; |
| 144 } | 304 } |
| 145 | 305 |
| 146 // Report usage of key system to UMA. There are 2 different counts logged: | 306 // Report usage of key system to UMA. There are 2 different counts logged: |
| 147 // 1. The key system is requested. | 307 // 1. The key system is requested. |
| 148 // 2. The requested key system and options are supported. | 308 // 2. The requested key system and options are supported. |
| 149 // Each stat is only reported once per renderer frame per key system. | 309 // Each stat is only reported once per renderer frame per key system. |
| 150 // Note that WebEncryptedMediaClientImpl is only created once by each | 310 // Note that WebEncryptedMediaClientImpl is only created once by each |
| 151 // renderer frame. | 311 // renderer frame. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { | 365 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { |
| 206 } | 366 } |
| 207 | 367 |
| 208 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( | 368 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
| 209 blink::WebEncryptedMediaRequest request) { | 369 blink::WebEncryptedMediaRequest request) { |
| 210 // TODO(jrummell): This should be asynchronous. | 370 // TODO(jrummell): This should be asynchronous. |
| 211 | 371 |
| 212 // Continued from requestMediaKeySystemAccess(), step 7, from | 372 // Continued from requestMediaKeySystemAccess(), step 7, from |
| 213 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | 373 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
| 214 // | 374 // |
| 215 // 7.1 If keySystem is not one of the Key Systems supported by the user | 375 // 7.1. If keySystem is not one of the Key Systems supported by the user |
| 216 // agent, reject promise with with a new DOMException whose name is | 376 // agent, reject promise with with a new DOMException whose name is |
| 217 // NotSupportedError. String comparison is case-sensitive. | 377 // NotSupportedError. String comparison is case-sensitive. |
| 218 if (!base::IsStringASCII(request.keySystem())) { | 378 if (!base::IsStringASCII(request.keySystem())) { |
| 219 request.requestNotSupported("Only ASCII keySystems are supported"); | 379 request.requestNotSupported("Only ASCII keySystems are supported"); |
| 220 return; | 380 return; |
| 221 } | 381 } |
| 222 | 382 |
| 223 std::string key_system = base::UTF16ToASCII(request.keySystem()); | 383 std::string key_system = base::UTF16ToASCII(request.keySystem()); |
| 224 | 384 |
| 225 // Report this request to the appropriate Reporter. | 385 // Report this request to the appropriate Reporter. |
| 226 Reporter* reporter = GetReporter(key_system); | 386 Reporter* reporter = GetReporter(key_system); |
| 227 reporter->ReportRequested(); | 387 reporter->ReportRequested(); |
| 228 | 388 |
| 229 if (!IsSupportedKeySystem(key_system)) { | 389 if (!IsSupportedKeySystem(key_system)) { |
| 230 request.requestNotSupported("Unsupported keySystem"); | 390 request.requestNotSupported("Unsupported keySystem"); |
| 231 return; | 391 return; |
| 232 } | 392 } |
| 233 | 393 |
| 234 // 7.2 Let implementation be the implementation of keySystem. | 394 // 7.2. Let implementation be the implementation of keySystem. |
| 235 // 7.3 For each value in supportedConfigurations, run the GetSupported | 395 // 7.3. For each value in supportedConfigurations: |
| 236 // Configuration algorithm and if successful, resolve promise with access | |
| 237 // and abort these steps. | |
| 238 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& | 396 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& |
| 239 configurations = request.supportedConfigurations(); | 397 configurations = request.supportedConfigurations(); |
| 240 | |
| 241 // TODO(sandersd): Remove once Blink requires the configurations parameter for | |
| 242 // requestMediaKeySystemAccess(). | |
| 243 if (configurations.isEmpty()) { | |
| 244 reporter->ReportSupported(); | |
| 245 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | |
| 246 request.keySystem(), blink::WebMediaKeySystemConfiguration(), | |
| 247 request.securityOrigin(), weak_factory_.GetWeakPtr())); | |
| 248 return; | |
| 249 } | |
| 250 | |
| 251 for (size_t i = 0; i < configurations.size(); i++) { | 398 for (size_t i = 0; i < configurations.size(); i++) { |
| 252 const blink::WebMediaKeySystemConfiguration& candidate = configurations[i]; | 399 // 7.3.1. Let candidate configuration be the value. |
| 400 const blink::WebMediaKeySystemConfiguration& candidate_configuration = | |
| 401 configurations[i]; | |
| 402 // 7.3.2. Let supported configuration be the result of executing the Get | |
| 403 // Supported Configuration algorithm on implementation, candidate | |
| 404 // configuration, and origin. | |
| 405 // 7.3.3. If supported configuration is not null, [initialize and return a | |
| 406 // new MediaKeySystemAccess object.] | |
| 253 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 407 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
| 254 if (GetSupportedConfiguration(key_system, candidate, | 408 if (GetSupportedConfiguration(key_system, candidate_configuration, |
| 255 request.securityOrigin(), | 409 request.securityOrigin(), |
| 256 &accumulated_configuration)) { | 410 &accumulated_configuration)) { |
| 257 reporter->ReportSupported(); | 411 reporter->ReportSupported(); |
| 258 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | 412 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
| 259 request.keySystem(), accumulated_configuration, | 413 request.keySystem(), accumulated_configuration, |
| 260 request.securityOrigin(), weak_factory_.GetWeakPtr())); | 414 request.securityOrigin(), weak_factory_.GetWeakPtr())); |
| 261 return; | 415 return; |
| 262 } | 416 } |
| 263 } | 417 } |
| 264 | 418 |
| 265 // 7.4 Reject promise with a new DOMException whose name is NotSupportedError. | 419 // 7.4. Reject promise with a new DOMException whose name is |
| 420 // NotSupportedError. | |
| 266 request.requestNotSupported( | 421 request.requestNotSupported( |
| 267 "None of the requested configurations were supported."); | 422 "None of the requested configurations were supported."); |
| 268 } | 423 } |
| 269 | 424 |
| 270 void WebEncryptedMediaClientImpl::CreateCdm( | 425 void WebEncryptedMediaClientImpl::CreateCdm( |
| 271 const blink::WebString& key_system, | 426 const blink::WebString& key_system, |
| 272 const blink::WebSecurityOrigin& security_origin, | 427 const blink::WebSecurityOrigin& security_origin, |
| 273 blink::WebContentDecryptionModuleResult result) { | 428 blink::WebContentDecryptionModuleResult result) { |
| 274 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), security_origin, | 429 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), security_origin, |
| 275 key_system, result); | 430 key_system, result); |
| 276 } | 431 } |
| 277 | 432 |
| 278 // Lazily create Reporters. | 433 // Lazily create Reporters. |
| 279 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( | 434 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( |
| 280 const std::string& key_system) { | 435 const std::string& key_system) { |
| 281 std::string uma_name = GetKeySystemNameForUMA(key_system); | 436 std::string uma_name = GetKeySystemNameForUMA(key_system); |
| 282 Reporter* reporter = reporters_.get(uma_name); | 437 Reporter* reporter = reporters_.get(uma_name); |
| 283 if (reporter != nullptr) | 438 if (reporter != nullptr) |
| 284 return reporter; | 439 return reporter; |
| 285 | 440 |
| 286 // Reporter not found, so create one. | 441 // Reporter not found, so create one. |
| 287 auto result = | 442 auto result = |
| 288 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 443 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
| 289 DCHECK(result.second); | 444 DCHECK(result.second); |
| 290 return result.first->second; | 445 return result.first->second; |
| 291 } | 446 } |
| 292 | 447 |
| 293 } // namespace media | 448 } // namespace media |
| OLD | NEW |