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_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" |
15 #include "base/i18n/case_conversion.h" | 16 #include "base/i18n/case_conversion.h" |
16 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
23 #include "build/build_config.h" | 25 #include "build/build_config.h" |
24 #include "components/autofill/content/renderer/form_autofill_util.h" | 26 #include "components/autofill/content/renderer/form_autofill_util.h" |
25 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 27 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
26 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 28 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
27 #include "components/autofill/core/common/autofill_constants.h" | 29 #include "components/autofill/core/common/autofill_constants.h" |
| 30 #include "components/autofill/core/common/autofill_switches.h" |
28 #include "components/autofill/core/common/autofill_util.h" | 31 #include "components/autofill/core/common/autofill_util.h" |
29 #include "components/autofill/core/common/form_field_data.h" | 32 #include "components/autofill/core/common/form_field_data.h" |
30 #include "components/autofill/core/common/password_form_fill_data.h" | 33 #include "components/autofill/core/common/password_form_fill_data.h" |
31 #include "components/security_state/core/security_state.h" | 34 #include "components/security_state/core/security_state.h" |
32 #include "content/public/common/origin_util.h" | 35 #include "content/public/common/origin_util.h" |
33 #include "content/public/renderer/document_state.h" | 36 #include "content/public/renderer/document_state.h" |
34 #include "content/public/renderer/navigation_state.h" | 37 #include "content/public/renderer/navigation_state.h" |
35 #include "content/public/renderer/render_frame.h" | 38 #include "content/public/renderer/render_frame.h" |
36 #include "content/public/renderer/render_view.h" | 39 #include "content/public/renderer/render_view.h" |
37 #include "services/service_manager/public/cpp/interface_provider.h" | 40 #include "services/service_manager/public/cpp/interface_provider.h" |
(...skipping 15 matching lines...) Expand all Loading... |
53 | 56 |
54 namespace autofill { | 57 namespace autofill { |
55 namespace { | 58 namespace { |
56 | 59 |
57 // The size above which we stop triggering autocomplete. | 60 // The size above which we stop triggering autocomplete. |
58 static const size_t kMaximumTextSizeForAutocomplete = 1000; | 61 static const size_t kMaximumTextSizeForAutocomplete = 1000; |
59 | 62 |
60 const char kDummyUsernameField[] = "anonymous_username"; | 63 const char kDummyUsernameField[] = "anonymous_username"; |
61 const char kDummyPasswordField[] = "anonymous_password"; | 64 const char kDummyPasswordField[] = "anonymous_password"; |
62 | 65 |
| 66 const char kDebugAttributeForFormSignature[] = "form_signature"; |
| 67 const char kDebugAttributeForFieldSignature[] = "field_signature"; |
| 68 |
63 // Maps element names to the actual elements to simplify form filling. | 69 // Maps element names to the actual elements to simplify form filling. |
64 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; | 70 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; |
65 | 71 |
66 // Use the shorter name when referencing SavePasswordProgressLogger::StringID | 72 // Use the shorter name when referencing SavePasswordProgressLogger::StringID |
67 // values to spare line breaks. The code provides enough context for that | 73 // values to spare line breaks. The code provides enough context for that |
68 // already. | 74 // already. |
69 typedef SavePasswordProgressLogger Logger; | 75 typedef SavePasswordProgressLogger Logger; |
70 | 76 |
71 typedef std::vector<FormInputElementMap> FormElementsList; | 77 typedef std::vector<FormInputElementMap> FormElementsList; |
72 | 78 |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 } | 561 } |
556 | 562 |
557 // Fill if we have an exact match for the username. Note that this sets | 563 // Fill if we have an exact match for the username. Note that this sets |
558 // username to autofilled. | 564 // username to autofilled. |
559 return FillUserNameAndPassword( | 565 return FillUserNameAndPassword( |
560 &username_element, &password_element, fill_data, | 566 &username_element, &password_element, fill_data, |
561 true /* exact_username_match */, false /* set_selection */, | 567 true /* exact_username_match */, false /* set_selection */, |
562 field_value_and_properties_map, registration_callback, logger); | 568 field_value_and_properties_map, registration_callback, logger); |
563 } | 569 } |
564 | 570 |
| 571 // Annotate |forms| with form and field signatures as HTML attributes. |
| 572 void AnnotateFormsWithSignatures( |
| 573 blink::WebVector<blink::WebFormElement> forms) { |
| 574 for (blink::WebFormElement form : forms) { |
| 575 std::unique_ptr<PasswordForm> password_form( |
| 576 CreatePasswordFormFromWebForm(form, nullptr, nullptr)); |
| 577 if (password_form) { |
| 578 form.setAttribute( |
| 579 blink::WebString::fromASCII(kDebugAttributeForFormSignature), |
| 580 blink::WebString::fromUTF8(base::Uint64ToString( |
| 581 CalculateFormSignature(password_form->form_data)))); |
| 582 |
| 583 blink::WebVector<blink::WebFormControlElement> control_elements = |
| 584 form_util::ExtractAutofillableElementsInForm(form); |
| 585 DCHECK(control_elements.size() == password_form->form_data.fields.size()); |
| 586 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 587 blink::WebFormControlElement& control_element = control_elements[i]; |
| 588 if (!form_util::IsAutofillableElement(control_element)) |
| 589 continue; |
| 590 |
| 591 const FormFieldData& field = password_form->form_data.fields[i]; |
| 592 DCHECK(field.name == control_element.nameForAutofill().utf16()); |
| 593 control_element.setAttribute( |
| 594 blink::WebString::fromASCII(kDebugAttributeForFieldSignature), |
| 595 blink::WebString::fromUTF8( |
| 596 base::Uint64ToString(CalculateFieldSignatureForField(field)))); |
| 597 } |
| 598 } |
| 599 } |
| 600 } |
| 601 |
565 } // namespace | 602 } // namespace |
566 | 603 |
567 //////////////////////////////////////////////////////////////////////////////// | 604 //////////////////////////////////////////////////////////////////////////////// |
568 // PasswordAutofillAgent, public: | 605 // PasswordAutofillAgent, public: |
569 | 606 |
570 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) | 607 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) |
571 : content::RenderFrameObserver(render_frame), | 608 : content::RenderFrameObserver(render_frame), |
572 logging_state_active_(false), | 609 logging_state_active_(false), |
573 was_username_autofilled_(false), | 610 was_username_autofilled_(false), |
574 was_password_autofilled_(false), | 611 was_password_autofilled_(false), |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 // Checks whether the webpage is a redirect page or an empty page. | 1046 // Checks whether the webpage is a redirect page or an empty page. |
1010 if (form_util::IsWebpageEmpty(frame)) { | 1047 if (form_util::IsWebpageEmpty(frame)) { |
1011 if (logger) { | 1048 if (logger) { |
1012 logger->LogMessage(Logger::STRING_WEBPAGE_EMPTY); | 1049 logger->LogMessage(Logger::STRING_WEBPAGE_EMPTY); |
1013 } | 1050 } |
1014 return; | 1051 return; |
1015 } | 1052 } |
1016 | 1053 |
1017 blink::WebVector<blink::WebFormElement> forms; | 1054 blink::WebVector<blink::WebFormElement> forms; |
1018 frame->document().forms(forms); | 1055 frame->document().forms(forms); |
| 1056 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1057 switches::kShowAutofillSignatures)) { |
| 1058 AnnotateFormsWithSignatures(forms); |
| 1059 } |
1019 if (logger) | 1060 if (logger) |
1020 logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); | 1061 logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); |
1021 | 1062 |
1022 std::vector<PasswordForm> password_forms; | 1063 std::vector<PasswordForm> password_forms; |
1023 for (const blink::WebFormElement& form : forms) { | 1064 for (const blink::WebFormElement& form : forms) { |
1024 if (only_visible) { | 1065 if (only_visible) { |
1025 bool is_form_visible = form_util::AreFormContentsVisible(form); | 1066 bool is_form_visible = form_util::AreFormContentsVisible(form); |
1026 if (logger) { | 1067 if (logger) { |
1027 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); | 1068 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); |
1028 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); | 1069 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 PasswordAutofillAgent::GetPasswordManagerDriver() { | 1589 PasswordAutofillAgent::GetPasswordManagerDriver() { |
1549 if (!password_manager_driver_) { | 1590 if (!password_manager_driver_) { |
1550 render_frame()->GetRemoteInterfaces()->GetInterface( | 1591 render_frame()->GetRemoteInterfaces()->GetInterface( |
1551 mojo::MakeRequest(&password_manager_driver_)); | 1592 mojo::MakeRequest(&password_manager_driver_)); |
1552 } | 1593 } |
1553 | 1594 |
1554 return password_manager_driver_; | 1595 return password_manager_driver_; |
1555 } | 1596 } |
1556 | 1597 |
1557 } // namespace autofill | 1598 } // namespace autofill |
OLD | NEW |