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 08ce18a0f74af0e02c0a673f28de4724c40345c5..992f8f5ea7ccd9d7c9f6c84dcef1d63f71bee17a 100644 |
| --- a/chrome/browser/autofill/autofill_external_delegate.cc |
| +++ b/chrome/browser/autofill/autofill_external_delegate.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/autocomplete_history_manager.h" |
| #include "chrome/browser/autofill/autofill_external_delegate.h" |
| #include "chrome/browser/autofill/autofill_manager.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| @@ -30,9 +31,7 @@ AutofillExternalDelegate::AutofillExternalDelegate( |
| tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), |
| autofill_query_id_(0), |
| display_warning_if_disabled_(false), |
| - has_shown_autofill_popup_for_current_edit_(false), |
| - suggestions_clear_index_(-1), |
| - suggestions_options_index_(-1) { |
| + has_shown_autofill_popup_for_current_edit_(false) { |
| } |
| void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, |
| @@ -41,8 +40,8 @@ void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, |
| autofill_query_field_)) |
| return; |
| - if (list_index == suggestions_options_index_ || |
| - list_index == suggestions_clear_index_ || |
| + if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions || |
| + unique_id == WebAutofillClient::MenuItemIDClearForm || |
| unique_id == WebAutofillClient::MenuItemIDWarningMessage) |
| return; |
| @@ -81,7 +80,6 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
| std::vector<string16> l(labels); |
| std::vector<string16> i(icons); |
| std::vector<int> ids(unique_ids); |
| - int separator_index = -1; |
| DCHECK_GT(ids.size(), 0U); |
| if (!autofill_query_field_.should_autocomplete) { |
| @@ -113,16 +111,15 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
| } |
| } |
| + int separator_index = ids.size(); |
|
Ilya Sherman
2012/04/19 21:01:57
Do we still need to keep track of the separator_in
csharp
2012/04/20 15:03:18
See other comment for reason to keep this.
|
| + |
| // The form has been auto-filled, so give the user the chance to clear the |
| // form. Append the 'Clear form' menu item. |
| - if (has_autofill_item && |
| - autofill_query_field_.is_autofilled) { |
| + if (has_autofill_item && autofill_query_field_.is_autofilled) { |
| v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); |
| l.push_back(string16()); |
| i.push_back(string16()); |
| - ids.push_back(0); |
| - suggestions_clear_index_ = v.size() - 1; |
| - separator_index = v.size() - 1; |
| + ids.push_back(WebAutofillClient::MenuItemIDClearForm); |
| } |
| if (has_autofill_item) { |
| @@ -130,9 +127,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned( |
| v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); |
| l.push_back(string16()); |
| i.push_back(string16()); |
| - ids.push_back(0); |
| - suggestions_options_index_ = v.size() - 1; |
| - separator_index = values.size(); |
| + ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions); |
| } |
| // Send to display. |
| @@ -163,6 +158,19 @@ void AutofillExternalDelegate::OnShowPasswordSuggestions( |
| ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); |
| } |
| +void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) { |
| + if (tab_contents_wrapper_) { |
| + tab_contents_wrapper_->autocomplete_history_manager()-> |
| + OnRemoveAutocompleteEntry(autofill_query_field_.name, value); |
| + } |
| +} |
| + |
| +void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard( |
| + int unique_id) { |
| + autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id); |
| +} |
| + |
| + |
| void AutofillExternalDelegate::DidEndTextFieldEditing() { |
| has_shown_autofill_popup_for_current_edit_ = false; |
| } |
| @@ -175,12 +183,10 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( |
| if (unique_id == WebAutofillClient::MenuItemIDWarningMessage) |
| return false; |
| - if (suggestions_options_index_ != -1 && |
| - index == static_cast<unsigned>(suggestions_options_index_)) { |
| + if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) { |
| // User selected 'Autofill Options'. |
| autofill_manager_->OnShowAutofillDialog(); |
| - } else if (suggestions_clear_index_ != -1 && |
| - index == static_cast<unsigned>(suggestions_clear_index_)) { |
| + } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) { |
| // User selected 'Clear form'. |
| RenderViewHost* host = |
| tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| @@ -189,7 +195,7 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( |
| autofill_query_field_, value)) { |
| // DidAcceptAutofillSuggestion has already handled the work to fill in |
| // the page as required. |
| - } else if (!unique_id) { |
| + } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) { |
| // User selected an Autocomplete, so we fill directly. |
| RenderViewHost* host = |
| tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| @@ -216,9 +222,6 @@ void AutofillExternalDelegate::ClearPreviewedForm() { |
| } |
| void AutofillExternalDelegate::HideAutofillPopup() { |
| - suggestions_clear_index_ = -1; |
| - suggestions_options_index_ = -1; |
| - |
| HideAutofillPopupInternal(); |
| } |