| 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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/password_manager/password_form_manager.h" | 10 #include "chrome/browser/password_manager/password_form_manager.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { | 108 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { |
| 109 if (!IsSavingEnabled()) | 109 if (!IsSavingEnabled()) |
| 110 return; | 110 return; |
| 111 | 111 |
| 112 // No password to save? Then don't. | 112 // No password to save? Then don't. |
| 113 if (form.password_value.empty()) | 113 if (form.password_value.empty()) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 scoped_ptr<PasswordFormManager> manager; | 116 scoped_ptr<PasswordFormManager> manager; |
| 117 ScopedVector<PasswordFormManager>::iterator matched_manager_it = |
| 118 pending_login_managers_.end(); |
| 117 for (ScopedVector<PasswordFormManager>::iterator iter = | 119 for (ScopedVector<PasswordFormManager>::iterator iter = |
| 118 pending_login_managers_.begin(); | 120 pending_login_managers_.begin(); |
| 119 iter != pending_login_managers_.end(); ++iter) { | 121 iter != pending_login_managers_.end(); ++iter) { |
| 120 if ((*iter)->DoesManage(form)) { | 122 // If we find a manager that exactly matches the submitted form including |
| 121 // Transfer ownership of the manager from |pending_login_managers_| to | 123 // the action URL, exit the loop. |
| 122 // |manager|. | 124 if ((*iter)->DoesManage(form, true)) { |
| 123 manager.reset(*iter); | 125 matched_manager_it = iter; |
| 124 pending_login_managers_.weak_erase(iter); | |
| 125 break; | 126 break; |
| 127 // If the current manager matches the submitted form excluding the action |
| 128 // URL, remember it as a candidate and continue searching for an exact |
| 129 // match. |
| 130 } else if ((*iter)->DoesManage(form, false)) { |
| 131 matched_manager_it = iter; |
| 126 } | 132 } |
| 127 } | 133 } |
| 128 // If we didn't find a manager, this means a form was submitted without | 134 // If we didn't find a manager, this means a form was submitted without |
| 129 // first loading the page containing the form. Don't offer to save | 135 // first loading the page containing the form. Don't offer to save |
| 130 // passwords in this case. | 136 // passwords in this case. |
| 131 if (!manager.get()) | 137 if (matched_manager_it != pending_login_managers_.end()) { |
| 138 // Transfer ownership of the manager from |pending_login_managers_| to |
| 139 // |manager|. |
| 140 manager.reset(*matched_manager_it); |
| 141 pending_login_managers_.weak_erase(matched_manager_it); |
| 142 } else { |
| 132 return; | 143 return; |
| 144 } |
| 133 | 145 |
| 134 // If we found a manager but it didn't finish matching yet, the user has | 146 // If we found a manager but it didn't finish matching yet, the user has |
| 135 // tried to submit credentials before we had time to even find matching | 147 // tried to submit credentials before we had time to even find matching |
| 136 // results for the given form and autofill. If this is the case, we just | 148 // results for the given form and autofill. If this is the case, we just |
| 137 // give up. | 149 // give up. |
| 138 if (!manager->HasCompletedMatching()) | 150 if (!manager->HasCompletedMatching()) |
| 139 return; | 151 return; |
| 140 | 152 |
| 141 // Also get out of here if the user told us to 'never remember' passwords for | 153 // Also get out of here if the user told us to 'never remember' passwords for |
| 142 // this form. | 154 // this form. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 if (observer_) { | 286 if (observer_) { |
| 275 observer_->OnAutofillDataAvailable(preferred_match.username_value, | 287 observer_->OnAutofillDataAvailable(preferred_match.username_value, |
| 276 preferred_match.password_value); | 288 preferred_match.password_value); |
| 277 } | 289 } |
| 278 } | 290 } |
| 279 } | 291 } |
| 280 | 292 |
| 281 bool PasswordManager::IsFillingEnabled() const { | 293 bool PasswordManager::IsFillingEnabled() const { |
| 282 return delegate_->GetProfile() && *password_manager_enabled_; | 294 return delegate_->GetProfile() && *password_manager_enabled_; |
| 283 } | 295 } |
| OLD | NEW |