Index: chrome/browser/autofill/autofill_external_delegate.cc |
diff --git a/chrome/browser/autofill/autofill_external_delegate.cc b/chrome/browser/autofill/autofill_external_delegate.cc |
index 8c0bcddd2684b5f6e19602e47d431a514968369b..e99fb98454dfc64647d25c68e6617e0749d65783 100644 |
--- a/chrome/browser/autofill/autofill_external_delegate.cc |
+++ b/chrome/browser/autofill/autofill_external_delegate.cc |
@@ -26,12 +26,22 @@ AutofillExternalDelegate::AutofillExternalDelegate( |
has_shown_autofill_popup_for_current_edit_(false) { |
} |
-void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int listIndex) { |
+void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, |
+ int list_index) { |
+ if (suggestions_options_index_ == list_index || |
+ suggestions_clear_index_ == list_index) |
+ return; |
+ |
RenderViewHost* host = |
tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
- host->Send(new AutofillMsg_SelectAutofillSuggestionAtIndex( |
- host->routing_id(), |
- listIndex)); |
+ host->Send(new AutofillMsg_SetAutofillActionPreview( |
+ host->routing_id())); |
+ |
+ // Fill the values for the whole form. |
+ autofill_manager_->OnFillAutofillFormData(autofill_query_id_, |
+ autofill_query_form_, |
+ autofill_query_field_, |
+ unique_id); |
} |
void AutofillExternalDelegate::OnQuery(int query_id, |
@@ -39,6 +49,7 @@ void AutofillExternalDelegate::OnQuery(int query_id, |
const webkit::forms::FormField& field, |
const gfx::Rect& bounds, |
bool display_warning_if_disabled) { |
+ autofill_query_form_ = form; |
autofill_query_field_ = field; |
display_warning_if_disabled_ = display_warning_if_disabled; |
autofill_query_id_ = query_id; |
@@ -50,6 +61,50 @@ void AutofillExternalDelegate::DidEndTextFieldEditing() { |
has_shown_autofill_popup_for_current_edit_ = false; |
} |
+void AutofillExternalDelegate::didAcceptAutofillSuggestions(string16 value, |
+ int unique_id, |
+ unsigned index) { |
+ HideAutofillPopup(); |
+ |
+ // TODO(csharp): Add the password autofill manager. |
+ //if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) |
+ // return; |
+ |
+ if (suggestions_options_index_ != -1 && |
+ index == static_cast<unsigned>(suggestions_options_index_)) { |
+ // User selected 'Autofill Options'. |
+ autofill_manager_->OnShowAutofillDialog(); |
+ } else if (suggestions_clear_index_ != -1 && |
+ index == static_cast<unsigned>(suggestions_clear_index_)) { |
+ // User selected 'Clear form'. |
+ RenderViewHost* host = |
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
+ host->Send(new AutofillMsg_ClearForm(host->routing_id())); |
+ |
+ } else if (!unique_id) { |
+ // User selected an Autocomplete entry, so we fill directly. |
+ RenderViewHost* host = |
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
+ host->Send(new AutofillMsg_SetNodeText( |
+ host->routing_id(), |
+ value)); |
+ } else { |
+ RenderViewHost* host = |
+ tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
+ host->Send(new AutofillMsg_SetAutofillActionFill( |
+ host->routing_id())); |
+ |
+ // Fill the values for the whole form. |
+ autofill_manager_->OnFillAutofillFormData(autofill_query_id_, |
+ autofill_query_form_, |
+ autofill_query_field_, |
+ unique_id); |
+ } |
+ |
+ suggestions_clear_index_ = -1; |
+ suggestions_options_index_ = -1; |
+} |
+ |
void AutofillExternalDelegate::OnSuggestionsReturned( |
int query_id, |
const std::vector<string16>& values, |
@@ -109,6 +164,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
l.push_back(string16()); |
i.push_back(string16()); |
ids.push_back(0); |
+ suggestions_clear_index_ = v.size() - 1; |
separator_index = v.size() - 1; |
} |
@@ -119,6 +175,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
l.push_back(string16()); |
i.push_back(string16()); |
ids.push_back(0); |
+ suggestions_options_index_ = v.size() - 1; |
separator_index = values.size(); |
} |