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

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

Issue 11348273: [autofill] Fill in values on a successful run of interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: estade@ review Created 8 years, 1 month 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') | chrome/renderer/autofill/form_autofill_util.h » ('j') | 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 69fd3ede8c5a02cb4a157d8105c24e55ad0d1cd8..991c8ca9aff45b6d73af90e96280b19278af5484 100644
--- a/chrome/renderer/autofill/autofill_agent.cc
+++ b/chrome/renderer/autofill/autofill_agent.cc
@@ -158,8 +158,10 @@ bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
OnAcceptDataListSuggestion)
IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
OnAcceptPasswordAutofillSuggestion)
- IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteFinished,
- OnRequestAutocompleteFinished)
+ IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteSuccess,
+ OnRequestAutocompleteSuccess)
+ IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteError,
+ OnRequestAutocompleteError)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -331,8 +333,8 @@ void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
void AutofillAgent::textFieldDidChange(const WebInputElement& element) {
if (did_set_node_text_) {
- did_set_node_text_ = false;
- return;
+ did_set_node_text_ = false;
+ return;
}
// We post a task for doing the Autofill as the caret position is not set
@@ -589,11 +591,47 @@ void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) {
DCHECK(handled);
}
-void AutofillAgent::OnRequestAutocompleteFinished(
- WebFormElement::AutocompleteResult result) {
+void AutofillAgent::OnRequestAutocompleteSuccess(const FormData& form_data) {
DCHECK(!in_flight_request_form_.isNull());
- in_flight_request_form_.finishRequestAutocomplete(result);
+ // TODO(dbeam): handle <select>s?
+ std::vector<WebKit::WebFormControlElement> elements;
+ autofill::ExtractAutofillableElements(in_flight_request_form_,
+ REQUIRE_AUTOCOMPLETE,
+ &elements);
+
+ for (size_t i = 0; i < form_data.fields.size() && !elements.empty(); ++i) {
+ // TODO(dbeam): change to DCHECK() if values must be non-empty to confirm.
+ const FormFieldData& field = form_data.fields[i];
+ if (field.value.empty())
+ continue;
+
+ for (size_t j = 0; j < elements.size(); ++j) {
+ const string16 element_attr16 = elements[j].getAttribute("autocomplete");
Evan Stade 2012/11/29 04:01:25 don't put type hints in variable names.
Dan Beam 2012/11/29 04:15:19 Done.
+ if (!IsStringASCII(element_attr16)) {
+ elements.erase(elements.begin() + j--);
Evan Stade 2012/11/29 04:01:25 don't erase, it is error prone
Dan Beam 2012/11/29 04:15:19 Done.
+ continue;
+ }
+
+ std::string element_attr = UTF16ToASCII(element_attr16);
Evan Stade 2012/11/29 04:01:25 I don't think you need to do this conversion. fiel
Dan Beam 2012/11/29 04:15:19 Done.
+ if (LowerCaseEqualsASCII(field.autocomplete_attribute,
+ element_attr.c_str())) {
+ autofill::FillFormField(field, false, &elements[j]);
Evan Stade 2012/11/29 04:01:25 it is confusing that what is called field here is
Dan Beam 2012/11/29 04:15:19 Done.
+ elements.erase(elements.begin() + j--);
+ break;
+ }
+ }
+ }
+
+ in_flight_request_form_.finishRequestAutocomplete(
+ WebFormElement::AutocompleteResultSuccess);
+ in_flight_request_form_.reset();
+}
+
+void AutofillAgent::OnRequestAutocompleteError() {
+ DCHECK(!in_flight_request_form_.isNull());
+ in_flight_request_form_.finishRequestAutocomplete(
+ WebFormElement::AutocompleteResultError);
in_flight_request_form_.reset();
}
« no previous file with comments | « chrome/renderer/autofill/autofill_agent.h ('k') | chrome/renderer/autofill/form_autofill_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698