| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "media/base/key_systems.h" | 12 #include "media/base/key_systems.h" |
| 13 #include "media/base/media_permission.h" | 13 #include "media/base/media_permission.h" |
| 14 #include "media/blink/webcontentdecryptionmodule_impl.h" | 14 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 15 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h" | 15 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h" |
| 16 #include "net/base/mime_util.h" | 16 #include "net/base/mime_util.h" |
| 17 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" | 17 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" | 18 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 | 23 |
| 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 // TODO(jrummell): Convert to an enum. http://crbug.com/418239 | |
| 29 const char kTemporarySessionType[] = "temporary"; | |
| 30 const char kPersistentLicenseSessionType[] = "persistent-license"; | |
| 31 const char kPersistentReleaseMessageSessionType[] = | |
| 32 "persistent-release-message"; | |
| 33 | |
| 34 enum ConfigurationSupport { | 28 enum ConfigurationSupport { |
| 35 CONFIGURATION_NOT_SUPPORTED, | 29 CONFIGURATION_NOT_SUPPORTED, |
| 36 CONFIGURATION_REQUIRES_PERMISSION, | 30 CONFIGURATION_REQUIRES_PERMISSION, |
| 37 CONFIGURATION_SUPPORTED, | 31 CONFIGURATION_SUPPORTED, |
| 38 }; | 32 }; |
| 39 | 33 |
| 40 static bool IsSupportedContentType(const std::string& key_system, | 34 static bool IsSupportedContentType(const std::string& key_system, |
| 41 const std::string& mime_type, | 35 const std::string& mime_type, |
| 42 const std::string& codecs) { | 36 const std::string& codecs) { |
| 43 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid | 37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 138 |
| 145 // It is possible to obtain user permission unless permission was already | 139 // It is possible to obtain user permission unless permission was already |
| 146 // requested and denied. | 140 // requested and denied. |
| 147 bool is_permission_possible = | 141 bool is_permission_possible = |
| 148 !was_permission_requested || is_permission_granted; | 142 !was_permission_requested || is_permission_granted; |
| 149 | 143 |
| 150 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | 144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
| 151 // 1. Let accumulated configuration be empty. (Done by caller.) | 145 // 1. Let accumulated configuration be empty. (Done by caller.) |
| 152 // 2. If candidate configuration's initDataTypes attribute is not empty, run | 146 // 2. If candidate configuration's initDataTypes attribute is not empty, run |
| 153 // the following steps: | 147 // the following steps: |
| 154 if (!candidate.initDataTypes.isEmpty()) { | 148 blink::WebVector<blink::WebEncryptedMediaInitDataType> init_data_types = |
| 149 candidate.getInitDataTypes(); |
| 150 if (!init_data_types.isEmpty()) { |
| 155 // 2.1. Let supported types be empty. | 151 // 2.1. Let supported types be empty. |
| 156 std::vector<blink::WebString> supported_types; | 152 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; |
| 157 | 153 |
| 158 // 2.2. For each value in candidate configuration's initDataTypes attribute: | 154 // 2.2. For each value in candidate configuration's initDataTypes attribute: |
| 159 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { | 155 for (size_t i = 0; i < init_data_types.size(); i++) { |
| 160 // 2.2.1. Let initDataType be the value. | 156 // 2.2.1. Let initDataType be the value. |
| 161 const blink::WebString& init_data_type = candidate.initDataTypes[i]; | 157 blink::WebEncryptedMediaInitDataType init_data_type = init_data_types[i]; |
| 162 // 2.2.2. If initDataType is the empty string, return null. | 158 // 2.2.2. If initDataType is the empty string, return null. |
| 163 if (init_data_type.isEmpty()) | 159 if (init_data_type == blink::WebEncryptedMediaInitDataType::Unknown) |
| 164 return CONFIGURATION_NOT_SUPPORTED; | 160 continue; |
| 165 // 2.2.3. If the implementation supports generating requests based on | 161 // 2.2.3. If the implementation supports generating requests based on |
| 166 // initDataType, add initDataType to supported types. String | 162 // initDataType, add initDataType to supported types. String |
| 167 // comparison is case-sensitive. | 163 // comparison is case-sensitive. |
| 168 if (base::IsStringASCII(init_data_type) && | 164 // TODO(jrummell): |init_data_type| should be an enum all the way through |
| 169 IsSupportedKeySystemWithInitDataType( | 165 // Chromium. http://crbug.com/417440 |
| 170 key_system, base::UTF16ToASCII(init_data_type))) { | 166 std::string init_data_type_as_ascii = "unknown"; |
| 167 switch (init_data_type) { |
| 168 case blink::WebEncryptedMediaInitDataType::Cenc: |
| 169 init_data_type_as_ascii = "cenc"; |
| 170 break; |
| 171 case blink::WebEncryptedMediaInitDataType::Keyids: |
| 172 init_data_type_as_ascii = "keyids"; |
| 173 break; |
| 174 case blink::WebEncryptedMediaInitDataType::Webm: |
| 175 init_data_type_as_ascii = "webm"; |
| 176 break; |
| 177 case blink::WebEncryptedMediaInitDataType::Unknown: |
| 178 NOTREACHED(); |
| 179 break; |
| 180 } |
| 181 if (IsSupportedKeySystemWithInitDataType(key_system, |
| 182 init_data_type_as_ascii)) { |
| 171 supported_types.push_back(init_data_type); | 183 supported_types.push_back(init_data_type); |
| 172 } | 184 } |
| 173 } | 185 } |
| 174 | 186 |
| 175 // 2.3. If supported types is empty, return null. | 187 // 2.3. If supported types is empty, return null. |
| 176 if (supported_types.empty()) | 188 if (supported_types.empty()) |
| 177 return CONFIGURATION_NOT_SUPPORTED; | 189 return CONFIGURATION_NOT_SUPPORTED; |
| 178 | 190 |
| 179 // 2.4. Add supported types to accumulated configuration. | 191 // 2.4. Add supported types to accumulated configuration. |
| 180 accumulated_configuration->initDataTypes = supported_types; | 192 accumulated_configuration->setInitDataTypes(supported_types); |
| 181 } | 193 } |
| 182 | 194 |
| 183 // 3. Follow the steps for the value of candidate configuration's | 195 // 3. Follow the steps for the value of candidate configuration's |
| 184 // distinctiveIdentifier attribute from the following list: | 196 // distinctiveIdentifier attribute from the following list: |
| 185 // - "required": If the implementation does not support a persistent | 197 // - "required": If the implementation does not support a persistent |
| 186 // Distinctive Identifier in combination with accumulated configuration, | 198 // Distinctive Identifier in combination with accumulated configuration, |
| 187 // return null. | 199 // return null. |
| 188 // - "optional": Continue. | 200 // - "optional": Continue. |
| 189 // - "not-allowed": If the implementation requires a Distinctive | 201 // - "not-allowed": If the implementation requires a Distinctive |
| 190 // Identifier in combination with accumulated configuration, return | 202 // Identifier in combination with accumulated configuration, return |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 ConvertRequirement(accumulated_configuration->persistentState); | 334 ConvertRequirement(accumulated_configuration->persistentState); |
| 323 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | 335 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, |
| 324 is_permission_granted)) { | 336 is_permission_granted)) { |
| 325 DCHECK(!was_permission_requested); // Should have failed at step 5. | 337 DCHECK(!was_permission_requested); // Should have failed at step 5. |
| 326 return CONFIGURATION_REQUIRES_PERMISSION; | 338 return CONFIGURATION_REQUIRES_PERMISSION; |
| 327 } | 339 } |
| 328 | 340 |
| 329 // 12. Return accumulated configuration. | 341 // 12. Return accumulated configuration. |
| 330 // (As an extra step, we record the available session types so that | 342 // (As an extra step, we record the available session types so that |
| 331 // createSession() can be synchronous.) | 343 // createSession() can be synchronous.) |
| 332 std::vector<blink::WebString> session_types; | 344 std::vector<blink::WebEncryptedMediaSessionType> session_types; |
| 333 session_types.push_back(kTemporarySessionType); | 345 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); |
| 334 if (accumulated_configuration->persistentState == | 346 if (accumulated_configuration->persistentState == |
| 335 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | 347 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
| 336 if (IsPersistentLicenseSessionSupported(key_system, | 348 if (IsPersistentLicenseSessionSupported(key_system, |
| 337 is_permission_granted)) { | 349 is_permission_granted)) { |
| 338 session_types.push_back(kPersistentLicenseSessionType); | 350 session_types.push_back( |
| 351 blink::WebEncryptedMediaSessionType::PersistentLicense); |
| 339 } | 352 } |
| 340 if (IsPersistentReleaseMessageSessionSupported(key_system, | 353 if (IsPersistentReleaseMessageSessionSupported(key_system, |
| 341 is_permission_granted)) { | 354 is_permission_granted)) { |
| 342 session_types.push_back(kPersistentReleaseMessageSessionType); | 355 session_types.push_back( |
| 356 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); |
| 343 } | 357 } |
| 344 } | 358 } |
| 345 accumulated_configuration->sessionTypes = session_types; | 359 accumulated_configuration->setSessionTypes(session_types); |
| 346 | 360 |
| 347 return CONFIGURATION_SUPPORTED; | 361 return CONFIGURATION_SUPPORTED; |
| 348 } | 362 } |
| 349 | 363 |
| 350 // Report usage of key system to UMA. There are 2 different counts logged: | 364 // Report usage of key system to UMA. There are 2 different counts logged: |
| 351 // 1. The key system is requested. | 365 // 1. The key system is requested. |
| 352 // 2. The requested key system and options are supported. | 366 // 2. The requested key system and options are supported. |
| 353 // Each stat is only reported once per renderer frame per key system. | 367 // Each stat is only reported once per renderer frame per key system. |
| 354 // Note that WebEncryptedMediaClientImpl is only created once by each | 368 // Note that WebEncryptedMediaClientImpl is only created once by each |
| 355 // renderer frame. | 369 // renderer frame. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 return reporter; | 524 return reporter; |
| 511 | 525 |
| 512 // Reporter not found, so create one. | 526 // Reporter not found, so create one. |
| 513 auto result = | 527 auto result = |
| 514 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 528 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
| 515 DCHECK(result.second); | 529 DCHECK(result.second); |
| 516 return result.first->second; | 530 return result.first->second; |
| 517 } | 531 } |
| 518 | 532 |
| 519 } // namespace media | 533 } // namespace media |
| OLD | NEW |