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

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

Issue 19705013: [password autofill] Remove references to PasswordForm from RenderViewImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Callback Created 7 years, 5 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
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/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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 !delegate_->DidLastPageLoadEncounterSSLErrors(); 203 !delegate_->DidLastPageLoadEncounterSSLErrors();
204 provisionally_saved_form.preferred = true; 204 provisionally_saved_form.preferred = true;
205 PasswordFormManager::OtherPossibleUsernamesAction action = 205 PasswordFormManager::OtherPossibleUsernamesAction action =
206 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES; 206 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES;
207 if (OtherPossibleUsernamesEnabled()) 207 if (OtherPossibleUsernamesEnabled())
208 action = PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES; 208 action = PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES;
209 manager->ProvisionallySave(provisionally_saved_form, action); 209 manager->ProvisionallySave(provisionally_saved_form, action);
210 provisional_save_manager_.swap(manager); 210 provisional_save_manager_.swap(manager);
211 } 211 }
212 212
213 void PasswordManager::AddSubmissionCallback(
214 const PasswordSubmittedCallback& callback) {
215 submission_callbacks_.push_back(callback);
216 }
217
213 void PasswordManager::AddObserver(LoginModelObserver* observer) { 218 void PasswordManager::AddObserver(LoginModelObserver* observer) {
214 observers_.AddObserver(observer); 219 observers_.AddObserver(observer);
215 } 220 }
216 221
217 void PasswordManager::RemoveObserver(LoginModelObserver* observer) { 222 void PasswordManager::RemoveObserver(LoginModelObserver* observer) {
218 observers_.RemoveObserver(observer); 223 observers_.RemoveObserver(observer);
219 } 224 }
220 225
221 void PasswordManager::DidNavigateAnyFrame( 226 void PasswordManager::DidNavigateMainFrame(
222 const content::LoadCommittedDetails& details, 227 const content::LoadCommittedDetails& details,
223 const content::FrameNavigateParams& params) { 228 const content::FrameNavigateParams& params) {
224 bool password_form_submitted = params.password_form.origin.is_valid(); 229 // Clear data after main frame navigation. We don't want to clear data after
225 230 // subframe navigation as there might be password forms on other frames that
226 // Try to save the password if one was submitted. 231 // could be submitted.
227 if (password_form_submitted) 232 pending_login_managers_.clear();
228 ProvisionallySavePassword(params.password_form);
229
230 // Clear data after submission or main frame navigation. We don't want
231 // to clear data after subframe navigation as there might be password
232 // forms on other frames that could be submitted.
233 if (password_form_submitted || details.is_main_frame)
234 pending_login_managers_.clear();
235 } 233 }
236 234
237 bool PasswordManager::OnMessageReceived(const IPC::Message& message) { 235 bool PasswordManager::OnMessageReceived(const IPC::Message& message) {
238 bool handled = true; 236 bool handled = true;
239 IPC_BEGIN_MESSAGE_MAP(PasswordManager, message) 237 IPC_BEGIN_MESSAGE_MAP(PasswordManager, message)
240 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsParsed, 238 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsParsed,
241 OnPasswordFormsParsed) 239 OnPasswordFormsParsed)
242 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsRendered, 240 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsRendered,
243 OnPasswordFormsRendered) 241 OnPasswordFormsRendered)
242 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormSubmitted,
243 OnPasswordFormSubmitted)
244 IPC_MESSAGE_UNHANDLED(handled = false) 244 IPC_MESSAGE_UNHANDLED(handled = false)
245 IPC_END_MESSAGE_MAP() 245 IPC_END_MESSAGE_MAP()
246 return handled; 246 return handled;
247 } 247 }
248 248
249 void PasswordManager::OnPasswordFormSubmitted(
250 const PasswordForm& password_form) {
251 ProvisionallySavePassword(password_form);
Ilya Sherman 2013/07/27 01:09:48 Should you be calling pending_login_managers_.clea
Garrett Casto 2013/08/03 00:38:42 I actually did this on purpose, though now that I
252 for (size_t i = 0; i < submission_callbacks_.size(); ++i)
Ilya Sherman 2013/07/27 01:09:48 Optional nit: I prefer to always use curly braces
Garrett Casto 2013/08/03 00:38:42 Done.
253 submission_callbacks_[i].Run(password_form);
254 }
255
249 void PasswordManager::OnPasswordFormsParsed( 256 void PasswordManager::OnPasswordFormsParsed(
250 const std::vector<PasswordForm>& forms) { 257 const std::vector<PasswordForm>& forms) {
251 // Ask the SSLManager for current security. 258 // Ask the SSLManager for current security.
252 bool had_ssl_error = delegate_->DidLastPageLoadEncounterSSLErrors(); 259 bool had_ssl_error = delegate_->DidLastPageLoadEncounterSSLErrors();
253 260
254 for (std::vector<PasswordForm>::const_iterator iter = forms.begin(); 261 for (std::vector<PasswordForm>::const_iterator iter = forms.begin();
255 iter != forms.end(); ++iter) { 262 iter != forms.end(); ++iter) {
256 // Don't involve the password manager if this form corresponds to 263 // Don't involve the password manager if this form corresponds to
257 // SpdyProxy authentication, as indicated by the realm. 264 // SpdyProxy authentication, as indicated by the realm.
258 if (EndsWith(iter->signon_realm, kSpdyProxyRealm, true)) 265 if (EndsWith(iter->signon_realm, kSpdyProxyRealm, true))
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 311 }
305 312
306 // Looks like a successful login attempt. Either show an infobar or 313 // Looks like a successful login attempt. Either show an infobar or
307 // automatically save the login data. We prompt when the user hasn't already 314 // automatically save the login data. We prompt when the user hasn't already
308 // given consent, either through previously accepting the infobar or by having 315 // given consent, either through previously accepting the infobar or by having
309 // the browser generate the password. 316 // the browser generate the password.
310 provisional_save_manager_->SubmitPassed(); 317 provisional_save_manager_->SubmitPassed();
311 if (provisional_save_manager_->HasGeneratedPassword()) 318 if (provisional_save_manager_->HasGeneratedPassword())
312 UMA_HISTOGRAM_COUNTS("PasswordGeneration.Submitted", 1); 319 UMA_HISTOGRAM_COUNTS("PasswordGeneration.Submitted", 1);
313 320
314 if(!CommandLine::ForCurrentProcess()->HasSwitch( 321 if (!CommandLine::ForCurrentProcess()->HasSwitch(
315 switches::kEnableSavePasswordBubble)){ 322 switches::kEnableSavePasswordBubble)){
316 if (ShouldShowSavePasswordInfoBar()) { 323 if (ShouldShowSavePasswordInfoBar()) {
317 delegate_->AddSavePasswordInfoBarIfPermitted( 324 delegate_->AddSavePasswordInfoBarIfPermitted(
318 provisional_save_manager_.release()); 325 provisional_save_manager_.release());
319 } else { 326 } else {
320 provisional_save_manager_->Save(); 327 provisional_save_manager_->Save();
321 provisional_save_manager_.reset(); 328 provisional_save_manager_.reset();
322 } 329 }
323 } 330 }
324 } 331 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 373 }
367 374
368 void PasswordManager::Autofill( 375 void PasswordManager::Autofill(
369 const PasswordForm& form_for_autofill, 376 const PasswordForm& form_for_autofill,
370 const PasswordFormMap& best_matches, 377 const PasswordFormMap& best_matches,
371 const PasswordForm& preferred_match, 378 const PasswordForm& preferred_match,
372 bool wait_for_username) const { 379 bool wait_for_username) const {
373 PossiblyInitializeUsernamesExperiment(best_matches); 380 PossiblyInitializeUsernamesExperiment(best_matches);
374 switch (form_for_autofill.scheme) { 381 switch (form_for_autofill.scheme) {
375 case PasswordForm::SCHEME_HTML: { 382 case PasswordForm::SCHEME_HTML: {
376 // Note the check above is required because the observer_ for a non-HTML 383 // Note the check above is required because the observers_ for a non-HTML
377 // schemed password form may have been freed, so we need to distinguish. 384 // schemed password form may have been freed, so we need to distinguish.
378 autofill::PasswordFormFillData fill_data; 385 autofill::PasswordFormFillData fill_data;
379 InitPasswordFormFillData(form_for_autofill, 386 InitPasswordFormFillData(form_for_autofill,
380 best_matches, 387 best_matches,
381 &preferred_match, 388 &preferred_match,
382 wait_for_username, 389 wait_for_username,
383 OtherPossibleUsernamesEnabled(), 390 OtherPossibleUsernamesEnabled(),
384 &fill_data); 391 &fill_data);
385 delegate_->FillPasswordForm(fill_data); 392 delegate_->FillPasswordForm(fill_data);
386 return; 393 return;
387 } 394 }
388 default: 395 default:
389 FOR_EACH_OBSERVER( 396 FOR_EACH_OBSERVER(
390 LoginModelObserver, 397 LoginModelObserver,
391 observers_, 398 observers_,
392 OnAutofillDataAvailable(preferred_match.username_value, 399 OnAutofillDataAvailable(preferred_match.username_value,
393 preferred_match.password_value)); 400 preferred_match.password_value));
394 } 401 }
395 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698