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.
5 #include "chrome/browser/android/password_authentication_manager.h"
7 #include "chrome/browser/android/tab_android.h"
8 #include "jni/PasswordAuthenticationManager_jni.h"
12 class PasswordAuthenticationCallback {
14 explicit PasswordAuthenticationCallback(
15 const base::Closure& success_callback) {
16 success_callback_ = success_callback;
19 void OnResult(bool result) {
21 success_callback_.Run();
26 virtual ~PasswordAuthenticationCallback() {}
28 base::Closure success_callback_;
33 PasswordAuthenticationManager::PasswordAuthenticationManager() {
36 PasswordAuthenticationManager::~PasswordAuthenticationManager() {
39 bool PasswordAuthenticationManager::RegisterPasswordAuthenticationManager(
41 return RegisterNativesImpl(env);
44 void PasswordAuthenticationManager::AuthenticatePasswordAutofill(
45 content::WebContents* web_contents,
46 const base::Closure& success_callback) {
47 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
51 JNIEnv* env = base::android::AttachCurrentThread();
52 PasswordAuthenticationCallback* auth_callback =
53 new PasswordAuthenticationCallback(success_callback);
54 Java_PasswordAuthenticationManager_requestAuthentication(
56 tab->GetJavaObject().obj(),
57 Java_PasswordAuthenticationCallback_create(
59 reinterpret_cast<intptr_t>(auth_callback)).obj());
63 void OnResult(JNIEnv* env,
66 jboolean authenticated) {
67 PasswordAuthenticationCallback* callback =
68 reinterpret_cast<PasswordAuthenticationCallback*>(callback_ptr);
69 callback->OnResult(authenticated);