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 { |
| 83 switch (rule) { |
| 84 case EmeConfigRule::NOT_SUPPORTED: |
| 85 return false; |
| 86 case EmeConfigRule::IDENTIFIER_REQUIRED: |
| 87 return is_permission_granted_; |
| 88 case EmeConfigRule::IDENTIFIER_RECOMMENDED: |
| 89 return true; |
| 90 case EmeConfigRule::SUPPORTED: |
| 91 return true; |
| 92 } |
| 93 NOTREACHED(); |
| 94 return false; |
| 95 } |
| 96 |
| 97 // Add a rule to the accumulated configuration state. |
| 98 void AddRule(EmeConfigRule rule) { |
| 99 switch (rule) { |
| 100 case EmeConfigRule::NOT_SUPPORTED: |
| 101 return; |
| 102 case EmeConfigRule::IDENTIFIER_REQUIRED: |
| 103 is_identifier_required_ = true; |
| 104 return; |
| 105 case EmeConfigRule::IDENTIFIER_RECOMMENDED: |
| 106 is_identifier_recommended_ = true; |
| 107 return; |
| 108 case EmeConfigRule::SUPPORTED: |
| 109 return; |
| 110 } |
| 111 NOTREACHED(); |
| 112 } |
| 113 |
| 114 private: |
| 115 // Whether permission to use a distinctive identifier was requested. If set, |
| 116 // |is_permission_granted_| represents the final decision. |
| 117 const bool was_permission_requested_; |
| 118 |
| 119 // Whether permission to use a distinctive identifier has been granted. |
| 120 const bool is_permission_granted_; |
| 121 |
| 122 // Whether a rule has been added that requires a distinctive identifier. |
| 123 bool is_identifier_required_; |
| 124 |
| 125 // Whether a rule has been added that recommends a distinctive identifier. |
| 126 bool is_identifier_recommended_; |
| 127 }; |
| 128 |
34 static bool IsSupportedContentType(const std::string& key_system, | 129 static bool IsSupportedContentType(const std::string& key_system, |
35 const std::string& mime_type, | 130 const std::string& mime_type, |
36 const std::string& codecs) { | 131 const std::string& codecs) { |
37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid | 132 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
38 // parameters can be rejected. http://crbug.com/417561 | 133 // parameters can be rejected. http://crbug.com/417561 |
39 // TODO(sandersd): Pass in the media type (audio or video) and check that the | 134 // TODO(sandersd): Pass in the media type (audio or video) and check that the |
40 // container type matches. http://crbug.com/457384 | 135 // container type matches. http://crbug.com/457384 |
41 std::string container = base::StringToLowerASCII(mime_type); | 136 std::string container = base::StringToLowerASCII(mime_type); |
42 | 137 |
43 // Check that |codecs| are supported by the CDM. This check does not handle | 138 // Check that |codecs| are supported by the CDM. This check does not handle |
(...skipping 14 matching lines...) Expand all Loading... |
58 // decode is required). | 153 // decode is required). |
59 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 | 154 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 |
60 codec_vector.clear(); | 155 codec_vector.clear(); |
61 net::ParseCodecString(codecs, &codec_vector, false); | 156 net::ParseCodecString(codecs, &codec_vector, false); |
62 return net::AreSupportedMediaCodecs(codec_vector); | 157 return net::AreSupportedMediaCodecs(codec_vector); |
63 } | 158 } |
64 | 159 |
65 static bool GetSupportedCapabilities( | 160 static bool GetSupportedCapabilities( |
66 const std::string& key_system, | 161 const std::string& key_system, |
67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& | 162 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
68 capabilities, | 163 requested_media_capabilities, |
| 164 EmeMediaType media_type, |
69 std::vector<blink::WebMediaKeySystemMediaCapability>* | 165 std::vector<blink::WebMediaKeySystemMediaCapability>* |
70 media_type_capabilities) { | 166 supported_media_capabilities, |
| 167 ConfigState* config_state) { |
71 // From | 168 // From |
72 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media
-type | 169 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media
-type |
73 // 1. Let accumulated capabilities be partial configuration. | 170 // 1. Let local accumulated capabilities be a local copy of partial |
74 // (Skipped as there are no configuration-based codec restrictions.) | 171 // configuration. |
75 // 2. Let media type capabilities be empty. | 172 // (Skipped as we directly update |config_state|. This is safe because we |
76 DCHECK_EQ(media_type_capabilities->size(), 0ul); | 173 // only do so when at least one requested media capability is supported.) |
77 // 3. For each value in capabilities: | 174 // 2. Let supported media capabilities be empty. |
78 for (size_t i = 0; i < capabilities.size(); i++) { | 175 DCHECK_EQ(supported_media_capabilities->size(), 0ul); |
| 176 // 3. For each value in requested media capabilities: |
| 177 for (size_t i = 0; i < requested_media_capabilities.size(); i++) { |
79 // 3.1. Let contentType be the value's contentType member. | 178 // 3.1. Let contentType be the value's contentType member. |
80 // 3.2. Let robustness be the value's robustness member. | 179 // 3.2. Let robustness be the value's robustness member. |
81 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; | 180 const blink::WebMediaKeySystemMediaCapability& capability = |
| 181 requested_media_capabilities[i]; |
82 // 3.3. If contentType is the empty string, return null. | 182 // 3.3. If contentType is the empty string, return null. |
83 if (capability.mimeType.isEmpty()) | 183 if (capability.mimeType.isEmpty()) { |
| 184 DVLOG(2) << "Rejecting requested configuration because " |
| 185 << "a capability contentType was empty."; |
84 return false; | 186 return false; |
| 187 } |
85 // 3.4-3.11. (Implemented by IsSupportedContentType().) | 188 // 3.4-3.11. (Implemented by IsSupportedContentType().) |
86 if (!base::IsStringASCII(capability.mimeType) || | 189 if (!base::IsStringASCII(capability.mimeType) || |
87 !base::IsStringASCII(capability.codecs) || | 190 !base::IsStringASCII(capability.codecs) || |
88 !IsSupportedContentType(key_system, | 191 !IsSupportedContentType(key_system, |
89 base::UTF16ToASCII(capability.mimeType), | 192 base::UTF16ToASCII(capability.mimeType), |
90 base::UTF16ToASCII(capability.codecs))) { | 193 base::UTF16ToASCII(capability.codecs))) { |
91 continue; | 194 continue; |
92 } | 195 } |
93 // 3.12. If robustness is not the empty string, run the following steps: | 196 // 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()) { | 197 if (!capability.robustness.isEmpty()) { |
97 LOG(WARNING) << "Configuration rejected because rubustness strings are " | 198 // 3.12.1. If robustness is an unrecognized value or not supported by |
98 << "not yet supported."; | 199 // implementation, continue to the next iteration. String |
99 continue; | 200 // comparison is case-sensitive. |
| 201 if (!base::IsStringASCII(capability.robustness)) |
| 202 continue; |
| 203 EmeConfigRule robustness_rule = GetRobustnessConfigRule( |
| 204 key_system, media_type, base::UTF16ToASCII(capability.robustness)); |
| 205 if (!config_state->IsRuleSupported(robustness_rule)) |
| 206 continue; |
| 207 config_state->AddRule(robustness_rule); |
| 208 // 3.12.2. Add robustness to configuration. |
| 209 // (It's already added, we use capability as configuration.) |
100 } | 210 } |
101 // 3.13. If the user agent and implementation do not support playback of | 211 // 3.13. If the user agent and implementation do not support playback of |
102 // encrypted media data as specified by configuration, including all | 212 // encrypted media data as specified by configuration, including all |
103 // media types, in combination with accumulated capabilities, | 213 // media types, in combination with local accumulated capabilities, |
104 // continue to the next iteration. | 214 // continue to the next iteration. |
105 // (Skipped as there are no configuration-based codec restrictions.) | 215 // (This is handled when adding rules to |config_state|.) |
106 // 3.14. Add configuration to media type capabilities. | 216 // 3.14. Add configuration to supported media capabilities. |
107 media_type_capabilities->push_back(capability); | 217 supported_media_capabilities->push_back(capability); |
108 // 3.15. Add configuration to accumulated capabilities. | 218 // 3.15. Add configuration to local accumulated capabilities. |
109 // (Skipped as there are no configuration-based codec restrictions.) | 219 // (Skipped as we directly update |config_state|.) |
110 } | 220 } |
111 // 4. If media type capabilities is empty, return null. | 221 // 4. If supported media capabilities is empty, return null. |
| 222 if (supported_media_capabilities->empty()) { |
| 223 DVLOG(2) << "Rejecting requested configuration because " |
| 224 << "no capabilities were supported."; |
| 225 return false; |
| 226 } |
112 // 5. Return media type capabilities. | 227 // 5. Return media type capabilities. |
113 return !media_type_capabilities->empty(); | 228 return true; |
114 } | 229 } |
115 | 230 |
116 static EmeFeatureRequirement ConvertRequirement( | 231 static EmeFeatureRequirement ConvertRequirement( |
117 blink::WebMediaKeySystemConfiguration::Requirement requirement) { | 232 blink::WebMediaKeySystemConfiguration::Requirement requirement) { |
118 switch (requirement) { | 233 switch (requirement) { |
119 case blink::WebMediaKeySystemConfiguration::Requirement::Required: | 234 case blink::WebMediaKeySystemConfiguration::Requirement::Required: |
120 return EME_FEATURE_REQUIRED; | 235 return EME_FEATURE_REQUIRED; |
121 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: | 236 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: |
122 return EME_FEATURE_OPTIONAL; | 237 return EME_FEATURE_OPTIONAL; |
123 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | 238 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
124 return EME_FEATURE_NOT_ALLOWED; | 239 return EME_FEATURE_NOT_ALLOWED; |
125 } | 240 } |
126 | 241 |
127 NOTREACHED(); | 242 NOTREACHED(); |
128 return EME_FEATURE_NOT_ALLOWED; | 243 return EME_FEATURE_NOT_ALLOWED; |
129 } | 244 } |
130 | 245 |
131 static ConfigurationSupport GetSupportedConfiguration( | 246 static ConfigurationSupport GetSupportedConfiguration( |
132 const std::string& key_system, | 247 const std::string& key_system, |
133 const blink::WebMediaKeySystemConfiguration& candidate, | 248 const blink::WebMediaKeySystemConfiguration& candidate, |
134 blink::WebMediaKeySystemConfiguration* accumulated_configuration, | |
135 bool was_permission_requested, | 249 bool was_permission_requested, |
136 bool is_permission_granted) { | 250 bool is_permission_granted, |
137 DCHECK(was_permission_requested || !is_permission_granted); | 251 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
138 | 252 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 | 253 |
144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | 254 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
145 // 1. Let accumulated configuration be empty. (Done by caller.) | 255 // 1. Let accumulated configuration be empty. (Done by caller.) |
146 // 2. If candidate configuration's initDataTypes attribute is not empty, run | 256 // 2. If candidate configuration's initDataTypes attribute is not empty, run |
147 // the following steps: | 257 // the following steps: |
148 if (!candidate.initDataTypes.isEmpty()) { | 258 if (!candidate.initDataTypes.isEmpty()) { |
149 // 2.1. Let supported types be empty. | 259 // 2.1. Let supported types be empty. |
150 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; | 260 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; |
151 | 261 |
152 // 2.2. For each value in candidate configuration's initDataTypes attribute: | 262 // 2.2. For each value in candidate configuration's initDataTypes attribute: |
(...skipping 24 matching lines...) Expand all Loading... |
177 NOTREACHED(); | 287 NOTREACHED(); |
178 break; | 288 break; |
179 } | 289 } |
180 if (IsSupportedKeySystemWithInitDataType(key_system, | 290 if (IsSupportedKeySystemWithInitDataType(key_system, |
181 init_data_type_as_ascii)) { | 291 init_data_type_as_ascii)) { |
182 supported_types.push_back(init_data_type); | 292 supported_types.push_back(init_data_type); |
183 } | 293 } |
184 } | 294 } |
185 | 295 |
186 // 2.3. If supported types is empty, return null. | 296 // 2.3. If supported types is empty, return null. |
187 if (supported_types.empty()) | 297 if (supported_types.empty()) { |
| 298 DVLOG(2) << "Rejecting requested configuration because " |
| 299 << "no initDataType values were supported."; |
188 return CONFIGURATION_NOT_SUPPORTED; | 300 return CONFIGURATION_NOT_SUPPORTED; |
| 301 } |
189 | 302 |
190 // 2.4. Add supported types to accumulated configuration. | 303 // 2.4. Add supported types to accumulated configuration. |
191 accumulated_configuration->initDataTypes = supported_types; | 304 accumulated_configuration->initDataTypes = supported_types; |
192 } | 305 } |
193 | 306 |
194 // 3. Follow the steps for the value of candidate configuration's | 307 // 3. Follow the steps for the value of candidate configuration's |
195 // distinctiveIdentifier attribute from the following list: | 308 // distinctiveIdentifier attribute from the following list: |
196 // - "required": If the implementation does not support a persistent | 309 // - "required": If the implementation does not support a persistent |
197 // Distinctive Identifier in combination with accumulated configuration, | 310 // Distinctive Identifier in combination with accumulated configuration, |
198 // return null. | 311 // return null. |
199 // - "optional": Continue. | 312 // - "optional": Continue. |
200 // - "not-allowed": If the implementation requires a Distinctive | 313 // - "not-allowed": If the implementation requires a Distinctive |
201 // Identifier in combination with accumulated configuration, return | 314 // Identifier in combination with accumulated configuration, return |
202 // null. | 315 // null. |
203 EmeFeatureRequirement di_requirement = | 316 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and |
204 ConvertRequirement(candidate.distinctiveIdentifier); | 317 // permission has already been denied. This would happen anyway at step 11. |
205 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 318 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule( |
206 is_permission_possible)) { | 319 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); |
| 320 if (!config_state.IsRuleSupported(di_rule)) { |
| 321 DVLOG(2) << "Rejecting requested configuration because " |
| 322 << "the distinctiveIdentifier requirement was not supported."; |
207 return CONFIGURATION_NOT_SUPPORTED; | 323 return CONFIGURATION_NOT_SUPPORTED; |
208 } | 324 } |
| 325 config_state.AddRule(di_rule); |
209 | 326 |
210 // 4. Add the value of the candidate configuration's distinctiveIdentifier | 327 // 4. Add the value of the candidate configuration's distinctiveIdentifier |
211 // attribute to accumulated configuration. | 328 // attribute to accumulated configuration. |
212 accumulated_configuration->distinctiveIdentifier = | 329 accumulated_configuration->distinctiveIdentifier = |
213 candidate.distinctiveIdentifier; | 330 candidate.distinctiveIdentifier; |
214 | 331 |
215 // 5. Follow the steps for the value of candidate configuration's | 332 // 5. Follow the steps for the value of candidate configuration's |
216 // persistentState attribute from the following list: | 333 // persistentState attribute from the following list: |
217 // - "required": If the implementation does not support persisting state | 334 // - "required": If the implementation does not support persisting state |
218 // in combination with accumulated configuration, return null. | 335 // in combination with accumulated configuration, return null. |
219 // - "optional": Continue. | 336 // - "optional": Continue. |
220 // - "not-allowed": If the implementation requires persisting state in | 337 // - "not-allowed": If the implementation requires persisting state in |
221 // combination with accumulated configuration, return null. | 338 // combination with accumulated configuration, return null. |
222 EmeFeatureRequirement ps_requirement = | 339 EmeConfigRule ps_rule = GetPersistentStateConfigRule( |
223 ConvertRequirement(candidate.persistentState); | 340 key_system, ConvertRequirement(candidate.persistentState)); |
224 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | 341 if (!config_state.IsRuleSupported(ps_rule)) { |
225 is_permission_possible)) { | 342 DVLOG(2) << "Rejecting requested configuration because " |
| 343 << "the persistentState requirement was not supported."; |
226 return CONFIGURATION_NOT_SUPPORTED; | 344 return CONFIGURATION_NOT_SUPPORTED; |
227 } | 345 } |
| 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 DVLOG(2) << "Rejecting requested configuration because " |
| 437 << "distinctiveIdentifier was implicitly required but " |
| 438 << "not allowed."; |
| 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 // Now that distinctiveIdentifier has been resolved, it is too late to allow |
| 457 // persistentState to affect the configuration. |
| 458 bool not_allowed_supported = |
| 459 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule); |
| 460 bool required_supported = |
| 461 config_state.IsRuleSupportedWithCurrentState(required_rule); |
| 462 if (not_allowed_supported) { |
303 accumulated_configuration->persistentState = | 463 accumulated_configuration->persistentState = |
304 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 464 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
305 } else { | 465 } else if (required_supported) { |
306 accumulated_configuration->persistentState = | 466 accumulated_configuration->persistentState = |
307 blink::WebMediaKeySystemConfiguration::Requirement::Required; | 467 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 468 } else { |
| 469 // We should not have passed step 5. |
| 470 NOTREACHED(); |
| 471 return CONFIGURATION_NOT_SUPPORTED; |
308 } | 472 } |
309 } | 473 } |
310 | 474 |
311 // 11. If implementation in the configuration specified by the combination of | 475 // 11. If implementation in the configuration specified by the combination of |
312 // the values in accumulated configuration is not supported or not allowed | 476 // the values in accumulated configuration is not supported or not allowed |
313 // in the origin, return null. | 477 // in the origin, return null. |
314 di_requirement = | 478 // 12. If accumulated configuration's distinctiveIdentifier value is |
315 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); | 479 // "required", [prompt the user for consent]. |
316 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 480 if (accumulated_configuration->distinctiveIdentifier == |
317 is_permission_granted)) { | 481 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
318 if (was_permission_requested) { | 482 // The caller is responsible for resolving what to do if permission is |
319 // The optional permission was requested and denied. | 483 // required but has been denied (it should treat it as NOT_SUPPORTED). |
320 // TODO(sandersd): Avoid the need for this logic - crbug.com/460616. | 484 if (!config_state.IsPermissionGranted()) |
321 DCHECK(candidate.distinctiveIdentifier == | |
322 blink::WebMediaKeySystemConfiguration::Requirement::Optional); | |
323 DCHECK(di_requirement == EME_FEATURE_REQUIRED); | |
324 DCHECK(!is_permission_granted); | |
325 accumulated_configuration->distinctiveIdentifier = | |
326 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
327 } else { | |
328 return CONFIGURATION_REQUIRES_PERMISSION; | 485 return CONFIGURATION_REQUIRES_PERMISSION; |
329 } | |
330 } | 486 } |
331 | 487 |
332 ps_requirement = | 488 // 13. Return accumulated configuration. |
333 ConvertRequirement(accumulated_configuration->persistentState); | 489 // |
334 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | 490 // We also record the available session types so that createSession() can be |
335 is_permission_granted)) { | 491 // synchronous. |
336 DCHECK(!was_permission_requested); // Should have failed at step 5. | |
337 return CONFIGURATION_REQUIRES_PERMISSION; | |
338 } | |
339 | |
340 // 12. Return accumulated configuration. | |
341 // (As an extra step, we record the available session types so that | |
342 // createSession() can be synchronous.) | |
343 std::vector<blink::WebEncryptedMediaSessionType> session_types; | 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 if (was_permission_requested) { |
| 633 DVLOG(2) << "Rejecting requested configuration because " |
| 634 << "permission was denied."; |
| 635 continue; |
| 636 } |
484 media_permission_->RequestPermission( | 637 media_permission_->RequestPermission( |
485 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, | 638 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, |
486 GURL(request.securityOrigin().toString()), | 639 GURL(request.securityOrigin().toString()), |
487 // Try again with |was_permission_requested| true and | 640 // Try again with |was_permission_requested| true and |
488 // |is_permission_granted| the value of the permission. | 641 // |is_permission_granted| the value of the permission. |
489 base::Bind( | 642 base::Bind( |
490 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, | 643 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, |
491 weak_factory_.GetWeakPtr(), request, true)); | 644 weak_factory_.GetWeakPtr(), request, true)); |
492 return; | 645 return; |
493 case CONFIGURATION_SUPPORTED: | 646 case CONFIGURATION_SUPPORTED: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 return reporter; | 680 return reporter; |
528 | 681 |
529 // Reporter not found, so create one. | 682 // Reporter not found, so create one. |
530 auto result = | 683 auto result = |
531 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 684 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
532 DCHECK(result.second); | 685 DCHECK(result.second); |
533 return result.first->second; | 686 return result.first->second; |
534 } | 687 } |
535 | 688 |
536 } // namespace media | 689 } // namespace media |
OLD | NEW |