summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/autofill
diff options
context:
space:
mode:
authorcsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-08 21:24:08 +0000
committercsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-08 21:24:08 +0000
commit5c8de6b907f1bbc25f76b9a1062b5fd9df0735fb (patch)
tree4d28cc605a2a37a626b471502f26291a4b0dfd16 /chrome/renderer/autofill
parent59ac148b23ebd8aa24eb4319c8a15133b90719ed (diff)
downloadchromium_src-5c8de6b907f1bbc25f76b9a1062b5fd9df0735fb.zip
chromium_src-5c8de6b907f1bbc25f76b9a1062b5fd9df0735fb.tar.gz
chromium_src-5c8de6b907f1bbc25f76b9a1062b5fd9df0735fb.tar.bz2
Add Datalist Support to New Autofill UI
Show Datalist elements in the new Autofill UI, properly separated from the other data and fully selectable. BUG=51644 TEST=The datalist elements can be selected like normal autofill elements and unit tests pass. Review URL: https://chromiumcodereview.appspot.com/10443084 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/autofill')
-rw-r--r--chrome/renderer/autofill/autofill_agent.cc59
-rw-r--r--chrome/renderer/autofill/autofill_agent.h1
2 files changed, 60 insertions, 0 deletions
diff --git a/chrome/renderer/autofill/autofill_agent.cc b/chrome/renderer/autofill/autofill_agent.cc
index 2442899..a86a213 100644
--- a/chrome/renderer/autofill/autofill_agent.cc
+++ b/chrome/renderer/autofill/autofill_agent.cc
@@ -52,6 +52,10 @@ namespace {
// (so to avoid sending long strings through IPC).
const size_t kMaximumTextSizeForAutofill = 1000;
+// The maximum number of data list elements to send to the browser process
+// via IPC (to prevent long IPC messages).
+const size_t kMaximumDataListSizeForAutofill = 30;
+
void AppendDataListSuggestions(const WebKit::WebInputElement& element,
std::vector<string16>* values,
std::vector<string16>* labels,
@@ -86,6 +90,33 @@ void AppendDataListSuggestions(const WebKit::WebInputElement& element,
}
}
+// Trim the vectors before sending them to the browser process to ensure we
+// don't send too much data through the IPC.
+void TrimDataListsForIPC(std::vector<string16>* values,
+ std::vector<string16>* labels,
+ std::vector<string16>* icons,
+ std::vector<int>* unique_ids) {
+ // Limit the size of the vectors.
+ if (values->size() > kMaximumDataListSizeForAutofill) {
+ values->resize(kMaximumDataListSizeForAutofill);
+ labels->resize(kMaximumDataListSizeForAutofill);
+ icons->resize(kMaximumDataListSizeForAutofill);
+ unique_ids->resize(kMaximumDataListSizeForAutofill);
+ }
+
+ // Limit the size of the strings in the vectors
+ for (size_t i = 0; i < values->size(); ++i) {
+ if ((*values)[i].length() > kMaximumTextSizeForAutofill)
+ (*values)[i].resize(kMaximumTextSizeForAutofill);
+
+ if ((*labels)[i].length() > kMaximumTextSizeForAutofill)
+ (*labels)[i].resize(kMaximumTextSizeForAutofill);
+
+ if ((*icons)[i].length() > kMaximumTextSizeForAutofill)
+ (*icons)[i].resize(kMaximumTextSizeForAutofill);
+ }
+}
+
} // namespace
namespace autofill {
@@ -126,6 +157,8 @@ bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
OnClearPreviewedForm)
IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText,
OnSetNodeText)
+ IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
+ OnAcceptDataListSuggestion)
IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
OnAcceptPasswordAutofillSuggestion)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -529,6 +562,10 @@ void AutofillAgent::OnSetNodeText(const string16& value) {
SetNodeText(value, &element_);
}
+void AutofillAgent::OnAcceptDataListSuggestion(const string16& value) {
+ AcceptDataListSuggestion(value);
+}
+
void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) {
// We need to make sure this is handled here because the browser process
// skipped it handling because it believed it would be handled here. If it
@@ -600,6 +637,28 @@ void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element,
gfx::Rect bounding_box(element_.boundsInViewportSpace());
+ // Find the datalist values and send them to the browser process.
+ std::vector<string16> data_list_values;
+ std::vector<string16> data_list_labels;
+ std::vector<string16> data_list_icons;
+ std::vector<int> data_list_unique_ids;
+ AppendDataListSuggestions(element_,
+ &data_list_values,
+ &data_list_labels,
+ &data_list_icons,
+ &data_list_unique_ids);
+
+ TrimDataListsForIPC(&data_list_values,
+ &data_list_labels,
+ &data_list_icons,
+ &data_list_unique_ids);
+
+ Send(new AutofillHostMsg_SetDataList(routing_id(),
+ data_list_values,
+ data_list_labels,
+ data_list_icons,
+ data_list_unique_ids));
+
Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(),
autofill_query_id_,
form,
diff --git a/chrome/renderer/autofill/autofill_agent.h b/chrome/renderer/autofill/autofill_agent.h
index 2c7fd55..245b639 100644
--- a/chrome/renderer/autofill/autofill_agent.h
+++ b/chrome/renderer/autofill/autofill_agent.h
@@ -112,6 +112,7 @@ class AutofillAgent : public content::RenderViewObserver,
void OnSetAutofillActionPreview();
void OnClearPreviewedForm();
void OnSetNodeText(const string16& value);
+ void OnAcceptDataListSuggestion(const string16& value);
void OnAcceptPasswordAutofillSuggestion(const string16& value);
// Called in a posted task by textFieldDidChange() to work-around a WebKit bug