summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_external_delegate.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/autofill/autofill_external_delegate.cc')
-rw-r--r--chrome/browser/autofill/autofill_external_delegate.cc227
1 files changed, 153 insertions, 74 deletions
diff --git a/chrome/browser/autofill/autofill_external_delegate.cc b/chrome/browser/autofill/autofill_external_delegate.cc
index 436e6577..ada423f 100644
--- a/chrome/browser/autofill/autofill_external_delegate.cc
+++ b/chrome/browser/autofill/autofill_external_delegate.cc
@@ -30,22 +30,16 @@ AutofillExternalDelegate::AutofillExternalDelegate(
tab_contents ? tab_contents->web_contents() : NULL),
autofill_query_id_(0),
display_warning_if_disabled_(false),
- has_shown_autofill_popup_for_current_edit_(false) {
+ has_shown_autofill_popup_for_current_edit_(false),
+ popup_visible_(false) {
}
void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) {
- if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions ||
- unique_id == WebAutofillClient::MenuItemIDClearForm ||
- unique_id == WebAutofillClient::MenuItemIDSeparator ||
- unique_id == WebAutofillClient::MenuItemIDWarningMessage)
- return;
-
ClearPreviewedForm();
- 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,
@@ -63,49 +57,25 @@ void AutofillExternalDelegate::OnQuery(int query_id,
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) {
+ const std::vector<string16>& autofill_values,
+ const std::vector<string16>& autofill_labels,
+ const std::vector<string16>& autofill_icons,
+ const std::vector<int>& autofill_unique_ids) {
if (query_id != autofill_query_id_)
return;
- if (values.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);
+ std::vector<string16> values(autofill_values);
+ std::vector<string16> labels(autofill_labels);
+ std::vector<string16> icons(autofill_icons);
+ std::vector<int> ids(autofill_unique_ids);
// Add a separator to go between the values and menu items.
- v.push_back(string16());
- l.push_back(string16());
- i.push_back(string16());
+ values.push_back(string16());
+ labels.push_back(string16());
+ icons.push_back(string16());
ids.push_back(WebAutofillClient::MenuItemIDSeparator);
- DCHECK_GT(ids.size(), 0U);
- if (!autofill_query_field_.should_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, WebAutofillClient::MenuItemIDWarningMessage);
- } 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;
+ ApplyAutofillWarnings(&values, &labels, &icons, &ids);
// Only include "Autofill Options" special menu item if we have Autofill
// items, identified by |unique_ids| having at least one valid value.
@@ -117,38 +87,34 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
}
}
- // 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(WebAutofillClient::MenuItemIDClearForm);
- }
-
- if (has_autofill_item) {
- // Append the 'Chrome Autofill options' menu item;
- v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP));
- l.push_back(string16());
- i.push_back(string16());
- ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions);
- }
+ if (has_autofill_item)
+ ApplyAutofillOptions(&values, &labels, &icons, &ids);
// Remove the separator if it is the last element.
- if (*(ids.rbegin()) == WebAutofillClient::MenuItemIDSeparator) {
- v.pop_back();
- l.pop_back();
- i.pop_back();
+ if (ids.back() == WebAutofillClient::MenuItemIDSeparator) {
+ values.pop_back();
+ labels.pop_back();
+ icons.pop_back();
ids.pop_back();
}
+ InsertDataListValues(&values, &labels, &icons, &ids);
+
+ if (values.empty()) {
+ // No suggestions, any popup currently showing is obsolete.
+ HideAutofillPopup();
+ return;
+ }
+
// Send to display.
- if (!v.empty() && autofill_query_field_.is_focusable)
- ApplyAutofillSuggestions(v, l, i, ids);
+ if (autofill_query_field_.is_focusable) {
+ popup_visible_ = true;
+ ApplyAutofillSuggestions(values, labels, icons, ids);
- tab_contents_->autofill_manager()->OnDidShowAutofillSuggestions(
- has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
- has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
+ tab_contents_->autofill_manager()->OnDidShowAutofillSuggestions(
+ has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
+ has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
+ }
}
void AutofillExternalDelegate::OnShowPasswordSuggestions(
@@ -170,6 +136,22 @@ 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) {
+ // TODO(csharp): Modify the code to allow the data list values to change
+ // even if the popup is visible.
+ // http://crbug.com/131003
+ if (!popup_visible_) {
+ 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;
+ }
+}
+
void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) {
if (tab_contents_) {
tab_contents_->autocomplete_history_manager()->
@@ -197,21 +179,25 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
return false;
+ RenderViewHost* host =
+ tab_contents_->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_->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_->web_contents()->GetRenderViewHost();
host->Send(new AutofillMsg_SetNodeText(
host->GetRoutingID(),
value));
@@ -230,6 +216,8 @@ void AutofillExternalDelegate::ClearPreviewedForm() {
}
void AutofillExternalDelegate::HideAutofillPopup() {
+ popup_visible_ = false;
+
HideAutofillPopupInternal();
}
@@ -264,6 +252,97 @@ void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
unique_id);
}
+void AutofillExternalDelegate::ApplyAutofillWarnings(
+ std::vector<string16>* autofill_values,
+ std::vector<string16>* autofill_labels,
+ std::vector<string16>* autofill_icons,
+ std::vector<int>* autofill_unique_ids) {
+ if (!autofill_query_field_.should_autocomplete) {
+ // If autofill is disabled and we had suggestions, show a warning instead.
+ autofill_values->assign(
+ 1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
+ autofill_labels->assign(1, string16());
+ autofill_icons->assign(1, string16());
+ autofill_unique_ids->assign(1, WebAutofillClient::MenuItemIDWarningMessage);
+ } else if (autofill_unique_ids->size() > 1 &&
+ (*autofill_unique_ids)[0] ==
+ WebAutofillClient::MenuItemIDWarningMessage) {
+ // If we received a warning instead of suggestions from autofill but regular
+ // suggestions from autocomplete, don't show the autofill warning.
+ autofill_values->erase(autofill_values->begin());
+ autofill_labels->erase(autofill_labels->begin());
+ autofill_icons->erase(autofill_icons->begin());
+ autofill_unique_ids->erase(autofill_unique_ids->begin());
+ }
+
+ // If we were about to show a warning and we shouldn't, don't.
+ if (!autofill_unique_ids->empty() &&
+ (*autofill_unique_ids)[0] ==
+ WebAutofillClient::MenuItemIDWarningMessage &&
+ !display_warning_if_disabled_) {
+ autofill_values->clear();
+ autofill_labels->clear();
+ autofill_icons->clear();
+ autofill_unique_ids->clear();
+ }
+}
+
+void AutofillExternalDelegate::ApplyAutofillOptions(
+ std::vector<string16>* autofill_values,
+ std::vector<string16>* autofill_labels,
+ std::vector<string16>* autofill_icons,
+ std::vector<int>* autofill_unique_ids) {
+ // The form has been auto-filled, so give the user the chance to clear the
+ // form. Append the 'Clear form' menu item.
+ if (autofill_query_field_.is_autofilled) {
+ autofill_values->push_back(
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
+ autofill_labels->push_back(string16());
+ autofill_icons->push_back(string16());
+ autofill_unique_ids->push_back(WebAutofillClient::MenuItemIDClearForm);
+ }
+
+ // Append the 'Chrome Autofill options' menu item;
+ autofill_values->push_back(
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP));
+ autofill_labels->push_back(string16());
+ autofill_icons->push_back(string16());
+ autofill_unique_ids->push_back(WebAutofillClient::MenuItemIDAutofillOptions);
+}
+
+void AutofillExternalDelegate::InsertDataListValues(
+ std::vector<string16>* autofill_values,
+ std::vector<string16>* autofill_labels,
+ std::vector<string16>* autofill_icons,
+ std::vector<int>* autofill_unique_ids) {
+ if (data_list_values_.empty())
+ return;
+
+ // Insert the separator between the datalist and Autofill values (if there
+ // are any).
+ if (!autofill_values->empty()) {
+ autofill_values->insert(autofill_values->begin(), string16());
+ autofill_labels->insert(autofill_labels->begin(), string16());
+ autofill_icons->insert(autofill_icons->begin(), string16());
+ autofill_unique_ids->insert(autofill_unique_ids->begin(),
+ WebAutofillClient::MenuItemIDSeparator);
+ }
+
+ // Insert the datalist elements.
+ autofill_values->insert(autofill_values->begin(),
+ data_list_values_.begin(),
+ data_list_values_.end());
+ autofill_labels->insert(autofill_labels->begin(),
+ data_list_labels_.begin(),
+ data_list_labels_.end());
+ autofill_icons->insert(autofill_icons->begin(),
+ data_list_icons_.begin(),
+ data_list_icons_.end());
+ autofill_unique_ids->insert(autofill_unique_ids->begin(),
+ data_list_unique_ids_.begin(),
+ data_list_unique_ids_.end());
+}
+
// Add a "!defined(OS_YOUROS) for each platform that implements this
// in an autofill_external_delegate_YOUROS.cc. Currently there are
// none, so all platforms use the default.