Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/browser/ui/webui/options/password_manager_handler.cc

Issue 1318523011: [Password Manager] Copiable username and origin. Linkable origin elided from the left. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes with StringPiece Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/password_manager_handler.h" 5 #include "chrome/browser/ui/webui/options/password_manager_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h" 17 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #if defined(OS_WIN) && defined(USE_ASH) 18 #if defined(OS_WIN) && defined(USE_ASH)
19 #include "chrome/browser/ui/ash/ash_util.h" 19 #include "chrome/browser/ui/ash/ash_util.h"
20 #endif 20 #endif
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "components/autofill/core/common/password_form.h" 24 #include "components/autofill/core/common/password_form.h"
25 #include "components/password_manager/core/browser/affiliation_utils.h" 25 #include <components/password_manager/core/browser/password_ui_utils.h>
26 #include "components/password_manager/core/browser/password_bubble_experiment.h" 26 #include "components/password_manager/core/browser/password_bubble_experiment.h"
27 #include "components/password_manager/core/common/experiments.h" 27 #include "components/password_manager/core/common/experiments.h"
28 #include "components/url_formatter/url_formatter.h"
28 #include "content/public/browser/notification_details.h" 29 #include "content/public/browser/notification_details.h"
29 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
30 #include "content/public/browser/user_metrics.h" 31 #include "content/public/browser/user_metrics.h"
31 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
32 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
33 #include "content/public/common/content_switches.h" 34 #include "content/public/common/content_switches.h"
35 #include "content/public/common/origin_util.h"
34 #include "net/base/net_util.h" 36 #include "net/base/net_util.h"
35 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
36 38
37 namespace options { 39 namespace options {
38 40
41 namespace {
42 // The following constants should be synchronized with the constants in
43 // chrome/browser/resources/options/password_manager_list.js.
44 const char kOriginField[] = "origin";
45 const char kShownUrlField[] = "shownUrl";
46 const char kIsSecureField[] = "isSecure";
47 const char kUsernameField[] = "username";
48 const char kPasswordField[] = "password";
49 const char kFederationField[] = "federation";
50
51 // Copies from |form| to |entry| the origin, shown origin and whether the
52 // origin is secure or not.
53 void copyOriginInfoOfPasswordForm(const autofill::PasswordForm* form,
54 const std::string& languages,
55 scoped_ptr<base::DictionaryValue>& entry) {
56 entry->SetString(
57 kOriginField,
58 url_formatter::FormatUrl(
59 form->origin, languages, url_formatter::kFormatUrlOmitNothing,
60 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr));
61 entry->SetString(kShownUrlField,
62 password_manager::GetShownOrigin(form->origin, languages));
63 entry->SetBoolean(kIsSecureField, content::IsOriginSecure(form->origin));
64 }
65
66 } // namespace
67
39 PasswordManagerHandler::PasswordManagerHandler() 68 PasswordManagerHandler::PasswordManagerHandler()
40 : password_manager_presenter_(this) {} 69 : password_manager_presenter_(this) {}
41 70
42 PasswordManagerHandler::~PasswordManagerHandler() {} 71 PasswordManagerHandler::~PasswordManagerHandler() {}
43 72
44 Profile* PasswordManagerHandler::GetProfile() { 73 Profile* PasswordManagerHandler::GetProfile() {
45 return Profile::FromWebUI(web_ui()); 74 return Profile::FromWebUI(web_ui());
46 } 75 }
47 76
48 #if !defined(OS_ANDROID) 77 #if !defined(OS_ANDROID)
49 gfx::NativeWindow PasswordManagerHandler::GetNativeWindow() const { 78 gfx::NativeWindow PasswordManagerHandler::GetNativeWindow() const {
50 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); 79 return web_ui()->GetWebContents()->GetTopLevelNativeWindow();
51 } 80 }
52 #endif 81 #endif
53 82
54 void PasswordManagerHandler::GetLocalizedValues( 83 void PasswordManagerHandler::GetLocalizedValues(
55 base::DictionaryValue* localized_strings) { 84 base::DictionaryValue* localized_strings) {
56 DCHECK(localized_strings); 85 DCHECK(localized_strings);
57 86
58 static const OptionsStringResource resources[] = { 87 static const OptionsStringResource resources[] = {
59 { "autoSigninTitle", 88 {"autoSigninTitle", IDS_PASSWORDS_AUTO_SIGNIN_TITLE},
60 IDS_PASSWORDS_AUTO_SIGNIN_TITLE }, 89 {"autoSigninDescription", IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION},
61 { "autoSigninDescription", 90 {"savedPasswordsTitle", IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE},
62 IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION }, 91 {"passwordExceptionsTitle", IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE},
63 { "savedPasswordsTitle", 92 {"passwordSearchPlaceholder", IDS_PASSWORDS_PAGE_SEARCH_PASSWORDS},
64 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE }, 93 {"passwordShowButton", IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON},
65 { "passwordExceptionsTitle", 94 {"passwordHideButton", IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON},
66 IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE }, 95 {"passwordsNoPasswordsDescription",
67 { "passwordSearchPlaceholder", 96 IDS_PASSWORDS_PAGE_VIEW_NO_PASSWORDS_DESCRIPTION},
68 IDS_PASSWORDS_PAGE_SEARCH_PASSWORDS }, 97 {"passwordsNoExceptionsDescription",
69 { "passwordShowButton", 98 IDS_PASSWORDS_PAGE_VIEW_NO_EXCEPTIONS_DESCRIPTION},
70 IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON },
71 { "passwordHideButton",
72 IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON },
73 { "passwordsNoPasswordsDescription",
74 IDS_PASSWORDS_PAGE_VIEW_NO_PASSWORDS_DESCRIPTION },
75 { "passwordsNoExceptionsDescription",
76 IDS_PASSWORDS_PAGE_VIEW_NO_EXCEPTIONS_DESCRIPTION },
77 }; 99 };
78 100
79 RegisterStrings(localized_strings, resources, arraysize(resources)); 101 RegisterStrings(localized_strings, resources, arraysize(resources));
80 102
81 const ProfileSyncService* sync_service = 103 const ProfileSyncService* sync_service =
82 ProfileSyncServiceFactory::GetForProfile(GetProfile()); 104 ProfileSyncServiceFactory::GetForProfile(GetProfile());
83 int title_id = 105 int title_id =
84 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service) ? 106 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service)
85 IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS : 107 ? IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS
86 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE; 108 : IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE;
87 RegisterTitle(localized_strings, "passwordsPage", title_id); 109 RegisterTitle(localized_strings, "passwordsPage", title_id);
88 110
89 localized_strings->SetString("passwordManagerLearnMoreURL", 111 localized_strings->SetString("passwordManagerLearnMoreURL",
90 chrome::kPasswordManagerLearnMoreURL); 112 chrome::kPasswordManagerLearnMoreURL);
91 localized_strings->SetString("passwordsManagePasswordsLink", 113 localized_strings->SetString("passwordsManagePasswordsLink",
92 chrome::kPasswordManagerAccountDashboardURL); 114 chrome::kPasswordManagerAccountDashboardURL);
93 115
94 std::string management_hostname = 116 std::string management_hostname =
95 GURL(chrome::kPasswordManagerAccountDashboardURL).host(); 117 GURL(chrome::kPasswordManagerAccountDashboardURL).host();
96 base::string16 link_text = base::UTF8ToUTF16(management_hostname); 118 base::string16 link_text = base::UTF8ToUTF16(management_hostname);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 const base::ListValue* args) { 213 const base::ListValue* args) {
192 password_manager_presenter_.UpdatePasswordLists(); 214 password_manager_presenter_.UpdatePasswordLists();
193 } 215 }
194 216
195 void PasswordManagerHandler::SetPasswordList( 217 void PasswordManagerHandler::SetPasswordList(
196 const ScopedVector<autofill::PasswordForm>& password_list, 218 const ScopedVector<autofill::PasswordForm>& password_list,
197 bool show_passwords) { 219 bool show_passwords) {
198 base::ListValue entries; 220 base::ListValue entries;
199 languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); 221 languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
200 base::string16 placeholder(base::ASCIIToUTF16(" ")); 222 base::string16 placeholder(base::ASCIIToUTF16(" "));
201 for (size_t i = 0; i < password_list.size(); ++i) { 223 for (const autofill::PasswordForm* saved_password : password_list) {
202 base::ListValue* entry = new base::ListValue(); 224 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
203 entry->AppendString(password_manager::GetHumanReadableOrigin( 225 copyOriginInfoOfPasswordForm(saved_password, languages_, entry);
204 *password_list[i], languages_)); 226
205 entry->AppendString(password_list[i]->username_value); 227 entry->SetString(kUsernameField, saved_password->username_value);
206 if (show_passwords) { 228 if (show_passwords) {
207 entry->AppendString(password_list[i]->password_value); 229 entry->SetString(kPasswordField, saved_password->password_value);
208 } else { 230 } else {
209 // Use a placeholder value with the same length as the password. 231 // Use a placeholder value with the same length as the password.
210 entry->AppendString( 232 entry->SetString(
211 base::string16(password_list[i]->password_value.length(), ' ')); 233 kPasswordField,
234 base::string16(saved_password->password_value.length(), ' '));
212 } 235 }
213 const GURL& federation_url = password_list[i]->federation_url; 236 const GURL& federation_url = saved_password->federation_url;
214 if (!federation_url.is_empty()) { 237 if (!federation_url.is_empty()) {
215 entry->AppendString(l10n_util::GetStringFUTF16( 238 entry->SetString(
216 IDS_PASSWORDS_VIA_FEDERATION, 239 kFederationField,
217 base::UTF8ToUTF16(federation_url.host()))); 240 l10n_util::GetStringFUTF16(IDS_PASSWORDS_VIA_FEDERATION,
241 base::UTF8ToUTF16(federation_url.host())));
218 } 242 }
219 entries.Append(entry); 243
244 entries.Append(entry.release());
220 } 245 }
221 246
222 web_ui()->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", 247 web_ui()->CallJavascriptFunction("PasswordManager.setSavedPasswordsList",
223 entries); 248 entries);
224 } 249 }
225 250
226 void PasswordManagerHandler::SetPasswordExceptionList( 251 void PasswordManagerHandler::SetPasswordExceptionList(
227 const ScopedVector<autofill::PasswordForm>& password_exception_list) { 252 const ScopedVector<autofill::PasswordForm>& password_exception_list) {
228 base::ListValue entries; 253 base::ListValue entries;
229 for (size_t i = 0; i < password_exception_list.size(); ++i) { 254 for (const autofill::PasswordForm* exception : password_exception_list) {
230 entries.AppendString(password_manager::GetHumanReadableOrigin( 255 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
231 *password_exception_list[i], languages_)); 256 copyOriginInfoOfPasswordForm(exception, languages_, entry);
257 entries.Append(entry.release());
232 } 258 }
233 259
234 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", 260 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList",
235 entries); 261 entries);
236 } 262 }
237 263
238 } // namespace options 264 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/password_manager_list.js ('k') | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698