summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-24 23:23:16 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-24 23:23:16 +0000
commit25bacf3dd25367f130baa92895a0c01c3d1d7e13 (patch)
tree3cd2ce246d1254ae666dcc46992cb04206e6cb1f /chrome
parent0452c6e3ee2dcaa67b976398e248a97c59deeede (diff)
downloadchromium_src-25bacf3dd25367f130baa92895a0c01c3d1d7e13.zip
chromium_src-25bacf3dd25367f130baa92895a0c01c3d1d7e13.tar.gz
chromium_src-25bacf3dd25367f130baa92895a0c01c3d1d7e13.tar.bz2
AutoFill: Don't show labels in the suggestions popup when the user is editing a
field in an auto-filled form. BUG=47437 TEST=AutoFillManagerTest.GetFieldSuggestionsFormIsAutoFilled Review URL: http://codereview.chromium.org/2861025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50782 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/autofill_manager.cc9
-rw-r--r--chrome/browser/autofill/autofill_manager.h1
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc45
-rw-r--r--chrome/browser/chromeos/login/account_creation_view.cc2
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc5
-rw-r--r--chrome/browser/renderer_host/render_view_host.h1
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h7
-rw-r--r--chrome/common/render_messages_internal.h3
-rw-r--r--chrome/renderer/render_view.cc3
9 files changed, 62 insertions, 14 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 15b5ba8..4d489ef 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -121,6 +121,7 @@ void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) {
}
bool AutoFillManager::GetAutoFillSuggestions(int query_id,
+ bool form_autofilled,
const FormField& field) {
if (!IsAutoFillEnabled())
return false;
@@ -180,6 +181,14 @@ bool AutoFillManager::GetAutoFillSuggestions(int query_id,
if (values.empty())
return false;
+ // If the form is auto-filled and the renderer is querying for suggestions,
+ // then the user is editing the value of a field. In this case, we don't
+ // want to display the labels, as that information is redundant.
+ if (form_autofilled) {
+ for (size_t i = 0; i < labels.size(); ++i)
+ labels[i] = string16();
+ }
+
host->AutoFillSuggestionsReturned(query_id, values, labels);
return true;
}
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index 46ee0f5..f45f7ed 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -49,6 +49,7 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
virtual void FormsSeen(
const std::vector<webkit_glue::FormData>& forms);
virtual bool GetAutoFillSuggestions(int query_id,
+ bool form_autofilled,
const webkit_glue::FormField& field);
virtual bool FillAutoFillFormData(int query_id,
const webkit_glue::FormData& form,
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 2435b93..700966d 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -215,7 +215,7 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
Profile* profile() { return contents()->profile(); }
- bool GetAutoFillSuggestionsMessage(int *page_id,
+ bool GetAutoFillSuggestionsMessage(int* page_id,
std::vector<string16>* values,
std::vector<string16>* labels) {
const uint32 kMsgID = ViewMsg_AutoFillSuggestionsReturned::ID;
@@ -275,7 +275,7 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) {
webkit_glue::FormField field;
CreateTestFormField("First Name", "firstname", "", "text", &field);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -306,7 +306,7 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMatchCharacter) {
webkit_glue::FormField field;
CreateTestFormField("First Name", "firstname", "E", "text", &field);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -335,7 +335,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
webkit_glue::FormField field;
CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -374,7 +374,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
webkit_glue::FormField field;
CreateTestFormField("Card Number", "cardnumber", "1", "text", &field);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -407,7 +407,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
webkit_glue::FormField field;
CreateTestFormField("Name on Card", "nameoncard", "", "text", &field);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -448,7 +448,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsSemicolon) {
webkit_glue::FormField field;
CreateTestFormField("Name on Card", "nameoncard", "", "text", &field);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field));
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -476,6 +476,37 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsSemicolon) {
EXPECT_EQ(ASCIIToUTF16("Home; 8765; 8765"), labels[7]);
}
+TEST_F(AutoFillManagerTest, GetFieldSuggestionsFormIsAutoFilled) {
+ FormData form;
+ CreateTestFormData(&form);
+
+ // Set up our FormStructures.
+ std::vector<FormData> forms;
+ forms.push_back(form);
+ autofill_manager_->FormsSeen(forms);
+
+ // The page ID sent to the AutoFillManager from the RenderView, used to send
+ // an IPC message back to the renderer.
+ const int kPageID = 1;
+
+ webkit_glue::FormField field;
+ CreateTestFormField("First Name", "firstname", "", "text", &field);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field));
+
+ // Test that we sent the right message to the renderer.
+ int page_id = 0;
+ std::vector<string16> values;
+ std::vector<string16> labels;
+ EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels));
+ EXPECT_EQ(kPageID, page_id);
+ ASSERT_EQ(2U, values.size());
+ EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
+ EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
+ ASSERT_EQ(2U, labels.size());
+ EXPECT_EQ(string16(), labels[0]);
+ EXPECT_EQ(string16(), labels[1]);
+}
+
TEST_F(AutoFillManagerTest, FillCreditCardForm) {
FormData form;
CreateTestFormDataBilling(&form);
diff --git a/chrome/browser/chromeos/login/account_creation_view.cc b/chrome/browser/chromeos/login/account_creation_view.cc
index d03ef75..591a1fc 100644
--- a/chrome/browser/chromeos/login/account_creation_view.cc
+++ b/chrome/browser/chromeos/login/account_creation_view.cc
@@ -55,7 +55,7 @@ class AccountCreationTabContents : public WizardWebPageViewTabContents,
}
virtual bool GetAutoFillSuggestions(
- int query_id, const webkit_glue::FormField& field) {
+ int query_id, bool form_autofilled, const webkit_glue::FormField& field) {
return false;
}
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index fb0788b..8d069de 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1587,13 +1587,14 @@ void RenderViewHost::OnMsgShouldCloseACK(bool proceed) {
}
void RenderViewHost::OnQueryFormFieldAutoFill(
- int query_id, const webkit_glue::FormField& field) {
+ int query_id, bool form_autofilled, const webkit_glue::FormField& field) {
RenderViewHostDelegate::AutoFill* autofill_delegate =
delegate_->GetAutoFillDelegate();
// If the AutoFill delegate has results to return, we don't need any results
// from the Autocomplete delegate.
if (autofill_delegate &&
- autofill_delegate->GetAutoFillSuggestions(query_id, field)) {
+ autofill_delegate->GetAutoFillSuggestions(
+ query_id, form_autofilled, field)) {
return;
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 8619094..1cea762 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -604,6 +604,7 @@ class RenderViewHost : public RenderWidgetHost {
const webkit_glue::WebApplicationInfo& info);
void OnMsgShouldCloseACK(bool proceed);
void OnQueryFormFieldAutoFill(int request_id,
+ bool form_autofilled,
const webkit_glue::FormField& field);
void OnRemoveAutocompleteEntry(const string16& field_name,
const string16& value);
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index e0deb4a..cf0c9d9 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -426,10 +426,13 @@ class RenderViewHostDelegate {
// Called to retrieve a list of AutoFill suggestions from the web database
// given the name of the field and what the user has already typed in the
- // field. Returns true to indicate that
+ // field. |form_autofilled| is true if the form containing |field| has any
+ // auto-filled fields. Returns true to indicate that
// RenderViewHost::AutoFillSuggestionsReturned has been called.
virtual bool GetAutoFillSuggestions(
- int query_id, const webkit_glue::FormField& field) = 0;
+ int query_id,
+ bool form_autofilled,
+ const webkit_glue::FormField& field) = 0;
// Called to fill the FormData object with AutoFill profile information that
// matches the |value|, |label| key. Returns true to indicate that
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 53c33a9..0ba750a 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -1825,8 +1825,9 @@ IPC_BEGIN_MESSAGES(ViewHost)
gfx::Rect /* Out: Window location */)
// Queries the browser for AutoFill suggestions for a form input field.
- IPC_MESSAGE_ROUTED2(ViewHostMsg_QueryFormFieldAutoFill,
+ IPC_MESSAGE_ROUTED3(ViewHostMsg_QueryFormFieldAutoFill,
int /* id of this message */,
+ bool /* form_autofilled */,
webkit_glue::FormField /* the form field */)
// Instructs the browser to fill in the values for a form using AutoFill
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 6b95e29..be49bbf 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -2082,8 +2082,9 @@ void RenderView::queryAutofillSuggestions(const WebNode& node,
// data in FormManager.
field.set_label(FormManager::LabelForElement(element));
+ bool form_autofilled = form_manager_.FormWithNodeIsAutoFilled(node);
Send(new ViewHostMsg_QueryFormFieldAutoFill(
- routing_id_, autofill_query_id_, field));
+ routing_id_, autofill_query_id_, form_autofilled, field));
}
void RenderView::removeAutofillSuggestions(const WebString& name,