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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
366 // Stores all visible forms from the frame. | |
vabr (Chromium)
2014/06/11 08:22:12
optional nit: Stores -> Store
We usually use imper
vabr (Chromium)
2014/06/11 08:22:12
optional nit: It's up to you if you say "record" o
| |
367 for (size_t i = 0; i < visible_forms.size(); ++i) | |
368 all_visible_forms_.insert(all_visible_forms_.end(), visible_forms[i]); | |
vabr (Chromium)
2014/06/11 08:22:12
No, this is not what I meant. :)
I meant: "Use ins
| |
369 | |
365 // If we see the login form again, then the login failed. | 370 // If we see the login form again, then the login failed. |
366 for (size_t i = 0; i < visible_forms.size(); ++i) { | 371 if (did_stop_loading) { |
367 // TODO(vabr): The similarity check is just action equality for now. If it | 372 for (size_t i = 0; i < all_visible_forms_.size(); ++i) { |
368 // becomes more complex, it may make sense to consider modifying and using | 373 // TODO(vabr): The similarity check is just action equality for now. If it |
369 // PasswordFormManager::DoesManage for it. | 374 // becomes more complex, it may make sense to consider modifying and using |
370 if (visible_forms[i].action.is_valid() && | 375 // PasswordFormManager::DoesManage for it. |
371 provisional_save_manager_->pending_credentials().action == | 376 if (all_visible_forms_[i].action.is_valid() && |
372 visible_forms[i].action) { | 377 provisional_save_manager_->pending_credentials().action == |
373 if (logger) { | 378 all_visible_forms_[i].action) { |
374 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED, | 379 if (logger) { |
375 visible_forms[i]); | 380 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_REAPPEARED, |
376 logger->LogMessage(Logger::STRING_DECISION_DROP); | 381 visible_forms[i]); |
382 logger->LogMessage(Logger::STRING_DECISION_DROP); | |
383 } | |
384 provisional_save_manager_->SubmitFailed(); | |
385 provisional_save_manager_.reset(); | |
386 // Clear all_visible_forms_ once we found the match. | |
387 all_visible_forms_.clear(); | |
388 return; | |
377 } | 389 } |
378 provisional_save_manager_->SubmitFailed(); | 390 } |
391 | |
392 // Clear all_visible_forms_ after checking all the visible forms. | |
393 all_visible_forms_.clear(); | |
394 | |
395 // Looks like a successful login attempt. Either show an infobar or | |
396 // automatically save the login data. We prompt when the user hasn't | |
397 // already given consent, either through previously accepting the infobar | |
398 // or by having the browser generate the password. | |
399 provisional_save_manager_->SubmitPassed(); | |
400 | |
401 if (ShouldPromptUserToSavePassword()) { | |
402 if (logger) | |
403 logger->LogMessage(Logger::STRING_DECISION_ASK); | |
404 client_->PromptUserToSavePassword(provisional_save_manager_.release()); | |
405 } else { | |
406 if (logger) | |
407 logger->LogMessage(Logger::STRING_DECISION_SAVE); | |
408 provisional_save_manager_->Save(); | |
379 provisional_save_manager_.reset(); | 409 provisional_save_manager_.reset(); |
380 return; | |
381 } | 410 } |
382 } | 411 } |
383 | |
384 // Looks like a successful login attempt. Either show an infobar or | |
385 // automatically save the login data. We prompt when the user hasn't already | |
386 // given consent, either through previously accepting the infobar or by having | |
387 // the browser generate the password. | |
388 provisional_save_manager_->SubmitPassed(); | |
389 | |
390 if (ShouldPromptUserToSavePassword()) { | |
391 if (logger) | |
392 logger->LogMessage(Logger::STRING_DECISION_ASK); | |
393 client_->PromptUserToSavePassword(provisional_save_manager_.release()); | |
394 } else { | |
395 if (logger) | |
396 logger->LogMessage(Logger::STRING_DECISION_SAVE); | |
397 provisional_save_manager_->Save(); | |
398 provisional_save_manager_.reset(); | |
399 } | |
400 } | 412 } |
401 | 413 |
402 void PasswordManager::PossiblyInitializeUsernamesExperiment( | 414 void PasswordManager::PossiblyInitializeUsernamesExperiment( |
403 const PasswordFormMap& best_matches) const { | 415 const PasswordFormMap& best_matches) const { |
404 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment)) | 416 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment)) |
405 return; | 417 return; |
406 | 418 |
407 bool other_possible_usernames_exist = false; | 419 bool other_possible_usernames_exist = false; |
408 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin(); | 420 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin(); |
409 it != best_matches.end(); | 421 it != best_matches.end(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 observers_, | 489 observers_, |
478 OnAutofillDataAvailable(preferred_match.username_value, | 490 OnAutofillDataAvailable(preferred_match.username_value, |
479 preferred_match.password_value)); | 491 preferred_match.password_value)); |
480 break; | 492 break; |
481 } | 493 } |
482 | 494 |
483 client_->PasswordWasAutofilled(best_matches); | 495 client_->PasswordWasAutofilled(best_matches); |
484 } | 496 } |
485 | 497 |
486 } // namespace password_manager | 498 } // namespace password_manager |
OLD | NEW |