1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/password_ui_view_android.h"
#include "base/android/jni_string.h"
#include "base/android/jni_weak_ref.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/common/experiments.h"
#include "components/password_manager/core/common/password_manager_switches.h"
#include "jni/PasswordUIView_jni.h"
using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString;
using base::android::ScopedJavaLocalRef;
PasswordUIViewAndroid::PasswordUIViewAndroid(JNIEnv* env, jobject obj)
: password_manager_presenter_(this), weak_java_ui_controller_(env, obj) {}
PasswordUIViewAndroid::~PasswordUIViewAndroid() {}
void PasswordUIViewAndroid::Destroy(JNIEnv*, jobject) { delete this; }
Profile* PasswordUIViewAndroid::GetProfile() {
return ProfileManager::GetLastUsedProfile();
}
void PasswordUIViewAndroid::ShowPassword(
size_t index, const base::string16& password_value) {
NOTIMPLEMENTED();
}
void PasswordUIViewAndroid::SetPasswordList(
const ScopedVector<autofill::PasswordForm>& password_list,
bool show_passwords) {
// Android just ignores the |show_passwords| argument.
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
if (!ui_controller.is_null()) {
Java_PasswordUIView_passwordListAvailable(
env, ui_controller.obj(), static_cast<int>(password_list.size()));
}
}
void PasswordUIViewAndroid::SetPasswordExceptionList(
const ScopedVector<autofill::PasswordForm>& password_exception_list) {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
if (!ui_controller.is_null()) {
Java_PasswordUIView_passwordExceptionListAvailable(
env,
ui_controller.obj(),
static_cast<int>(password_exception_list.size()));
}
}
void PasswordUIViewAndroid::UpdatePasswordLists(JNIEnv* env, jobject) {
password_manager_presenter_.UpdatePasswordLists();
}
ScopedJavaLocalRef<jobject>
PasswordUIViewAndroid::GetSavedPasswordEntry(JNIEnv* env, jobject, int index) {
const autofill::PasswordForm* form =
password_manager_presenter_.GetPassword(index);
if (!form) {
return Java_PasswordUIView_createSavedPasswordEntry(
env,
ConvertUTF8ToJavaString(env, std::string()).obj(),
ConvertUTF16ToJavaString(env, base::string16()).obj());
}
std::string human_readable_origin = GetHumanReadableOrigin(
*form, GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
return Java_PasswordUIView_createSavedPasswordEntry(
env, ConvertUTF8ToJavaString(env, human_readable_origin).obj(),
ConvertUTF16ToJavaString(env, form->username_value).obj());
}
ScopedJavaLocalRef<jstring> PasswordUIViewAndroid::GetSavedPasswordException(
JNIEnv* env, jobject, int index) {
const autofill::PasswordForm* form =
password_manager_presenter_.GetPasswordException(index);
if (!form)
return ConvertUTF8ToJavaString(env, std::string());
std::string human_readable_origin = GetHumanReadableOrigin(
*form, GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
return ConvertUTF8ToJavaString(env, human_readable_origin);
}
void PasswordUIViewAndroid::HandleRemoveSavedPasswordEntry(
JNIEnv* env, jobject, int index) {
password_manager_presenter_.RemoveSavedPassword(index);
}
void PasswordUIViewAndroid::HandleRemoveSavedPasswordException(
JNIEnv* env, jobject, int index) {
password_manager_presenter_.RemovePasswordException(index);
}
jstring GetAccountDashboardURL(JNIEnv* env, jclass) {
return ConvertUTF8ToJavaString(
env, chrome::kPasswordManagerAccountDashboardURL).Release();
}
static jboolean ShouldDisplayManageAccountLink(
JNIEnv* env, jclass) {
return password_manager::ManageAccountLinkExperimentEnabled();
}
static jboolean ShouldUseSmartLockBranding(
JNIEnv* env, jclass) {
const ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(
ProfileManager::GetLastUsedProfile());
return password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service);
}
// static
static jlong Init(JNIEnv* env, jobject obj) {
PasswordUIViewAndroid* controller = new PasswordUIViewAndroid(env, obj);
return reinterpret_cast<intptr_t>(controller);
}
bool PasswordUIViewAndroid::RegisterPasswordUIViewAndroid(JNIEnv* env) {
return RegisterNativesImpl(env);
}
|