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

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

Issue 1005903003: Implement robustness strings in requestMediaKeySystemAccess(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change parameter names. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // 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/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 13 matching lines...) Expand all
24 // These names are used by UMA. 24 // These names are used by UMA.
25 const char kKeySystemSupportUMAPrefix[] = 25 const char kKeySystemSupportUMAPrefix[] =
26 "Media.EME.RequestMediaKeySystemAccess."; 26 "Media.EME.RequestMediaKeySystemAccess.";
27 27
28 enum ConfigurationSupport { 28 enum ConfigurationSupport {
29 CONFIGURATION_NOT_SUPPORTED, 29 CONFIGURATION_NOT_SUPPORTED,
30 CONFIGURATION_REQUIRES_PERMISSION, 30 CONFIGURATION_REQUIRES_PERMISSION,
31 CONFIGURATION_SUPPORTED, 31 CONFIGURATION_SUPPORTED,
32 }; 32 };
33 33
34 // Accumulates configuration rules to determine if a feature (additional
35 // configuration rule) can be added to an accumulated configuration.
36 class ConfigState {
37 public:
38 ConfigState(bool was_permission_requested, bool is_permission_granted)
39 : was_permission_requested_(was_permission_requested),
40 is_permission_granted_(is_permission_granted),
41 is_identifier_required_(false),
42 is_identifier_recommended_(false){
43 }
44
45 bool IsPermissionGranted() const {
46 return is_permission_granted_;
47 }
48
49 // Permission is possible if it has not been denied.
50 bool IsPermissionPossible() const {
51 return is_permission_granted_ || !was_permission_requested_;
52 }
53
54 bool IsIdentifierRequired() const {
55 return is_identifier_required_;
56 }
57
58 bool IsIdentifierRecommended() const {
59 return is_identifier_recommended_;
60 }
61
62 // Checks whether a rule is compatible with all previously added rules.
63 bool IsRuleSupported(EmeConfigRule rule) const {
64 switch (rule) {
65 case EmeConfigRule::NOT_SUPPORTED:
66 return false;
67 case EmeConfigRule::IDENTIFIER_REQUIRED:
68 return IsPermissionPossible();
69 case EmeConfigRule::IDENTIFIER_RECOMMENDED:
70 return true;
71 case EmeConfigRule::SUPPORTED:
72 return true;
73 }
74 NOTREACHED();
75 return false;
76 }
77
78 // Checks whether a rule is compatible with all previously added rules, and
79 // can be accepted without needing to add it to the configuration state. This
80 // allows considering more rules after the configuration state is final (that
81 // is, after distinctiveIdentifier has been resolved).
82 bool IsRuleSupportedWithCurrentState(EmeConfigRule rule) const {
83 switch (rule) {
84 case EmeConfigRule::NOT_SUPPORTED:
85 return false;
86 case EmeConfigRule::IDENTIFIER_REQUIRED:
87 return is_permission_granted_;
88 case EmeConfigRule::IDENTIFIER_RECOMMENDED:
89 return true;
90 case EmeConfigRule::SUPPORTED:
91 return true;
92 }
93 NOTREACHED();
94 return false;
95 }
96
97 // Add a rule to the accumulated configuration state.
98 void AddRule(EmeConfigRule rule) {
99 switch (rule) {
100 case EmeConfigRule::NOT_SUPPORTED:
101 return;
102 case EmeConfigRule::IDENTIFIER_REQUIRED:
103 is_identifier_required_ = true;
104 return;
105 case EmeConfigRule::IDENTIFIER_RECOMMENDED:
106 is_identifier_recommended_ = true;
107 return;
108 case EmeConfigRule::SUPPORTED:
109 return;
110 }
111 NOTREACHED();
112 }
113
114 private:
115 // Whether permission to use a distinctive identifier was requested. If set,
116 // |is_permission_granted_| represents the final decision.
117 const bool was_permission_requested_;
118
119 // Whether permission to use a distinctive identifier has been granted.
120 const bool is_permission_granted_;
121
122 // Whether a rule has been added that requires a distinctive identifier.
123 bool is_identifier_required_;
124
125 // Whether a rule has been added that recommends a distinctive identifier.
126 bool is_identifier_recommended_;
127 };
128
129 static EmeRobustness ConvertRobustness(const blink::WebString& robustness) {
130 if (robustness.isEmpty())
131 return EmeRobustness::EMPTY;
132 if (robustness == "SW_SECURE_CRYPTO")
133 return EmeRobustness::SW_SECURE_CRYPTO;
134 if (robustness == "SW_SECURE_DECODE")
135 return EmeRobustness::SW_SECURE_DECODE;
136 if (robustness == "HW_SECURE_CRYPTO")
137 return EmeRobustness::HW_SECURE_CRYPTO;
138 if (robustness == "HW_SECURE_DECODE")
139 return EmeRobustness::HW_SECURE_DECODE;
140 if (robustness == "HW_SECURE_ALL")
141 return EmeRobustness::HW_SECURE_ALL;
142 return EmeRobustness::INVALID;
143 }
144
34 static bool IsSupportedContentType(const std::string& key_system, 145 static bool IsSupportedContentType(const std::string& key_system,
35 const std::string& mime_type, 146 const std::string& mime_type,
36 const std::string& codecs) { 147 const std::string& codecs) {
37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid 148 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid
38 // parameters can be rejected. http://crbug.com/417561 149 // parameters can be rejected. http://crbug.com/417561
39 // TODO(sandersd): Pass in the media type (audio or video) and check that the 150 // TODO(sandersd): Pass in the media type (audio or video) and check that the
40 // container type matches. http://crbug.com/457384 151 // container type matches. http://crbug.com/457384
41 std::string container = base::StringToLowerASCII(mime_type); 152 std::string container = base::StringToLowerASCII(mime_type);
42 153
43 // Check that |codecs| are supported by the CDM. This check does not handle 154 // Check that |codecs| are supported by the CDM. This check does not handle
(...skipping 14 matching lines...) Expand all
58 // decode is required). 169 // decode is required).
59 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 170 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751
60 codec_vector.clear(); 171 codec_vector.clear();
61 net::ParseCodecString(codecs, &codec_vector, false); 172 net::ParseCodecString(codecs, &codec_vector, false);
62 return net::AreSupportedMediaCodecs(codec_vector); 173 return net::AreSupportedMediaCodecs(codec_vector);
63 } 174 }
64 175
65 static bool GetSupportedCapabilities( 176 static bool GetSupportedCapabilities(
66 const std::string& key_system, 177 const std::string& key_system,
67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& 178 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>&
68 capabilities, 179 requested_media_capabilities,
180 EmeMediaType media_type,
69 std::vector<blink::WebMediaKeySystemMediaCapability>* 181 std::vector<blink::WebMediaKeySystemMediaCapability>*
70 media_type_capabilities) { 182 supported_media_capabilities,
183 ConfigState* config_state) {
71 // From 184 // From
72 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type 185 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type
73 // 1. Let accumulated capabilities be partial configuration. 186 // 1. Let local accumulated capabilities be a local copy of partial
74 // (Skipped as there are no configuration-based codec restrictions.) 187 // configuration.
75 // 2. Let media type capabilities be empty. 188 // (Skipped as we directly update |config_state|. This is safe because we
76 DCHECK_EQ(media_type_capabilities->size(), 0ul); 189 // only do so when at least one requested media capability is supported.)
77 // 3. For each value in capabilities: 190 // 2. Let supported media capabilities be empty.
78 for (size_t i = 0; i < capabilities.size(); i++) { 191 DCHECK_EQ(supported_media_capabilities->size(), 0ul);
192 // 3. For each value in requested media capabilities:
193 for (size_t i = 0; i < requested_media_capabilities.size(); i++) {
79 // 3.1. Let contentType be the value's contentType member. 194 // 3.1. Let contentType be the value's contentType member.
80 // 3.2. Let robustness be the value's robustness member. 195 // 3.2. Let robustness be the value's robustness member.
81 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; 196 const blink::WebMediaKeySystemMediaCapability& capability =
197 requested_media_capabilities[i];
82 // 3.3. If contentType is the empty string, return null. 198 // 3.3. If contentType is the empty string, return null.
83 if (capability.mimeType.isEmpty()) 199 if (capability.mimeType.isEmpty()) {
200 DVLOG(2) << "Rejecting requested configuration because "
201 << "a capability contentType was empty.";
84 return false; 202 return false;
203 }
85 // 3.4-3.11. (Implemented by IsSupportedContentType().) 204 // 3.4-3.11. (Implemented by IsSupportedContentType().)
86 if (!base::IsStringASCII(capability.mimeType) || 205 if (!base::IsStringASCII(capability.mimeType) ||
87 !base::IsStringASCII(capability.codecs) || 206 !base::IsStringASCII(capability.codecs) ||
88 !IsSupportedContentType(key_system, 207 !IsSupportedContentType(key_system,
89 base::UTF16ToASCII(capability.mimeType), 208 base::UTF16ToASCII(capability.mimeType),
90 base::UTF16ToASCII(capability.codecs))) { 209 base::UTF16ToASCII(capability.codecs))) {
91 continue; 210 continue;
92 } 211 }
93 // 3.12. If robustness is not the empty string, run the following steps: 212 // 3.12. If robustness is not the empty string, run the following steps:
94 // (Robustness is not supported.)
95 // TODO(sandersd): Implement robustness. http://crbug.com/442586
96 if (!capability.robustness.isEmpty()) { 213 if (!capability.robustness.isEmpty()) {
97 LOG(WARNING) << "Configuration rejected because rubustness strings are " 214 // 3.12.1. If robustness is an unrecognized value or not supported by
98 << "not yet supported."; 215 // implementation, continue to the next iteration. String
99 continue; 216 // comparison is case-sensitive.
217 EmeConfigRule robustness_rule = GetRobustnessConfigRule(
218 key_system, media_type, ConvertRobustness(capability.robustness));
ddorwin 2015/03/24 18:11:37 On second thought, regardless of how we define or
sandersd (OOO until July 31) 2015/03/24 18:20:25 Done.
219 if (!config_state->IsRuleSupported(robustness_rule))
220 continue;
221 config_state->AddRule(robustness_rule);
222 // 3.12.2. Add robustness to configuration.
223 // (It's already added, we use capability as configuration.)
100 } 224 }
101 // 3.13. If the user agent and implementation do not support playback of 225 // 3.13. If the user agent and implementation do not support playback of
102 // encrypted media data as specified by configuration, including all 226 // encrypted media data as specified by configuration, including all
103 // media types, in combination with accumulated capabilities, 227 // media types, in combination with local accumulated capabilities,
104 // continue to the next iteration. 228 // continue to the next iteration.
105 // (Skipped as there are no configuration-based codec restrictions.) 229 // (This is handled when adding rules to |config_state|.)
106 // 3.14. Add configuration to media type capabilities. 230 // 3.14. Add configuration to supported media capabilities.
107 media_type_capabilities->push_back(capability); 231 supported_media_capabilities->push_back(capability);
108 // 3.15. Add configuration to accumulated capabilities. 232 // 3.15. Add configuration to local accumulated capabilities.
109 // (Skipped as there are no configuration-based codec restrictions.) 233 // (Skipped as we directly update |config_state|.)
110 } 234 }
111 // 4. If media type capabilities is empty, return null. 235 // 4. If supported media capabilities is empty, return null.
236 if (supported_media_capabilities->empty()) {
237 DVLOG(2) << "Rejecting requested configuration because "
238 << "no capabilities were supported.";
239 return false;
240 }
112 // 5. Return media type capabilities. 241 // 5. Return media type capabilities.
113 return !media_type_capabilities->empty(); 242 return true;
114 } 243 }
115 244
116 static EmeFeatureRequirement ConvertRequirement( 245 static EmeFeatureRequirement ConvertRequirement(
117 blink::WebMediaKeySystemConfiguration::Requirement requirement) { 246 blink::WebMediaKeySystemConfiguration::Requirement requirement) {
118 switch (requirement) { 247 switch (requirement) {
119 case blink::WebMediaKeySystemConfiguration::Requirement::Required: 248 case blink::WebMediaKeySystemConfiguration::Requirement::Required:
120 return EME_FEATURE_REQUIRED; 249 return EME_FEATURE_REQUIRED;
121 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: 250 case blink::WebMediaKeySystemConfiguration::Requirement::Optional:
122 return EME_FEATURE_OPTIONAL; 251 return EME_FEATURE_OPTIONAL;
123 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: 252 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed:
124 return EME_FEATURE_NOT_ALLOWED; 253 return EME_FEATURE_NOT_ALLOWED;
125 } 254 }
126 255
127 NOTREACHED(); 256 NOTREACHED();
128 return EME_FEATURE_NOT_ALLOWED; 257 return EME_FEATURE_NOT_ALLOWED;
129 } 258 }
130 259
131 static ConfigurationSupport GetSupportedConfiguration( 260 static ConfigurationSupport GetSupportedConfiguration(
132 const std::string& key_system, 261 const std::string& key_system,
133 const blink::WebMediaKeySystemConfiguration& candidate, 262 const blink::WebMediaKeySystemConfiguration& candidate,
134 blink::WebMediaKeySystemConfiguration* accumulated_configuration,
135 bool was_permission_requested, 263 bool was_permission_requested,
136 bool is_permission_granted) { 264 bool is_permission_granted,
137 DCHECK(was_permission_requested || !is_permission_granted); 265 blink::WebMediaKeySystemConfiguration* accumulated_configuration) {
138 266 ConfigState config_state(was_permission_requested, is_permission_granted);
139 // It is possible to obtain user permission unless permission was already
140 // requested and denied.
141 bool is_permission_possible =
142 !was_permission_requested || is_permission_granted;
143 267
144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration 268 // From https://w3c.github.io/encrypted-media/#get-supported-configuration
145 // 1. Let accumulated configuration be empty. (Done by caller.) 269 // 1. Let accumulated configuration be empty. (Done by caller.)
146 // 2. If candidate configuration's initDataTypes attribute is not empty, run 270 // 2. If candidate configuration's initDataTypes attribute is not empty, run
147 // the following steps: 271 // the following steps:
148 if (!candidate.initDataTypes.isEmpty()) { 272 if (!candidate.initDataTypes.isEmpty()) {
149 // 2.1. Let supported types be empty. 273 // 2.1. Let supported types be empty.
150 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; 274 std::vector<blink::WebEncryptedMediaInitDataType> supported_types;
151 275
152 // 2.2. For each value in candidate configuration's initDataTypes attribute: 276 // 2.2. For each value in candidate configuration's initDataTypes attribute:
(...skipping 24 matching lines...) Expand all
177 NOTREACHED(); 301 NOTREACHED();
178 break; 302 break;
179 } 303 }
180 if (IsSupportedKeySystemWithInitDataType(key_system, 304 if (IsSupportedKeySystemWithInitDataType(key_system,
181 init_data_type_as_ascii)) { 305 init_data_type_as_ascii)) {
182 supported_types.push_back(init_data_type); 306 supported_types.push_back(init_data_type);
183 } 307 }
184 } 308 }
185 309
186 // 2.3. If supported types is empty, return null. 310 // 2.3. If supported types is empty, return null.
187 if (supported_types.empty()) 311 if (supported_types.empty()) {
312 DVLOG(2) << "Rejecting requested configuration because "
313 << "no initDataType values were supported.";
188 return CONFIGURATION_NOT_SUPPORTED; 314 return CONFIGURATION_NOT_SUPPORTED;
315 }
189 316
190 // 2.4. Add supported types to accumulated configuration. 317 // 2.4. Add supported types to accumulated configuration.
191 accumulated_configuration->initDataTypes = supported_types; 318 accumulated_configuration->initDataTypes = supported_types;
192 } 319 }
193 320
194 // 3. Follow the steps for the value of candidate configuration's 321 // 3. Follow the steps for the value of candidate configuration's
195 // distinctiveIdentifier attribute from the following list: 322 // distinctiveIdentifier attribute from the following list:
196 // - "required": If the implementation does not support a persistent 323 // - "required": If the implementation does not support a persistent
197 // Distinctive Identifier in combination with accumulated configuration, 324 // Distinctive Identifier in combination with accumulated configuration,
198 // return null. 325 // return null.
199 // - "optional": Continue. 326 // - "optional": Continue.
200 // - "not-allowed": If the implementation requires a Distinctive 327 // - "not-allowed": If the implementation requires a Distinctive
201 // Identifier in combination with accumulated configuration, return 328 // Identifier in combination with accumulated configuration, return
202 // null. 329 // null.
203 EmeFeatureRequirement di_requirement = 330 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and
204 ConvertRequirement(candidate.distinctiveIdentifier); 331 // permission has already been denied. This would happen anyway at step 11.
205 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, 332 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule(
206 is_permission_possible)) { 333 key_system, ConvertRequirement(candidate.distinctiveIdentifier));
334 if (!config_state.IsRuleSupported(di_rule)) {
335 DVLOG(2) << "Rejecting requested configuration because "
336 << "the distinctiveIdentifier requirement was not supported.";
207 return CONFIGURATION_NOT_SUPPORTED; 337 return CONFIGURATION_NOT_SUPPORTED;
208 } 338 }
339 config_state.AddRule(di_rule);
209 340
210 // 4. Add the value of the candidate configuration's distinctiveIdentifier 341 // 4. Add the value of the candidate configuration's distinctiveIdentifier
211 // attribute to accumulated configuration. 342 // attribute to accumulated configuration.
212 accumulated_configuration->distinctiveIdentifier = 343 accumulated_configuration->distinctiveIdentifier =
213 candidate.distinctiveIdentifier; 344 candidate.distinctiveIdentifier;
214 345
215 // 5. Follow the steps for the value of candidate configuration's 346 // 5. Follow the steps for the value of candidate configuration's
216 // persistentState attribute from the following list: 347 // persistentState attribute from the following list:
217 // - "required": If the implementation does not support persisting state 348 // - "required": If the implementation does not support persisting state
218 // in combination with accumulated configuration, return null. 349 // in combination with accumulated configuration, return null.
219 // - "optional": Continue. 350 // - "optional": Continue.
220 // - "not-allowed": If the implementation requires persisting state in 351 // - "not-allowed": If the implementation requires persisting state in
221 // combination with accumulated configuration, return null. 352 // combination with accumulated configuration, return null.
222 EmeFeatureRequirement ps_requirement = 353 EmeConfigRule ps_rule = GetPersistentStateConfigRule(
223 ConvertRequirement(candidate.persistentState); 354 key_system, ConvertRequirement(candidate.persistentState));
224 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, 355 if (!config_state.IsRuleSupported(ps_rule)) {
225 is_permission_possible)) { 356 DVLOG(2) << "Rejecting requested configuration because "
357 << "the persistentState requirement was not supported.";
226 return CONFIGURATION_NOT_SUPPORTED; 358 return CONFIGURATION_NOT_SUPPORTED;
227 } 359 }
360 config_state.AddRule(ps_rule);
228 361
229 // 6. Add the value of the candidate configuration's persistentState 362 // 6. Add the value of the candidate configuration's persistentState
230 // attribute to accumulated configuration. 363 // attribute to accumulated configuration.
231 accumulated_configuration->persistentState = candidate.persistentState; 364 accumulated_configuration->persistentState = candidate.persistentState;
232 365
233 // 7. If candidate configuration's videoCapabilities attribute is not empty, 366 // 7. If candidate configuration's videoCapabilities attribute is not empty,
234 // run the following steps: 367 // run the following steps:
235 if (!candidate.videoCapabilities.isEmpty()) { 368 if (!candidate.videoCapabilities.isEmpty()) {
236 // 7.1. Let video capabilities be the result of executing the Get Supported 369 // 7.1. Let video capabilities be the result of executing the Get Supported
237 // Capabilities for Media Type algorithm on Video, candidate 370 // Capabilities for Media Type algorithm on Video, candidate
238 // configuration's videoCapabilities attribute, and accumulated 371 // configuration's videoCapabilities attribute, and accumulated
239 // configuration. 372 // configuration.
240 // 7.2. If video capabilities is null, return null. 373 // 7.2. If video capabilities is null, return null.
241 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; 374 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities;
242 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, 375 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities,
243 &video_capabilities)) { 376 EmeMediaType::VIDEO, &video_capabilities,
377 &config_state)) {
244 return CONFIGURATION_NOT_SUPPORTED; 378 return CONFIGURATION_NOT_SUPPORTED;
245 } 379 }
246 380
247 // 7.3. Add video capabilities to accumulated configuration. 381 // 7.3. Add video capabilities to accumulated configuration.
248 accumulated_configuration->videoCapabilities = video_capabilities; 382 accumulated_configuration->videoCapabilities = video_capabilities;
249 } 383 }
250 384
251 // 8. If candidate configuration's audioCapabilities attribute is not empty, 385 // 8. If candidate configuration's audioCapabilities attribute is not empty,
252 // run the following steps: 386 // run the following steps:
253 if (!candidate.audioCapabilities.isEmpty()) { 387 if (!candidate.audioCapabilities.isEmpty()) {
254 // 8.1. Let audio capabilities be the result of executing the Get Supported 388 // 8.1. Let audio capabilities be the result of executing the Get Supported
255 // Capabilities for Media Type algorithm on Audio, candidate 389 // Capabilities for Media Type algorithm on Audio, candidate
256 // configuration's audioCapabilities attribute, and accumulated 390 // configuration's audioCapabilities attribute, and accumulated
257 // configuration. 391 // configuration.
258 // 8.2. If audio capabilities is null, return null. 392 // 8.2. If audio capabilities is null, return null.
259 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; 393 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities;
260 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, 394 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities,
261 &audio_capabilities)) { 395 EmeMediaType::AUDIO, &audio_capabilities,
396 &config_state)) {
262 return CONFIGURATION_NOT_SUPPORTED; 397 return CONFIGURATION_NOT_SUPPORTED;
263 } 398 }
264 399
265 // 8.3. Add audio capabilities to accumulated configuration. 400 // 8.3. Add audio capabilities to accumulated configuration.
266 accumulated_configuration->audioCapabilities = audio_capabilities; 401 accumulated_configuration->audioCapabilities = audio_capabilities;
267 } 402 }
268 403
269 // 9. If accumulated configuration's distinctiveIdentifier value is 404 // 9. If accumulated configuration's distinctiveIdentifier value is
270 // "optional", follow the steps for the first matching condition from the 405 // "optional", follow the steps for the first matching condition from the
271 // following list: 406 // following list:
272 // - If the implementation requires a Distinctive Identifier for any of 407 // - If the implementation requires a Distinctive Identifier for any of
273 // the combinations in accumulated configuration, change accumulated 408 // the combinations in accumulated configuration, change accumulated
274 // configuration's distinctiveIdentifier value to "required". 409 // configuration's distinctiveIdentifier value to "required".
275 // - Otherwise, change accumulated configuration's distinctiveIdentifier 410 // - Otherwise, change accumulated configuration's distinctiveIdentifier
276 // value to "not-allowed". 411 // value to "not-allowed".
277 // (Without robustness support, capabilities do not affect this.)
278 // TODO(sandersd): Implement robustness. http://crbug.com/442586
279 if (accumulated_configuration->distinctiveIdentifier == 412 if (accumulated_configuration->distinctiveIdentifier ==
280 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 413 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
281 if (IsDistinctiveIdentifierRequirementSupported( 414 EmeConfigRule not_allowed_rule =
282 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { 415 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED);
283 accumulated_configuration->distinctiveIdentifier = 416 EmeConfigRule required_rule =
284 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 417 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED);
285 } else { 418 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule);
419 bool required_supported = config_state.IsRuleSupported(required_rule);
420 if (not_allowed_supported) {
421 bool prefer_required = config_state.IsIdentifierRequired() ||
422 (config_state.IsIdentifierRecommended() &&
423 config_state.IsPermissionPossible());
424 if (required_supported && prefer_required) {
425 accumulated_configuration->distinctiveIdentifier =
426 blink::WebMediaKeySystemConfiguration::Requirement::Required;
427 config_state.AddRule(required_rule);
428 DCHECK(config_state.IsIdentifierRequired());
429 } else {
430 accumulated_configuration->distinctiveIdentifier =
431 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
432 config_state.AddRule(not_allowed_rule);
433 }
434 } else if (required_supported) {
286 accumulated_configuration->distinctiveIdentifier = 435 accumulated_configuration->distinctiveIdentifier =
287 blink::WebMediaKeySystemConfiguration::Requirement::Required; 436 blink::WebMediaKeySystemConfiguration::Requirement::Required;
437 config_state.AddRule(required_rule);
438 } else {
439 // We should not have passed step 3.
440 NOTREACHED();
441 return CONFIGURATION_NOT_SUPPORTED;
288 } 442 }
289 } 443 }
290 444
445 // If permission is required but we couldn't enable it, reject the
446 // configuration.
447 if (config_state.IsIdentifierRequired() &&
448 accumulated_configuration->distinctiveIdentifier !=
449 blink::WebMediaKeySystemConfiguration::Requirement::Required) {
450 DVLOG(2) << "Rejecting requested configuration because "
451 << "distinctiveIdentifier was implicitly required but "
452 << "not allowed.";
453 return CONFIGURATION_NOT_SUPPORTED;
454 }
455
291 // 10. If accumulated configuration's persistentState value is "optional", 456 // 10. If accumulated configuration's persistentState value is "optional",
292 // follow the steps for the first matching condition from the following 457 // follow the steps for the first matching condition from the following
293 // list: 458 // list:
294 // - If the implementation requires persisting state for any of the 459 // - If the implementation requires persisting state for any of the
295 // combinations in accumulated configuration, change accumulated 460 // combinations in accumulated configuration, change accumulated
296 // configuration's persistentState value to "required". 461 // configuration's persistentState value to "required".
297 // - Otherwise, change accumulated configuration's persistentState value 462 // - Otherwise, change accumulated configuration's persistentState value
298 // to "not-allowed". 463 // to "not-allowed".
299 if (accumulated_configuration->persistentState == 464 if (accumulated_configuration->persistentState ==
300 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 465 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
301 if (IsPersistentStateRequirementSupported( 466 EmeConfigRule not_allowed_rule =
302 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { 467 GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED);
468 EmeConfigRule required_rule =
469 GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED);
470 // Now that distinctiveIdentifier has been resolved, it is too late to allow
471 // persistentState to affect the configuration.
472 bool not_allowed_supported =
473 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule);
474 bool required_supported =
475 config_state.IsRuleSupportedWithCurrentState(required_rule);
476 if (not_allowed_supported) {
303 accumulated_configuration->persistentState = 477 accumulated_configuration->persistentState =
304 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 478 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
305 } else { 479 } else if (required_supported) {
306 accumulated_configuration->persistentState = 480 accumulated_configuration->persistentState =
307 blink::WebMediaKeySystemConfiguration::Requirement::Required; 481 blink::WebMediaKeySystemConfiguration::Requirement::Required;
482 } else {
483 // We should not have passed step 5.
484 NOTREACHED();
485 return CONFIGURATION_NOT_SUPPORTED;
308 } 486 }
309 } 487 }
310 488
311 // 11. If implementation in the configuration specified by the combination of 489 // 11. If implementation in the configuration specified by the combination of
312 // the values in accumulated configuration is not supported or not allowed 490 // the values in accumulated configuration is not supported or not allowed
313 // in the origin, return null. 491 // in the origin, return null.
314 di_requirement = 492 // 12. If accumulated configuration's distinctiveIdentifier value is
315 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); 493 // "required", [prompt the user for consent].
316 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, 494 if (accumulated_configuration->distinctiveIdentifier ==
317 is_permission_granted)) { 495 blink::WebMediaKeySystemConfiguration::Requirement::Required) {
318 if (was_permission_requested) { 496 // The caller is responsible for resolving what to do if permission is
319 // The optional permission was requested and denied. 497 // required but has been denied (it should treat it as NOT_SUPPORTED).
320 // TODO(sandersd): Avoid the need for this logic - crbug.com/460616. 498 if (!config_state.IsPermissionGranted())
321 DCHECK(candidate.distinctiveIdentifier ==
322 blink::WebMediaKeySystemConfiguration::Requirement::Optional);
323 DCHECK(di_requirement == EME_FEATURE_REQUIRED);
324 DCHECK(!is_permission_granted);
325 accumulated_configuration->distinctiveIdentifier =
326 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
327 } else {
328 return CONFIGURATION_REQUIRES_PERMISSION; 499 return CONFIGURATION_REQUIRES_PERMISSION;
329 }
330 } 500 }
331 501
332 ps_requirement = 502 // 13. Return accumulated configuration.
333 ConvertRequirement(accumulated_configuration->persistentState); 503 //
334 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, 504 // We also record the available session types so that createSession() can be
335 is_permission_granted)) { 505 // synchronous.
336 DCHECK(!was_permission_requested); // Should have failed at step 5.
337 return CONFIGURATION_REQUIRES_PERMISSION;
338 }
339
340 // 12. Return accumulated configuration.
341 // (As an extra step, we record the available session types so that
342 // createSession() can be synchronous.)
343 std::vector<blink::WebEncryptedMediaSessionType> session_types; 506 std::vector<blink::WebEncryptedMediaSessionType> session_types;
344 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); 507 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary);
345 if (accumulated_configuration->persistentState == 508 if (accumulated_configuration->persistentState ==
346 blink::WebMediaKeySystemConfiguration::Requirement::Required) { 509 blink::WebMediaKeySystemConfiguration::Requirement::Required) {
347 if (IsPersistentLicenseSessionSupported(key_system, 510 if (config_state.IsRuleSupportedWithCurrentState(
348 is_permission_granted)) { 511 GetPersistentLicenseSessionConfigRule(key_system))) {
349 session_types.push_back( 512 session_types.push_back(
350 blink::WebEncryptedMediaSessionType::PersistentLicense); 513 blink::WebEncryptedMediaSessionType::PersistentLicense);
351 } 514 }
352 if (IsPersistentReleaseMessageSessionSupported(key_system, 515 if (config_state.IsRuleSupportedWithCurrentState(
353 is_permission_granted)) { 516 GetPersistentReleaseMessageSessionConfigRule(key_system))) {
354 session_types.push_back( 517 session_types.push_back(
355 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); 518 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage);
356 } 519 }
357 } 520 }
358 accumulated_configuration->sessionTypes = session_types; 521 accumulated_configuration->sessionTypes = session_types;
359 522
360 return CONFIGURATION_SUPPORTED; 523 return CONFIGURATION_SUPPORTED;
361 } 524 }
362 525
363 // Report usage of key system to UMA. There are 2 different counts logged: 526 // Report usage of key system to UMA. There are 2 different counts logged:
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // 7.3.1. Let candidate configuration be the value. 630 // 7.3.1. Let candidate configuration be the value.
468 const blink::WebMediaKeySystemConfiguration& candidate_configuration = 631 const blink::WebMediaKeySystemConfiguration& candidate_configuration =
469 configurations[i]; 632 configurations[i];
470 // 7.3.2. Let supported configuration be the result of executing the Get 633 // 7.3.2. Let supported configuration be the result of executing the Get
471 // Supported Configuration algorithm on implementation, candidate 634 // Supported Configuration algorithm on implementation, candidate
472 // configuration, and origin. 635 // configuration, and origin.
473 // 7.3.3. If supported configuration is not null, [initialize and return a 636 // 7.3.3. If supported configuration is not null, [initialize and return a
474 // new MediaKeySystemAccess object.] 637 // new MediaKeySystemAccess object.]
475 blink::WebMediaKeySystemConfiguration accumulated_configuration; 638 blink::WebMediaKeySystemConfiguration accumulated_configuration;
476 ConfigurationSupport supported = GetSupportedConfiguration( 639 ConfigurationSupport supported = GetSupportedConfiguration(
477 key_system, candidate_configuration, &accumulated_configuration, 640 key_system, candidate_configuration, was_permission_requested,
478 was_permission_requested, is_permission_granted); 641 is_permission_granted, &accumulated_configuration);
479 switch (supported) { 642 switch (supported) {
480 case CONFIGURATION_NOT_SUPPORTED: 643 case CONFIGURATION_NOT_SUPPORTED:
481 continue; 644 continue;
482 case CONFIGURATION_REQUIRES_PERMISSION: 645 case CONFIGURATION_REQUIRES_PERMISSION:
483 DCHECK(!was_permission_requested); 646 if (was_permission_requested) {
647 DVLOG(2) << "Rejecting requested configuration because "
648 << "permission was denied.";
649 continue;
650 }
484 media_permission_->RequestPermission( 651 media_permission_->RequestPermission(
485 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, 652 MediaPermission::PROTECTED_MEDIA_IDENTIFIER,
486 GURL(request.securityOrigin().toString()), 653 GURL(request.securityOrigin().toString()),
487 // Try again with |was_permission_requested| true and 654 // Try again with |was_permission_requested| true and
488 // |is_permission_granted| the value of the permission. 655 // |is_permission_granted| the value of the permission.
489 base::Bind( 656 base::Bind(
490 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, 657 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration,
491 weak_factory_.GetWeakPtr(), request, true)); 658 weak_factory_.GetWeakPtr(), request, true));
492 return; 659 return;
493 case CONFIGURATION_SUPPORTED: 660 case CONFIGURATION_SUPPORTED:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 return reporter; 694 return reporter;
528 695
529 // Reporter not found, so create one. 696 // Reporter not found, so create one.
530 auto result = 697 auto result =
531 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); 698 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name)));
532 DCHECK(result.second); 699 DCHECK(result.second);
533 return result.first->second; 700 return result.first->second;
534 } 701 }
535 702
536 } // namespace media 703 } // namespace media
OLDNEW
« media/base/key_systems.cc ('K') | « media/base/key_systems_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698