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

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

Issue 2650623002: Use explicit WebString conversions in autofill (Closed)
Patch Set: . Created 3 years, 11 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 FieldSignature field_signature) {
79 auto iter = std::find_if( 79 auto iter = std::find_if(
80 all_password_elements.begin(), all_password_elements.end(), 80 all_password_elements.begin(), all_password_elements.end(),
81 [&field_signature](const blink::WebInputElement& input) { 81 [&field_signature](const blink::WebInputElement& input) {
82 FieldSignature signature = CalculateFieldSignatureByNameAndType( 82 FieldSignature signature = CalculateFieldSignatureByNameAndType(
83 input.nameForAutofill(), input.formControlType().utf8()); 83 input.nameForAutofill().utf16(), input.formControlType().utf8());
84 return signature == field_signature; 84 return signature == field_signature;
85 }); 85 });
86 std::vector<blink::WebInputElement> passwords; 86 std::vector<blink::WebInputElement> passwords;
87 87
88 // We copy not more than 2 fields because occasionally there are forms where 88 // We copy not more than 2 fields because occasionally there are forms where
89 // the security question answers are put in password fields and we don't want 89 // the security question answers are put in password fields and we don't want
90 // to fill those. 90 // to fill those.
91 for (; iter != all_password_elements.end() && passwords.size() < 2; ++iter) 91 for (; iter != all_password_elements.end() && passwords.size() < 2; ++iter)
92 passwords.push_back(*iter); 92 passwords.push_back(*iter);
93 return passwords; 93 return passwords;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 not_blacklisted_password_form_origins_.push_back(form.origin); 298 not_blacklisted_password_form_origins_.push_back(form.origin);
299 DetermineGenerationElement(); 299 DetermineGenerationElement();
300 } 300 }
301 301
302 void PasswordGenerationAgent::GeneratedPasswordAccepted( 302 void PasswordGenerationAgent::GeneratedPasswordAccepted(
303 const base::string16& password) { 303 const base::string16& password) {
304 password_is_generated_ = true; 304 password_is_generated_ = true;
305 password_generation::LogPasswordGenerationEvent( 305 password_generation::LogPasswordGenerationEvent(
306 password_generation::PASSWORD_ACCEPTED); 306 password_generation::PASSWORD_ACCEPTED);
307 for (auto& password_element : generation_form_data_->password_elements) { 307 for (auto& password_element : generation_form_data_->password_elements) {
308 password_element.setValue(password, true /* sendEvents */); 308 password_element.setValue(blink::WebString::fromUTF16(password),
309 true /* sendEvents */);
309 // setValue() above may have resulted in JavaScript closing the frame. 310 // setValue() above may have resulted in JavaScript closing the frame.
310 if (!render_frame()) 311 if (!render_frame())
311 return; 312 return;
312 password_element.setAutofilled(true); 313 password_element.setAutofilled(true);
313 // Needed to notify password_autofill_agent that the content of the field 314 // Needed to notify password_autofill_agent that the content of the field
314 // has changed. Without this we will overwrite the generated 315 // has changed. Without this we will overwrite the generated
315 // password with an Autofilled password when saving. 316 // password with an Autofilled password when saving.
316 // https://crbug.com/493455 317 // https://crbug.com/493455
317 password_agent_->UpdateStateForTextChange(password_element); 318 password_agent_->UpdateStateForTextChange(password_element);
318 // Advance focus to the next input field. We assume password fields in 319 // Advance focus to the next input field. We assume password fields in
(...skipping 17 matching lines...) Expand all
336 password_form = CreatePasswordFormFromWebForm(generation_element_.form(), 337 password_form = CreatePasswordFormFromWebForm(generation_element_.form(),
337 nullptr, nullptr); 338 nullptr, nullptr);
338 } else { 339 } else {
339 password_form = CreatePasswordFormFromUnownedInputElements( 340 password_form = CreatePasswordFormFromUnownedInputElements(
340 *render_frame()->GetWebFrame(), nullptr, nullptr); 341 *render_frame()->GetWebFrame(), nullptr, nullptr);
341 } 342 }
342 if (password_form) { 343 if (password_form) {
343 // TODO(kolos): when we are good in username detection, save username 344 // TODO(kolos): when we are good in username detection, save username
344 // as well. 345 // as well.
345 password_form->username_value = base::string16(); 346 password_form->username_value = base::string16();
346 password_form->password_value = generation_element_.value(); 347 password_form->password_value = generation_element_.value().utf16();
347 } 348 }
348 349
349 return password_form; 350 return password_form;
350 } 351 }
351 352
352 void PasswordGenerationAgent::FoundFormsEligibleForGeneration( 353 void PasswordGenerationAgent::FoundFormsEligibleForGeneration(
353 const std::vector<PasswordFormGenerationData>& forms) { 354 const std::vector<PasswordFormGenerationData>& forms) {
354 generation_enabled_forms_.insert(generation_enabled_forms_.end(), 355 generation_enabled_forms_.insert(generation_enabled_forms_.end(),
355 forms.begin(), forms.end()); 356 forms.begin(), forms.end());
356 DetermineGenerationElement(); 357 DetermineGenerationElement();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 509
509 return true; 510 return true;
510 } 511 }
511 512
512 void PasswordGenerationAgent::ShowGenerationPopup() { 513 void PasswordGenerationAgent::ShowGenerationPopup() {
513 if (!render_frame()) 514 if (!render_frame())
514 return; 515 return;
515 GetPasswordManagerClient()->ShowPasswordGenerationPopup( 516 GetPasswordManagerClient()->ShowPasswordGenerationPopup(
516 render_frame()->GetRenderView()->ElementBoundsInWindow( 517 render_frame()->GetRenderView()->ElementBoundsInWindow(
517 generation_element_), 518 generation_element_),
518 generation_element_.maxLength(), generation_element_.nameForAutofill(), 519 generation_element_.maxLength(),
519 is_manually_triggered_, *generation_form_data_->form); 520 generation_element_.nameForAutofill().utf16(), is_manually_triggered_,
521 *generation_form_data_->form);
520 generation_popup_shown_ = true; 522 generation_popup_shown_ = true;
521 } 523 }
522 524
523 void PasswordGenerationAgent::ShowEditingPopup() { 525 void PasswordGenerationAgent::ShowEditingPopup() {
524 if (!render_frame()) 526 if (!render_frame())
525 return; 527 return;
526 GetPasswordManagerClient()->ShowPasswordEditingPopup( 528 GetPasswordManagerClient()->ShowPasswordEditingPopup(
527 render_frame()->GetRenderView()->ElementBoundsInWindow( 529 render_frame()->GetRenderView()->ElementBoundsInWindow(
528 generation_element_), 530 generation_element_),
529 *generation_form_data_->form); 531 *generation_form_data_->form);
(...skipping 27 matching lines...) Expand all
557 559
558 if (!password_form) 560 if (!password_form)
559 return; 561 return;
560 562
561 generation_element_ = last_focused_password_element_; 563 generation_element_ = last_focused_password_element_;
562 std::vector<blink::WebInputElement> password_elements; 564 std::vector<blink::WebInputElement> password_elements;
563 GetAccountCreationPasswordFields(control_elements, &password_elements); 565 GetAccountCreationPasswordFields(control_elements, &password_elements);
564 password_elements = FindPasswordElementsForGeneration( 566 password_elements = FindPasswordElementsForGeneration(
565 password_elements, 567 password_elements,
566 CalculateFieldSignatureByNameAndType( 568 CalculateFieldSignatureByNameAndType(
567 last_focused_password_element_.nameForAutofill(), 569 last_focused_password_element_.nameForAutofill().utf16(),
568 last_focused_password_element_.formControlType().utf8())); 570 last_focused_password_element_.formControlType().utf8()));
569 generation_form_data_.reset(new AccountCreationFormData( 571 generation_form_data_.reset(new AccountCreationFormData(
570 make_linked_ptr(password_form.release()), password_elements)); 572 make_linked_ptr(password_form.release()), password_elements));
571 is_manually_triggered_ = true; 573 is_manually_triggered_ = true;
572 ShowGenerationPopup(); 574 ShowGenerationPopup();
573 } 575 }
574 576
575 const mojom::PasswordManagerDriverPtr& 577 const mojom::PasswordManagerDriverPtr&
576 PasswordGenerationAgent::GetPasswordManagerDriver() { 578 PasswordGenerationAgent::GetPasswordManagerDriver() {
577 DCHECK(password_agent_); 579 DCHECK(password_agent_);
578 return password_agent_->GetPasswordManagerDriver(); 580 return password_agent_->GetPasswordManagerDriver();
579 } 581 }
580 582
581 const mojom::PasswordManagerClientAssociatedPtr& 583 const mojom::PasswordManagerClientAssociatedPtr&
582 PasswordGenerationAgent::GetPasswordManagerClient() { 584 PasswordGenerationAgent::GetPasswordManagerClient() {
583 if (!password_manager_client_) { 585 if (!password_manager_client_) {
584 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( 586 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
585 &password_manager_client_); 587 &password_manager_client_);
586 } 588 }
587 589
588 return password_manager_client_; 590 return password_manager_client_;
589 } 591 }
590 592
591 } // namespace autofill 593 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698