Chromium Code Reviews| 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 1a7d2e56c42dcd5a72c4140fe6b34194719a982c..2dc27624f68a210fcbcf061941d888ebed0e30e1 100644 |
| --- a/chrome/browser/autofill/autofill_external_delegate.cc |
| +++ b/chrome/browser/autofill/autofill_external_delegate.cc |
| @@ -45,7 +45,9 @@ void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) { |
| if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry) |
| return; |
| - FillAutofillFormData(unique_id, true); |
| + // Only preview the data if it is a profile. |
| + if (unique_id > 0) |
| + FillAutofillFormData(unique_id, true); |
| } |
| void AutofillExternalDelegate::OnQuery(int query_id, |
| @@ -70,17 +72,33 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
| if (query_id != autofill_query_id_) |
| return; |
| - if (values.empty()) { |
| + // List any data list values at the start. |
| + std::vector<string16> v(data_list_values_); |
| + std::vector<string16> l(data_list_labels_); |
| + std::vector<string16> i(data_list_icons_); |
| + std::vector<int> ids(data_list_unique_ids_); |
| + |
| + // If there are both <datalist> items and Autofill suggestions, add a |
| + // separator between them. |
| + if (!values.empty() && !v.empty()) { |
| + v.push_back(string16()); |
| + l.push_back(string16()); |
| + i.push_back(string16()); |
| + ids.push_back(WebAutofillClient::MenuItemIDSeparator); |
| + } |
| + |
| + // Append the Autofill suggestions. |
| + v.insert(v.end(), values.begin(), values.end()); |
| + l.insert(l.end(), labels.begin(), labels.end()); |
| + i.insert(i.end(), icons.begin(), icons.end()); |
| + ids.insert(ids.end(), unique_ids.begin(), unique_ids.end()); |
| + |
| + if (v.empty()) { |
| // No suggestions, any popup currently showing is obsolete. |
| HideAutofillPopup(); |
| return; |
| } |
| - std::vector<string16> v(values); |
| - std::vector<string16> l(labels); |
| - std::vector<string16> i(icons); |
| - std::vector<int> ids(unique_ids); |
| - |
| // Add a separator to go between the values and menu items. |
| v.push_back(string16()); |
| l.push_back(string16()); |
| @@ -94,7 +112,8 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
| l.assign(1, string16()); |
| i.assign(1, string16()); |
| ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage); |
| - } else if (ids[0] < 0 && ids.size() > 1) { |
| + } else if (ids[0] == WebAutofillClient::MenuItemIDWarningMessage && |
|
Ilya Sherman
2012/05/30 21:55:43
ids[0] is no longer guaranteed to be the first Aut
csharp
2012/05/31 14:20:26
Done.
|
| + ids.size() > 1) { |
| // If we received a warning instead of suggestions from autofill but regular |
| // suggestions from autocomplete, don't show the autofill warning. |
| v.erase(v.begin()); |
| @@ -104,7 +123,8 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
| } |
| // If we were about to show a warning and we shouldn't, don't. |
| - if (ids[0] < 0 && !display_warning_if_disabled_) |
| + if (ids[0] == WebAutofillClient::MenuItemIDWarningMessage && |
| + !display_warning_if_disabled_) |
| return; |
| // Only include "Autofill Options" special menu item if we have Autofill |
| @@ -170,6 +190,17 @@ void AutofillExternalDelegate::OnShowPasswordSuggestions( |
| ApplyAutofillSuggestions(suggestions, empty, empty, password_ids); |
| } |
| +void AutofillExternalDelegate::SetCurrentDataListValues( |
| + const std::vector<string16>& data_list_values, |
| + const std::vector<string16>& data_list_labels, |
| + const std::vector<string16>& data_list_icons, |
| + const std::vector<int>& data_list_unique_ids) { |
| + data_list_values_ = data_list_values; |
| + data_list_labels_ = data_list_labels; |
| + data_list_icons_ = data_list_icons; |
| + data_list_unique_ids_ = data_list_unique_ids; |
| +} |
|
Ilya Sherman
2012/05/30 21:55:43
Shouldn't this method also update the popup conten
csharp
2012/05/31 14:20:26
This method shouldn't ever get called when the pop
Ilya Sherman
2012/06/01 06:28:16
Ok. The DCHECK is probably good enough for now; b
csharp
2012/06/04 15:02:03
Had to replace the DCHECK with an if, since if you
|
| + |
| void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) { |
| if (tab_contents_wrapper_) { |
| tab_contents_wrapper_->autocomplete_history_manager()-> |
| @@ -197,23 +228,25 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( |
| if (unique_id == WebAutofillClient::MenuItemIDWarningMessage) |
| return false; |
| + RenderViewHost* host = |
| + tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| + |
| if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) { |
| // User selected 'Autofill Options'. |
| autofill_manager_->OnShowAutofillDialog(); |
| } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) { |
| // User selected 'Clear form'. |
| - RenderViewHost* host = |
| - tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); |
| } else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry && |
| password_autofill_manager_.DidAcceptAutofillSuggestion( |
| autofill_query_field_, value)) { |
| // DidAcceptAutofillSuggestion has already handled the work to fill in |
| // the page as required. |
| + } else if (unique_id == WebAutofillClient::MenuItemIDDataListEntry) { |
| + host->Send(new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(), |
| + value)); |
| } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) { |
| // User selected an Autocomplete, so we fill directly. |
| - RenderViewHost* host = |
| - tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| host->Send(new AutofillMsg_SetNodeText( |
| host->GetRoutingID(), |
| value)); |