Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/affiliation_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"; | |
|
Evan Stade
2015/10/13 17:15:01
ditto, not much use for these if you refactor/shar
kolos1
2015/10/15 09:34:53
I would like to have it. It gives explicit descrip
| |
| 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 | |
| 39 PasswordManagerHandler::PasswordManagerHandler() | 52 PasswordManagerHandler::PasswordManagerHandler() |
| 40 : password_manager_presenter_(this) {} | 53 : password_manager_presenter_(this) {} |
| 41 | 54 |
| 42 PasswordManagerHandler::~PasswordManagerHandler() {} | 55 PasswordManagerHandler::~PasswordManagerHandler() {} |
| 43 | 56 |
| 44 Profile* PasswordManagerHandler::GetProfile() { | 57 Profile* PasswordManagerHandler::GetProfile() { |
| 45 return Profile::FromWebUI(web_ui()); | 58 return Profile::FromWebUI(web_ui()); |
| 46 } | 59 } |
| 47 | 60 |
| 48 #if !defined(OS_ANDROID) | 61 #if !defined(OS_ANDROID) |
| 49 gfx::NativeWindow PasswordManagerHandler::GetNativeWindow() const { | 62 gfx::NativeWindow PasswordManagerHandler::GetNativeWindow() const { |
| 50 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 63 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
| 51 } | 64 } |
| 52 #endif | 65 #endif |
| 53 | 66 |
| 54 void PasswordManagerHandler::GetLocalizedValues( | 67 void PasswordManagerHandler::GetLocalizedValues( |
| 55 base::DictionaryValue* localized_strings) { | 68 base::DictionaryValue* localized_strings) { |
| 56 DCHECK(localized_strings); | 69 DCHECK(localized_strings); |
| 57 | 70 |
| 58 static const OptionsStringResource resources[] = { | 71 static const OptionsStringResource resources[] = { |
| 59 { "autoSigninTitle", | 72 {"autoSigninTitle", IDS_PASSWORDS_AUTO_SIGNIN_TITLE}, |
| 60 IDS_PASSWORDS_AUTO_SIGNIN_TITLE }, | 73 {"autoSigninDescription", IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION}, |
| 61 { "autoSigninDescription", | 74 {"savedPasswordsTitle", IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE}, |
| 62 IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION }, | 75 {"passwordExceptionsTitle", IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE}, |
| 63 { "savedPasswordsTitle", | 76 {"passwordSearchPlaceholder", IDS_PASSWORDS_PAGE_SEARCH_PASSWORDS}, |
| 64 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE }, | 77 {"passwordShowButton", IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON}, |
| 65 { "passwordExceptionsTitle", | 78 {"passwordHideButton", IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON}, |
| 66 IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE }, | 79 {"passwordsNoPasswordsDescription", |
| 67 { "passwordSearchPlaceholder", | 80 IDS_PASSWORDS_PAGE_VIEW_NO_PASSWORDS_DESCRIPTION}, |
| 68 IDS_PASSWORDS_PAGE_SEARCH_PASSWORDS }, | 81 {"passwordsNoExceptionsDescription", |
| 69 { "passwordShowButton", | 82 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 }; | 83 }; |
| 78 | 84 |
| 79 RegisterStrings(localized_strings, resources, arraysize(resources)); | 85 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 80 | 86 |
| 81 const ProfileSyncService* sync_service = | 87 const ProfileSyncService* sync_service = |
| 82 ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 88 ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
| 83 int title_id = | 89 int title_id = |
| 84 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service) ? | 90 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service) |
| 85 IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS : | 91 ? IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS |
| 86 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE; | 92 : IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE; |
| 87 RegisterTitle(localized_strings, "passwordsPage", title_id); | 93 RegisterTitle(localized_strings, "passwordsPage", title_id); |
| 88 | 94 |
| 89 localized_strings->SetString("passwordManagerLearnMoreURL", | 95 localized_strings->SetString("passwordManagerLearnMoreURL", |
| 90 chrome::kPasswordManagerLearnMoreURL); | 96 chrome::kPasswordManagerLearnMoreURL); |
| 91 localized_strings->SetString("passwordsManagePasswordsLink", | 97 localized_strings->SetString("passwordsManagePasswordsLink", |
| 92 chrome::kPasswordManagerAccountDashboardURL); | 98 chrome::kPasswordManagerAccountDashboardURL); |
| 93 | 99 |
| 94 std::string management_hostname = | 100 std::string management_hostname = |
| 95 GURL(chrome::kPasswordManagerAccountDashboardURL).host(); | 101 GURL(chrome::kPasswordManagerAccountDashboardURL).host(); |
| 96 base::string16 link_text = base::UTF8ToUTF16(management_hostname); | 102 base::string16 link_text = base::UTF8ToUTF16(management_hostname); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 password_manager_presenter_.UpdatePasswordLists(); | 205 password_manager_presenter_.UpdatePasswordLists(); |
| 200 } | 206 } |
| 201 | 207 |
| 202 void PasswordManagerHandler::SetPasswordList( | 208 void PasswordManagerHandler::SetPasswordList( |
| 203 const ScopedVector<autofill::PasswordForm>& password_list, | 209 const ScopedVector<autofill::PasswordForm>& password_list, |
| 204 bool show_passwords) { | 210 bool show_passwords) { |
| 205 base::ListValue entries; | 211 base::ListValue entries; |
| 206 languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 212 languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 207 base::string16 placeholder(base::ASCIIToUTF16(" ")); | 213 base::string16 placeholder(base::ASCIIToUTF16(" ")); |
| 208 for (size_t i = 0; i < password_list.size(); ++i) { | 214 for (size_t i = 0; i < password_list.size(); ++i) { |
| 209 base::ListValue* entry = new base::ListValue(); | 215 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 210 entry->AppendString(password_manager::GetHumanReadableOrigin( | 216 |
| 211 *password_list[i], languages_)); | 217 entry->SetString(kOriginField, |
| 212 entry->AppendString(password_list[i]->username_value); | 218 url_formatter::FormatUrl( |
| 219 password_list[i]->origin, languages_, | |
| 220 url_formatter::kFormatUrlOmitNothing, | |
| 221 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr)); | |
| 222 | |
| 223 entry->SetString(kShownUrlField, password_manager::GetShownOrigin( | |
| 224 password_list[i]->origin, languages_)); | |
| 225 entry->SetBoolean(kIsSecureField, | |
| 226 content::IsOriginSecure(password_list[i]->origin)); | |
| 227 entry->SetString(kUsernameField, password_list[i]->username_value); | |
| 213 if (show_passwords) { | 228 if (show_passwords) { |
| 214 entry->AppendString(password_list[i]->password_value); | 229 entry->SetString(kPasswordField, password_list[i]->password_value); |
| 215 } else { | 230 } else { |
| 216 // Use a placeholder value with the same length as the password. | 231 // Use a placeholder value with the same length as the password. |
| 217 entry->AppendString( | 232 entry->SetString( |
| 233 kPasswordField, | |
| 218 base::string16(password_list[i]->password_value.length(), ' ')); | 234 base::string16(password_list[i]->password_value.length(), ' ')); |
| 219 } | 235 } |
| 220 const GURL& federation_url = password_list[i]->federation_url; | 236 const GURL& federation_url = password_list[i]->federation_url; |
| 221 if (!federation_url.is_empty()) { | 237 if (!federation_url.is_empty()) { |
| 222 entry->AppendString(l10n_util::GetStringFUTF16( | 238 entry->SetString( |
| 223 IDS_PASSWORDS_VIA_FEDERATION, | 239 kFederationField, |
| 224 base::UTF8ToUTF16(federation_url.host()))); | 240 l10n_util::GetStringFUTF16(IDS_PASSWORDS_VIA_FEDERATION, |
| 241 base::UTF8ToUTF16(federation_url.host()))); | |
| 225 } | 242 } |
| 226 entries.Append(entry); | 243 |
| 244 entries.Append(entry.release()); | |
| 227 } | 245 } |
| 228 | 246 |
| 229 web_ui()->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", | 247 web_ui()->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", |
| 230 entries); | 248 entries); |
| 231 } | 249 } |
| 232 | 250 |
| 233 void PasswordManagerHandler::SetPasswordExceptionList( | 251 void PasswordManagerHandler::SetPasswordExceptionList( |
|
Evan Stade
2015/10/13 17:15:01
it seems like there's a lot of overlap here and in
kolos1
2015/10/15 09:34:53
Done. Thanks.
| |
| 234 const ScopedVector<autofill::PasswordForm>& password_exception_list) { | 252 const ScopedVector<autofill::PasswordForm>& password_exception_list) { |
| 235 base::ListValue entries; | 253 base::ListValue entries; |
| 236 for (size_t i = 0; i < password_exception_list.size(); ++i) { | 254 for (size_t i = 0; i < password_exception_list.size(); ++i) { |
|
Evan Stade
2015/10/13 17:15:01
for (const autofill::PasswordForm& exception : pas
kolos1
2015/10/15 09:34:54
Done. Thanks
| |
| 237 entries.AppendString(password_manager::GetHumanReadableOrigin( | 255 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 238 *password_exception_list[i], languages_)); | 256 |
| 257 entry->SetString(kOriginField, | |
| 258 url_formatter::FormatUrl( | |
| 259 password_exception_list[i]->origin, languages_, | |
| 260 url_formatter::kFormatUrlOmitNothing, | |
| 261 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr)); | |
| 262 entry->SetString(kShownUrlField, | |
| 263 password_manager::GetShownOrigin( | |
| 264 password_exception_list[i]->origin, languages_)); | |
| 265 entry->SetBoolean(kIsSecureField, content::IsOriginSecure( | |
| 266 password_exception_list[i]->origin)); | |
| 267 | |
| 268 entries.Append(entry.release()); | |
| 239 } | 269 } |
| 240 | 270 |
| 241 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 271 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", |
| 242 entries); | 272 entries); |
| 243 } | 273 } |
| 244 | 274 |
| 245 } // namespace options | 275 } // namespace options |
| OLD | NEW |