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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/renderer/password_autofill_agent.cc
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index 8eabb52bcaa7ec1136b2010ec8199db6179572d0..f19af2da3d31d94fc8101d2fe3d4ad2766e6e35a 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -12,11 +12,13 @@
#include <vector>
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/i18n/case_conversion.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_macros.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -25,6 +27,7 @@
#include "components/autofill/content/renderer/password_form_conversion_utils.h"
#include "components/autofill/content/renderer/renderer_save_password_progress_logger.h"
#include "components/autofill/core/common/autofill_constants.h"
+#include "components/autofill/core/common/autofill_switches.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/password_form_fill_data.h"
@@ -60,6 +63,9 @@ static const size_t kMaximumTextSizeForAutocomplete = 1000;
const char kDummyUsernameField[] = "anonymous_username";
const char kDummyPasswordField[] = "anonymous_password";
+const char kDebugAttributeForFormSignature[] = "form_signature";
+const char kDebugAttributeForFieldSignature[] = "field_signature";
+
// Maps element names to the actual elements to simplify form filling.
typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap;
@@ -562,6 +568,35 @@ bool FillFormOnPasswordReceived(
field_value_and_properties_map, registration_callback, logger);
}
+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.
+ blink::WebVector<blink::WebFormElement> forms) {
+ for (blink::WebFormElement form : forms) {
+ std::unique_ptr<PasswordForm> password_form(
+ CreatePasswordFormFromWebForm(form, nullptr, nullptr));
+ if (password_form) {
+ form.setAttribute(
+ blink::WebString::fromASCII(kDebugAttributeForFormSignature),
+ blink::WebString::fromUTF8(base::Uint64ToString(
+ CalculateFormSignature(password_form->form_data))));
+ blink::WebVector<blink::WebFormControlElement> control_elements =
+ form_util::ExtractAutofillableElementsInForm(form);
+ CHECK(control_elements.size() == password_form->form_data.fields.size());
+ for (size_t i = 0; i < control_elements.size(); ++i) {
+ blink::WebFormControlElement& control_element = control_elements[i];
+ if (!form_util::IsAutofillableElement(control_element))
+ continue;
+
+ const FormFieldData& field = password_form->form_data.fields[i];
+ CHECK(field.name == control_element.nameForAutofill().utf16());
+ control_element.setAttribute(
+ blink::WebString::fromASCII(kDebugAttributeForFieldSignature),
+ blink::WebString::fromUTF8(
+ base::Uint64ToString(CalculateFieldSignatureForField(field))));
+ }
+ }
+ }
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -984,6 +1019,10 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
blink::WebVector<blink::WebFormElement> forms;
frame->document().forms(forms);
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kShowAutofillSignatures)) {
+ AnnotateFormsWithSignatures(forms);
+ }
if (logger)
logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size());
« 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