| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "components/autofill/content/common/autofill_messages.h" | 10 #include "components/autofill/content/common/autofill_messages.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 : form(password_form), | 113 : form(password_form), |
| 114 password_elements(passwords) {} | 114 password_elements(passwords) {} |
| 115 | 115 |
| 116 PasswordGenerationAgent::AccountCreationFormData::~AccountCreationFormData() {} | 116 PasswordGenerationAgent::AccountCreationFormData::~AccountCreationFormData() {} |
| 117 | 117 |
| 118 PasswordGenerationAgent::PasswordGenerationAgent( | 118 PasswordGenerationAgent::PasswordGenerationAgent( |
| 119 content::RenderFrame* render_frame, | 119 content::RenderFrame* render_frame, |
| 120 PasswordAutofillAgent* password_agent) | 120 PasswordAutofillAgent* password_agent) |
| 121 : content::RenderFrameObserver(render_frame), | 121 : content::RenderFrameObserver(render_frame), |
| 122 password_is_generated_(false), | 122 password_is_generated_(false), |
| 123 is_manually_triggered_(false), |
| 123 password_edited_(false), | 124 password_edited_(false), |
| 124 generation_popup_shown_(false), | 125 generation_popup_shown_(false), |
| 125 editing_popup_shown_(false), | 126 editing_popup_shown_(false), |
| 126 enabled_(password_generation::IsPasswordGenerationEnabled()), | 127 enabled_(password_generation::IsPasswordGenerationEnabled()), |
| 127 password_agent_(password_agent) { | 128 password_agent_(password_agent) { |
| 128 VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); | 129 VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); |
| 129 } | 130 } |
| 130 PasswordGenerationAgent::~PasswordGenerationAgent() {} | 131 PasswordGenerationAgent::~PasswordGenerationAgent() {} |
| 131 | 132 |
| 132 void PasswordGenerationAgent::DidFinishDocumentLoad() { | 133 void PasswordGenerationAgent::DidFinishDocumentLoad() { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 247 |
| 247 bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) { | 248 bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) { |
| 248 bool handled = true; | 249 bool handled = true; |
| 249 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message) | 250 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message) |
| 250 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, | 251 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, |
| 251 OnFormNotBlacklisted) | 252 OnFormNotBlacklisted) |
| 252 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, | 253 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, |
| 253 OnPasswordAccepted) | 254 OnPasswordAccepted) |
| 254 IPC_MESSAGE_HANDLER(AutofillMsg_FoundFormsEligibleForGeneration, | 255 IPC_MESSAGE_HANDLER(AutofillMsg_FoundFormsEligibleForGeneration, |
| 255 OnFormsEligibleForGenerationFound); | 256 OnFormsEligibleForGenerationFound); |
| 256 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratePassword, OnGeneratePassword); | 257 IPC_MESSAGE_HANDLER(AutofillMsg_UserTriggeredGeneratePassword, |
| 258 OnUserTriggeredGeneratePassword); |
| 257 IPC_MESSAGE_UNHANDLED(handled = false) | 259 IPC_MESSAGE_UNHANDLED(handled = false) |
| 258 IPC_END_MESSAGE_MAP() | 260 IPC_END_MESSAGE_MAP() |
| 259 return handled; | 261 return handled; |
| 260 } | 262 } |
| 261 | 263 |
| 262 void PasswordGenerationAgent::OnFormNotBlacklisted(const PasswordForm& form) { | 264 void PasswordGenerationAgent::OnFormNotBlacklisted(const PasswordForm& form) { |
| 263 not_blacklisted_password_form_origins_.push_back(form.origin); | 265 not_blacklisted_password_form_origins_.push_back(form.origin); |
| 264 DetermineGenerationElement(); | 266 DetermineGenerationElement(); |
| 265 } | 267 } |
| 266 | 268 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // characters typed, so keep offering the password. Note this function | 433 // characters typed, so keep offering the password. Note this function |
| 432 // will just keep the previous popup if one is already showing. | 434 // will just keep the previous popup if one is already showing. |
| 433 ShowGenerationPopup(); | 435 ShowGenerationPopup(); |
| 434 } | 436 } |
| 435 | 437 |
| 436 return true; | 438 return true; |
| 437 } | 439 } |
| 438 | 440 |
| 439 void PasswordGenerationAgent::ShowGenerationPopup() { | 441 void PasswordGenerationAgent::ShowGenerationPopup() { |
| 440 Send(new AutofillHostMsg_ShowPasswordGenerationPopup( | 442 Send(new AutofillHostMsg_ShowPasswordGenerationPopup( |
| 441 routing_id(), | 443 routing_id(), |
| 442 render_frame()->GetRenderView()->ElementBoundsInWindow( | 444 render_frame()->GetRenderView()->ElementBoundsInWindow( |
| 443 generation_element_), | 445 generation_element_), |
| 444 generation_element_.maxLength(), | 446 generation_element_.maxLength(), |
| 445 *generation_form_data_->form)); | 447 generation_element_.nameForAutofill(), |
| 448 is_manually_triggered_, |
| 449 *generation_form_data_->form)); |
| 446 generation_popup_shown_ = true; | 450 generation_popup_shown_ = true; |
| 447 } | 451 } |
| 448 | 452 |
| 449 void PasswordGenerationAgent::ShowEditingPopup() { | 453 void PasswordGenerationAgent::ShowEditingPopup() { |
| 450 Send(new AutofillHostMsg_ShowPasswordEditingPopup( | 454 Send(new AutofillHostMsg_ShowPasswordEditingPopup( |
| 451 routing_id(), | 455 routing_id(), |
| 452 render_frame()->GetRenderView()->ElementBoundsInWindow( | 456 render_frame()->GetRenderView()->ElementBoundsInWindow( |
| 453 generation_element_), | 457 generation_element_), |
| 454 *generation_form_data_->form)); | 458 *generation_form_data_->form)); |
| 455 editing_popup_shown_ = true; | 459 editing_popup_shown_ = true; |
| 456 } | 460 } |
| 457 | 461 |
| 458 void PasswordGenerationAgent::HidePopup() { | 462 void PasswordGenerationAgent::HidePopup() { |
| 459 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 463 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
| 460 } | 464 } |
| 461 | 465 |
| 462 void PasswordGenerationAgent::OnGeneratePassword() { | 466 void PasswordGenerationAgent::OnUserTriggeredGeneratePassword() { |
| 463 blink::WebDocument doc = render_frame()->GetWebFrame()->document(); | 467 blink::WebDocument doc = render_frame()->GetWebFrame()->document(); |
| 464 if (doc.isNull()) | 468 if (doc.isNull()) |
| 465 return; | 469 return; |
| 466 | 470 |
| 467 blink::WebElement focused_element = doc.focusedElement(); | 471 blink::WebElement focused_element = doc.focusedElement(); |
| 468 const blink::WebInputElement* element = toWebInputElement(&focused_element); | 472 const blink::WebInputElement* element = toWebInputElement(&focused_element); |
| 469 if (!element || !element->isPasswordField()) | 473 if (!element || !element->isPasswordField()) |
| 470 return; | 474 return; |
| 471 | 475 |
| 472 blink::WebFormElement form = element->form(); | 476 blink::WebFormElement form = element->form(); |
| 473 if (form.isNull()) | 477 if (form.isNull()) |
| 474 return; | 478 return; |
| 475 | 479 |
| 476 scoped_ptr<PasswordForm> password_form( | 480 scoped_ptr<PasswordForm> password_form( |
| 477 CreatePasswordFormFromWebForm(form, nullptr, nullptr)); | 481 CreatePasswordFormFromWebForm(form, nullptr, nullptr)); |
| 478 if (!password_form) | 482 if (!password_form) |
| 479 return; | 483 return; |
| 480 | 484 |
| 481 generation_element_ = *element; | 485 generation_element_ = *element; |
| 482 std::vector<blink::WebInputElement> password_elements; | 486 std::vector<blink::WebInputElement> password_elements; |
| 483 GetAccountCreationPasswordFields(form, &password_elements); | 487 GetAccountCreationPasswordFields(form, &password_elements); |
| 484 password_elements = FindPasswordElementsForGeneration( | 488 password_elements = FindPasswordElementsForGeneration( |
| 485 password_elements, element->nameForAutofill()); | 489 password_elements, element->nameForAutofill()); |
| 486 generation_form_data_.reset(new AccountCreationFormData( | 490 generation_form_data_.reset(new AccountCreationFormData( |
| 487 make_linked_ptr(password_form.release()), password_elements)); | 491 make_linked_ptr(password_form.release()), password_elements)); |
| 492 is_manually_triggered_ = true; |
| 488 ShowGenerationPopup(); | 493 ShowGenerationPopup(); |
| 489 } | 494 } |
| 490 | 495 |
| 491 } // namespace autofill | 496 } // namespace autofill |
| OLD | NEW |