Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / android / password_ui_view_android.cc
blobbb3cb5efc8943ac6246bfbf2426dabb9edfa55a5
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/password_manager_switches.h"
15 #include "jni/PasswordUIView_jni.h"
17 using base::android::ConvertUTF16ToJavaString;
18 using base::android::ConvertUTF8ToJavaString;
19 using base::android::ScopedJavaLocalRef;
21 PasswordUIViewAndroid::PasswordUIViewAndroid(JNIEnv* env, jobject obj)
22 : password_manager_presenter_(this), weak_java_ui_controller_(env, obj) {}
24 PasswordUIViewAndroid::~PasswordUIViewAndroid() {}
26 void PasswordUIViewAndroid::Destroy(JNIEnv*, jobject) { delete this; }
28 Profile* PasswordUIViewAndroid::GetProfile() {
29 return ProfileManager::GetLastUsedProfile();
32 void PasswordUIViewAndroid::ShowPassword(
33 size_t index, const base::string16& password_value) {
34 NOTIMPLEMENTED();
37 void PasswordUIViewAndroid::SetPasswordList(
38 const ScopedVector<autofill::PasswordForm>& password_list,
39 bool show_passwords) {
40 // Android just ignores the |show_passwords| argument.
41 JNIEnv* env = base::android::AttachCurrentThread();
42 ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
43 if (!ui_controller.is_null()) {
44 Java_PasswordUIView_passwordListAvailable(
45 env, ui_controller.obj(), static_cast<int>(password_list.size()));
49 void PasswordUIViewAndroid::SetPasswordExceptionList(
50 const ScopedVector<autofill::PasswordForm>& password_exception_list) {
51 JNIEnv* env = base::android::AttachCurrentThread();
52 ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
53 if (!ui_controller.is_null()) {
54 Java_PasswordUIView_passwordExceptionListAvailable(
55 env,
56 ui_controller.obj(),
57 static_cast<int>(password_exception_list.size()));
61 void PasswordUIViewAndroid::UpdatePasswordLists(JNIEnv* env, jobject) {
62 password_manager_presenter_.UpdatePasswordLists();
65 ScopedJavaLocalRef<jobject>
66 PasswordUIViewAndroid::GetSavedPasswordEntry(JNIEnv* env, jobject, int index) {
67 const autofill::PasswordForm* form =
68 password_manager_presenter_.GetPassword(index);
69 if (!form) {
70 return Java_PasswordUIView_createSavedPasswordEntry(
71 env,
72 ConvertUTF8ToJavaString(env, std::string()).obj(),
73 ConvertUTF16ToJavaString(env, base::string16()).obj());
75 return Java_PasswordUIView_createSavedPasswordEntry(
76 env,
77 ConvertUTF8ToJavaString(env, form->origin.spec()).obj(),
78 ConvertUTF16ToJavaString(env, form->username_value).obj());
81 ScopedJavaLocalRef<jstring> PasswordUIViewAndroid::GetSavedPasswordException(
82 JNIEnv* env, jobject, int index) {
83 const autofill::PasswordForm* form =
84 password_manager_presenter_.GetPasswordException(index);
85 if (!form)
86 return ConvertUTF8ToJavaString(env, std::string());
87 return ConvertUTF8ToJavaString(env, form->origin.spec());
90 void PasswordUIViewAndroid::HandleRemoveSavedPasswordEntry(
91 JNIEnv* env, jobject, int index) {
92 password_manager_presenter_.RemoveSavedPassword(index);
95 void PasswordUIViewAndroid::HandleRemoveSavedPasswordException(
96 JNIEnv* env, jobject, int index) {
97 password_manager_presenter_.RemovePasswordException(index);
100 jstring GetAccountDashboardURL(JNIEnv* env, jclass) {
101 return ConvertUTF8ToJavaString(
102 env, chrome::kPasswordManagerAccountDashboardURL).Release();
105 static jboolean ShouldDisplayManageAccountLink(
106 JNIEnv* env, jclass) {
107 std::string group_name =
108 base::FieldTrialList::FindFullName("AndroidPasswordLinkInSettings");
110 CommandLine* command_line = CommandLine::ForCurrentProcess();
111 if (command_line->HasSwitch(
112 password_manager::switches::kDisableAndroidPasswordLink)) {
113 return false;
116 if (command_line->HasSwitch(
117 password_manager::switches::kEnableAndroidPasswordLink)) {
118 return true;
121 return group_name == "Enabled";
124 // static
125 static jlong Init(JNIEnv* env, jobject obj) {
126 PasswordUIViewAndroid* controller = new PasswordUIViewAndroid(env, obj);
127 return reinterpret_cast<intptr_t>(controller);
130 bool PasswordUIViewAndroid::RegisterPasswordUIViewAndroid(JNIEnv* env) {
131 return RegisterNativesImpl(env);