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/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 pending_credentials_.preferred = true; | 120 pending_credentials_.preferred = true; |
121 pending_credentials_.blacklisted_by_user = true; | 121 pending_credentials_.blacklisted_by_user = true; |
122 pending_credentials_.username_value.clear(); | 122 pending_credentials_.username_value.clear(); |
123 pending_credentials_.password_value.clear(); | 123 pending_credentials_.password_value.clear(); |
124 | 124 |
125 // Retroactively forget existing matches for this form, so we NEVER prompt or | 125 // Retroactively forget existing matches for this form, so we NEVER prompt or |
126 // autofill it again. | 126 // autofill it again. |
127 if (!best_matches_.empty()) { | 127 if (!best_matches_.empty()) { |
128 PasswordFormMap::const_iterator iter; | 128 PasswordFormMap::const_iterator iter; |
129 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 129 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
130 profile_, Profile::EXPLICIT_ACCESS); | 130 profile_, Profile::EXPLICIT_ACCESS).get(); |
131 if (!password_store) { | 131 if (!password_store) { |
132 NOTREACHED(); | 132 NOTREACHED(); |
133 return; | 133 return; |
134 } | 134 } |
135 for (iter = best_matches_.begin(); iter != best_matches_.end(); ++iter) { | 135 for (iter = best_matches_.begin(); iter != best_matches_.end(); ++iter) { |
136 // We want to remove existing matches for this form so that the exact | 136 // We want to remove existing matches for this form so that the exact |
137 // origin match with |blackisted_by_user == true| is the only result that | 137 // origin match with |blackisted_by_user == true| is the only result that |
138 // shows up in the future for this origin URL. However, we don't want to | 138 // shows up in the future for this origin URL. However, we don't want to |
139 // delete logins that were actually saved on a different page (hence with | 139 // delete logins that were actually saved on a different page (hence with |
140 // different origin URL) and just happened to match this form because of | 140 // different origin URL) and just happened to match this form because of |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 SaveAsNewLogin(true); | 221 SaveAsNewLogin(true); |
222 else | 222 else |
223 UpdateLogin(); | 223 UpdateLogin(); |
224 } | 224 } |
225 | 225 |
226 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { | 226 void PasswordFormManager::FetchMatchingLoginsFromPasswordStore() { |
227 DCHECK_EQ(state_, PRE_MATCHING_PHASE); | 227 DCHECK_EQ(state_, PRE_MATCHING_PHASE); |
228 DCHECK(!pending_login_query_); | 228 DCHECK(!pending_login_query_); |
229 state_ = MATCHING_PHASE; | 229 state_ = MATCHING_PHASE; |
230 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 230 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
231 profile_, Profile::EXPLICIT_ACCESS); | 231 profile_, Profile::EXPLICIT_ACCESS).get(); |
232 if (!password_store) { | 232 if (!password_store) { |
233 NOTREACHED(); | 233 NOTREACHED(); |
234 return; | 234 return; |
235 } | 235 } |
236 pending_login_query_ = password_store->GetLogins(observed_form_, this); | 236 pending_login_query_ = password_store->GetLogins(observed_form_, this); |
237 } | 237 } |
238 | 238 |
239 bool PasswordFormManager::HasCompletedMatching() { | 239 bool PasswordFormManager::HasCompletedMatching() { |
240 return state_ == POST_MATCHING_PHASE; | 240 return state_ == POST_MATCHING_PHASE; |
241 } | 241 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 376 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
377 DCHECK(IsNewLogin()); | 377 DCHECK(IsNewLogin()); |
378 // The new_form is being used to sign in, so it is preferred. | 378 // The new_form is being used to sign in, so it is preferred. |
379 DCHECK(pending_credentials_.preferred); | 379 DCHECK(pending_credentials_.preferred); |
380 // new_form contains the same basic data as observed_form_ (because its the | 380 // new_form contains the same basic data as observed_form_ (because its the |
381 // same form), but with the newly added credentials. | 381 // same form), but with the newly added credentials. |
382 | 382 |
383 DCHECK(!profile_->IsOffTheRecord()); | 383 DCHECK(!profile_->IsOffTheRecord()); |
384 | 384 |
385 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 385 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
386 profile_, Profile::IMPLICIT_ACCESS); | 386 profile_, Profile::IMPLICIT_ACCESS).get(); |
387 if (!password_store) { | 387 if (!password_store) { |
388 NOTREACHED(); | 388 NOTREACHED(); |
389 return; | 389 return; |
390 } | 390 } |
391 | 391 |
392 pending_credentials_.date_created = Time::Now(); | 392 pending_credentials_.date_created = Time::Now(); |
393 password_store->AddLogin(pending_credentials_); | 393 password_store->AddLogin(pending_credentials_); |
394 | 394 |
395 if (reset_preferred_login) { | 395 if (reset_preferred_login) { |
396 UpdatePreferredLoginState(password_store); | 396 UpdatePreferredLoginState(password_store); |
(...skipping 20 matching lines...) Expand all Loading... |
417 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 417 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
418 DCHECK(preferred_match_); | 418 DCHECK(preferred_match_); |
419 // If we're doing an Update, we either autofilled correctly and need to | 419 // If we're doing an Update, we either autofilled correctly and need to |
420 // update the stats, or the user typed in a new password for autofilled | 420 // update the stats, or the user typed in a new password for autofilled |
421 // username, or the user selected one of the non-preferred matches, | 421 // username, or the user selected one of the non-preferred matches, |
422 // thus requiring a swap of preferred bits. | 422 // thus requiring a swap of preferred bits. |
423 DCHECK(!IsNewLogin() && pending_credentials_.preferred); | 423 DCHECK(!IsNewLogin() && pending_credentials_.preferred); |
424 DCHECK(!profile_->IsOffTheRecord()); | 424 DCHECK(!profile_->IsOffTheRecord()); |
425 | 425 |
426 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 426 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
427 profile_, Profile::IMPLICIT_ACCESS); | 427 profile_, Profile::IMPLICIT_ACCESS).get(); |
428 if (!password_store) { | 428 if (!password_store) { |
429 NOTREACHED(); | 429 NOTREACHED(); |
430 return; | 430 return; |
431 } | 431 } |
432 | 432 |
433 UpdatePreferredLoginState(password_store); | 433 UpdatePreferredLoginState(password_store); |
434 | 434 |
435 // Update the new preferred login. | 435 // Update the new preferred login. |
436 // Note origin.spec().length > signon_realm.length implies the origin has a | 436 // Note origin.spec().length > signon_realm.length implies the origin has a |
437 // path, since signon_realm is a prefix of origin for HTML password forms. | 437 // path, since signon_realm is a prefix of origin for HTML password forms. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 515 |
516 void PasswordFormManager::SubmitFailed() { | 516 void PasswordFormManager::SubmitFailed() { |
517 submit_result_ = kSubmitResultFailed; | 517 submit_result_ = kSubmitResultFailed; |
518 } | 518 } |
519 | 519 |
520 void PasswordFormManager::SendNotBlacklistedToRenderer() { | 520 void PasswordFormManager::SendNotBlacklistedToRenderer() { |
521 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); | 521 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); |
522 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), | 522 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), |
523 observed_form_)); | 523 observed_form_)); |
524 } | 524 } |
OLD | NEW |