| 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_manager.h" | 5 #include "chrome/browser/password_manager/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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "chrome/browser/password_manager/password_form_manager.h" | 14 #include "chrome/browser/password_manager/password_form_manager.h" |
| 15 #include "chrome/browser/password_manager/password_manager_delegate.h" | 15 #include "chrome/browser/password_manager/password_manager_delegate.h" |
| 16 #include "chrome/browser/password_manager/password_manager_driver.h" |
| 16 #include "chrome/browser/password_manager/password_manager_metrics_util.h" | 17 #include "chrome/browser/password_manager/password_manager_metrics_util.h" |
| 17 #include "chrome/browser/password_manager/password_manager_util.h" | 18 #include "chrome/browser/password_manager/password_manager_util.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | 20 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "components/autofill/content/common/autofill_messages.h" | 24 #include "components/autofill/content/common/autofill_messages.h" |
| 24 #include "components/autofill/core/common/password_autofill_util.h" | 25 #include "components/autofill/core/common/password_autofill_util.h" |
| 25 #include "components/user_prefs/pref_registry_syncable.h" | 26 #include "components/user_prefs/pref_registry_syncable.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return; | 106 return; |
| 106 } | 107 } |
| 107 | 108 |
| 108 contents->SetUserData(UserDataKey(), | 109 contents->SetUserData(UserDataKey(), |
| 109 new PasswordManager(contents, delegate)); | 110 new PasswordManager(contents, delegate)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 PasswordManager::PasswordManager(WebContents* web_contents, | 113 PasswordManager::PasswordManager(WebContents* web_contents, |
| 113 PasswordManagerDelegate* delegate) | 114 PasswordManagerDelegate* delegate) |
| 114 : content::WebContentsObserver(web_contents), | 115 : content::WebContentsObserver(web_contents), |
| 115 delegate_(delegate) { | 116 delegate_(delegate), |
| 117 driver_(delegate->GetDriver()) { |
| 116 DCHECK(delegate_); | 118 DCHECK(delegate_); |
| 119 DCHECK(driver_); |
| 117 password_manager_enabled_.Init(prefs::kPasswordManagerEnabled, | 120 password_manager_enabled_.Init(prefs::kPasswordManagerEnabled, |
| 118 delegate_->GetProfile()->GetPrefs()); | 121 delegate_->GetProfile()->GetPrefs()); |
| 119 | 122 |
| 120 ReportMetrics(*password_manager_enabled_); | 123 ReportMetrics(*password_manager_enabled_); |
| 121 } | 124 } |
| 122 | 125 |
| 123 PasswordManager::~PasswordManager() { | 126 PasswordManager::~PasswordManager() { |
| 124 FOR_EACH_OBSERVER(LoginModelObserver, observers_, OnLoginModelDestroying()); | 127 FOR_EACH_OBSERVER(LoginModelObserver, observers_, OnLoginModelDestroying()); |
| 125 } | 128 } |
| 126 | 129 |
| 127 void PasswordManager::SetFormHasGeneratedPassword(const PasswordForm& form) { | 130 void PasswordManager::SetFormHasGeneratedPassword(const PasswordForm& form) { |
| 128 for (ScopedVector<PasswordFormManager>::iterator iter = | 131 for (ScopedVector<PasswordFormManager>::iterator iter = |
| 129 pending_login_managers_.begin(); | 132 pending_login_managers_.begin(); |
| 130 iter != pending_login_managers_.end(); ++iter) { | 133 iter != pending_login_managers_.end(); ++iter) { |
| 131 if ((*iter)->DoesManage( | 134 if ((*iter)->DoesManage( |
| 132 form, PasswordFormManager::ACTION_MATCH_REQUIRED)) { | 135 form, PasswordFormManager::ACTION_MATCH_REQUIRED)) { |
| 133 (*iter)->SetHasGeneratedPassword(); | 136 (*iter)->SetHasGeneratedPassword(); |
| 134 return; | 137 return; |
| 135 } | 138 } |
| 136 } | 139 } |
| 137 // If there is no corresponding PasswordFormManager, we create one. This is | 140 // If there is no corresponding PasswordFormManager, we create one. This is |
| 138 // not the common case, and should only happen when there is a bug in our | 141 // not the common case, and should only happen when there is a bug in our |
| 139 // ability to detect forms. | 142 // ability to detect forms. |
| 140 bool ssl_valid = (form.origin.SchemeIsSecure() && | 143 bool ssl_valid = (form.origin.SchemeIsSecure() && |
| 141 !delegate_->DidLastPageLoadEncounterSSLErrors()); | 144 !driver_->DidLastPageLoadEncounterSSLErrors()); |
| 142 PasswordFormManager* manager = | 145 PasswordFormManager* manager = |
| 143 new PasswordFormManager(delegate_->GetProfile(), | 146 new PasswordFormManager(delegate_->GetProfile(), |
| 144 this, | 147 this, |
| 145 web_contents(), | 148 web_contents(), |
| 146 form, | 149 form, |
| 147 ssl_valid); | 150 ssl_valid); |
| 148 pending_login_managers_.push_back(manager); | 151 pending_login_managers_.push_back(manager); |
| 149 manager->SetHasGeneratedPassword(); | 152 manager->SetHasGeneratedPassword(); |
| 150 // TODO(gcasto): Add UMA stats to track this. | 153 // TODO(gcasto): Add UMA stats to track this. |
| 151 } | 154 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // autocomplete attribute if autocomplete='off' is not ignored. | 230 // autocomplete attribute if autocomplete='off' is not ignored. |
| 228 if (!autofill::ShouldIgnoreAutocompleteOffForPasswordFields() && | 231 if (!autofill::ShouldIgnoreAutocompleteOffForPasswordFields() && |
| 229 !manager->HasGeneratedPassword() && | 232 !manager->HasGeneratedPassword() && |
| 230 !form.password_autocomplete_set) { | 233 !form.password_autocomplete_set) { |
| 231 RecordFailure(AUTOCOMPLETE_OFF, form.origin.host()); | 234 RecordFailure(AUTOCOMPLETE_OFF, form.origin.host()); |
| 232 return; | 235 return; |
| 233 } | 236 } |
| 234 | 237 |
| 235 PasswordForm provisionally_saved_form(form); | 238 PasswordForm provisionally_saved_form(form); |
| 236 provisionally_saved_form.ssl_valid = form.origin.SchemeIsSecure() && | 239 provisionally_saved_form.ssl_valid = form.origin.SchemeIsSecure() && |
| 237 !delegate_->DidLastPageLoadEncounterSSLErrors(); | 240 !driver_->DidLastPageLoadEncounterSSLErrors(); |
| 238 provisionally_saved_form.preferred = true; | 241 provisionally_saved_form.preferred = true; |
| 239 PasswordFormManager::OtherPossibleUsernamesAction action = | 242 PasswordFormManager::OtherPossibleUsernamesAction action = |
| 240 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; | 243 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; |
| 241 if (OtherPossibleUsernamesEnabled()) | 244 if (OtherPossibleUsernamesEnabled()) |
| 242 action = PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES; | 245 action = PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES; |
| 243 manager->ProvisionallySave(provisionally_saved_form, action); | 246 manager->ProvisionallySave(provisionally_saved_form, action); |
| 244 provisional_save_manager_.swap(manager); | 247 provisional_save_manager_.swap(manager); |
| 245 } | 248 } |
| 246 | 249 |
| 247 void PasswordManager::RecordFailure(ProvisionalSaveFailure failure, | 250 void PasswordManager::RecordFailure(ProvisionalSaveFailure failure, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 for (size_t i = 0; i < submission_callbacks_.size(); ++i) { | 305 for (size_t i = 0; i < submission_callbacks_.size(); ++i) { |
| 303 submission_callbacks_[i].Run(password_form); | 306 submission_callbacks_[i].Run(password_form); |
| 304 } | 307 } |
| 305 | 308 |
| 306 pending_login_managers_.clear(); | 309 pending_login_managers_.clear(); |
| 307 } | 310 } |
| 308 | 311 |
| 309 void PasswordManager::OnPasswordFormsParsed( | 312 void PasswordManager::OnPasswordFormsParsed( |
| 310 const std::vector<PasswordForm>& forms) { | 313 const std::vector<PasswordForm>& forms) { |
| 311 // Ask the SSLManager for current security. | 314 // Ask the SSLManager for current security. |
| 312 bool had_ssl_error = delegate_->DidLastPageLoadEncounterSSLErrors(); | 315 bool had_ssl_error = driver_->DidLastPageLoadEncounterSSLErrors(); |
| 313 | 316 |
| 314 for (std::vector<PasswordForm>::const_iterator iter = forms.begin(); | 317 for (std::vector<PasswordForm>::const_iterator iter = forms.begin(); |
| 315 iter != forms.end(); ++iter) { | 318 iter != forms.end(); ++iter) { |
| 316 // Don't involve the password manager if this form corresponds to | 319 // Don't involve the password manager if this form corresponds to |
| 317 // SpdyProxy authentication, as indicated by the realm. | 320 // SpdyProxy authentication, as indicated by the realm. |
| 318 if (EndsWith(iter->signon_realm, kSpdyProxyRealm, true)) | 321 if (EndsWith(iter->signon_realm, kSpdyProxyRealm, true)) |
| 319 continue; | 322 continue; |
| 320 | 323 |
| 321 bool ssl_valid = iter->origin.SchemeIsSecure() && !had_ssl_error; | 324 bool ssl_valid = iter->origin.SchemeIsSecure() && !had_ssl_error; |
| 322 PasswordFormManager* manager = | 325 PasswordFormManager* manager = |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 case PasswordForm::SCHEME_HTML: { | 448 case PasswordForm::SCHEME_HTML: { |
| 446 // Note the check above is required because the observers_ for a non-HTML | 449 // Note the check above is required because the observers_ for a non-HTML |
| 447 // schemed password form may have been freed, so we need to distinguish. | 450 // schemed password form may have been freed, so we need to distinguish. |
| 448 autofill::PasswordFormFillData fill_data; | 451 autofill::PasswordFormFillData fill_data; |
| 449 InitPasswordFormFillData(form_for_autofill, | 452 InitPasswordFormFillData(form_for_autofill, |
| 450 best_matches, | 453 best_matches, |
| 451 &preferred_match, | 454 &preferred_match, |
| 452 wait_for_username, | 455 wait_for_username, |
| 453 OtherPossibleUsernamesEnabled(), | 456 OtherPossibleUsernamesEnabled(), |
| 454 &fill_data); | 457 &fill_data); |
| 455 delegate_->FillPasswordForm(fill_data); | 458 driver_->FillPasswordForm(fill_data); |
| 456 break; | 459 break; |
| 457 } | 460 } |
| 458 default: | 461 default: |
| 459 FOR_EACH_OBSERVER( | 462 FOR_EACH_OBSERVER( |
| 460 LoginModelObserver, | 463 LoginModelObserver, |
| 461 observers_, | 464 observers_, |
| 462 OnAutofillDataAvailable(preferred_match.username_value, | 465 OnAutofillDataAvailable(preferred_match.username_value, |
| 463 preferred_match.password_value)); | 466 preferred_match.password_value)); |
| 464 break; | 467 break; |
| 465 } | 468 } |
| 466 | 469 |
| 467 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = | 470 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = |
| 468 ManagePasswordsBubbleUIController::FromWebContents(web_contents()); | 471 ManagePasswordsBubbleUIController::FromWebContents(web_contents()); |
| 469 if (manage_passwords_bubble_ui_controller && | 472 if (manage_passwords_bubble_ui_controller && |
| 470 CommandLine::ForCurrentProcess()->HasSwitch( | 473 CommandLine::ForCurrentProcess()->HasSwitch( |
| 471 switches::kEnableSavePasswordBubble)) { | 474 switches::kEnableSavePasswordBubble)) { |
| 472 manage_passwords_bubble_ui_controller->OnPasswordAutofilled(best_matches); | 475 manage_passwords_bubble_ui_controller->OnPasswordAutofilled(best_matches); |
| 473 } | 476 } |
| 474 } | 477 } |
| OLD | NEW |