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 "net/base/mime_util.h" | 13 #include "net/base/mime_util.h" |
14 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" | 14 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" |
15 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" | 15 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" |
16 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
17 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
18 #include "webcontentdecryptionmodule_impl.h" | 18 #include "webcontentdecryptionmodule_impl.h" |
19 #include "webcontentdecryptionmoduleaccess_impl.h" | 19 #include "webcontentdecryptionmoduleaccess_impl.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.) | |
jrummell
2015/02/14 01:28:35
Can you add an ASSERT(media_type_capabilities.size
sandersd (OOO until July 31)
2015/02/18 23:41:18
Done.
| |
75 // 3. For each value in capabilities: | |
76 for (size_t i = 0; i < capabilities.size(); i++) { | |
77 // 3.1. Let contentType be the value's contentType member. | |
78 // 3.2. Let robustness be the value's robustness member. | |
79 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; | |
80 // 3.3. If contentType is the empty string, return null. | |
81 if (capability.mimeType.isEmpty()) | |
82 return false; | |
83 // 3.4-3.11. (Implemented by IsSupportedContentType().) | |
84 if (!base::IsStringASCII(capability.mimeType) || | |
85 !base::IsStringASCII(capability.codecs) || | |
86 !IsSupportedContentType(key_system, | |
87 base::UTF16ToASCII(capability.mimeType), | |
88 base::UTF16ToASCII(capability.codecs))) { | |
89 continue; | |
90 } | |
91 // 3.12. If robustness is not the empty string, run the following steps: | |
92 // (Robustness is not supported.) | |
93 if (!capability.robustness.isEmpty()) | |
94 continue; | |
95 // 3.13. If the user agent and implementation do not support playback of | |
96 // encrypted media data as specified by configuration, including all | |
97 // media types, in combination with accumulated capabilities, | |
98 // continue to the next iteration. | |
99 // (Skipped as there are no configuration-based codec restrictions.) | |
100 // 3.14. Add configuration to media type capabilities. | |
101 media_type_capabilities->push_back(capability); | |
102 // 3.15. Add configuration to accumulated capabilities. | |
103 // (Skipped as there are no configuration-based codec restrictions.) | |
104 } | |
105 // 4. If media type capabilities is empty, return null. | |
106 // 5. Return media type capabilities. | |
107 return !media_type_capabilities->empty(); | |
108 } | |
109 | |
110 static EmeRequirement ConvertToEmeRequirement( | |
111 blink::WebMediaKeySystemConfiguration::Requirement requirement) { | |
112 switch (requirement) { | |
113 case blink::WebMediaKeySystemConfiguration::Requirement::Required: | |
114 return EME_REQUIREMENT_REQUIRED; | |
115 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: | |
116 return EME_REQUIREMENT_OPTIONAL; | |
117 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | |
118 return EME_REQUIREMENT_NOT_ALLOWED; | |
119 } | |
120 | |
121 NOTREACHED(); | |
ddorwin
2015/02/17 22:34:58
Can we get away with no code in this "branch" sinc
sandersd (OOO until July 31)
2015/02/18 23:41:18
MSVC has complained at me before with other simila
| |
122 return EME_REQUIREMENT_NOT_ALLOWED; | |
50 } | 123 } |
51 | 124 |
52 static bool GetSupportedConfiguration( | 125 static bool GetSupportedConfiguration( |
53 const std::string& key_system, | 126 const std::string& key_system, |
54 const blink::WebMediaKeySystemConfiguration& candidate, | 127 const blink::WebMediaKeySystemConfiguration& candidate, |
55 const blink::WebSecurityOrigin& security_origin, | 128 const blink::WebSecurityOrigin& security_origin, |
56 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { | 129 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
130 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | |
131 // 1. Let accumulated configuration be empty. (Done by caller.) | |
132 // 2. If candidate configuration's initDataTypes attribute is not empty, run | |
133 // the following steps: | |
57 if (!candidate.initDataTypes.isEmpty()) { | 134 if (!candidate.initDataTypes.isEmpty()) { |
58 std::vector<blink::WebString> init_data_types; | 135 // 2.1. Let supported types be empty. |
136 std::vector<blink::WebString> supported_types; | |
59 | 137 |
138 // 2.2. For each value in candidate configuration's initDataTypes attribute: | |
60 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { | 139 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { |
140 // 2.2.1. Let initDataType be the value. | |
61 const blink::WebString& init_data_type = candidate.initDataTypes[i]; | 141 const blink::WebString& init_data_type = candidate.initDataTypes[i]; |
142 // 2.2.2. If initDataType is the empty string, return null. | |
62 if (init_data_type.isEmpty()) | 143 if (init_data_type.isEmpty()) |
63 return false; | 144 return false; |
145 // 2.2.3. If the implementation supports generating requests based on | |
146 // initDataType, add initDataType to supported types. String | |
147 // comparison is case-sensitive. | |
64 if (base::IsStringASCII(init_data_type) && | 148 if (base::IsStringASCII(init_data_type) && |
65 IsSupportedKeySystemWithInitDataType( | 149 IsSupportedKeySystemWithInitDataType( |
66 key_system, base::UTF16ToASCII(init_data_type))) { | 150 key_system, base::UTF16ToASCII(init_data_type))) { |
67 init_data_types.push_back(init_data_type); | 151 supported_types.push_back(init_data_type); |
68 } | 152 } |
69 } | 153 } |
70 | 154 |
71 if (init_data_types.empty()) | 155 // 2.3. If supported types is empty, return null. |
156 if (supported_types.empty()) | |
72 return false; | 157 return false; |
73 | 158 |
74 accumulated_configuration->initDataTypes = init_data_types; | 159 // 2.4. Add supported types to accumulated configuration. |
160 accumulated_configuration->initDataTypes = supported_types; | |
75 } | 161 } |
76 | 162 |
77 // TODO(sandersd): Implement distinctiveIdentifier and persistentState checks. | 163 // 3. Follow the steps for the value of candidate configuration's |
78 if (candidate.distinctiveIdentifier != | 164 // distinctiveIdentifier attribute from the following list: |
79 blink::WebMediaKeySystemConfiguration::Requirement::Optional || | 165 // - "required": If the implementation does not support a persistent |
80 candidate.persistentState != | 166 // Distinctive Identifier in combination with accumulated configuration, |
167 // return null. | |
168 // - "optional": Continue. | |
169 // - "not-allowed": If the implementation requires a Distinctive | |
170 // Identifier in combination with accumulated configuration, return | |
171 // null. | |
172 EmeRequirement requirement; | |
173 requirement = ConvertToEmeRequirement(candidate.distinctiveIdentifier); | |
ddorwin
2015/02/17 22:34:58
collapse to one statement.
Alternatively, can this
sandersd (OOO until July 31)
2015/02/18 23:41:18
This seems to be the cleanest way, everything else
| |
174 if (!IsSupportedDistinctiveIdentifierRequirement(key_system, requirement)) | |
175 return false; | |
176 | |
177 // 4. Add the value of the candidate configuration's distinctiveIdentifier | |
178 // attribute to accumulated configuration. | |
179 accumulated_configuration->distinctiveIdentifier = | |
180 candidate.distinctiveIdentifier; | |
181 | |
182 // 5. Follow the steps for the value of candidate configuration's | |
183 // persistentState attribute from the following list: | |
184 // - "required": If the implementation does not support persisting state | |
185 // in combination with accumulated configuration, return null. | |
186 // - "optional": Continue. | |
187 // - "not-allowed": If the implementation requires persisting state in | |
188 // combination with accumulated configuration, return null. | |
189 requirement = ConvertToEmeRequirement(candidate.persistentState); | |
190 if (!IsSupportedPersistentStateRequirement(key_system, requirement)) | |
191 return false; | |
192 | |
193 // 6. Add the value of the candidate configuration's persistentState | |
194 // attribute to accumulated configuration. | |
195 accumulated_configuration->persistentState = candidate.persistentState; | |
196 | |
197 // 7. If candidate configuration's videoCapabilities attribute is not empty, | |
198 // run the following steps: | |
199 if (!candidate.videoCapabilities.isEmpty()) { | |
200 // 7.1. Let video capabilities be the result of executing the Get Supported | |
201 // Capabilities for Media Type algorithm on Video, candidate | |
202 // configuration's videoCapabilities attribute, and accumulated | |
203 // configuration. | |
204 // 7.2. If video capabilities is null, return null. | |
205 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | |
206 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, | |
207 &video_capabilities)) { | |
208 return false; | |
209 } | |
210 | |
211 // 7.3. Add video capabilities to accumulated configuration. | |
212 accumulated_configuration->videoCapabilities = video_capabilities; | |
213 } | |
214 | |
215 // 8. If candidate configuration's audioCapabilities attribute is not empty, | |
216 // run the following steps: | |
217 if (!candidate.audioCapabilities.isEmpty()) { | |
218 // 8.1. Let audio capabilities be the result of executing the Get Supported | |
219 // Capabilities for Media Type algorithm on Video, candidate | |
ddorwin
2015/02/17 22:34:58
Audio
sandersd (OOO until July 31)
2015/02/18 23:41:18
Done.
| |
220 // configuration's audioCapabilities attribute, and accumulated | |
221 // configuration. | |
222 // 8.2. If audio capabilities is null, return null. | |
223 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | |
224 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, | |
225 &audio_capabilities)) { | |
226 return false; | |
227 } | |
228 | |
229 // 8.3. Add video capabilities to accumulated configuration. | |
ddorwin
2015/02/17 22:34:58
audio
sandersd (OOO until July 31)
2015/02/18 23:41:18
Done.
| |
230 accumulated_configuration->videoCapabilities = audio_capabilities; | |
jrummell
2015/02/14 01:28:35
video = audio?
sandersd (OOO until July 31)
2015/02/18 23:41:18
Done.
| |
231 } | |
232 | |
233 // 9. If accumulated configuration's distinctiveIdentifier value is | |
234 // "optional", follow the steps for the first matching condition from the | |
235 // following list: | |
236 // - If the implementation requires a Distinctive Identifier for any of | |
237 // the combinations in accumulated configuration, change accumulated | |
238 // configuration's distinctiveIdentifier value to "required". | |
239 // - Otherwise, change accumulated configuration's distinctiveIdentifier | |
240 // value to "not-allowed". | |
241 // (Without robustness support, capabilities do not affect this.) | |
ddorwin
2015/02/17 22:34:58
TODO with bug?
sandersd (OOO until July 31)
2015/02/18 23:41:18
Done.
| |
242 if (accumulated_configuration->distinctiveIdentifier == | |
81 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 243 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
244 if (!IsSupportedDistinctiveIdentifierRequirement( | |
245 key_system, EME_REQUIREMENT_NOT_ALLOWED)) { | |
246 accumulated_configuration->distinctiveIdentifier = | |
247 blink::WebMediaKeySystemConfiguration::Requirement::Required; | |
248 } else { | |
249 accumulated_configuration->distinctiveIdentifier = | |
250 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
251 } | |
252 } | |
253 | |
254 // 10. If accumulated configuration's persistentState value is "optional", | |
255 // follow the steps for the first matching condition from the following | |
256 // list: | |
257 // - If the implementation requires persisting state for any of the | |
258 // combinations in accumulated configuration, change accumulated | |
259 // configuration's persistentState value to "required". | |
260 // - Otherwise, change accumulated configuration's persistentState value | |
261 // to "not-allowed". | |
262 if (accumulated_configuration->persistentState == | |
263 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | |
264 if (!IsSupportedPersistentStateRequirement( | |
265 key_system, EME_REQUIREMENT_NOT_ALLOWED)) { | |
266 accumulated_configuration->persistentState = | |
267 blink::WebMediaKeySystemConfiguration::Requirement::Required; | |
268 } else { | |
269 accumulated_configuration->persistentState = | |
270 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
271 } | |
272 } | |
273 | |
274 // 11. If implementation in the configuration specified by the combination of | |
275 // the values in accumulated configuration is not supported or not allowed | |
276 // in the origin, return null. | |
277 // TODO(sandersd): Implement prompting. http://crbug.com/446263 | |
278 if (accumulated_configuration->distinctiveIdentifier == | |
279 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | |
82 return false; | 280 return false; |
83 } | 281 } |
84 | 282 |
85 if (!candidate.audioCapabilities.isEmpty()) { | 283 // 12. Return accumulated configuration. |
86 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | 284 // (As an extra step, we record the available session types so that |
87 | 285 // createSession() can be synchronous.) |
88 for (size_t i = 0; i < candidate.audioCapabilities.size(); i++) { | 286 std::vector<blink::WebString> session_types; |
89 const blink::WebMediaKeySystemMediaCapability& capabilities = | 287 if (IsSupportedSessionType(key_system, EME_SESSION_TYPE_TEMPORARY)) { |
ddorwin
2015/02/17 22:34:58
Per the spec, this can be a DCHECK
sandersd (OOO until July 31)
2015/02/18 23:41:18
Acknowledged.
| |
90 candidate.audioCapabilities[i]; | 288 session_types.push_back(kTemporarySessionType); |
91 if (capabilities.mimeType.isEmpty()) | 289 } |
92 return false; | 290 if (accumulated_configuration->persistentState == |
93 if (!base::IsStringASCII(capabilities.mimeType) || | 291 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
94 !base::IsStringASCII(capabilities.codecs) || | 292 if (IsSupportedSessionType( |
95 !IsSupportedContentType( | 293 key_system, EME_SESSION_TYPE_PERSISTENT_LICENSE)) { |
96 key_system, base::UTF16ToASCII(capabilities.mimeType), | 294 session_types.push_back(kPersistentLicenseSessionType); |
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 } | 295 } |
105 | 296 if (IsSupportedSessionType( |
106 if (audio_capabilities.empty()) | 297 key_system, EME_SESSION_TYPE_PERSISTENT_RELEASE_MESSAGE)) { |
107 return false; | 298 session_types.push_back(kPersistentReleaseMessageSessionType); |
108 | 299 } |
109 accumulated_configuration->audioCapabilities = audio_capabilities; | |
110 } | 300 } |
111 | 301 accumulated_configuration->sessionTypes = session_types; |
112 if (!candidate.videoCapabilities.isEmpty()) { | |
113 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | |
114 | |
115 for (size_t i = 0; i < candidate.videoCapabilities.size(); i++) { | |
116 const blink::WebMediaKeySystemMediaCapability& capabilities = | |
117 candidate.videoCapabilities[i]; | |
118 if (capabilities.mimeType.isEmpty()) | |
119 return false; | |
120 if (!base::IsStringASCII(capabilities.mimeType) || | |
121 !base::IsStringASCII(capabilities.codecs) || | |
122 !IsSupportedContentType( | |
123 key_system, base::UTF16ToASCII(capabilities.mimeType), | |
124 base::UTF16ToASCII(capabilities.codecs))) { | |
125 continue; | |
126 } | |
127 // TODO(sandersd): Support robustness. | |
128 if (!capabilities.robustness.isEmpty()) | |
129 continue; | |
130 video_capabilities.push_back(capabilities); | |
131 } | |
132 | |
133 if (video_capabilities.empty()) | |
134 return false; | |
135 | |
136 accumulated_configuration->videoCapabilities = video_capabilities; | |
137 } | |
138 | |
139 // TODO(sandersd): Prompt for distinctive identifiers and/or persistent state | |
140 // if required. Make sure that future checks are silent. | |
141 // http://crbug.com/446263. | |
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 (!IsConcreteSupportedKeySystem(key_system)) { | 389 if (!IsConcreteSupportedKeySystem(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, run the Get Supported |
236 // Configuration algorithm and if successful, resolve promise with access | 396 // Configuration algorithm and if successful, resolve promise with access |
237 // and abort these steps. | 397 // and abort these steps. |
398 // 7.3. For each value in supportedConfigurations: | |
jrummell
2015/02/14 01:28:35
Two 7.3 comments, remove one.
sandersd (OOO until July 31)
2015/02/18 23:41:18
Done.
| |
238 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& | 399 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& |
239 configurations = request.supportedConfigurations(); | 400 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++) { | 401 for (size_t i = 0; i < configurations.size(); i++) { |
252 const blink::WebMediaKeySystemConfiguration& candidate = configurations[i]; | 402 // 7.3.1. Let candidate configuration be the value. |
403 const blink::WebMediaKeySystemConfiguration& candidate_configuration = | |
404 configurations[i]; | |
405 // 7.3.2. Let supported configuration be the result of executing the Get | |
406 // Supported Configuration algorithm on implementation, candidate | |
407 // configuration, and origin. | |
253 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 408 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
254 if (GetSupportedConfiguration(key_system, candidate, | 409 if (GetSupportedConfiguration(key_system, candidate_configuration, |
255 request.securityOrigin(), | 410 request.securityOrigin(), |
256 &accumulated_configuration)) { | 411 &accumulated_configuration)) { |
412 // 7.3.3. If supported configuration is not null, [initialize and return | |
ddorwin
2015/02/17 22:34:58
nit: This should be above 409, right?
sandersd (OOO until July 31)
2015/02/18 23:41:18
Done.
| |
413 // a new MediaKeySystemAccess object.] | |
257 reporter->ReportSupported(); | 414 reporter->ReportSupported(); |
258 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | 415 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
259 request.keySystem(), accumulated_configuration, | 416 request.keySystem(), accumulated_configuration, |
260 request.securityOrigin(), weak_factory_.GetWeakPtr())); | 417 request.securityOrigin(), weak_factory_.GetWeakPtr())); |
261 return; | 418 return; |
262 } | 419 } |
263 } | 420 } |
264 | 421 |
265 // 7.4 Reject promise with a new DOMException whose name is NotSupportedError. | 422 // 7.4. Reject promise with a new DOMException whose name is |
423 // NotSupportedError. | |
266 request.requestNotSupported( | 424 request.requestNotSupported( |
267 "None of the requested configurations were supported."); | 425 "None of the requested configurations were supported."); |
268 } | 426 } |
269 | 427 |
270 void WebEncryptedMediaClientImpl::CreateCdm( | 428 void WebEncryptedMediaClientImpl::CreateCdm( |
271 const blink::WebString& key_system, | 429 const blink::WebString& key_system, |
272 const blink::WebSecurityOrigin& security_origin, | 430 const blink::WebSecurityOrigin& security_origin, |
273 blink::WebContentDecryptionModuleResult result) { | 431 blink::WebContentDecryptionModuleResult result) { |
274 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), security_origin, | 432 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), security_origin, |
275 key_system, result); | 433 key_system, result); |
276 } | 434 } |
277 | 435 |
278 // Lazily create Reporters. | 436 // Lazily create Reporters. |
279 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( | 437 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( |
280 const std::string& key_system) { | 438 const std::string& key_system) { |
281 std::string uma_name = GetKeySystemNameForUMA(key_system); | 439 std::string uma_name = GetKeySystemNameForUMA(key_system); |
282 Reporter* reporter = reporters_.get(uma_name); | 440 Reporter* reporter = reporters_.get(uma_name); |
283 if (reporter != nullptr) | 441 if (reporter != nullptr) |
284 return reporter; | 442 return reporter; |
285 | 443 |
286 // Reporter not found, so create one. | 444 // Reporter not found, so create one. |
287 auto result = | 445 auto result = |
288 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 446 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
289 DCHECK(result.second); | 447 DCHECK(result.second); |
290 return result.first->second; | 448 return result.first->second; |
291 } | 449 } |
292 | 450 |
293 } // namespace media | 451 } // namespace media |
OLD | NEW |