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 |
| 39 PasswordManagerHandler::PasswordManagerHandler() | 41 PasswordManagerHandler::PasswordManagerHandler() |
| 40 : password_manager_presenter_(this) {} | 42 : password_manager_presenter_(this) {} |
| 41 | 43 |
| 42 PasswordManagerHandler::~PasswordManagerHandler() {} | 44 PasswordManagerHandler::~PasswordManagerHandler() {} |
| 43 | 45 |
| 44 Profile* PasswordManagerHandler::GetProfile() { | 46 Profile* PasswordManagerHandler::GetProfile() { |
| 45 return Profile::FromWebUI(web_ui()); | 47 return Profile::FromWebUI(web_ui()); |
| 46 } | 48 } |
| 47 | 49 |
| 48 #if !defined(OS_ANDROID) | 50 #if !defined(OS_ANDROID) |
| 49 gfx::NativeWindow PasswordManagerHandler::GetNativeWindow() const { | 51 gfx::NativeWindow PasswordManagerHandler::GetNativeWindow() const { |
| 50 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 52 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
| 51 } | 53 } |
| 52 #endif | 54 #endif |
| 53 | 55 |
| 54 void PasswordManagerHandler::GetLocalizedValues( | 56 void PasswordManagerHandler::GetLocalizedValues( |
| 55 base::DictionaryValue* localized_strings) { | 57 base::DictionaryValue* localized_strings) { |
| 56 DCHECK(localized_strings); | 58 DCHECK(localized_strings); |
| 57 | 59 |
| 58 static const OptionsStringResource resources[] = { | 60 static const OptionsStringResource resources[] = { |
| 59 { "autoSigninTitle", | 61 {"autoSigninTitle", IDS_PASSWORDS_AUTO_SIGNIN_TITLE}, |
| 60 IDS_PASSWORDS_AUTO_SIGNIN_TITLE }, | 62 {"autoSigninDescription", IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION}, |
| 61 { "autoSigninDescription", | 63 {"savedPasswordsTitle", IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE}, |
| 62 IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION }, | 64 {"passwordExceptionsTitle", IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE}, |
| 63 { "savedPasswordsTitle", | 65 {"passwordSearchPlaceholder", IDS_PASSWORDS_PAGE_SEARCH_PASSWORDS}, |
| 64 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE }, | 66 {"passwordShowButton", IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON}, |
| 65 { "passwordExceptionsTitle", | 67 {"passwordHideButton", IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON}, |
| 66 IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE }, | 68 {"passwordsNoPasswordsDescription", |
| 67 { "passwordSearchPlaceholder", | 69 IDS_PASSWORDS_PAGE_VIEW_NO_PASSWORDS_DESCRIPTION}, |
| 68 IDS_PASSWORDS_PAGE_SEARCH_PASSWORDS }, | 70 {"passwordsNoExceptionsDescription", |
| 69 { "passwordShowButton", | 71 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 }; | 72 }; |
| 78 | 73 |
| 79 RegisterStrings(localized_strings, resources, arraysize(resources)); | 74 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 80 | 75 |
| 81 const ProfileSyncService* sync_service = | 76 const ProfileSyncService* sync_service = |
| 82 ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 77 ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
| 83 int title_id = | 78 int title_id = |
| 84 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service) ? | 79 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service) |
| 85 IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS : | 80 ? IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS |
| 86 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE; | 81 : IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE; |
| 87 RegisterTitle(localized_strings, "passwordsPage", title_id); | 82 RegisterTitle(localized_strings, "passwordsPage", title_id); |
| 88 | 83 |
| 89 localized_strings->SetString("passwordManagerLearnMoreURL", | 84 localized_strings->SetString("passwordManagerLearnMoreURL", |
| 90 chrome::kPasswordManagerLearnMoreURL); | 85 chrome::kPasswordManagerLearnMoreURL); |
| 91 localized_strings->SetString("passwordsManagePasswordsLink", | 86 localized_strings->SetString("passwordsManagePasswordsLink", |
| 92 chrome::kPasswordManagerAccountDashboardURL); | 87 chrome::kPasswordManagerAccountDashboardURL); |
| 93 | 88 |
| 94 std::string management_hostname = | 89 std::string management_hostname = |
| 95 GURL(chrome::kPasswordManagerAccountDashboardURL).host(); | 90 GURL(chrome::kPasswordManagerAccountDashboardURL).host(); |
| 96 base::string16 link_text = base::UTF8ToUTF16(management_hostname); | 91 base::string16 link_text = base::UTF8ToUTF16(management_hostname); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 195 } |
| 201 | 196 |
| 202 void PasswordManagerHandler::SetPasswordList( | 197 void PasswordManagerHandler::SetPasswordList( |
| 203 const ScopedVector<autofill::PasswordForm>& password_list, | 198 const ScopedVector<autofill::PasswordForm>& password_list, |
| 204 bool show_passwords) { | 199 bool show_passwords) { |
| 205 base::ListValue entries; | 200 base::ListValue entries; |
| 206 languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 201 languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 207 base::string16 placeholder(base::ASCIIToUTF16(" ")); | 202 base::string16 placeholder(base::ASCIIToUTF16(" ")); |
| 208 for (size_t i = 0; i < password_list.size(); ++i) { | 203 for (size_t i = 0; i < password_list.size(); ++i) { |
| 209 base::ListValue* entry = new base::ListValue(); | 204 base::ListValue* entry = new base::ListValue(); |
| 210 entry->AppendString(password_manager::GetHumanReadableOrigin( | 205 entry->AppendString(url_formatter::FormatUrl( |
| 211 *password_list[i], languages_)); | 206 password_list[i]->origin, languages_, |
| 207 url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, | |
| 208 nullptr, nullptr, nullptr)); | |
| 209 entry->AppendString( | |
| 210 password_manager::GetShownOrigin(password_list[i]->origin, languages_)); | |
| 211 entry->AppendBoolean(content::IsOriginSecure(password_list[i]->origin)); | |
| 212 entry->AppendString(password_list[i]->username_value); | 212 entry->AppendString(password_list[i]->username_value); |
| 213 if (show_passwords) { | 213 if (show_passwords) { |
| 214 entry->AppendString(password_list[i]->password_value); | 214 entry->AppendString(password_list[i]->password_value); |
| 215 } else { | 215 } else { |
| 216 // Use a placeholder value with the same length as the password. | 216 // Use a placeholder value with the same length as the password. |
| 217 entry->AppendString( | 217 entry->AppendString( |
| 218 base::string16(password_list[i]->password_value.length(), ' ')); | 218 base::string16(password_list[i]->password_value.length(), ' ')); |
| 219 } | 219 } |
| 220 const GURL& federation_url = password_list[i]->federation_url; | 220 const GURL& federation_url = password_list[i]->federation_url; |
| 221 if (!federation_url.is_empty()) { | 221 if (!federation_url.is_empty()) { |
| 222 entry->AppendString(l10n_util::GetStringFUTF16( | 222 entry->AppendString( |
| 223 IDS_PASSWORDS_VIA_FEDERATION, | 223 l10n_util::GetStringFUTF16(IDS_PASSWORDS_VIA_FEDERATION, |
| 224 base::UTF8ToUTF16(federation_url.host()))); | 224 base::UTF8ToUTF16(federation_url.host()))); |
| 225 } | 225 } |
| 226 | |
| 226 entries.Append(entry); | 227 entries.Append(entry); |
| 227 } | 228 } |
| 228 | 229 |
| 229 web_ui()->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", | 230 web_ui()->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", |
| 230 entries); | 231 entries); |
| 231 } | 232 } |
| 232 | 233 |
| 233 void PasswordManagerHandler::SetPasswordExceptionList( | 234 void PasswordManagerHandler::SetPasswordExceptionList( |
| 234 const ScopedVector<autofill::PasswordForm>& password_exception_list) { | 235 const ScopedVector<autofill::PasswordForm>& password_exception_list) { |
| 235 base::ListValue entries; | 236 base::ListValue entries; |
| 236 for (size_t i = 0; i < password_exception_list.size(); ++i) { | 237 for (size_t i = 0; i < password_exception_list.size(); ++i) { |
| 237 entries.AppendString(password_manager::GetHumanReadableOrigin( | 238 base::ListValue* entry = new base::ListValue(); |
|
Evan Stade
2015/10/05 18:59:41
it makes more sense for this to be a dictionary, s
kolos1
2015/10/06 18:52:33
Done.
| |
| 238 *password_exception_list[i], languages_)); | 239 entry->AppendString(url_formatter::FormatUrl( |
| 240 password_exception_list[i]->origin, languages_, | |
| 241 url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, | |
| 242 nullptr, nullptr, nullptr)); | |
| 243 entry->AppendString(password_manager::GetShownOrigin( | |
| 244 password_exception_list[i]->origin, languages_)); | |
| 245 entry->AppendBoolean( | |
| 246 content::IsOriginSecure(password_exception_list[i]->origin)); | |
| 247 | |
| 248 entries.Append(entry); | |
|
Evan Stade
2015/10/05 18:59:41
this version of ListValue::Append is deprecated
kolos1
2015/10/06 18:52:33
Done.
| |
| 239 } | 249 } |
| 240 | 250 |
| 241 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 251 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", |
| 242 entries); | 252 entries); |
| 243 } | 253 } |
| 244 | 254 |
| 245 } // namespace options | 255 } // namespace options |
| OLD | NEW |