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 // |
| 37 // Note: The encrypted media permission is equivalent to allowing access |
| 38 // to a distinctive identifier. |
| 39 class ConfigState { |
| 40 public: |
| 41 ConfigState(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 } |
| 46 |
| 47 // The state is invalid if permission is required but has been denied. |
| 48 // It should not be possible to enter an invalid state if only supported rules |
| 49 // are added. |
| 50 bool IsValid() const { |
| 51 return !is_permission_required_ || is_permission_granted_ || |
| 52 !was_permission_requested_; |
| 53 } |
| 54 |
| 55 bool IsPermissionRequired() const { |
| 56 return is_permission_required_; |
| 57 } |
| 58 |
| 59 // Permission should be requested if it is required and had not been denied. |
| 60 bool ShouldRequestPermission() const { |
| 61 return is_permission_required_ && !is_permission_granted_ && |
| 62 !was_permission_requested_; |
| 63 } |
| 64 |
| 65 // Checks whether a rule is compatible with all previously added rules. |
| 66 bool IsRuleSupported(EmeConfigRule rule) const { |
| 67 switch (rule) { |
| 68 case EmeConfigRule::NOT_SUPPORTED: |
| 69 return false; |
| 70 case EmeConfigRule::PERMISSION_REQUIRED: |
| 71 return IsPermissionPossible(); |
| 72 case EmeConfigRule::PERMISSION_RECOMMENDED: |
| 73 return true; |
| 74 case EmeConfigRule::SUPPORTED: |
| 75 return true; |
| 76 } |
| 77 NOTREACHED(); |
| 78 return false; |
| 79 } |
| 80 |
| 81 // Checks whether a rule is compatible with all previously added rules, and |
| 82 // can be accepted without needing to add it to the configuration state. This |
| 83 // allows considering more rules after the configuration state is final (that |
| 84 // is, after distinctiveIdentifier has been resolved). |
| 85 bool IsRuleSupportedWithCurrentState(EmeConfigRule rule) const { |
| 86 switch (rule) { |
| 87 case EmeConfigRule::NOT_SUPPORTED: |
| 88 return false; |
| 89 case EmeConfigRule::PERMISSION_REQUIRED: |
| 90 return is_permission_granted_; |
| 91 case EmeConfigRule::PERMISSION_RECOMMENDED: |
| 92 return true; |
| 93 case EmeConfigRule::SUPPORTED: |
| 94 return true; |
| 95 } |
| 96 NOTREACHED(); |
| 97 return false; |
| 98 } |
| 99 |
| 100 // Add a rule to the accumulated configuration state. |
| 101 void AddRule(EmeConfigRule rule) { |
| 102 switch (rule) { |
| 103 case EmeConfigRule::NOT_SUPPORTED: |
| 104 return; |
| 105 case EmeConfigRule::PERMISSION_REQUIRED: |
| 106 is_permission_required_ = true; |
| 107 return; |
| 108 case EmeConfigRule::PERMISSION_RECOMMENDED: |
| 109 if (IsPermissionPossible()) |
| 110 is_permission_required_ = true; |
| 111 return; |
| 112 case EmeConfigRule::SUPPORTED: |
| 113 return; |
| 114 } |
| 115 NOTREACHED(); |
| 116 } |
| 117 |
| 118 private: |
| 119 // Permission is possible it has not been denied. |
| 120 bool IsPermissionPossible() const { |
| 121 return is_permission_granted_ || !was_permission_requested_; |
| 122 } |
| 123 |
| 124 // Was a permission request made? (If so, is_permission_granted_ can not be |
| 125 // changed by requesting again.) |
| 126 bool was_permission_requested_; |
| 127 |
| 128 // Do we know that permission has been granted? |
| 129 bool is_permission_granted_; |
| 130 |
| 131 // Have we added a configuration option that requires permission? |
| 132 bool is_permission_required_; |
| 133 }; |
| 134 |
| 135 static EmeRobustness ConvertRobustness(const blink::WebString& robustness) { |
| 136 if (robustness.isEmpty()) |
| 137 return EmeRobustness::EMPTY; |
| 138 if (robustness == "SW_SECURE_CRYPTO") |
| 139 return EmeRobustness::SW_SECURE_CRYPTO; |
| 140 if (robustness == "SW_SECURE_DECODE") |
| 141 return EmeRobustness::SW_SECURE_DECODE; |
| 142 if (robustness == "HW_SECURE_CRYPTO") |
| 143 return EmeRobustness::HW_SECURE_CRYPTO; |
| 144 if (robustness == "HW_SECURE_DECODE") |
| 145 return EmeRobustness::HW_SECURE_DECODE; |
| 146 if (robustness == "HW_SECURE_ALL") |
| 147 return EmeRobustness::HW_SECURE_ALL; |
| 148 return EmeRobustness::INVALID; |
| 149 } |
| 150 |
34 static bool IsSupportedContentType(const std::string& key_system, | 151 static bool IsSupportedContentType(const std::string& key_system, |
35 const std::string& mime_type, | 152 const std::string& mime_type, |
36 const std::string& codecs) { | 153 const std::string& codecs) { |
37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid | 154 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
38 // parameters can be rejected. http://crbug.com/417561 | 155 // parameters can be rejected. http://crbug.com/417561 |
39 // TODO(sandersd): Pass in the media type (audio or video) and check that the | 156 // TODO(sandersd): Pass in the media type (audio or video) and check that the |
40 // container type matches. http://crbug.com/457384 | 157 // container type matches. http://crbug.com/457384 |
41 std::string container = base::StringToLowerASCII(mime_type); | 158 std::string container = base::StringToLowerASCII(mime_type); |
42 | 159 |
43 // Check that |codecs| are supported by the CDM. This check does not handle | 160 // 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 | 176 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 |
60 codec_vector.clear(); | 177 codec_vector.clear(); |
61 net::ParseCodecString(codecs, &codec_vector, false); | 178 net::ParseCodecString(codecs, &codec_vector, false); |
62 return net::AreSupportedMediaCodecs(codec_vector); | 179 return net::AreSupportedMediaCodecs(codec_vector); |
63 } | 180 } |
64 | 181 |
65 static bool GetSupportedCapabilities( | 182 static bool GetSupportedCapabilities( |
66 const std::string& key_system, | 183 const std::string& key_system, |
67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& | 184 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
68 capabilities, | 185 capabilities, |
| 186 EmeMediaType media_type, |
69 std::vector<blink::WebMediaKeySystemMediaCapability>* | 187 std::vector<blink::WebMediaKeySystemMediaCapability>* |
70 media_type_capabilities) { | 188 media_type_capabilities, |
| 189 ConfigState* config_state) { |
71 // From | 190 // From |
72 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media
-type | 191 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media
-type |
73 // 1. Let accumulated capabilities be partial configuration. | 192 // 1. Let accumulated capabilities be partial configuration. |
74 // (Skipped as there are no configuration-based codec restrictions.) | 193 // (Skipped as there are no configuration-based codec restrictions.) |
75 // 2. Let media type capabilities be empty. | 194 // 2. Let media type capabilities be empty. |
76 DCHECK_EQ(media_type_capabilities->size(), 0ul); | 195 DCHECK_EQ(media_type_capabilities->size(), 0ul); |
77 // 3. For each value in capabilities: | 196 // 3. For each value in capabilities: |
78 for (size_t i = 0; i < capabilities.size(); i++) { | 197 for (size_t i = 0; i < capabilities.size(); i++) { |
79 // 3.1. Let contentType be the value's contentType member. | 198 // 3.1. Let contentType be the value's contentType member. |
80 // 3.2. Let robustness be the value's robustness member. | 199 // 3.2. Let robustness be the value's robustness member. |
81 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; | 200 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; |
82 // 3.3. If contentType is the empty string, return null. | 201 // 3.3. If contentType is the empty string, return null. |
83 if (capability.mimeType.isEmpty()) | 202 if (capability.mimeType.isEmpty()) |
84 return false; | 203 return false; |
85 // 3.4-3.11. (Implemented by IsSupportedContentType().) | 204 // 3.4-3.11. (Implemented by IsSupportedContentType().) |
86 if (!base::IsStringASCII(capability.mimeType) || | 205 if (!base::IsStringASCII(capability.mimeType) || |
87 !base::IsStringASCII(capability.codecs) || | 206 !base::IsStringASCII(capability.codecs) || |
88 !IsSupportedContentType(key_system, | 207 !IsSupportedContentType(key_system, |
89 base::UTF16ToASCII(capability.mimeType), | 208 base::UTF16ToASCII(capability.mimeType), |
90 base::UTF16ToASCII(capability.codecs))) { | 209 base::UTF16ToASCII(capability.codecs))) { |
91 continue; | 210 continue; |
92 } | 211 } |
93 // 3.12. If robustness is not the empty string, run the following steps: | 212 // 3.12. If robustness is not the empty string, run the following steps: |
94 // (Robustness is not supported.) | |
95 // TODO(sandersd): Implement robustness. http://crbug.com/442586 | |
96 if (!capability.robustness.isEmpty()) { | 213 if (!capability.robustness.isEmpty()) { |
97 LOG(WARNING) << "Configuration rejected because rubustness strings are " | 214 // 3.12.1. If robustness is an unrecognized value or not supported by |
98 << "not yet supported."; | 215 // implementation, continue to the next iteration. String |
99 continue; | 216 // comparison is case-sensitive. |
| 217 EmeConfigRule robustness_rule = GetRobustnessConfigRule( |
| 218 key_system, media_type, ConvertRobustness(capability.robustness)); |
| 219 if (!config_state->IsRuleSupported(robustness_rule)) |
| 220 continue; |
| 221 config_state->AddRule(robustness_rule); |
| 222 // 3.12.2. Add robustness to configuration. |
| 223 // (It's already added, the original object is used directly.) |
100 } | 224 } |
101 // 3.13. If the user agent and implementation do not support playback of | 225 // 3.13. If the user agent and implementation do not support playback of |
102 // encrypted media data as specified by configuration, including all | 226 // encrypted media data as specified by configuration, including all |
103 // media types, in combination with accumulated capabilities, | 227 // media types, in combination with accumulated capabilities, |
104 // continue to the next iteration. | 228 // continue to the next iteration. |
105 // (Skipped as there are no configuration-based codec restrictions.) | 229 // (Skipped as there are no configuration-based codec restrictions. |
| 230 // There will be when the Android security level becomes configurable |
| 231 // based on robustness. http://crbug.com/467779) |
106 // 3.14. Add configuration to media type capabilities. | 232 // 3.14. Add configuration to media type capabilities. |
107 media_type_capabilities->push_back(capability); | 233 media_type_capabilities->push_back(capability); |
108 // 3.15. Add configuration to accumulated capabilities. | 234 // 3.15. Add configuration to accumulated capabilities. |
109 // (Skipped as there are no configuration-based codec restrictions.) | 235 // (Skipped as there are no configuration-based codec restrictions. |
| 236 // Note that this is the local accumulated capabilities, the global |
| 237 // one is updated by the caller.) |
110 } | 238 } |
111 // 4. If media type capabilities is empty, return null. | 239 // 4. If media type capabilities is empty, return null. |
112 // 5. Return media type capabilities. | 240 // 5. Return media type capabilities. |
113 return !media_type_capabilities->empty(); | 241 return !media_type_capabilities->empty(); |
114 } | 242 } |
115 | 243 |
116 static EmeFeatureRequirement ConvertRequirement( | 244 static EmeFeatureRequirement ConvertRequirement( |
117 blink::WebMediaKeySystemConfiguration::Requirement requirement) { | 245 blink::WebMediaKeySystemConfiguration::Requirement requirement) { |
118 switch (requirement) { | 246 switch (requirement) { |
119 case blink::WebMediaKeySystemConfiguration::Requirement::Required: | 247 case blink::WebMediaKeySystemConfiguration::Requirement::Required: |
120 return EME_FEATURE_REQUIRED; | 248 return EME_FEATURE_REQUIRED; |
121 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: | 249 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: |
122 return EME_FEATURE_OPTIONAL; | 250 return EME_FEATURE_OPTIONAL; |
123 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | 251 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
124 return EME_FEATURE_NOT_ALLOWED; | 252 return EME_FEATURE_NOT_ALLOWED; |
125 } | 253 } |
126 | 254 |
127 NOTREACHED(); | 255 NOTREACHED(); |
128 return EME_FEATURE_NOT_ALLOWED; | 256 return EME_FEATURE_NOT_ALLOWED; |
129 } | 257 } |
130 | 258 |
131 static ConfigurationSupport GetSupportedConfiguration( | 259 static ConfigurationSupport GetSupportedConfiguration( |
132 const std::string& key_system, | 260 const std::string& key_system, |
133 const blink::WebMediaKeySystemConfiguration& candidate, | 261 const blink::WebMediaKeySystemConfiguration& candidate, |
134 blink::WebMediaKeySystemConfiguration* accumulated_configuration, | |
135 bool was_permission_requested, | 262 bool was_permission_requested, |
136 bool is_permission_granted) { | 263 bool is_permission_granted, |
137 DCHECK(was_permission_requested || !is_permission_granted); | 264 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
138 | 265 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 | 266 |
144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | 267 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
145 // 1. Let accumulated configuration be empty. (Done by caller.) | 268 // 1. Let accumulated configuration be empty. (Done by caller.) |
146 // 2. If candidate configuration's initDataTypes attribute is not empty, run | 269 // 2. If candidate configuration's initDataTypes attribute is not empty, run |
147 // the following steps: | 270 // the following steps: |
148 if (!candidate.initDataTypes.isEmpty()) { | 271 if (!candidate.initDataTypes.isEmpty()) { |
149 // 2.1. Let supported types be empty. | 272 // 2.1. Let supported types be empty. |
150 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; | 273 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; |
151 | 274 |
152 // 2.2. For each value in candidate configuration's initDataTypes attribute: | 275 // 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 | 316 |
194 // 3. Follow the steps for the value of candidate configuration's | 317 // 3. Follow the steps for the value of candidate configuration's |
195 // distinctiveIdentifier attribute from the following list: | 318 // distinctiveIdentifier attribute from the following list: |
196 // - "required": If the implementation does not support a persistent | 319 // - "required": If the implementation does not support a persistent |
197 // Distinctive Identifier in combination with accumulated configuration, | 320 // Distinctive Identifier in combination with accumulated configuration, |
198 // return null. | 321 // return null. |
199 // - "optional": Continue. | 322 // - "optional": Continue. |
200 // - "not-allowed": If the implementation requires a Distinctive | 323 // - "not-allowed": If the implementation requires a Distinctive |
201 // Identifier in combination with accumulated configuration, return | 324 // Identifier in combination with accumulated configuration, return |
202 // null. | 325 // null. |
203 EmeFeatureRequirement di_requirement = | 326 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and |
204 ConvertRequirement(candidate.distinctiveIdentifier); | 327 // permission has already been denied. This would happen anyway at step 11. |
205 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 328 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule( |
206 is_permission_possible)) { | 329 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); |
| 330 if (!config_state.IsRuleSupported(di_rule)) |
207 return CONFIGURATION_NOT_SUPPORTED; | 331 return CONFIGURATION_NOT_SUPPORTED; |
208 } | 332 config_state.AddRule(di_rule); |
209 | 333 |
210 // 4. Add the value of the candidate configuration's distinctiveIdentifier | 334 // 4. Add the value of the candidate configuration's distinctiveIdentifier |
211 // attribute to accumulated configuration. | 335 // attribute to accumulated configuration. |
212 accumulated_configuration->distinctiveIdentifier = | 336 accumulated_configuration->distinctiveIdentifier = |
213 candidate.distinctiveIdentifier; | 337 candidate.distinctiveIdentifier; |
214 | 338 |
215 // 5. Follow the steps for the value of candidate configuration's | 339 // 5. Follow the steps for the value of candidate configuration's |
216 // persistentState attribute from the following list: | 340 // persistentState attribute from the following list: |
217 // - "required": If the implementation does not support persisting state | 341 // - "required": If the implementation does not support persisting state |
218 // in combination with accumulated configuration, return null. | 342 // in combination with accumulated configuration, return null. |
219 // - "optional": Continue. | 343 // - "optional": Continue. |
220 // - "not-allowed": If the implementation requires persisting state in | 344 // - "not-allowed": If the implementation requires persisting state in |
221 // combination with accumulated configuration, return null. | 345 // combination with accumulated configuration, return null. |
222 EmeFeatureRequirement ps_requirement = | 346 EmeConfigRule ps_rule = GetPersistentStateConfigRule( |
223 ConvertRequirement(candidate.persistentState); | 347 key_system, ConvertRequirement(candidate.persistentState)); |
224 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | 348 if (!config_state.IsRuleSupported(ps_rule)) |
225 is_permission_possible)) { | |
226 return CONFIGURATION_NOT_SUPPORTED; | 349 return CONFIGURATION_NOT_SUPPORTED; |
227 } | 350 config_state.AddRule(ps_rule); |
228 | 351 |
229 // 6. Add the value of the candidate configuration's persistentState | 352 // 6. Add the value of the candidate configuration's persistentState |
230 // attribute to accumulated configuration. | 353 // attribute to accumulated configuration. |
231 accumulated_configuration->persistentState = candidate.persistentState; | 354 accumulated_configuration->persistentState = candidate.persistentState; |
232 | 355 |
233 // 7. If candidate configuration's videoCapabilities attribute is not empty, | 356 // 7. If candidate configuration's videoCapabilities attribute is not empty, |
234 // run the following steps: | 357 // run the following steps: |
235 if (!candidate.videoCapabilities.isEmpty()) { | 358 if (!candidate.videoCapabilities.isEmpty()) { |
236 // 7.1. Let video capabilities be the result of executing the Get Supported | 359 // 7.1. Let video capabilities be the result of executing the Get Supported |
237 // Capabilities for Media Type algorithm on Video, candidate | 360 // Capabilities for Media Type algorithm on Video, candidate |
238 // configuration's videoCapabilities attribute, and accumulated | 361 // configuration's videoCapabilities attribute, and accumulated |
239 // configuration. | 362 // configuration. |
240 // 7.2. If video capabilities is null, return null. | 363 // 7.2. If video capabilities is null, return null. |
241 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | 364 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; |
242 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, | 365 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, |
243 &video_capabilities)) { | 366 EmeMediaType::VIDEO, &video_capabilities, |
| 367 &config_state)) { |
244 return CONFIGURATION_NOT_SUPPORTED; | 368 return CONFIGURATION_NOT_SUPPORTED; |
245 } | 369 } |
246 | 370 |
247 // 7.3. Add video capabilities to accumulated configuration. | 371 // 7.3. Add video capabilities to accumulated configuration. |
248 accumulated_configuration->videoCapabilities = video_capabilities; | 372 accumulated_configuration->videoCapabilities = video_capabilities; |
249 } | 373 } |
250 | 374 |
251 // 8. If candidate configuration's audioCapabilities attribute is not empty, | 375 // 8. If candidate configuration's audioCapabilities attribute is not empty, |
252 // run the following steps: | 376 // run the following steps: |
253 if (!candidate.audioCapabilities.isEmpty()) { | 377 if (!candidate.audioCapabilities.isEmpty()) { |
254 // 8.1. Let audio capabilities be the result of executing the Get Supported | 378 // 8.1. Let audio capabilities be the result of executing the Get Supported |
255 // Capabilities for Media Type algorithm on Audio, candidate | 379 // Capabilities for Media Type algorithm on Audio, candidate |
256 // configuration's audioCapabilities attribute, and accumulated | 380 // configuration's audioCapabilities attribute, and accumulated |
257 // configuration. | 381 // configuration. |
258 // 8.2. If audio capabilities is null, return null. | 382 // 8.2. If audio capabilities is null, return null. |
259 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | 383 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
260 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, | 384 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, |
261 &audio_capabilities)) { | 385 EmeMediaType::AUDIO, &audio_capabilities, |
| 386 &config_state)) { |
262 return CONFIGURATION_NOT_SUPPORTED; | 387 return CONFIGURATION_NOT_SUPPORTED; |
263 } | 388 } |
264 | 389 |
265 // 8.3. Add audio capabilities to accumulated configuration. | 390 // 8.3. Add audio capabilities to accumulated configuration. |
266 accumulated_configuration->audioCapabilities = audio_capabilities; | 391 accumulated_configuration->audioCapabilities = audio_capabilities; |
267 } | 392 } |
268 | 393 |
269 // 9. If accumulated configuration's distinctiveIdentifier value is | 394 // 9. If accumulated configuration's distinctiveIdentifier value is |
270 // "optional", follow the steps for the first matching condition from the | 395 // "optional", follow the steps for the first matching condition from the |
271 // following list: | 396 // following list: |
272 // - If the implementation requires a Distinctive Identifier for any of | 397 // - If the implementation requires a Distinctive Identifier for any of |
273 // the combinations in accumulated configuration, change accumulated | 398 // the combinations in accumulated configuration, change accumulated |
274 // configuration's distinctiveIdentifier value to "required". | 399 // configuration's distinctiveIdentifier value to "required". |
275 // - Otherwise, change accumulated configuration's distinctiveIdentifier | 400 // - Otherwise, change accumulated configuration's distinctiveIdentifier |
276 // value to "not-allowed". | 401 // 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 == | 402 if (accumulated_configuration->distinctiveIdentifier == |
280 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 403 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
281 if (IsDistinctiveIdentifierRequirementSupported( | 404 EmeConfigRule not_allowed_rule = |
282 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { | 405 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
283 accumulated_configuration->distinctiveIdentifier = | 406 EmeConfigRule required_rule = |
284 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 407 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED); |
285 } else { | 408 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); |
| 409 bool required_supported = config_state.IsRuleSupported(required_rule); |
| 410 if (not_allowed_supported) { |
| 411 if (required_supported && config_state.IsPermissionRequired()) { |
| 412 accumulated_configuration->distinctiveIdentifier = |
| 413 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 414 config_state.AddRule(required_rule); |
| 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 // TODO(sandersd): Add configuration rules that will fail if |
| 434 // distinctiveIdentifier is set to 'not-allowed' so that this check won't be |
| 435 // necessary. |
| 436 if (config_state.IsPermissionRequired() && |
| 437 accumulated_configuration->distinctiveIdentifier != |
| 438 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
| 439 return CONFIGURATION_NOT_SUPPORTED; |
| 440 } |
| 441 |
291 // 10. If accumulated configuration's persistentState value is "optional", | 442 // 10. If accumulated configuration's persistentState value is "optional", |
292 // follow the steps for the first matching condition from the following | 443 // follow the steps for the first matching condition from the following |
293 // list: | 444 // list: |
294 // - If the implementation requires persisting state for any of the | 445 // - If the implementation requires persisting state for any of the |
295 // combinations in accumulated configuration, change accumulated | 446 // combinations in accumulated configuration, change accumulated |
296 // configuration's persistentState value to "required". | 447 // configuration's persistentState value to "required". |
297 // - Otherwise, change accumulated configuration's persistentState value | 448 // - Otherwise, change accumulated configuration's persistentState value |
298 // to "not-allowed". | 449 // to "not-allowed". |
299 if (accumulated_configuration->persistentState == | 450 if (accumulated_configuration->persistentState == |
300 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 451 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
301 if (IsPersistentStateRequirementSupported( | 452 EmeConfigRule not_allowed_rule = |
302 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { | 453 GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
| 454 EmeConfigRule required_rule = |
| 455 GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED); |
| 456 bool not_allowed_supported = |
| 457 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule); |
| 458 bool required_supported = |
| 459 config_state.IsRuleSupportedWithCurrentState(required_rule); |
| 460 if (not_allowed_supported) { |
303 accumulated_configuration->persistentState = | 461 accumulated_configuration->persistentState = |
304 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 462 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
305 } else { | 463 } else if (required_supported) { |
306 accumulated_configuration->persistentState = | 464 accumulated_configuration->persistentState = |
307 blink::WebMediaKeySystemConfiguration::Requirement::Required; | 465 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 466 } else { |
| 467 // We should not have passed step 5. |
| 468 NOTREACHED(); |
| 469 return CONFIGURATION_NOT_SUPPORTED; |
308 } | 470 } |
309 } | 471 } |
310 | 472 |
311 // 11. If implementation in the configuration specified by the combination of | 473 // 11. If implementation in the configuration specified by the combination of |
312 // the values in accumulated configuration is not supported or not allowed | 474 // the values in accumulated configuration is not supported or not allowed |
313 // in the origin, return null. | 475 // in the origin, return null. |
314 di_requirement = | 476 // If accumulated configuration's distinctiveIdentifier value is |
315 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); | 477 // "required", [request user consent]. |
316 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 478 if (!config_state.IsValid()) { |
317 is_permission_granted)) { | 479 // This should not be possible, as only supported rules are added. |
318 if (was_permission_requested) { | 480 NOTREACHED(); |
319 // The optional permission was requested and denied. | 481 return CONFIGURATION_NOT_SUPPORTED; |
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 } | 482 } |
331 | 483 |
332 ps_requirement = | 484 // If a permission is required but has not been requested yet, request it now. |
333 ConvertRequirement(accumulated_configuration->persistentState); | 485 if (config_state.ShouldRequestPermission()) |
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; | 486 return CONFIGURATION_REQUIRES_PERMISSION; |
338 } | |
339 | 487 |
340 // 12. Return accumulated configuration. | 488 // 12. Return accumulated configuration. |
341 // (As an extra step, we record the available session types so that | 489 // |
342 // createSession() can be synchronous.) | 490 // We also record the available session types so that createSession() can be |
| 491 // synchronous. |
343 std::vector<blink::WebEncryptedMediaSessionType> session_types; | 492 std::vector<blink::WebEncryptedMediaSessionType> session_types; |
344 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); | 493 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); |
345 if (accumulated_configuration->persistentState == | 494 if (accumulated_configuration->persistentState == |
346 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | 495 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
347 if (IsPersistentLicenseSessionSupported(key_system, | 496 if (config_state.IsRuleSupportedWithCurrentState( |
348 is_permission_granted)) { | 497 GetPersistentLicenseSessionConfigRule(key_system))) { |
349 session_types.push_back( | 498 session_types.push_back( |
350 blink::WebEncryptedMediaSessionType::PersistentLicense); | 499 blink::WebEncryptedMediaSessionType::PersistentLicense); |
351 } | 500 } |
352 if (IsPersistentReleaseMessageSessionSupported(key_system, | 501 if (config_state.IsRuleSupportedWithCurrentState( |
353 is_permission_granted)) { | 502 GetPersistentReleaseMessageSessionConfigRule(key_system))) { |
354 session_types.push_back( | 503 session_types.push_back( |
355 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); | 504 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); |
356 } | 505 } |
357 } | 506 } |
358 accumulated_configuration->sessionTypes = session_types; | 507 accumulated_configuration->sessionTypes = session_types; |
359 | 508 |
360 return CONFIGURATION_SUPPORTED; | 509 return CONFIGURATION_SUPPORTED; |
361 } | 510 } |
362 | 511 |
363 // Report usage of key system to UMA. There are 2 different counts logged: | 512 // 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. | 616 // 7.3.1. Let candidate configuration be the value. |
468 const blink::WebMediaKeySystemConfiguration& candidate_configuration = | 617 const blink::WebMediaKeySystemConfiguration& candidate_configuration = |
469 configurations[i]; | 618 configurations[i]; |
470 // 7.3.2. Let supported configuration be the result of executing the Get | 619 // 7.3.2. Let supported configuration be the result of executing the Get |
471 // Supported Configuration algorithm on implementation, candidate | 620 // Supported Configuration algorithm on implementation, candidate |
472 // configuration, and origin. | 621 // configuration, and origin. |
473 // 7.3.3. If supported configuration is not null, [initialize and return a | 622 // 7.3.3. If supported configuration is not null, [initialize and return a |
474 // new MediaKeySystemAccess object.] | 623 // new MediaKeySystemAccess object.] |
475 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 624 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
476 ConfigurationSupport supported = GetSupportedConfiguration( | 625 ConfigurationSupport supported = GetSupportedConfiguration( |
477 key_system, candidate_configuration, &accumulated_configuration, | 626 key_system, candidate_configuration, was_permission_requested, |
478 was_permission_requested, is_permission_granted); | 627 is_permission_granted, &accumulated_configuration); |
479 switch (supported) { | 628 switch (supported) { |
480 case CONFIGURATION_NOT_SUPPORTED: | 629 case CONFIGURATION_NOT_SUPPORTED: |
481 continue; | 630 continue; |
482 case CONFIGURATION_REQUIRES_PERMISSION: | 631 case CONFIGURATION_REQUIRES_PERMISSION: |
483 DCHECK(!was_permission_requested); | 632 DCHECK(!was_permission_requested); |
484 media_permission_->RequestPermission( | 633 media_permission_->RequestPermission( |
485 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, | 634 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, |
486 GURL(request.securityOrigin().toString()), | 635 GURL(request.securityOrigin().toString()), |
487 // Try again with |was_permission_requested| true and | 636 // Try again with |was_permission_requested| true and |
488 // |is_permission_granted| the value of the permission. | 637 // |is_permission_granted| the value of the permission. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 return reporter; | 676 return reporter; |
528 | 677 |
529 // Reporter not found, so create one. | 678 // Reporter not found, so create one. |
530 auto result = | 679 auto result = |
531 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 680 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
532 DCHECK(result.second); | 681 DCHECK(result.second); |
533 return result.first->second; | 682 return result.first->second; |
534 } | 683 } |
535 | 684 |
536 } // namespace media | 685 } // namespace media |
OLD | NEW |