| 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" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 store->RemoveLogin(*it->second); | 128 store->RemoveLogin(*it->second); |
| 129 duplicates->erase(key); | 129 duplicates->erase(key); |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 PasswordManagerPresenter::PasswordManagerPresenter( | 134 PasswordManagerPresenter::PasswordManagerPresenter( |
| 135 PasswordUIView* password_view) | 135 PasswordUIView* password_view) |
| 136 : populater_(this), | 136 : populater_(this), |
| 137 exception_populater_(this), | 137 exception_populater_(this), |
| 138 require_reauthentication_( | |
| 139 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 140 switches::kDisablePasswordManagerReauthentication)), | |
| 141 password_view_(password_view) { | 138 password_view_(password_view) { |
| 142 DCHECK(password_view_); | 139 DCHECK(password_view_); |
| 143 } | 140 } |
| 144 | 141 |
| 145 PasswordManagerPresenter::~PasswordManagerPresenter() { | 142 PasswordManagerPresenter::~PasswordManagerPresenter() { |
| 146 PasswordStore* store = GetPasswordStore(); | 143 PasswordStore* store = GetPasswordStore(); |
| 147 if (store) | 144 if (store) |
| 148 store->RemoveObserver(this); | 145 store->RemoveObserver(this); |
| 149 } | 146 } |
| 150 | 147 |
| 151 void PasswordManagerPresenter::Initialize() { | 148 void PasswordManagerPresenter::Initialize() { |
| 152 // Due to the way that handlers are (re)initialized under certain types of | |
| 153 // navigation, the presenter may already be initialized. (See bugs 88986 | |
| 154 // and 86448). If this is the case, return immediately. This is a hack. | |
| 155 // TODO(mdm): remove this hack once it is no longer necessary. | |
| 156 if (!show_passwords_.GetPrefName().empty()) | |
| 157 return; | |
| 158 | |
| 159 show_passwords_.Init( | |
| 160 password_manager::prefs::kPasswordManagerAllowShowPasswords, | |
| 161 password_view_->GetProfile()->GetPrefs(), | |
| 162 base::Bind(&PasswordManagerPresenter::UpdatePasswordLists, | |
| 163 base::Unretained(this))); | |
| 164 // TODO(jhawkins) We should not cache web_ui()->GetProfile().See | |
| 165 // crosbug.com/6304. | |
| 166 PasswordStore* store = GetPasswordStore(); | 149 PasswordStore* store = GetPasswordStore(); |
| 167 if (store) | 150 if (store) |
| 168 store->AddObserver(this); | 151 store->AddObserver(this); |
| 169 | 152 |
| 170 languages_ = password_view_->GetProfile()->GetPrefs()-> | 153 languages_ = password_view_->GetProfile()->GetPrefs()-> |
| 171 GetString(prefs::kAcceptLanguages); | 154 GetString(prefs::kAcceptLanguages); |
| 172 } | 155 } |
| 173 | 156 |
| 174 void PasswordManagerPresenter::OnLoginsChanged( | 157 void PasswordManagerPresenter::OnLoginsChanged( |
| 175 const password_manager::PasswordStoreChangeList& changes) { | 158 const password_manager::PasswordStoreChangeList& changes) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 216 } |
| 234 | 217 |
| 235 void PasswordManagerPresenter::RequestShowPassword(size_t index) { | 218 void PasswordManagerPresenter::RequestShowPassword(size_t index) { |
| 236 #if !defined(OS_ANDROID) // This is never called on Android. | 219 #if !defined(OS_ANDROID) // This is never called on Android. |
| 237 if (index >= password_list_.size()) { | 220 if (index >= password_list_.size()) { |
| 238 // |index| out of bounds might come from a compromised renderer, don't let | 221 // |index| out of bounds might come from a compromised renderer, don't let |
| 239 // it crash the browser. http://crbug.com/362054 | 222 // it crash the browser. http://crbug.com/362054 |
| 240 NOTREACHED(); | 223 NOTREACHED(); |
| 241 return; | 224 return; |
| 242 } | 225 } |
| 243 if (require_reauthentication_ && | 226 if ((base::TimeTicks::Now() - last_authentication_time_) > |
| 244 (base::TimeTicks::Now() - last_authentication_time_) > | 227 base::TimeDelta::FromSeconds(60)) { |
| 245 base::TimeDelta::FromSeconds(60)) { | |
| 246 bool authenticated = true; | 228 bool authenticated = true; |
| 247 #if defined(OS_WIN) | 229 #if defined(OS_WIN) |
| 248 authenticated = password_manager_util_win::AuthenticateUser( | 230 authenticated = password_manager_util_win::AuthenticateUser( |
| 249 password_view_->GetNativeWindow()); | 231 password_view_->GetNativeWindow()); |
| 250 #elif defined(OS_MACOSX) | 232 #elif defined(OS_MACOSX) |
| 251 authenticated = password_manager_util_mac::AuthenticateUser(); | 233 authenticated = password_manager_util_mac::AuthenticateUser(); |
| 252 #endif | 234 #endif |
| 253 if (authenticated) | 235 if (authenticated) |
| 254 last_authentication_time_ = base::TimeTicks::Now(); | 236 last_authentication_time_ = base::TimeTicks::Now(); |
| 255 else | 237 else |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 if (index >= password_exception_list_.size()) { | 278 if (index >= password_exception_list_.size()) { |
| 297 // |index| out of bounds might come from a compromised renderer, don't let | 279 // |index| out of bounds might come from a compromised renderer, don't let |
| 298 // it crash the browser. http://crbug.com/362054 | 280 // it crash the browser. http://crbug.com/362054 |
| 299 NOTREACHED(); | 281 NOTREACHED(); |
| 300 return NULL; | 282 return NULL; |
| 301 } | 283 } |
| 302 return password_exception_list_[index].get(); | 284 return password_exception_list_[index].get(); |
| 303 } | 285 } |
| 304 | 286 |
| 305 void PasswordManagerPresenter::SetPasswordList() { | 287 void PasswordManagerPresenter::SetPasswordList() { |
| 306 // Due to the way that handlers are (re)initialized under certain types of | 288 password_view_->SetPasswordList(password_list_); |
| 307 // navigation, the presenter may already be initialized. (See bugs 88986 | |
| 308 // and 86448). If this is the case, return immediately. This is a hack. | |
| 309 // If this is the case, initialize on demand. This is a hack. | |
| 310 // TODO(mdm): remove this hack once it is no longer necessary. | |
| 311 if (show_passwords_.GetPrefName().empty()) | |
| 312 Initialize(); | |
| 313 | |
| 314 bool show_passwords = *show_passwords_ && !require_reauthentication_; | |
| 315 password_view_->SetPasswordList(password_list_, show_passwords); | |
| 316 } | 289 } |
| 317 | 290 |
| 318 void PasswordManagerPresenter::SetPasswordExceptionList() { | 291 void PasswordManagerPresenter::SetPasswordExceptionList() { |
| 319 password_view_->SetPasswordExceptionList(password_exception_list_); | 292 password_view_->SetPasswordExceptionList(password_exception_list_); |
| 320 } | 293 } |
| 321 | 294 |
| 322 void PasswordManagerPresenter::SortEntriesAndHideDuplicates( | 295 void PasswordManagerPresenter::SortEntriesAndHideDuplicates( |
| 323 const std::string& languages, | 296 const std::string& languages, |
| 324 std::vector<scoped_ptr<autofill::PasswordForm>>* list, | 297 std::vector<scoped_ptr<autofill::PasswordForm>>* list, |
| 325 DuplicatesMap* duplicates, | 298 DuplicatesMap* duplicates, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 373 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 401 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 374 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
| 402 page_->password_exception_list_ = | 375 page_->password_exception_list_ = |
| 403 password_manager_util::ConvertScopedVector(std::move(results)); | 376 password_manager_util::ConvertScopedVector(std::move(results)); |
| 404 page_->SortEntriesAndHideDuplicates( | 377 page_->SortEntriesAndHideDuplicates( |
| 405 page_->languages_, &page_->password_exception_list_, | 378 page_->languages_, &page_->password_exception_list_, |
| 406 &page_->password_exception_duplicates_, | 379 &page_->password_exception_duplicates_, |
| 407 false /* don't use username and password*/); | 380 false /* don't use username and password*/); |
| 408 page_->SetPasswordExceptionList(); | 381 page_->SetPasswordExceptionList(); |
| 409 } | 382 } |
| OLD | NEW |