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. |
| 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 LOG(WARNING) << "Configuration rejected because rubustness strings are " |
| 97 << "not yet supported."; |
| 98 continue; |
| 99 } |
| 100 // 3.13. If the user agent and implementation do not support playback of |
| 101 // encrypted media data as specified by configuration, including all |
| 102 // media types, in combination with accumulated capabilities, |
| 103 // continue to the next iteration. |
| 104 // (Skipped as there are no configuration-based codec restrictions.) |
| 105 // 3.14. Add configuration to media type capabilities. |
| 106 media_type_capabilities->push_back(capability); |
| 107 // 3.15. Add configuration to accumulated capabilities. |
| 108 // (Skipped as there are no configuration-based codec restrictions.) |
| 109 } |
| 110 // 4. If media type capabilities is empty, return null. |
| 111 // 5. Return media type capabilities. |
| 112 return !media_type_capabilities->empty(); |
| 113 } |
| 114 |
| 115 static EmeFeatureRequirement ConvertRequirement( |
| 116 blink::WebMediaKeySystemConfiguration::Requirement requirement) { |
| 117 switch (requirement) { |
| 118 case blink::WebMediaKeySystemConfiguration::Requirement::Required: |
| 119 return EME_FEATURE_REQUIRED; |
| 120 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: |
| 121 return EME_FEATURE_OPTIONAL; |
| 122 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
| 123 return EME_FEATURE_NOT_ALLOWED; |
| 124 } |
| 125 |
| 126 NOTREACHED(); |
| 127 return EME_FEATURE_NOT_ALLOWED; |
50 } | 128 } |
51 | 129 |
52 static bool GetSupportedConfiguration( | 130 static bool GetSupportedConfiguration( |
53 const std::string& key_system, | 131 const std::string& key_system, |
54 const blink::WebMediaKeySystemConfiguration& candidate, | 132 const blink::WebMediaKeySystemConfiguration& candidate, |
55 const blink::WebSecurityOrigin& security_origin, | 133 const blink::WebSecurityOrigin& security_origin, |
56 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { | 134 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
| 135 // When determining support, assume that permission could be granted. |
| 136 // TODO(sandersd): Set to false if the permission is rejected. |
| 137 bool is_permission_possible = true; |
| 138 |
| 139 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
| 140 // 1. Let accumulated configuration be empty. (Done by caller.) |
| 141 // 2. If candidate configuration's initDataTypes attribute is not empty, run |
| 142 // the following steps: |
57 if (!candidate.initDataTypes.isEmpty()) { | 143 if (!candidate.initDataTypes.isEmpty()) { |
58 std::vector<blink::WebString> init_data_types; | 144 // 2.1. Let supported types be empty. |
| 145 std::vector<blink::WebString> supported_types; |
59 | 146 |
| 147 // 2.2. For each value in candidate configuration's initDataTypes attribute: |
60 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { | 148 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { |
| 149 // 2.2.1. Let initDataType be the value. |
61 const blink::WebString& init_data_type = candidate.initDataTypes[i]; | 150 const blink::WebString& init_data_type = candidate.initDataTypes[i]; |
| 151 // 2.2.2. If initDataType is the empty string, return null. |
62 if (init_data_type.isEmpty()) | 152 if (init_data_type.isEmpty()) |
63 return false; | 153 return false; |
| 154 // 2.2.3. If the implementation supports generating requests based on |
| 155 // initDataType, add initDataType to supported types. String |
| 156 // comparison is case-sensitive. |
64 if (base::IsStringASCII(init_data_type) && | 157 if (base::IsStringASCII(init_data_type) && |
65 IsSupportedKeySystemWithInitDataType( | 158 IsSupportedKeySystemWithInitDataType( |
66 key_system, base::UTF16ToASCII(init_data_type))) { | 159 key_system, base::UTF16ToASCII(init_data_type))) { |
67 init_data_types.push_back(init_data_type); | 160 supported_types.push_back(init_data_type); |
68 } | 161 } |
69 } | 162 } |
70 | 163 |
71 if (init_data_types.empty()) | 164 // 2.3. If supported types is empty, return null. |
| 165 if (supported_types.empty()) |
72 return false; | 166 return false; |
73 | 167 |
74 accumulated_configuration->initDataTypes = init_data_types; | 168 // 2.4. Add supported types to accumulated configuration. |
| 169 accumulated_configuration->initDataTypes = supported_types; |
75 } | 170 } |
76 | 171 |
77 // TODO(sandersd): Implement distinctiveIdentifier and persistentState checks. | 172 // 3. Follow the steps for the value of candidate configuration's |
78 if (candidate.distinctiveIdentifier != | 173 // distinctiveIdentifier attribute from the following list: |
79 blink::WebMediaKeySystemConfiguration::Requirement::Optional || | 174 // - "required": If the implementation does not support a persistent |
80 candidate.persistentState != | 175 // Distinctive Identifier in combination with accumulated configuration, |
81 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 176 // return null. |
| 177 // - "optional": Continue. |
| 178 // - "not-allowed": If the implementation requires a Distinctive |
| 179 // Identifier in combination with accumulated configuration, return |
| 180 // null. |
| 181 EmeFeatureRequirement di_requirement = |
| 182 ConvertRequirement(candidate.distinctiveIdentifier); |
| 183 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, |
| 184 is_permission_possible)) { |
82 return false; | 185 return false; |
83 } | 186 } |
84 | 187 |
85 if (!candidate.audioCapabilities.isEmpty()) { | 188 // 4. Add the value of the candidate configuration's distinctiveIdentifier |
86 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | 189 // attribute to accumulated configuration. |
| 190 accumulated_configuration->distinctiveIdentifier = |
| 191 candidate.distinctiveIdentifier; |
87 | 192 |
88 for (size_t i = 0; i < candidate.audioCapabilities.size(); i++) { | 193 // 5. Follow the steps for the value of candidate configuration's |
89 const blink::WebMediaKeySystemMediaCapability& capabilities = | 194 // persistentState attribute from the following list: |
90 candidate.audioCapabilities[i]; | 195 // - "required": If the implementation does not support persisting state |
91 if (capabilities.mimeType.isEmpty()) | 196 // in combination with accumulated configuration, return null. |
92 return false; | 197 // - "optional": Continue. |
93 if (!base::IsStringASCII(capabilities.mimeType) || | 198 // - "not-allowed": If the implementation requires persisting state in |
94 !base::IsStringASCII(capabilities.codecs) || | 199 // combination with accumulated configuration, return null. |
95 !IsSupportedContentType( | 200 EmeFeatureRequirement ps_requirement = |
96 key_system, base::UTF16ToASCII(capabilities.mimeType), | 201 ConvertRequirement(candidate.persistentState); |
97 base::UTF16ToASCII(capabilities.codecs))) { | 202 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, |
98 continue; | 203 is_permission_possible)) { |
99 } | 204 return false; |
100 // TODO(sandersd): Support robustness. | 205 } |
101 if (!capabilities.robustness.isEmpty()) | 206 |
102 continue; | 207 // 6. Add the value of the candidate configuration's persistentState |
103 audio_capabilities.push_back(capabilities); | 208 // attribute to accumulated configuration. |
| 209 accumulated_configuration->persistentState = candidate.persistentState; |
| 210 |
| 211 // 7. If candidate configuration's videoCapabilities attribute is not empty, |
| 212 // run the following steps: |
| 213 if (!candidate.videoCapabilities.isEmpty()) { |
| 214 // 7.1. Let video capabilities be the result of executing the Get Supported |
| 215 // Capabilities for Media Type algorithm on Video, candidate |
| 216 // configuration's videoCapabilities attribute, and accumulated |
| 217 // configuration. |
| 218 // 7.2. If video capabilities is null, return null. |
| 219 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; |
| 220 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, |
| 221 &video_capabilities)) { |
| 222 return false; |
104 } | 223 } |
105 | 224 |
106 if (audio_capabilities.empty()) | 225 // 7.3. Add video capabilities to accumulated configuration. |
| 226 accumulated_configuration->videoCapabilities = video_capabilities; |
| 227 } |
| 228 |
| 229 // 8. If candidate configuration's audioCapabilities attribute is not empty, |
| 230 // run the following steps: |
| 231 if (!candidate.audioCapabilities.isEmpty()) { |
| 232 // 8.1. Let audio capabilities be the result of executing the Get Supported |
| 233 // Capabilities for Media Type algorithm on Audio, candidate |
| 234 // configuration's audioCapabilities attribute, and accumulated |
| 235 // configuration. |
| 236 // 8.2. If audio capabilities is null, return null. |
| 237 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
| 238 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, |
| 239 &audio_capabilities)) { |
107 return false; | 240 return false; |
| 241 } |
108 | 242 |
| 243 // 8.3. Add audio capabilities to accumulated configuration. |
109 accumulated_configuration->audioCapabilities = audio_capabilities; | 244 accumulated_configuration->audioCapabilities = audio_capabilities; |
110 } | 245 } |
111 | 246 |
112 if (!candidate.videoCapabilities.isEmpty()) { | 247 // 9. If accumulated configuration's distinctiveIdentifier value is |
113 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | 248 // "optional", follow the steps for the first matching condition from the |
114 | 249 // following list: |
115 for (size_t i = 0; i < candidate.videoCapabilities.size(); i++) { | 250 // - If the implementation requires a Distinctive Identifier for any of |
116 const blink::WebMediaKeySystemMediaCapability& capabilities = | 251 // the combinations in accumulated configuration, change accumulated |
117 candidate.videoCapabilities[i]; | 252 // configuration's distinctiveIdentifier value to "required". |
118 if (capabilities.mimeType.isEmpty()) | 253 // - Otherwise, change accumulated configuration's distinctiveIdentifier |
119 return false; | 254 // value to "not-allowed". |
120 if (!base::IsStringASCII(capabilities.mimeType) || | 255 // (Without robustness support, capabilities do not affect this.) |
121 !base::IsStringASCII(capabilities.codecs) || | 256 // TODO(sandersd): Implement robustness. http://crbug.com/442586 |
122 !IsSupportedContentType( | 257 if (accumulated_configuration->distinctiveIdentifier == |
123 key_system, base::UTF16ToASCII(capabilities.mimeType), | 258 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
124 base::UTF16ToASCII(capabilities.codecs))) { | 259 if (IsDistinctiveIdentifierRequirementSupported(key_system, |
125 continue; | 260 EME_FEATURE_NOT_ALLOWED, |
126 } | 261 is_permission_possible)) { |
127 // TODO(sandersd): Support robustness. | 262 accumulated_configuration->distinctiveIdentifier = |
128 if (!capabilities.robustness.isEmpty()) | 263 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
129 continue; | 264 } else { |
130 video_capabilities.push_back(capabilities); | 265 accumulated_configuration->distinctiveIdentifier = |
| 266 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
131 } | 267 } |
132 | |
133 if (video_capabilities.empty()) | |
134 return false; | |
135 | |
136 accumulated_configuration->videoCapabilities = video_capabilities; | |
137 } | 268 } |
138 | 269 |
139 // TODO(sandersd): Prompt for distinctive identifiers and/or persistent state | 270 // 10. If accumulated configuration's persistentState value is "optional", |
140 // if required. Make sure that future checks are silent. | 271 // follow the steps for the first matching condition from the following |
141 // http://crbug.com/446263. | 272 // list: |
| 273 // - If the implementation requires persisting state for any of the |
| 274 // combinations in accumulated configuration, change accumulated |
| 275 // configuration's persistentState value to "required". |
| 276 // - Otherwise, change accumulated configuration's persistentState value |
| 277 // to "not-allowed". |
| 278 if (accumulated_configuration->persistentState == |
| 279 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| 280 if (IsPersistentStateRequirementSupported(key_system, |
| 281 EME_FEATURE_NOT_ALLOWED, |
| 282 is_permission_possible)) { |
| 283 accumulated_configuration->persistentState = |
| 284 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
| 285 } else { |
| 286 accumulated_configuration->persistentState = |
| 287 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 288 } |
| 289 } |
| 290 |
| 291 // 11. If implementation in the configuration specified by the combination of |
| 292 // the values in accumulated configuration is not supported or not allowed |
| 293 // in the origin, return null. |
| 294 // TODO(sandersd): Implement prompting. http://crbug.com/446263 |
| 295 // For now, assume that the permission was not granted. |
| 296 di_requirement = |
| 297 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); |
| 298 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, |
| 299 false)) { |
| 300 return false; |
| 301 } |
| 302 |
| 303 ps_requirement = |
| 304 ConvertRequirement(accumulated_configuration->persistentState); |
| 305 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, false)) |
| 306 return false; |
| 307 |
| 308 // 12. Return accumulated configuration. |
| 309 // (As an extra step, we record the available session types so that |
| 310 // createSession() can be synchronous.) |
| 311 std::vector<blink::WebString> session_types; |
| 312 session_types.push_back(kTemporarySessionType); |
| 313 if (accumulated_configuration->persistentState == |
| 314 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
| 315 if (IsPersistentLicenseSessionSupported(key_system, false)) |
| 316 session_types.push_back(kPersistentLicenseSessionType); |
| 317 if (IsPersistentReleaseMessageSessionSupported(key_system, false)) |
| 318 session_types.push_back(kPersistentReleaseMessageSessionType); |
| 319 } |
| 320 accumulated_configuration->sessionTypes = session_types; |
142 | 321 |
143 return true; | 322 return true; |
144 } | 323 } |
145 | 324 |
146 // Report usage of key system to UMA. There are 2 different counts logged: | 325 // Report usage of key system to UMA. There are 2 different counts logged: |
147 // 1. The key system is requested. | 326 // 1. The key system is requested. |
148 // 2. The requested key system and options are supported. | 327 // 2. The requested key system and options are supported. |
149 // Each stat is only reported once per renderer frame per key system. | 328 // Each stat is only reported once per renderer frame per key system. |
150 // Note that WebEncryptedMediaClientImpl is only created once by each | 329 // Note that WebEncryptedMediaClientImpl is only created once by each |
151 // renderer frame. | 330 // renderer frame. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { | 384 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { |
206 } | 385 } |
207 | 386 |
208 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( | 387 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
209 blink::WebEncryptedMediaRequest request) { | 388 blink::WebEncryptedMediaRequest request) { |
210 // TODO(jrummell): This should be asynchronous. | 389 // TODO(jrummell): This should be asynchronous. |
211 | 390 |
212 // Continued from requestMediaKeySystemAccess(), step 7, from | 391 // Continued from requestMediaKeySystemAccess(), step 7, from |
213 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | 392 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
214 // | 393 // |
215 // 7.1 If keySystem is not one of the Key Systems supported by the user | 394 // 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 | 395 // agent, reject promise with with a new DOMException whose name is |
217 // NotSupportedError. String comparison is case-sensitive. | 396 // NotSupportedError. String comparison is case-sensitive. |
218 if (!base::IsStringASCII(request.keySystem())) { | 397 if (!base::IsStringASCII(request.keySystem())) { |
219 request.requestNotSupported("Only ASCII keySystems are supported"); | 398 request.requestNotSupported("Only ASCII keySystems are supported"); |
220 return; | 399 return; |
221 } | 400 } |
222 | 401 |
223 std::string key_system = base::UTF16ToASCII(request.keySystem()); | 402 std::string key_system = base::UTF16ToASCII(request.keySystem()); |
224 | 403 |
225 // Report this request to the appropriate Reporter. | 404 // Report this request to the appropriate Reporter. |
226 Reporter* reporter = GetReporter(key_system); | 405 Reporter* reporter = GetReporter(key_system); |
227 reporter->ReportRequested(); | 406 reporter->ReportRequested(); |
228 | 407 |
229 if (!IsSupportedKeySystem(key_system)) { | 408 if (!IsSupportedKeySystem(key_system)) { |
230 request.requestNotSupported("Unsupported keySystem"); | 409 request.requestNotSupported("Unsupported keySystem"); |
231 return; | 410 return; |
232 } | 411 } |
233 | 412 |
234 // 7.2 Let implementation be the implementation of keySystem. | 413 // 7.2. Let implementation be the implementation of keySystem. |
235 // 7.3 For each value in supportedConfigurations, run the GetSupported | 414 // 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>& | 415 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& |
239 configurations = request.supportedConfigurations(); | 416 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++) { | 417 for (size_t i = 0; i < configurations.size(); i++) { |
252 const blink::WebMediaKeySystemConfiguration& candidate = configurations[i]; | 418 // 7.3.1. Let candidate configuration be the value. |
| 419 const blink::WebMediaKeySystemConfiguration& candidate_configuration = |
| 420 configurations[i]; |
| 421 // 7.3.2. Let supported configuration be the result of executing the Get |
| 422 // Supported Configuration algorithm on implementation, candidate |
| 423 // configuration, and origin. |
| 424 // 7.3.3. If supported configuration is not null, [initialize and return a |
| 425 // new MediaKeySystemAccess object.] |
253 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 426 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
254 if (GetSupportedConfiguration(key_system, candidate, | 427 if (GetSupportedConfiguration(key_system, candidate_configuration, |
255 request.securityOrigin(), | 428 request.securityOrigin(), |
256 &accumulated_configuration)) { | 429 &accumulated_configuration)) { |
257 reporter->ReportSupported(); | 430 reporter->ReportSupported(); |
258 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | 431 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
259 request.keySystem(), accumulated_configuration, | 432 request.keySystem(), accumulated_configuration, |
260 request.securityOrigin(), weak_factory_.GetWeakPtr())); | 433 request.securityOrigin(), weak_factory_.GetWeakPtr())); |
261 return; | 434 return; |
262 } | 435 } |
263 } | 436 } |
264 | 437 |
265 // 7.4 Reject promise with a new DOMException whose name is NotSupportedError. | 438 // 7.4. Reject promise with a new DOMException whose name is |
| 439 // NotSupportedError. |
266 request.requestNotSupported( | 440 request.requestNotSupported( |
267 "None of the requested configurations were supported."); | 441 "None of the requested configurations were supported."); |
268 } | 442 } |
269 | 443 |
270 void WebEncryptedMediaClientImpl::CreateCdm( | 444 void WebEncryptedMediaClientImpl::CreateCdm( |
271 const blink::WebString& key_system, | 445 const blink::WebString& key_system, |
272 const blink::WebSecurityOrigin& security_origin, | 446 const blink::WebSecurityOrigin& security_origin, |
273 blink::WebContentDecryptionModuleResult result) { | 447 blink::WebContentDecryptionModuleResult result) { |
274 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), security_origin, | 448 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), security_origin, |
275 key_system, result); | 449 key_system, result); |
276 } | 450 } |
277 | 451 |
278 // Lazily create Reporters. | 452 // Lazily create Reporters. |
279 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( | 453 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( |
280 const std::string& key_system) { | 454 const std::string& key_system) { |
281 std::string uma_name = GetKeySystemNameForUMA(key_system); | 455 std::string uma_name = GetKeySystemNameForUMA(key_system); |
282 Reporter* reporter = reporters_.get(uma_name); | 456 Reporter* reporter = reporters_.get(uma_name); |
283 if (reporter != nullptr) | 457 if (reporter != nullptr) |
284 return reporter; | 458 return reporter; |
285 | 459 |
286 // Reporter not found, so create one. | 460 // Reporter not found, so create one. |
287 auto result = | 461 auto result = |
288 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 462 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
289 DCHECK(result.second); | 463 DCHECK(result.second); |
290 return result.first->second; | 464 return result.first->second; |
291 } | 465 } |
292 | 466 |
293 } // namespace media | 467 } // namespace media |
OLD | NEW |