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" | |
16 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
17 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
18 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
19 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
20 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
21 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
23 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
24 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
25 #include "build/build_config.h" | 24 #include "build/build_config.h" |
26 #include "components/autofill/content/renderer/form_autofill_util.h" | 25 #include "components/autofill/content/renderer/form_autofill_util.h" |
27 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 26 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
28 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 27 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
29 #include "components/autofill/core/common/autofill_constants.h" | 28 #include "components/autofill/core/common/autofill_constants.h" |
30 #include "components/autofill/core/common/autofill_switches.h" | |
31 #include "components/autofill/core/common/autofill_util.h" | 29 #include "components/autofill/core/common/autofill_util.h" |
32 #include "components/autofill/core/common/form_field_data.h" | 30 #include "components/autofill/core/common/form_field_data.h" |
33 #include "components/autofill/core/common/password_form_fill_data.h" | 31 #include "components/autofill/core/common/password_form_fill_data.h" |
34 #include "components/security_state/core/security_state.h" | 32 #include "components/security_state/core/security_state.h" |
35 #include "content/public/common/origin_util.h" | 33 #include "content/public/common/origin_util.h" |
36 #include "content/public/renderer/document_state.h" | 34 #include "content/public/renderer/document_state.h" |
37 #include "content/public/renderer/navigation_state.h" | 35 #include "content/public/renderer/navigation_state.h" |
38 #include "content/public/renderer/render_frame.h" | 36 #include "content/public/renderer/render_frame.h" |
39 #include "content/public/renderer/render_view.h" | 37 #include "content/public/renderer/render_view.h" |
40 #include "services/service_manager/public/cpp/interface_provider.h" | 38 #include "services/service_manager/public/cpp/interface_provider.h" |
(...skipping 15 matching lines...) Expand all Loading... |
56 | 54 |
57 namespace autofill { | 55 namespace autofill { |
58 namespace { | 56 namespace { |
59 | 57 |
60 // The size above which we stop triggering autocomplete. | 58 // The size above which we stop triggering autocomplete. |
61 static const size_t kMaximumTextSizeForAutocomplete = 1000; | 59 static const size_t kMaximumTextSizeForAutocomplete = 1000; |
62 | 60 |
63 const char kDummyUsernameField[] = "anonymous_username"; | 61 const char kDummyUsernameField[] = "anonymous_username"; |
64 const char kDummyPasswordField[] = "anonymous_password"; | 62 const char kDummyPasswordField[] = "anonymous_password"; |
65 | 63 |
66 const char kDebugAttributeForFormSignature[] = "form_signature"; | |
67 const char kDebugAttributeForFieldSignature[] = "field_signature"; | |
68 | |
69 // Maps element names to the actual elements to simplify form filling. | 64 // Maps element names to the actual elements to simplify form filling. |
70 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; | 65 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; |
71 | 66 |
72 // Use the shorter name when referencing SavePasswordProgressLogger::StringID | 67 // Use the shorter name when referencing SavePasswordProgressLogger::StringID |
73 // values to spare line breaks. The code provides enough context for that | 68 // values to spare line breaks. The code provides enough context for that |
74 // already. | 69 // already. |
75 typedef SavePasswordProgressLogger Logger; | 70 typedef SavePasswordProgressLogger Logger; |
76 | 71 |
77 typedef std::vector<FormInputElementMap> FormElementsList; | 72 typedef std::vector<FormInputElementMap> FormElementsList; |
78 | 73 |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 blink::WebVector<blink::WebFormElement> forms) { | 568 blink::WebVector<blink::WebFormElement> forms) { |
574 for (blink::WebFormElement form : forms) { | 569 for (blink::WebFormElement form : forms) { |
575 std::unique_ptr<PasswordForm> password_form( | 570 std::unique_ptr<PasswordForm> password_form( |
576 CreatePasswordFormFromWebForm(form, nullptr, nullptr)); | 571 CreatePasswordFormFromWebForm(form, nullptr, nullptr)); |
577 if (password_form) { | 572 if (password_form) { |
578 form.setAttribute( | 573 form.setAttribute( |
579 blink::WebString::fromASCII(kDebugAttributeForFormSignature), | 574 blink::WebString::fromASCII(kDebugAttributeForFormSignature), |
580 blink::WebString::fromUTF8(base::Uint64ToString( | 575 blink::WebString::fromUTF8(base::Uint64ToString( |
581 CalculateFormSignature(password_form->form_data)))); | 576 CalculateFormSignature(password_form->form_data)))); |
582 | 577 |
583 blink::WebVector<blink::WebFormControlElement> control_elements = | 578 std::vector<blink::WebFormControlElement> control_elements = |
584 form_util::ExtractAutofillableElementsInForm(form); | 579 form_util::ExtractAutofillableElementsInForm(form); |
585 DCHECK(control_elements.size() == password_form->form_data.fields.size()); | 580 |
| 581 if (control_elements.size() != password_form->form_data.fields.size()) |
| 582 return; |
| 583 |
586 for (size_t i = 0; i < control_elements.size(); ++i) { | 584 for (size_t i = 0; i < control_elements.size(); ++i) { |
587 blink::WebFormControlElement& control_element = control_elements[i]; | 585 blink::WebFormControlElement control_element = control_elements[i]; |
588 if (!form_util::IsAutofillableElement(control_element)) | |
589 continue; | |
590 | 586 |
591 const FormFieldData& field = password_form->form_data.fields[i]; | 587 const FormFieldData& field = password_form->form_data.fields[i]; |
592 DCHECK(field.name == control_element.nameForAutofill().utf16()); | 588 if (field.name != control_element.nameForAutofill().utf16()) |
| 589 continue; |
593 control_element.setAttribute( | 590 control_element.setAttribute( |
594 blink::WebString::fromASCII(kDebugAttributeForFieldSignature), | 591 blink::WebString::fromASCII(kDebugAttributeForFieldSignature), |
595 blink::WebString::fromUTF8( | 592 blink::WebString::fromUTF8( |
596 base::Uint64ToString(CalculateFieldSignatureForField(field)))); | 593 base::Uint64ToString(CalculateFieldSignatureForField(field)))); |
597 } | 594 } |
598 } | 595 } |
599 } | 596 } |
600 } | 597 } |
601 | 598 |
602 } // namespace | 599 } // namespace |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 // Checks whether the webpage is a redirect page or an empty page. | 1043 // Checks whether the webpage is a redirect page or an empty page. |
1047 if (form_util::IsWebpageEmpty(frame)) { | 1044 if (form_util::IsWebpageEmpty(frame)) { |
1048 if (logger) { | 1045 if (logger) { |
1049 logger->LogMessage(Logger::STRING_WEBPAGE_EMPTY); | 1046 logger->LogMessage(Logger::STRING_WEBPAGE_EMPTY); |
1050 } | 1047 } |
1051 return; | 1048 return; |
1052 } | 1049 } |
1053 | 1050 |
1054 blink::WebVector<blink::WebFormElement> forms; | 1051 blink::WebVector<blink::WebFormElement> forms; |
1055 frame->document().forms(forms); | 1052 frame->document().forms(forms); |
1056 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1053 |
1057 switches::kShowAutofillSignatures)) { | 1054 if (IsShowAutofillSignaturesEnabled()) |
1058 AnnotateFormsWithSignatures(forms); | 1055 AnnotateFormsWithSignatures(forms); |
1059 } | |
1060 if (logger) | 1056 if (logger) |
1061 logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); | 1057 logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); |
1062 | 1058 |
1063 std::vector<PasswordForm> password_forms; | 1059 std::vector<PasswordForm> password_forms; |
1064 for (const blink::WebFormElement& form : forms) { | 1060 for (const blink::WebFormElement& form : forms) { |
1065 if (only_visible) { | 1061 if (only_visible) { |
1066 bool is_form_visible = form_util::AreFormContentsVisible(form); | 1062 bool is_form_visible = form_util::AreFormContentsVisible(form); |
1067 if (logger) { | 1063 if (logger) { |
1068 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); | 1064 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); |
1069 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); | 1065 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 PasswordAutofillAgent::GetPasswordManagerDriver() { | 1585 PasswordAutofillAgent::GetPasswordManagerDriver() { |
1590 if (!password_manager_driver_) { | 1586 if (!password_manager_driver_) { |
1591 render_frame()->GetRemoteInterfaces()->GetInterface( | 1587 render_frame()->GetRemoteInterfaces()->GetInterface( |
1592 mojo::MakeRequest(&password_manager_driver_)); | 1588 mojo::MakeRequest(&password_manager_driver_)); |
1593 } | 1589 } |
1594 | 1590 |
1595 return password_manager_driver_; | 1591 return password_manager_driver_; |
1596 } | 1592 } |
1597 | 1593 |
1598 } // namespace autofill | 1594 } // namespace autofill |
OLD | NEW |