| 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 canvas.DrawStringWithShadows( | 474 canvas.DrawStringWithShadows( |
| 475 card_number, | 475 card_number, |
| 476 helvetica, | 476 helvetica, |
| 477 SK_ColorWHITE, | 477 SK_ColorWHITE, |
| 478 display_rect, 0, 0, shadows); | 478 display_rect, 0, 0, shadows); |
| 479 | 479 |
| 480 gfx::ImageSkia skia(canvas.ExtractImageRep()); | 480 gfx::ImageSkia skia(canvas.ExtractImageRep()); |
| 481 return gfx::Image(skia); | 481 return gfx::Image(skia); |
| 482 } | 482 } |
| 483 | 483 |
| 484 // Returns the ID of the address or instrument that should be selected in the |
| 485 // UI, given that the |default_id| is currently the default ID on the Wallet |
| 486 // server, |previous_default_id| was the default ID prior to re-fetching the |
| 487 // Wallet data, and |previously_selected_id| was the ID of the item selected in |
| 488 // the dialog prior to re-fetching the Wallet data. |
| 489 std::string GetIdToSelect(const std::string& default_id, |
| 490 const std::string& previous_default_id, |
| 491 const std::string& previously_selected_id) { |
| 492 // If the default ID changed since the last fetch of the Wallet data, select |
| 493 // it rather than the previously selected item, as the user's intention in |
| 494 // changing the default was probably to use it. |
| 495 if (default_id != previous_default_id) |
| 496 return default_id; |
| 497 |
| 498 // Otherwise, prefer the previously selected item, if there was one. |
| 499 return !previously_selected_id.empty() ? previously_selected_id : default_id; |
| 500 } |
| 501 |
| 502 |
| 503 |
| 484 } // namespace | 504 } // namespace |
| 485 | 505 |
| 486 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} | 506 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} |
| 487 | 507 |
| 488 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { | 508 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { |
| 489 if (popup_controller_) | 509 if (popup_controller_) |
| 490 popup_controller_->Hide(); | 510 popup_controller_->Hide(); |
| 491 | 511 |
| 492 GetMetricLogger().LogDialogInitialUserState( | 512 GetMetricLogger().LogDialogInitialUserState( |
| 493 GetDialogType(), initial_user_state_); | 513 GetDialogType(), initial_user_state_); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 !wallet_items_->instruments().empty() && | 855 !wallet_items_->instruments().empty() && |
| 836 !wallet_items_->addresses().empty(); | 856 !wallet_items_->addresses().empty(); |
| 837 } | 857 } |
| 838 | 858 |
| 839 bool AutofillDialogControllerImpl::IsSubmitPausedOn( | 859 bool AutofillDialogControllerImpl::IsSubmitPausedOn( |
| 840 wallet::RequiredAction required_action) const { | 860 wallet::RequiredAction required_action) const { |
| 841 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); | 861 return full_wallet_ && full_wallet_->HasRequiredAction(required_action); |
| 842 } | 862 } |
| 843 | 863 |
| 844 void AutofillDialogControllerImpl::GetWalletItems() { | 864 void AutofillDialogControllerImpl::GetWalletItems() { |
| 845 DCHECK(previously_selected_instrument_id_.empty()); | |
| 846 DCHECK(previously_selected_shipping_address_id_.empty()); | |
| 847 ScopedViewUpdates updates(view_.get()); | 865 ScopedViewUpdates updates(view_.get()); |
| 848 | 866 |
| 867 previously_selected_instrument_id_.clear(); |
| 868 previously_selected_shipping_address_id_.clear(); |
| 849 if (wallet_items_) { | 869 if (wallet_items_) { |
| 850 if (ActiveInstrument()) | 870 previous_default_instrument_id_ = wallet_items_->default_instrument_id(); |
| 851 previously_selected_instrument_id_ = ActiveInstrument()->object_id(); | 871 previous_default_shipping_address_id_ = wallet_items_->default_address_id(); |
| 872 |
| 873 const wallet::WalletItems::MaskedInstrument* instrument = |
| 874 ActiveInstrument(); |
| 875 if (instrument) |
| 876 previously_selected_instrument_id_ = instrument->object_id(); |
| 852 | 877 |
| 853 const wallet::Address* address = ActiveShippingAddress(); | 878 const wallet::Address* address = ActiveShippingAddress(); |
| 854 if (address) | 879 if (address) |
| 855 previously_selected_shipping_address_id_ = address->object_id(); | 880 previously_selected_shipping_address_id_ = address->object_id(); |
| 856 } | 881 } |
| 857 | 882 |
| 858 last_wallet_items_fetch_timestamp_ = base::TimeTicks::Now(); | 883 last_wallet_items_fetch_timestamp_ = base::TimeTicks::Now(); |
| 859 wallet_items_.reset(); | 884 wallet_items_.reset(); |
| 860 | 885 |
| 861 // The "Loading..." page should be showing now, which should cause the | 886 // The "Loading..." page should be showing now, which should cause the |
| (...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 const std::vector<wallet::Address*>& addresses = | 2405 const std::vector<wallet::Address*>& addresses = |
| 2381 wallet_items_->addresses(); | 2406 wallet_items_->addresses(); |
| 2382 for (size_t i = 0; i < addresses.size(); ++i) { | 2407 for (size_t i = 0; i < addresses.size(); ++i) { |
| 2383 std::string key = base::IntToString(i); | 2408 std::string key = base::IntToString(i); |
| 2384 suggested_shipping_.AddKeyedItemWithSublabel( | 2409 suggested_shipping_.AddKeyedItemWithSublabel( |
| 2385 key, | 2410 key, |
| 2386 addresses[i]->DisplayName(), | 2411 addresses[i]->DisplayName(), |
| 2387 addresses[i]->DisplayNameDetail()); | 2412 addresses[i]->DisplayNameDetail()); |
| 2388 | 2413 |
| 2389 const std::string default_shipping_address_id = | 2414 const std::string default_shipping_address_id = |
| 2390 !previously_selected_shipping_address_id_.empty() ? | 2415 GetIdToSelect(wallet_items_->default_address_id(), |
| 2391 previously_selected_shipping_address_id_ : | 2416 previous_default_shipping_address_id_, |
| 2392 wallet_items_->default_address_id(); | 2417 previously_selected_shipping_address_id_); |
| 2393 if (addresses[i]->object_id() == default_shipping_address_id) | 2418 if (addresses[i]->object_id() == default_shipping_address_id) |
| 2394 suggested_shipping_.SetCheckedItem(key); | 2419 suggested_shipping_.SetCheckedItem(key); |
| 2395 } | 2420 } |
| 2396 previously_selected_shipping_address_id_.clear(); | |
| 2397 | 2421 |
| 2398 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 2422 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 2399 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = | 2423 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = |
| 2400 wallet_items_->instruments(); | 2424 wallet_items_->instruments(); |
| 2401 std::string first_active_instrument_key; | 2425 std::string first_active_instrument_key; |
| 2402 std::string default_instrument_key; | 2426 std::string default_instrument_key; |
| 2403 for (size_t i = 0; i < instruments.size(); ++i) { | 2427 for (size_t i = 0; i < instruments.size(); ++i) { |
| 2404 bool allowed = IsInstrumentAllowed(*instruments[i]); | 2428 bool allowed = IsInstrumentAllowed(*instruments[i]); |
| 2405 gfx::Image icon = instruments[i]->CardIcon(); | 2429 gfx::Image icon = instruments[i]->CardIcon(); |
| 2406 if (!allowed && !icon.IsEmpty()) { | 2430 if (!allowed && !icon.IsEmpty()) { |
| 2407 // Create a grayed disabled icon. | 2431 // Create a grayed disabled icon. |
| 2408 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | 2432 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
| 2409 *icon.ToSkBitmap(), kGrayImageShift); | 2433 *icon.ToSkBitmap(), kGrayImageShift); |
| 2410 icon = gfx::Image( | 2434 icon = gfx::Image( |
| 2411 gfx::ImageSkia::CreateFrom1xBitmap(disabled_bitmap)); | 2435 gfx::ImageSkia::CreateFrom1xBitmap(disabled_bitmap)); |
| 2412 } | 2436 } |
| 2413 std::string key = base::IntToString(i); | 2437 std::string key = base::IntToString(i); |
| 2414 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( | 2438 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( |
| 2415 key, | 2439 key, |
| 2416 instruments[i]->DisplayName(), | 2440 instruments[i]->DisplayName(), |
| 2417 instruments[i]->DisplayNameDetail(), | 2441 instruments[i]->DisplayNameDetail(), |
| 2418 icon); | 2442 icon); |
| 2419 suggested_cc_billing_.SetEnabled(key, allowed); | 2443 suggested_cc_billing_.SetEnabled(key, allowed); |
| 2420 | 2444 |
| 2421 if (allowed) { | 2445 if (allowed) { |
| 2422 if (first_active_instrument_key.empty()) | 2446 if (first_active_instrument_key.empty()) |
| 2423 first_active_instrument_key = key; | 2447 first_active_instrument_key = key; |
| 2424 | 2448 |
| 2425 const std::string default_instrument_id = | 2449 const std::string default_instrument_id = |
| 2426 !previously_selected_instrument_id_.empty() ? | 2450 GetIdToSelect(wallet_items_->default_instrument_id(), |
| 2427 previously_selected_instrument_id_ : | 2451 previous_default_instrument_id_, |
| 2428 wallet_items_->default_instrument_id(); | 2452 previously_selected_instrument_id_); |
| 2429 if (instruments[i]->object_id() == default_instrument_id) | 2453 if (instruments[i]->object_id() == default_instrument_id) |
| 2430 default_instrument_key = key; | 2454 default_instrument_key = key; |
| 2431 } | 2455 } |
| 2432 } | 2456 } |
| 2433 previously_selected_instrument_id_.clear(); | |
| 2434 | 2457 |
| 2435 // TODO(estade): this should have a URL sublabel. | 2458 // TODO(estade): this should have a URL sublabel. |
| 2436 suggested_cc_billing_.AddKeyedItem( | 2459 suggested_cc_billing_.AddKeyedItem( |
| 2437 kAddNewItemKey, | 2460 kAddNewItemKey, |
| 2438 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); | 2461 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); |
| 2439 if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { | 2462 if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { |
| 2440 suggested_cc_billing_.AddKeyedItemWithSublabel( | 2463 suggested_cc_billing_.AddKeyedItemWithSublabel( |
| 2441 kManageItemsKey, | 2464 kManageItemsKey, |
| 2442 l10n_util::GetStringUTF16( | 2465 l10n_util::GetStringUTF16( |
| 2443 IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS), | 2466 IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS), |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3329 } | 3352 } |
| 3330 #if !defined(OS_ANDROID) | 3353 #if !defined(OS_ANDROID) |
| 3331 GeneratedCreditCardBubbleController::Show( | 3354 GeneratedCreditCardBubbleController::Show( |
| 3332 web_contents(), | 3355 web_contents(), |
| 3333 full_wallet_->TypeAndLastFourDigits(), | 3356 full_wallet_->TypeAndLastFourDigits(), |
| 3334 backing_last_four); | 3357 backing_last_four); |
| 3335 #endif | 3358 #endif |
| 3336 } | 3359 } |
| 3337 | 3360 |
| 3338 } // namespace autofill | 3361 } // namespace autofill |
| OLD | NEW |