diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 53 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.h | 12 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager_unittest.cc | 56 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 35 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host_delegate.h | 5 |
6 files changed, 107 insertions, 61 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. |