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

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: Rename all the things. 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.
ddorwin 2015/03/16 23:25:10 We really need to test this code thoroughly. We ca
sandersd (OOO until July 31) 2015/03/19 20:05:09 I've filed a bug for this, assigned to myself.
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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
(...skipping 12 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 //
37 // Note: We consider the encrypted media permission to be equivalent to access
38 // to a distinctive identifier, even though they are conceptually distinct. We
39 // may want to separate the concepts in the future to make it possible to
40 // recommend or require permission without providing access to a distinctive
41 // identifier.
42 class ConfigState {
43 public:
44 ConfigState(bool was_permission_requested, bool is_permission_granted)
45 : was_permission_requested_(was_permission_requested),
46 is_permission_granted_(is_permission_granted),
47 is_permission_required_(false),
ddorwin 2015/03/16 23:25:09 Use a tri-state enum instead of two bools?
sandersd (OOO until July 31) 2015/03/17 22:10:40 They are actually handled separately, although it
48 is_permission_recommended_(false) {
49 }
50
51 // The state is invalid if permission is required but has been denied.
52 // It should not be possible to enter an invalid state if only supported rules
53 // are added.
54 bool IsValid() {
ddorwin 2015/03/16 23:25:09 const here and below - all except AddRule().
sandersd (OOO until July 31) 2015/03/17 22:10:39 Done.
55 return !is_permission_required_ || is_permission_granted_ ||
56 !was_permission_requested_;
57 }
58
59 // Permission is possible it has not been denied.
60 bool IsPermissionPossible() {
61 return is_permission_granted_ || !was_permission_requested_;
62 }
63
64 // Permission is recommended (read 'should be used') if it is explicitly
65 // required by a requirement, or if it has been recommended and has not
66 // denied.
67 bool IsPermissionRecommended() {
ddorwin 2015/03/16 23:25:08 These two methods are odd and difficult to reason
sandersd (OOO until July 31) 2015/03/17 22:10:39 I went a different direction here but hopefully it
68 return is_permission_required_ || (is_permission_recommended_ &&
69 IsPermissionPossible());
70 }
71
72 // A permission request is required if permission is required but has not
73 // been requested yet.
74 bool IsPermissionRequestRequired() {
ddorwin 2015/03/16 23:25:08 This name is also confusing. It's not just that th
sandersd (OOO until July 31) 2015/03/17 22:10:39 Done.
75 return is_permission_required_ && !is_permission_granted_ &&
ddorwin 2015/03/16 23:25:10 Continued from the IsPermissionRecommended() comme
sandersd (OOO until July 31) 2015/03/17 22:10:40 Acknowledged.
76 !was_permission_requested_;
77 }
78
79 // Checks whether a rule is compatible with all previously added rules.
80 bool IsRuleSupported(EmeConfigRule rule) {
81 switch (rule) {
82 case EmeConfigRule::NOT_SUPPORTED:
83 return false;
84 case EmeConfigRule::PERMISSION_REQUIRED:
85 return IsPermissionPossible();
86 case EmeConfigRule::PERMISSION_RECOMMENDED:
87 return true;
88 case EmeConfigRule::SUPPORTED:
89 return true;
90 }
91 NOTREACHED();
92 return false;
93 }
94
95 // Checks whether a rule is compatible with all previously added rules,
ddorwin 2015/03/16 23:25:09 This doesn't seem consistent with the function nam
sandersd (OOO until July 31) 2015/03/17 22:10:39 Done.
96 // without altering permission state. (This is a hack to allow adding more
97 // rules after the permission request, the correct solution is to always
ddorwin 2015/03/16 23:25:09 Why don't we do that? What's the reason it is this
sandersd (OOO until July 31) 2015/03/17 22:10:40 This is because we don't want session types to aff
98 // request permission last.)
99 bool IsRuleSupportedWithoutPrompt(EmeConfigRule rule) {
ddorwin 2015/03/16 23:25:09 s/Prompt/Permission/ WithoutAnotherRequest? The i
sandersd (OOO until July 31) 2015/03/17 22:10:39 Done.
100 switch (rule) {
101 case EmeConfigRule::NOT_SUPPORTED:
102 return false;
103 case EmeConfigRule::PERMISSION_REQUIRED:
104 return is_permission_granted_;
105 case EmeConfigRule::PERMISSION_RECOMMENDED:
106 return true;
107 case EmeConfigRule::SUPPORTED:
108 return true;
109 }
110 NOTREACHED();
111 return false;
112 }
113
114 // Add a rule to the accumulated configuration state.
115 void AddRule(EmeConfigRule rule) {
116 switch (rule) {
117 case EmeConfigRule::NOT_SUPPORTED:
118 return;
119 case EmeConfigRule::PERMISSION_REQUIRED:
120 is_permission_required_ = true;
121 return;
122 case EmeConfigRule::PERMISSION_RECOMMENDED:
123 is_permission_recommended_ = true;
124 return;
125 case EmeConfigRule::SUPPORTED:
126 return;
127 }
128 NOTREACHED();
129 }
130
131 private:
132 bool was_permission_requested_;
ddorwin 2015/03/16 23:25:09 It might help to explain what this means? I assume
sandersd (OOO until July 31) 2015/03/17 22:10:40 I'm not certain what you mean; a temporary class i
ddorwin 2015/03/19 18:08:35 I was asking when this would be true. As I noted i
sandersd (OOO until July 31) 2015/03/19 20:05:09 Done.
133 bool is_permission_granted_;
134 bool is_permission_required_;
135 bool is_permission_recommended_;
136 };
137
138 static EmeRobustness ConvertRobustness(const blink::WebString& robustness) {
139 if (robustness.isEmpty())
140 return EmeRobustness::EMPTY;
141 if (robustness == "SW_SECURE_CRYPTO")
142 return EmeRobustness::SW_SECURE_CRYPTO;
143 if (robustness == "SW_SECURE_DECODE")
144 return EmeRobustness::SW_SECURE_DECODE;
145 if (robustness == "HW_SECURE_CRYPTO")
146 return EmeRobustness::HW_SECURE_CRYPTO;
147 if (robustness == "HW_SECURE_DECODE")
148 return EmeRobustness::HW_SECURE_DECODE;
149 if (robustness == "HW_SECURE_ALL")
150 return EmeRobustness::HW_SECURE_ALL;
151 return EmeRobustness::INVALID;
152 }
153
34 static bool IsSupportedContentType(const std::string& key_system, 154 static bool IsSupportedContentType(const std::string& key_system,
35 const std::string& mime_type, 155 const std::string& mime_type,
36 const std::string& codecs) { 156 const std::string& codecs) {
37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid 157 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid
38 // parameters can be rejected. http://crbug.com/417561 158 // parameters can be rejected. http://crbug.com/417561
39 // TODO(sandersd): Pass in the media type (audio or video) and check that the 159 // TODO(sandersd): Pass in the media type (audio or video) and check that the
40 // container type matches. http://crbug.com/457384 160 // container type matches. http://crbug.com/457384
41 std::string container = base::StringToLowerASCII(mime_type); 161 std::string container = base::StringToLowerASCII(mime_type);
42 162
43 // Check that |codecs| are supported by the CDM. This check does not handle 163 // 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 179 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751
60 codec_vector.clear(); 180 codec_vector.clear();
61 net::ParseCodecString(codecs, &codec_vector, false); 181 net::ParseCodecString(codecs, &codec_vector, false);
62 return net::AreSupportedMediaCodecs(codec_vector); 182 return net::AreSupportedMediaCodecs(codec_vector);
63 } 183 }
64 184
65 static bool GetSupportedCapabilities( 185 static bool GetSupportedCapabilities(
66 const std::string& key_system, 186 const std::string& key_system,
67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& 187 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>&
68 capabilities, 188 capabilities,
189 EmeMediaType media_type,
69 std::vector<blink::WebMediaKeySystemMediaCapability>* 190 std::vector<blink::WebMediaKeySystemMediaCapability>*
70 media_type_capabilities) { 191 media_type_capabilities,
192 ConfigState* config_state) {
71 // From 193 // From
72 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type 194 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type
73 // 1. Let accumulated capabilities be partial configuration. 195 // 1. Let accumulated capabilities be partial configuration.
74 // (Skipped as there are no configuration-based codec restrictions.) 196 // (Skipped as there are no configuration-based codec restrictions.)
75 // 2. Let media type capabilities be empty. 197 // 2. Let media type capabilities be empty.
76 DCHECK_EQ(media_type_capabilities->size(), 0ul); 198 DCHECK_EQ(media_type_capabilities->size(), 0ul);
77 // 3. For each value in capabilities: 199 // 3. For each value in capabilities:
78 for (size_t i = 0; i < capabilities.size(); i++) { 200 for (size_t i = 0; i < capabilities.size(); i++) {
79 // 3.1. Let contentType be the value's contentType member. 201 // 3.1. Let contentType be the value's contentType member.
80 // 3.2. Let robustness be the value's robustness member. 202 // 3.2. Let robustness be the value's robustness member.
81 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; 203 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i];
82 // 3.3. If contentType is the empty string, return null. 204 // 3.3. If contentType is the empty string, return null.
83 if (capability.mimeType.isEmpty()) 205 if (capability.mimeType.isEmpty())
84 return false; 206 return false;
85 // 3.4-3.11. (Implemented by IsSupportedContentType().) 207 // 3.4-3.11. (Implemented by IsSupportedContentType().)
86 if (!base::IsStringASCII(capability.mimeType) || 208 if (!base::IsStringASCII(capability.mimeType) ||
87 !base::IsStringASCII(capability.codecs) || 209 !base::IsStringASCII(capability.codecs) ||
88 !IsSupportedContentType(key_system, 210 !IsSupportedContentType(key_system,
89 base::UTF16ToASCII(capability.mimeType), 211 base::UTF16ToASCII(capability.mimeType),
90 base::UTF16ToASCII(capability.codecs))) { 212 base::UTF16ToASCII(capability.codecs))) {
91 continue; 213 continue;
92 } 214 }
93 // 3.12. If robustness is not the empty string, run the following steps: 215 // 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()) { 216 if (!capability.robustness.isEmpty()) {
97 LOG(WARNING) << "Configuration rejected because rubustness strings are " 217 // 3.12.1. If robustness is an unrecognized value or not supported by
98 << "not yet supported."; 218 // implementation, continue to the next iteration. String
99 continue; 219 // comparison is case-sensitive.
220 EmeConfigRule robustness_rule = GetRobustnessConfigRule(
221 key_system, media_type, ConvertRobustness(capability.robustness));
222 if (!config_state->IsRuleSupported(robustness_rule))
223 continue;
ddorwin 2015/03/16 23:25:09 It would be nice to expose such results to develop
sandersd (OOO until July 31) 2015/03/19 20:05:09 Done.
224 config_state->AddRule(robustness_rule);
225 // 3.12.2. Add robustness to configuration.
226 // (It's already added, the original object is used directly.)
ddorwin 2015/03/16 23:25:09 by the caller?
sandersd (OOO until July 31) 2015/03/17 22:10:40 No, when we push the capability on to media_type_c
100 } 227 }
101 // 3.13. If the user agent and implementation do not support playback of 228 // 3.13. If the user agent and implementation do not support playback of
102 // encrypted media data as specified by configuration, including all 229 // encrypted media data as specified by configuration, including all
103 // media types, in combination with accumulated capabilities, 230 // media types, in combination with accumulated capabilities,
104 // continue to the next iteration. 231 // continue to the next iteration.
105 // (Skipped as there are no configuration-based codec restrictions.) 232 // (Skipped as there are no configuration-based codec restrictions.
233 // There will be when the Android security level becomes configurable
234 // based on robustness.)
ddorwin 2015/03/16 23:25:09 Bug?
sandersd (OOO until July 31) 2015/03/17 22:10:40 Done.
106 // 3.14. Add configuration to media type capabilities. 235 // 3.14. Add configuration to media type capabilities.
107 media_type_capabilities->push_back(capability); 236 media_type_capabilities->push_back(capability);
108 // 3.15. Add configuration to accumulated capabilities. 237 // 3.15. Add configuration to accumulated capabilities.
109 // (Skipped as there are no configuration-based codec restrictions.) 238 // (Skipped as there are no configuration-based codec restrictions.
239 // Note that this is the local accumulated capabilities, the global
240 // one is updated by the caller.)
110 } 241 }
111 // 4. If media type capabilities is empty, return null. 242 // 4. If media type capabilities is empty, return null.
112 // 5. Return media type capabilities. 243 // 5. Return media type capabilities.
113 return !media_type_capabilities->empty(); 244 return !media_type_capabilities->empty();
114 } 245 }
115 246
116 static EmeFeatureRequirement ConvertRequirement( 247 static EmeFeatureRequirement ConvertRequirement(
117 blink::WebMediaKeySystemConfiguration::Requirement requirement) { 248 blink::WebMediaKeySystemConfiguration::Requirement requirement) {
118 switch (requirement) { 249 switch (requirement) {
119 case blink::WebMediaKeySystemConfiguration::Requirement::Required: 250 case blink::WebMediaKeySystemConfiguration::Requirement::Required:
120 return EME_FEATURE_REQUIRED; 251 return EME_FEATURE_REQUIRED;
121 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: 252 case blink::WebMediaKeySystemConfiguration::Requirement::Optional:
122 return EME_FEATURE_OPTIONAL; 253 return EME_FEATURE_OPTIONAL;
123 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: 254 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed:
124 return EME_FEATURE_NOT_ALLOWED; 255 return EME_FEATURE_NOT_ALLOWED;
125 } 256 }
126 257
127 NOTREACHED(); 258 NOTREACHED();
128 return EME_FEATURE_NOT_ALLOWED; 259 return EME_FEATURE_NOT_ALLOWED;
129 } 260 }
130 261
131 static ConfigurationSupport GetSupportedConfiguration( 262 static ConfigurationSupport GetSupportedConfiguration(
132 const std::string& key_system, 263 const std::string& key_system,
133 const blink::WebMediaKeySystemConfiguration& candidate, 264 const blink::WebMediaKeySystemConfiguration& candidate,
134 blink::WebMediaKeySystemConfiguration* accumulated_configuration,
135 bool was_permission_requested, 265 bool was_permission_requested,
136 bool is_permission_granted) { 266 bool is_permission_granted,
137 DCHECK(was_permission_requested || !is_permission_granted); 267 blink::WebMediaKeySystemConfiguration* accumulated_configuration) {
138 268 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 269
144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration 270 // From https://w3c.github.io/encrypted-media/#get-supported-configuration
145 // 1. Let accumulated configuration be empty. (Done by caller.) 271 // 1. Let accumulated configuration be empty. (Done by caller.)
146 // 2. If candidate configuration's initDataTypes attribute is not empty, run 272 // 2. If candidate configuration's initDataTypes attribute is not empty, run
147 // the following steps: 273 // the following steps:
148 if (!candidate.initDataTypes.isEmpty()) { 274 if (!candidate.initDataTypes.isEmpty()) {
149 // 2.1. Let supported types be empty. 275 // 2.1. Let supported types be empty.
150 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; 276 std::vector<blink::WebEncryptedMediaInitDataType> supported_types;
151 277
152 // 2.2. For each value in candidate configuration's initDataTypes attribute: 278 // 2.2. For each value in candidate configuration's initDataTypes attribute:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 319
194 // 3. Follow the steps for the value of candidate configuration's 320 // 3. Follow the steps for the value of candidate configuration's
195 // distinctiveIdentifier attribute from the following list: 321 // distinctiveIdentifier attribute from the following list:
196 // - "required": If the implementation does not support a persistent 322 // - "required": If the implementation does not support a persistent
197 // Distinctive Identifier in combination with accumulated configuration, 323 // Distinctive Identifier in combination with accumulated configuration,
198 // return null. 324 // return null.
199 // - "optional": Continue. 325 // - "optional": Continue.
200 // - "not-allowed": If the implementation requires a Distinctive 326 // - "not-allowed": If the implementation requires a Distinctive
201 // Identifier in combination with accumulated configuration, return 327 // Identifier in combination with accumulated configuration, return
202 // null. 328 // null.
203 EmeFeatureRequirement di_requirement = 329 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule(
204 ConvertRequirement(candidate.distinctiveIdentifier); 330 key_system, ConvertRequirement(candidate.distinctiveIdentifier));
205 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, 331 if (!config_state.IsRuleSupported(di_rule))
206 is_permission_possible)) {
207 return CONFIGURATION_NOT_SUPPORTED; 332 return CONFIGURATION_NOT_SUPPORTED;
208 } 333 config_state.AddRule(di_rule);
209 334
210 // 4. Add the value of the candidate configuration's distinctiveIdentifier 335 // 4. Add the value of the candidate configuration's distinctiveIdentifier
211 // attribute to accumulated configuration. 336 // attribute to accumulated configuration.
212 accumulated_configuration->distinctiveIdentifier = 337 accumulated_configuration->distinctiveIdentifier =
213 candidate.distinctiveIdentifier; 338 candidate.distinctiveIdentifier;
214 339
215 // 5. Follow the steps for the value of candidate configuration's 340 // 5. Follow the steps for the value of candidate configuration's
216 // persistentState attribute from the following list: 341 // persistentState attribute from the following list:
217 // - "required": If the implementation does not support persisting state 342 // - "required": If the implementation does not support persisting state
218 // in combination with accumulated configuration, return null. 343 // in combination with accumulated configuration, return null.
219 // - "optional": Continue. 344 // - "optional": Continue.
220 // - "not-allowed": If the implementation requires persisting state in 345 // - "not-allowed": If the implementation requires persisting state in
221 // combination with accumulated configuration, return null. 346 // combination with accumulated configuration, return null.
222 EmeFeatureRequirement ps_requirement = 347 EmeConfigRule ps_rule = GetPersistentStateConfigRule(
223 ConvertRequirement(candidate.persistentState); 348 key_system, ConvertRequirement(candidate.persistentState));
224 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, 349 if (!config_state.IsRuleSupported(ps_rule))
225 is_permission_possible)) {
226 return CONFIGURATION_NOT_SUPPORTED; 350 return CONFIGURATION_NOT_SUPPORTED;
227 } 351 config_state.AddRule(ps_rule);
228 352
229 // 6. Add the value of the candidate configuration's persistentState 353 // 6. Add the value of the candidate configuration's persistentState
230 // attribute to accumulated configuration. 354 // attribute to accumulated configuration.
231 accumulated_configuration->persistentState = candidate.persistentState; 355 accumulated_configuration->persistentState = candidate.persistentState;
232 356
233 // 7. If candidate configuration's videoCapabilities attribute is not empty, 357 // 7. If candidate configuration's videoCapabilities attribute is not empty,
234 // run the following steps: 358 // run the following steps:
235 if (!candidate.videoCapabilities.isEmpty()) { 359 if (!candidate.videoCapabilities.isEmpty()) {
236 // 7.1. Let video capabilities be the result of executing the Get Supported 360 // 7.1. Let video capabilities be the result of executing the Get Supported
237 // Capabilities for Media Type algorithm on Video, candidate 361 // Capabilities for Media Type algorithm on Video, candidate
238 // configuration's videoCapabilities attribute, and accumulated 362 // configuration's videoCapabilities attribute, and accumulated
239 // configuration. 363 // configuration.
240 // 7.2. If video capabilities is null, return null. 364 // 7.2. If video capabilities is null, return null.
241 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; 365 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities;
242 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, 366 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities,
243 &video_capabilities)) { 367 EmeMediaType::VIDEO, &video_capabilities,
368 &config_state)) {
244 return CONFIGURATION_NOT_SUPPORTED; 369 return CONFIGURATION_NOT_SUPPORTED;
245 } 370 }
246 371
247 // 7.3. Add video capabilities to accumulated configuration. 372 // 7.3. Add video capabilities to accumulated configuration.
248 accumulated_configuration->videoCapabilities = video_capabilities; 373 accumulated_configuration->videoCapabilities = video_capabilities;
249 } 374 }
250 375
251 // 8. If candidate configuration's audioCapabilities attribute is not empty, 376 // 8. If candidate configuration's audioCapabilities attribute is not empty,
252 // run the following steps: 377 // run the following steps:
253 if (!candidate.audioCapabilities.isEmpty()) { 378 if (!candidate.audioCapabilities.isEmpty()) {
254 // 8.1. Let audio capabilities be the result of executing the Get Supported 379 // 8.1. Let audio capabilities be the result of executing the Get Supported
255 // Capabilities for Media Type algorithm on Audio, candidate 380 // Capabilities for Media Type algorithm on Audio, candidate
256 // configuration's audioCapabilities attribute, and accumulated 381 // configuration's audioCapabilities attribute, and accumulated
257 // configuration. 382 // configuration.
258 // 8.2. If audio capabilities is null, return null. 383 // 8.2. If audio capabilities is null, return null.
259 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; 384 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities;
260 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, 385 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities,
261 &audio_capabilities)) { 386 EmeMediaType::AUDIO, &audio_capabilities,
387 &config_state)) {
262 return CONFIGURATION_NOT_SUPPORTED; 388 return CONFIGURATION_NOT_SUPPORTED;
263 } 389 }
264 390
265 // 8.3. Add audio capabilities to accumulated configuration. 391 // 8.3. Add audio capabilities to accumulated configuration.
266 accumulated_configuration->audioCapabilities = audio_capabilities; 392 accumulated_configuration->audioCapabilities = audio_capabilities;
267 } 393 }
268 394
269 // 9. If accumulated configuration's distinctiveIdentifier value is 395 // 9. If accumulated configuration's distinctiveIdentifier value is
270 // "optional", follow the steps for the first matching condition from the 396 // "optional", follow the steps for the first matching condition from the
271 // following list: 397 // following list:
272 // - If the implementation requires a Distinctive Identifier for any of 398 // - If the implementation requires a Distinctive Identifier for any of
273 // the combinations in accumulated configuration, change accumulated 399 // the combinations in accumulated configuration, change accumulated
274 // configuration's distinctiveIdentifier value to "required". 400 // configuration's distinctiveIdentifier value to "required".
275 // - Otherwise, change accumulated configuration's distinctiveIdentifier 401 // - Otherwise, change accumulated configuration's distinctiveIdentifier
276 // value to "not-allowed". 402 // 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 == 403 if (accumulated_configuration->distinctiveIdentifier ==
280 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 404 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
281 if (IsDistinctiveIdentifierRequirementSupported( 405 EmeConfigRule not_allowed_rule =
282 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { 406 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED);
407 EmeConfigRule required_rule =
408 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED);
409 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule);
410 bool required_supported = config_state.IsRuleSupported(required_rule);
411 if (not_allowed_supported && required_supported) {
ddorwin 2015/03/16 23:25:09 Since we check these both below, this can probably
sandersd (OOO until July 31) 2015/03/17 22:10:39 Done.
412 if (config_state.IsPermissionRecommended()) {
413 accumulated_configuration->distinctiveIdentifier =
414 blink::WebMediaKeySystemConfiguration::Requirement::Required;
415 config_state.AddRule(required_rule);
ddorwin 2015/03/16 23:25:10 Should we add "DCHECK(IsPermissionRequestRequired(
sandersd (OOO until July 31) 2015/03/17 22:10:40 I've changed the definition of AddRule() to set |i
ddorwin 2015/03/19 18:08:35 This reply does not seem to match the change (in P
sandersd (OOO until July 31) 2015/03/19 20:05:09 Acknowledged.
416 } else {
417 accumulated_configuration->distinctiveIdentifier =
418 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
419 config_state.AddRule(not_allowed_rule);
420 }
421 } else if (not_allowed_supported) {
283 accumulated_configuration->distinctiveIdentifier = 422 accumulated_configuration->distinctiveIdentifier =
284 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 423 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
285 } else { 424 config_state.AddRule(not_allowed_rule);
425 } else if (required_supported) {
286 accumulated_configuration->distinctiveIdentifier = 426 accumulated_configuration->distinctiveIdentifier =
287 blink::WebMediaKeySystemConfiguration::Requirement::Required; 427 blink::WebMediaKeySystemConfiguration::Requirement::Required;
428 config_state.AddRule(required_rule);
429 } else {
430 return CONFIGURATION_NOT_SUPPORTED;
ddorwin 2015/03/16 23:25:10 Is this reachable? It seems we should have failed
sandersd (OOO until July 31) 2015/03/17 22:10:40 It was before, but I've fixed up GetDistinctiveIde
sandersd (OOO until July 31) 2015/03/17 22:10:40 Done.
288 } 431 }
289 } 432 }
290 433
291 // 10. If accumulated configuration's persistentState value is "optional", 434 // 10. If accumulated configuration's persistentState value is "optional",
292 // follow the steps for the first matching condition from the following 435 // follow the steps for the first matching condition from the following
293 // list: 436 // list:
294 // - If the implementation requires persisting state for any of the 437 // - If the implementation requires persisting state for any of the
295 // combinations in accumulated configuration, change accumulated 438 // combinations in accumulated configuration, change accumulated
296 // configuration's persistentState value to "required". 439 // configuration's persistentState value to "required".
297 // - Otherwise, change accumulated configuration's persistentState value 440 // - Otherwise, change accumulated configuration's persistentState value
298 // to "not-allowed". 441 // to "not-allowed".
299 if (accumulated_configuration->persistentState == 442 if (accumulated_configuration->persistentState ==
300 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 443 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
301 if (IsPersistentStateRequirementSupported( 444 EmeConfigRule not_allowed_rule =
302 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { 445 GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED);
446 EmeConfigRule required_rule =
447 GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED);
448 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule);
449 bool required_supported = config_state.IsRuleSupported(required_rule);
450 if (not_allowed_supported) {
303 accumulated_configuration->persistentState = 451 accumulated_configuration->persistentState =
304 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 452 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
305 } else { 453 config_state.AddRule(not_allowed_rule);
454 } else if (required_supported) {
306 accumulated_configuration->persistentState = 455 accumulated_configuration->persistentState =
307 blink::WebMediaKeySystemConfiguration::Requirement::Required; 456 blink::WebMediaKeySystemConfiguration::Requirement::Required;
457 config_state.AddRule(required_rule);
458 } else {
459 return CONFIGURATION_NOT_SUPPORTED;
ddorwin 2015/03/16 23:25:10 ditto
sandersd (OOO until July 31) 2015/03/17 22:10:40 Done.
308 } 460 }
309 } 461 }
310 462
311 // 11. If implementation in the configuration specified by the combination of 463 // 11. If implementation in the configuration specified by the combination of
312 // the values in accumulated configuration is not supported or not allowed 464 // the values in accumulated configuration is not supported or not allowed
313 // in the origin, return null. 465 // in the origin, return null.
314 di_requirement = 466 // If accumulated configuration's distinctiveIdentifier value is
315 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); 467 // "required", [request user consent].
316 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement,
317 is_permission_granted)) {
318 if (was_permission_requested) {
319 // The optional permission was requested and denied.
320 // TODO(sandersd): Avoid the need for this logic - crbug.com/460616.
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 }
331 468
332 ps_requirement = 469 // If the combination of permissions cannot be satisfied, give up.
333 ConvertRequirement(accumulated_configuration->persistentState); 470 // TODO(sandersd): Prove that this can't happen.
ddorwin 2015/03/16 23:25:09 Step 1: Add NOTREACHED() :)
sandersd (OOO until July 31) 2015/03/17 22:10:40 Done.
334 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, 471 if (!config_state.IsValid())
335 is_permission_granted)) { 472 return CONFIGURATION_NOT_SUPPORTED;
336 DCHECK(!was_permission_requested); // Should have failed at step 5. 473
474 // If a permission is required but has not been requested, prompt.
ddorwin 2015/03/16 23:25:09 prompt is one possible outcome. Replace with "requ
sandersd (OOO until July 31) 2015/03/17 22:10:40 Done.
475 if (config_state.IsPermissionRequestRequired())
ddorwin 2015/03/16 23:25:10 Initially I wondered, How do we get from preferred
sandersd (OOO until July 31) 2015/03/17 22:10:40 Acknowledged.
337 return CONFIGURATION_REQUIRES_PERMISSION; 476 return CONFIGURATION_REQUIRES_PERMISSION;
338 }
339 477
340 // 12. Return accumulated configuration. 478 // 12. Return accumulated configuration.
341 // (As an extra step, we record the available session types so that 479 // (As an extra step, we record the available session types so that
342 // createSession() can be synchronous.) 480 // createSession() can be synchronous.)
343 std::vector<blink::WebEncryptedMediaSessionType> session_types; 481 std::vector<blink::WebEncryptedMediaSessionType> session_types;
344 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); 482 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary);
345 if (accumulated_configuration->persistentState == 483 if (accumulated_configuration->persistentState ==
346 blink::WebMediaKeySystemConfiguration::Requirement::Required) { 484 blink::WebMediaKeySystemConfiguration::Requirement::Required) {
347 if (IsPersistentLicenseSessionSupported(key_system, 485 // TODO(sandersd): This should happen sooner so that it can affect the
ddorwin 2015/03/16 23:25:09 Is this solved by updating the spec? We would onl
sandersd (OOO until July 31) 2015/03/17 22:10:39 It will be, yes.
348 is_permission_granted)) { 486 // permission state.
487 if (config_state.IsRuleSupportedWithoutPrompt(
488 GetPersistentLicenseSessionConfigRule(key_system))) {
349 session_types.push_back( 489 session_types.push_back(
350 blink::WebEncryptedMediaSessionType::PersistentLicense); 490 blink::WebEncryptedMediaSessionType::PersistentLicense);
351 } 491 }
352 if (IsPersistentReleaseMessageSessionSupported(key_system, 492 if (config_state.IsRuleSupportedWithoutPrompt(
353 is_permission_granted)) { 493 GetPersistentReleaseMessageSessionConfigRule(key_system))) {
354 session_types.push_back( 494 session_types.push_back(
355 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); 495 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage);
356 } 496 }
357 } 497 }
358 accumulated_configuration->sessionTypes = session_types; 498 accumulated_configuration->sessionTypes = session_types;
359 499
360 return CONFIGURATION_SUPPORTED; 500 return CONFIGURATION_SUPPORTED;
361 } 501 }
362 502
363 // Report usage of key system to UMA. There are 2 different counts logged: 503 // 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. 580 // Report this request to the UMA.
441 std::string key_system = base::UTF16ToASCII(request.keySystem()); 581 std::string key_system = base::UTF16ToASCII(request.keySystem());
442 GetReporter(key_system)->ReportRequested(); 582 GetReporter(key_system)->ReportRequested();
443 583
444 if (!IsSupportedKeySystem(key_system)) { 584 if (!IsSupportedKeySystem(key_system)) {
445 request.requestNotSupported("Unsupported keySystem"); 585 request.requestNotSupported("Unsupported keySystem");
446 return; 586 return;
447 } 587 }
448 588
449 // 7.2-7.4. Implemented by SelectSupportedConfiguration(). 589 // 7.2-7.4. Implemented by SelectSupportedConfiguration().
590 // TODO(sandersd): Query the permission first.
ddorwin 2015/03/16 23:25:09 Why? It might shortcut some of the code execution,
sandersd (OOO until July 31) 2015/03/17 22:10:40 Done.
450 SelectSupportedConfiguration(request, false, false); 591 SelectSupportedConfiguration(request, false, false);
451 } 592 }
452 593
453 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( 594 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration(
454 blink::WebEncryptedMediaRequest request, 595 blink::WebEncryptedMediaRequest request,
455 bool was_permission_requested, 596 bool was_permission_requested,
456 bool is_permission_granted) { 597 bool is_permission_granted) {
457 // Continued from requestMediaKeySystemAccess(), step 7.1, from 598 // Continued from requestMediaKeySystemAccess(), step 7.1, from
458 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess 599 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
459 // 600 //
460 // 7.2. Let implementation be the implementation of keySystem. 601 // 7.2. Let implementation be the implementation of keySystem.
461 std::string key_system = base::UTF16ToASCII(request.keySystem()); 602 std::string key_system = base::UTF16ToASCII(request.keySystem());
462 603
463 // 7.3. For each value in supportedConfigurations: 604 // 7.3. For each value in supportedConfigurations:
464 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& 605 const blink::WebVector<blink::WebMediaKeySystemConfiguration>&
465 configurations = request.supportedConfigurations(); 606 configurations = request.supportedConfigurations();
466 for (size_t i = 0; i < configurations.size(); i++) { 607 for (size_t i = 0; i < configurations.size(); i++) {
467 // 7.3.1. Let candidate configuration be the value. 608 // 7.3.1. Let candidate configuration be the value.
468 const blink::WebMediaKeySystemConfiguration& candidate_configuration = 609 const blink::WebMediaKeySystemConfiguration& candidate_configuration =
469 configurations[i]; 610 configurations[i];
470 // 7.3.2. Let supported configuration be the result of executing the Get 611 // 7.3.2. Let supported configuration be the result of executing the Get
471 // Supported Configuration algorithm on implementation, candidate 612 // Supported Configuration algorithm on implementation, candidate
472 // configuration, and origin. 613 // configuration, and origin.
473 // 7.3.3. If supported configuration is not null, [initialize and return a 614 // 7.3.3. If supported configuration is not null, [initialize and return a
474 // new MediaKeySystemAccess object.] 615 // new MediaKeySystemAccess object.]
475 blink::WebMediaKeySystemConfiguration accumulated_configuration; 616 blink::WebMediaKeySystemConfiguration accumulated_configuration;
476 ConfigurationSupport supported = GetSupportedConfiguration( 617 ConfigurationSupport supported = GetSupportedConfiguration(
477 key_system, candidate_configuration, &accumulated_configuration, 618 key_system, candidate_configuration, was_permission_requested,
478 was_permission_requested, is_permission_granted); 619 is_permission_granted, &accumulated_configuration);
479 switch (supported) { 620 switch (supported) {
480 case CONFIGURATION_NOT_SUPPORTED: 621 case CONFIGURATION_NOT_SUPPORTED:
481 continue; 622 continue;
482 case CONFIGURATION_REQUIRES_PERMISSION: 623 case CONFIGURATION_REQUIRES_PERMISSION:
483 DCHECK(!was_permission_requested); 624 DCHECK(!was_permission_requested);
484 media_permission_->RequestPermission( 625 media_permission_->RequestPermission(
485 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, 626 MediaPermission::PROTECTED_MEDIA_IDENTIFIER,
486 GURL(request.securityOrigin().toString()), 627 GURL(request.securityOrigin().toString()),
487 // Try again with |was_permission_requested| true and 628 // Try again with |was_permission_requested| true and
488 // |is_permission_granted| the value of the permission. 629 // |is_permission_granted| the value of the permission.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 return reporter; 668 return reporter;
528 669
529 // Reporter not found, so create one. 670 // Reporter not found, so create one.
530 auto result = 671 auto result =
531 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); 672 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name)));
532 DCHECK(result.second); 673 DCHECK(result.second);
533 return result.first->second; 674 return result.first->second;
534 } 675 }
535 676
536 } // namespace media 677 } // 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