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/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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 return; | 116 return; |
| 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 |
| 126 bool PasswordManagerPresenter::RequestToExportPassword() { | |
|
vabr (Chromium)
2015/07/07 12:58:05
This method now adds nothing to calling IsUserAuth
xunlu
2015/07/07 18:42:47
Done.
| |
| 127 #if defined(OS_ANDROID) | |
| 128 NOTREACHED(); | |
| 129 return false; | |
| 130 #else | |
| 131 return IsUserAuthenticated(); | |
| 132 #endif | |
| 133 } | |
| 134 | |
| 125 void PasswordManagerPresenter::RequestShowPassword(size_t index) { | 135 void PasswordManagerPresenter::RequestShowPassword(size_t index) { |
| 126 #if !defined(OS_ANDROID) // This is never called on Android. | 136 #if defined(OS_ANDROID) |
| 137 NOTREACHED(); | |
| 138 #else | |
| 127 if (index >= password_list_.size()) { | 139 if (index >= password_list_.size()) { |
| 128 // |index| out of bounds might come from a compromised renderer, don't let | 140 // |index| out of bounds might come from a compromised renderer, don't let |
| 129 // it crash the browser. http://crbug.com/362054 | 141 // it crash the browser. http://crbug.com/362054 |
| 130 NOTREACHED(); | 142 NOTREACHED(); |
| 131 return; | 143 return; |
| 132 } | 144 } |
| 133 if (IsAuthenticationRequired()) { | 145 |
| 134 if (password_manager_util::AuthenticateUser( | 146 if (!IsUserAuthenticated()) { |
| 135 password_view_->GetNativeWindow())) | 147 return; |
| 136 last_authentication_time_ = base::TimeTicks::Now(); | |
| 137 else | |
| 138 return; | |
| 139 } | 148 } |
| 140 | 149 |
| 141 if (password_manager_sync_metrics::IsSyncAccountCredential( | 150 if (password_manager_sync_metrics::IsSyncAccountCredential( |
| 142 password_view_->GetProfile(), | 151 password_view_->GetProfile(), |
| 143 base::UTF16ToUTF8(password_list_[index]->username_value), | 152 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 144 password_list_[index]->signon_realm)) { | 153 password_list_[index]->signon_realm)) { |
| 145 content::RecordAction( | 154 content::RecordAction( |
| 146 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); | 155 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); |
| 147 } | 156 } |
| 148 | 157 |
| 149 // Call back the front end to reveal the password. | 158 // Call back the front end to reveal the password. |
| 150 std::string origin_url = password_manager::GetHumanReadableOrigin( | 159 std::string origin_url = password_manager::GetHumanReadableOrigin( |
| 151 *password_list_[index], languages_); | 160 *password_list_[index], languages_); |
| 152 password_view_->ShowPassword( | 161 password_view_->ShowPassword( |
| 153 index, | 162 index, |
| 154 origin_url, | 163 origin_url, |
| 155 base::UTF16ToUTF8(password_list_[index]->username_value), | 164 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 156 password_list_[index]->password_value); | 165 password_list_[index]->password_value); |
| 157 #endif | 166 #endif |
| 158 } | 167 } |
| 159 | 168 |
| 169 ScopedVector<autofill::PasswordForm> | |
| 170 PasswordManagerPresenter::GetAllPasswords() { | |
| 171 ScopedVector<autofill::PasswordForm> ret_val; | |
| 172 | |
| 173 for (const autofill::PasswordForm* form : password_list_.get()) { | |
| 174 ret_val.push_back(new autofill::PasswordForm(*form)); | |
| 175 } | |
| 176 | |
| 177 return ret_val.Pass(); | |
| 178 } | |
| 179 | |
| 160 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 180 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
| 161 size_t index) { | 181 size_t index) { |
| 162 if (index >= password_list_.size()) { | 182 if (index >= password_list_.size()) { |
| 163 // |index| out of bounds might come from a compromised renderer, don't let | 183 // |index| out of bounds might come from a compromised renderer, don't let |
| 164 // it crash the browser. http://crbug.com/362054 | 184 // it crash the browser. http://crbug.com/362054 |
| 165 NOTREACHED(); | 185 NOTREACHED(); |
| 166 return NULL; | 186 return NULL; |
| 167 } | 187 } |
| 168 return password_list_[index]; | 188 return password_list_[index]; |
| 169 } | 189 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 195 void PasswordManagerPresenter::SetPasswordExceptionList() { | 215 void PasswordManagerPresenter::SetPasswordExceptionList() { |
| 196 password_view_->SetPasswordExceptionList(password_exception_list_); | 216 password_view_->SetPasswordExceptionList(password_exception_list_); |
| 197 } | 217 } |
| 198 | 218 |
| 199 bool PasswordManagerPresenter::IsAuthenticationRequired() { | 219 bool PasswordManagerPresenter::IsAuthenticationRequired() { |
| 200 base::TimeDelta delta = base::TimeDelta::FromSeconds(60); | 220 base::TimeDelta delta = base::TimeDelta::FromSeconds(60); |
| 201 return require_reauthentication_ && | 221 return require_reauthentication_ && |
| 202 (base::TimeTicks::Now() - last_authentication_time_) > delta; | 222 (base::TimeTicks::Now() - last_authentication_time_) > delta; |
| 203 } | 223 } |
| 204 | 224 |
| 225 bool PasswordManagerPresenter::IsUserAuthenticated() { | |
| 226 #if defined(OS_ANDROID) | |
| 227 NOTREACHED(); | |
| 228 return false; | |
| 229 #else | |
| 230 if (IsAuthenticationRequired()) { | |
| 231 if (password_manager_util::AuthenticateUser( | |
| 232 password_view_->GetNativeWindow())) | |
| 233 last_authentication_time_ = base::TimeTicks::Now(); | |
| 234 else | |
| 235 return false; | |
| 236 } | |
| 237 return true; | |
| 238 #endif | |
| 239 } | |
| 240 | |
| 205 PasswordManagerPresenter::ListPopulater::ListPopulater( | 241 PasswordManagerPresenter::ListPopulater::ListPopulater( |
| 206 PasswordManagerPresenter* page) : page_(page) { | 242 PasswordManagerPresenter* page) : page_(page) { |
| 207 } | 243 } |
| 208 | 244 |
| 209 PasswordManagerPresenter::ListPopulater::~ListPopulater() { | 245 PasswordManagerPresenter::ListPopulater::~ListPopulater() { |
| 210 } | 246 } |
| 211 | 247 |
| 212 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( | 248 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( |
| 213 PasswordManagerPresenter* page) : ListPopulater(page) { | 249 PasswordManagerPresenter* page) : ListPopulater(page) { |
| 214 } | 250 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 242 } else { | 278 } else { |
| 243 LOG(ERROR) << "No password store! Cannot display exceptions."; | 279 LOG(ERROR) << "No password store! Cannot display exceptions."; |
| 244 } | 280 } |
| 245 } | 281 } |
| 246 | 282 |
| 247 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 283 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 248 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 284 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
| 249 page_->password_exception_list_.swap(results); | 285 page_->password_exception_list_.swap(results); |
| 250 page_->SetPasswordExceptionList(); | 286 page_->SetPasswordExceptionList(); |
| 251 } | 287 } |
| OLD | NEW |