summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 17:34:39 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 17:34:39 +0000
commit0a0554502c87277323e1438a6ab5b50acb9aab46 (patch)
tree885e2fdc2c97b972b4683469e49e4a0cdc7a5c43
parent308b6a1e93de0916f775c44818704717a00fcf70 (diff)
downloadchromium_src-0a0554502c87277323e1438a6ab5b50acb9aab46.zip
chromium_src-0a0554502c87277323e1438a6ab5b50acb9aab46.tar.gz
chromium_src-0a0554502c87277323e1438a6ab5b50acb9aab46.tar.bz2
AutoFill: Use unique IDs to identify the profile or credit card to fill.
BUG=none TEST=none Review URL: http://codereview.chromium.org/3019001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52699 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_manager.cc53
-rw-r--r--chrome/browser/autofill/autofill_manager.h12
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc56
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc35
-rw-r--r--chrome/browser/renderer_host/render_view_host.h7
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h5
-rw-r--r--chrome/common/render_messages_internal.h10
-rw-r--r--chrome/renderer/render_view.cc30
-rw-r--r--chrome/renderer/render_view.h18
-rw-r--r--chrome/renderer/render_view_unittest.cc2
-rw-r--r--webkit/glue/webpasswordautocompletelistener_impl.cc4
11 files changed, 142 insertions, 90 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index d3cceef..3d67d76 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -39,22 +39,27 @@ const int kAutoFillPhoneNumberSuffixCount = 4;
const string16::value_type kLabelSeparator[] = {';',' ',0};
-// Removes duplicate elements whilst preserving original order of |elements|.
-void RemoveDuplicateElements(std::vector<string16>* elements) {
+// Removes duplicate elements whilst preserving original order of |elements| and
+// |unique_ids|.
+void RemoveDuplicateElements(
+ std::vector<string16>* elements, std::vector<int>* unique_ids) {
std::vector<string16> copy;
- for (std::vector<string16>::iterator iter = elements->begin();
- iter != elements->end(); ++iter) {
+ for (size_t i = 0; i < elements->size(); ++i) {
+ const string16& element = (*elements)[i];
+
bool unique = true;
for (std::vector<string16>::const_iterator copy_iter = copy.begin();
copy_iter != copy.end(); ++copy_iter) {
- if (*iter == *copy_iter) {
+ if (element == *copy_iter) {
unique = false;
break;
}
}
if (unique)
- copy.push_back(*iter);
+ copy.push_back(element);
+ else
+ unique_ids->erase(unique_ids->begin() + i);
}
elements->assign(copy.begin(), copy.end());
@@ -178,16 +183,18 @@ bool AutoFillManager::GetAutoFillSuggestions(int query_id,
std::vector<string16> values;
std::vector<string16> labels;
+ std::vector<int> unique_ids;
AutoFillType type(autofill_field->type());
if (type.group() == AutoFillType::CREDIT_CARD)
- GetCreditCardSuggestions(form, field, type, &values, &labels);
+ GetCreditCardSuggestions(form, field, type, &values, &labels, &unique_ids);
else if (type.group() == AutoFillType::ADDRESS_BILLING)
- GetBillingProfileSuggestions(field, type, &values, &labels);
+ GetBillingProfileSuggestions(field, type, &values, &labels, &unique_ids);
else
- GetProfileSuggestions(form, field, type, &values, &labels);
+ GetProfileSuggestions(form, field, type, &values, &labels, &unique_ids);
DCHECK_EQ(values.size(), labels.size());
+ DCHECK_EQ(values.size(), unique_ids.size());
// No suggestions.
if (values.empty())
@@ -198,14 +205,14 @@ bool AutoFillManager::GetAutoFillSuggestions(int query_id,
// labels, as that information is redundant. In addition, remove duplicate
// values.
if (form_autofilled) {
- RemoveDuplicateElements(&values);
+ RemoveDuplicateElements(&values, &unique_ids);
labels.resize(values.size());
for (size_t i = 0; i < labels.size(); ++i)
labels[i] = string16();
}
- host->AutoFillSuggestionsReturned(query_id, values, labels);
+ host->AutoFillSuggestionsReturned(query_id, values, labels, unique_ids);
return true;
}
@@ -213,7 +220,8 @@ bool AutoFillManager::GetAutoFillSuggestions(int query_id,
bool AutoFillManager::FillAutoFillFormData(int query_id,
const FormData& form,
const string16& value,
- const string16& label) {
+ const string16& label,
+ int unique_id) {
if (!IsAutoFillEnabled())
return false;
@@ -249,7 +257,6 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
// |cc_digits| will contain the last four digits of a credit card number only
// if the form has billing fields.
- string16 profile_label = label;
string16 cc_digits;
// If the form has billing fields, |label| will contain at least one "; "
@@ -259,18 +266,16 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
// proper can contain this sequence of characters.
size_t index = label.find_last_of(kLabelSeparator);
if (index != string16::npos) {
- profile_label = label.substr(0, index - 1);
-
size_t cc_index = index + 1;
cc_digits = label.substr(cc_index);
}
}
- // Find the profile that matches the |profile_label|.
+ // Find the profile that matches the |unique_id|.
const AutoFillProfile* profile = NULL;
for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
iter != profiles.end(); ++iter) {
- if ((*iter)->Label() == profile_label) {
+ if ((*iter)->unique_id() == unique_id) {
profile = *iter;
}
}
@@ -443,7 +448,8 @@ void AutoFillManager::GetProfileSuggestions(FormStructure* form,
const FormField& field,
AutoFillType type,
std::vector<string16>* values,
- std::vector<string16>* labels) {
+ std::vector<string16>* labels,
+ std::vector<int>* unique_ids) {
const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles();
for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
iter != profiles.end(); ++iter) {
@@ -457,6 +463,7 @@ void AutoFillManager::GetProfileSuggestions(FormStructure* form,
if (!form->HasBillingFields()) {
values->push_back(profile_field_value);
labels->push_back(profile->Label());
+ unique_ids->push_back(profile->unique_id());
} else {
for (std::vector<CreditCard*>::const_iterator cc =
personal_data_->credit_cards().begin();
@@ -466,6 +473,7 @@ void AutoFillManager::GetProfileSuggestions(FormStructure* form,
string16 label = profile->Label() + kLabelSeparator +
(*cc)->LastFourDigits();
labels->push_back(label);
+ unique_ids->push_back(profile->unique_id());
}
}
}
@@ -476,7 +484,8 @@ void AutoFillManager::GetBillingProfileSuggestions(
const FormField& field,
AutoFillType type,
std::vector<string16>* values,
- std::vector<string16>* labels) {
+ std::vector<string16>* labels,
+ std::vector<int>* unique_ids) {
std::vector<CreditCard*> matching_creditcards;
std::vector<AutoFillProfile*> matching_profiles;
std::vector<string16> cc_values;
@@ -517,6 +526,7 @@ void AutoFillManager::GetBillingProfileSuggestions(
ASCIIToUTF16("; ") +
(*cc)->LastFourDigits();
labels->push_back(label);
+ unique_ids->push_back((*iter)->unique_id());
}
}
}
@@ -525,7 +535,8 @@ void AutoFillManager::GetCreditCardSuggestions(FormStructure* form,
const FormField& field,
AutoFillType type,
std::vector<string16>* values,
- std::vector<string16>* labels) {
+ std::vector<string16>* labels,
+ std::vector<int>* unique_ids) {
// Don't return CC suggestions for non-HTTPS pages.
if (!form->ConvertToFormData().origin.SchemeIs(chrome::kHttpsScheme))
return;
@@ -546,6 +557,7 @@ void AutoFillManager::GetCreditCardSuggestions(FormStructure* form,
if (!form->HasNonBillingFields()) {
values->push_back(creditcard_field_value);
labels->push_back(credit_card->Label());
+ unique_ids->push_back(credit_card->unique_id());
} else {
for (std::vector<AutoFillProfile*>::const_iterator iter =
personal_data_->profiles().begin();
@@ -556,6 +568,7 @@ void AutoFillManager::GetCreditCardSuggestions(FormStructure* form,
ASCIIToUTF16("; ") +
credit_card->LastFourDigits();
labels->push_back(label);
+ unique_ids->push_back((*iter)->unique_id());
}
}
}
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index c46d625..e39ba5d 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -53,7 +53,8 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
virtual bool FillAutoFillFormData(int query_id,
const webkit_glue::FormData& form,
const string16& value,
- const string16& label);
+ const string16& label,
+ int unique_id);
virtual void ShowAutoFillDialog();
// Called by the AutoFillCCInfoBarDelegate when the user interacts with the
@@ -103,14 +104,16 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
const webkit_glue::FormField& field,
AutoFillType type,
std::vector<string16>* values,
- std::vector<string16>* labels);
+ std::vector<string16>* labels,
+ std::vector<int>* unique_ids);
// Same as GetProfileSuggestions, but the list of stored profiles is limited
// to the linked billing addresses from the list of credit cards.
void GetBillingProfileSuggestions(const webkit_glue::FormField& field,
AutoFillType type,
std::vector<string16>* values,
- std::vector<string16>* labels);
+ std::vector<string16>* labels,
+ std::vector<int>* unique_ids);
// Returns a list of values from the stored credit cards that match |type| and
// the value of |field| and returns the labels of the matching credit cards.
@@ -118,7 +121,8 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
const webkit_glue::FormField& field,
AutoFillType type,
std::vector<string16>* values,
- std::vector<string16>* labels);
+ std::vector<string16>* labels,
+ std::vector<int>* unique_ids);
// Set |field| argument's value based on |type| and contents of the
// |credit_card|. The |type| field is expected to have main group type of
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 2acfc92..85e4b49 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -30,6 +30,11 @@ using webkit_glue::FormData;
namespace {
+typedef Tuple4<int,
+ std::vector<string16>,
+ std::vector<string16>,
+ std::vector<int> > AutoFillParam;
+
class TestPersonalDataManager : public PersonalDataManager {
public:
TestPersonalDataManager() {
@@ -61,6 +66,7 @@ class TestPersonalDataManager : public PersonalDataManager {
"3734 Elvis Presley Blvd.", "Apt. 10",
"Memphis", "Tennessee", "38116", "USA",
"12345678901", "");
+ profile->set_unique_id(1);
profiles->push_back(profile);
profile = new AutoFillProfile;
autofill_unittest::SetProfileInfo(profile, "Work", "Charles", "Hardin",
@@ -68,10 +74,12 @@ class TestPersonalDataManager : public PersonalDataManager {
"123 Apple St.", "unit 6", "Lubbock",
"Texas", "79401", "USA", "23456789012",
"");
+ profile->set_unique_id(2);
profiles->push_back(profile);
profile = new AutoFillProfile;
autofill_unittest::SetProfileInfo(profile, "Empty", "", "", "", "", "", "",
"", "", "", "", "", "", "");
+ profile->set_unique_id(3);
profiles->push_back(profile);
}
@@ -80,15 +88,18 @@ class TestPersonalDataManager : public PersonalDataManager {
autofill_unittest::SetCreditCardInfo(credit_card, "First", "Elvis Presley",
"Visa", "1234567890123456", "04",
"2012", "Home");
+ credit_card->set_unique_id(4);
credit_cards->push_back(credit_card);
credit_card = new CreditCard;
autofill_unittest::SetCreditCardInfo(credit_card, "Second", "Buddy Holly",
"Mastercard", "0987654321098765", "10",
"2014", "");
+ credit_card->set_unique_id(5);
credit_cards->push_back(credit_card);
credit_card = new CreditCard;
autofill_unittest::SetCreditCardInfo(credit_card, "Empty", "", "", "", "",
"", "");
+ credit_card->set_unique_id(6);
credit_cards->push_back(credit_card);
}
@@ -234,7 +245,8 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
process()->sink().GetFirstMessageMatching(kMsgID);
if (!message)
return false;
- Tuple3<int, std::vector<string16>, std::vector<string16> > autofill_param;
+
+ AutoFillParam autofill_param;
ViewMsg_AutoFillSuggestionsReturned::Read(message, &autofill_param);
if (page_id)
*page_id = autofill_param.a;
@@ -714,7 +726,8 @@ TEST_F(AutoFillManagerTest, FillCreditCardForm) {
autofill_manager_->FillAutoFillFormData(kPageID,
form,
string16(),
- ASCIIToUTF16("Home; 3456")));
+ ASCIIToUTF16("Home; 3456"),
+ 1));
int page_id = 0;
FormData results;
@@ -782,6 +795,7 @@ TEST_F(AutoFillManagerTest, FillNonBillingFormSemicolon) {
"916 16th St.", "Apt. 6", "Lubbock",
"Texas", "79401", "USA",
"12345678901", "");
+ profile->set_unique_id(6);
autofill_manager_->AddProfile(profile);
FormData form;
@@ -799,7 +813,8 @@ TEST_F(AutoFillManagerTest, FillNonBillingFormSemicolon) {
autofill_manager_->FillAutoFillFormData(kPageID,
form,
string16(),
- ASCIIToUTF16("Home; 8765")));
+ ASCIIToUTF16("Home; 8765"),
+ 6));
int page_id = 0;
FormData results;
@@ -854,6 +869,7 @@ TEST_F(AutoFillManagerTest, FillBillFormSemicolon) {
"916 16th St.", "Apt. 6", "Lubbock",
"Texas", "79401", "USA",
"12345678901", "");
+ profile->set_unique_id(6);
autofill_manager_->AddProfile(profile);
FormData form;
@@ -868,7 +884,7 @@ TEST_F(AutoFillManagerTest, FillBillFormSemicolon) {
// an IPC message back to the renderer.
const int kPageID = 1;
EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
- kPageID, form, string16(), ASCIIToUTF16("Home; 8765; 3456")));
+ kPageID, form, string16(), ASCIIToUTF16("Home; 8765; 3456"), 6));
int page_id = 0;
FormData results;
@@ -928,7 +944,7 @@ TEST_F(AutoFillManagerTest, FillBillFormSemicolon) {
EXPECT_TRUE(field.StrictlyEqualsHack(results.fields[14]));
}
-TEST_F(AutoFillManagerTest, FillPhoneNumberTest) {
+TEST_F(AutoFillManagerTest, FillPhoneNumber) {
FormData form;
form.name = ASCIIToUTF16("MyPhoneForm");
@@ -977,10 +993,12 @@ TEST_F(AutoFillManagerTest, FillPhoneNumberTest) {
// an IPC message back to the renderer.
int page_id = 100 - i;
process()->sink().ClearMessages();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(page_id,
- form,
- ASCIIToUTF16(test_data),
- ASCIIToUTF16("Work")));
+ EXPECT_TRUE(
+ autofill_manager_->FillAutoFillFormData(page_id,
+ form,
+ ASCIIToUTF16(test_data),
+ ASCIIToUTF16("Work"),
+ work_profile->unique_id()));
page_id = 0;
FormData results;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
@@ -1034,11 +1052,11 @@ TEST_F(AutoFillManagerTest, FormChangesRemoveField) {
// The page ID sent to the AutoFillManager from the RenderView, used to send
// an IPC message back to the renderer.
const int kPageID = 1;
- EXPECT_TRUE(
- autofill_manager_->FillAutoFillFormData(kPageID,
- form,
- ASCIIToUTF16("Elvis"),
- ASCIIToUTF16("Home")));
+ EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(kPageID,
+ form,
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Home"),
+ 1));
int page_id = 0;
FormData results;
@@ -1099,11 +1117,11 @@ TEST_F(AutoFillManagerTest, FormChangesAddField) {
// The page ID sent to the AutoFillManager from the RenderView, used to send
// an IPC message back to the renderer.
const int kPageID = 1;
- EXPECT_TRUE(
- autofill_manager_->FillAutoFillFormData(kPageID,
- form,
- ASCIIToUTF16("Elvis"),
- ASCIIToUTF16("Home")));
+ EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(kPageID,
+ form,
+ ASCIIToUTF16("Elvis"),
+ ASCIIToUTF16("Home"),
+ 1));
int page_id = 0;
FormData results;
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index cf890e4..15fd450 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1601,7 +1601,8 @@ void RenderViewHost::OnQueryFormFieldAutoFill(
// No suggestions provided, so supply an empty vector as the results.
AutoFillSuggestionsReturned(query_id,
std::vector<string16>(),
- std::vector<string16>());
+ std::vector<string16>(),
+ std::vector<int>());
}
RenderViewHostDelegate::Autocomplete* autocomplete_delegate =
@@ -1635,46 +1636,52 @@ void RenderViewHost::OnShowAutoFillDialog() {
void RenderViewHost::OnFillAutoFillFormData(int query_id,
const FormData& form,
const string16& name,
- const string16& label) {
+ const string16& label,
+ int unique_id) {
RenderViewHostDelegate::AutoFill* autofill_delegate =
delegate_->GetAutoFillDelegate();
if (!autofill_delegate)
return;
- autofill_delegate->FillAutoFillFormData(query_id, form, name, label);
+ autofill_delegate->FillAutoFillFormData(
+ query_id, form, name, label, unique_id);
}
void RenderViewHost::AutoFillSuggestionsReturned(
int query_id,
const std::vector<string16>& names,
- const std::vector<string16>& labels) {
+ const std::vector<string16>& labels,
+ const std::vector<int>& unique_ids) {
autofill_query_id_ = query_id;
- autofill_values_.clear();
- autofill_values_.insert(autofill_values_.begin(), names.begin(), names.end());
- autofill_labels_.clear();
- autofill_labels_.insert(
- autofill_labels_.begin(), labels.begin(), labels.end());
+ autofill_values_.assign(names.begin(), names.end());
+ autofill_labels_.assign(labels.begin(), labels.end());
+ autofill_unique_ids_.assign(unique_ids.begin(), unique_ids.end());
}
void RenderViewHost::AutocompleteSuggestionsReturned(
int query_id, const std::vector<string16>& suggestions) {
- // When query ids match we are responding to an AutoFill and Autocomplete
+ // When query IDs match we are responding to an AutoFill and Autocomplete
// combined query response.
- // Otherwise Autocomplete is cancelling, so we only send suggestions (usually
+ // Otherwise Autocomplete is canceling, so we only send suggestions (usually
// an empty list).
if (autofill_query_id_ != query_id) {
- // Autocomplete is cancelling.
+ // Autocomplete is canceling.
autofill_values_.clear();
autofill_labels_.clear();
+ autofill_unique_ids_.clear();
}
// Combine AutoFill and Autocomplete values into values and labels.
for (size_t i = 0; i < suggestions.size(); ++i) {
autofill_values_.push_back(suggestions[i]);
autofill_labels_.push_back(string16());
+ autofill_unique_ids_.push_back(0); // 0 means no profile.
}
- Send(new ViewMsg_AutoFillSuggestionsReturned(
- routing_id(), query_id, autofill_values_, autofill_labels_));
+ Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(),
+ query_id,
+ autofill_values_,
+ autofill_labels_,
+ autofill_unique_ids_));
}
void RenderViewHost::AutoFillFormDataFilled(int query_id,
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index aa66275..2021cfb 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -388,7 +388,8 @@ class RenderViewHost : public RenderWidgetHost {
void AutoFillSuggestionsReturned(
int query_id,
const std::vector<string16>& values,
- const std::vector<string16>& labels);
+ const std::vector<string16>& labels,
+ const std::vector<int>& unique_ids);
// Called by the AutocompleteHistoryManager when the list of suggestions is
// ready.
@@ -612,7 +613,8 @@ class RenderViewHost : public RenderWidgetHost {
void OnFillAutoFillFormData(int query_id,
const webkit_glue::FormData& form,
const string16& value,
- const string16& label);
+ const string16& label,
+ int unique_id);
void OnShowDesktopNotification(
const ViewHostMsg_ShowNotification_Params& params);
@@ -721,6 +723,7 @@ class RenderViewHost : public RenderWidgetHost {
int autofill_query_id_;
std::vector<string16> autofill_values_;
std::vector<string16> autofill_labels_;
+ std::vector<int> autofill_unique_ids_;
DISALLOW_COPY_AND_ASSIGN(RenderViewHost);
};
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 9050cbd..eec96e8 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -468,12 +468,13 @@ class RenderViewHostDelegate {
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
+ // matches the |value|, |unique_id| key. Returns true to indicate that
// RenderViewHost::AutoFillFormDataFilled has been called.
virtual bool FillAutoFillFormData(int query_id,
const webkit_glue::FormData& form,
const string16& value,
- const string16& label) = 0;
+ const string16& label,
+ int unique_id) = 0;
// Called when the user selects the 'AutoFill Options...' suggestions in the
// AutoFill popup.
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 7b66469..680fcc9 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -638,10 +638,11 @@ IPC_BEGIN_MESSAGES(View)
// Reply to the ViewHostMsg_QueryFormFieldAutoFill message with the
// AutoFill suggestions.
- IPC_MESSAGE_ROUTED3(ViewMsg_AutoFillSuggestionsReturned,
+ IPC_MESSAGE_ROUTED4(ViewMsg_AutoFillSuggestionsReturned,
int /* id of the request message */,
std::vector<string16> /* names */,
- std::vector<string16> /* labels */)
+ std::vector<string16> /* labels */,
+ std::vector<int> /* unique_ids */)
// Reply to the ViewHostMsg_FillAutoFillFormData message with the
// AutoFill form data.
@@ -1869,11 +1870,12 @@ IPC_BEGIN_MESSAGES(ViewHost)
// Instructs the browser to fill in the values for a form using AutoFill
// profile data.
- IPC_MESSAGE_ROUTED4(ViewHostMsg_FillAutoFillFormData,
+ IPC_MESSAGE_ROUTED5(ViewHostMsg_FillAutoFillFormData,
int /* id of this message */,
webkit_glue::FormData /* the form */,
string16 /* profile name */,
- string16 /* profile label */)
+ string16 /* profile label */,
+ int /* profile unique ID */)
// Instructs the browser to remove the specified Autocomplete entry from the
// database.
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 1931d09..c725aa4 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1513,10 +1513,12 @@ void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
void RenderView::OnAutoFillSuggestionsReturned(
int query_id,
const std::vector<string16>& values,
- const std::vector<string16>& labels) {
+ const std::vector<string16>& labels,
+ const std::vector<int>& unique_ids) {
if (webview() && query_id == autofill_query_id_) {
std::vector<string16> v(values);
std::vector<string16> l(labels);
+ std::vector<int> ids(unique_ids);
int separator_index = -1;
// The form has been auto-filled, so give the user the chance to clear the
@@ -1524,6 +1526,7 @@ void RenderView::OnAutoFillSuggestionsReturned(
if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) {
v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
l.push_back(string16());
+ ids.push_back(0);
suggestions_clear_index_ = v.size() - 1;
separator_index = values.size();
}
@@ -1540,6 +1543,7 @@ void RenderView::OnAutoFillSuggestionsReturned(
// Append the 'AutoFill Options...' menu item.
v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS));
l.push_back(string16());
+ ids.push_back(0);
suggestions_options_index_ = v.size() - 1;
separator_index = values.size();
}
@@ -1547,7 +1551,7 @@ void RenderView::OnAutoFillSuggestionsReturned(
// Send to WebKit for display.
if (!v.empty())
webview()->applyAutoFillSuggestions(
- autofill_query_node_, v, l, separator_index);
+ autofill_query_node_, v, l, ids, separator_index);
}
}
@@ -2150,14 +2154,8 @@ void RenderView::removeAutofillSuggestions(const WebString& name,
void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
const WebKit::WebString& value,
- const WebKit::WebString& label) {
- // DEPRECATED
- didAcceptAutoFillSuggestion(node, value, label, -1);
-}
-
-void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
- const WebKit::WebString& value,
const WebKit::WebString& label,
+ int unique_id,
unsigned index) {
if (suggestions_options_index_ != -1 &&
index == static_cast<unsigned>(suggestions_options_index_)) {
@@ -2169,8 +2167,8 @@ void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
// The form has been auto-filled, so give the user the chance to clear the
// form.
form_manager_.ClearFormWithNode(node);
- } else if (form_manager_.FormWithNodeIsAutoFilled(node) || label.isEmpty()) {
- // User selected an unlabeled menu item, so we fill directly.
+ } else if (form_manager_.FormWithNodeIsAutoFilled(node) || !unique_id) {
+ // User selected an Autocomplete entry, so we fill directly.
WebInputElement element = node.toConst<WebInputElement>();
element.setValue(value);
@@ -2180,7 +2178,7 @@ void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
}
} else {
// Fill the values for the whole form.
- QueryAutoFillFormData(node, value, label, AUTOFILL_FILL);
+ QueryAutoFillFormData(node, value, label, unique_id, AUTOFILL_FILL);
}
suggestions_clear_index_ = -1;
@@ -2189,9 +2187,10 @@ void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
const WebKit::WebString& value,
- const WebKit::WebString& label) {
+ const WebKit::WebString& label,
+ int unique_id) {
didClearAutoFillSelection(node);
- QueryAutoFillFormData(node, value, label, AUTOFILL_PREVIEW);
+ QueryAutoFillFormData(node, value, label, unique_id, AUTOFILL_PREVIEW);
}
void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
@@ -5306,6 +5305,7 @@ bool RenderView::IsNonLocalTopLevelNavigation(
void RenderView::QueryAutoFillFormData(const WebKit::WebNode& node,
const WebKit::WebString& value,
const WebKit::WebString& label,
+ int unique_id,
AutoFillAction action) {
static int query_counter = 0;
autofill_query_id_ = query_counter++;
@@ -5318,5 +5318,5 @@ void RenderView::QueryAutoFillFormData(const WebKit::WebNode& node,
autofill_action_ = action;
Send(new ViewHostMsg_FillAutoFillFormData(
- routing_id_, autofill_query_id_, form, value, label));
+ routing_id_, autofill_query_id_, form, value, label, unique_id));
}
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index f81d847..5320c52 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -394,17 +394,15 @@ class RenderView : public RenderWidget,
const WebKit::WebString& value);
virtual void removeAutofillSuggestions(const WebKit::WebString& name,
const WebKit::WebString& value);
- // DEPRECATED.
- virtual void didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
- const WebKit::WebString& value,
- const WebKit::WebString& label);
virtual void didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
const WebKit::WebString& value,
const WebKit::WebString& label,
+ int unique_id,
unsigned index);
virtual void didSelectAutoFillSuggestion(const WebKit::WebNode& node,
const WebKit::WebString& value,
- const WebKit::WebString& label);
+ const WebKit::WebString& label,
+ int unique_id);
virtual void didClearAutoFillSelection(const WebKit::WebNode& node);
virtual void didAcceptAutocompleteSuggestion(
const WebKit::WebInputElement& element);
@@ -711,7 +709,8 @@ class RenderView : public RenderWidget,
void OnAutoFillSuggestionsReturned(
int query_id,
const std::vector<string16>& values,
- const std::vector<string16>& labels);
+ const std::vector<string16>& labels,
+ const std::vector<int>& unique_ids);
void OnCancelDownload(int32 download_id);
void OnClearFocusedNode();
void OnClosePage(const ViewMsg_ClosePage_Params& params);
@@ -930,12 +929,13 @@ class RenderView : public RenderWidget,
void Print(WebKit::WebFrame* frame, bool script_initiated);
// Queries the AutoFillManager for form data for the form containing |node|.
- // |value| is the current text in the field, and |label| is the selected
- // profile label. |action| specifies whether to Fill or Preview the values
- // returned from the AutoFillManager.
+ // |value| is the current text in the field, and |unique_id| is the selected
+ // profile's unique ID. |action| specifies whether to Fill or Preview the
+ // values returned from the AutoFillManager.
void QueryAutoFillFormData(const WebKit::WebNode& node,
const WebKit::WebString& value,
const WebKit::WebString& label,
+ int unique_id,
AutoFillAction action);
// Scans the given frame for forms and sends them up to the browser.
diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc
index 9b9640e..47d99f1 100644
--- a/chrome/renderer/render_view_unittest.cc
+++ b/chrome/renderer/render_view_unittest.cc
@@ -994,6 +994,7 @@ TEST_F(RenderViewTest, SendForms) {
view_->didAcceptAutoFillSuggestion(firstname,
WebKit::WebString::fromUTF8("Johnny"),
WebKit::WebString::fromUTF8("Home"),
+ 1,
-1);
ProcessPendingMessages();
@@ -1073,6 +1074,7 @@ TEST_F(RenderViewTest, FillFormElement) {
view_->didAcceptAutoFillSuggestion(firstname,
WebKit::WebString::fromUTF8("David"),
WebKit::WebString(),
+ 0,
0);
ProcessPendingMessages();
diff --git a/webkit/glue/webpasswordautocompletelistener_impl.cc b/webkit/glue/webpasswordautocompletelistener_impl.cc
index a1ea755..5caeae1 100644
--- a/webkit/glue/webpasswordautocompletelistener_impl.cc
+++ b/webkit/glue/webpasswordautocompletelistener_impl.cc
@@ -59,13 +59,15 @@ void WebInputElementDelegate::RefreshAutofillPopup(
if (webview) {
std::vector<string16> names;
std::vector<string16> labels;
+ std::vector<int> unique_ids;
for (size_t i = 0; i < suggestions.size(); ++i) {
names.push_back(suggestions[i]);
labels.push_back(string16());
+ unique_ids.push_back(0);
}
- webview->applyAutoFillSuggestions(element_, names, labels, -1);
+ webview->applyAutoFillSuggestions(element_, names, labels, unique_ids, -1);
}
}