summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_external_delegate.cc
diff options
context:
space:
mode:
authorcsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 02:56:26 +0000
committercsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 02:56:26 +0000
commite7e834702fcd0237014e1808f72097e367ef8a63 (patch)
tree39f6a6f7a8d67ead2b3d2ad2f4c73b94b4167e49 /chrome/browser/autofill/autofill_external_delegate.cc
parent634bc5d15ae1b294dcd29a17111a11e4228bd0ac (diff)
downloadchromium_src-e7e834702fcd0237014e1808f72097e367ef8a63.zip
chromium_src-e7e834702fcd0237014e1808f72097e367ef8a63.tar.gz
chromium_src-e7e834702fcd0237014e1808f72097e367ef8a63.tar.bz2
Add Password Autofill Manager to New Autofill
Copied over the password Autofill Manager functions from the renderer to the browser to allow the new Autofill UI to have access to them. BUG=51644 TEST= Review URL: http://codereview.chromium.org/9600038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/autofill_external_delegate.cc')
-rw-r--r--chrome/browser/autofill/autofill_external_delegate.cc66
1 files changed, 58 insertions, 8 deletions
diff --git a/chrome/browser/autofill/autofill_external_delegate.cc b/chrome/browser/autofill/autofill_external_delegate.cc
index 13f0b7d..ff94bd4 100644
--- a/chrome/browser/autofill/autofill_external_delegate.cc
+++ b/chrome/browser/autofill/autofill_external_delegate.cc
@@ -16,6 +16,16 @@
using content::RenderViewHost;
+namespace {
+
+// The value to give as the unique id for all warnings.
+const int kWarningId = -1;
+
+// The value to give as the unique id for all password entries.
+const int kPasswordEntryId = -2;
+
+} // namespace
+
AutofillExternalDelegate::~AutofillExternalDelegate() {
}
@@ -24,6 +34,8 @@ AutofillExternalDelegate::AutofillExternalDelegate(
AutofillManager* autofill_manager)
: tab_contents_wrapper_(tab_contents_wrapper),
autofill_manager_(autofill_manager),
+ password_autofill_manager_(
+ 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),
@@ -33,9 +45,13 @@ AutofillExternalDelegate::AutofillExternalDelegate(
void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
int list_index) {
+ if (password_autofill_manager_.DidSelectAutofillSuggestion(
+ autofill_query_field_))
+ return;
+
if (list_index == suggestions_options_index_ ||
list_index == suggestions_clear_index_ ||
- unique_id == -1)
+ unique_id == kWarningId)
return;
FillAutofillFormData(unique_id, true);
@@ -81,7 +97,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
l.assign(1, string16());
i.assign(1, string16());
- ids.assign(1, -1);
+ ids.assign(1, kWarningId);
} 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.
@@ -136,6 +152,24 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
}
+void AutofillExternalDelegate::OnShowPasswordSuggestions(
+ const std::vector<string16>& suggestions,
+ const webkit::forms::FormField& field,
+ const gfx::Rect& bounds) {
+ autofill_query_field_ = field;
+
+ if (suggestions.empty()) {
+ HideAutofillPopup();
+ return;
+ }
+
+ SetBounds(bounds);
+
+ std::vector<string16> empty(suggestions.size());
+ std::vector<int> password_ids(suggestions.size(), kPasswordEntryId);
+ ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1);
+}
+
void AutofillExternalDelegate::DidEndTextFieldEditing() {
has_shown_autofill_popup_for_current_edit_ = false;
}
@@ -145,13 +179,9 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
int unique_id,
unsigned index) {
// If the selected element is a warning we don't want to do anything.
- if (unique_id < 0)
+ if (unique_id == kWarningId)
return false;
- // 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'.
@@ -162,8 +192,12 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
RenderViewHost* host =
tab_contents_wrapper_->web_contents()->GetRenderViewHost();
host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
+ } else if (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) {
- // User selected an Autocomplete entry, so we fill directly.
+ // User selected an Autocomplete, so we fill directly.
RenderViewHost* host =
tab_contents_wrapper_->web_contents()->GetRenderViewHost();
host->Send(new AutofillMsg_SetNodeText(
@@ -179,6 +213,10 @@ bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
}
void AutofillExternalDelegate::ClearPreviewedForm() {
+ if (password_autofill_manager_.DidClearAutofillSelection(
+ autofill_query_field_))
+ return;
+
RenderViewHost* host =
tab_contents_wrapper_->web_contents()->GetRenderViewHost();
host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
@@ -191,6 +229,18 @@ void AutofillExternalDelegate::HideAutofillPopup() {
HideAutofillPopupInternal();
}
+void AutofillExternalDelegate::Reset() {
+ HideAutofillPopup();
+
+ password_autofill_manager_.Reset();
+}
+
+void AutofillExternalDelegate::AddPasswordFormMapping(
+ const webkit::forms::FormField& form,
+ const webkit::forms::PasswordFormFillData& fill_data) {
+ password_autofill_manager_.AddPasswordFormMapping(form, fill_data);
+}
+
void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
bool is_preview) {
RenderViewHost* host =