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 "components/password_manager/core/browser/password_manager.h" | 5 #include "components/password_manager/core/browser/password_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 357 } |
358 | 358 |
359 bool PasswordManager::ShouldPromptUserToSavePassword() const { | 359 bool PasswordManager::ShouldPromptUserToSavePassword() const { |
360 return !client_->IsAutomaticPasswordSavingEnabled() && | 360 return !client_->IsAutomaticPasswordSavingEnabled() && |
361 provisional_save_manager_->IsNewLogin() && | 361 provisional_save_manager_->IsNewLogin() && |
362 !provisional_save_manager_->HasGeneratedPassword() && | 362 !provisional_save_manager_->HasGeneratedPassword() && |
363 !provisional_save_manager_->IsPendingCredentialsPublicSuffixMatch(); | 363 !provisional_save_manager_->IsPendingCredentialsPublicSuffixMatch(); |
364 } | 364 } |
365 | 365 |
366 void PasswordManager::OnPasswordFormsRendered( | 366 void PasswordManager::OnPasswordFormsRendered( |
367 const std::vector<PasswordForm>& visible_forms) { | 367 const std::vector<PasswordForm>& visible_forms, |
| 368 bool did_stop_loading) { |
368 CreatePendingLoginManagers(visible_forms); | 369 CreatePendingLoginManagers(visible_forms); |
369 | |
370 scoped_ptr<BrowserSavePasswordProgressLogger> logger; | 370 scoped_ptr<BrowserSavePasswordProgressLogger> logger; |
371 if (client_->IsLoggingActive()) { | 371 if (client_->IsLoggingActive()) { |
372 logger.reset(new BrowserSavePasswordProgressLogger(client_)); | 372 logger.reset(new BrowserSavePasswordProgressLogger(client_)); |
373 logger->LogMessage(Logger::STRING_ON_PASSWORD_FORMS_RENDERED_METHOD); | 373 logger->LogMessage(Logger::STRING_ON_PASSWORD_FORMS_RENDERED_METHOD); |
374 } | 374 } |
375 | 375 |
376 if (!provisional_save_manager_.get()) { | 376 if (!provisional_save_manager_.get()) { |
377 if (logger) { | 377 if (logger) { |
378 logger->LogMessage(Logger::STRING_NO_PROVISIONAL_SAVE_MANAGER); | 378 logger->LogMessage(Logger::STRING_NO_PROVISIONAL_SAVE_MANAGER); |
379 logger->LogMessage(Logger::STRING_DECISION_DROP); | 379 logger->LogMessage(Logger::STRING_DECISION_DROP); |
380 } | 380 } |
381 return; | 381 return; |
382 } | 382 } |
383 | 383 |
384 DCHECK(IsSavingEnabledForCurrentPage()); | 384 DCHECK(IsSavingEnabledForCurrentPage()); |
385 | 385 |
386 if (logger) { | 386 if (logger) { |
387 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS, | 387 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS, |
388 visible_forms.size()); | 388 visible_forms.size()); |
389 } | 389 } |
390 | 390 |
| 391 // Record all visible forms from the frame. |
| 392 all_visible_forms_.insert(all_visible_forms_.end(), |
| 393 visible_forms.begin(), |
| 394 visible_forms.end()); |
| 395 |
391 // If we see the login form again, then the login failed. | 396 // If we see the login form again, then the login failed. |
392 for (size_t i = 0; i < visible_forms.size(); ++i) { | 397 if (did_stop_loading) { |
393 // TODO(vabr): The similarity check is just action equality for now. If it | 398 for (size_t i = 0; i < all_visible_forms_.size(); ++i) { |
394 // becomes more complex, it may make sense to consider modifying and using | 399 // TODO(vabr): The similarity check is just action equality for now. If it |
395 // PasswordFormManager::DoesManage for it. | 400 // becomes more complex, it may make sense to consider modifying and using |
396 if (visible_forms[i].action.is_valid() && | 401 // PasswordFormManager::DoesManage for it. |
397 provisional_save_manager_->pending_credentials().action == | 402 if (all_visible_forms_[i].action.is_valid() && |
398 visible_forms[i].action) { | 403 provisional_save_manager_->pending_credentials().action == |
399 if (logger) { | 404 all_visible_forms_[i].action) { |
400 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED, | 405 if (logger) { |
401 visible_forms[i]); | 406 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED, |
402 logger->LogMessage(Logger::STRING_DECISION_DROP); | 407 visible_forms[i]); |
| 408 logger->LogMessage(Logger::STRING_DECISION_DROP); |
| 409 } |
| 410 provisional_save_manager_->SubmitFailed(); |
| 411 provisional_save_manager_.reset(); |
| 412 // Clear all_visible_forms_ once we found the match. |
| 413 all_visible_forms_.clear(); |
| 414 return; |
403 } | 415 } |
404 provisional_save_manager_->SubmitFailed(); | 416 } |
| 417 |
| 418 // Clear all_visible_forms_ after checking all the visible forms. |
| 419 all_visible_forms_.clear(); |
| 420 |
| 421 // Looks like a successful login attempt. Either show an infobar or |
| 422 // automatically save the login data. We prompt when the user hasn't |
| 423 // already given consent, either through previously accepting the infobar |
| 424 // or by having the browser generate the password. |
| 425 provisional_save_manager_->SubmitPassed(); |
| 426 |
| 427 if (ShouldPromptUserToSavePassword()) { |
| 428 if (logger) |
| 429 logger->LogMessage(Logger::STRING_DECISION_ASK); |
| 430 client_->PromptUserToSavePassword(provisional_save_manager_.release()); |
| 431 } else { |
| 432 if (logger) |
| 433 logger->LogMessage(Logger::STRING_DECISION_SAVE); |
| 434 provisional_save_manager_->Save(); |
405 provisional_save_manager_.reset(); | 435 provisional_save_manager_.reset(); |
406 return; | |
407 } | 436 } |
408 } | 437 } |
409 | |
410 // Looks like a successful login attempt. Either show an infobar or | |
411 // automatically save the login data. We prompt when the user hasn't already | |
412 // given consent, either through previously accepting the infobar or by having | |
413 // the browser generate the password. | |
414 provisional_save_manager_->SubmitPassed(); | |
415 | |
416 if (ShouldPromptUserToSavePassword()) { | |
417 if (logger) | |
418 logger->LogMessage(Logger::STRING_DECISION_ASK); | |
419 client_->PromptUserToSavePassword(provisional_save_manager_.release()); | |
420 } else { | |
421 if (logger) | |
422 logger->LogMessage(Logger::STRING_DECISION_SAVE); | |
423 provisional_save_manager_->Save(); | |
424 provisional_save_manager_.reset(); | |
425 } | |
426 } | 438 } |
427 | 439 |
428 void PasswordManager::PossiblyInitializeUsernamesExperiment( | 440 void PasswordManager::PossiblyInitializeUsernamesExperiment( |
429 const PasswordFormMap& best_matches) const { | 441 const PasswordFormMap& best_matches) const { |
430 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment)) | 442 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment)) |
431 return; | 443 return; |
432 | 444 |
433 bool other_possible_usernames_exist = false; | 445 bool other_possible_usernames_exist = false; |
434 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin(); | 446 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin(); |
435 it != best_matches.end(); | 447 it != best_matches.end(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 observers_, | 515 observers_, |
504 OnAutofillDataAvailable(preferred_match.username_value, | 516 OnAutofillDataAvailable(preferred_match.username_value, |
505 preferred_match.password_value)); | 517 preferred_match.password_value)); |
506 break; | 518 break; |
507 } | 519 } |
508 | 520 |
509 client_->PasswordWasAutofilled(best_matches); | 521 client_->PasswordWasAutofilled(best_matches); |
510 } | 522 } |
511 | 523 |
512 } // namespace password_manager | 524 } // namespace password_manager |
OLD | NEW |