| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "android_webview/native/token_binding_manager_bridge.h" | 5 #include "android_webview/native/token_binding_manager_bridge.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/net/token_binding_manager.h" | 7 #include "android_webview/browser/net/token_binding_manager.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // Provides the key to the Webview client. | 27 // Provides the key to the Webview client. |
| 28 void OnKeyReady(const ScopedJavaGlobalRef<jobject>& callback, | 28 void OnKeyReady(const ScopedJavaGlobalRef<jobject>& callback, |
| 29 int status, | 29 int status, |
| 30 crypto::ECPrivateKey* key) { | 30 crypto::ECPrivateKey* key) { |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 31 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 32 | 32 |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | 33 JNIEnv* env = base::android::AttachCurrentThread(); |
| 34 | 34 |
| 35 if (status != net::OK || !key) { | 35 if (status != net::OK || !key) { |
| 36 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), nullptr, | 36 Java_AwTokenBindingManager_onKeyReady(env, callback, nullptr, nullptr); |
| 37 nullptr); | |
| 38 return; | 37 return; |
| 39 } | 38 } |
| 40 | 39 |
| 41 std::vector<uint8_t> private_key; | 40 std::vector<uint8_t> private_key; |
| 42 key->ExportPrivateKey(&private_key); | 41 key->ExportPrivateKey(&private_key); |
| 43 ScopedJavaLocalRef<jbyteArray> jprivate_key = base::android::ToJavaByteArray( | 42 ScopedJavaLocalRef<jbyteArray> jprivate_key = base::android::ToJavaByteArray( |
| 44 env, private_key.data(), private_key.size()); | 43 env, private_key.data(), private_key.size()); |
| 45 | 44 |
| 46 std::vector<uint8_t> public_key; | 45 std::vector<uint8_t> public_key; |
| 47 key->ExportPublicKey(&public_key); | 46 key->ExportPublicKey(&public_key); |
| 48 ScopedJavaLocalRef<jbyteArray> jpublic_key = base::android::ToJavaByteArray( | 47 ScopedJavaLocalRef<jbyteArray> jpublic_key = base::android::ToJavaByteArray( |
| 49 env, public_key.data(), public_key.size()); | 48 env, public_key.data(), public_key.size()); |
| 50 | 49 |
| 51 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), jprivate_key.obj(), | 50 Java_AwTokenBindingManager_onKeyReady(env, callback, jprivate_key, |
| 52 jpublic_key.obj()); | 51 jpublic_key); |
| 53 } | 52 } |
| 54 | 53 |
| 55 // Indicates webview client that key deletion is complete. | 54 // Indicates webview client that key deletion is complete. |
| 56 void OnDeletionComplete(const ScopedJavaGlobalRef<jobject>& callback) { | 55 void OnDeletionComplete(const ScopedJavaGlobalRef<jobject>& callback) { |
| 57 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 58 if (callback.is_null()) | 57 if (callback.is_null()) |
| 59 return; | 58 return; |
| 60 JNIEnv* env = base::android::AttachCurrentThread(); | 59 JNIEnv* env = base::android::AttachCurrentThread(); |
| 61 Java_AwTokenBindingManager_onDeletionComplete(env, callback.obj()); | 60 Java_AwTokenBindingManager_onDeletionComplete(env, callback); |
| 62 } | 61 } |
| 63 | 62 |
| 64 } // namespace | 63 } // namespace |
| 65 | 64 |
| 66 static void EnableTokenBinding(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 65 static void EnableTokenBinding(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 67 // This needs to be called before starting chromium engine, so no thread | 66 // This needs to be called before starting chromium engine, so no thread |
| 68 // checks for UI. | 67 // checks for UI. |
| 69 TokenBindingManager::GetInstance()->enable_token_binding(); | 68 TokenBindingManager::GetInstance()->enable_token_binding(); |
| 70 } | 69 } |
| 71 | 70 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 TokenBindingManager::DeletionCompleteCallback complete_callback = | 110 TokenBindingManager::DeletionCompleteCallback complete_callback = |
| 112 base::Bind(&OnDeletionComplete, j_callback); | 111 base::Bind(&OnDeletionComplete, j_callback); |
| 113 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback); | 112 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback); |
| 114 } | 113 } |
| 115 | 114 |
| 116 bool RegisterTokenBindingManager(JNIEnv* env) { | 115 bool RegisterTokenBindingManager(JNIEnv* env) { |
| 117 return RegisterNativesImpl(env); | 116 return RegisterNativesImpl(env); |
| 118 } | 117 } |
| 119 | 118 |
| 120 } // android_webview namespace | 119 } // android_webview namespace |
| OLD | NEW |