Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1071)

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 12208070: allow wallet items to appear in requestAutocomplete UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: relative patchset again Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 529118ab290145944415d73da8be20eaca37dcb0..9a24202948aabb97c4871fffb3b0a30784d9e63f 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/logging.h"
+#include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -21,6 +22,7 @@
#include "chrome/browser/autofill/wallet/wallet_service_url.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
+#include "chrome/browser/ui/autofill/data_model_wrapper.h"
#include "chrome/common/form_data.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_details.h"
@@ -383,24 +385,47 @@ string16 AutofillDialogControllerImpl::SuggestionTextForSection(
if (section == SECTION_EMAIL)
return model->GetLabelAt(model->checked_item());
+ scoped_ptr<DataModelWrapper> wrapper(CreateWrapper(section));
+ return wrapper->GetDisplayText();
+}
+
+DataModelWrapper* AutofillDialogControllerImpl::CreateWrapper(
+ DialogSection section) {
+ SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
+ std::string item_key = model->GetItemKeyAt(model->checked_item());
+ if (item_key.empty())
+ return NULL;
+
+ if (CanPayWithWallet()) {
+ int index;
+ if (!base::StringToInt(item_key, &index))
+ NOTREACHED();
Ilya Sherman 2013/02/12 22:50:34 Optional nit: IMO these two lines would be clearer
Evan Stade 2013/02/13 00:11:58 Done.
+
+ if (section == SECTION_CC)
+ return new WalletInstrumentWrapper(wallet_items_->instruments()[index]);
Ilya Sherman 2013/02/12 22:50:34 nit: Is it worth DCHECK'ing that the index is in b
Evan Stade 2013/02/13 00:11:58 IMO no, because it's already self-evident that we
+
+ return new WalletAddressWrapper(wallet_items_->addresses()[index]);
+ }
+
if (section == SECTION_CC) {
CreditCard* card = GetManager()->GetCreditCardByGUID(item_key);
- return card->TypeAndLastFourDigits();
+ DCHECK(card);
+ return new AutofillCreditCardWrapper(card);
+ }
+
+ // Calculate the variant by looking at how many items come from the same
+ // FormGroup. TODO(estade): add a test for this.
+ size_t variant = 0;
+ for (int i = model->checked_item() - 1; i >= 0; --i) {
+ if (model->GetItemKeyAt(i) == item_key)
+ variant++;
+ else
+ break;
}
- const std::string app_locale = AutofillCountry::ApplicationLocale();
AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key);
- string16 comma = ASCIIToUTF16(", ");
- string16 label = profile->GetInfo(NAME_FULL, app_locale) +
- comma + profile->GetInfo(ADDRESS_HOME_LINE1, app_locale);
- string16 address2 = profile->GetInfo(ADDRESS_HOME_LINE2, app_locale);
- if (!address2.empty())
- label += comma + address2;
- label += ASCIIToUTF16("\n") +
- profile->GetInfo(ADDRESS_HOME_CITY, app_locale) + comma +
- profile->GetInfo(ADDRESS_HOME_STATE, app_locale) + ASCIIToUTF16(" ") +
- profile->GetInfo(ADDRESS_HOME_ZIP, app_locale);
- return label;
+ DCHECK(profile);
+ return new AutofillDataModelWrapper(profile, variant);
}
gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection(
@@ -408,11 +433,11 @@ gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection(
if (section != SECTION_CC)
return gfx::Image();
- std::string item_key =
- suggested_cc_.GetItemKeyAt(suggested_cc_.checked_item());
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- CreditCard* card = GetManager()->GetCreditCardByGUID(item_key);
- return rb.GetImageNamed(card->IconResourceId());
+ scoped_ptr<DataModelWrapper> model(CreateWrapper(section));
+ if (!model.get())
+ return gfx::Image();
+
+ return model->GetIcon();
}
void AutofillDialogControllerImpl::EditClickedForSection(
@@ -427,14 +452,8 @@ void AutofillDialogControllerImpl::EditClickedForSection(
(*inputs)[0].autofilled_value = model->GetLabelAt(model->checked_item());
} else {
- std::string guid = model->GetItemKeyAt(model->checked_item());
- DCHECK(!guid.empty());
-
- FormGroup* form_group = section == SECTION_CC ?
- static_cast<FormGroup*>(GetManager()->GetCreditCardByGUID(guid)) :
- static_cast<FormGroup*>(GetManager()->GetProfileByGUID(guid));
- DCHECK(form_group);
- FillInputFromFormGroup(form_group, inputs);
+ scoped_ptr<DataModelWrapper> model(CreateWrapper(section));
+ model->FillInputs(inputs);
}
section_editing_state_[section] = true;
@@ -701,6 +720,8 @@ void AutofillDialogControllerImpl::OnDidGetWalletItems(
WalletRequestCompleted(true);
if (items_changed) {
+ GenerateSuggestionsModels();
+ view_->ModelChanged();
view_->UpdateAccountChooser();
view_->UpdateNotificationArea();
}
@@ -811,6 +832,8 @@ void AutofillDialogControllerImpl::WalletRequestCompleted(bool success) {
if (!success) {
had_wallet_error_ = true;
wallet_items_.reset();
+ GenerateSuggestionsModels();
+ view_->ModelChanged();
view_->UpdateAccountChooser();
view_->UpdateNotificationArea();
return;
@@ -826,35 +849,53 @@ void AutofillDialogControllerImpl::GenerateSuggestionsModels() {
suggested_email_.Reset();
suggested_shipping_.Reset();
- PersonalDataManager* manager = GetManager();
- const std::vector<CreditCard*>& cards = manager->credit_cards();
- for (size_t i = 0; i < cards.size(); ++i) {
- suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label());
- }
- // TODO(estade): real strings and i18n.
- suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card"));
-
- const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
- const std::string app_locale = AutofillCountry::ApplicationLocale();
- for (size_t i = 0; i < profiles.size(); ++i) {
- if (!IsCompleteProfile(*profiles[i]))
- continue;
-
- // Add all email addresses.
- std::vector<string16> values;
- profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values);
- for (size_t j = 0; j < values.size(); ++j) {
- if (!values[j].empty())
- suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]);
+ if (CanPayWithWallet()) {
+ if (wallet_items_.get()) {
+ // TODO(estade): seems we need to hardcode the email address.
+ // TODO(estade): CC and billing need to be combined into one section,
+ // and suggestions added here.
+ const std::vector<wallet::Address*>& addresses =
+ wallet_items_->addresses();
+ for (size_t i = 0; i < addresses.size(); ++i) {
+ suggested_billing_.AddKeyedItem(base::IntToString(i),
+ addresses[i]->DisplayName());
+ suggested_shipping_.AddKeyedItem(base::IntToString(i),
+ addresses[i]->DisplayName());
+ }
+ }
+ } else {
+ PersonalDataManager* manager = GetManager();
+ const std::vector<CreditCard*>& cards = manager->credit_cards();
+ for (size_t i = 0; i < cards.size(); ++i) {
+ suggested_cc_.AddKeyedItem(cards[i]->guid(), cards[i]->Label());
}
- // Don't add variants for addresses: the email variants are handled above,
- // name is part of credit card and we'll just ignore phone number variants.
- suggested_billing_.AddKeyedItem(profiles[i]->guid(), profiles[i]->Label());
- suggested_shipping_.AddKeyedItem(profiles[i]->guid(), profiles[i]->Label());
+ const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
+ const std::string app_locale = AutofillCountry::ApplicationLocale();
+ for (size_t i = 0; i < profiles.size(); ++i) {
+ if (!IsCompleteProfile(*profiles[i]))
+ continue;
+
+ // Add all email addresses.
+ std::vector<string16> values;
+ profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values);
+ for (size_t j = 0; j < values.size(); ++j) {
+ if (!values[j].empty())
+ suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]);
+ }
+
+ // Don't add variants for addresses: the email variants are handled above,
+ // name is part of credit card and we'll just ignore phone number
+ // variants.
+ suggested_billing_.AddKeyedItem(profiles[i]->guid(),
+ profiles[i]->Label());
+ suggested_shipping_.AddKeyedItem(profiles[i]->guid(),
+ profiles[i]->Label());
+ }
}
// TODO(estade): real strings and i18n.
+ suggested_cc_.AddKeyedItem("", ASCIIToUTF16("Enter new card"));
suggested_billing_.AddKeyedItem("", ASCIIToUTF16("Enter new billing"));
suggested_email_.AddKeyedItem("", ASCIIToUTF16("Enter new email"));
suggested_shipping_.AddKeyedItem("", ASCIIToUTF16("Enter new shipping"));
@@ -877,25 +918,13 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
DialogSection section,
const InputFieldComparator& compare) {
SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
- std::string guid = model->GetItemKeyAt(model->checked_item());
+ std::string item_key = model->GetItemKeyAt(model->checked_item());
PersonalDataManager* manager = GetManager();
Ilya Sherman 2013/02/12 22:50:34 nit: Move this into the else stmt?
Evan Stade 2013/02/13 00:11:58 Done.
- if (!guid.empty() && !section_editing_state_[section]) {
- FormGroup* form_group = section == SECTION_CC ?
- static_cast<FormGroup*>(manager->GetCreditCardByGUID(guid)) :
- static_cast<FormGroup*>(manager->GetProfileByGUID(guid));
- DCHECK(form_group);
-
- // Calculate the variant by looking at how many items come from the same
- // FormGroup. TODO(estade): add a test for this.
- size_t variant = 0;
- for (int i = model->checked_item() - 1; i >= 0; --i) {
- if (model->GetItemKeyAt(i) == guid)
- variant++;
- else
- break;
- }
-
- FillFormStructureForSection(*form_group, variant, section, compare);
+ if (!item_key.empty() && !section_editing_state_[section]) {
+ scoped_ptr<DataModelWrapper> model(CreateWrapper(section));
+ // Only fill in data that is associated with this section.
+ const DetailInputs& inputs = RequestedFieldsForSection(section);
+ model->FillFormStructure(inputs, compare, &form_structure_);
// CVC needs special-casing because the CreditCard class doesn't store
// or handle them.

Powered by Google App Engine
This is Rietveld 408576698