OLD | NEW |
---|---|
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 68 } |
69 return nullptr; | 69 return nullptr; |
70 } | 70 } |
71 | 71 |
72 // This function returns a vector of password fields into which Chrome should | 72 // This function returns a vector of password fields into which Chrome should |
73 // fill the generated password. It assumes that |field_signature| describes the | 73 // fill the generated password. It assumes that |field_signature| describes the |
74 // field where Chrome shows the password generation prompt. It returns no more | 74 // field where Chrome shows the password generation prompt. It returns no more |
75 // than 2 elements. | 75 // than 2 elements. |
76 std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( | 76 std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( |
77 const std::vector<blink::WebInputElement>& all_password_elements, | 77 const std::vector<blink::WebInputElement>& all_password_elements, |
78 const FieldSignature field_signature) { | 78 const PasswordFormGenerationData& generation_data) { |
79 auto iter = std::find_if( | 79 auto generation_field_iter = all_password_elements.end(); |
80 all_password_elements.begin(), all_password_elements.end(), | 80 auto confirmation_field_iter = all_password_elements.end(); |
81 [&field_signature](const blink::WebInputElement& input) { | 81 for (auto iter = all_password_elements.begin(); |
82 FieldSignature signature = CalculateFieldSignatureByNameAndType( | 82 iter != all_password_elements.end(); ++iter) { |
83 input.nameForAutofill().utf16(), input.formControlType().utf8()); | 83 const blink::WebInputElement& input = *iter; |
84 return signature == field_signature; | 84 FieldSignature signature = CalculateFieldSignatureByNameAndType( |
85 }); | 85 input.nameForAutofill().utf16(), input.formControlType().utf8()); |
86 if (signature == generation_data.field_signature) | |
87 generation_field_iter = iter; | |
88 else if (generation_data.confirmation_field_signature.has_value() && | |
dcheng
2017/03/07 21:42:26
Nit:
else if (generation_data.confirmation_field_
kolos1
2017/03/08 07:43:50
Done.
| |
89 signature == generation_data.confirmation_field_signature.value()) | |
90 confirmation_field_iter = iter; | |
91 } | |
92 | |
86 std::vector<blink::WebInputElement> passwords; | 93 std::vector<blink::WebInputElement> passwords; |
94 if (generation_field_iter != all_password_elements.end()) { | |
95 passwords.push_back(*generation_field_iter); | |
87 | 96 |
88 // We copy not more than 2 fields because occasionally there are forms where | 97 if (confirmation_field_iter == all_password_elements.end()) |
89 // the security question answers are put in password fields and we don't want | 98 confirmation_field_iter = generation_field_iter + 1; |
90 // to fill those. | 99 if (confirmation_field_iter != all_password_elements.end()) |
91 for (; iter != all_password_elements.end() && passwords.size() < 2; ++iter) | 100 passwords.push_back(*confirmation_field_iter); |
92 passwords.push_back(*iter); | 101 } |
93 return passwords; | 102 return passwords; |
94 } | 103 } |
95 | 104 |
96 void CopyElementValueToOtherInputElements( | 105 void CopyElementValueToOtherInputElements( |
97 const blink::WebInputElement* element, | 106 const blink::WebInputElement* element, |
98 std::vector<blink::WebInputElement>* elements) { | 107 std::vector<blink::WebInputElement>* elements) { |
99 for (blink::WebInputElement& it : *elements) { | 108 for (blink::WebInputElement& it : *elements) { |
100 if (*element != it) { | 109 if (*element != it) { |
101 it.setValue(element->value(), true /* sendEvents */); | 110 it.setValue(element->value(), true /* sendEvents */); |
102 } | 111 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 VLOG(2) | 406 VLOG(2) |
398 << "Have not received confirmation from Autofill that form is " | 407 << "Have not received confirmation from Autofill that form is " |
399 << "used for account creation"; | 408 << "used for account creation"; |
400 continue; | 409 continue; |
401 } | 410 } |
402 } | 411 } |
403 } | 412 } |
404 | 413 |
405 VLOG(2) << "Password generation eligible form found"; | 414 VLOG(2) << "Password generation eligible form found"; |
406 std::vector<blink::WebInputElement> password_elements = | 415 std::vector<blink::WebInputElement> password_elements = |
407 generation_data ? FindPasswordElementsForGeneration( | 416 generation_data |
408 possible_form_data.password_elements, | 417 ? FindPasswordElementsForGeneration( |
409 generation_data->field_signature) | 418 possible_form_data.password_elements, *generation_data) |
410 : possible_form_data.password_elements; | 419 : possible_form_data.password_elements; |
411 if (password_elements.empty()) { | 420 if (password_elements.empty()) { |
412 // It might be if JavaScript changes field names. | 421 // It might be if JavaScript changes field names. |
413 VLOG(2) << "Fields for generation are not found"; | 422 VLOG(2) << "Fields for generation are not found"; |
414 return; | 423 return; |
415 } | 424 } |
416 generation_form_data_.reset(new AccountCreationFormData( | 425 generation_form_data_.reset(new AccountCreationFormData( |
417 possible_form_data.form, std::move(password_elements))); | 426 possible_form_data.form, std::move(password_elements))); |
418 generation_element_ = generation_form_data_->password_elements[0]; | 427 generation_element_ = generation_form_data_->password_elements[0]; |
419 generation_element_.setAttribute("aria-autocomplete", "list"); | 428 generation_element_.setAttribute("aria-autocomplete", "list"); |
420 password_generation::LogPasswordGenerationEvent( | 429 password_generation::LogPasswordGenerationEvent( |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 } | 567 } |
559 | 568 |
560 if (!password_form) | 569 if (!password_form) |
561 return; | 570 return; |
562 | 571 |
563 generation_element_ = last_focused_password_element_; | 572 generation_element_ = last_focused_password_element_; |
564 std::vector<blink::WebInputElement> password_elements; | 573 std::vector<blink::WebInputElement> password_elements; |
565 GetAccountCreationPasswordFields(control_elements, &password_elements); | 574 GetAccountCreationPasswordFields(control_elements, &password_elements); |
566 password_elements = FindPasswordElementsForGeneration( | 575 password_elements = FindPasswordElementsForGeneration( |
567 password_elements, | 576 password_elements, |
568 CalculateFieldSignatureByNameAndType( | 577 PasswordFormGenerationData( |
569 last_focused_password_element_.nameForAutofill().utf16(), | 578 0, /* form_signature */ |
570 last_focused_password_element_.formControlType().utf8())); | 579 CalculateFieldSignatureByNameAndType( |
580 last_focused_password_element_.nameForAutofill().utf16(), | |
581 last_focused_password_element_.formControlType().utf8()))); | |
571 generation_form_data_.reset(new AccountCreationFormData( | 582 generation_form_data_.reset(new AccountCreationFormData( |
572 make_linked_ptr(password_form.release()), password_elements)); | 583 make_linked_ptr(password_form.release()), password_elements)); |
573 is_manually_triggered_ = true; | 584 is_manually_triggered_ = true; |
574 ShowGenerationPopup(); | 585 ShowGenerationPopup(); |
575 } | 586 } |
576 | 587 |
577 const mojom::PasswordManagerDriverPtr& | 588 const mojom::PasswordManagerDriverPtr& |
578 PasswordGenerationAgent::GetPasswordManagerDriver() { | 589 PasswordGenerationAgent::GetPasswordManagerDriver() { |
579 DCHECK(password_agent_); | 590 DCHECK(password_agent_); |
580 return password_agent_->GetPasswordManagerDriver(); | 591 return password_agent_->GetPasswordManagerDriver(); |
581 } | 592 } |
582 | 593 |
583 const mojom::PasswordManagerClientAssociatedPtr& | 594 const mojom::PasswordManagerClientAssociatedPtr& |
584 PasswordGenerationAgent::GetPasswordManagerClient() { | 595 PasswordGenerationAgent::GetPasswordManagerClient() { |
585 if (!password_manager_client_) { | 596 if (!password_manager_client_) { |
586 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( | 597 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( |
587 &password_manager_client_); | 598 &password_manager_client_); |
588 } | 599 } |
589 | 600 |
590 return password_manager_client_; | 601 return password_manager_client_; |
591 } | 602 } |
592 | 603 |
593 } // namespace autofill | 604 } // namespace autofill |
OLD | NEW |