OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webencryptedmediaclient_impl.h" | 5 #include "webencryptedmediaclient_impl.h" |
6 | 6 |
7 #include "base/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 Loading... | |
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 { | |
ddorwin
2015/03/19 18:08:35
"CurrentState" implies that the other method (abov
sandersd (OOO until July 31)
2015/03/19 20:05:09
I am trying to remove all unnecessary references t
| |
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 // Was a permission to usa a distinctive identifier requested? | |
ddorwin
2015/03/19 18:08:35
nit: Ending in '?' is a bit weird. Perhaps "Whethe
sandersd (OOO until July 31)
2015/03/19 20:05:09
Done.
| |
116 bool was_permission_requested_; | |
ddorwin
2015/03/19 18:08:35
These first two can be const. That might help read
sandersd (OOO until July 31)
2015/03/19 20:05:09
Done.
| |
117 | |
118 // Do we know that permission to use a distinctive identifier has been | |
119 // granted? | |
120 bool is_permission_granted_; | |
121 | |
122 // Have we added a configuration option that requires a distinctive | |
123 // identifier? | |
124 bool is_identifier_required_; | |
125 | |
126 // Have we added a configuration option that recommends a distinctive | |
127 // identifier? | |
128 bool is_identifier_recommended_; | |
129 }; | |
130 | |
131 static EmeRobustness ConvertRobustness(const blink::WebString& robustness) { | |
132 if (robustness.isEmpty()) | |
133 return EmeRobustness::EMPTY; | |
134 if (robustness == "SW_SECURE_CRYPTO") | |
135 return EmeRobustness::SW_SECURE_CRYPTO; | |
136 if (robustness == "SW_SECURE_DECODE") | |
137 return EmeRobustness::SW_SECURE_DECODE; | |
138 if (robustness == "HW_SECURE_CRYPTO") | |
139 return EmeRobustness::HW_SECURE_CRYPTO; | |
140 if (robustness == "HW_SECURE_DECODE") | |
141 return EmeRobustness::HW_SECURE_DECODE; | |
142 if (robustness == "HW_SECURE_ALL") | |
143 return EmeRobustness::HW_SECURE_ALL; | |
144 return EmeRobustness::INVALID; | |
145 } | |
146 | |
34 static bool IsSupportedContentType(const std::string& key_system, | 147 static bool IsSupportedContentType(const std::string& key_system, |
35 const std::string& mime_type, | 148 const std::string& mime_type, |
36 const std::string& codecs) { | 149 const std::string& codecs) { |
37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid | 150 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
38 // parameters can be rejected. http://crbug.com/417561 | 151 // parameters can be rejected. http://crbug.com/417561 |
39 // TODO(sandersd): Pass in the media type (audio or video) and check that the | 152 // TODO(sandersd): Pass in the media type (audio or video) and check that the |
40 // container type matches. http://crbug.com/457384 | 153 // container type matches. http://crbug.com/457384 |
41 std::string container = base::StringToLowerASCII(mime_type); | 154 std::string container = base::StringToLowerASCII(mime_type); |
42 | 155 |
43 // Check that |codecs| are supported by the CDM. This check does not handle | 156 // Check that |codecs| are supported by the CDM. This check does not handle |
(...skipping 15 matching lines...) Expand all Loading... | |
59 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 | 172 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 |
60 codec_vector.clear(); | 173 codec_vector.clear(); |
61 net::ParseCodecString(codecs, &codec_vector, false); | 174 net::ParseCodecString(codecs, &codec_vector, false); |
62 return net::AreSupportedMediaCodecs(codec_vector); | 175 return net::AreSupportedMediaCodecs(codec_vector); |
63 } | 176 } |
64 | 177 |
65 static bool GetSupportedCapabilities( | 178 static bool GetSupportedCapabilities( |
66 const std::string& key_system, | 179 const std::string& key_system, |
67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& | 180 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
68 capabilities, | 181 capabilities, |
182 EmeMediaType media_type, | |
69 std::vector<blink::WebMediaKeySystemMediaCapability>* | 183 std::vector<blink::WebMediaKeySystemMediaCapability>* |
70 media_type_capabilities) { | 184 media_type_capabilities, |
185 ConfigState* config_state) { | |
71 // From | 186 // From |
72 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type | 187 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type |
73 // 1. Let accumulated capabilities be partial configuration. | 188 // 1. Let accumulated capabilities be partial configuration. |
74 // (Skipped as there are no configuration-based codec restrictions.) | 189 // (Skipped as there are no configuration-based codec restrictions.) |
75 // 2. Let media type capabilities be empty. | 190 // 2. Let media type capabilities be empty. |
76 DCHECK_EQ(media_type_capabilities->size(), 0ul); | 191 DCHECK_EQ(media_type_capabilities->size(), 0ul); |
77 // 3. For each value in capabilities: | 192 // 3. For each value in capabilities: |
78 for (size_t i = 0; i < capabilities.size(); i++) { | 193 for (size_t i = 0; i < 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 = capabilities[i]; |
82 // 3.3. If contentType is the empty string, return null. | 197 // 3.3. If contentType is the empty string, return null. |
83 if (capability.mimeType.isEmpty()) | 198 if (capability.mimeType.isEmpty()) |
84 return false; | 199 return false; |
85 // 3.4-3.11. (Implemented by IsSupportedContentType().) | 200 // 3.4-3.11. (Implemented by IsSupportedContentType().) |
86 if (!base::IsStringASCII(capability.mimeType) || | 201 if (!base::IsStringASCII(capability.mimeType) || |
87 !base::IsStringASCII(capability.codecs) || | 202 !base::IsStringASCII(capability.codecs) || |
88 !IsSupportedContentType(key_system, | 203 !IsSupportedContentType(key_system, |
89 base::UTF16ToASCII(capability.mimeType), | 204 base::UTF16ToASCII(capability.mimeType), |
90 base::UTF16ToASCII(capability.codecs))) { | 205 base::UTF16ToASCII(capability.codecs))) { |
91 continue; | 206 continue; |
92 } | 207 } |
93 // 3.12. If robustness is not the empty string, run the following steps: | 208 // 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()) { | 209 if (!capability.robustness.isEmpty()) { |
97 LOG(WARNING) << "Configuration rejected because rubustness strings are " | 210 // 3.12.1. If robustness is an unrecognized value or not supported by |
98 << "not yet supported."; | 211 // implementation, continue to the next iteration. String |
99 continue; | 212 // comparison is case-sensitive. |
213 EmeConfigRule robustness_rule = GetRobustnessConfigRule( | |
214 key_system, media_type, ConvertRobustness(capability.robustness)); | |
215 if (!config_state->IsRuleSupported(robustness_rule)) | |
216 continue; | |
217 config_state->AddRule(robustness_rule); | |
218 // 3.12.2. Add robustness to configuration. | |
219 // (It's already added, the original object is used directly.) | |
ddorwin
2015/03/19 18:08:35
Suggest: It's added when the original object is pu
sandersd (OOO until July 31)
2015/03/19 20:05:09
Done.
| |
100 } | 220 } |
101 // 3.13. If the user agent and implementation do not support playback of | 221 // 3.13. If the user agent and implementation do not support playback of |
102 // encrypted media data as specified by configuration, including all | 222 // encrypted media data as specified by configuration, including all |
103 // media types, in combination with accumulated capabilities, | 223 // media types, in combination with accumulated capabilities, |
104 // continue to the next iteration. | 224 // continue to the next iteration. |
105 // (Skipped as there are no configuration-based codec restrictions.) | 225 // (Skipped as there are no configuration-based codec restrictions. |
226 // There will be when the Android security level becomes configurable | |
227 // based on robustness. http://crbug.com/467779) | |
106 // 3.14. Add configuration to media type capabilities. | 228 // 3.14. Add configuration to media type capabilities. |
107 media_type_capabilities->push_back(capability); | 229 media_type_capabilities->push_back(capability); |
108 // 3.15. Add configuration to accumulated capabilities. | 230 // 3.15. Add configuration to accumulated capabilities. |
109 // (Skipped as there are no configuration-based codec restrictions.) | 231 // (Skipped as there are no configuration-based codec restrictions. |
232 // Note that this is the local accumulated capabilities, the global | |
233 // one is updated by the caller.) | |
110 } | 234 } |
111 // 4. If media type capabilities is empty, return null. | 235 // 4. If media type capabilities is empty, return null. |
112 // 5. Return media type capabilities. | 236 // 5. Return media type capabilities. |
113 return !media_type_capabilities->empty(); | 237 return !media_type_capabilities->empty(); |
114 } | 238 } |
115 | 239 |
116 static EmeFeatureRequirement ConvertRequirement( | 240 static EmeFeatureRequirement ConvertRequirement( |
117 blink::WebMediaKeySystemConfiguration::Requirement requirement) { | 241 blink::WebMediaKeySystemConfiguration::Requirement requirement) { |
118 switch (requirement) { | 242 switch (requirement) { |
119 case blink::WebMediaKeySystemConfiguration::Requirement::Required: | 243 case blink::WebMediaKeySystemConfiguration::Requirement::Required: |
120 return EME_FEATURE_REQUIRED; | 244 return EME_FEATURE_REQUIRED; |
121 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: | 245 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: |
122 return EME_FEATURE_OPTIONAL; | 246 return EME_FEATURE_OPTIONAL; |
123 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | 247 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
124 return EME_FEATURE_NOT_ALLOWED; | 248 return EME_FEATURE_NOT_ALLOWED; |
125 } | 249 } |
126 | 250 |
127 NOTREACHED(); | 251 NOTREACHED(); |
128 return EME_FEATURE_NOT_ALLOWED; | 252 return EME_FEATURE_NOT_ALLOWED; |
129 } | 253 } |
130 | 254 |
131 static ConfigurationSupport GetSupportedConfiguration( | 255 static ConfigurationSupport GetSupportedConfiguration( |
132 const std::string& key_system, | 256 const std::string& key_system, |
133 const blink::WebMediaKeySystemConfiguration& candidate, | 257 const blink::WebMediaKeySystemConfiguration& candidate, |
134 blink::WebMediaKeySystemConfiguration* accumulated_configuration, | |
135 bool was_permission_requested, | 258 bool was_permission_requested, |
136 bool is_permission_granted) { | 259 bool is_permission_granted, |
137 DCHECK(was_permission_requested || !is_permission_granted); | 260 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
138 | 261 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 | 262 |
144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | 263 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
145 // 1. Let accumulated configuration be empty. (Done by caller.) | 264 // 1. Let accumulated configuration be empty. (Done by caller.) |
146 // 2. If candidate configuration's initDataTypes attribute is not empty, run | 265 // 2. If candidate configuration's initDataTypes attribute is not empty, run |
147 // the following steps: | 266 // the following steps: |
148 if (!candidate.initDataTypes.isEmpty()) { | 267 if (!candidate.initDataTypes.isEmpty()) { |
149 // 2.1. Let supported types be empty. | 268 // 2.1. Let supported types be empty. |
150 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; | 269 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; |
151 | 270 |
152 // 2.2. For each value in candidate configuration's initDataTypes attribute: | 271 // 2.2. For each value in candidate configuration's initDataTypes attribute: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 312 |
194 // 3. Follow the steps for the value of candidate configuration's | 313 // 3. Follow the steps for the value of candidate configuration's |
195 // distinctiveIdentifier attribute from the following list: | 314 // distinctiveIdentifier attribute from the following list: |
196 // - "required": If the implementation does not support a persistent | 315 // - "required": If the implementation does not support a persistent |
197 // Distinctive Identifier in combination with accumulated configuration, | 316 // Distinctive Identifier in combination with accumulated configuration, |
198 // return null. | 317 // return null. |
199 // - "optional": Continue. | 318 // - "optional": Continue. |
200 // - "not-allowed": If the implementation requires a Distinctive | 319 // - "not-allowed": If the implementation requires a Distinctive |
201 // Identifier in combination with accumulated configuration, return | 320 // Identifier in combination with accumulated configuration, return |
202 // null. | 321 // null. |
203 EmeFeatureRequirement di_requirement = | 322 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and |
204 ConvertRequirement(candidate.distinctiveIdentifier); | 323 // permission has already been denied. This would happen anyway at step 11. |
205 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 324 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule( |
206 is_permission_possible)) { | 325 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); |
326 if (!config_state.IsRuleSupported(di_rule)) | |
207 return CONFIGURATION_NOT_SUPPORTED; | 327 return CONFIGURATION_NOT_SUPPORTED; |
208 } | 328 config_state.AddRule(di_rule); |
209 | 329 |
210 // 4. Add the value of the candidate configuration's distinctiveIdentifier | 330 // 4. Add the value of the candidate configuration's distinctiveIdentifier |
211 // attribute to accumulated configuration. | 331 // attribute to accumulated configuration. |
212 accumulated_configuration->distinctiveIdentifier = | 332 accumulated_configuration->distinctiveIdentifier = |
213 candidate.distinctiveIdentifier; | 333 candidate.distinctiveIdentifier; |
214 | 334 |
215 // 5. Follow the steps for the value of candidate configuration's | 335 // 5. Follow the steps for the value of candidate configuration's |
216 // persistentState attribute from the following list: | 336 // persistentState attribute from the following list: |
217 // - "required": If the implementation does not support persisting state | 337 // - "required": If the implementation does not support persisting state |
218 // in combination with accumulated configuration, return null. | 338 // in combination with accumulated configuration, return null. |
219 // - "optional": Continue. | 339 // - "optional": Continue. |
220 // - "not-allowed": If the implementation requires persisting state in | 340 // - "not-allowed": If the implementation requires persisting state in |
221 // combination with accumulated configuration, return null. | 341 // combination with accumulated configuration, return null. |
222 EmeFeatureRequirement ps_requirement = | 342 EmeConfigRule ps_rule = GetPersistentStateConfigRule( |
223 ConvertRequirement(candidate.persistentState); | 343 key_system, ConvertRequirement(candidate.persistentState)); |
224 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | 344 if (!config_state.IsRuleSupported(ps_rule)) |
225 is_permission_possible)) { | |
226 return CONFIGURATION_NOT_SUPPORTED; | 345 return CONFIGURATION_NOT_SUPPORTED; |
227 } | 346 config_state.AddRule(ps_rule); |
228 | 347 |
229 // 6. Add the value of the candidate configuration's persistentState | 348 // 6. Add the value of the candidate configuration's persistentState |
230 // attribute to accumulated configuration. | 349 // attribute to accumulated configuration. |
231 accumulated_configuration->persistentState = candidate.persistentState; | 350 accumulated_configuration->persistentState = candidate.persistentState; |
232 | 351 |
233 // 7. If candidate configuration's videoCapabilities attribute is not empty, | 352 // 7. If candidate configuration's videoCapabilities attribute is not empty, |
234 // run the following steps: | 353 // run the following steps: |
235 if (!candidate.videoCapabilities.isEmpty()) { | 354 if (!candidate.videoCapabilities.isEmpty()) { |
236 // 7.1. Let video capabilities be the result of executing the Get Supported | 355 // 7.1. Let video capabilities be the result of executing the Get Supported |
237 // Capabilities for Media Type algorithm on Video, candidate | 356 // Capabilities for Media Type algorithm on Video, candidate |
238 // configuration's videoCapabilities attribute, and accumulated | 357 // configuration's videoCapabilities attribute, and accumulated |
239 // configuration. | 358 // configuration. |
240 // 7.2. If video capabilities is null, return null. | 359 // 7.2. If video capabilities is null, return null. |
241 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | 360 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; |
242 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, | 361 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, |
243 &video_capabilities)) { | 362 EmeMediaType::VIDEO, &video_capabilities, |
363 &config_state)) { | |
244 return CONFIGURATION_NOT_SUPPORTED; | 364 return CONFIGURATION_NOT_SUPPORTED; |
245 } | 365 } |
246 | 366 |
247 // 7.3. Add video capabilities to accumulated configuration. | 367 // 7.3. Add video capabilities to accumulated configuration. |
248 accumulated_configuration->videoCapabilities = video_capabilities; | 368 accumulated_configuration->videoCapabilities = video_capabilities; |
249 } | 369 } |
250 | 370 |
251 // 8. If candidate configuration's audioCapabilities attribute is not empty, | 371 // 8. If candidate configuration's audioCapabilities attribute is not empty, |
252 // run the following steps: | 372 // run the following steps: |
253 if (!candidate.audioCapabilities.isEmpty()) { | 373 if (!candidate.audioCapabilities.isEmpty()) { |
254 // 8.1. Let audio capabilities be the result of executing the Get Supported | 374 // 8.1. Let audio capabilities be the result of executing the Get Supported |
255 // Capabilities for Media Type algorithm on Audio, candidate | 375 // Capabilities for Media Type algorithm on Audio, candidate |
256 // configuration's audioCapabilities attribute, and accumulated | 376 // configuration's audioCapabilities attribute, and accumulated |
257 // configuration. | 377 // configuration. |
258 // 8.2. If audio capabilities is null, return null. | 378 // 8.2. If audio capabilities is null, return null. |
259 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | 379 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
260 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, | 380 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, |
261 &audio_capabilities)) { | 381 EmeMediaType::AUDIO, &audio_capabilities, |
382 &config_state)) { | |
262 return CONFIGURATION_NOT_SUPPORTED; | 383 return CONFIGURATION_NOT_SUPPORTED; |
263 } | 384 } |
264 | 385 |
265 // 8.3. Add audio capabilities to accumulated configuration. | 386 // 8.3. Add audio capabilities to accumulated configuration. |
266 accumulated_configuration->audioCapabilities = audio_capabilities; | 387 accumulated_configuration->audioCapabilities = audio_capabilities; |
267 } | 388 } |
268 | 389 |
269 // 9. If accumulated configuration's distinctiveIdentifier value is | 390 // 9. If accumulated configuration's distinctiveIdentifier value is |
270 // "optional", follow the steps for the first matching condition from the | 391 // "optional", follow the steps for the first matching condition from the |
271 // following list: | 392 // following list: |
272 // - If the implementation requires a Distinctive Identifier for any of | 393 // - If the implementation requires a Distinctive Identifier for any of |
273 // the combinations in accumulated configuration, change accumulated | 394 // the combinations in accumulated configuration, change accumulated |
274 // configuration's distinctiveIdentifier value to "required". | 395 // configuration's distinctiveIdentifier value to "required". |
275 // - Otherwise, change accumulated configuration's distinctiveIdentifier | 396 // - Otherwise, change accumulated configuration's distinctiveIdentifier |
276 // value to "not-allowed". | 397 // 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 == | 398 if (accumulated_configuration->distinctiveIdentifier == |
280 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 399 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
281 if (IsDistinctiveIdentifierRequirementSupported( | 400 EmeConfigRule not_allowed_rule = |
282 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { | 401 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
283 accumulated_configuration->distinctiveIdentifier = | 402 EmeConfigRule required_rule = |
284 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 403 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED); |
285 } else { | 404 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); |
405 bool required_supported = config_state.IsRuleSupported(required_rule); | |
406 if (not_allowed_supported) { | |
407 bool prefer_required = config_state.IsIdentifierRequired() || | |
408 (config_state.IsIdentifierRecommended() && | |
409 config_state.IsPermissionPossible()); | |
410 if (required_supported && prefer_required) { | |
411 accumulated_configuration->distinctiveIdentifier = | |
412 blink::WebMediaKeySystemConfiguration::Requirement::Required; | |
413 config_state.AddRule(required_rule); | |
414 DCHECK(config_state.IsIdentifierRequired()); | |
415 } else { | |
416 accumulated_configuration->distinctiveIdentifier = | |
417 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
418 config_state.AddRule(not_allowed_rule); | |
419 } | |
420 } else if (required_supported) { | |
286 accumulated_configuration->distinctiveIdentifier = | 421 accumulated_configuration->distinctiveIdentifier = |
287 blink::WebMediaKeySystemConfiguration::Requirement::Required; | 422 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
423 config_state.AddRule(required_rule); | |
424 } else { | |
425 // We should not have passed step 3. | |
426 NOTREACHED(); | |
427 return CONFIGURATION_NOT_SUPPORTED; | |
288 } | 428 } |
289 } | 429 } |
290 | 430 |
431 // If permission is required but we couldn't enable it, reject the | |
432 // configuration. | |
433 if (config_state.IsIdentifierRequired() && | |
434 accumulated_configuration->distinctiveIdentifier != | |
435 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | |
436 return CONFIGURATION_NOT_SUPPORTED; | |
437 } | |
438 | |
291 // 10. If accumulated configuration's persistentState value is "optional", | 439 // 10. If accumulated configuration's persistentState value is "optional", |
292 // follow the steps for the first matching condition from the following | 440 // follow the steps for the first matching condition from the following |
293 // list: | 441 // list: |
294 // - If the implementation requires persisting state for any of the | 442 // - If the implementation requires persisting state for any of the |
295 // combinations in accumulated configuration, change accumulated | 443 // combinations in accumulated configuration, change accumulated |
296 // configuration's persistentState value to "required". | 444 // configuration's persistentState value to "required". |
297 // - Otherwise, change accumulated configuration's persistentState value | 445 // - Otherwise, change accumulated configuration's persistentState value |
298 // to "not-allowed". | 446 // to "not-allowed". |
299 if (accumulated_configuration->persistentState == | 447 if (accumulated_configuration->persistentState == |
300 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 448 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
301 if (IsPersistentStateRequirementSupported( | 449 EmeConfigRule not_allowed_rule = |
302 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { | 450 GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
451 EmeConfigRule required_rule = | |
452 GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED); | |
453 bool not_allowed_supported = | |
454 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule); | |
ddorwin
2015/03/19 18:08:35
It's not obvious to me why we use this method here
sandersd (OOO until July 31)
2015/03/19 20:05:09
That's right. At this point we may accept a rule t
ddorwin
2015/03/19 22:11:57
Should we add a comment pointing this out, either
sandersd (OOO until July 31)
2015/03/19 23:05:43
Done.
| |
455 bool required_supported = | |
456 config_state.IsRuleSupportedWithCurrentState(required_rule); | |
457 if (not_allowed_supported) { | |
303 accumulated_configuration->persistentState = | 458 accumulated_configuration->persistentState = |
304 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 459 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
305 } else { | 460 } else if (required_supported) { |
306 accumulated_configuration->persistentState = | 461 accumulated_configuration->persistentState = |
307 blink::WebMediaKeySystemConfiguration::Requirement::Required; | 462 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
463 } else { | |
464 // We should not have passed step 5. | |
465 NOTREACHED(); | |
466 return CONFIGURATION_NOT_SUPPORTED; | |
308 } | 467 } |
309 } | 468 } |
310 | 469 |
311 // 11. If implementation in the configuration specified by the combination of | 470 // 11. If implementation in the configuration specified by the combination of |
312 // the values in accumulated configuration is not supported or not allowed | 471 // the values in accumulated configuration is not supported or not allowed |
313 // in the origin, return null. | 472 // in the origin, return null. |
314 di_requirement = | 473 // |
315 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); | 474 // If accumulated configuration's distinctiveIdentifier value is |
316 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 475 // "required", [request user consent]. |
317 is_permission_granted)) { | 476 if (accumulated_configuration->distinctiveIdentifier == |
318 if (was_permission_requested) { | 477 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
319 // The optional permission was requested and denied. | 478 if (!config_state.IsPermissionGranted()) |
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; | 479 return CONFIGURATION_REQUIRES_PERMISSION; |
ddorwin
2015/03/19 18:08:35
Is the case where we've already requested the perm
sandersd (OOO until July 31)
2015/03/19 20:05:10
It turned out to remove a lot of cases (and invali
ddorwin
2015/03/19 22:11:57
Okay. Perhaps note that this is handled by the cal
sandersd (OOO until July 31)
2015/03/19 23:05:43
Done.
| |
329 } | |
330 } | |
331 | |
332 ps_requirement = | |
333 ConvertRequirement(accumulated_configuration->persistentState); | |
334 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | |
335 is_permission_granted)) { | |
336 DCHECK(!was_permission_requested); // Should have failed at step 5. | |
337 return CONFIGURATION_REQUIRES_PERMISSION; | |
338 } | 480 } |
339 | 481 |
340 // 12. Return accumulated configuration. | 482 // 12. Return accumulated configuration. |
341 // (As an extra step, we record the available session types so that | 483 // |
342 // createSession() can be synchronous.) | 484 // We also record the available session types so that createSession() can be |
485 // synchronous. | |
343 std::vector<blink::WebEncryptedMediaSessionType> session_types; | 486 std::vector<blink::WebEncryptedMediaSessionType> session_types; |
344 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); | 487 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); |
345 if (accumulated_configuration->persistentState == | 488 if (accumulated_configuration->persistentState == |
346 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | 489 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
347 if (IsPersistentLicenseSessionSupported(key_system, | 490 if (config_state.IsRuleSupportedWithCurrentState( |
ddorwin
2015/03/19 18:08:35
This one is more clear that we're not going to req
sandersd (OOO until July 31)
2015/03/19 20:05:09
Acknowledged.
| |
348 is_permission_granted)) { | 491 GetPersistentLicenseSessionConfigRule(key_system))) { |
349 session_types.push_back( | 492 session_types.push_back( |
350 blink::WebEncryptedMediaSessionType::PersistentLicense); | 493 blink::WebEncryptedMediaSessionType::PersistentLicense); |
351 } | 494 } |
352 if (IsPersistentReleaseMessageSessionSupported(key_system, | 495 if (config_state.IsRuleSupportedWithCurrentState( |
353 is_permission_granted)) { | 496 GetPersistentReleaseMessageSessionConfigRule(key_system))) { |
354 session_types.push_back( | 497 session_types.push_back( |
355 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); | 498 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); |
356 } | 499 } |
357 } | 500 } |
358 accumulated_configuration->sessionTypes = session_types; | 501 accumulated_configuration->sessionTypes = session_types; |
359 | 502 |
360 return CONFIGURATION_SUPPORTED; | 503 return CONFIGURATION_SUPPORTED; |
361 } | 504 } |
362 | 505 |
363 // Report usage of key system to UMA. There are 2 different counts logged: | 506 // 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 Loading... | |
467 // 7.3.1. Let candidate configuration be the value. | 610 // 7.3.1. Let candidate configuration be the value. |
468 const blink::WebMediaKeySystemConfiguration& candidate_configuration = | 611 const blink::WebMediaKeySystemConfiguration& candidate_configuration = |
469 configurations[i]; | 612 configurations[i]; |
470 // 7.3.2. Let supported configuration be the result of executing the Get | 613 // 7.3.2. Let supported configuration be the result of executing the Get |
471 // Supported Configuration algorithm on implementation, candidate | 614 // Supported Configuration algorithm on implementation, candidate |
472 // configuration, and origin. | 615 // configuration, and origin. |
473 // 7.3.3. If supported configuration is not null, [initialize and return a | 616 // 7.3.3. If supported configuration is not null, [initialize and return a |
474 // new MediaKeySystemAccess object.] | 617 // new MediaKeySystemAccess object.] |
475 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 618 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
476 ConfigurationSupport supported = GetSupportedConfiguration( | 619 ConfigurationSupport supported = GetSupportedConfiguration( |
477 key_system, candidate_configuration, &accumulated_configuration, | 620 key_system, candidate_configuration, was_permission_requested, |
478 was_permission_requested, is_permission_granted); | 621 is_permission_granted, &accumulated_configuration); |
479 switch (supported) { | 622 switch (supported) { |
480 case CONFIGURATION_NOT_SUPPORTED: | 623 case CONFIGURATION_NOT_SUPPORTED: |
481 continue; | 624 continue; |
482 case CONFIGURATION_REQUIRES_PERMISSION: | 625 case CONFIGURATION_REQUIRES_PERMISSION: |
483 DCHECK(!was_permission_requested); | 626 if (was_permission_requested) |
ddorwin
2015/03/19 18:08:35
This is the code corresponding to my question at l
sandersd (OOO until July 31)
2015/03/19 20:05:09
Acknowledged.
| |
627 continue; | |
484 media_permission_->RequestPermission( | 628 media_permission_->RequestPermission( |
485 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, | 629 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, |
486 GURL(request.securityOrigin().toString()), | 630 GURL(request.securityOrigin().toString()), |
487 // Try again with |was_permission_requested| true and | 631 // Try again with |was_permission_requested| true and |
488 // |is_permission_granted| the value of the permission. | 632 // |is_permission_granted| the value of the permission. |
489 base::Bind( | 633 base::Bind( |
490 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, | 634 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, |
491 weak_factory_.GetWeakPtr(), request, true)); | 635 weak_factory_.GetWeakPtr(), request, true)); |
492 return; | 636 return; |
493 case CONFIGURATION_SUPPORTED: | 637 case CONFIGURATION_SUPPORTED: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 return reporter; | 671 return reporter; |
528 | 672 |
529 // Reporter not found, so create one. | 673 // Reporter not found, so create one. |
530 auto result = | 674 auto result = |
531 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 675 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
532 DCHECK(result.second); | 676 DCHECK(result.second); |
533 return result.first->second; | 677 return result.first->second; |
534 } | 678 } |
535 | 679 |
536 } // namespace media | 680 } // namespace media |
OLD | NEW |