Chromium Code Reviews| 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/password_manager/password_form_manager.h" | 5 #include "chrome/browser/password_manager/password_form_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 PasswordFormManager::PasswordFormManager(Profile* profile, | 29 PasswordFormManager::PasswordFormManager(Profile* profile, |
| 30 PasswordManager* password_manager, | 30 PasswordManager* password_manager, |
| 31 content::WebContents* web_contents, | 31 content::WebContents* web_contents, |
| 32 const PasswordForm& observed_form, | 32 const PasswordForm& observed_form, |
| 33 bool ssl_valid) | 33 bool ssl_valid) |
| 34 : best_matches_deleter_(&best_matches_), | 34 : best_matches_deleter_(&best_matches_), |
| 35 observed_form_(observed_form), | 35 observed_form_(observed_form), |
| 36 is_new_login_(true), | 36 is_new_login_(true), |
| 37 has_generated_password_(false), | 37 has_generated_password_(false), |
| 38 remover_(false), | |
| 38 password_manager_(password_manager), | 39 password_manager_(password_manager), |
| 39 preferred_match_(NULL), | 40 preferred_match_(NULL), |
| 40 state_(PRE_MATCHING_PHASE), | 41 state_(PRE_MATCHING_PHASE), |
| 41 profile_(profile), | 42 profile_(profile), |
| 42 web_contents_(web_contents), | 43 web_contents_(web_contents), |
| 43 manager_action_(kManagerActionNone), | 44 manager_action_(kManagerActionNone), |
| 44 user_action_(kUserActionNone), | 45 user_action_(kUserActionNone), |
| 45 submit_result_(kSubmitResultNotSubmitted) { | 46 submit_result_(kSubmitResultNotSubmitted) { |
| 46 DCHECK(profile_); | 47 DCHECK(profile_); |
| 47 if (observed_form_.origin.is_valid()) | 48 if (observed_form_.origin.is_valid()) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 form.origin.spec().end(), | 103 form.origin.spec().end(), |
| 103 after_scheme2, | 104 after_scheme2, |
| 104 observed_form_.origin.spec().end()) | 105 observed_form_.origin.spec().end()) |
| 105 != form.origin.spec().end(); | 106 != form.origin.spec().end(); |
| 106 } | 107 } |
| 107 return false; | 108 return false; |
| 108 } | 109 } |
| 109 return true; | 110 return true; |
| 110 } | 111 } |
| 111 | 112 |
| 113 void PasswordFormManager::RemoveAndUpdate(const string16& username_to_remove) { | |
|
vabr (Chromium)
2014/03/07 23:43:36
This is duplicated code: RemoveAndUpdate and Updat
riadh.chtara
2014/03/14 17:16:08
Done.
| |
| 114 remover_ = true; | |
| 115 only_update_ = false; | |
| 116 username_to_remove_ = username_to_remove; | |
| 117 | |
| 118 state_ = PRE_MATCHING_PHASE; | |
| 119 FetchMatchingLoginsFromPasswordStore(); | |
| 120 } | |
| 121 | |
| 122 void PasswordFormManager::Update(const string16& username_to_remove) { | |
| 123 remover_ = true; | |
| 124 only_update_ = true; | |
| 125 username_to_remove_ = username_to_remove; | |
| 126 | |
| 127 state_ = PRE_MATCHING_PHASE; | |
| 128 FetchMatchingLoginsFromPasswordStore(); | |
| 129 } | |
| 130 | |
| 112 bool PasswordFormManager::IsBlacklisted() { | 131 bool PasswordFormManager::IsBlacklisted() { |
| 113 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 132 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
| 114 if (preferred_match_ && preferred_match_->blacklisted_by_user) | 133 if (preferred_match_ && preferred_match_->blacklisted_by_user) |
| 115 return true; | 134 return true; |
| 116 return false; | 135 return false; |
| 117 } | 136 } |
| 118 | 137 |
| 119 void PasswordFormManager::PermanentlyBlacklist() { | 138 void PasswordFormManager::PermanentlyBlacklist() { |
| 120 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 139 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
| 121 | 140 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 | 275 |
| 257 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { | 276 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { |
| 258 DCHECK_EQ(state_, PRE_MATCHING_PHASE); | 277 DCHECK_EQ(state_, PRE_MATCHING_PHASE); |
| 259 state_ = MATCHING_PHASE; | 278 state_ = MATCHING_PHASE; |
| 260 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 279 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
| 261 profile_, Profile::EXPLICIT_ACCESS).get(); | 280 profile_, Profile::EXPLICIT_ACCESS).get(); |
| 262 if (!password_store) { | 281 if (!password_store) { |
| 263 NOTREACHED(); | 282 NOTREACHED(); |
| 264 return; | 283 return; |
| 265 } | 284 } |
| 266 password_store->GetLogins(observed_form_, this); | 285 PasswordForm f = observed_form_; |
|
vabr (Chromium)
2014/03/07 23:43:36
Could you please explain to me why do we need to d
riadh.chtara
2014/03/14 18:06:18
I thought that using GetLogins with a PasswordForm
| |
| 286 f.username_value = string16(); | |
| 287 password_store->GetLogins(f, this); | |
| 267 } | 288 } |
| 268 | 289 |
| 269 bool PasswordFormManager::HasCompletedMatching() { | 290 bool PasswordFormManager::HasCompletedMatching() { |
| 270 return state_ == POST_MATCHING_PHASE; | 291 return state_ == POST_MATCHING_PHASE; |
| 271 } | 292 } |
| 272 | 293 |
| 273 void PasswordFormManager::OnRequestDone( | 294 void PasswordFormManager::OnRequestDone( |
| 274 const std::vector<PasswordForm*>& logins_result) { | 295 const std::vector<PasswordForm*>& logins_result) { |
| 275 // Note that the result gets deleted after this call completes, but we own | 296 // Note that the result gets deleted after this call completes, but we own |
| 276 // the PasswordForm objects pointed to by the result vector, thus we keep | 297 // the PasswordForm objects pointed to by the result vector, thus we keep |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 // or (3) if it matched using public suffix domain matching. | 396 // or (3) if it matched using public suffix domain matching. |
| 376 bool wait_for_username = | 397 bool wait_for_username = |
| 377 profile_->IsOffTheRecord() || | 398 profile_->IsOffTheRecord() || |
| 378 observed_form_.action.GetWithEmptyPath() != | 399 observed_form_.action.GetWithEmptyPath() != |
| 379 preferred_match_->action.GetWithEmptyPath() || | 400 preferred_match_->action.GetWithEmptyPath() || |
| 380 preferred_match_->IsPublicSuffixMatch(); | 401 preferred_match_->IsPublicSuffixMatch(); |
| 381 if (wait_for_username) | 402 if (wait_for_username) |
| 382 manager_action_ = kManagerActionNone; | 403 manager_action_ = kManagerActionNone; |
| 383 else | 404 else |
| 384 manager_action_ = kManagerActionAutofilled; | 405 manager_action_ = kManagerActionAutofilled; |
| 385 password_manager_->Autofill(observed_form_, best_matches_, | 406 |
| 386 *preferred_match_, wait_for_username); | 407 if (!remover_) { |
| 408 password_manager_->Autofill( | |
| 409 observed_form_, best_matches_, *preferred_match_, wait_for_username); | |
| 410 } else { | |
| 411 remover_ = false; | |
| 412 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | |
| 413 profile_, Profile::EXPLICIT_ACCESS).get(); | |
| 414 if (!password_store) { | |
| 415 NOTREACHED(); | |
| 416 return; | |
| 417 } | |
| 418 | |
| 419 PasswordFormMap::iterator it = best_matches_.find(username_to_remove_); | |
| 420 | |
| 421 if (it != best_matches_.end()) { | |
| 422 if (!only_update_) | |
| 423 password_store->RemoveLogin(*(it->second)); | |
| 424 | |
| 425 best_matches_.erase(it); | |
| 426 if (best_matches_.size() > 0) { | |
| 427 preferred_match_ = best_matches_.begin()->second; | |
| 428 password_manager_->Autofill(observed_form_, | |
| 429 best_matches_, | |
| 430 *preferred_match_, | |
| 431 wait_for_username); | |
| 432 } | |
| 433 | |
| 434 } | |
| 435 | |
| 436 } | |
| 387 } | 437 } |
| 388 | 438 |
| 389 void PasswordFormManager::OnPasswordStoreRequestDone( | 439 void PasswordFormManager::OnPasswordStoreRequestDone( |
| 390 CancelableRequestProvider::Handle handle, | 440 CancelableRequestProvider::Handle handle, |
| 391 const std::vector<autofill::PasswordForm*>& result) { | 441 const std::vector<autofill::PasswordForm*>& result) { |
| 392 // TODO(kaiwang): Remove this function. | 442 // TODO(kaiwang): Remove this function. |
| 393 NOTREACHED(); | 443 NOTREACHED(); |
| 394 } | 444 } |
| 395 | 445 |
| 396 void PasswordFormManager::OnGetPasswordStoreResults( | 446 void PasswordFormManager::OnGetPasswordStoreResults( |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 | 700 |
| 651 void PasswordFormManager::SubmitFailed() { | 701 void PasswordFormManager::SubmitFailed() { |
| 652 submit_result_ = kSubmitResultFailed; | 702 submit_result_ = kSubmitResultFailed; |
| 653 } | 703 } |
| 654 | 704 |
| 655 void PasswordFormManager::SendNotBlacklistedToRenderer() { | 705 void PasswordFormManager::SendNotBlacklistedToRenderer() { |
| 656 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); | 706 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 657 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), | 707 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), |
| 658 observed_form_)); | 708 observed_form_)); |
| 659 } | 709 } |
| OLD | NEW |