| 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> |
| 8 |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "components/autofill/content/common/autofill_messages.h" | 11 #include "components/autofill/content/common/autofill_messages.h" |
| 11 #include "components/autofill/content/renderer/form_autofill_util.h" | 12 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 12 #include "components/autofill/content/renderer/password_autofill_agent.h" | 13 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 13 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 14 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
| 14 #include "components/autofill/core/common/autofill_switches.h" | 15 #include "components/autofill/core/common/autofill_switches.h" |
| 15 #include "components/autofill/core/common/form_data.h" | 16 #include "components/autofill/core/common/form_data.h" |
| 16 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
| 17 #include "components/autofill/core/common/password_form_generation_data.h" | 18 #include "components/autofill/core/common/password_form_generation_data.h" |
| 18 #include "components/autofill/core/common/password_generation_util.h" | 19 #include "components/autofill/core/common/password_generation_util.h" |
| 19 #include "content/public/renderer/render_frame.h" | 20 #include "content/public/renderer/render_frame.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return; | 197 return; |
| 197 | 198 |
| 198 blink::WebVector<blink::WebFormElement> forms; | 199 blink::WebVector<blink::WebFormElement> forms; |
| 199 render_frame()->GetWebFrame()->document().forms(forms); | 200 render_frame()->GetWebFrame()->document().forms(forms); |
| 200 for (size_t i = 0; i < forms.size(); ++i) { | 201 for (size_t i = 0; i < forms.size(); ++i) { |
| 201 if (forms[i].isNull()) | 202 if (forms[i].isNull()) |
| 202 continue; | 203 continue; |
| 203 | 204 |
| 204 // If we can't get a valid PasswordForm, we skip this form because the | 205 // If we can't get a valid PasswordForm, we skip this form because the |
| 205 // the password won't get saved even if we generate it. | 206 // the password won't get saved even if we generate it. |
| 206 scoped_ptr<PasswordForm> password_form( | 207 std::unique_ptr<PasswordForm> password_form( |
| 207 CreatePasswordFormFromWebForm(forms[i], nullptr, nullptr)); | 208 CreatePasswordFormFromWebForm(forms[i], nullptr, nullptr)); |
| 208 if (!password_form.get()) { | 209 if (!password_form.get()) { |
| 209 VLOG(2) << "Skipping form as it would not be saved"; | 210 VLOG(2) << "Skipping form as it would not be saved"; |
| 210 continue; | 211 continue; |
| 211 } | 212 } |
| 212 | 213 |
| 213 // Do not generate password for GAIA since it is used to retrieve the | 214 // Do not generate password for GAIA since it is used to retrieve the |
| 214 // generated paswords. | 215 // generated paswords. |
| 215 GURL realm(password_form->signon_realm); | 216 GURL realm(password_form->signon_realm); |
| 216 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) | 217 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 | 465 |
| 465 void PasswordGenerationAgent::HidePopup() { | 466 void PasswordGenerationAgent::HidePopup() { |
| 466 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 467 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
| 467 } | 468 } |
| 468 | 469 |
| 469 void PasswordGenerationAgent::OnUserTriggeredGeneratePassword() { | 470 void PasswordGenerationAgent::OnUserTriggeredGeneratePassword() { |
| 470 if (last_focused_password_element_.isNull()) | 471 if (last_focused_password_element_.isNull()) |
| 471 return; | 472 return; |
| 472 | 473 |
| 473 blink::WebFormElement form = last_focused_password_element_.form(); | 474 blink::WebFormElement form = last_focused_password_element_.form(); |
| 474 scoped_ptr<PasswordForm> password_form; | 475 std::unique_ptr<PasswordForm> password_form; |
| 475 std::vector<blink::WebFormControlElement> control_elements; | 476 std::vector<blink::WebFormControlElement> control_elements; |
| 476 if (!form.isNull()) { | 477 if (!form.isNull()) { |
| 477 password_form = CreatePasswordFormFromWebForm(form, nullptr, nullptr); | 478 password_form = CreatePasswordFormFromWebForm(form, nullptr, nullptr); |
| 478 control_elements = form_util::ExtractAutofillableElementsInForm(form); | 479 control_elements = form_util::ExtractAutofillableElementsInForm(form); |
| 479 } else { | 480 } else { |
| 480 const blink::WebFrame& frame = *render_frame()->GetWebFrame(); | 481 const blink::WebFrame& frame = *render_frame()->GetWebFrame(); |
| 481 blink::WebDocument doc = frame.document(); | 482 blink::WebDocument doc = frame.document(); |
| 482 if (doc.isNull()) | 483 if (doc.isNull()) |
| 483 return; | 484 return; |
| 484 password_form = | 485 password_form = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 495 GetAccountCreationPasswordFields(control_elements, &password_elements); | 496 GetAccountCreationPasswordFields(control_elements, &password_elements); |
| 496 password_elements = FindPasswordElementsForGeneration( | 497 password_elements = FindPasswordElementsForGeneration( |
| 497 password_elements, last_focused_password_element_.nameForAutofill()); | 498 password_elements, last_focused_password_element_.nameForAutofill()); |
| 498 generation_form_data_.reset(new AccountCreationFormData( | 499 generation_form_data_.reset(new AccountCreationFormData( |
| 499 make_linked_ptr(password_form.release()), password_elements)); | 500 make_linked_ptr(password_form.release()), password_elements)); |
| 500 is_manually_triggered_ = true; | 501 is_manually_triggered_ = true; |
| 501 ShowGenerationPopup(); | 502 ShowGenerationPopup(); |
| 502 } | 503 } |
| 503 | 504 |
| 504 } // namespace autofill | 505 } // namespace autofill |
| OLD | NEW |