| 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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_split.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #if defined(OS_WIN) && defined(USE_ASH) | 15 #if defined(OS_WIN) && defined(USE_ASH) |
| 15 #include "chrome/browser/ui/ash/ash_util.h" | 16 #include "chrome/browser/ui/ash/ash_util.h" |
| 16 #endif | 17 #endif |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/autofill/core/common/password_form.h" | 21 #include "components/autofill/core/common/password_form.h" |
| 22 #include "components/password_manager/core/common/experiments.h" |
| 21 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
| 26 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 29 #include "ui/base/l10n/l10n_util.h" |
| 27 | 30 |
| 28 namespace options { | 31 namespace options { |
| 29 | 32 |
| 30 PasswordManagerHandler::PasswordManagerHandler() | 33 PasswordManagerHandler::PasswordManagerHandler() |
| 31 : password_manager_presenter_(this) {} | 34 : password_manager_presenter_(this) {} |
| 32 | 35 |
| 33 PasswordManagerHandler::~PasswordManagerHandler() {} | 36 PasswordManagerHandler::~PasswordManagerHandler() {} |
| 34 | 37 |
| 35 Profile* PasswordManagerHandler::GetProfile() { | 38 Profile* PasswordManagerHandler::GetProfile() { |
| 36 return Profile::FromWebUI(web_ui()); | 39 return Profile::FromWebUI(web_ui()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 62 { "passwordsNoExceptionsDescription", | 65 { "passwordsNoExceptionsDescription", |
| 63 IDS_PASSWORDS_PAGE_VIEW_NO_EXCEPTIONS_DESCRIPTION }, | 66 IDS_PASSWORDS_PAGE_VIEW_NO_EXCEPTIONS_DESCRIPTION }, |
| 64 }; | 67 }; |
| 65 | 68 |
| 66 RegisterStrings(localized_strings, resources, arraysize(resources)); | 69 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 67 RegisterTitle(localized_strings, "passwordsPage", | 70 RegisterTitle(localized_strings, "passwordsPage", |
| 68 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); | 71 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); |
| 69 | 72 |
| 70 localized_strings->SetString("passwordManagerLearnMoreURL", | 73 localized_strings->SetString("passwordManagerLearnMoreURL", |
| 71 chrome::kPasswordManagerLearnMoreURL); | 74 chrome::kPasswordManagerLearnMoreURL); |
| 75 localized_strings->SetString("passwordsManagePasswordsLink", |
| 76 chrome::kPasswordManagerAccountDashboardURL); |
| 77 |
| 78 std::vector<base::string16> pieces; |
| 79 base::SplitStringDontTrim( |
| 80 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_REMOTE_TEXT), |
| 81 '|', // separator |
| 82 &pieces); |
| 83 DCHECK_EQ(2U, pieces.size()); |
| 84 localized_strings->SetString("passwordsManagePasswordsText", pieces[0]); |
| 85 localized_strings->SetString("passwordsManagePasswordsLinkText", pieces[1]); |
| 86 |
| 72 bool disable_show_passwords = false; | 87 bool disable_show_passwords = false; |
| 73 | 88 |
| 74 #if defined(OS_WIN) && defined(USE_ASH) | 89 #if defined(OS_WIN) && defined(USE_ASH) |
| 75 // We disable the ability to show passwords when running in Windows Metro | 90 // We disable the ability to show passwords when running in Windows Metro |
| 76 // interface. This is because we cannot pop native Win32 dialogs from the | 91 // interface. This is because we cannot pop native Win32 dialogs from the |
| 77 // Metro process. | 92 // Metro process. |
| 78 // TODO(wfh): Revisit this if Metro usage grows. | 93 // TODO(wfh): Revisit this if Metro usage grows. |
| 79 if (chrome::IsNativeWindowInAsh(GetNativeWindow())) | 94 if (chrome::IsNativeWindowInAsh(GetNativeWindow())) |
| 80 disable_show_passwords = true; | 95 disable_show_passwords = true; |
| 81 #endif | 96 #endif |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 web_ui()->RegisterMessageCallback( | 114 web_ui()->RegisterMessageCallback( |
| 100 "requestShowPassword", | 115 "requestShowPassword", |
| 101 base::Bind(&PasswordManagerHandler::HandleRequestShowPassword, | 116 base::Bind(&PasswordManagerHandler::HandleRequestShowPassword, |
| 102 base::Unretained(this))); | 117 base::Unretained(this))); |
| 103 } | 118 } |
| 104 | 119 |
| 105 void PasswordManagerHandler::InitializeHandler() { | 120 void PasswordManagerHandler::InitializeHandler() { |
| 106 password_manager_presenter_.Initialize(); | 121 password_manager_presenter_.Initialize(); |
| 107 } | 122 } |
| 108 | 123 |
| 124 void PasswordManagerHandler::InitializePage() { |
| 125 base::FundamentalValue visible( |
| 126 password_manager::ManageAccountLinkExperimentEnabled()); |
| 127 web_ui()->CallJavascriptFunction( |
| 128 "PasswordManager.setManageAccountLinkVisibility", visible); |
| 129 } |
| 130 |
| 109 void PasswordManagerHandler::HandleRemoveSavedPassword( | 131 void PasswordManagerHandler::HandleRemoveSavedPassword( |
| 110 const base::ListValue* args) { | 132 const base::ListValue* args) { |
| 111 std::string string_value = base::UTF16ToUTF8(ExtractStringValue(args)); | 133 std::string string_value = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 112 int index; | 134 int index; |
| 113 if (base::StringToInt(string_value, &index) && index >= 0) { | 135 if (base::StringToInt(string_value, &index) && index >= 0) { |
| 114 password_manager_presenter_.RemoveSavedPassword(static_cast<size_t>(index)); | 136 password_manager_presenter_.RemoveSavedPassword(static_cast<size_t>(index)); |
| 115 } | 137 } |
| 116 } | 138 } |
| 117 | 139 |
| 118 void PasswordManagerHandler::HandleRemovePasswordException( | 140 void PasswordManagerHandler::HandleRemovePasswordException( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 for (size_t i = 0; i < password_exception_list.size(); ++i) { | 202 for (size_t i = 0; i < password_exception_list.size(); ++i) { |
| 181 entries.Append(new base::StringValue( | 203 entries.Append(new base::StringValue( |
| 182 net::FormatUrl(password_exception_list[i]->origin, languages_))); | 204 net::FormatUrl(password_exception_list[i]->origin, languages_))); |
| 183 } | 205 } |
| 184 | 206 |
| 185 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 207 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", |
| 186 entries); | 208 entries); |
| 187 } | 209 } |
| 188 | 210 |
| 189 } // namespace options | 211 } // namespace options |
| OLD | NEW |