| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "content/browser/media/android/media_drm_credential_manager.h" | 5 #include "content/browser/media/android/media_drm_credential_manager.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/scoped_java_ref.h" |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "jni/MediaDrmCredentialManager_jni.h" |
| 9 #include "media/base/android/media_drm_bridge.h" | 12 #include "media/base/android/media_drm_bridge.h" |
| 10 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 11 | 14 |
| 15 using base::android::ScopedJavaGlobalRef; |
| 16 |
| 17 namespace { |
| 18 |
| 19 void MediaDrmCredentialManagerCallback( |
| 20 const ScopedJavaGlobalRef<jobject>& j_media_drm_credential_manager_callback, |
| 21 bool succeeded) { |
| 22 JNIEnv* env = base::android::AttachCurrentThread(); |
| 23 content::Java_MediaDrmCredentialManagerCallback_onCredentialResetFinished( |
| 24 env, j_media_drm_credential_manager_callback.obj(), succeeded); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 12 namespace content { | 29 namespace content { |
| 13 | 30 |
| 14 // TODO(qinmin): Move the UUID definition to some common places. | 31 // TODO(qinmin): Move the UUID definition to some common places. |
| 15 static const uint8 kWidevineUuid[16] = { | 32 static const uint8 kWidevineUuid[16] = { |
| 16 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 33 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
| 17 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 34 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
| 18 | 35 |
| 19 MediaDrmCredentialManager::MediaDrmCredentialManager() {} | 36 MediaDrmCredentialManager::MediaDrmCredentialManager() {}; |
| 20 | 37 |
| 21 MediaDrmCredentialManager::~MediaDrmCredentialManager() {} | 38 MediaDrmCredentialManager::~MediaDrmCredentialManager() {}; |
| 39 |
| 40 // static |
| 41 MediaDrmCredentialManager* MediaDrmCredentialManager::GetInstance() { |
| 42 return Singleton<MediaDrmCredentialManager>::get(); |
| 43 } |
| 22 | 44 |
| 23 void MediaDrmCredentialManager::ResetCredentials( | 45 void MediaDrmCredentialManager::ResetCredentials( |
| 24 const ResetCredentialsCB& callback) { | 46 const ResetCredentialsCB& callback) { |
| 25 // Ignore reset request if one is already in progress. | 47 // Ignore reset request if one is already in progress. |
| 26 if (!reset_credentials_cb_.is_null()) | 48 if (!reset_credentials_cb_.is_null()) |
| 27 return; | 49 return; |
| 28 | 50 |
| 29 reset_credentials_cb_ = callback; | 51 reset_credentials_cb_ = callback; |
| 30 | 52 |
| 31 // First reset the L3 credential. | 53 // First reset the L3 credential. |
| 32 if (!ResetCredentialsInternal("L3")) { | 54 if (!ResetCredentialsInternal("L3")) { |
| 33 // TODO(qinmin): We should post a task instead. | 55 // TODO(qinmin): We should post a task instead. |
| 34 base::ResetAndReturn(&reset_credentials_cb_).Run(false); | 56 base::ResetAndReturn(&reset_credentials_cb_).Run(false); |
| 35 } | 57 } |
| 36 } | 58 } |
| 37 | 59 |
| 60 // static |
| 61 void ResetCredentials( |
| 62 JNIEnv* env, |
| 63 jclass clazz, |
| 64 jobject j_media_drm_credential_manager_callback) { |
| 65 MediaDrmCredentialManager* media_drm_credential_manager = |
| 66 MediaDrmCredentialManager::GetInstance(); |
| 67 |
| 68 ScopedJavaGlobalRef<jobject> j_scoped_media_drm_credential_manager_callback; |
| 69 j_scoped_media_drm_credential_manager_callback.Reset( |
| 70 env, j_media_drm_credential_manager_callback); |
| 71 |
| 72 MediaDrmCredentialManager::ResetCredentialsCB callback_runner = |
| 73 base::Bind(&MediaDrmCredentialManagerCallback, |
| 74 j_scoped_media_drm_credential_manager_callback); |
| 75 |
| 76 media_drm_credential_manager->ResetCredentials(callback_runner); |
| 77 } |
| 78 |
| 38 void MediaDrmCredentialManager::OnResetCredentialsCompleted( | 79 void MediaDrmCredentialManager::OnResetCredentialsCompleted( |
| 39 const std::string& security_level, bool success) { | 80 const std::string& security_level, bool success) { |
| 40 if (security_level == "L3" && success) { | 81 if (security_level == "L3" && success) { |
| 41 if (ResetCredentialsInternal("L1")) | 82 if (ResetCredentialsInternal("L1")) |
| 42 return; | 83 return; |
| 43 success = false; | 84 success = false; |
| 44 } | 85 } |
| 45 | 86 |
| 46 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 87 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 47 media_drm_bridge_.reset(); | 88 media_drm_bridge_.reset(); |
| 48 } | 89 } |
| 49 | 90 |
| 50 bool MediaDrmCredentialManager::ResetCredentialsInternal( | 91 bool MediaDrmCredentialManager::ResetCredentialsInternal( |
| 51 const std::string& security_level) { | 92 const std::string& security_level) { |
| 52 std::vector<uint8> uuid(kWidevineUuid, kWidevineUuid + 16); | 93 std::vector<uint8> uuid(kWidevineUuid, kWidevineUuid + 16); |
| 53 media_drm_bridge_ = media::MediaDrmBridge::Create( | 94 media_drm_bridge_ = media::MediaDrmBridge::Create( |
| 54 0, uuid, GURL(), security_level, NULL); | 95 0, uuid, GURL(), security_level, NULL); |
| 55 if (!media_drm_bridge_) | 96 if (!media_drm_bridge_) |
| 56 return false; | 97 return false; |
| 57 media_drm_bridge_->ResetDeviceCredentials( | 98 media_drm_bridge_->ResetDeviceCredentials( |
| 58 base::Bind(&MediaDrmCredentialManager::OnResetCredentialsCompleted, | 99 base::Bind(&MediaDrmCredentialManager::OnResetCredentialsCompleted, |
| 59 base::Unretained(this), security_level)); | 100 base::Unretained(this), security_level)); |
| 60 return true; | 101 return true; |
| 61 } | 102 } |
| 62 | 103 |
| 104 // static |
| 105 bool MediaDrmCredentialManager::RegisterMediaDrmCredentialManager(JNIEnv* env) { |
| 106 return RegisterNativesImpl(env); |
| 107 } |
| 108 |
| 63 } // namespace content | 109 } // namespace content |
| OLD | NEW |