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 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 37 require_reauthentication_ = |
| 38 cl->HasSwitch(switches::kEnablePasswordManagerReauthentication) && |
| 39 !(cl->HasSwitch(switches::kDisablePasswordManagerReauthentication)); |
33 } | 40 } |
34 | 41 |
35 PasswordManagerHandler::~PasswordManagerHandler() { | 42 PasswordManagerHandler::~PasswordManagerHandler() { |
36 PasswordStore* store = GetPasswordStore(); | 43 PasswordStore* store = GetPasswordStore(); |
37 if (store) | 44 if (store) |
38 store->RemoveObserver(this); | 45 store->RemoveObserver(this); |
39 } | 46 } |
40 | 47 |
41 void PasswordManagerHandler::GetLocalizedValues( | 48 void PasswordManagerHandler::GetLocalizedValues( |
42 DictionaryValue* localized_strings) { | 49 DictionaryValue* localized_strings) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 157 } |
151 } | 158 } |
152 | 159 |
153 void PasswordManagerHandler::RequestShowPassword(const ListValue* args) { | 160 void PasswordManagerHandler::RequestShowPassword(const ListValue* args) { |
154 int index; | 161 int index; |
155 if (!ExtractIntegerValue(args, &index)) { | 162 if (!ExtractIntegerValue(args, &index)) { |
156 NOTREACHED(); | 163 NOTREACHED(); |
157 return; | 164 return; |
158 } | 165 } |
159 | 166 |
160 if (!is_user_authenticated_) { | 167 if (IsAuthenticationRequired()) { |
161 // TODO(dubroy): Insert actual authentication code here. | 168 if (password_manager_util::AuthenticateUser()) |
162 is_user_authenticated_ = true; | 169 last_authentication_time_ = base::TimeTicks::Now(); |
| 170 else |
| 171 return; |
163 } | 172 } |
164 | 173 |
165 // Call back the front end to reveal the password. | 174 // Call back the front end to reveal the password. |
166 web_ui()->CallJavascriptFunction( | 175 web_ui()->CallJavascriptFunction( |
167 "PasswordManager.showPassword", | 176 "PasswordManager.showPassword", |
168 base::FundamentalValue(index), | 177 base::FundamentalValue(index), |
169 StringValue(password_list_[index]->password_value)); | 178 StringValue(password_list_[index]->password_value)); |
170 } | 179 } |
171 | 180 |
172 void PasswordManagerHandler::SetPasswordList() { | 181 void PasswordManagerHandler::SetPasswordList() { |
173 // Due to the way that handlers are (re)initialized under certain types of | 182 // 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.) | 183 // 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. | 184 // If this is the case, initialize on demand. This is a hack. |
176 // TODO(mdm): remove this hack once it is no longer necessary. | 185 // TODO(mdm): remove this hack once it is no longer necessary. |
177 if (show_passwords_.GetPrefName().empty()) | 186 if (show_passwords_.GetPrefName().empty()) |
178 InitializeHandler(); | 187 InitializeHandler(); |
179 | 188 |
180 ListValue entries; | 189 ListValue entries; |
181 bool show_passwords = *show_passwords_ && is_user_authenticated_; | 190 bool show_passwords = *show_passwords_ && !require_reauthentication_; |
182 string16 placeholder(ASCIIToUTF16(" ")); | 191 string16 placeholder(ASCIIToUTF16(" ")); |
183 for (size_t i = 0; i < password_list_.size(); ++i) { | 192 for (size_t i = 0; i < password_list_.size(); ++i) { |
184 ListValue* entry = new ListValue(); | 193 ListValue* entry = new ListValue(); |
185 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 194 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, |
186 languages_))); | 195 languages_))); |
187 entry->Append(new StringValue(password_list_[i]->username_value)); | 196 entry->Append(new StringValue(password_list_[i]->username_value)); |
188 if (show_passwords) { | 197 if (show_passwords) { |
189 entry->Append(new StringValue(password_list_[i]->password_value)); | 198 entry->Append(new StringValue(password_list_[i]->password_value)); |
190 } else { | 199 } else { |
191 // Use a placeholder value with the same length as the password. | 200 // Use a placeholder value with the same length as the password. |
(...skipping 11 matching lines...) Expand all Loading... |
203 ListValue entries; | 212 ListValue entries; |
204 for (size_t i = 0; i < password_exception_list_.size(); ++i) { | 213 for (size_t i = 0; i < password_exception_list_.size(); ++i) { |
205 entries.Append(new StringValue( | 214 entries.Append(new StringValue( |
206 net::FormatUrl(password_exception_list_[i]->origin, languages_))); | 215 net::FormatUrl(password_exception_list_[i]->origin, languages_))); |
207 } | 216 } |
208 | 217 |
209 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 218 web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", |
210 entries); | 219 entries); |
211 } | 220 } |
212 | 221 |
| 222 bool PasswordManagerHandler::IsAuthenticationRequired() { |
| 223 base::TimeDelta delta = base::TimeDelta::FromSeconds(60); |
| 224 return require_reauthentication_ && |
| 225 (base::TimeTicks::Now() - last_authentication_time_) > delta; |
| 226 } |
| 227 |
213 PasswordManagerHandler::ListPopulater::ListPopulater( | 228 PasswordManagerHandler::ListPopulater::ListPopulater( |
214 PasswordManagerHandler* page) | 229 PasswordManagerHandler* page) |
215 : page_(page), | 230 : page_(page), |
216 pending_login_query_(0) { | 231 pending_login_query_(0) { |
217 } | 232 } |
218 | 233 |
219 PasswordManagerHandler::ListPopulater::~ListPopulater() { | 234 PasswordManagerHandler::ListPopulater::~ListPopulater() { |
220 } | 235 } |
221 | 236 |
222 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( | 237 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 300 |
286 void PasswordManagerHandler::PasswordExceptionListPopulater:: | 301 void PasswordManagerHandler::PasswordExceptionListPopulater:: |
287 OnGetPasswordStoreResults( | 302 OnGetPasswordStoreResults( |
288 const std::vector<autofill::PasswordForm*>& results) { | 303 const std::vector<autofill::PasswordForm*>& results) { |
289 // TODO(kaiwang): Implement when I refactor | 304 // TODO(kaiwang): Implement when I refactor |
290 // PasswordStore::GetAutofillableLogins and PasswordStore::GetBlacklistLogins. | 305 // PasswordStore::GetAutofillableLogins and PasswordStore::GetBlacklistLogins. |
291 NOTIMPLEMENTED(); | 306 NOTIMPLEMENTED(); |
292 } | 307 } |
293 | 308 |
294 } // namespace options | 309 } // namespace options |
OLD | NEW |