OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 !wallet_items_->instruments().empty() && | 835 !wallet_items_->instruments().empty() && |
836 !wallet_items_->addresses().empty(); | 836 !wallet_items_->addresses().empty(); |
837 } | 837 } |
838 | 838 |
839 bool AutofillDialogControllerImpl::IsSubmitPausedOn( | 839 bool AutofillDialogControllerImpl::IsSubmitPausedOn( |
840 wallet::RequiredAction required_action) const { | 840 wallet::RequiredAction required_action) const { |
841 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); | 841 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); |
842 } | 842 } |
843 | 843 |
844 void AutofillDialogControllerImpl::GetWalletItems() { | 844 void AutofillDialogControllerImpl::GetWalletItems() { |
845 DCHECK(previously_selected_instrument_id_.empty()); | |
846 DCHECK(previously_selected_shipping_address_id_.empty()); | |
847 ScopedViewUpdates updates(view_.get()); | 845 ScopedViewUpdates updates(view_.get()); |
848 | 846 |
847 previously_selected_instrument_id_.clear(); | |
848 previously_selected_shipping_address_id_.clear(); | |
849 if (wallet_items_) { | 849 if (wallet_items_) { |
850 if (ActiveInstrument()) | 850 previous_default_instrument_id_ = wallet_items_->default_instrument_id(); |
851 previously_selected_instrument_id_ = ActiveInstrument()->object_id(); | 851 previous_default_shipping_address_id_ = wallet_items_->default_address_id(); |
852 | |
853 const wallet::WalletItems::MaskedInstrument* instrument = | |
854 ActiveInstrument(); | |
855 if (instrument) | |
856 previously_selected_instrument_id_ = instrument->object_id(); | |
852 | 857 |
853 const wallet::Address* address = ActiveShippingAddress(); | 858 const wallet::Address* address = ActiveShippingAddress(); |
854 if (address) | 859 if (address) |
855 previously_selected_shipping_address_id_ = address->object_id(); | 860 previously_selected_shipping_address_id_ = address->object_id(); |
856 } | 861 } |
857 | 862 |
858 last_wallet_items_fetch_timestamp_ = base::TimeTicks::Now(); | 863 last_wallet_items_fetch_timestamp_ = base::TimeTicks::Now(); |
859 wallet_items_.reset(); | 864 wallet_items_.reset(); |
860 | 865 |
861 // The "Loading..." page should be showing now, which should cause the | 866 // The "Loading..." page should be showing now, which should cause the |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2370 kSameAsBillingKey, | 2375 kSameAsBillingKey, |
2371 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); | 2376 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); |
2372 | 2377 |
2373 if (IsPayingWithWallet()) { | 2378 if (IsPayingWithWallet()) { |
2374 if (!account_chooser_model_.active_wallet_account_name().empty()) { | 2379 if (!account_chooser_model_.active_wallet_account_name().empty()) { |
2375 suggested_email_.AddKeyedItem( | 2380 suggested_email_.AddKeyedItem( |
2376 base::IntToString(0), | 2381 base::IntToString(0), |
2377 account_chooser_model_.active_wallet_account_name()); | 2382 account_chooser_model_.active_wallet_account_name()); |
2378 } | 2383 } |
2379 | 2384 |
2385 // If the default address changed since the last fetch of the Wallet data, | |
2386 // select it rather than the previously selected address, as the user's | |
2387 // intention in changing the default address was probably to use it. | |
2388 if (previous_default_shipping_address_id_ != | |
2389 wallet_items_->default_address_id()) { | |
2390 previously_selected_shipping_address_id_.clear(); | |
2391 } | |
2392 | |
2380 const std::vector<wallet::Address*>& addresses = | 2393 const std::vector<wallet::Address*>& addresses = |
2381 wallet_items_->addresses(); | 2394 wallet_items_->addresses(); |
2382 for (size_t i = 0; i < addresses.size(); ++i) { | 2395 for (size_t i = 0; i < addresses.size(); ++i) { |
2383 std::string key = base::IntToString(i); | 2396 std::string key = base::IntToString(i); |
2384 suggested_shipping_.AddKeyedItemWithSublabel( | 2397 suggested_shipping_.AddKeyedItemWithSublabel( |
2385 key, | 2398 key, |
2386 addresses[i]->DisplayName(), | 2399 addresses[i]->DisplayName(), |
2387 addresses[i]->DisplayNameDetail()); | 2400 addresses[i]->DisplayNameDetail()); |
2388 | 2401 |
2389 const std::string default_shipping_address_id = | 2402 const std::string default_shipping_address_id = |
2390 !previously_selected_shipping_address_id_.empty() ? | 2403 !previously_selected_shipping_address_id_.empty() ? |
2391 previously_selected_shipping_address_id_ : | 2404 previously_selected_shipping_address_id_ : |
2392 wallet_items_->default_address_id(); | 2405 wallet_items_->default_address_id(); |
2393 if (addresses[i]->object_id() == default_shipping_address_id) | 2406 if (addresses[i]->object_id() == default_shipping_address_id) |
2394 suggested_shipping_.SetCheckedItem(key); | 2407 suggested_shipping_.SetCheckedItem(key); |
2395 } | 2408 } |
2396 previously_selected_shipping_address_id_.clear(); | 2409 previously_selected_shipping_address_id_.clear(); |
2397 | 2410 |
2398 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 2411 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
2412 // If the default address changed since the last fetch of the Wallet data, | |
2413 // select it rather than the previously selected address, as the user's | |
2414 // intention in changing the default address was probably to use it. | |
2415 if (previous_default_instrument_id_ != | |
2416 wallet_items_->default_instrument_id()) { | |
2417 previously_selected_instrument_id_.clear(); | |
Evan Stade
2013/09/04 19:25:28
can you keep all this default instrument logic in
Ilya Sherman
2013/09/05 01:13:59
Done.
| |
2418 } | |
2419 | |
2399 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = | 2420 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = |
2400 wallet_items_->instruments(); | 2421 wallet_items_->instruments(); |
2401 std::string first_active_instrument_key; | 2422 std::string first_active_instrument_key; |
2402 std::string default_instrument_key; | 2423 std::string default_instrument_key; |
2403 for (size_t i = 0; i < instruments.size(); ++i) { | 2424 for (size_t i = 0; i < instruments.size(); ++i) { |
2404 bool allowed = IsInstrumentAllowed(*instruments[i]); | 2425 bool allowed = IsInstrumentAllowed(*instruments[i]); |
2405 gfx::Image icon = instruments[i]->CardIcon(); | 2426 gfx::Image icon = instruments[i]->CardIcon(); |
2406 if (!allowed && !icon.IsEmpty()) { | 2427 if (!allowed && !icon.IsEmpty()) { |
2407 // Create a grayed disabled icon. | 2428 // Create a grayed disabled icon. |
2408 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | 2429 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
(...skipping 14 matching lines...) Expand all Loading... | |
2423 first_active_instrument_key = key; | 2444 first_active_instrument_key = key; |
2424 | 2445 |
2425 const std::string default_instrument_id = | 2446 const std::string default_instrument_id = |
2426 !previously_selected_instrument_id_.empty() ? | 2447 !previously_selected_instrument_id_.empty() ? |
2427 previously_selected_instrument_id_ : | 2448 previously_selected_instrument_id_ : |
2428 wallet_items_->default_instrument_id(); | 2449 wallet_items_->default_instrument_id(); |
2429 if (instruments[i]->object_id() == default_instrument_id) | 2450 if (instruments[i]->object_id() == default_instrument_id) |
2430 default_instrument_key = key; | 2451 default_instrument_key = key; |
2431 } | 2452 } |
2432 } | 2453 } |
2433 previously_selected_instrument_id_.clear(); | 2454 previously_selected_instrument_id_.clear(); |
Evan Stade
2013/09/04 19:25:28
do we still need this here?
Ilya Sherman
2013/09/05 01:13:59
Done.
| |
2434 | 2455 |
2435 // TODO(estade): this should have a URL sublabel. | 2456 // TODO(estade): this should have a URL sublabel. |
2436 suggested_cc_billing_.AddKeyedItem( | 2457 suggested_cc_billing_.AddKeyedItem( |
2437 kAddNewItemKey, | 2458 kAddNewItemKey, |
2438 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); | 2459 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); |
2439 if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { | 2460 if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { |
2440 suggested_cc_billing_.AddKeyedItemWithSublabel( | 2461 suggested_cc_billing_.AddKeyedItemWithSublabel( |
2441 kManageItemsKey, | 2462 kManageItemsKey, |
2442 l10n_util::GetStringUTF16( | 2463 l10n_util::GetStringUTF16( |
2443 IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS), | 2464 IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS), |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3329 } | 3350 } |
3330 #if !defined(OS_ANDROID) | 3351 #if !defined(OS_ANDROID) |
3331 GeneratedCreditCardBubbleController::Show( | 3352 GeneratedCreditCardBubbleController::Show( |
3332 web_contents(), | 3353 web_contents(), |
3333 full_wallet_->TypeAndLastFourDigits(), | 3354 full_wallet_->TypeAndLastFourDigits(), |
3334 backing_last_four); | 3355 backing_last_four); |
3335 #endif | 3356 #endif |
3336 } | 3357 } |
3337 | 3358 |
3338 } // namespace autofill | 3359 } // namespace autofill |
OLD | NEW |