Chromium Code Reviews| 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 | 13 |
| 14 using base::android::AttachCurrentThread; | |
| 15 using base::android::ScopedJavaGlobalRef; | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 void MediaDrmCredentialManagerCallback( | |
| 20 ScopedJavaGlobalRef<jobject>* j_media_drm_credential_manager_callback, | |
|
qinmin
2013/09/20 22:25:50
i don't think you need a pointer to a javaref, jus
Kibeom Kim (inactive)
2013/09/20 23:30:48
Done.
| |
| 21 bool succeeded) { | |
| 22 JNIEnv* env = AttachCurrentThread(); | |
| 23 content::Java_MediaDrmCredentialManagerCallback_onCredentialResetFinished( | |
| 24 env, j_media_drm_credential_manager_callback->obj(), succeeded); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 11 namespace content { | 29 namespace content { |
| 12 | 30 |
| 13 // TODO(qinmin): Move the UUID definition to some common places. | 31 // TODO(qinmin): Move the UUID definition to some common places. |
| 14 static const uint8 kWidevineUuid[16] = { | 32 static const uint8 kWidevineUuid[16] = { |
| 15 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 33 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
| 16 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 34 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
| 17 | 35 |
| 18 MediaDrmCredentialManager::MediaDrmCredentialManager() {} | 36 MediaDrmCredentialManager::MediaDrmCredentialManager() {} |
| 19 | 37 |
| 20 MediaDrmCredentialManager::~MediaDrmCredentialManager() {} | 38 MediaDrmCredentialManager::~MediaDrmCredentialManager() {} |
| 21 | 39 |
| 40 void MediaDrmCredentialManager::Destroy(JNIEnv* env, jobject obj) { | |
| 41 delete this; | |
| 42 } | |
| 43 | |
| 22 void MediaDrmCredentialManager::ResetCredentials( | 44 void MediaDrmCredentialManager::ResetCredentials( |
| 23 const ResetCredentialsCB& callback) { | 45 const ResetCredentialsCB& callback) { |
| 24 // Ignore reset request if one is already in progress. | 46 // Ignore reset request if one is already in progress. |
| 25 if (!reset_credentials_cb_.is_null()) | 47 if (!reset_credentials_cb_.is_null()) |
| 26 return; | 48 return; |
| 27 | 49 |
| 28 reset_credentials_cb_ = callback; | 50 reset_credentials_cb_ = callback; |
| 29 | 51 |
| 30 // First reset the L3 credential. | 52 // First reset the L3 credential. |
| 31 if (!ResetCredentialsInternal("L3")) { | 53 if (!ResetCredentialsInternal("L3")) { |
| 32 // TODO(qinmin): We should post a task instead. | 54 // TODO(qinmin): We should post a task instead. |
| 33 base::ResetAndReturn(&reset_credentials_cb_).Run(false); | 55 base::ResetAndReturn(&reset_credentials_cb_).Run(false); |
| 34 } | 56 } |
| 35 } | 57 } |
| 36 | 58 |
| 59 void MediaDrmCredentialManager::ResetCredentials( | |
| 60 JNIEnv* env, | |
| 61 jobject obj, | |
| 62 jobject j_media_drm_credential_manager_callback) { | |
| 63 ScopedJavaGlobalRef<jobject>* j_scoped_media_drm_credential_manager_callback = | |
|
qinmin
2013/09/20 22:25:50
you don't need to new the pointer.
Kibeom Kim (inactive)
2013/09/20 22:39:41
Question: then what's the correct way to modify ba
| |
| 64 new ScopedJavaGlobalRef<jobject>(); | |
| 65 j_scoped_media_drm_credential_manager_callback->Reset( | |
| 66 env, j_media_drm_credential_manager_callback); | |
| 67 ResetCredentialsCB callback_runner = | |
| 68 base::Bind(&MediaDrmCredentialManagerCallback, | |
| 69 base::Owned(j_scoped_media_drm_credential_manager_callback)); | |
| 70 | |
| 71 ResetCredentials(callback_runner); | |
| 72 } | |
| 73 | |
| 37 void MediaDrmCredentialManager::OnResetCredentialsCompleted( | 74 void MediaDrmCredentialManager::OnResetCredentialsCompleted( |
| 38 const std::string& security_level, bool success) { | 75 const std::string& security_level, bool success) { |
| 39 if (security_level == "L3" && success) { | 76 if (security_level == "L3" && success) { |
| 40 if (ResetCredentialsInternal("L1")) | 77 if (ResetCredentialsInternal("L1")) |
| 41 return; | 78 return; |
| 42 success = false; | 79 success = false; |
| 43 } | 80 } |
| 44 | 81 |
| 45 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 82 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 46 media_drm_bridge_.reset(); | 83 media_drm_bridge_.reset(); |
| 47 } | 84 } |
| 48 | 85 |
| 49 bool MediaDrmCredentialManager::ResetCredentialsInternal( | 86 bool MediaDrmCredentialManager::ResetCredentialsInternal( |
| 50 const std::string& security_level) { | 87 const std::string& security_level) { |
| 51 std::vector<uint8> uuid(kWidevineUuid, kWidevineUuid + 16); | 88 std::vector<uint8> uuid(kWidevineUuid, kWidevineUuid + 16); |
| 52 media_drm_bridge_ = media::MediaDrmBridge::Create( | 89 media_drm_bridge_ = media::MediaDrmBridge::Create( |
| 53 0, uuid, security_level, NULL); | 90 0, uuid, GURL(), security_level, NULL); |
| 54 if (!media_drm_bridge_) | 91 if (!media_drm_bridge_) |
| 55 return false; | 92 return false; |
| 56 media_drm_bridge_->ResetDeviceCredentials( | 93 media_drm_bridge_->ResetDeviceCredentials( |
| 57 base::Bind(&MediaDrmCredentialManager::OnResetCredentialsCompleted, | 94 base::Bind(&MediaDrmCredentialManager::OnResetCredentialsCompleted, |
| 58 base::Unretained(this), security_level)); | 95 base::Unretained(this), security_level)); |
| 59 return true; | 96 return true; |
| 60 } | 97 } |
| 61 | 98 |
| 99 static jint Init(JNIEnv* env, jclass clazz) { | |
| 100 return reinterpret_cast<jint>(new content::MediaDrmCredentialManager()); | |
| 101 } | |
| 102 | |
| 103 // static | |
| 104 bool MediaDrmCredentialManager::RegisterMediaDrmCredentialManager(JNIEnv* env) { | |
| 105 return RegisterNativesImpl(env); | |
| 106 } | |
| 107 | |
| 62 } // namespace content | 108 } // namespace content |
| OLD | NEW |