| Index: trunk/src/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
|
| ===================================================================
|
| --- trunk/src/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc (revision 195318)
|
| +++ trunk/src/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc (working copy)
|
| @@ -80,10 +80,6 @@
|
| const int kCartMax = 1850;
|
| const char kCartCurrency[] = "USD";
|
|
|
| -const char kAddNewItemKey[] = "add-new-item";
|
| -const char kManageItemsKey[] = "manage-items";
|
| -const char kSameAsBillingKey[] = "same-as-billing";
|
| -
|
| // Returns true if |input| should be shown when |field| has been requested.
|
| bool InputTypeMatchesFieldType(const DetailInput& input,
|
| const AutofillField& field) {
|
| @@ -416,6 +412,11 @@
|
| return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT);
|
| }
|
|
|
| +string16 AutofillDialogControllerImpl::UseBillingForShippingText() const {
|
| + return l10n_util::GetStringUTF16(
|
| + IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING);
|
| +}
|
| +
|
| string16 AutofillDialogControllerImpl::CancelButtonText() const {
|
| return l10n_util::GetStringUTF16(IDS_CANCEL);
|
| }
|
| @@ -724,7 +725,6 @@
|
| SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection(
|
| DialogSection section) {
|
| return SuggestionState(SuggestionTextForSection(section),
|
| - SuggestionTextStyleForSection(section),
|
| SuggestionIconForSection(section),
|
| ExtraSuggestionTextForSection(section),
|
| ExtraSuggestionIconForSection(section),
|
| @@ -744,12 +744,7 @@
|
|
|
| SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
|
| std::string item_key = model->GetItemKeyForCheckedItem();
|
| - if (item_key == kSameAsBillingKey) {
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING);
|
| - }
|
| -
|
| - if (!IsASuggestionItemKey(item_key))
|
| + if (item_key.empty())
|
| return string16();
|
|
|
| if (section == SECTION_EMAIL)
|
| @@ -759,16 +754,6 @@
|
| return wrapper->GetDisplayText();
|
| }
|
|
|
| -gfx::Font::FontStyle
|
| - AutofillDialogControllerImpl::SuggestionTextStyleForSection(
|
| - DialogSection section) const {
|
| - const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
|
| - if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey)
|
| - return gfx::Font::ITALIC;
|
| -
|
| - return gfx::Font::NORMAL;
|
| -}
|
| -
|
| string16 AutofillDialogControllerImpl::RequiredActionTextForSection(
|
| DialogSection section) const {
|
| if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) {
|
| @@ -811,10 +796,11 @@
|
| }
|
| }
|
|
|
| + if (IsManuallyEditingSection(section))
|
| + return scoped_ptr<DataModelWrapper>();
|
| +
|
| SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
|
| std::string item_key = model->GetItemKeyForCheckedItem();
|
| - if (!IsASuggestionItemKey(item_key) || IsManuallyEditingSection(section))
|
| - return scoped_ptr<DataModelWrapper>();
|
|
|
| if (IsPayingWithWallet()) {
|
| int index;
|
| @@ -876,15 +862,7 @@
|
|
|
| bool AutofillDialogControllerImpl::EditEnabledForSection(
|
| DialogSection section) const {
|
| - if (SuggestionsMenuModelForSection(section)->GetItemKeyForCheckedItem() ==
|
| - kSameAsBillingKey) {
|
| - return false;
|
| - }
|
| -
|
| - if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV))
|
| - return false;
|
| -
|
| - return true;
|
| + return section != SECTION_CC_BILLING || !IsSubmitPausedOn(wallet::VERIFY_CVV);
|
| }
|
|
|
| void AutofillDialogControllerImpl::EditClickedForSection(
|
| @@ -1379,17 +1357,11 @@
|
| // SuggestionsMenuModelDelegate implementation.
|
|
|
| void AutofillDialogControllerImpl::SuggestionItemSelected(
|
| - SuggestionsMenuModel* model,
|
| - size_t index) {
|
| - if (model->GetItemKeyAt(index) == kManageItemsKey) {
|
| - // TODO(estade): show chrome://settings or a wallet URL.
|
| - return;
|
| - }
|
| + const SuggestionsMenuModel& model) {
|
| + const DialogSection section = SectionForSuggestionsMenuModel(model);
|
| + EditCancelledForSection(section);
|
|
|
| - model->SetCheckedIndex(index);
|
| - EditCancelledForSection(SectionForSuggestionsMenuModel(*model));
|
| -
|
| - LogSuggestionItemSelectedMetric(*model);
|
| + LogSuggestionItemSelectedMetric(model);
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -1706,10 +1678,6 @@
|
| suggested_shipping_.Reset();
|
| HidePopup();
|
|
|
| - suggested_shipping_.AddKeyedItem(
|
| - kSameAsBillingKey,
|
| - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING));
|
| -
|
| if (IsPayingWithWallet()) {
|
| if (!account_chooser_model_.active_wallet_account_name().empty()) {
|
| suggested_email_.AddKeyedItem(
|
| @@ -1725,7 +1693,6 @@
|
| base::IntToString(i),
|
| addresses[i]->DisplayName(),
|
| addresses[i]->DisplayNameDetail());
|
| -
|
| }
|
|
|
| if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
|
| @@ -1740,14 +1707,9 @@
|
| instruments[i]->CardIcon());
|
| }
|
|
|
| - // TODO(estade): this should have a URL sublabel.
|
| suggested_cc_billing_.AddKeyedItem(
|
| - kAddNewItemKey,
|
| + std::string(),
|
| l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS));
|
| - suggested_cc_billing_.AddKeyedItem(
|
| - kManageItemsKey,
|
| - l10n_util::GetStringUTF16(
|
| - IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS));
|
| }
|
| } else {
|
| PersonalDataManager* manager = GetManager();
|
| @@ -1784,42 +1746,20 @@
|
| }
|
|
|
| suggested_cc_.AddKeyedItem(
|
| - kAddNewItemKey,
|
| + std::string(),
|
| l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD));
|
| - suggested_cc_.AddKeyedItem(
|
| - kManageItemsKey,
|
| - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD));
|
| suggested_billing_.AddKeyedItem(
|
| - kAddNewItemKey,
|
| + std::string(),
|
| l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS));
|
| - suggested_billing_.AddKeyedItem(
|
| - kManageItemsKey,
|
| - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS));
|
| }
|
|
|
| suggested_email_.AddKeyedItem(
|
| - kAddNewItemKey,
|
| + std::string(),
|
| l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS));
|
| - if (!IsPayingWithWallet()) {
|
| - suggested_email_.AddKeyedItem(
|
| - kManageItemsKey,
|
| - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS));
|
| - }
|
| -
|
| suggested_shipping_.AddKeyedItem(
|
| - kAddNewItemKey,
|
| + std::string(),
|
| l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS));
|
| - suggested_shipping_.AddKeyedItem(
|
| - kManageItemsKey,
|
| - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS));
|
|
|
| - // Default shipping address is the first suggestion, if one exists. Otherwise
|
| - // it's the "Use shipping for billing" item.
|
| - const std::string& first_real_suggestion_item_key =
|
| - suggested_shipping_.GetItemKeyAt(1);
|
| - if (IsASuggestionItemKey(first_real_suggestion_item_key))
|
| - suggested_shipping_.SetCheckedItem(first_real_suggestion_item_key);
|
| -
|
| if (view_)
|
| view_->ModelChanged();
|
| }
|
| @@ -1920,6 +1860,14 @@
|
|
|
| SuggestionsMenuModel* AutofillDialogControllerImpl::
|
| SuggestionsMenuModelForSection(DialogSection section) {
|
| + const AutofillDialogControllerImpl* const_this =
|
| + static_cast<const AutofillDialogControllerImpl*>(this);
|
| + return const_cast<SuggestionsMenuModel*>(
|
| + const_this->SuggestionsMenuModelForSection(section));
|
| +}
|
| +
|
| +const SuggestionsMenuModel* AutofillDialogControllerImpl::
|
| + SuggestionsMenuModelForSection(DialogSection section) const {
|
| switch (section) {
|
| case SECTION_EMAIL:
|
| return &suggested_email_;
|
| @@ -1937,12 +1885,6 @@
|
| return NULL;
|
| }
|
|
|
| -const SuggestionsMenuModel* AutofillDialogControllerImpl::
|
| - SuggestionsMenuModelForSection(DialogSection section) const {
|
| - return const_cast<AutofillDialogControllerImpl*>(this)->
|
| - SuggestionsMenuModelForSection(section);
|
| -}
|
| -
|
| DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel(
|
| const SuggestionsMenuModel& model) {
|
| if (&model == &suggested_email_)
|
| @@ -2012,17 +1954,9 @@
|
| section_editing_state_.find(section);
|
| return (it != section_editing_state_.end() && it->second) ||
|
| SuggestionsMenuModelForSection(section)->
|
| - GetItemKeyForCheckedItem() == kAddNewItemKey;
|
| + GetItemKeyForCheckedItem().empty();
|
| }
|
|
|
| -bool AutofillDialogControllerImpl::IsASuggestionItemKey(
|
| - const std::string& key) {
|
| - return !key.empty() &&
|
| - key != kAddNewItemKey &&
|
| - key != kManageItemsKey &&
|
| - key != kSameAsBillingKey;
|
| -}
|
| -
|
| bool AutofillDialogControllerImpl::IsManuallyEditingAnySection() const {
|
| for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) {
|
| if (IsManuallyEditingSection(static_cast<DialogSection>(section)))
|
| @@ -2050,7 +1984,13 @@
|
| }
|
|
|
| bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
|
| - return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
|
| + // If the user is editing or inputting data, ask the view.
|
| + if (IsManuallyEditingSection(SECTION_SHIPPING))
|
| + return view_->UseBillingForShipping();
|
| +
|
| + // Otherwise, the checkbox should be hidden so its state is irrelevant.
|
| + // Always use the shipping suggestion model.
|
| + return false;
|
| }
|
|
|
| bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() {
|
| @@ -2085,7 +2025,7 @@
|
| if (!section_editing_state_[SECTION_CC_BILLING]) {
|
| SuggestionsMenuModel* billing =
|
| SuggestionsMenuModelForSection(SECTION_CC_BILLING);
|
| - if (IsASuggestionItemKey(billing->GetItemKeyForCheckedItem()) &&
|
| + if (!billing->GetItemKeyForCheckedItem().empty() &&
|
| billing->checked_item() <
|
| static_cast<int>(wallet_items_->instruments().size())) {
|
| const wallet::WalletItems::MaskedInstrument* active_instrument =
|
| @@ -2101,11 +2041,11 @@
|
| if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) {
|
| SuggestionsMenuModel* shipping =
|
| SuggestionsMenuModelForSection(SECTION_SHIPPING);
|
| - if (IsASuggestionItemKey(shipping->GetItemKeyForCheckedItem()) &&
|
| - shipping->checked_item() - 1 <
|
| + if (!shipping->GetItemKeyForCheckedItem().empty() &&
|
| + shipping->checked_item() <
|
| static_cast<int>(wallet_items_->addresses().size())) {
|
| active_address_id_ =
|
| - wallet_items_->addresses()[shipping->checked_item() - 1]->object_id();
|
| + wallet_items_->addresses()[shipping->checked_item()]->object_id();
|
| }
|
| }
|
|
|
| @@ -2262,17 +2202,13 @@
|
| DialogSection section = SectionForSuggestionsMenuModel(model);
|
|
|
| AutofillMetrics::DialogUiEvent dialog_ui_event;
|
| - if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) {
|
| + if (model.GetItemKeyForCheckedItem().empty()) {
|
| // Selected to add a new item.
|
| dialog_ui_event = DialogSectionToUiItemAddedEvent(section);
|
| - } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) {
|
| + } else {
|
| // Selected an existing item.
|
| DCHECK(!section_editing_state_[section]);
|
| dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section);
|
| - } else {
|
| - // TODO(estade): add logging for "Manage items" or "Use billing for
|
| - // shipping"?
|
| - return;
|
| }
|
|
|
| GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event);
|
| @@ -2281,11 +2217,11 @@
|
| AutofillMetrics::DialogInitialUserStateMetric
|
| AutofillDialogControllerImpl::GetInitialUserState() const {
|
| // Consider a user to be an Autofill user if the user has any credit cards
|
| - // or addresses saved. Check that the item count is greater than 2 because
|
| - // an "empty" menu still has the "add new" menu item and "manage" menu item.
|
| + // or addresses saved. Check that the item count is greater than 1 because
|
| + // an "empty" menu still has the "add new" menu item.
|
| const bool has_autofill_profiles =
|
| - suggested_cc_.GetItemCount() > 2 ||
|
| - suggested_billing_.GetItemCount() > 2;
|
| + suggested_cc_.GetItemCount() > 1 ||
|
| + suggested_billing_.GetItemCount() > 1;
|
|
|
| if (SignedInState() != SIGNED_IN) {
|
| // Not signed in.
|
|
|