| 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/passwords/password_manager_presenter.h" | 5 #include "chrome/browser/ui/passwords/password_manager_presenter.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/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/password_manager/password_store_factory.h" | 14 #include "chrome/browser/password_manager/password_store_factory.h" |
| 15 #include "chrome/browser/password_manager/sync_metrics.h" | 15 #include "chrome/browser/password_manager/sync_metrics.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 17 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 18 #include "chrome/browser/ui/passwords/password_ui_view.h" | 18 #include "chrome/browser/ui/passwords/password_ui_view.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "components/autofill/core/common/password_form.h" | 22 #include "components/autofill/core/common/password_form.h" |
| 23 #include "components/password_manager/core/browser/affiliation_utils.h" | 23 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 24 #include "components/password_manager/core/browser/import/password_importer.h" |
| 24 #include "components/password_manager/core/browser/password_manager_util.h" | 25 #include "components/password_manager/core/browser/password_manager_util.h" |
| 25 #include "components/password_manager/core/common/password_manager_pref_names.h" | 26 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 26 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 | 29 |
| 29 using password_manager::PasswordStore; | 30 using password_manager::PasswordStore; |
| 30 | 31 |
| 31 PasswordManagerPresenter::PasswordManagerPresenter( | 32 PasswordManagerPresenter::PasswordManagerPresenter( |
| 32 PasswordUIView* password_view) | 33 PasswordUIView* password_view) |
| 33 : populater_(this), | 34 : populater_(this), |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 117 } |
| 117 PasswordStore* store = GetPasswordStore(); | 118 PasswordStore* store = GetPasswordStore(); |
| 118 if (!store) | 119 if (!store) |
| 119 return; | 120 return; |
| 120 store->RemoveLogin(*password_exception_list_[index]); | 121 store->RemoveLogin(*password_exception_list_[index]); |
| 121 content::RecordAction( | 122 content::RecordAction( |
| 122 base::UserMetricsAction("PasswordManager_RemovePasswordException")); | 123 base::UserMetricsAction("PasswordManager_RemovePasswordException")); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void PasswordManagerPresenter::RequestShowPassword(size_t index) { | 126 void PasswordManagerPresenter::RequestShowPassword(size_t index) { |
| 126 #if !defined(OS_ANDROID) // This is never called on Android. | 127 #if defined(OS_ANDROID) |
| 128 NOTREACHED(); |
| 129 #else |
| 127 if (index >= password_list_.size()) { | 130 if (index >= password_list_.size()) { |
| 128 // |index| out of bounds might come from a compromised renderer, don't let | 131 // |index| out of bounds might come from a compromised renderer, don't let |
| 129 // it crash the browser. http://crbug.com/362054 | 132 // it crash the browser. http://crbug.com/362054 |
| 130 NOTREACHED(); | 133 NOTREACHED(); |
| 131 return; | 134 return; |
| 132 } | 135 } |
| 133 if (IsAuthenticationRequired()) { | 136 |
| 134 if (password_manager_util::AuthenticateUser( | 137 if (!IsUserAuthenticated()) { |
| 135 password_view_->GetNativeWindow())) | 138 return; |
| 136 last_authentication_time_ = base::TimeTicks::Now(); | |
| 137 else | |
| 138 return; | |
| 139 } | 139 } |
| 140 | 140 |
| 141 if (password_manager_sync_metrics::IsSyncAccountCredential( | 141 if (password_manager_sync_metrics::IsSyncAccountCredential( |
| 142 password_view_->GetProfile(), | 142 password_view_->GetProfile(), |
| 143 base::UTF16ToUTF8(password_list_[index]->username_value), | 143 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 144 password_list_[index]->signon_realm)) { | 144 password_list_[index]->signon_realm)) { |
| 145 content::RecordAction( | 145 content::RecordAction( |
| 146 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); | 146 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Call back the front end to reveal the password. | 149 // Call back the front end to reveal the password. |
| 150 std::string origin_url = password_manager::GetHumanReadableOrigin( | 150 std::string origin_url = password_manager::GetHumanReadableOrigin( |
| 151 *password_list_[index], languages_); | 151 *password_list_[index], languages_); |
| 152 password_view_->ShowPassword( | 152 password_view_->ShowPassword( |
| 153 index, | 153 index, |
| 154 origin_url, | 154 origin_url, |
| 155 base::UTF16ToUTF8(password_list_[index]->username_value), | 155 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 156 password_list_[index]->password_value); | 156 password_list_[index]->password_value); |
| 157 #endif | 157 #endif |
| 158 } | 158 } |
| 159 | 159 |
| 160 ScopedVector<autofill::PasswordForm> |
| 161 PasswordManagerPresenter::GetAllPasswords() { |
| 162 ScopedVector<autofill::PasswordForm> ret_val; |
| 163 |
| 164 for (const autofill::PasswordForm* form : password_list_.get()) { |
| 165 ret_val.push_back(new autofill::PasswordForm(*form)); |
| 166 } |
| 167 |
| 168 return ret_val.Pass(); |
| 169 } |
| 170 |
| 160 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 171 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
| 161 size_t index) { | 172 size_t index) { |
| 162 if (index >= password_list_.size()) { | 173 if (index >= password_list_.size()) { |
| 163 // |index| out of bounds might come from a compromised renderer, don't let | 174 // |index| out of bounds might come from a compromised renderer, don't let |
| 164 // it crash the browser. http://crbug.com/362054 | 175 // it crash the browser. http://crbug.com/362054 |
| 165 NOTREACHED(); | 176 NOTREACHED(); |
| 166 return NULL; | 177 return NULL; |
| 167 } | 178 } |
| 168 return password_list_[index]; | 179 return password_list_[index]; |
| 169 } | 180 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 195 void PasswordManagerPresenter::SetPasswordExceptionList() { | 206 void PasswordManagerPresenter::SetPasswordExceptionList() { |
| 196 password_view_->SetPasswordExceptionList(password_exception_list_); | 207 password_view_->SetPasswordExceptionList(password_exception_list_); |
| 197 } | 208 } |
| 198 | 209 |
| 199 bool PasswordManagerPresenter::IsAuthenticationRequired() { | 210 bool PasswordManagerPresenter::IsAuthenticationRequired() { |
| 200 base::TimeDelta delta = base::TimeDelta::FromSeconds(60); | 211 base::TimeDelta delta = base::TimeDelta::FromSeconds(60); |
| 201 return require_reauthentication_ && | 212 return require_reauthentication_ && |
| 202 (base::TimeTicks::Now() - last_authentication_time_) > delta; | 213 (base::TimeTicks::Now() - last_authentication_time_) > delta; |
| 203 } | 214 } |
| 204 | 215 |
| 216 bool PasswordManagerPresenter::IsUserAuthenticated() { |
| 217 #if defined(OS_ANDROID) |
| 218 NOTREACHED(); |
| 219 return false; |
| 220 #else |
| 221 if (IsAuthenticationRequired()) { |
| 222 if (password_manager_util::AuthenticateUser( |
| 223 password_view_->GetNativeWindow())) |
| 224 last_authentication_time_ = base::TimeTicks::Now(); |
| 225 else |
| 226 return false; |
| 227 } |
| 228 return true; |
| 229 #endif |
| 230 } |
| 231 |
| 205 PasswordManagerPresenter::ListPopulater::ListPopulater( | 232 PasswordManagerPresenter::ListPopulater::ListPopulater( |
| 206 PasswordManagerPresenter* page) : page_(page) { | 233 PasswordManagerPresenter* page) : page_(page) { |
| 207 } | 234 } |
| 208 | 235 |
| 209 PasswordManagerPresenter::ListPopulater::~ListPopulater() { | 236 PasswordManagerPresenter::ListPopulater::~ListPopulater() { |
| 210 } | 237 } |
| 211 | 238 |
| 212 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( | 239 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( |
| 213 PasswordManagerPresenter* page) : ListPopulater(page) { | 240 PasswordManagerPresenter* page) : ListPopulater(page) { |
| 214 } | 241 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 242 } else { | 269 } else { |
| 243 LOG(ERROR) << "No password store! Cannot display exceptions."; | 270 LOG(ERROR) << "No password store! Cannot display exceptions."; |
| 244 } | 271 } |
| 245 } | 272 } |
| 246 | 273 |
| 247 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 274 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 248 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 275 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
| 249 page_->password_exception_list_.swap(results); | 276 page_->password_exception_list_.swap(results); |
| 250 page_->SetPasswordExceptionList(); | 277 page_->SetPasswordExceptionList(); |
| 251 } | 278 } |
| OLD | NEW |