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

Unified Diff: chrome/renderer/autofill/autofill_agent.cc

Issue 10443084: Add Datalist Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merging Created 8 years, 6 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
« no previous file with comments | « chrome/renderer/autofill/autofill_agent.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/autofill/autofill_agent.cc
diff --git a/chrome/renderer/autofill/autofill_agent.cc b/chrome/renderer/autofill/autofill_agent.cc
index 2442899cf2c42695a5bb97b7a5923975623cdc23..a86a213215059a18c6c77e980c5860f836480afe 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,
« no previous file with comments | « chrome/renderer/autofill/autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698