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

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

Issue 2704503002: [Autofill] Add Chrome flag that annotates web forms with form and field signatures (Closed)
Patch Set: Created 3 years, 10 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_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
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
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 void AnnotateFormsWithSignatures(
sebsg 2017/02/17 16:19:57 Can you just add a small comment here to explain t
kolos1 2017/02/20 10:04:54 Done.
572 blink::WebVector<blink::WebFormElement> forms) {
573 for (blink::WebFormElement form : forms) {
574 std::unique_ptr<PasswordForm> password_form(
575 CreatePasswordFormFromWebForm(form, nullptr, nullptr));
576 if (password_form) {
577 form.setAttribute(
578 blink::WebString::fromASCII(kDebugAttributeForFormSignature),
579 blink::WebString::fromUTF8(base::Uint64ToString(
580 CalculateFormSignature(password_form->form_data))));
581 blink::WebVector<blink::WebFormControlElement> control_elements =
582 form_util::ExtractAutofillableElementsInForm(form);
583 CHECK(control_elements.size() == password_form->form_data.fields.size());
584 for (size_t i = 0; i < control_elements.size(); ++i) {
585 blink::WebFormControlElement& control_element = control_elements[i];
586 if (!form_util::IsAutofillableElement(control_element))
587 continue;
588
589 const FormFieldData& field = password_form->form_data.fields[i];
590 CHECK(field.name == control_element.nameForAutofill().utf16());
591 control_element.setAttribute(
592 blink::WebString::fromASCII(kDebugAttributeForFieldSignature),
593 blink::WebString::fromUTF8(
594 base::Uint64ToString(CalculateFieldSignatureForField(field))));
595 }
596 }
597 }
598 }
599
565 } // namespace 600 } // namespace
566 601
567 //////////////////////////////////////////////////////////////////////////////// 602 ////////////////////////////////////////////////////////////////////////////////
568 // PasswordAutofillAgent, public: 603 // PasswordAutofillAgent, public:
569 604
570 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) 605 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame)
571 : content::RenderFrameObserver(render_frame), 606 : content::RenderFrameObserver(render_frame),
572 logging_state_active_(false), 607 logging_state_active_(false),
573 was_username_autofilled_(false), 608 was_username_autofilled_(false),
574 was_password_autofilled_(false), 609 was_password_autofilled_(false),
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 // Checks whether the webpage is a redirect page or an empty page. 1012 // Checks whether the webpage is a redirect page or an empty page.
978 if (form_util::IsWebpageEmpty(frame)) { 1013 if (form_util::IsWebpageEmpty(frame)) {
979 if (logger) { 1014 if (logger) {
980 logger->LogMessage(Logger::STRING_WEBPAGE_EMPTY); 1015 logger->LogMessage(Logger::STRING_WEBPAGE_EMPTY);
981 } 1016 }
982 return; 1017 return;
983 } 1018 }
984 1019
985 blink::WebVector<blink::WebFormElement> forms; 1020 blink::WebVector<blink::WebFormElement> forms;
986 frame->document().forms(forms); 1021 frame->document().forms(forms);
1022 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1023 switches::kShowAutofillSignatures)) {
1024 AnnotateFormsWithSignatures(forms);
1025 }
987 if (logger) 1026 if (logger)
988 logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); 1027 logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size());
989 1028
990 std::vector<PasswordForm> password_forms; 1029 std::vector<PasswordForm> password_forms;
991 for (const blink::WebFormElement& form : forms) { 1030 for (const blink::WebFormElement& form : forms) {
992 if (only_visible) { 1031 if (only_visible) {
993 bool is_form_visible = form_util::AreFormContentsVisible(form); 1032 bool is_form_visible = form_util::AreFormContentsVisible(form);
994 if (logger) { 1033 if (logger) {
995 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); 1034 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form);
996 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); 1035 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible);
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 PasswordAutofillAgent::GetPasswordManagerDriver() { 1555 PasswordAutofillAgent::GetPasswordManagerDriver() {
1517 if (!password_manager_driver_) { 1556 if (!password_manager_driver_) {
1518 render_frame()->GetRemoteInterfaces()->GetInterface( 1557 render_frame()->GetRemoteInterfaces()->GetInterface(
1519 mojo::MakeRequest(&password_manager_driver_)); 1558 mojo::MakeRequest(&password_manager_driver_));
1520 } 1559 }
1521 1560
1522 return password_manager_driver_; 1561 return password_manager_driver_;
1523 } 1562 }
1524 1563
1525 } // namespace autofill 1564 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/form_autofill_util.cc ('k') | components/autofill/core/common/autofill_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698