| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/password_manager/password_store_factory.h" | 16 #include "chrome/browser/password_manager/password_store_factory.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 20 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 21 #include "chrome/browser/ui/passwords/password_ui_view.h" | 21 #include "chrome/browser/ui/passwords/password_ui_view.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "components/autofill/core/common/password_form.h" | 25 #include "components/autofill/core/common/password_form.h" |
| 26 #include "components/browser_sync/browser/profile_sync_service.h" | 26 #include "components/browser_sync/browser/profile_sync_service.h" |
| 27 #include "components/password_manager/core/browser/affiliation_utils.h" | 27 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 28 #include "components/password_manager/core/browser/import/password_importer.h" |
| 28 #include "components/password_manager/core/browser/password_manager_util.h" | 29 #include "components/password_manager/core/browser/password_manager_util.h" |
| 29 #include "components/password_manager/core/common/password_manager_pref_names.h" | 30 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 30 #include "components/password_manager/sync/browser/password_sync_util.h" | 31 #include "components/password_manager/sync/browser/password_sync_util.h" |
| 31 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 33 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 33 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 34 | 36 |
| 35 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 36 #include "chrome/browser/password_manager/password_manager_util_win.h" | 38 #include "chrome/browser/password_manager/password_manager_util_win.h" |
| 37 #elif defined(OS_MACOSX) | 39 #elif defined(OS_MACOSX) |
| 38 #include "chrome/browser/password_manager/password_manager_util_mac.h" | 40 #include "chrome/browser/password_manager/password_manager_util_mac.h" |
| 39 #endif | 41 #endif |
| 40 | 42 |
| 41 using password_manager::PasswordStore; | 43 using password_manager::PasswordStore; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 137 } |
| 136 | 138 |
| 137 void PasswordManagerPresenter::RequestShowPassword(size_t index) { | 139 void PasswordManagerPresenter::RequestShowPassword(size_t index) { |
| 138 #if !defined(OS_ANDROID) // This is never called on Android. | 140 #if !defined(OS_ANDROID) // This is never called on Android. |
| 139 if (index >= password_list_.size()) { | 141 if (index >= password_list_.size()) { |
| 140 // |index| out of bounds might come from a compromised renderer, don't let | 142 // |index| out of bounds might come from a compromised renderer, don't let |
| 141 // it crash the browser. http://crbug.com/362054 | 143 // it crash the browser. http://crbug.com/362054 |
| 142 NOTREACHED(); | 144 NOTREACHED(); |
| 143 return; | 145 return; |
| 144 } | 146 } |
| 145 if (require_reauthentication_ && | 147 |
| 146 (base::TimeTicks::Now() - last_authentication_time_) > | 148 if (!IsUserAuthenticated()) { |
| 147 base::TimeDelta::FromSeconds(60)) { | 149 return; |
| 148 bool authenticated = true; | |
| 149 #if defined(OS_WIN) | |
| 150 authenticated = password_manager_util_win::AuthenticateUser( | |
| 151 password_view_->GetNativeWindow()); | |
| 152 #elif defined(OS_MACOSX) | |
| 153 authenticated = password_manager_util_mac::AuthenticateUser(); | |
| 154 #endif | |
| 155 if (authenticated) | |
| 156 last_authentication_time_ = base::TimeTicks::Now(); | |
| 157 else | |
| 158 return; | |
| 159 } | 150 } |
| 160 | 151 |
| 161 sync_driver::SyncService* sync_service = nullptr; | 152 sync_driver::SyncService* sync_service = nullptr; |
| 162 if (ProfileSyncServiceFactory::HasProfileSyncService( | 153 if (ProfileSyncServiceFactory::HasProfileSyncService( |
| 163 password_view_->GetProfile())) { | 154 password_view_->GetProfile())) { |
| 164 sync_service = | 155 sync_service = |
| 165 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile()); | 156 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile()); |
| 166 } | 157 } |
| 167 if (password_manager::sync_util::IsSyncAccountCredential( | 158 if (password_manager::sync_util::IsSyncAccountCredential( |
| 168 *password_list_[index], sync_service, | 159 *password_list_[index], sync_service, |
| 169 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) { | 160 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) { |
| 170 content::RecordAction( | 161 content::RecordAction( |
| 171 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); | 162 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); |
| 172 } | 163 } |
| 173 | 164 |
| 174 // Call back the front end to reveal the password. | 165 // Call back the front end to reveal the password. |
| 175 std::string origin_url = password_manager::GetHumanReadableOrigin( | 166 std::string origin_url = password_manager::GetHumanReadableOrigin( |
| 176 *password_list_[index], languages_); | 167 *password_list_[index], languages_); |
| 177 password_view_->ShowPassword( | 168 password_view_->ShowPassword( |
| 178 index, | 169 index, |
| 179 origin_url, | 170 origin_url, |
| 180 base::UTF16ToUTF8(password_list_[index]->username_value), | 171 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 181 password_list_[index]->password_value); | 172 password_list_[index]->password_value); |
| 182 #endif | 173 #endif |
| 183 } | 174 } |
| 184 | 175 |
| 176 std::vector<scoped_ptr<autofill::PasswordForm>> |
| 177 PasswordManagerPresenter::GetAllPasswords() { |
| 178 std::vector<scoped_ptr<autofill::PasswordForm>> ret_val; |
| 179 |
| 180 for (const auto& form : password_list_) { |
| 181 ret_val.push_back(make_scoped_ptr(new autofill::PasswordForm(*form))); |
| 182 } |
| 183 |
| 184 return ret_val; |
| 185 } |
| 186 |
| 185 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 187 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
| 186 size_t index) { | 188 size_t index) { |
| 187 if (index >= password_list_.size()) { | 189 if (index >= password_list_.size()) { |
| 188 // |index| out of bounds might come from a compromised renderer, don't let | 190 // |index| out of bounds might come from a compromised renderer, don't let |
| 189 // it crash the browser. http://crbug.com/362054 | 191 // it crash the browser. http://crbug.com/362054 |
| 190 NOTREACHED(); | 192 NOTREACHED(); |
| 191 return NULL; | 193 return NULL; |
| 192 } | 194 } |
| 193 return password_list_[index].get(); | 195 return password_list_[index].get(); |
| 194 } | 196 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 214 Initialize(); | 216 Initialize(); |
| 215 | 217 |
| 216 bool show_passwords = *show_passwords_ && !require_reauthentication_; | 218 bool show_passwords = *show_passwords_ && !require_reauthentication_; |
| 217 password_view_->SetPasswordList(password_list_, show_passwords); | 219 password_view_->SetPasswordList(password_list_, show_passwords); |
| 218 } | 220 } |
| 219 | 221 |
| 220 void PasswordManagerPresenter::SetPasswordExceptionList() { | 222 void PasswordManagerPresenter::SetPasswordExceptionList() { |
| 221 password_view_->SetPasswordExceptionList(password_exception_list_); | 223 password_view_->SetPasswordExceptionList(password_exception_list_); |
| 222 } | 224 } |
| 223 | 225 |
| 226 bool PasswordManagerPresenter::IsUserAuthenticated() { |
| 227 #if defined(OS_ANDROID) |
| 228 NOTREACHED(); |
| 229 #endif |
| 230 if (require_reauthentication_ && |
| 231 (base::TimeTicks::Now() - last_authentication_time_) > |
| 232 base::TimeDelta::FromSeconds(60)) { |
| 233 bool authenticated = true; |
| 234 #if defined(OS_WIN) |
| 235 authenticated = password_manager_util_win::AuthenticateUser( |
| 236 password_view_->GetNativeWindow()); |
| 237 #elif defined(OS_MACOSX) |
| 238 authenticated = password_manager_util_mac::AuthenticateUser(); |
| 239 #endif |
| 240 if (authenticated) |
| 241 last_authentication_time_ = base::TimeTicks::Now(); |
| 242 return authenticated; |
| 243 } |
| 244 return true; |
| 245 } |
| 246 |
| 224 PasswordManagerPresenter::ListPopulater::ListPopulater( | 247 PasswordManagerPresenter::ListPopulater::ListPopulater( |
| 225 PasswordManagerPresenter* page) : page_(page) { | 248 PasswordManagerPresenter* page) : page_(page) { |
| 226 } | 249 } |
| 227 | 250 |
| 228 PasswordManagerPresenter::ListPopulater::~ListPopulater() { | 251 PasswordManagerPresenter::ListPopulater::~ListPopulater() { |
| 229 } | 252 } |
| 230 | 253 |
| 231 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( | 254 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( |
| 232 PasswordManagerPresenter* page) : ListPopulater(page) { | 255 PasswordManagerPresenter* page) : ListPopulater(page) { |
| 233 } | 256 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 263 LOG(ERROR) << "No password store! Cannot display exceptions."; | 286 LOG(ERROR) << "No password store! Cannot display exceptions."; |
| 264 } | 287 } |
| 265 } | 288 } |
| 266 | 289 |
| 267 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 290 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 268 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 291 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
| 269 page_->password_exception_list_ = | 292 page_->password_exception_list_ = |
| 270 password_manager_util::ConvertScopedVector(std::move(results)); | 293 password_manager_util::ConvertScopedVector(std::move(results)); |
| 271 page_->SetPasswordExceptionList(); | 294 page_->SetPasswordExceptionList(); |
| 272 } | 295 } |
| OLD | NEW |