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

Side by Side Diff: media/blink/key_system_config_selector.cc

Issue 1052273004: Extract requestMediaKeySystemAccess() algorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 // 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 "key_system_config_selector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
12 #include "media/base/key_systems.h" 11 #include "media/base/key_systems.h"
13 #include "media/base/media_permission.h" 12 #include "media/base/media_permission.h"
14 #include "media/blink/webcontentdecryptionmodule_impl.h"
15 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h"
16 #include "media/blink/webmediaplayer_util.h" 13 #include "media/blink/webmediaplayer_util.h"
17 #include "net/base/mime_util.h" 14 #include "net/base/mime_util.h"
18 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h"
19 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" 15 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h"
16 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
20 #include "third_party/WebKit/public/platform/WebString.h" 17 #include "third_party/WebKit/public/platform/WebString.h"
21 #include "third_party/WebKit/public/platform/WebVector.h" 18 #include "third_party/WebKit/public/platform/WebVector.h"
19 #include "url/gurl.h"
22 20
23 namespace media { 21 namespace media {
24 22
25 // These names are used by UMA. 23 namespace {
26 const char kKeySystemSupportUMAPrefix[] =
27 "Media.EME.RequestMediaKeySystemAccess.";
28 24
29 enum ConfigurationSupport { 25 static EmeFeatureRequirement ConvertRequirement(
30 CONFIGURATION_NOT_SUPPORTED, 26 blink::WebMediaKeySystemConfiguration::Requirement requirement) {
31 CONFIGURATION_REQUIRES_PERMISSION, 27 switch (requirement) {
32 CONFIGURATION_SUPPORTED, 28 case blink::WebMediaKeySystemConfiguration::Requirement::Required:
29 return EME_FEATURE_REQUIRED;
30 case blink::WebMediaKeySystemConfiguration::Requirement::Optional:
31 return EME_FEATURE_OPTIONAL;
32 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed:
33 return EME_FEATURE_NOT_ALLOWED;
34 }
35
36 NOTREACHED();
37 return EME_FEATURE_NOT_ALLOWED;
38 }
39
40 } // namespace
41
42 struct KeySystemConfigSelector::SelectionRequest {
43 std::string key_system;
44 blink::WebVector<blink::WebMediaKeySystemConfiguration>
45 candidate_configurations;
46 blink::WebSecurityOrigin security_origin;
47 base::Callback<void(const blink::WebMediaKeySystemConfiguration&)>
48 succeeded_cb;
49 base::Callback<void(const blink::WebString&)> not_supported_cb;
50 bool was_permission_requested = false;
51 bool is_permission_granted = false;
33 }; 52 };
34 53
35 // Accumulates configuration rules to determine if a feature (additional 54 // Accumulates configuration rules to determine if a feature (additional
36 // configuration rule) can be added to an accumulated configuration. 55 // configuration rule) can be added to an accumulated configuration.
37 class ConfigState { 56 class KeySystemConfigSelector::ConfigState {
38 public: 57 public:
39 ConfigState(bool was_permission_requested, bool is_permission_granted) 58 ConfigState(const SelectionRequest* request)
40 : was_permission_requested_(was_permission_requested), 59 : was_permission_requested_(request->was_permission_requested),
41 is_permission_granted_(is_permission_granted) { 60 is_permission_granted_(request->is_permission_granted) {
42 } 61 }
43 62
44 bool IsPermissionGranted() const { 63 bool IsPermissionGranted() const {
45 return is_permission_granted_; 64 return is_permission_granted_;
46 } 65 }
47 66
48 // Permission is possible if it has not been denied. 67 // Permission is possible if it has not been denied.
49 bool IsPermissionPossible() const { 68 bool IsPermissionPossible() const {
50 return is_permission_granted_ || !was_permission_requested_; 69 return is_permission_granted_ || !was_permission_requested_;
51 } 70 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // identifier. 147 // identifier.
129 bool is_identifier_required_ = false; 148 bool is_identifier_required_ = false;
130 bool is_identifier_not_allowed_ = false; 149 bool is_identifier_not_allowed_ = false;
131 150
132 // Whether a rule has been added that recommends a distinctive identifier. 151 // Whether a rule has been added that recommends a distinctive identifier.
133 bool is_identifier_recommended_ = false; 152 bool is_identifier_recommended_ = false;
134 153
135 // Whether a rule has been added that requires or blocks persistent state. 154 // Whether a rule has been added that requires or blocks persistent state.
136 bool is_persistence_required_ = false; 155 bool is_persistence_required_ = false;
137 bool is_persistence_not_allowed_ = false; 156 bool is_persistence_not_allowed_ = false;
157
158 DISALLOW_COPY_AND_ASSIGN(ConfigState);
138 }; 159 };
139 160
140 static bool IsSupportedContentType( 161 KeySystemConfigSelector::KeySystemConfigSelector(
141 const KeySystems& key_systems, 162 const KeySystems* key_systems,
142 const std::string& key_system, 163 MediaPermission* media_permission)
143 EmeMediaType media_type, 164 : key_systems_(key_systems),
144 const std::string& container_mime_type, 165 media_permission_(media_permission),
145 const std::string& codecs) { 166 weak_factory_(this) {
146 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid 167 DCHECK(key_systems_);
147 // parameters can be rejected. http://crbug.com/417561 168 DCHECK(media_permission_);
148 std::string container_lower = base::StringToLowerASCII(container_mime_type); 169 }
149 170
150 // Check that |container_mime_type| and |codecs| are supported by the CDM. 171 KeySystemConfigSelector::~KeySystemConfigSelector() {
151 // This check does not handle extended codecs, so extended codec information 172 }
152 // is stripped. 173
153 std::vector<std::string> codec_vector; 174 void KeySystemConfigSelector::SelectConfig(
154 net::ParseCodecString(codecs, &codec_vector, true); 175 const blink::WebString& key_system,
155 if (!key_systems.IsSupportedCodecCombination( 176 const blink::WebVector<blink::WebMediaKeySystemConfiguration>&
156 key_system, media_type, container_lower, codec_vector)) { 177 candidate_configurations,
157 return false; 178 const blink::WebSecurityOrigin& security_origin,
179 base::Callback<void(const blink::WebMediaKeySystemConfiguration&)>
180 succeeded_cb,
181 base::Callback<void(const blink::WebString&)> not_supported_cb) {
182 // Continued from requestMediaKeySystemAccess(), step 7, from
183 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
184 //
185 // 7.1. If keySystem is not one of the Key Systems supported by the user
186 // agent, reject promise with with a new DOMException whose name is
187 // NotSupportedError. String comparison is case-sensitive.
188 if (!base::IsStringASCII(key_system)) {
189 not_supported_cb.Run("Only ASCII keySystems are supported");
190 return;
158 } 191 }
159 192
160 // Check that |container_mime_type| is supported by Chrome. This can only 193 scoped_ptr<SelectionRequest> request(new SelectionRequest());
161 // happen if the CDM declares support for a container that Chrome does not. 194 request->key_system = base::UTF16ToASCII(key_system);
162 if (!net::IsSupportedMediaMimeType(container_lower)) { 195 if (!key_systems_->IsSupportedKeySystem(request->key_system)) {
163 NOTREACHED(); 196 not_supported_cb.Run("Unsupported keySystem");
164 return false; 197 return;
165 } 198 }
166 199
167 // Check that |codecs| are supported by Chrome. This is done primarily to 200 // 7.2-7.4. Implemented by OnSelectConfig().
168 // validate extended codecs, but it also ensures that the CDM cannot support 201 // TODO(sandersd): This should be async, ideally not on the main thread.
169 // codecs that Chrome does not (which could complicate the robustness 202 request->candidate_configurations = candidate_configurations;
170 // algorithm). 203 request->security_origin = security_origin;
171 if (codec_vector.empty()) 204 request->succeeded_cb = succeeded_cb;
172 return true; 205 request->not_supported_cb = not_supported_cb;
173 codec_vector.clear(); 206 OnSelectConfig(request.Pass());
174 net::ParseCodecString(codecs, &codec_vector, false);
175 return (net::IsSupportedStrictMediaMimeType(container_lower, codec_vector) ==
176 net::IsSupported);
177 } 207 }
178 208
179 static bool GetSupportedCapabilities( 209 void KeySystemConfigSelector::OnPermissionResult(
180 const KeySystems& key_systems, 210 scoped_ptr<SelectionRequest> request,
181 const std::string& key_system, 211 bool is_permission_granted) {
182 EmeMediaType media_type, 212 request->was_permission_requested = true;
183 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& 213 request->is_permission_granted = is_permission_granted;
184 requested_media_capabilities, 214 OnSelectConfig(request.Pass());
185 ConfigState* config_state,
186 std::vector<blink::WebMediaKeySystemMediaCapability>*
187 supported_media_capabilities) {
188 // From
189 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type
190 // 1. Let local accumulated capabilities be a local copy of partial
191 // configuration.
192 // (Skipped as we directly update |config_state|. This is safe because we
193 // only do so when at least one requested media capability is supported.)
194 // 2. Let supported media capabilities be empty.
195 DCHECK_EQ(supported_media_capabilities->size(), 0ul);
196 // 3. For each value in requested media capabilities:
197 for (size_t i = 0; i < requested_media_capabilities.size(); i++) {
198 // 3.1. Let contentType be the value's contentType member.
199 // 3.2. Let robustness be the value's robustness member.
200 const blink::WebMediaKeySystemMediaCapability& capability =
201 requested_media_capabilities[i];
202 // 3.3. If contentType is the empty string, return null.
203 if (capability.mimeType.isEmpty()) {
204 DVLOG(2) << "Rejecting requested configuration because "
205 << "a capability contentType was empty.";
206 return false;
207 }
208 // 3.4-3.11. (Implemented by IsSupportedContentType().)
209 if (!base::IsStringASCII(capability.mimeType) ||
210 !base::IsStringASCII(capability.codecs) ||
211 !IsSupportedContentType(key_systems, key_system, media_type,
212 base::UTF16ToASCII(capability.mimeType),
213 base::UTF16ToASCII(capability.codecs))) {
214 continue;
215 }
216 // 3.12. If robustness is not the empty string, run the following steps:
217 if (!capability.robustness.isEmpty()) {
218 // 3.12.1. If robustness is an unrecognized value or not supported by
219 // implementation, continue to the next iteration. String
220 // comparison is case-sensitive.
221 if (!base::IsStringASCII(capability.robustness))
222 continue;
223 EmeConfigRule robustness_rule = key_systems.GetRobustnessConfigRule(
224 key_system, media_type, base::UTF16ToASCII(capability.robustness));
225 if (!config_state->IsRuleSupported(robustness_rule))
226 continue;
227 config_state->AddRule(robustness_rule);
228 // 3.12.2. Add robustness to configuration.
229 // (It's already added, we use capability as configuration.)
230 }
231 // 3.13. If the user agent and implementation do not support playback of
232 // encrypted media data as specified by configuration, including all
233 // media types, in combination with local accumulated capabilities,
234 // continue to the next iteration.
235 // (This is handled when adding rules to |config_state|.)
236 // 3.14. Add configuration to supported media capabilities.
237 supported_media_capabilities->push_back(capability);
238 // 3.15. Add configuration to local accumulated capabilities.
239 // (Skipped as we directly update |config_state|.)
240 }
241 // 4. If supported media capabilities is empty, return null.
242 if (supported_media_capabilities->empty()) {
243 DVLOG(2) << "Rejecting requested configuration because "
244 << "no capabilities were supported.";
245 return false;
246 }
247 // 5. Return media type capabilities.
248 return true;
249 } 215 }
250 216
251 static EmeFeatureRequirement ConvertRequirement( 217 void KeySystemConfigSelector::OnSelectConfig(
252 blink::WebMediaKeySystemConfiguration::Requirement requirement) { 218 scoped_ptr<SelectionRequest> request) {
253 switch (requirement) { 219 // Continued from requestMediaKeySystemAccess(), step 7.1, from
254 case blink::WebMediaKeySystemConfiguration::Requirement::Required: 220 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
255 return EME_FEATURE_REQUIRED; 221 //
256 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: 222 // 7.2. Let implementation be the implementation of keySystem.
257 return EME_FEATURE_OPTIONAL; 223 // (|key_systems_| fills this role.)
258 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: 224 // 7.3. For each value in supportedConfigurations:
259 return EME_FEATURE_NOT_ALLOWED; 225 for (size_t i = 0; i < request->candidate_configurations.size(); i++) {
226 // 7.3.1. Let candidate configuration be the value.
227 // 7.3.2. Let supported configuration be the result of executing the Get
228 // Supported Configuration algorithm on implementation, candidate
229 // configuration, and origin.
230 // 7.3.3. If supported configuration is not null, [initialize and return a
231 // new MediaKeySystemAccess object.]
232 ConfigState config_state(request.get());
233 blink::WebMediaKeySystemConfiguration accumulated_configuration;
234 ConfigurationSupport support = GetSupportedConfiguration(
235 request->key_system, request->candidate_configurations[i],
236 &config_state, &accumulated_configuration);
237 switch (support) {
238 case CONFIGURATION_NOT_SUPPORTED:
239 continue;
240 case CONFIGURATION_REQUIRES_PERMISSION:
241 if (request->was_permission_requested) {
242 DVLOG(2) << "Rejecting requested configuration because "
243 << "permission was denied.";
244 continue;
245 }
246 media_permission_->RequestPermission(
247 MediaPermission::PROTECTED_MEDIA_IDENTIFIER,
248 GURL(request->security_origin.toString()),
249 base::Bind(&KeySystemConfigSelector::OnPermissionResult,
250 weak_factory_.GetWeakPtr(), base::Passed(&request)));
251 return;
252 case CONFIGURATION_SUPPORTED:
253 request->succeeded_cb.Run(accumulated_configuration);
254 return;
255 }
260 } 256 }
261 257
262 NOTREACHED(); 258 // 7.4. Reject promise with a new DOMException whose name is
263 return EME_FEATURE_NOT_ALLOWED; 259 // NotSupportedError.
260 request->not_supported_cb.Run(
261 "None of the requested configurations were supported.");
264 } 262 }
265 263
266 static ConfigurationSupport GetSupportedConfiguration( 264 KeySystemConfigSelector::ConfigurationSupport
267 const KeySystems& key_systems, 265 KeySystemConfigSelector::GetSupportedConfiguration(
268 const std::string& key_system, 266 const std::string& key_system,
269 const blink::WebMediaKeySystemConfiguration& candidate, 267 const blink::WebMediaKeySystemConfiguration& candidate,
270 bool was_permission_requested, 268 ConfigState* config_state,
271 bool is_permission_granted,
272 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { 269 blink::WebMediaKeySystemConfiguration* accumulated_configuration) {
273 ConfigState config_state(was_permission_requested, is_permission_granted);
274
275 // From https://w3c.github.io/encrypted-media/#get-supported-configuration 270 // From https://w3c.github.io/encrypted-media/#get-supported-configuration
276 // 1. Let accumulated configuration be empty. (Done by caller.) 271 // 1. Let accumulated configuration be empty. (Done by caller.)
277 // 2. If the initDataTypes member is present in candidate configuration, run 272 // 2. If the initDataTypes member is present in candidate configuration, run
278 // the following steps: 273 // the following steps:
279 if (candidate.hasInitDataTypes) { 274 if (candidate.hasInitDataTypes) {
280 // 2.1. Let supported types be empty. 275 // 2.1. Let supported types be empty.
281 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; 276 std::vector<blink::WebEncryptedMediaInitDataType> supported_types;
282 277
283 // 2.2. For each value in candidate configuration's initDataTypes member: 278 // 2.2. For each value in candidate configuration's initDataTypes member:
284 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { 279 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) {
285 // 2.2.1. Let initDataType be the value. 280 // 2.2.1. Let initDataType be the value.
286 blink::WebEncryptedMediaInitDataType init_data_type = 281 blink::WebEncryptedMediaInitDataType init_data_type =
287 candidate.initDataTypes[i]; 282 candidate.initDataTypes[i];
288 // 2.2.2. If the implementation supports generating requests based on 283 // 2.2.2. If the implementation supports generating requests based on
289 // initDataType, add initDataType to supported types. String 284 // initDataType, add initDataType to supported types. String
290 // comparison is case-sensitive. The empty string is never 285 // comparison is case-sensitive. The empty string is never
291 // supported. 286 // supported.
292 if (init_data_type == blink::WebEncryptedMediaInitDataType::Unknown) 287 if (key_systems_->IsSupportedInitDataType(
293 continue;
294 if (key_systems.IsSupportedInitDataType(
295 key_system, ConvertToEmeInitDataType(init_data_type))) { 288 key_system, ConvertToEmeInitDataType(init_data_type))) {
296 supported_types.push_back(init_data_type); 289 supported_types.push_back(init_data_type);
297 } 290 }
298 } 291 }
299 292
300 // 2.3. If supported types is empty, return null. 293 // 2.3. If supported types is empty, return null.
301 if (supported_types.empty()) { 294 if (supported_types.empty()) {
302 DVLOG(2) << "Rejecting requested configuration because " 295 DVLOG(2) << "Rejecting requested configuration because "
303 << "no initDataType values were supported."; 296 << "no initDataType values were supported.";
304 return CONFIGURATION_NOT_SUPPORTED; 297 return CONFIGURATION_NOT_SUPPORTED;
305 } 298 }
306 299
307 // 2.4. Add supported types to accumulated configuration. 300 // 2.4. Add supported types to accumulated configuration.
308 accumulated_configuration->initDataTypes = supported_types; 301 accumulated_configuration->initDataTypes = supported_types;
309 } 302 }
310 303
311 // 3. Follow the steps for the value of candidate configuration's 304 // 3. Follow the steps for the value of candidate configuration's
312 // distinctiveIdentifier attribute from the following list: 305 // distinctiveIdentifier attribute from the following list:
313 // - "required": If the implementation does not support a persistent 306 // - "required": If the implementation does not support a persistent
314 // Distinctive Identifier in combination with accumulated 307 // Distinctive Identifier in combination with accumulated
315 // configuration, return null. 308 // configuration, return null.
316 // - "optional": Continue. 309 // - "optional": Continue.
317 // - "not-allowed": If the implementation requires a Distinctive 310 // - "not-allowed": If the implementation requires a Distinctive
318 // Identifier in combination with accumulated configuration, return 311 // Identifier in combination with accumulated configuration, return
319 // null. 312 // null.
320 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and 313 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and
321 // permission has already been denied. This would happen anyway at step 11. 314 // permission has already been denied. This would happen anyway at step 11.
322 EmeConfigRule di_rule = key_systems.GetDistinctiveIdentifierConfigRule( 315 EmeConfigRule di_rule = key_systems_->GetDistinctiveIdentifierConfigRule(
323 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); 316 key_system, ConvertRequirement(candidate.distinctiveIdentifier));
324 if (!config_state.IsRuleSupported(di_rule)) { 317 if (!config_state->IsRuleSupported(di_rule)) {
325 DVLOG(2) << "Rejecting requested configuration because " 318 DVLOG(2) << "Rejecting requested configuration because "
326 << "the distinctiveIdentifier requirement was not supported."; 319 << "the distinctiveIdentifier requirement was not supported.";
327 return CONFIGURATION_NOT_SUPPORTED; 320 return CONFIGURATION_NOT_SUPPORTED;
328 } 321 }
329 config_state.AddRule(di_rule); 322 config_state->AddRule(di_rule);
330 323
331 // 4. Add the value of the candidate configuration's distinctiveIdentifier 324 // 4. Add the value of the candidate configuration's distinctiveIdentifier
332 // attribute to accumulated configuration. 325 // attribute to accumulated configuration.
333 accumulated_configuration->distinctiveIdentifier = 326 accumulated_configuration->distinctiveIdentifier =
334 candidate.distinctiveIdentifier; 327 candidate.distinctiveIdentifier;
335 328
336 // 5. Follow the steps for the value of candidate configuration's 329 // 5. Follow the steps for the value of candidate configuration's
337 // persistentState attribute from the following list: 330 // persistentState attribute from the following list:
338 // - "required": If the implementation does not support persisting state 331 // - "required": If the implementation does not support persisting state
339 // in combination with accumulated configuration, return null. 332 // in combination with accumulated configuration, return null.
340 // - "optional": Continue. 333 // - "optional": Continue.
341 // - "not-allowed": If the implementation requires persisting state in 334 // - "not-allowed": If the implementation requires persisting state in
342 // combination with accumulated configuration, return null. 335 // combination with accumulated configuration, return null.
343 EmeConfigRule ps_rule = key_systems.GetPersistentStateConfigRule( 336 EmeConfigRule ps_rule = key_systems_->GetPersistentStateConfigRule(
344 key_system, ConvertRequirement(candidate.persistentState)); 337 key_system, ConvertRequirement(candidate.persistentState));
345 if (!config_state.IsRuleSupported(ps_rule)) { 338 if (!config_state->IsRuleSupported(ps_rule)) {
346 DVLOG(2) << "Rejecting requested configuration because " 339 DVLOG(2) << "Rejecting requested configuration because "
347 << "the persistentState requirement was not supported."; 340 << "the persistentState requirement was not supported.";
348 return CONFIGURATION_NOT_SUPPORTED; 341 return CONFIGURATION_NOT_SUPPORTED;
349 } 342 }
350 config_state.AddRule(ps_rule); 343 config_state->AddRule(ps_rule);
351 344
352 // 6. Add the value of the candidate configuration's persistentState 345 // 6. Add the value of the candidate configuration's persistentState
353 // attribute to accumulated configuration. 346 // attribute to accumulated configuration.
354 accumulated_configuration->persistentState = candidate.persistentState; 347 accumulated_configuration->persistentState = candidate.persistentState;
355 348
356 // 7. Follow the steps for the first matching condition from the following 349 // 7. Follow the steps for the first matching condition from the following
357 // list: 350 // list:
358 // - If the sessionTypes member is present in candidate configuration, 351 // - If the sessionTypes member is present in candidate configuration,
359 // let session types be candidate configuration's sessionTypes member. 352 // let session types be candidate configuration's sessionTypes member.
360 // - Otherwise, let session types be [ "temporary" ]. 353 // - Otherwise, let session types be [ "temporary" ].
(...skipping 23 matching lines...) Expand all
384 switch (session_type) { 377 switch (session_type) {
385 case blink::WebEncryptedMediaSessionType::Unknown: 378 case blink::WebEncryptedMediaSessionType::Unknown:
386 DVLOG(2) << "Rejecting requested configuration because " 379 DVLOG(2) << "Rejecting requested configuration because "
387 << "a required session type was not recognized."; 380 << "a required session type was not recognized.";
388 return CONFIGURATION_NOT_SUPPORTED; 381 return CONFIGURATION_NOT_SUPPORTED;
389 case blink::WebEncryptedMediaSessionType::Temporary: 382 case blink::WebEncryptedMediaSessionType::Temporary:
390 session_type_rule = EmeConfigRule::SUPPORTED; 383 session_type_rule = EmeConfigRule::SUPPORTED;
391 break; 384 break;
392 case blink::WebEncryptedMediaSessionType::PersistentLicense: 385 case blink::WebEncryptedMediaSessionType::PersistentLicense:
393 session_type_rule = 386 session_type_rule =
394 key_systems.GetPersistentLicenseSessionConfigRule(key_system); 387 key_systems_->GetPersistentLicenseSessionConfigRule(key_system);
395 break; 388 break;
396 case blink::WebEncryptedMediaSessionType::PersistentReleaseMessage: 389 case blink::WebEncryptedMediaSessionType::PersistentReleaseMessage:
397 session_type_rule = 390 session_type_rule =
398 key_systems.GetPersistentReleaseMessageSessionConfigRule( 391 key_systems_->GetPersistentReleaseMessageSessionConfigRule(
399 key_system); 392 key_system);
400 break; 393 break;
401 } 394 }
402 if (!config_state.IsRuleSupported(session_type_rule)) { 395 if (!config_state->IsRuleSupported(session_type_rule)) {
403 DVLOG(2) << "Rejecting requested configuration because " 396 DVLOG(2) << "Rejecting requested configuration because "
404 << "a required session type was not supported."; 397 << "a required session type was not supported.";
405 return CONFIGURATION_NOT_SUPPORTED; 398 return CONFIGURATION_NOT_SUPPORTED;
406 } 399 }
407 config_state.AddRule(session_type_rule); 400 config_state->AddRule(session_type_rule);
408 } 401 }
409 402
410 // 9. Add session types to accumulated configuration. 403 // 9. Add session types to accumulated configuration.
411 accumulated_configuration->sessionTypes = session_types; 404 accumulated_configuration->sessionTypes = session_types;
412 405
413 // 10. If the videoCapabilities member is present in candidate configuration: 406 // 10. If the videoCapabilities member is present in candidate configuration:
414 if (candidate.hasVideoCapabilities) { 407 if (candidate.hasVideoCapabilities) {
415 // 10.1. Let video capabilities be the result of executing the Get Supported 408 // 10.1. Let video capabilities be the result of executing the Get Supported
416 // Capabilities for Media Type algorithm on Video, candidate 409 // Capabilities for Media Type algorithm on Video, candidate
417 // configuration's videoCapabilities member, and accumulated 410 // configuration's videoCapabilities member, and accumulated
418 // configuration. 411 // configuration.
419 // 10.2. If video capabilities is null, return null. 412 // 10.2. If video capabilities is null, return null.
420 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; 413 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities;
421 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::VIDEO, 414 if (!GetSupportedCapabilities(key_system, EmeMediaType::VIDEO,
422 candidate.videoCapabilities, 415 candidate.videoCapabilities,
423 &config_state, &video_capabilities)) { 416 config_state, &video_capabilities)) {
424 return CONFIGURATION_NOT_SUPPORTED; 417 return CONFIGURATION_NOT_SUPPORTED;
425 } 418 }
426 419
427 // 10.3. Add video capabilities to accumulated configuration. 420 // 10.3. Add video capabilities to accumulated configuration.
428 accumulated_configuration->videoCapabilities = video_capabilities; 421 accumulated_configuration->videoCapabilities = video_capabilities;
429 } 422 }
430 423
431 // 11. If the audioCapabilities member is present in candidate configuration: 424 // 11. If the audioCapabilities member is present in candidate configuration:
432 if (candidate.hasAudioCapabilities) { 425 if (candidate.hasAudioCapabilities) {
433 // 11.1. Let audio capabilities be the result of executing the Get Supported 426 // 11.1. Let audio capabilities be the result of executing the Get Supported
434 // Capabilities for Media Type algorithm on Audio, candidate 427 // Capabilities for Media Type algorithm on Audio, candidate
435 // configuration's audioCapabilities member, and accumulated 428 // configuration's audioCapabilities member, and accumulated
436 // configuration. 429 // configuration.
437 // 11.2. If audio capabilities is null, return null. 430 // 11.2. If audio capabilities is null, return null.
438 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; 431 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities;
439 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::AUDIO, 432 if (!GetSupportedCapabilities(key_system, EmeMediaType::AUDIO,
440 candidate.audioCapabilities, 433 candidate.audioCapabilities,
441 &config_state, &audio_capabilities)) { 434 config_state, &audio_capabilities)) {
442 return CONFIGURATION_NOT_SUPPORTED; 435 return CONFIGURATION_NOT_SUPPORTED;
443 } 436 }
444 437
445 // 11.3. Add audio capabilities to accumulated configuration. 438 // 11.3. Add audio capabilities to accumulated configuration.
446 accumulated_configuration->audioCapabilities = audio_capabilities; 439 accumulated_configuration->audioCapabilities = audio_capabilities;
447 } 440 }
448 441
449 // 12. If accumulated configuration's distinctiveIdentifier value is 442 // 12. If accumulated configuration's distinctiveIdentifier value is
450 // "optional", follow the steps for the first matching condition from the 443 // "optional", follow the steps for the first matching condition from the
451 // following list: 444 // following list:
452 // - If the implementation requires a Distinctive Identifier for any of 445 // - If the implementation requires a Distinctive Identifier for any of
453 // the combinations in accumulated configuration, change accumulated 446 // the combinations in accumulated configuration, change accumulated
454 // configuration's distinctiveIdentifier value to "required". 447 // configuration's distinctiveIdentifier value to "required".
455 // - Otherwise, change accumulated configuration's distinctiveIdentifier 448 // - Otherwise, change accumulated configuration's distinctiveIdentifier
456 // value to "not-allowed". 449 // value to "not-allowed".
457 if (accumulated_configuration->distinctiveIdentifier == 450 if (accumulated_configuration->distinctiveIdentifier ==
458 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 451 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
459 EmeConfigRule not_allowed_rule = 452 EmeConfigRule not_allowed_rule =
460 key_systems.GetDistinctiveIdentifierConfigRule( 453 key_systems_->GetDistinctiveIdentifierConfigRule(
461 key_system, EME_FEATURE_NOT_ALLOWED); 454 key_system, EME_FEATURE_NOT_ALLOWED);
462 EmeConfigRule required_rule = 455 EmeConfigRule required_rule =
463 key_systems.GetDistinctiveIdentifierConfigRule( 456 key_systems_->GetDistinctiveIdentifierConfigRule(
464 key_system, EME_FEATURE_REQUIRED); 457 key_system, EME_FEATURE_REQUIRED);
465 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); 458 bool not_allowed_supported =
466 bool required_supported = config_state.IsRuleSupported(required_rule); 459 config_state->IsRuleSupported(not_allowed_rule);
460 bool required_supported = config_state->IsRuleSupported(required_rule);
467 // If a distinctive identifier is recommend and that is a possible outcome, 461 // If a distinctive identifier is recommend and that is a possible outcome,
468 // prefer that. 462 // prefer that.
469 if (required_supported && 463 if (required_supported &&
470 config_state.IsIdentifierRecommended() && 464 config_state->IsIdentifierRecommended() &&
471 config_state.IsPermissionPossible()) { 465 config_state->IsPermissionPossible()) {
472 not_allowed_supported = false; 466 not_allowed_supported = false;
473 } 467 }
474 if (not_allowed_supported) { 468 if (not_allowed_supported) {
475 accumulated_configuration->distinctiveIdentifier = 469 accumulated_configuration->distinctiveIdentifier =
476 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 470 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
477 config_state.AddRule(not_allowed_rule); 471 config_state->AddRule(not_allowed_rule);
478 } else if (required_supported) { 472 } else if (required_supported) {
479 accumulated_configuration->distinctiveIdentifier = 473 accumulated_configuration->distinctiveIdentifier =
480 blink::WebMediaKeySystemConfiguration::Requirement::Required; 474 blink::WebMediaKeySystemConfiguration::Requirement::Required;
481 config_state.AddRule(required_rule); 475 config_state->AddRule(required_rule);
482 } else { 476 } else {
483 // We should not have passed step 3. 477 // We should not have passed step 3.
484 NOTREACHED(); 478 NOTREACHED();
485 return CONFIGURATION_NOT_SUPPORTED; 479 return CONFIGURATION_NOT_SUPPORTED;
486 } 480 }
487 } 481 }
488 482
489 // 13. If accumulated configuration's persistentState value is "optional", 483 // 13. If accumulated configuration's persistentState value is "optional",
490 // follow the steps for the first matching condition from the following 484 // follow the steps for the first matching condition from the following
491 // list: 485 // list:
492 // - If the implementation requires persisting state for any of the 486 // - If the implementation requires persisting state for any of the
493 // combinations in accumulated configuration, change accumulated 487 // combinations in accumulated configuration, change accumulated
494 // configuration's persistentState value to "required". 488 // configuration's persistentState value to "required".
495 // - Otherwise, change accumulated configuration's persistentState value 489 // - Otherwise, change accumulated configuration's persistentState value
496 // to "not-allowed". 490 // to "not-allowed".
497 if (accumulated_configuration->persistentState == 491 if (accumulated_configuration->persistentState ==
498 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 492 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
499 EmeConfigRule not_allowed_rule = 493 EmeConfigRule not_allowed_rule =
500 key_systems.GetPersistentStateConfigRule( 494 key_systems_->GetPersistentStateConfigRule(
501 key_system, EME_FEATURE_NOT_ALLOWED); 495 key_system, EME_FEATURE_NOT_ALLOWED);
502 EmeConfigRule required_rule = 496 EmeConfigRule required_rule =
503 key_systems.GetPersistentStateConfigRule( 497 key_systems_->GetPersistentStateConfigRule(
504 key_system, EME_FEATURE_REQUIRED); 498 key_system, EME_FEATURE_REQUIRED);
505 // |distinctiveIdentifier| should not be affected after it is decided. 499 // |distinctiveIdentifier| should not be affected after it is decided.
506 DCHECK(not_allowed_rule == EmeConfigRule::NOT_SUPPORTED || 500 DCHECK(not_allowed_rule == EmeConfigRule::NOT_SUPPORTED ||
507 not_allowed_rule == EmeConfigRule::PERSISTENCE_NOT_ALLOWED); 501 not_allowed_rule == EmeConfigRule::PERSISTENCE_NOT_ALLOWED);
508 DCHECK(required_rule == EmeConfigRule::NOT_SUPPORTED || 502 DCHECK(required_rule == EmeConfigRule::NOT_SUPPORTED ||
509 required_rule == EmeConfigRule::PERSISTENCE_REQUIRED); 503 required_rule == EmeConfigRule::PERSISTENCE_REQUIRED);
510 bool not_allowed_supported = 504 bool not_allowed_supported =
511 config_state.IsRuleSupported(not_allowed_rule); 505 config_state->IsRuleSupported(not_allowed_rule);
512 bool required_supported = 506 bool required_supported =
513 config_state.IsRuleSupported(required_rule); 507 config_state->IsRuleSupported(required_rule);
514 if (not_allowed_supported) { 508 if (not_allowed_supported) {
515 accumulated_configuration->persistentState = 509 accumulated_configuration->persistentState =
516 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 510 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
517 config_state.AddRule(not_allowed_rule); 511 config_state->AddRule(not_allowed_rule);
518 } else if (required_supported) { 512 } else if (required_supported) {
519 accumulated_configuration->persistentState = 513 accumulated_configuration->persistentState =
520 blink::WebMediaKeySystemConfiguration::Requirement::Required; 514 blink::WebMediaKeySystemConfiguration::Requirement::Required;
521 config_state.AddRule(required_rule); 515 config_state->AddRule(required_rule);
522 } else { 516 } else {
523 // We should not have passed step 5. 517 // We should not have passed step 5.
524 NOTREACHED(); 518 NOTREACHED();
525 return CONFIGURATION_NOT_SUPPORTED; 519 return CONFIGURATION_NOT_SUPPORTED;
526 } 520 }
527 } 521 }
528 522
529 // 14. If implementation in the configuration specified by the combination of 523 // 14. If implementation in the configuration specified by the combination of
530 // the values in accumulated configuration is not supported or not allowed 524 // the values in accumulated configuration is not supported or not allowed
531 // in the origin, return null. 525 // in the origin, return null.
532 // 15. If accumulated configuration's distinctiveIdentifier value is 526 // 15. If accumulated configuration's distinctiveIdentifier value is
533 // "required", [prompt the user for consent]. 527 // "required", [prompt the user for consent].
534 if (accumulated_configuration->distinctiveIdentifier == 528 if (accumulated_configuration->distinctiveIdentifier ==
535 blink::WebMediaKeySystemConfiguration::Requirement::Required) { 529 blink::WebMediaKeySystemConfiguration::Requirement::Required) {
536 // The caller is responsible for resolving what to do if permission is 530 // The caller is responsible for resolving what to do if permission is
537 // required but has been denied (it should treat it as NOT_SUPPORTED). 531 // required but has been denied (it should treat it as NOT_SUPPORTED).
538 if (!config_state.IsPermissionGranted()) 532 if (!config_state->IsPermissionGranted())
539 return CONFIGURATION_REQUIRES_PERMISSION; 533 return CONFIGURATION_REQUIRES_PERMISSION;
540 } 534 }
541 535
542 // 16. Return accumulated configuration. 536 // 16. Return accumulated configuration.
543 return CONFIGURATION_SUPPORTED; 537 return CONFIGURATION_SUPPORTED;
544 } 538 }
545 539
546 // Report usage of key system to UMA. There are 2 different counts logged: 540 bool KeySystemConfigSelector::GetSupportedCapabilities(
547 // 1. The key system is requested. 541 const std::string& key_system,
548 // 2. The requested key system and options are supported. 542 EmeMediaType media_type,
549 // Each stat is only reported once per renderer frame per key system. 543 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>&
550 // Note that WebEncryptedMediaClientImpl is only created once by each 544 requested_media_capabilities,
551 // renderer frame. 545 KeySystemConfigSelector::ConfigState* config_state,
552 class WebEncryptedMediaClientImpl::Reporter { 546 std::vector<blink::WebMediaKeySystemMediaCapability>*
553 public: 547 supported_media_capabilities) {
554 enum KeySystemSupportStatus { 548 // From
555 KEY_SYSTEM_REQUESTED = 0, 549 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type
556 KEY_SYSTEM_SUPPORTED = 1, 550 // 1. Let local accumulated capabilities be a local copy of partial
557 KEY_SYSTEM_SUPPORT_STATUS_COUNT 551 // configuration.
558 }; 552 // (Skipped as we directly update |config_state|. This is safe because we
553 // only do so when at least one requested media capability is supported.)
554 // 2. Let supported media capabilities be empty.
555 DCHECK_EQ(supported_media_capabilities->size(), 0ul);
556 // 3. For each value in requested media capabilities:
557 for (size_t i = 0; i < requested_media_capabilities.size(); i++) {
558 // 3.1. Let contentType be the value's contentType member.
559 // 3.2. Let robustness be the value's robustness member.
560 const blink::WebMediaKeySystemMediaCapability& capability =
561 requested_media_capabilities[i];
562 // 3.3. If contentType is the empty string, return null.
563 if (capability.mimeType.isEmpty()) {
564 DVLOG(2) << "Rejecting requested configuration because "
565 << "a capability contentType was empty.";
566 return false;
567 }
568 // 3.4-3.11. (Implemented by IsSupportedContentType().)
569 if (!base::IsStringASCII(capability.mimeType) ||
570 !base::IsStringASCII(capability.codecs) ||
571 !IsSupportedContentType(key_system, media_type,
572 base::UTF16ToASCII(capability.mimeType),
573 base::UTF16ToASCII(capability.codecs))) {
574 continue;
575 }
576 // 3.12. If robustness is not the empty string, run the following steps:
577 if (!capability.robustness.isEmpty()) {
578 // 3.12.1. If robustness is an unrecognized value or not supported by
579 // implementation, continue to the next iteration. String
580 // comparison is case-sensitive.
581 if (!base::IsStringASCII(capability.robustness))
582 continue;
583 EmeConfigRule robustness_rule = key_systems_->GetRobustnessConfigRule(
584 key_system, media_type, base::UTF16ToASCII(capability.robustness));
585 if (!config_state->IsRuleSupported(robustness_rule))
586 continue;
587 config_state->AddRule(robustness_rule);
588 // 3.12.2. Add robustness to configuration.
589 // (It's already added, we use capability as configuration.)
590 }
591 // 3.13. If the user agent and implementation do not support playback of
592 // encrypted media data as specified by configuration, including all
593 // media types, in combination with local accumulated capabilities,
594 // continue to the next iteration.
595 // (This is handled when adding rules to |config_state|.)
596 // 3.14. Add configuration to supported media capabilities.
597 supported_media_capabilities->push_back(capability);
598 // 3.15. Add configuration to local accumulated capabilities.
599 // (Skipped as we directly update |config_state|.)
600 }
601 // 4. If supported media capabilities is empty, return null.
602 if (supported_media_capabilities->empty()) {
603 DVLOG(2) << "Rejecting requested configuration because "
604 << "no capabilities were supported.";
605 return false;
606 }
607 // 5. Return media type capabilities.
608 return true;
609 }
559 610
560 explicit Reporter(const std::string& key_system_for_uma) 611 bool KeySystemConfigSelector::IsSupportedContentType(
561 : uma_name_(kKeySystemSupportUMAPrefix + key_system_for_uma), 612 const std::string& key_system,
562 is_request_reported_(false), 613 EmeMediaType media_type,
563 is_support_reported_(false) {} 614 const std::string& container_mime_type,
564 ~Reporter() {} 615 const std::string& codecs) {
616 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid
617 // parameters can be rejected. http://crbug.com/417561
618 std::string container_lower = base::StringToLowerASCII(container_mime_type);
565 619
566 void ReportRequested() { 620 // Check that |container_mime_type| and |codecs| are supported by the CDM.
567 if (is_request_reported_) 621 // This check does not handle extended codecs, so extended codec information
568 return; 622 // is stripped.
569 Report(KEY_SYSTEM_REQUESTED); 623 std::vector<std::string> codec_vector;
570 is_request_reported_ = true; 624 net::ParseCodecString(codecs, &codec_vector, true);
625 if (!key_systems_->IsSupportedCodecCombination(
626 key_system, media_type, container_lower, codec_vector)) {
627 return false;
571 } 628 }
572 629
573 void ReportSupported() { 630 // Check that |container_mime_type| is supported by Chrome. This can only
574 DCHECK(is_request_reported_); 631 // happen if the CDM declares support for a container that Chrome does not.
575 if (is_support_reported_) 632 if (!net::IsSupportedMediaMimeType(container_lower)) {
576 return; 633 NOTREACHED();
577 Report(KEY_SYSTEM_SUPPORTED); 634 return false;
578 is_support_reported_ = true;
579 } 635 }
580 636
581 private: 637 // Check that |codecs| are supported by Chrome. This is done primarily to
582 void Report(KeySystemSupportStatus status) { 638 // validate extended codecs, but it also ensures that the CDM cannot support
583 // Not using UMA_HISTOGRAM_ENUMERATION directly because UMA_* macros 639 // codecs that Chrome does not (which could complicate the robustness
584 // require the names to be constant throughout the process' lifetime. 640 // algorithm).
585 base::LinearHistogram::FactoryGet( 641 if (codec_vector.empty())
586 uma_name_, 1, KEY_SYSTEM_SUPPORT_STATUS_COUNT, 642 return true;
587 KEY_SYSTEM_SUPPORT_STATUS_COUNT + 1, 643 codec_vector.clear();
588 base::Histogram::kUmaTargetedHistogramFlag)->Add(status); 644 net::ParseCodecString(codecs, &codec_vector, false);
589 } 645 return (net::IsSupportedStrictMediaMimeType(container_lower, codec_vector) ==
590 646 net::IsSupported);
591 const std::string uma_name_;
592 bool is_request_reported_;
593 bool is_support_reported_;
594 };
595
596 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl(
597 scoped_ptr<CdmFactory> cdm_factory,
598 MediaPermission* media_permission)
599 : key_systems_(KeySystems::GetInstance()),
600 cdm_factory_(cdm_factory.Pass()),
601 media_permission_(media_permission),
602 weak_factory_(this) {
603 DCHECK(media_permission);
604 }
605
606 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() {
607 }
608
609 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
610 blink::WebEncryptedMediaRequest request) {
611 // TODO(jrummell): This should be asynchronous, ideally not on the main
612 // thread.
613
614 // Continued from requestMediaKeySystemAccess(), step 7, from
615 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
616 //
617 // 7.1. If keySystem is not one of the Key Systems supported by the user
618 // agent, reject promise with with a new DOMException whose name is
619 // NotSupportedError. String comparison is case-sensitive.
620 if (!base::IsStringASCII(request.keySystem())) {
621 request.requestNotSupported("Only ASCII keySystems are supported");
622 return;
623 }
624
625 // Report this request to the UMA.
626 std::string key_system = base::UTF16ToASCII(request.keySystem());
627 GetReporter(key_system)->ReportRequested();
628
629 if (!key_systems_.IsSupportedKeySystem(key_system)) {
630 request.requestNotSupported("Unsupported keySystem");
631 return;
632 }
633
634 // 7.2-7.4. Implemented by SelectSupportedConfiguration().
635 SelectSupportedConfiguration(request, false, false);
636 }
637
638 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration(
639 blink::WebEncryptedMediaRequest request,
640 bool was_permission_requested,
641 bool is_permission_granted) {
642 // Continued from requestMediaKeySystemAccess(), step 7.1, from
643 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
644 //
645 // 7.2. Let implementation be the implementation of keySystem.
646 std::string key_system = base::UTF16ToASCII(request.keySystem());
647
648 // 7.3. For each value in supportedConfigurations:
649 const blink::WebVector<blink::WebMediaKeySystemConfiguration>&
650 configurations = request.supportedConfigurations();
651 for (size_t i = 0; i < configurations.size(); i++) {
652 // 7.3.1. Let candidate configuration be the value.
653 const blink::WebMediaKeySystemConfiguration& candidate_configuration =
654 configurations[i];
655 // 7.3.2. Let supported configuration be the result of executing the Get
656 // Supported Configuration algorithm on implementation, candidate
657 // configuration, and origin.
658 // 7.3.3. If supported configuration is not null, [initialize and return a
659 // new MediaKeySystemAccess object.]
660 blink::WebMediaKeySystemConfiguration accumulated_configuration;
661 ConfigurationSupport supported = GetSupportedConfiguration(
662 key_systems_, key_system, candidate_configuration,
663 was_permission_requested, is_permission_granted,
664 &accumulated_configuration);
665 switch (supported) {
666 case CONFIGURATION_NOT_SUPPORTED:
667 continue;
668 case CONFIGURATION_REQUIRES_PERMISSION:
669 if (was_permission_requested) {
670 DVLOG(2) << "Rejecting requested configuration because "
671 << "permission was denied.";
672 continue;
673 }
674 media_permission_->RequestPermission(
675 MediaPermission::PROTECTED_MEDIA_IDENTIFIER,
676 GURL(request.securityOrigin().toString()),
677 // Try again with |was_permission_requested| true and
678 // |is_permission_granted| the value of the permission.
679 base::Bind(
680 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration,
681 weak_factory_.GetWeakPtr(), request, true));
682 return;
683 case CONFIGURATION_SUPPORTED:
684 // Report that this request succeeded to the UMA.
685 GetReporter(key_system)->ReportSupported();
686 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
687 request.keySystem(), accumulated_configuration,
688 request.securityOrigin(), weak_factory_.GetWeakPtr()));
689 return;
690 }
691 }
692
693 // 7.4. Reject promise with a new DOMException whose name is
694 // NotSupportedError.
695 request.requestNotSupported(
696 "None of the requested configurations were supported.");
697 }
698
699 void WebEncryptedMediaClientImpl::CreateCdm(
700 const blink::WebString& key_system,
701 bool allow_distinctive_identifier,
702 bool allow_persistent_state,
703 const blink::WebSecurityOrigin& security_origin,
704 blink::WebContentDecryptionModuleResult result) {
705 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), key_system,
706 allow_distinctive_identifier,
707 allow_persistent_state,
708 security_origin, result);
709 }
710
711 // Lazily create Reporters.
712 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter(
713 const std::string& key_system) {
714 std::string uma_name = GetKeySystemNameForUMA(key_system);
715 Reporter* reporter = reporters_.get(uma_name);
716 if (reporter != nullptr)
717 return reporter;
718
719 // Reporter not found, so create one.
720 auto result =
721 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name)));
722 DCHECK(result.second);
723 return result.first->second;
724 } 647 }
725 648
726 } // namespace media 649 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698