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

Side by Side Diff: chrome/browser/password_manager/password_manager.cc

Issue 10892011: Fix for no password save when action URL is modified (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/password_manager/password_form_manager_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ReportMetrics(*password_manager_enabled_); 73 ReportMetrics(*password_manager_enabled_);
74 } 74 }
75 75
76 PasswordManager::~PasswordManager() { 76 PasswordManager::~PasswordManager() {
77 } 77 }
78 78
79 void PasswordManager::SetFormHasGeneratedPassword(const PasswordForm& form) { 79 void PasswordManager::SetFormHasGeneratedPassword(const PasswordForm& form) {
80 for (ScopedVector<PasswordFormManager>::iterator iter = 80 for (ScopedVector<PasswordFormManager>::iterator iter =
81 pending_login_managers_.begin(); 81 pending_login_managers_.begin();
82 iter != pending_login_managers_.end(); ++iter) { 82 iter != pending_login_managers_.end(); ++iter) {
83 if ((*iter)->DoesManage(form)) { 83 if ((*iter)->DoesManage(
84 form, PasswordFormManager::ACTION_MATCH_REQUIRED)) {
84 (*iter)->SetHasGeneratedPassword(); 85 (*iter)->SetHasGeneratedPassword();
85 return; 86 return;
86 } 87 }
87 } 88 }
88 // If there is no corresponding PasswordFormManager, we create one. This is 89 // If there is no corresponding PasswordFormManager, we create one. This is
89 // not the common case, and should only happen when there is a bug in our 90 // not the common case, and should only happen when there is a bug in our
90 // ability to detect forms. 91 // ability to detect forms.
91 bool ssl_valid = (form.origin.SchemeIsSecure() && 92 bool ssl_valid = (form.origin.SchemeIsSecure() &&
92 !delegate_->DidLastPageLoadEncounterSSLErrors()); 93 !delegate_->DidLastPageLoadEncounterSSLErrors());
93 PasswordFormManager* manager = 94 PasswordFormManager* manager =
(...skipping 13 matching lines...) Expand all
107 108
108 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) { 109 void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) {
109 if (!IsSavingEnabled()) 110 if (!IsSavingEnabled())
110 return; 111 return;
111 112
112 // No password to save? Then don't. 113 // No password to save? Then don't.
113 if (form.password_value.empty()) 114 if (form.password_value.empty())
114 return; 115 return;
115 116
116 scoped_ptr<PasswordFormManager> manager; 117 scoped_ptr<PasswordFormManager> manager;
118 ScopedVector<PasswordFormManager>::iterator matched_manager_it =
119 pending_login_managers_.end();
117 for (ScopedVector<PasswordFormManager>::iterator iter = 120 for (ScopedVector<PasswordFormManager>::iterator iter =
118 pending_login_managers_.begin(); 121 pending_login_managers_.begin();
119 iter != pending_login_managers_.end(); ++iter) { 122 iter != pending_login_managers_.end(); ++iter) {
120 if ((*iter)->DoesManage(form)) { 123 // If we find a manager that exactly matches the submitted form including
121 // Transfer ownership of the manager from |pending_login_managers_| to 124 // the action URL, exit the loop.
122 // |manager|. 125 if ((*iter)->DoesManage(
123 manager.reset(*iter); 126 form, PasswordFormManager::ACTION_MATCH_REQUIRED)) {
124 pending_login_managers_.weak_erase(iter); 127 matched_manager_it = iter;
125 break; 128 break;
129 // If the current manager matches the submitted form excluding the action
130 // URL, remember it as a candidate and continue searching for an exact
131 // match.
132 } else if ((*iter)->DoesManage(
133 form, PasswordFormManager::ACTION_MATCH_NOT_REQUIRED)) {
134 matched_manager_it = iter;
126 } 135 }
127 } 136 }
128 // If we didn't find a manager, this means a form was submitted without 137 // 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 138 // first loading the page containing the form. Don't offer to save
130 // passwords in this case. 139 // passwords in this case.
131 if (!manager.get()) 140 if (matched_manager_it != pending_login_managers_.end()) {
141 // Transfer ownership of the manager from |pending_login_managers_| to
142 // |manager|.
143 manager.reset(*matched_manager_it);
144 pending_login_managers_.weak_erase(matched_manager_it);
145 } else {
132 return; 146 return;
147 }
133 148
134 // If we found a manager but it didn't finish matching yet, the user has 149 // 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 150 // 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 151 // results for the given form and autofill. If this is the case, we just
137 // give up. 152 // give up.
138 if (!manager->HasCompletedMatching()) 153 if (!manager->HasCompletedMatching())
139 return; 154 return;
140 155
141 // Also get out of here if the user told us to 'never remember' passwords for 156 // Also get out of here if the user told us to 'never remember' passwords for
142 // this form. 157 // this form.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 void PasswordManager::OnPasswordFormsRendered( 227 void PasswordManager::OnPasswordFormsRendered(
213 const std::vector<PasswordForm>& visible_forms) { 228 const std::vector<PasswordForm>& visible_forms) {
214 if (!provisional_save_manager_.get()) 229 if (!provisional_save_manager_.get())
215 return; 230 return;
216 231
217 DCHECK(IsSavingEnabled()); 232 DCHECK(IsSavingEnabled());
218 233
219 // First, check for a failed login attempt. 234 // First, check for a failed login attempt.
220 for (std::vector<PasswordForm>::const_iterator iter = visible_forms.begin(); 235 for (std::vector<PasswordForm>::const_iterator iter = visible_forms.begin();
221 iter != visible_forms.end(); ++iter) { 236 iter != visible_forms.end(); ++iter) {
222 if (provisional_save_manager_->DoesManage(*iter)) { 237 if (provisional_save_manager_->DoesManage(
238 *iter, PasswordFormManager::ACTION_MATCH_REQUIRED)) {
223 // The form trying to be saved has immediately re-appeared. Assume login 239 // The form trying to be saved has immediately re-appeared. Assume login
224 // failure and abort this save, by clearing provisional_save_manager_. 240 // failure and abort this save, by clearing provisional_save_manager_.
225 provisional_save_manager_->SubmitFailed(); 241 provisional_save_manager_->SubmitFailed();
226 provisional_save_manager_.reset(); 242 provisional_save_manager_.reset();
227 return; 243 return;
228 } 244 }
229 } 245 }
230 246
231 if (!provisional_save_manager_->HasValidPasswordForm()) { 247 if (!provisional_save_manager_->HasValidPasswordForm()) {
232 // Form is not completely valid - we do not support it. 248 // Form is not completely valid - we do not support it.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (observer_) { 290 if (observer_) {
275 observer_->OnAutofillDataAvailable(preferred_match.username_value, 291 observer_->OnAutofillDataAvailable(preferred_match.username_value,
276 preferred_match.password_value); 292 preferred_match.password_value);
277 } 293 }
278 } 294 }
279 } 295 }
280 296
281 bool PasswordManager::IsFillingEnabled() const { 297 bool PasswordManager::IsFillingEnabled() const {
282 return delegate_->GetProfile() && *password_manager_enabled_; 298 return delegate_->GetProfile() && *password_manager_enabled_;
283 } 299 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_form_manager_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698