diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 20:03:25 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 20:03:25 +0000 |
commit | 40ac331674fa7488b139fa3633a36aade05defdc (patch) | |
tree | 1f491cbf2c76e0e50673cc5c49689b1707ad8d09 /chrome/renderer | |
parent | 3c644d83d23318c6ba120e2303816369045f5964 (diff) | |
download | chromium_src-40ac331674fa7488b139fa3633a36aade05defdc.zip chromium_src-40ac331674fa7488b139fa3633a36aade05defdc.tar.gz chromium_src-40ac331674fa7488b139fa3633a36aade05defdc.tar.bz2 |
Add a debugging flag to annotate web forms with their Autofill field type predictions.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7187029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/autofill/autofill_agent.cc | 11 | ||||
-rw-r--r-- | chrome/renderer/autofill/autofill_agent.h | 8 | ||||
-rw-r--r-- | chrome/renderer/autofill/form_manager.cc | 51 | ||||
-rw-r--r-- | chrome/renderer/autofill/form_manager.h | 7 |
4 files changed, 75 insertions, 2 deletions
diff --git a/chrome/renderer/autofill/autofill_agent.cc b/chrome/renderer/autofill/autofill_agent.cc index 5418dca..ab4c061 100644 --- a/chrome/renderer/autofill/autofill_agent.cc +++ b/chrome/renderer/autofill/autofill_agent.cc @@ -20,6 +20,7 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "webkit/glue/form_data.h" +#include "webkit/glue/form_data_predictions.h" #include "webkit/glue/form_field.h" #include "webkit/glue/password_form.h" @@ -31,6 +32,7 @@ using WebKit::WebKeyboardEvent; using WebKit::WebNode; using WebKit::WebString; using webkit_glue::FormData; +using webkit_glue::FormDataPredictions; namespace { @@ -64,6 +66,8 @@ bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) IPC_MESSAGE_HANDLER(AutofillMsg_SuggestionsReturned, OnSuggestionsReturned) IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) + IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, + OnFieldTypePredictionsAvailable) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -305,6 +309,13 @@ void AutofillAgent::OnFormDataFilled(int query_id, Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id())); } +void AutofillAgent::OnFieldTypePredictionsAvailable( + const std::vector<FormDataPredictions>& forms) { + for (size_t i = 0; i < forms.size(); ++i) { + form_manager_.ShowPredictions(forms[i]); + } +} + void AutofillAgent::ShowSuggestions(const WebInputElement& element, bool autofill_on_empty_values, bool requires_caret_at_end, diff --git a/chrome/renderer/autofill/autofill_agent.h b/chrome/renderer/autofill/autofill_agent.h index 6996d31..921744d 100644 --- a/chrome/renderer/autofill/autofill_agent.h +++ b/chrome/renderer/autofill/autofill_agent.h @@ -16,6 +16,12 @@ #include "content/renderer/render_view_observer.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutoFillClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" +#include "webkit/glue/form_data.h" +#include "webkit/glue/form_field.h" + +namespace webkit_glue { +struct FormDataPredictions; +} namespace autofill { @@ -87,6 +93,8 @@ class AutofillAgent : public RenderViewObserver, const std::vector<string16>& icons, const std::vector<int>& unique_ids); void OnFormDataFilled(int query_id, const webkit_glue::FormData& form); + void OnFieldTypePredictionsAvailable( + const std::vector<webkit_glue::FormDataPredictions>& forms); // Called in a posted task by textFieldDidChange() to work-around a WebKit bug // http://bugs.webkit.org/show_bug.cgi?id=16976 diff --git a/chrome/renderer/autofill/form_manager.cc b/chrome/renderer/autofill/form_manager.cc index c94bfa0..0adfbae 100644 --- a/chrome/renderer/autofill/form_manager.cc +++ b/chrome/renderer/autofill/form_manager.cc @@ -9,6 +9,7 @@ #include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "grit/generated_resources.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" @@ -21,12 +22,13 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebSelectElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" +#include "ui/base/l10n/l10n_util.h" #include "webkit/glue/form_data.h" +#include "webkit/glue/form_data_predictions.h" #include "webkit/glue/form_field.h" +#include "webkit/glue/form_field_predictions.h" #include "webkit/glue/web_io_operators.h" -using webkit_glue::FormData; -using webkit_glue::FormField; using WebKit::WebDocument; using WebKit::WebElement; using WebKit::WebFormControlElement; @@ -40,6 +42,10 @@ using WebKit::WebOptionElement; using WebKit::WebSelectElement; using WebKit::WebString; using WebKit::WebVector; +using webkit_glue::FormData; +using webkit_glue::FormDataPredictions; +using webkit_glue::FormField; +using webkit_glue::FormFieldPredictions; namespace { @@ -796,6 +802,47 @@ void FormManager::PreviewForm(const FormData& form, const WebNode& node) { &PreviewFormField); } +bool FormManager::ShowPredictions(const FormDataPredictions& form) { + FormElement* form_element = NULL; + if (!FindCachedFormElement(form.data, &form_element)) + return false; + + DCHECK_EQ(form.data.fields.size(), form.fields.size()); + for (size_t i = 0, j = 0; + i < form_element->control_elements.size() && j < form.fields.size(); + ++i) { + WebFormControlElement* element = &form_element->control_elements[i]; + string16 element_name(element->nameForAutofill()); + + // Search forward in the |form| for a corresponding field. + size_t k = j; + while (k < form.fields.size() && element_name != form.data.fields[k].name) + k++; + + if (k >= form.fields.size()) + continue; + + DCHECK_EQ(form.data.fields[k].name, element_name); + + std::string placeholder = form.fields[k].overall_type; + string16 title = l10n_util::GetStringFUTF16( + IDS_AUTOFILL_SHOW_PREDICTIONS_TITLE, + UTF8ToUTF16(form.fields[k].heuristic_type), + UTF8ToUTF16(form.fields[k].server_type), + UTF8ToUTF16(form.fields[k].signature), + UTF8ToUTF16(form.signature), + UTF8ToUTF16(form.experiment_id)); + if (!element->hasAttribute("placeholder")) + element->setAttribute("placeholder", WebString(UTF8ToUTF16(placeholder))); + element->setAttribute("title", WebString(title)); + + // We found a matching form field so move on to the next. + ++j; + } + + return true; +} + bool FormManager::ClearFormWithNode(const WebNode& node) { FormElement* form_element = NULL; if (!FindCachedFormElementWithNode(node, &form_element)) diff --git a/chrome/renderer/autofill/form_manager.h b/chrome/renderer/autofill/form_manager.h index 8ef30ac..b32dcb5 100644 --- a/chrome/renderer/autofill/form_manager.h +++ b/chrome/renderer/autofill/form_manager.h @@ -16,6 +16,7 @@ namespace webkit_glue { struct FormData; +struct FormDataPredictions; struct FormField; } // namespace webkit_glue @@ -98,6 +99,12 @@ class FormManager { void PreviewForm(const webkit_glue::FormData& form, const WebKit::WebNode &node); + // For each field in the |form|, sets the field's placeholder text to the + // field's overall predicted type. Also sets the title to include the field's + // heuristic type, server type, and signature; as well as the form's signature + // and the experiment id for the server predictions. + bool ShowPredictions(const webkit_glue::FormDataPredictions& form); + // Clears the values of all input elements in the form that contains |node|. // Returns false if the form is not found. bool ClearFormWithNode(const WebKit::WebNode& node); |