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 |
11 #include "apps/native_app_window.h" | 11 #include "apps/native_app_window.h" |
12 #include "apps/shell_window.h" | 12 #include "apps/shell_window.h" |
13 #include "apps/shell_window_registry.h" | 13 #include "apps/shell_window_registry.h" |
14 #include "base/base64.h" | 14 #include "base/base64.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/i18n/case_conversion.h" | |
16 #include "base/i18n/rtl.h" | 17 #include "base/i18n/rtl.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
20 #include "base/rand_util.h" | |
19 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
21 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
22 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
23 #include "base/time/time.h" | 25 #include "base/time/time.h" |
24 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 26 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
25 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 28 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
27 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" | 30 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 | 405 |
404 case wallet::WalletClient::UNKNOWN_ERROR: | 406 case wallet::WalletClient::UNKNOWN_ERROR: |
405 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, | 407 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_WALLET_UNKNOWN_ERROR, |
406 ASCIIToUTF16("74")); | 408 ASCIIToUTF16("74")); |
407 } | 409 } |
408 | 410 |
409 NOTREACHED(); | 411 NOTREACHED(); |
410 return base::string16(); | 412 return base::string16(); |
411 } | 413 } |
412 | 414 |
413 gfx::Image GetGeneratedCardImage(const string16& card_number) { | 415 gfx::Image GetGeneratedCardImage(const base::string16& card_number, |
416 const base::string16& name) { | |
414 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 417 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
415 const gfx::ImageSkia* card = | 418 const gfx::ImageSkia* card = |
416 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); | 419 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); |
417 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); | 420 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); |
418 canvas.DrawImageInt(*card, 0, 0); | 421 canvas.DrawImageInt(*card, 0, 0); |
419 | 422 |
423 // TODO(estade): space the text out a bit better. We might need a larger | |
424 // card image. | |
420 gfx::Rect display_rect(gfx::Point(), card->size()); | 425 gfx::Rect display_rect(gfx::Point(), card->size()); |
421 display_rect.Inset(14, 0, 14, 0); | 426 display_rect.Inset(8, 0, 14, 0); |
422 // TODO(estade): fallback font for systems that don't have Helvetica? | 427 gfx::Font monospace("monospace", 12); |
423 gfx::Font helvetica("Helvetica", 14); | |
424 gfx::ShadowValues shadows; | 428 gfx::ShadowValues shadows; |
425 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1), | 429 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1), |
426 0.0, | 430 0.0, |
427 SkColorSetARGB(85, 0, 0, 0))); | 431 SkColorSetARGB(85, 0, 0, 0))); |
428 canvas.DrawStringWithShadows( | 432 canvas.DrawStringWithShadows( |
429 card_number, | 433 card_number, |
430 helvetica, | 434 monospace, |
431 SK_ColorWHITE, | 435 SK_ColorWHITE, |
432 display_rect, 0, 0, shadows); | 436 display_rect, 0, 0, shadows); |
433 | 437 |
438 base::string16 capitalized_name = base::i18n::ToUpper(name); | |
439 display_rect.set_y(24); | |
440 canvas.DrawStringWithShadows( | |
441 capitalized_name, | |
442 monospace, | |
443 SK_ColorWHITE, | |
444 display_rect, 0, 0, shadows); | |
445 | |
434 gfx::ImageSkia skia(canvas.ExtractImageRep()); | 446 gfx::ImageSkia skia(canvas.ExtractImageRep()); |
435 return gfx::Image(skia); | 447 return gfx::Image(skia); |
436 } | 448 } |
437 | 449 |
438 } // namespace | 450 } // namespace |
439 | 451 |
440 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} | 452 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} |
441 | 453 |
442 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { | 454 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { |
443 if (popup_controller_) | 455 if (popup_controller_) |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; | 809 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; |
798 if (!show_wallet_interstitial) | 810 if (!show_wallet_interstitial) |
799 return DialogOverlayState(); | 811 return DialogOverlayState(); |
800 | 812 |
801 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 813 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
802 DialogOverlayState state; | 814 DialogOverlayState state; |
803 | 815 |
804 state.strings.push_back(DialogOverlayString()); | 816 state.strings.push_back(DialogOverlayString()); |
805 DialogOverlayString& string = state.strings.back(); | 817 DialogOverlayString& string = state.strings.back(); |
806 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); | 818 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); |
819 string.alignment = gfx::ALIGN_CENTER; | |
820 string.text_color = SK_ColorBLACK; | |
807 | 821 |
808 // First-run, post-submit, Wallet expository page. | 822 // First-run, post-submit, Wallet expository page. |
809 if (full_wallet_ && full_wallet_->required_actions().empty()) { | 823 if (full_wallet_ && full_wallet_->required_actions().empty()) { |
810 string16 cc_number = | 824 string16 cc_number = |
811 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); | 825 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); |
812 DCHECK_EQ(16U, cc_number.size()); | 826 DCHECK_EQ(16U, cc_number.size()); |
813 state.image = GetGeneratedCardImage( | 827 state.image = GetGeneratedCardImage( |
814 ASCIIToUTF16("xxxx xxxx xxxx ") + | 828 ASCIIToUTF16("XXXX XXXX XXXX ") + |
815 cc_number.substr(cc_number.size() - 4)); | 829 cc_number.substr(cc_number.size() - 4), |
830 full_wallet_->billing_address()->recipient_name()); | |
831 | |
816 string.text = l10n_util::GetStringUTF16( | 832 string.text = l10n_util::GetStringUTF16( |
817 IDS_AUTOFILL_DIALOG_CARD_GENERATION_DONE); | 833 IDS_AUTOFILL_DIALOG_CARD_GENERATION_DONE); |
818 string.text_color = SK_ColorBLACK; | |
819 string.alignment = gfx::ALIGN_CENTER; | |
820 | |
821 state.strings.push_back(DialogOverlayString()); | 834 state.strings.push_back(DialogOverlayString()); |
822 DialogOverlayString& subtext = state.strings.back(); | |
823 subtext.font = rb.GetFont(ui::ResourceBundle::BaseFont); | |
824 subtext.text_color = SkColorSetRGB(102, 102, 102); | |
825 subtext.text = l10n_util::GetStringUTF16( | |
826 IDS_AUTOFILL_DIALOG_CARD_GENERATION_EXPLANATION); | |
827 subtext.alignment = gfx::ALIGN_CENTER; | |
828 | |
829 state.button_text = l10n_util::GetStringUTF16( | |
830 IDS_AUTOFILL_DIALOG_CARD_GENERATION_OK_BUTTON); | |
831 } else { | 835 } else { |
832 // TODO(estade): fix this (animation?). | 836 // Generate a random card number. Tell the view to update it 100ms from now |
833 state.image = | 837 // (at which point we'll generate another random card number). |
834 GetGeneratedCardImage(ASCIIToUTF16("xxxx xxxx xx...")); | 838 std::string card_number; |
839 for (size_t i = 0; i < 4; ++i) { | |
840 int part = base::RandInt(0, 10000); | |
841 base::StringAppendF(&card_number, "%04d ", part); | |
842 } | |
843 state.image = GetGeneratedCardImage( | |
844 ASCIIToUTF16(card_number), | |
845 ActiveInstrument()->address().recipient_name()); | |
846 state.expiry = base::TimeDelta::FromMilliseconds(100); | |
groby-ooo-7-16
2013/09/03 18:50:04
Constant?
Evan Stade
2013/09/03 19:05:37
I don't see the purpose of a constant here because
| |
835 | 847 |
836 // "Submitting" waiting page. | 848 // "Submitting" waiting page. |
837 string.text = l10n_util::GetStringUTF16( | 849 string.text = l10n_util::GetStringUTF16( |
838 IDS_AUTOFILL_DIALOG_CARD_GENERATION_IN_PROGRESS); | 850 IDS_AUTOFILL_DIALOG_CARD_GENERATION_IN_PROGRESS); |
839 string.text_color = SK_ColorBLACK; | |
840 string.alignment = gfx::ALIGN_CENTER; | |
841 } | 851 } |
842 | 852 |
843 return state; | 853 return state; |
844 } | 854 } |
845 | 855 |
846 const std::vector<ui::Range>& AutofillDialogControllerImpl:: | 856 const std::vector<ui::Range>& AutofillDialogControllerImpl:: |
847 LegalDocumentLinks() { | 857 LegalDocumentLinks() { |
848 EnsureLegalDocumentsText(); | 858 EnsureLegalDocumentsText(); |
849 return legal_document_link_ranges_; | 859 return legal_document_link_ranges_; |
850 } | 860 } |
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1933 for (size_t i = 0; i < legal_document_link_ranges_.size(); ++i) { | 1943 for (size_t i = 0; i < legal_document_link_ranges_.size(); ++i) { |
1934 if (legal_document_link_ranges_[i] == range) { | 1944 if (legal_document_link_ranges_[i] == range) { |
1935 OpenTabWithUrl(wallet_items_->legal_documents()[i]->url()); | 1945 OpenTabWithUrl(wallet_items_->legal_documents()[i]->url()); |
1936 return; | 1946 return; |
1937 } | 1947 } |
1938 } | 1948 } |
1939 | 1949 |
1940 NOTREACHED(); | 1950 NOTREACHED(); |
1941 } | 1951 } |
1942 | 1952 |
1943 void AutofillDialogControllerImpl::OverlayButtonPressed() { | |
1944 DCHECK(is_submitting_); | |
1945 DCHECK(full_wallet_); | |
1946 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, | |
1947 true); | |
1948 FinishSubmit(); | |
1949 } | |
1950 | |
1951 bool AutofillDialogControllerImpl::OnCancel() { | 1953 bool AutofillDialogControllerImpl::OnCancel() { |
1952 HidePopup(); | 1954 HidePopup(); |
1953 if (autocheckout_state_ == AUTOCHECKOUT_NOT_STARTED && !is_submitting_) | 1955 if (autocheckout_state_ == AUTOCHECKOUT_NOT_STARTED && !is_submitting_) |
1954 LogOnCancelMetrics(); | 1956 LogOnCancelMetrics(); |
1955 if (autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS) { | 1957 if (autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS) { |
1956 GetMetricLogger().LogAutocheckoutDuration( | 1958 GetMetricLogger().LogAutocheckoutDuration( |
1957 base::Time::Now() - autocheckout_started_timestamp_, | 1959 base::Time::Now() - autocheckout_started_timestamp_, |
1958 AutofillMetrics::AUTOCHECKOUT_CANCELLED); | 1960 AutofillMetrics::AUTOCHECKOUT_CANCELLED); |
1959 } | 1961 } |
1960 callback_.Run(NULL, std::string()); | 1962 callback_.Run(NULL, std::string()); |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3174 if (*iter != wallet::INVALID_FORM_FIELD) { | 3176 if (*iter != wallet::INVALID_FORM_FIELD) { |
3175 // TODO(dbeam): handle this more gracefully. | 3177 // TODO(dbeam): handle this more gracefully. |
3176 DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); | 3178 DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); |
3177 } | 3179 } |
3178 } | 3180 } |
3179 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); | 3181 SetAutocheckoutState(AUTOCHECKOUT_NOT_STARTED); |
3180 SetIsSubmitting(false); | 3182 SetIsSubmitting(false); |
3181 } | 3183 } |
3182 | 3184 |
3183 void AutofillDialogControllerImpl::FinishSubmit() { | 3185 void AutofillDialogControllerImpl::FinishSubmit() { |
3184 if (IsPayingWithWallet() && | |
3185 !profile_->GetPrefs()->GetBoolean( | |
3186 ::prefs::kAutofillDialogHasPaidWithWallet)) { | |
3187 if (GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) { | |
3188 // To get past this point, the view must call back OverlayButtonPressed. | |
3189 #if defined(TOOLKIT_VIEWS) | 3186 #if defined(TOOLKIT_VIEWS) |
3190 ScopedViewUpdates updates(view_.get()); | 3187 // TODO(estade): implement overlays on other platforms. |
groby-ooo-7-16
2013/09/03 18:50:04
Is there a particular reason to not implement this
Evan Stade
2013/09/03 19:05:37
I'd rather that enabling this on mac be a separate
| |
3191 view_->UpdateButtonStrip(); | 3188 if (IsPayingWithWallet()) { |
3192 #else | 3189 // To get past this point, the view must call back OverlayButtonPressed. |
3193 // TODO(estade): implement overlays on other platforms. | 3190 ScopedViewUpdates updates(view_.get()); |
3194 OverlayButtonPressed(); | 3191 view_->UpdateButtonStrip(); |
3192 | |
3193 base::MessageLoop::current()->PostDelayedTask( | |
3194 FROM_HERE, | |
3195 base::Bind(&AutofillDialogControllerImpl::DoFinishSubmit, | |
3196 weak_ptr_factory_.GetWeakPtr()), | |
3197 base::TimeDelta::FromMilliseconds(2000)); | |
groby-ooo-7-16
2013/09/03 18:50:04
Declare as constant?
Evan Stade
2013/09/03 19:05:37
ditto
| |
3198 return; | |
3199 } | |
3195 #endif | 3200 #endif |
3196 return; | 3201 |
3197 } else { | 3202 DoFinishSubmit(); |
3198 profile_->GetPrefs()->SetBoolean( | 3203 } |
3199 ::prefs::kAutofillDialogHasPaidWithWallet, true); | 3204 |
3200 } | 3205 void AutofillDialogControllerImpl::DoFinishSubmit() { |
3206 if (IsPayingWithWallet()) { | |
3207 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, | |
3208 true); | |
3201 } | 3209 } |
3202 | 3210 |
3203 FillOutputForSection(SECTION_EMAIL); | 3211 FillOutputForSection(SECTION_EMAIL); |
3204 FillOutputForSection(SECTION_CC); | 3212 FillOutputForSection(SECTION_CC); |
3205 FillOutputForSection(SECTION_BILLING); | 3213 FillOutputForSection(SECTION_BILLING); |
3206 FillOutputForSection(SECTION_CC_BILLING); | 3214 FillOutputForSection(SECTION_CC_BILLING); |
3207 | 3215 |
3208 if (ShouldUseBillingForShipping()) { | 3216 if (ShouldUseBillingForShipping()) { |
3209 FillOutputForSectionWithComparator( | 3217 FillOutputForSectionWithComparator( |
3210 SECTION_BILLING, | 3218 SECTION_BILLING, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3506 } | 3514 } |
3507 #if !defined(OS_ANDROID) | 3515 #if !defined(OS_ANDROID) |
3508 GeneratedCreditCardBubbleController::Show( | 3516 GeneratedCreditCardBubbleController::Show( |
3509 web_contents(), | 3517 web_contents(), |
3510 full_wallet_->TypeAndLastFourDigits(), | 3518 full_wallet_->TypeAndLastFourDigits(), |
3511 backing_last_four); | 3519 backing_last_four); |
3512 #endif | 3520 #endif |
3513 } | 3521 } |
3514 | 3522 |
3515 } // namespace autofill | 3523 } // namespace autofill |
OLD | NEW |