| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" |
| 11 #include "base/values.h" | 13 #include "base/values.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/password_manager/password_manager_util.h" |
| 13 #include "chrome/browser/password_manager/password_store_factory.h" | 16 #include "chrome/browser/password_manager/password_store_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 17 #include "components/autofill/core/common/password_form.h" | 21 #include "components/autofill/core/common/password_form.h" |
| 18 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 21 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
| 22 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 24 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 26 | 30 |
| 27 namespace options { | 31 namespace options { |
| 28 | 32 |
| 29 PasswordManagerHandler::PasswordManagerHandler() | 33 PasswordManagerHandler::PasswordManagerHandler() |
| 30 : populater_(this), | 34 : populater_(this), |
| 31 exception_populater_(this), | 35 exception_populater_(this) { |
| 32 is_user_authenticated_(false) { | 36 require_reauthentication_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 37 switches::kEnablePasswordManagerReauthentication); |
| 33 } | 38 } |
| 34 | 39 |
| 35 PasswordManagerHandler::~PasswordManagerHandler() { | 40 PasswordManagerHandler::~PasswordManagerHandler() { |
| 36 PasswordStore* store = GetPasswordStore(); | 41 PasswordStore* store = GetPasswordStore(); |
| 37 if (store) | 42 if (store) |
| 38 store->RemoveObserver(this); | 43 store->RemoveObserver(this); |
| 39 } | 44 } |
| 40 | 45 |
| 41 void PasswordManagerHandler::GetLocalizedValues( | 46 void PasswordManagerHandler::GetLocalizedValues( |
| 42 DictionaryValue* localized_strings) { | 47 DictionaryValue* localized_strings) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 155 } |
| 151 } | 156 } |
| 152 | 157 |
| 153 void PasswordManagerHandler::RequestShowPassword(const ListValue* args) { | 158 void PasswordManagerHandler::RequestShowPassword(const ListValue* args) { |
| 154 int index; | 159 int index; |
| 155 if (!ExtractIntegerValue(args, &index)) { | 160 if (!ExtractIntegerValue(args, &index)) { |
| 156 NOTREACHED(); | 161 NOTREACHED(); |
| 157 return; | 162 return; |
| 158 } | 163 } |
| 159 | 164 |
| 160 if (!is_user_authenticated_) { | 165 if (IsAuthenticationRequired()) { |
| 161 // TODO(dubroy): Insert actual authentication code here. | 166 if (password_manager_util::AuthenticateUser()) |
| 162 is_user_authenticated_ = true; | 167 last_authentication_time_ = base::TimeTicks::Now(); |
| 168 else |
| 169 return; |
| 163 } | 170 } |
| 164 | 171 |
| 165 // Call back the front end to reveal the password. | 172 // Call back the front end to reveal the password. |
| 166 web_ui()->CallJavascriptFunction( | 173 web_ui()->CallJavascriptFunction( |
| 167 "PasswordManager.showPassword", | 174 "PasswordManager.showPassword", |
| 168 base::FundamentalValue(index), | 175 base::FundamentalValue(index), |
| 169 StringValue(password_list_[index]->password_value)); | 176 StringValue(password_list_[index]->password_value)); |
| 170 } | 177 } |
| 171 | 178 |
| 172 void PasswordManagerHandler::SetPasswordList() { | 179 void PasswordManagerHandler::SetPasswordList() { |
| 173 // Due to the way that handlers are (re)initialized under certain types of | 180 // Due to the way that handlers are (re)initialized under certain types of |
| 174 // navigation, we may not be initialized yet. (See bugs 88986 and 86448.) | 181 // navigation, we may not be initialized yet. (See bugs 88986 and 86448.) |
| 175 // If this is the case, initialize on demand. This is a hack. | 182 // If this is the case, initialize on demand. This is a hack. |
| 176 // TODO(mdm): remove this hack once it is no longer necessary. | 183 // TODO(mdm): remove this hack once it is no longer necessary. |
| 177 if (show_passwords_.GetPrefName().empty()) | 184 if (show_passwords_.GetPrefName().empty()) |
| 178 InitializeHandler(); | 185 InitializeHandler(); |
| 179 | 186 |
| 180 ListValue entries; | 187 ListValue entries; |
| 181 bool show_passwords = *show_passwords_ && is_user_authenticated_; | 188 bool show_passwords = *show_passwords_ && !require_reauthentication_; |
| 182 string16 placeholder(ASCIIToUTF16(" ")); | 189 string16 placeholder(ASCIIToUTF16(" ")); |
| 183 for (size_t i = 0; i < password_list_.size(); ++i) { | 190 for (size_t i = 0; i < password_list_.size(); ++i) { |
| 184 ListValue* entry = new ListValue(); | 191 ListValue* entry = new ListValue(); |
| 185 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 192 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, |
| 186 languages_))); | 193 languages_))); |
| 187 entry->Append(new StringValue(password_list_[i]->username_value)); | 194 entry->Append(new StringValue(password_list_[i]->username_value)); |
| 188 if (show_passwords) { | 195 if (show_passwords) { |
| 189 entry->Append(new StringValue(password_list_[i]->password_value)); | 196 entry->Append(new StringValue(password_list_[i]->password_value)); |
| 190 } else { | 197 } else { |
| 191 // Use a placeholder value with the same length as the password. | 198 // Use a placeholder value with the same length as the password. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 203 ListValue entries; | 210 ListValue entries; |
| 204 for (size_t i = 0; i < password_exception_list_.size(); ++i) { | 211 for (size_t i = 0; i < password_exception_list_.size(); ++i) { |
| 205 entries.Append(new StringValue( | 212 entries.Append(new StringValue( |
| 206 net::FormatUrl(password_exception_list_[i]->origin, languages_))); | 213 net::FormatUrl(password_exception_list_[i]->origin, languages_))); |
| 207 } | 214 } |
| 208 | 215 |
| 209 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 216 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", |
| 210 entries); | 217 entries); |
| 211 } | 218 } |
| 212 | 219 |
| 220 bool PasswordManagerHandler::IsAuthenticationRequired() { |
| 221 base::TimeDelta delta = base::TimeDelta::FromSeconds(60); |
| 222 return require_reauthentication_ && |
| 223 (base::TimeTicks::Now() - last_authentication_time_) > delta; |
| 224 } |
| 225 |
| 213 PasswordManagerHandler::ListPopulater::ListPopulater( | 226 PasswordManagerHandler::ListPopulater::ListPopulater( |
| 214 PasswordManagerHandler* page) | 227 PasswordManagerHandler* page) |
| 215 : page_(page), | 228 : page_(page), |
| 216 pending_login_query_(0) { | 229 pending_login_query_(0) { |
| 217 } | 230 } |
| 218 | 231 |
| 219 PasswordManagerHandler::ListPopulater::~ListPopulater() { | 232 PasswordManagerHandler::ListPopulater::~ListPopulater() { |
| 220 } | 233 } |
| 221 | 234 |
| 222 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( | 235 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 298 |
| 286 void PasswordManagerHandler::PasswordExceptionListPopulater:: | 299 void PasswordManagerHandler::PasswordExceptionListPopulater:: |
| 287 OnGetPasswordStoreResults( | 300 OnGetPasswordStoreResults( |
| 288 const std::vector<autofill::PasswordForm*>& results) { | 301 const std::vector<autofill::PasswordForm*>& results) { |
| 289 // TODO(kaiwang): Implement when I refactor | 302 // TODO(kaiwang): Implement when I refactor |
| 290 // PasswordStore::GetAutofillableLogins and PasswordStore::GetBlacklistLogins. | 303 // PasswordStore::GetAutofillableLogins and PasswordStore::GetBlacklistLogins. |
| 291 NOTIMPLEMENTED(); | 304 NOTIMPLEMENTED(); |
| 292 } | 305 } |
| 293 | 306 |
| 294 } // namespace options | 307 } // namespace options |
| OLD | NEW |