Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1046)

Side by Side Diff: components/password_manager/core/browser/password_manager.cc

Issue 293093002: Don't show "Save password" prompt for a failed login (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 333 }
334 334
335 bool PasswordManager::ShouldPromptUserToSavePassword() const { 335 bool PasswordManager::ShouldPromptUserToSavePassword() const {
336 return !client_->IsAutomaticPasswordSavingEnabled() && 336 return !client_->IsAutomaticPasswordSavingEnabled() &&
337 provisional_save_manager_->IsNewLogin() && 337 provisional_save_manager_->IsNewLogin() &&
338 !provisional_save_manager_->HasGeneratedPassword() && 338 !provisional_save_manager_->HasGeneratedPassword() &&
339 !provisional_save_manager_->IsPendingCredentialsPublicSuffixMatch(); 339 !provisional_save_manager_->IsPendingCredentialsPublicSuffixMatch();
340 } 340 }
341 341
342 void PasswordManager::OnPasswordFormsRendered( 342 void PasswordManager::OnPasswordFormsRendered(
343 const std::vector<PasswordForm>& visible_forms) { 343 const std::vector<PasswordForm>& visible_forms,
344 bool did_stop_loading) {
344 scoped_ptr<BrowserSavePasswordProgressLogger> logger; 345 scoped_ptr<BrowserSavePasswordProgressLogger> logger;
345 if (client_->IsLoggingActive()) { 346 if (client_->IsLoggingActive()) {
346 logger.reset(new BrowserSavePasswordProgressLogger(client_)); 347 logger.reset(new BrowserSavePasswordProgressLogger(client_));
347 logger->LogMessage(Logger::STRING_ON_PASSWORD_FORMS_RENDERED_METHOD); 348 logger->LogMessage(Logger::STRING_ON_PASSWORD_FORMS_RENDERED_METHOD);
348 } 349 }
349 350
350 if (!provisional_save_manager_.get()) { 351 if (!provisional_save_manager_.get()) {
351 if (logger) { 352 if (logger) {
352 logger->LogMessage(Logger::STRING_NO_PROVISIONAL_SAVE_MANAGER); 353 logger->LogMessage(Logger::STRING_NO_PROVISIONAL_SAVE_MANAGER);
353 logger->LogMessage(Logger::STRING_DECISION_DROP); 354 logger->LogMessage(Logger::STRING_DECISION_DROP);
354 } 355 }
355 return; 356 return;
356 } 357 }
357 358
358 DCHECK(IsSavingEnabled()); 359 DCHECK(IsSavingEnabled());
359 360
360 if (logger) { 361 if (logger) {
361 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS, 362 logger->LogNumber(Logger::STRING_NUMBER_OF_VISIBLE_FORMS,
362 visible_forms.size()); 363 visible_forms.size());
363 } 364 }
364 365
365 // If we see the login form again, then the login failed. 366 // Records all visible forms in the page.
vabr (Chromium) 2014/05/23 12:18:36 page or frame?
366 for (size_t i = 0; i < visible_forms.size(); ++i) { 367 for (size_t i = 0; i < visible_forms.size(); ++i) {
367 // TODO(vabr): The similarity check is just action equality for now. If it 368 all_visible_forms_.push_back(visible_forms[i]);
vabr (Chromium) 2014/05/23 12:18:36 nit: consider using std::vector::insert
368 // becomes more complex, it may make sense to consider modifying and using
369 // PasswordFormManager::DoesManage for it.
370 if (visible_forms[i].action.is_valid() &&
371 provisional_save_manager_->pending_credentials().action ==
372 visible_forms[i].action) {
373 if (logger) {
374 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED,
375 visible_forms[i]);
376 logger->LogMessage(Logger::STRING_DECISION_DROP);
377 }
378 provisional_save_manager_->SubmitFailed();
379 provisional_save_manager_.reset();
380 return;
381 }
382 } 369 }
383 370
384 // Looks like a successful login attempt. Either show an infobar or 371 // If we see the login form again, then the login failed.
385 // automatically save the login data. We prompt when the user hasn't already 372 if (did_stop_loading) {
386 // given consent, either through previously accepting the infobar or by having 373 for (size_t i = 0; i < all_visible_forms_.size(); ++i) {
387 // the browser generate the password. 374 // TODO(vabr): The similarity check is just action equality for now. If it
388 provisional_save_manager_->SubmitPassed(); 375 // becomes more complex, it may make sense to consider modifying and using
376 // PasswordFormManager::DoesManage for it.
377 if (all_visible_forms_[i].action.is_valid() &&
378 provisional_save_manager_->pending_credentials().action ==
379 all_visible_forms_[i].action) {
380 if (logger) {
381 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED,
382 visible_forms[i]);
383 logger->LogMessage(Logger::STRING_DECISION_DROP);
384 }
385 provisional_save_manager_->SubmitFailed();
386 provisional_save_manager_.reset();
387 // Clear all_visible_forms_ once we found the match.
388 while (all_visible_forms_.size()) {
vabr (Chromium) 2014/05/23 12:18:36 Did you just mean all_visible_forms_.clear()? Thi
389 all_visible_forms_.resize(all_visible_forms_.size() - 1);
390 }
391 return;
392 }
393 }
389 394
390 if (ShouldPromptUserToSavePassword()) { 395 // Clear all_visible_forms_ after checking all the forms.
391 if (logger) 396 while (all_visible_forms_.size()) {
392 logger->LogMessage(Logger::STRING_DECISION_ASK); 397 all_visible_forms_.resize(all_visible_forms_.size() - 1);
393 client_->PromptUserToSavePassword(provisional_save_manager_.release()); 398 }
394 } else { 399
395 if (logger) 400 // Looks like a successful login attempt. Either show an infobar or
396 logger->LogMessage(Logger::STRING_DECISION_SAVE); 401 // automatically save the login data. We prompt when the user hasn't
397 provisional_save_manager_->Save(); 402 // already given consent, either through previously accepting the infobar
398 provisional_save_manager_.reset(); 403 // or by having the browser generate the password.
404 provisional_save_manager_->SubmitPassed();
405
406 if (ShouldPromptUserToSavePassword()) {
407 if (logger)
408 logger->LogMessage(Logger::STRING_DECISION_ASK);
409 client_->PromptUserToSavePassword(provisional_save_manager_.release());
410 } else {
411 if (logger)
412 logger->LogMessage(Logger::STRING_DECISION_SAVE);
413 provisional_save_manager_->Save();
414 provisional_save_manager_.reset();
415 }
399 } 416 }
400 } 417 }
401 418
402 void PasswordManager::PossiblyInitializeUsernamesExperiment( 419 void PasswordManager::PossiblyInitializeUsernamesExperiment(
403 const PasswordFormMap& best_matches) const { 420 const PasswordFormMap& best_matches) const {
404 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment)) 421 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment))
405 return; 422 return;
406 423
407 bool other_possible_usernames_exist = false; 424 bool other_possible_usernames_exist = false;
408 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin(); 425 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 observers_, 494 observers_,
478 OnAutofillDataAvailable(preferred_match.username_value, 495 OnAutofillDataAvailable(preferred_match.username_value,
479 preferred_match.password_value)); 496 preferred_match.password_value));
480 break; 497 break;
481 } 498 }
482 499
483 client_->PasswordWasAutofilled(best_matches); 500 client_->PasswordWasAutofilled(best_matches);
484 } 501 }
485 502
486 } // namespace password_manager 503 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698