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

Side by Side Diff: components/autofill/content/renderer/password_generation_agent.cc

Issue 1817483002: [Password Manager] Presave the form with generated password till successful login (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed CPMD_BAD_ORIGIN_UPDATE_PRESAVED_PASSWORD in bad_message.h Created 4 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/content/renderer/password_generation_agent.h" 5 #include "components/autofill/content/renderer/password_generation_agent.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 password_element.setAutofilled(true); 278 password_element.setAutofilled(true);
279 // Needed to notify password_autofill_agent that the content of the field 279 // Needed to notify password_autofill_agent that the content of the field
280 // has changed. Without this we will overwrite the generated 280 // has changed. Without this we will overwrite the generated
281 // password with an Autofilled password when saving. 281 // password with an Autofilled password when saving.
282 // https://crbug.com/493455 282 // https://crbug.com/493455
283 password_agent_->UpdateStateForTextChange(password_element); 283 password_agent_->UpdateStateForTextChange(password_element);
284 // Advance focus to the next input field. We assume password fields in 284 // Advance focus to the next input field. We assume password fields in
285 // an account creation form are always adjacent. 285 // an account creation form are always adjacent.
286 render_frame()->GetRenderView()->GetWebView()->advanceFocus(false); 286 render_frame()->GetRenderView()->GetWebView()->advanceFocus(false);
287 } 287 }
288 std::unique_ptr<PasswordForm> presaved_form(CreatePasswordFormToPresave());
289 if (presaved_form) {
290 Send(new AutofillHostMsg_PresaveGeneratedPassword(routing_id(),
291 *presaved_form));
292 }
293 }
294
295 std::unique_ptr<PasswordForm>
296 PasswordGenerationAgent::CreatePasswordFormToPresave() {
297 DCHECK(!generation_element_.isNull());
298 // Since the form for presaving should match a form in the browser, create it
299 // with the same algorithm (to match html attributes, action, etc.), but
300 // change username and password values.
301 std::unique_ptr<PasswordForm> password_form;
302 if (!generation_element_.form().isNull()) {
303 password_form = CreatePasswordFormFromWebForm(generation_element_.form(),
304 nullptr, nullptr);
305 } else {
306 password_form = CreatePasswordFormFromUnownedInputElements(
307 *render_frame()->GetWebFrame(), nullptr, nullptr);
308 }
309 if (password_form) {
310 // TODO(kolos): when we are good in username detection, save username
311 // as well.
312 password_form->username_value = base::string16();
313 password_form->password_value = generation_element_.value();
314 }
315
316 return password_form;
288 } 317 }
289 318
290 void PasswordGenerationAgent::OnFormsEligibleForGenerationFound( 319 void PasswordGenerationAgent::OnFormsEligibleForGenerationFound(
291 const std::vector<autofill::PasswordFormGenerationData>& forms) { 320 const std::vector<autofill::PasswordFormGenerationData>& forms) {
292 generation_enabled_forms_.insert(generation_enabled_forms_.end(), 321 generation_enabled_forms_.insert(generation_enabled_forms_.end(),
293 forms.begin(), forms.end()); 322 forms.begin(), forms.end());
294 DetermineGenerationElement(); 323 DetermineGenerationElement();
295 } 324 }
296 325
297 void PasswordGenerationAgent::DetermineGenerationElement() { 326 void PasswordGenerationAgent::DetermineGenerationElement() {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (element != generation_element_) 435 if (element != generation_element_)
407 return false; 436 return false;
408 437
409 if (element.value().isEmpty()) { 438 if (element.value().isEmpty()) {
410 if (password_is_generated_) { 439 if (password_is_generated_) {
411 // User generated a password and then deleted it. 440 // User generated a password and then deleted it.
412 password_generation::LogPasswordGenerationEvent( 441 password_generation::LogPasswordGenerationEvent(
413 password_generation::PASSWORD_DELETED); 442 password_generation::PASSWORD_DELETED);
414 CopyElementValueToOtherInputElements(&element, 443 CopyElementValueToOtherInputElements(&element,
415 &generation_form_data_->password_elements); 444 &generation_form_data_->password_elements);
416 Send(new AutofillHostMsg_PasswordNoLongerGenerated( 445 std::unique_ptr<PasswordForm> presaved_form(
417 routing_id(), 446 CreatePasswordFormToPresave());
418 *generation_form_data_->form)); 447 if (presaved_form) {
448 Send(new AutofillHostMsg_PasswordNoLongerGenerated(routing_id(),
449 *presaved_form));
450 }
419 } 451 }
420 452
421 // Do not treat the password as generated, either here or in the browser. 453 // Do not treat the password as generated, either here or in the browser.
422 password_is_generated_ = false; 454 password_is_generated_ = false;
423 generation_element_.setShouldRevealPassword(false); 455 generation_element_.setShouldRevealPassword(false);
424 456
425 // Offer generation again. 457 // Offer generation again.
426 ShowGenerationPopup(); 458 ShowGenerationPopup();
427 } else if (password_is_generated_) { 459 } else if (password_is_generated_) {
428 password_edited_ = true; 460 password_edited_ = true;
429 // Mirror edits to any confirmation password fields. 461 // Mirror edits to any confirmation password fields.
430 CopyElementValueToOtherInputElements(&element, 462 CopyElementValueToOtherInputElements(&element,
431 &generation_form_data_->password_elements); 463 &generation_form_data_->password_elements);
464 std::unique_ptr<PasswordForm> presaved_form(CreatePasswordFormToPresave());
465 if (presaved_form) {
466 Send(new AutofillHostMsg_PresaveGeneratedPassword(routing_id(),
467 *presaved_form));
468 }
432 } else if (element.value().length() > kMaximumOfferSize) { 469 } else if (element.value().length() > kMaximumOfferSize) {
433 // User has rejected the feature and has started typing a password. 470 // User has rejected the feature and has started typing a password.
434 HidePopup(); 471 HidePopup();
435 } else { 472 } else {
436 // Password isn't generated and there are fewer than kMaximumOfferSize 473 // Password isn't generated and there are fewer than kMaximumOfferSize
437 // characters typed, so keep offering the password. Note this function 474 // characters typed, so keep offering the password. Note this function
438 // will just keep the previous popup if one is already showing. 475 // will just keep the previous popup if one is already showing.
439 ShowGenerationPopup(); 476 ShowGenerationPopup();
440 } 477 }
441 478
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 GetAccountCreationPasswordFields(control_elements, &password_elements); 533 GetAccountCreationPasswordFields(control_elements, &password_elements);
497 password_elements = FindPasswordElementsForGeneration( 534 password_elements = FindPasswordElementsForGeneration(
498 password_elements, last_focused_password_element_.nameForAutofill()); 535 password_elements, last_focused_password_element_.nameForAutofill());
499 generation_form_data_.reset(new AccountCreationFormData( 536 generation_form_data_.reset(new AccountCreationFormData(
500 make_linked_ptr(password_form.release()), password_elements)); 537 make_linked_ptr(password_form.release()), password_elements));
501 is_manually_triggered_ = true; 538 is_manually_triggered_ = true;
502 ShowGenerationPopup(); 539 ShowGenerationPopup();
503 } 540 }
504 541
505 } // namespace autofill 542 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698