Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / android / password_ui_view_android.cc
blobe657bc6e4751be3170c46484e6eda2e01dbe334a
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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/password_ui_view_android.h"
7 #include "base/android/jni_string.h"
8 #include "base/android/jni_weak_ref.h"
9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/common/url_constants.h"
13 #include "components/autofill/core/common/password_form.h"
14 #include "components/password_manager/core/common/experiments.h"
15 #include "components/password_manager/core/common/password_manager_switches.h"
16 #include "jni/PasswordUIView_jni.h"
18 using base::android::ConvertUTF16ToJavaString;
19 using base::android::ConvertUTF8ToJavaString;
20 using base::android::ScopedJavaLocalRef;
22 PasswordUIViewAndroid::PasswordUIViewAndroid(JNIEnv* env, jobject obj)
23 : password_manager_presenter_(this), weak_java_ui_controller_(env, obj) {}
25 PasswordUIViewAndroid::~PasswordUIViewAndroid() {}
27 void PasswordUIViewAndroid::Destroy(JNIEnv*, jobject) { delete this; }
29 Profile* PasswordUIViewAndroid::GetProfile() {
30 return ProfileManager::GetLastUsedProfile();
33 void PasswordUIViewAndroid::ShowPassword(
34 size_t index, const base::string16& password_value) {
35 NOTIMPLEMENTED();
38 void PasswordUIViewAndroid::SetPasswordList(
39 const ScopedVector<autofill::PasswordForm>& password_list,
40 bool show_passwords) {
41 // Android just ignores the |show_passwords| argument.
42 JNIEnv* env = base::android::AttachCurrentThread();
43 ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
44 if (!ui_controller.is_null()) {
45 Java_PasswordUIView_passwordListAvailable(
46 env, ui_controller.obj(), static_cast<int>(password_list.size()));
50 void PasswordUIViewAndroid::SetPasswordExceptionList(
51 const ScopedVector<autofill::PasswordForm>& password_exception_list) {
52 JNIEnv* env = base::android::AttachCurrentThread();
53 ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
54 if (!ui_controller.is_null()) {
55 Java_PasswordUIView_passwordExceptionListAvailable(
56 env,
57 ui_controller.obj(),
58 static_cast<int>(password_exception_list.size()));
62 void PasswordUIViewAndroid::UpdatePasswordLists(JNIEnv* env, jobject) {
63 password_manager_presenter_.UpdatePasswordLists();
66 ScopedJavaLocalRef<jobject>
67 PasswordUIViewAndroid::GetSavedPasswordEntry(JNIEnv* env, jobject, int index) {
68 const autofill::PasswordForm* form =
69 password_manager_presenter_.GetPassword(index);
70 if (!form) {
71 return Java_PasswordUIView_createSavedPasswordEntry(
72 env,
73 ConvertUTF8ToJavaString(env, std::string()).obj(),
74 ConvertUTF16ToJavaString(env, base::string16()).obj());
76 return Java_PasswordUIView_createSavedPasswordEntry(
77 env,
78 ConvertUTF8ToJavaString(env, form->origin.spec()).obj(),
79 ConvertUTF16ToJavaString(env, form->username_value).obj());
82 ScopedJavaLocalRef<jstring> PasswordUIViewAndroid::GetSavedPasswordException(
83 JNIEnv* env, jobject, int index) {
84 const autofill::PasswordForm* form =
85 password_manager_presenter_.GetPasswordException(index);
86 if (!form)
87 return ConvertUTF8ToJavaString(env, std::string());
88 return ConvertUTF8ToJavaString(env, form->origin.spec());
91 void PasswordUIViewAndroid::HandleRemoveSavedPasswordEntry(
92 JNIEnv* env, jobject, int index) {
93 password_manager_presenter_.RemoveSavedPassword(index);
96 void PasswordUIViewAndroid::HandleRemoveSavedPasswordException(
97 JNIEnv* env, jobject, int index) {
98 password_manager_presenter_.RemovePasswordException(index);
101 jstring GetAccountDashboardURL(JNIEnv* env, jclass) {
102 return ConvertUTF8ToJavaString(
103 env, chrome::kPasswordManagerAccountDashboardURL).Release();
106 static jboolean ShouldDisplayManageAccountLink(
107 JNIEnv* env, jclass) {
108 return password_manager::ManageAccountLinkExperimentEnabled();
111 // static
112 static jlong Init(JNIEnv* env, jobject obj) {
113 PasswordUIViewAndroid* controller = new PasswordUIViewAndroid(env, obj);
114 return reinterpret_cast<intptr_t>(controller);
117 bool PasswordUIViewAndroid::RegisterPasswordUIViewAndroid(JNIEnv* env) {
118 return RegisterNativesImpl(env);