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

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: 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
« media/base/key_systems.cc ('K') | « media/base/key_systems.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Note: We consider the encrypted media permission to be equivalent to access
35 // to a distinctive identifier, even though they are conceptually distinct. We
36 // may want to separate the concepts in the future to make it possible to
37 // recommend or require permission without providing access to a distinctive
38 // identifier.
39 class PermissionState {
40 public:
41 PermissionState(bool was_permission_requested, bool is_permission_granted)
42 : was_permission_requested_(was_permission_requested),
43 is_permission_granted_(is_permission_granted),
44 is_permission_required_(false),
45 is_permission_recommended_(false) {
46 }
47
48 // Permission state is invalid if permission is required but has been denied.
49 bool IsValid() {
50 return !is_permission_required_ || is_permission_granted_ ||
51 !was_permission_requested_;
52 }
53
54 // Permission is possible it has not been denied.
55 bool IsPermissionPossible() {
56 return is_permission_granted_ || !was_permission_requested_;
57 }
58
59 // Permission is required (read 'should be used') if it is explicitly
60 // required by a requirement, or if it has been recommended and has not
61 // denied.
62 bool IsPermissionRequired() {
63 return is_permission_required_ || (is_permission_recommended_ &&
64 IsPermissionPossible());
65 }
66
67 // A permission request is required if permission is required but has not
68 // been requested yet.
69 bool IsPermissionRequestRequired() {
70 return is_permission_required_ && !is_permission_granted_ &&
71 !was_permission_requested_;
72 }
73
74 bool IsRequirementSupported(EmeRequirementSupport support) {
75 switch (support) {
76 case EME_REQUIREMENT_NOT_SUPPORTED:
77 return false;
78 case EME_REQUIREMENT_SUPPORTED_WITH_PERMISSION:
79 return IsPermissionPossible();
80 case EME_REQUIREMENT_SUPPORTED_PERMISSION_RECOMMENDED:
81 return true;
82 case EME_REQUIREMENT_SUPPORTED:
83 return true;
84 }
85 NOTREACHED();
86 return false;
87 }
88
89 bool IsRequirementSupportedWithoutPrompt(EmeRequirementSupport support) {
90 switch (support) {
91 case EME_REQUIREMENT_NOT_SUPPORTED:
92 return false;
93 case EME_REQUIREMENT_SUPPORTED_WITH_PERMISSION:
94 return is_permission_granted_;
95 case EME_REQUIREMENT_SUPPORTED_PERMISSION_RECOMMENDED:
96 return true;
97 case EME_REQUIREMENT_SUPPORTED:
98 return true;
99 }
100 NOTREACHED();
101 return false;
102 }
103
104 void AddRequirement(EmeRequirementSupport support) {
105 if (support == EME_REQUIREMENT_SUPPORTED_WITH_PERMISSION)
106 is_permission_required_ = true;
107 if (support == EME_REQUIREMENT_SUPPORTED_PERMISSION_RECOMMENDED)
108 is_permission_recommended_ = true;
109 }
110
111 private:
112 bool was_permission_requested_;
113 bool is_permission_granted_;
114 bool is_permission_required_;
115 bool is_permission_recommended_;
116 };
117
118 static EmeRobustness ConvertRobustness(const blink::WebString& robustness) {
119 if (robustness.isEmpty())
120 return EmeRobustness::EMPTY;
121 if (robustness == "SW_SECURE_CRYPTO")
122 return EmeRobustness::SW_SECURE_CRYPTO;
123 if (robustness == "SW_SECURE_DECODE")
124 return EmeRobustness::SW_SECURE_DECODE;
125 if (robustness == "HW_SECURE_CRYPTO")
126 return EmeRobustness::HW_SECURE_CRYPTO;
127 if (robustness == "HW_SECURE_DECODE")
128 return EmeRobustness::HW_SECURE_DECODE;
129 if (robustness == "HW_SECURE_ALL")
130 return EmeRobustness::HW_SECURE_ALL;
131 return EmeRobustness::INVALID;
132 }
133
34 static bool IsSupportedContentType(const std::string& key_system, 134 static bool IsSupportedContentType(const std::string& key_system,
35 const std::string& mime_type, 135 const std::string& mime_type,
36 const std::string& codecs) { 136 const std::string& codecs) {
37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid 137 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid
38 // parameters can be rejected. http://crbug.com/417561 138 // parameters can be rejected. http://crbug.com/417561
39 // TODO(sandersd): Pass in the media type (audio or video) and check that the 139 // TODO(sandersd): Pass in the media type (audio or video) and check that the
40 // container type matches. http://crbug.com/457384 140 // container type matches. http://crbug.com/457384
41 std::string container = base::StringToLowerASCII(mime_type); 141 std::string container = base::StringToLowerASCII(mime_type);
42 142
43 // Check that |codecs| are supported by the CDM. This check does not handle 143 // Check that |codecs| are supported by the CDM. This check does not handle
(...skipping 15 matching lines...) Expand all
59 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 159 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751
60 codec_vector.clear(); 160 codec_vector.clear();
61 net::ParseCodecString(codecs, &codec_vector, false); 161 net::ParseCodecString(codecs, &codec_vector, false);
62 return net::AreSupportedMediaCodecs(codec_vector); 162 return net::AreSupportedMediaCodecs(codec_vector);
63 } 163 }
64 164
65 static bool GetSupportedCapabilities( 165 static bool GetSupportedCapabilities(
66 const std::string& key_system, 166 const std::string& key_system,
67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& 167 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>&
68 capabilities, 168 capabilities,
169 EmeMediaType media_type,
69 std::vector<blink::WebMediaKeySystemMediaCapability>* 170 std::vector<blink::WebMediaKeySystemMediaCapability>*
70 media_type_capabilities) { 171 media_type_capabilities,
172 PermissionState* permission_state) {
71 // From 173 // From
72 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type 174 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type
73 // 1. Let accumulated capabilities be partial configuration. 175 // 1. Let accumulated capabilities be partial configuration.
74 // (Skipped as there are no configuration-based codec restrictions.) 176 // (Skipped as there are no configuration-based codec restrictions.)
75 // 2. Let media type capabilities be empty. 177 // 2. Let media type capabilities be empty.
76 DCHECK_EQ(media_type_capabilities->size(), 0ul); 178 DCHECK_EQ(media_type_capabilities->size(), 0ul);
77 // 3. For each value in capabilities: 179 // 3. For each value in capabilities:
78 for (size_t i = 0; i < capabilities.size(); i++) { 180 for (size_t i = 0; i < capabilities.size(); i++) {
79 // 3.1. Let contentType be the value's contentType member. 181 // 3.1. Let contentType be the value's contentType member.
80 // 3.2. Let robustness be the value's robustness member. 182 // 3.2. Let robustness be the value's robustness member.
81 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; 183 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i];
82 // 3.3. If contentType is the empty string, return null. 184 // 3.3. If contentType is the empty string, return null.
83 if (capability.mimeType.isEmpty()) 185 if (capability.mimeType.isEmpty())
84 return false; 186 return false;
85 // 3.4-3.11. (Implemented by IsSupportedContentType().) 187 // 3.4-3.11. (Implemented by IsSupportedContentType().)
86 if (!base::IsStringASCII(capability.mimeType) || 188 if (!base::IsStringASCII(capability.mimeType) ||
87 !base::IsStringASCII(capability.codecs) || 189 !base::IsStringASCII(capability.codecs) ||
88 !IsSupportedContentType(key_system, 190 !IsSupportedContentType(key_system,
89 base::UTF16ToASCII(capability.mimeType), 191 base::UTF16ToASCII(capability.mimeType),
90 base::UTF16ToASCII(capability.codecs))) { 192 base::UTF16ToASCII(capability.codecs))) {
91 continue; 193 continue;
92 } 194 }
93 // 3.12. If robustness is not the empty string, run the following steps: 195 // 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()) { 196 if (!capability.robustness.isEmpty()) {
97 LOG(WARNING) << "Configuration rejected because rubustness strings are " 197 // 3.12.1. If robustness is an unrecognized value or not supported by
98 << "not yet supported."; 198 // implementation, continue to the next iteration. String
99 continue; 199 // comparison is case-sensitive.
200 EmeRequirementSupport support = GetRobustnessRequirementSupport(
201 key_system, media_type, ConvertRobustness(capability.robustness));
202 if (!permission_state->IsRequirementSupported(support))
203 continue;
204 permission_state->AddRequirement(support);
205 // 3.12.2. Add robustness to configuration.
206 // (It's already added, the original object is used directly.)
100 } 207 }
101 // 3.13. If the user agent and implementation do not support playback of 208 // 3.13. If the user agent and implementation do not support playback of
102 // encrypted media data as specified by configuration, including all 209 // encrypted media data as specified by configuration, including all
103 // media types, in combination with accumulated capabilities, 210 // media types, in combination with accumulated capabilities,
104 // continue to the next iteration. 211 // continue to the next iteration.
105 // (Skipped as there are no configuration-based codec restrictions.) 212 // (Skipped as there are no configuration-based codec restrictions.
213 // There will be when the Android security level becomes configurable
214 // based on robustness.)
106 // 3.14. Add configuration to media type capabilities. 215 // 3.14. Add configuration to media type capabilities.
107 media_type_capabilities->push_back(capability); 216 media_type_capabilities->push_back(capability);
108 // 3.15. Add configuration to accumulated capabilities. 217 // 3.15. Add configuration to accumulated capabilities.
109 // (Skipped as there are no configuration-based codec restrictions.) 218 // (Skipped as there are no configuration-based codec restrictions.
219 // Note that this is the local accumulated capabilities, the global
220 // one is updated by the caller.)
110 } 221 }
111 // 4. If media type capabilities is empty, return null. 222 // 4. If media type capabilities is empty, return null.
112 // 5. Return media type capabilities. 223 // 5. Return media type capabilities.
113 return !media_type_capabilities->empty(); 224 return !media_type_capabilities->empty();
114 } 225 }
115 226
116 static EmeFeatureRequirement ConvertRequirement( 227 static EmeFeatureRequirement ConvertRequirement(
117 blink::WebMediaKeySystemConfiguration::Requirement requirement) { 228 blink::WebMediaKeySystemConfiguration::Requirement requirement) {
118 switch (requirement) { 229 switch (requirement) {
119 case blink::WebMediaKeySystemConfiguration::Requirement::Required: 230 case blink::WebMediaKeySystemConfiguration::Requirement::Required:
120 return EME_FEATURE_REQUIRED; 231 return EME_FEATURE_REQUIRED;
121 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: 232 case blink::WebMediaKeySystemConfiguration::Requirement::Optional:
122 return EME_FEATURE_OPTIONAL; 233 return EME_FEATURE_OPTIONAL;
123 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: 234 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed:
124 return EME_FEATURE_NOT_ALLOWED; 235 return EME_FEATURE_NOT_ALLOWED;
125 } 236 }
126 237
127 NOTREACHED(); 238 NOTREACHED();
128 return EME_FEATURE_NOT_ALLOWED; 239 return EME_FEATURE_NOT_ALLOWED;
129 } 240 }
130 241
131 static ConfigurationSupport GetSupportedConfiguration( 242 static ConfigurationSupport GetSupportedConfiguration(
132 const std::string& key_system, 243 const std::string& key_system,
133 const blink::WebMediaKeySystemConfiguration& candidate, 244 const blink::WebMediaKeySystemConfiguration& candidate,
134 blink::WebMediaKeySystemConfiguration* accumulated_configuration,
135 bool was_permission_requested, 245 bool was_permission_requested,
136 bool is_permission_granted) { 246 bool is_permission_granted,
137 DCHECK(was_permission_requested || !is_permission_granted); 247 blink::WebMediaKeySystemConfiguration* accumulated_configuration) {
138 248 PermissionState permission_state(was_permission_requested,
139 // It is possible to obtain user permission unless permission was already 249 is_permission_granted);
140 // requested and denied.
141 bool is_permission_possible =
142 !was_permission_requested || is_permission_granted;
143 250
144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration 251 // From https://w3c.github.io/encrypted-media/#get-supported-configuration
145 // 1. Let accumulated configuration be empty. (Done by caller.) 252 // 1. Let accumulated configuration be empty. (Done by caller.)
146 // 2. If candidate configuration's initDataTypes attribute is not empty, run 253 // 2. If candidate configuration's initDataTypes attribute is not empty, run
147 // the following steps: 254 // the following steps:
148 if (!candidate.initDataTypes.isEmpty()) { 255 if (!candidate.initDataTypes.isEmpty()) {
149 // 2.1. Let supported types be empty. 256 // 2.1. Let supported types be empty.
150 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; 257 std::vector<blink::WebEncryptedMediaInitDataType> supported_types;
151 258
152 // 2.2. For each value in candidate configuration's initDataTypes attribute: 259 // 2.2. For each value in candidate configuration's initDataTypes attribute:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 300
194 // 3. Follow the steps for the value of candidate configuration's 301 // 3. Follow the steps for the value of candidate configuration's
195 // distinctiveIdentifier attribute from the following list: 302 // distinctiveIdentifier attribute from the following list:
196 // - "required": If the implementation does not support a persistent 303 // - "required": If the implementation does not support a persistent
197 // Distinctive Identifier in combination with accumulated configuration, 304 // Distinctive Identifier in combination with accumulated configuration,
198 // return null. 305 // return null.
199 // - "optional": Continue. 306 // - "optional": Continue.
200 // - "not-allowed": If the implementation requires a Distinctive 307 // - "not-allowed": If the implementation requires a Distinctive
201 // Identifier in combination with accumulated configuration, return 308 // Identifier in combination with accumulated configuration, return
202 // null. 309 // null.
203 EmeFeatureRequirement di_requirement = 310 EmeRequirementSupport di_support = GetDistinctiveIdentifierRequirementSupport(
204 ConvertRequirement(candidate.distinctiveIdentifier); 311 key_system, ConvertRequirement(candidate.distinctiveIdentifier));
205 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, 312 if (!permission_state.IsRequirementSupported(di_support))
206 is_permission_possible)) {
207 return CONFIGURATION_NOT_SUPPORTED; 313 return CONFIGURATION_NOT_SUPPORTED;
208 } 314 permission_state.AddRequirement(di_support);
209 315
210 // 4. Add the value of the candidate configuration's distinctiveIdentifier 316 // 4. Add the value of the candidate configuration's distinctiveIdentifier
211 // attribute to accumulated configuration. 317 // attribute to accumulated configuration.
212 accumulated_configuration->distinctiveIdentifier = 318 accumulated_configuration->distinctiveIdentifier =
213 candidate.distinctiveIdentifier; 319 candidate.distinctiveIdentifier;
214 320
215 // 5. Follow the steps for the value of candidate configuration's 321 // 5. Follow the steps for the value of candidate configuration's
216 // persistentState attribute from the following list: 322 // persistentState attribute from the following list:
217 // - "required": If the implementation does not support persisting state 323 // - "required": If the implementation does not support persisting state
218 // in combination with accumulated configuration, return null. 324 // in combination with accumulated configuration, return null.
219 // - "optional": Continue. 325 // - "optional": Continue.
220 // - "not-allowed": If the implementation requires persisting state in 326 // - "not-allowed": If the implementation requires persisting state in
221 // combination with accumulated configuration, return null. 327 // combination with accumulated configuration, return null.
222 EmeFeatureRequirement ps_requirement = 328 EmeRequirementSupport ps_support = GetPersistentStateRequirementSupport(
223 ConvertRequirement(candidate.persistentState); 329 key_system, ConvertRequirement(candidate.persistentState));
224 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, 330 if (!permission_state.IsRequirementSupported(ps_support))
225 is_permission_possible)) {
226 return CONFIGURATION_NOT_SUPPORTED; 331 return CONFIGURATION_NOT_SUPPORTED;
227 } 332 permission_state.AddRequirement(ps_support);
228 333
229 // 6. Add the value of the candidate configuration's persistentState 334 // 6. Add the value of the candidate configuration's persistentState
230 // attribute to accumulated configuration. 335 // attribute to accumulated configuration.
231 accumulated_configuration->persistentState = candidate.persistentState; 336 accumulated_configuration->persistentState = candidate.persistentState;
232 337
233 // 7. If candidate configuration's videoCapabilities attribute is not empty, 338 // 7. If candidate configuration's videoCapabilities attribute is not empty,
234 // run the following steps: 339 // run the following steps:
235 if (!candidate.videoCapabilities.isEmpty()) { 340 if (!candidate.videoCapabilities.isEmpty()) {
236 // 7.1. Let video capabilities be the result of executing the Get Supported 341 // 7.1. Let video capabilities be the result of executing the Get Supported
237 // Capabilities for Media Type algorithm on Video, candidate 342 // Capabilities for Media Type algorithm on Video, candidate
238 // configuration's videoCapabilities attribute, and accumulated 343 // configuration's videoCapabilities attribute, and accumulated
239 // configuration. 344 // configuration.
240 // 7.2. If video capabilities is null, return null. 345 // 7.2. If video capabilities is null, return null.
241 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; 346 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities;
242 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, 347 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities,
243 &video_capabilities)) { 348 EmeMediaType::VIDEO, &video_capabilities,
349 &permission_state)) {
244 return CONFIGURATION_NOT_SUPPORTED; 350 return CONFIGURATION_NOT_SUPPORTED;
245 } 351 }
246 352
247 // 7.3. Add video capabilities to accumulated configuration. 353 // 7.3. Add video capabilities to accumulated configuration.
248 accumulated_configuration->videoCapabilities = video_capabilities; 354 accumulated_configuration->videoCapabilities = video_capabilities;
249 } 355 }
250 356
251 // 8. If candidate configuration's audioCapabilities attribute is not empty, 357 // 8. If candidate configuration's audioCapabilities attribute is not empty,
252 // run the following steps: 358 // run the following steps:
253 if (!candidate.audioCapabilities.isEmpty()) { 359 if (!candidate.audioCapabilities.isEmpty()) {
254 // 8.1. Let audio capabilities be the result of executing the Get Supported 360 // 8.1. Let audio capabilities be the result of executing the Get Supported
255 // Capabilities for Media Type algorithm on Audio, candidate 361 // Capabilities for Media Type algorithm on Audio, candidate
256 // configuration's audioCapabilities attribute, and accumulated 362 // configuration's audioCapabilities attribute, and accumulated
257 // configuration. 363 // configuration.
258 // 8.2. If audio capabilities is null, return null. 364 // 8.2. If audio capabilities is null, return null.
259 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; 365 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities;
260 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, 366 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities,
261 &audio_capabilities)) { 367 EmeMediaType::AUDIO, &audio_capabilities,
368 &permission_state)) {
262 return CONFIGURATION_NOT_SUPPORTED; 369 return CONFIGURATION_NOT_SUPPORTED;
263 } 370 }
264 371
265 // 8.3. Add audio capabilities to accumulated configuration. 372 // 8.3. Add audio capabilities to accumulated configuration.
266 accumulated_configuration->audioCapabilities = audio_capabilities; 373 accumulated_configuration->audioCapabilities = audio_capabilities;
267 } 374 }
268 375
269 // 9. If accumulated configuration's distinctiveIdentifier value is 376 // 9. If accumulated configuration's distinctiveIdentifier value is
270 // "optional", follow the steps for the first matching condition from the 377 // "optional", follow the steps for the first matching condition from the
271 // following list: 378 // following list:
272 // - If the implementation requires a Distinctive Identifier for any of 379 // - If the implementation requires a Distinctive Identifier for any of
273 // the combinations in accumulated configuration, change accumulated 380 // the combinations in accumulated configuration, change accumulated
274 // configuration's distinctiveIdentifier value to "required". 381 // configuration's distinctiveIdentifier value to "required".
275 // - Otherwise, change accumulated configuration's distinctiveIdentifier 382 // - Otherwise, change accumulated configuration's distinctiveIdentifier
276 // value to "not-allowed". 383 // 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 == 384 if (accumulated_configuration->distinctiveIdentifier ==
280 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 385 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
281 if (IsDistinctiveIdentifierRequirementSupported( 386 EmeRequirementSupport not_allowed_support =
282 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { 387 GetDistinctiveIdentifierRequirementSupport(
388 key_system, EME_FEATURE_NOT_ALLOWED);
389 EmeRequirementSupport required_support =
390 GetDistinctiveIdentifierRequirementSupport(
391 key_system, EME_FEATURE_REQUIRED);
392 bool not_allowed_support_valid =
393 permission_state.IsRequirementSupported(not_allowed_support);
394 bool required_support_valid =
395 permission_state.IsRequirementSupported(required_support);
396 if (not_allowed_support_valid && required_support_valid) {
397 if (permission_state.IsPermissionRequired()) {
398 accumulated_configuration->distinctiveIdentifier =
399 blink::WebMediaKeySystemConfiguration::Requirement::Required;
400 permission_state.AddRequirement(required_support);
401 } else {
402 accumulated_configuration->distinctiveIdentifier =
403 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
404 permission_state.AddRequirement(not_allowed_support);
405 }
406 } else if (not_allowed_support_valid) {
283 accumulated_configuration->distinctiveIdentifier = 407 accumulated_configuration->distinctiveIdentifier =
284 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 408 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
285 } else { 409 permission_state.AddRequirement(not_allowed_support);
410 } else if (required_support_valid) {
286 accumulated_configuration->distinctiveIdentifier = 411 accumulated_configuration->distinctiveIdentifier =
287 blink::WebMediaKeySystemConfiguration::Requirement::Required; 412 blink::WebMediaKeySystemConfiguration::Requirement::Required;
413 permission_state.AddRequirement(required_support);
414 } else {
415 return CONFIGURATION_NOT_SUPPORTED;
288 } 416 }
289 } 417 }
290 418
291 // 10. If accumulated configuration's persistentState value is "optional", 419 // 10. If accumulated configuration's persistentState value is "optional",
292 // follow the steps for the first matching condition from the following 420 // follow the steps for the first matching condition from the following
293 // list: 421 // list:
294 // - If the implementation requires persisting state for any of the 422 // - If the implementation requires persisting state for any of the
295 // combinations in accumulated configuration, change accumulated 423 // combinations in accumulated configuration, change accumulated
296 // configuration's persistentState value to "required". 424 // configuration's persistentState value to "required".
297 // - Otherwise, change accumulated configuration's persistentState value 425 // - Otherwise, change accumulated configuration's persistentState value
298 // to "not-allowed". 426 // to "not-allowed".
299 if (accumulated_configuration->persistentState == 427 if (accumulated_configuration->persistentState ==
300 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 428 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
301 if (IsPersistentStateRequirementSupported( 429 EmeRequirementSupport not_allowed_support =
302 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { 430 GetPersistentStateRequirementSupport(
431 key_system, EME_FEATURE_NOT_ALLOWED);
432 EmeRequirementSupport required_support =
433 GetPersistentStateRequirementSupport(
434 key_system, EME_FEATURE_REQUIRED);
435 bool not_allowed_support_valid =
436 permission_state.IsRequirementSupported(not_allowed_support);
437 bool required_support_valid =
438 permission_state.IsRequirementSupported(required_support);
439 if (not_allowed_support_valid) {
303 accumulated_configuration->persistentState = 440 accumulated_configuration->persistentState =
304 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 441 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
305 } else { 442 permission_state.AddRequirement(not_allowed_support);
443 } else if (required_support_valid) {
306 accumulated_configuration->persistentState = 444 accumulated_configuration->persistentState =
307 blink::WebMediaKeySystemConfiguration::Requirement::Required; 445 blink::WebMediaKeySystemConfiguration::Requirement::Required;
446 permission_state.AddRequirement(required_support);
447 } else {
448 return CONFIGURATION_NOT_SUPPORTED;
308 } 449 }
309 } 450 }
310 451
311 // 11. If implementation in the configuration specified by the combination of 452 // 11. If implementation in the configuration specified by the combination of
312 // the values in accumulated configuration is not supported or not allowed 453 // the values in accumulated configuration is not supported or not allowed
313 // in the origin, return null. 454 // in the origin, return null.
314 di_requirement = 455
315 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); 456 // Enforce that distinctiveIdentifier is equivalent to the encrypted media
316 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, 457 // permission.
317 is_permission_granted)) { 458 if (permission_state.IsPermissionRequired() !=
318 if (was_permission_requested) { 459 (accumulated_configuration->distinctiveIdentifier ==
319 // The optional permission was requested and denied. 460 blink::WebMediaKeySystemConfiguration::Requirement::Required)) {
320 // TODO(sandersd): Avoid the need for this logic - crbug.com/460616. 461 return CONFIGURATION_NOT_SUPPORTED;
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;
329 }
330 } 462 }
331 463
332 ps_requirement = 464 // If the combination of permissions cannot be satisfied, give up.
333 ConvertRequirement(accumulated_configuration->persistentState); 465 if (!permission_state.IsValid())
334 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, 466 return CONFIGURATION_NOT_SUPPORTED;
335 is_permission_granted)) { 467
336 DCHECK(!was_permission_requested); // Should have failed at step 5. 468 // If a permission is required but has not been requested, prompt.
469 if (permission_state.IsPermissionRequestRequired())
337 return CONFIGURATION_REQUIRES_PERMISSION; 470 return CONFIGURATION_REQUIRES_PERMISSION;
338 }
339 471
340 // 12. Return accumulated configuration. 472 // 12. Return accumulated configuration.
341 // (As an extra step, we record the available session types so that 473 // (As an extra step, we record the available session types so that
342 // createSession() can be synchronous.) 474 // createSession() can be synchronous.)
343 std::vector<blink::WebEncryptedMediaSessionType> session_types; 475 std::vector<blink::WebEncryptedMediaSessionType> session_types;
344 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); 476 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary);
345 if (accumulated_configuration->persistentState == 477 if (accumulated_configuration->persistentState ==
346 blink::WebMediaKeySystemConfiguration::Requirement::Required) { 478 blink::WebMediaKeySystemConfiguration::Requirement::Required) {
347 if (IsPersistentLicenseSessionSupported(key_system, 479 // TODO(sandersd): This should happen sooner so that it can affect the
348 is_permission_granted)) { 480 // permission state.
481 if (permission_state.IsRequirementSupportedWithoutPrompt(
482 GetPersistentLicenseSessionSupport(key_system))) {
349 session_types.push_back( 483 session_types.push_back(
350 blink::WebEncryptedMediaSessionType::PersistentLicense); 484 blink::WebEncryptedMediaSessionType::PersistentLicense);
351 } 485 }
352 if (IsPersistentReleaseMessageSessionSupported(key_system, 486 if (permission_state.IsRequirementSupportedWithoutPrompt(
353 is_permission_granted)) { 487 GetPersistentReleaseMessageSessionSupport(key_system))) {
354 session_types.push_back( 488 session_types.push_back(
355 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); 489 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage);
356 } 490 }
357 } 491 }
358 accumulated_configuration->sessionTypes = session_types; 492 accumulated_configuration->sessionTypes = session_types;
359 493
360 return CONFIGURATION_SUPPORTED; 494 return CONFIGURATION_SUPPORTED;
361 } 495 }
362 496
363 // Report usage of key system to UMA. There are 2 different counts logged: 497 // Report usage of key system to UMA. There are 2 different counts logged:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // Report this request to the UMA. 574 // Report this request to the UMA.
441 std::string key_system = base::UTF16ToASCII(request.keySystem()); 575 std::string key_system = base::UTF16ToASCII(request.keySystem());
442 GetReporter(key_system)->ReportRequested(); 576 GetReporter(key_system)->ReportRequested();
443 577
444 if (!IsSupportedKeySystem(key_system)) { 578 if (!IsSupportedKeySystem(key_system)) {
445 request.requestNotSupported("Unsupported keySystem"); 579 request.requestNotSupported("Unsupported keySystem");
446 return; 580 return;
447 } 581 }
448 582
449 // 7.2-7.4. Implemented by SelectSupportedConfiguration(). 583 // 7.2-7.4. Implemented by SelectSupportedConfiguration().
584 // TODO(sandersd): Query the permission first.
450 SelectSupportedConfiguration(request, false, false); 585 SelectSupportedConfiguration(request, false, false);
451 } 586 }
452 587
453 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( 588 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration(
454 blink::WebEncryptedMediaRequest request, 589 blink::WebEncryptedMediaRequest request,
455 bool was_permission_requested, 590 bool was_permission_requested,
456 bool is_permission_granted) { 591 bool is_permission_granted) {
457 // Continued from requestMediaKeySystemAccess(), step 7.1, from 592 // Continued from requestMediaKeySystemAccess(), step 7.1, from
458 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess 593 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
459 // 594 //
460 // 7.2. Let implementation be the implementation of keySystem. 595 // 7.2. Let implementation be the implementation of keySystem.
461 std::string key_system = base::UTF16ToASCII(request.keySystem()); 596 std::string key_system = base::UTF16ToASCII(request.keySystem());
462 597
463 // 7.3. For each value in supportedConfigurations: 598 // 7.3. For each value in supportedConfigurations:
464 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& 599 const blink::WebVector<blink::WebMediaKeySystemConfiguration>&
465 configurations = request.supportedConfigurations(); 600 configurations = request.supportedConfigurations();
466 for (size_t i = 0; i < configurations.size(); i++) { 601 for (size_t i = 0; i < configurations.size(); i++) {
467 // 7.3.1. Let candidate configuration be the value. 602 // 7.3.1. Let candidate configuration be the value.
468 const blink::WebMediaKeySystemConfiguration& candidate_configuration = 603 const blink::WebMediaKeySystemConfiguration& candidate_configuration =
469 configurations[i]; 604 configurations[i];
470 // 7.3.2. Let supported configuration be the result of executing the Get 605 // 7.3.2. Let supported configuration be the result of executing the Get
471 // Supported Configuration algorithm on implementation, candidate 606 // Supported Configuration algorithm on implementation, candidate
472 // configuration, and origin. 607 // configuration, and origin.
473 // 7.3.3. If supported configuration is not null, [initialize and return a 608 // 7.3.3. If supported configuration is not null, [initialize and return a
474 // new MediaKeySystemAccess object.] 609 // new MediaKeySystemAccess object.]
475 blink::WebMediaKeySystemConfiguration accumulated_configuration; 610 blink::WebMediaKeySystemConfiguration accumulated_configuration;
476 ConfigurationSupport supported = GetSupportedConfiguration( 611 ConfigurationSupport supported = GetSupportedConfiguration(
477 key_system, candidate_configuration, &accumulated_configuration, 612 key_system, candidate_configuration, was_permission_requested,
478 was_permission_requested, is_permission_granted); 613 is_permission_granted, &accumulated_configuration);
479 switch (supported) { 614 switch (supported) {
480 case CONFIGURATION_NOT_SUPPORTED: 615 case CONFIGURATION_NOT_SUPPORTED:
481 continue; 616 continue;
482 case CONFIGURATION_REQUIRES_PERMISSION: 617 case CONFIGURATION_REQUIRES_PERMISSION:
483 DCHECK(!was_permission_requested); 618 DCHECK(!was_permission_requested);
484 media_permission_->RequestPermission( 619 media_permission_->RequestPermission(
485 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, 620 MediaPermission::PROTECTED_MEDIA_IDENTIFIER,
486 GURL(request.securityOrigin().toString()), 621 GURL(request.securityOrigin().toString()),
487 // Try again with |was_permission_requested| true and 622 // Try again with |was_permission_requested| true and
488 // |is_permission_granted| the value of the permission. 623 // |is_permission_granted| the value of the permission.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 return reporter; 662 return reporter;
528 663
529 // Reporter not found, so create one. 664 // Reporter not found, so create one.
530 auto result = 665 auto result =
531 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); 666 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name)));
532 DCHECK(result.second); 667 DCHECK(result.second);
533 return result.first->second; 668 return result.first->second;
534 } 669 }
535 670
536 } // namespace media 671 } // namespace media
OLDNEW
« media/base/key_systems.cc ('K') | « media/base/key_systems.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698