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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
// 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/ui/webui/options/password_manager_handler.h"
#include "base/bind.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#if defined(OS_WIN) && defined(USE_ASH)
#include "chrome/browser/ui/ash/ash_util.h"
#endif
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/autofill/core/common/password_form.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "net/base/net_util.h"
namespace options {
PasswordManagerHandler::PasswordManagerHandler()
: password_manager_presenter_(this) {}
PasswordManagerHandler::~PasswordManagerHandler() {}
Profile* PasswordManagerHandler::GetProfile() {
return Profile::FromWebUI(web_ui());
}
#if !defined(OS_ANDROID)
gfx::NativeWindow PasswordManagerHandler::GetNativeWindow() {
return web_ui()->GetWebContents()->GetTopLevelNativeWindow();
}
#endif
void PasswordManagerHandler::GetLocalizedValues(
base::DictionaryValue* localized_strings) {
DCHECK(localized_strings);
static const OptionsStringResource resources[] = {
{ "savedPasswordsTitle",
IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE },
{ "passwordExceptionsTitle",
IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE },
{ "passwordSearchPlaceholder",
IDS_PASSWORDS_PAGE_SEARCH_PASSWORDS },
{ "passwordShowButton",
IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON },
{ "passwordHideButton",
IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON },
{ "passwordsNoPasswordsDescription",
IDS_PASSWORDS_PAGE_VIEW_NO_PASSWORDS_DESCRIPTION },
{ "passwordsNoExceptionsDescription",
IDS_PASSWORDS_PAGE_VIEW_NO_EXCEPTIONS_DESCRIPTION },
};
RegisterStrings(localized_strings, resources, arraysize(resources));
RegisterTitle(localized_strings, "passwordsPage",
IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE);
localized_strings->SetString("passwordManagerLearnMoreURL",
chrome::kPasswordManagerLearnMoreURL);
bool disable_show_passwords = false;
#if defined(OS_WIN) && defined(USE_ASH)
// We disable the ability to show passwords when running in Windows Metro
// interface. This is because we cannot pop native Win32 dialogs from the
// Metro process.
// TODO(wfh): Revisit this if Metro usage grows.
if (chrome::IsNativeWindowInAsh(GetNativeWindow()))
disable_show_passwords = true;
#endif
localized_strings->SetBoolean("disableShowPasswords", disable_show_passwords);
}
void PasswordManagerHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"updatePasswordLists",
base::Bind(&PasswordManagerHandler::HandleUpdatePasswordLists,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"removeSavedPassword",
base::Bind(&PasswordManagerHandler::HandleRemoveSavedPassword,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"removePasswordException",
base::Bind(&PasswordManagerHandler::HandleRemovePasswordException,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"requestShowPassword",
base::Bind(&PasswordManagerHandler::HandleRequestShowPassword,
base::Unretained(this)));
}
void PasswordManagerHandler::InitializeHandler() {
password_manager_presenter_.Initialize();
}
void PasswordManagerHandler::HandleRemoveSavedPassword(
const base::ListValue* args) {
std::string string_value = base::UTF16ToUTF8(ExtractStringValue(args));
int index;
if (base::StringToInt(string_value, &index) && index >= 0) {
password_manager_presenter_.RemoveSavedPassword(static_cast<size_t>(index));
}
}
void PasswordManagerHandler::HandleRemovePasswordException(
const base::ListValue* args) {
std::string string_value = base::UTF16ToUTF8(ExtractStringValue(args));
int index;
if (base::StringToInt(string_value, &index) && index >= 0) {
password_manager_presenter_.RemovePasswordException(
static_cast<size_t>(index));
}
}
void PasswordManagerHandler::HandleRequestShowPassword(
const base::ListValue* args) {
int index;
if (!ExtractIntegerValue(args, &index))
NOTREACHED();
password_manager_presenter_.RequestShowPassword(static_cast<size_t>(index));
}
void PasswordManagerHandler::ShowPassword(
size_t index,
const base::string16& password_value) {
// Call back the front end to reveal the password.
web_ui()->CallJavascriptFunction(
"PasswordManager.showPassword",
base::FundamentalValue(static_cast<int>(index)),
base::StringValue(password_value));
}
void PasswordManagerHandler::HandleUpdatePasswordLists(
const base::ListValue* args) {
password_manager_presenter_.UpdatePasswordLists();
}
void PasswordManagerHandler::SetPasswordList(
const ScopedVector<autofill::PasswordForm>& password_list,
bool show_passwords) {
base::ListValue entries;
languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
base::string16 placeholder(base::ASCIIToUTF16(" "));
for (size_t i = 0; i < password_list.size(); ++i) {
base::ListValue* entry = new base::ListValue();
entry->Append(new base::StringValue(net::FormatUrl(password_list[i]->origin,
languages_)));
entry->Append(new base::StringValue(password_list[i]->username_value));
if (show_passwords) {
entry->Append(new base::StringValue(password_list[i]->password_value));
} else {
// Use a placeholder value with the same length as the password.
entry->Append(new base::StringValue(
base::string16(password_list[i]->password_value.length(), ' ')));
}
entries.Append(entry);
}
web_ui()->CallJavascriptFunction("PasswordManager.setSavedPasswordsList",
entries);
}
void PasswordManagerHandler::SetPasswordExceptionList(
const ScopedVector<autofill::PasswordForm>& password_exception_list) {
base::ListValue entries;
for (size_t i = 0; i < password_exception_list.size(); ++i) {
entries.Append(new base::StringValue(
net::FormatUrl(password_exception_list[i]->origin, languages_)));
}
web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList",
entries);
}
} // namespace options
|