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 457f86dfca472febe8da76c86b1dbe61ed198c40..bb9e959746d2d30ca209696c0fd195d910d980dc 100644 |
| --- a/chrome/browser/autofill/autofill_external_delegate.cc |
| +++ b/chrome/browser/autofill/autofill_external_delegate.cc |
| @@ -2,17 +2,23 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/utf_string_conversions.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" |
| #include "chrome/common/autofill_messages.h" |
| +#include "chrome/common/chrome_constants.h" |
| #include "content/browser/renderer_host/render_view_host.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| AutofillExternalDelegate::~AutofillExternalDelegate() { |
| } |
| AutofillExternalDelegate::AutofillExternalDelegate( |
| TabContentsWrapper* tab_contents_wrapper) |
| - : tab_contents_wrapper_(tab_contents_wrapper) { |
| + : tab_contents_wrapper_(tab_contents_wrapper), |
| + autofill_query_id_(0) { |
|
Ilya Sherman
2011/11/17 02:24:37
Don't forget to initialize other member variables,
csharp
2011/11/18 18:15:10
Done.
|
| } |
| void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int listIndex) { |
| @@ -22,6 +28,106 @@ void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int listIndex) { |
| listIndex)); |
| } |
| +void AutofillExternalDelegate::OnQuery(int query_id, |
| + const webkit_glue::FormData& form, |
| + const webkit_glue::FormField& field, |
| + bool display_warning) { |
| + autofill_query_field_ = field; |
| + display_warning_if_disabled_ = display_warning; |
| + autofill_query_id_ = query_id; |
|
Ilya Sherman
2011/11/17 02:24:37
Why not simply pass these values into OnSuggestion
csharp
2011/11/18 18:15:10
I don't think there would be an easy way to do tha
Ilya Sherman
2011/11/18 23:16:04
Fair enough -- I keep forgetting that the Autocomp
|
| + |
| + OnQueryPlatformSpecific(query_id, form, field); |
| +} |
| + |
| +void AutofillExternalDelegate::SetDidEndTextFieldEditing() { |
| + has_shown_autofill_popup_for_current_edit_ = false; |
| +} |
| + |
| +void AutofillExternalDelegate::OnSuggestionsReturned( |
| + int query_id, |
| + const std::vector<string16>& values, |
| + const std::vector<string16>& labels, |
| + const std::vector<string16>& icons, |
| + const std::vector<int>& unique_ids) { |
| + if (query_id != autofill_query_id_) |
| + return; |
|
Ilya Sherman
2011/11/17 02:24:37
This case shouldn't be reachable, since this commu
csharp
2011/11/18 18:15:10
I'm not sure that this all occurs in a single task
Ilya Sherman
2011/11/18 23:16:04
Yep, you're right -- again, I forgot that the Auto
|
| + |
| + if (values.empty()) { |
| + // No suggestions, any popup currently showing is obsolete. |
| + // TODO(csharp): Hide the popup once my other code is merged with this. |
| + // hidePopups(); |
| + return; |
| + } |
| + |
| + std::vector<string16> v(values); |
| + 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_.autocomplete) { |
| + // If autofill is disabled and we had suggestions, show a warning instead. |
| + v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); |
| + l.assign(1, string16()); |
| + i.assign(1, string16()); |
| + ids.assign(1, -1); |
| + } else if (ids[0] < 0 && 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()); |
| + l.erase(l.begin()); |
| + i.erase(i.begin()); |
| + ids.erase(ids.begin()); |
| + } |
| + |
| + // If we were about to show a warning and we shouldn't, don't. |
| + if (ids[0] < 0 && !display_warning_if_disabled_) |
| + return; |
| + |
| + // Only include "Autofill Options" special menu item if we have Autofill |
| + // items, identified by |unique_ids| having at least one valid value. |
| + bool has_autofill_item = false; |
| + for (size_t i = 0; i < ids.size(); ++i) { |
| + if (ids[i] > 0) { |
| + has_autofill_item = true; |
| + break; |
| + } |
| + } |
| + |
| + // 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) { |
| + 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; |
| + } |
| + |
| + if (has_autofill_item) { |
| + // Append the 'Chrome Autofill options' menu item; |
| + v.push_back(l10n_util::GetStringFUTF16(IDS_AUTOFILL_OPTIONS_POPUP, |
| + WideToUTF16(chrome::kBrowserAppName))); |
| + l.push_back(string16()); |
| + i.push_back(string16()); |
| + ids.push_back(0); |
| + suggestions_options_index_ = v.size() - 1; |
| + separator_index = values.size(); |
| + } |
| + |
| + // Send to display. |
| + if (!v.empty() && autofill_query_field_.is_focusable) { |
| + ApplyAutofillSuggestions(v, l, i, ids, separator_index); |
| + } |
|
Ilya Sherman
2011/11/17 02:24:37
nit: No need for curly braces since this is a one-
csharp
2011/11/18 18:15:10
Done.
|
| + |
| + tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( |
| + has_autofill_item && !has_shown_autofill_popup_for_current_edit_); |
| + has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
| +} |
| + |
| // Add a "!defined(OS_YOUROS) for each platform that implements this |
| // in an autofill_external_delegate_YOUROS.cc. Currently there are |