| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/password_authentication_manager.h" | |
| 6 | |
| 7 #include "chrome/browser/android/tab_android.h" | |
| 8 #include "jni/PasswordAuthenticationManager_jni.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 class PasswordAuthenticationCallback { | |
| 13 public: | |
| 14 explicit PasswordAuthenticationCallback( | |
| 15 const base::Closure& success_callback) { | |
| 16 success_callback_ = success_callback; | |
| 17 } | |
| 18 | |
| 19 void OnResult(bool result) { | |
| 20 if (result) | |
| 21 success_callback_.Run(); | |
| 22 delete this; | |
| 23 } | |
| 24 | |
| 25 private: | |
| 26 virtual ~PasswordAuthenticationCallback() {} | |
| 27 | |
| 28 base::Closure success_callback_; | |
| 29 }; | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 PasswordAuthenticationManager::PasswordAuthenticationManager() { | |
| 34 } | |
| 35 | |
| 36 PasswordAuthenticationManager::~PasswordAuthenticationManager() { | |
| 37 } | |
| 38 | |
| 39 bool PasswordAuthenticationManager::RegisterPasswordAuthenticationManager( | |
| 40 JNIEnv* env) { | |
| 41 return RegisterNativesImpl(env); | |
| 42 } | |
| 43 | |
| 44 void PasswordAuthenticationManager::AuthenticatePasswordAutofill( | |
| 45 content::WebContents* web_contents, | |
| 46 const base::Closure& success_callback) { | |
| 47 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | |
| 48 if (!tab) | |
| 49 return; | |
| 50 | |
| 51 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 52 PasswordAuthenticationCallback* auth_callback = | |
| 53 new PasswordAuthenticationCallback(success_callback); | |
| 54 Java_PasswordAuthenticationManager_requestAuthentication( | |
| 55 env, | |
| 56 tab->GetJavaObject().obj(), | |
| 57 Java_PasswordAuthenticationCallback_create( | |
| 58 env, | |
| 59 reinterpret_cast<intptr_t>(auth_callback)).obj()); | |
| 60 } | |
| 61 | |
| 62 // static | |
| 63 void OnResult(JNIEnv* env, | |
| 64 jclass jcaller, | |
| 65 jlong callback_ptr, | |
| 66 jboolean authenticated) { | |
| 67 PasswordAuthenticationCallback* callback = | |
| 68 reinterpret_cast<PasswordAuthenticationCallback*>(callback_ptr); | |
| 69 callback->OnResult(authenticated); | |
| 70 } | |
| OLD | NEW |