| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "media/base/android/media_drm_bridge.h" | 5 #include "media/base/android/media_drm_bridge.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 int32 os_bugfix_version = 0; | 291 int32 os_bugfix_version = 0; |
| 292 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, | 292 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, |
| 293 &os_minor_version, | 293 &os_minor_version, |
| 294 &os_bugfix_version); | 294 &os_bugfix_version); |
| 295 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0) | 295 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0) |
| 296 return false; | 296 return false; |
| 297 | 297 |
| 298 return true; | 298 return true; |
| 299 } | 299 } |
| 300 | 300 |
| 301 // TODO(ddorwin): This is specific to Widevine. http://crbug.com/459400 |
| 301 // static | 302 // static |
| 302 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) { | 303 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) { |
| 303 DCHECK(IsAvailable()); | 304 DCHECK(IsAvailable()); |
| 304 return SECURITY_LEVEL_1 == security_level; | 305 return SECURITY_LEVEL_1 == security_level; |
| 305 } | 306 } |
| 306 | 307 |
| 307 // static | 308 // static |
| 308 bool MediaDrmBridge::IsSecurityLevelSupported(const std::string& key_system, | |
| 309 SecurityLevel security_level) { | |
| 310 if (!IsAvailable()) | |
| 311 return false; | |
| 312 | |
| 313 scoped_ptr<MediaDrmBridge> media_drm_bridge = | |
| 314 MediaDrmBridge::CreateWithoutSessionSupport(key_system); | |
| 315 if (!media_drm_bridge) | |
| 316 return false; | |
| 317 | |
| 318 return media_drm_bridge->SetSecurityLevel(security_level); | |
| 319 } | |
| 320 | |
| 321 // static | |
| 322 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { | 309 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { |
| 323 return g_key_system_uuid_manager.Get().GetPlatformKeySystemNames(); | 310 return g_key_system_uuid_manager.Get().GetPlatformKeySystemNames(); |
| 324 } | 311 } |
| 325 | 312 |
| 326 // static | 313 // static |
| 327 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { | 314 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { |
| 328 DCHECK(!key_system.empty()); | 315 DCHECK(!key_system.empty()); |
| 329 return IsKeySystemSupportedWithTypeImpl(key_system, ""); | 316 return IsKeySystemSupportedWithTypeImpl(key_system, ""); |
| 330 } | 317 } |
| 331 | 318 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 384 |
| 398 // static | 385 // static |
| 399 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( | 386 scoped_ptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( |
| 400 const std::string& key_system) { | 387 const std::string& key_system) { |
| 401 return MediaDrmBridge::Create( | 388 return MediaDrmBridge::Create( |
| 402 key_system, SessionMessageCB(), SessionClosedCB(), SessionErrorCB(), | 389 key_system, SessionMessageCB(), SessionClosedCB(), SessionErrorCB(), |
| 403 SessionKeysChangeCB(), SessionExpirationUpdateCB()); | 390 SessionKeysChangeCB(), SessionExpirationUpdateCB()); |
| 404 } | 391 } |
| 405 | 392 |
| 406 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { | 393 bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { |
| 394 if (security_level != SECURITY_LEVEL_NONE && |
| 395 !std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) { |
| 396 NOTREACHED() << "Widevine security level " << security_level |
| 397 << "used with another key system"; |
| 398 return false; |
| 399 } |
| 400 |
| 407 JNIEnv* env = AttachCurrentThread(); | 401 JNIEnv* env = AttachCurrentThread(); |
| 408 | 402 |
| 409 std::string security_level_str = GetSecurityLevelString(security_level); | 403 std::string security_level_str = GetSecurityLevelString(security_level); |
| 410 if (security_level_str.empty()) | 404 if (security_level_str.empty()) |
| 411 return false; | 405 return false; |
| 412 | 406 |
| 413 ScopedJavaLocalRef<jstring> j_security_level = | 407 ScopedJavaLocalRef<jstring> j_security_level = |
| 414 ConvertUTF8ToJavaString(env, security_level_str); | 408 ConvertUTF8ToJavaString(env, security_level_str); |
| 415 return Java_MediaDrmBridge_setSecurityLevel( | 409 return Java_MediaDrmBridge_setSecurityLevel( |
| 416 env, j_media_drm_.obj(), j_security_level.obj()); | 410 env, j_media_drm_.obj(), j_security_level.obj()); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 623 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
| 630 JNIEnv* env = AttachCurrentThread(); | 624 JNIEnv* env = AttachCurrentThread(); |
| 631 ScopedJavaLocalRef<jstring> j_security_level = | 625 ScopedJavaLocalRef<jstring> j_security_level = |
| 632 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); | 626 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); |
| 633 std::string security_level_str = | 627 std::string security_level_str = |
| 634 ConvertJavaStringToUTF8(env, j_security_level.obj()); | 628 ConvertJavaStringToUTF8(env, j_security_level.obj()); |
| 635 return GetSecurityLevelFromString(security_level_str); | 629 return GetSecurityLevelFromString(security_level_str); |
| 636 } | 630 } |
| 637 | 631 |
| 638 bool MediaDrmBridge::IsProtectedSurfaceRequired() { | 632 bool MediaDrmBridge::IsProtectedSurfaceRequired() { |
| 639 return IsSecureDecoderRequired(GetSecurityLevel()); | 633 // For Widevine, this depends on the security level. |
| 634 if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid)) |
| 635 return IsSecureDecoderRequired(GetSecurityLevel()); |
| 636 |
| 637 // For other key systems, assume true. |
| 638 return true; |
| 640 } | 639 } |
| 641 | 640 |
| 642 void MediaDrmBridge::ResetDeviceCredentials( | 641 void MediaDrmBridge::ResetDeviceCredentials( |
| 643 const ResetCredentialsCB& callback) { | 642 const ResetCredentialsCB& callback) { |
| 644 DCHECK(reset_credentials_cb_.is_null()); | 643 DCHECK(reset_credentials_cb_.is_null()); |
| 645 reset_credentials_cb_ = callback; | 644 reset_credentials_cb_ = callback; |
| 646 JNIEnv* env = AttachCurrentThread(); | 645 JNIEnv* env = AttachCurrentThread(); |
| 647 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 646 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
| 648 } | 647 } |
| 649 | 648 |
| 650 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 649 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
| 651 JNIEnv* env, jobject, bool success) { | 650 JNIEnv* env, jobject, bool success) { |
| 652 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 651 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 653 } | 652 } |
| 654 | 653 |
| 655 } // namespace media | 654 } // namespace media |
| OLD | NEW |