| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "build/build_config.h" | |
| 9 #include "components/autofill/core/browser/credit_card.h" | |
| 10 #include "components/autofill/core/browser/personal_data_manager.h" | |
| 11 #include "components/autofill/core/common/autofill_constants.h" | |
| 12 #include "components/infobars/core/infobar.h" | |
| 13 #include "components/infobars/core/infobar_manager.h" | |
| 14 #include "grit/components_scaled_resources.h" | |
| 15 #include "grit/components_strings.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 #include "ui/gfx/vector_icons_public.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace autofill { | |
| 21 | |
| 22 // static | |
| 23 void AutofillCCInfoBarDelegate::CreateForLocalSave( | |
| 24 infobars::InfoBarManager* infobar_manager, | |
| 25 const base::Closure& save_card_callback) { | |
| 26 infobar_manager->AddInfoBar( | |
| 27 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | |
| 28 new AutofillCCInfoBarDelegate(false, save_card_callback)))); | |
| 29 } | |
| 30 | |
| 31 // static | |
| 32 void AutofillCCInfoBarDelegate::CreateForUpload( | |
| 33 infobars::InfoBarManager* infobar_manager, | |
| 34 const base::Closure& save_card_callback) { | |
| 35 infobar_manager->AddInfoBar( | |
| 36 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | |
| 37 new AutofillCCInfoBarDelegate(true, save_card_callback)))); | |
| 38 } | |
| 39 | |
| 40 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { | |
| 41 if (!had_user_interaction_) | |
| 42 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | |
| 43 } | |
| 44 | |
| 45 int AutofillCCInfoBarDelegate::GetIconId() const { | |
| 46 return IDR_INFOBAR_AUTOFILL_CC; | |
| 47 } | |
| 48 | |
| 49 base::string16 AutofillCCInfoBarDelegate::GetMessageText() const { | |
| 50 return l10n_util::GetStringUTF16( | |
| 51 upload_ ? IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD | |
| 52 : IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL); | |
| 53 } | |
| 54 | |
| 55 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const { | |
| 56 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
| 57 } | |
| 58 | |
| 59 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( | |
| 60 bool upload, | |
| 61 const base::Closure& save_card_callback) | |
| 62 : ConfirmInfoBarDelegate(), | |
| 63 upload_(upload), | |
| 64 save_card_callback_(save_card_callback), | |
| 65 had_user_interaction_(false) { | |
| 66 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
| 67 } | |
| 68 | |
| 69 void AutofillCCInfoBarDelegate::LogUserAction( | |
| 70 AutofillMetrics::InfoBarMetric user_action) { | |
| 71 DCHECK(!had_user_interaction_); | |
| 72 | |
| 73 AutofillMetrics::LogCreditCardInfoBarMetric(user_action); | |
| 74 had_user_interaction_ = true; | |
| 75 } | |
| 76 | |
| 77 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 78 AutofillCCInfoBarDelegate::GetIdentifier() const { | |
| 79 return AUTOFILL_CC_INFOBAR_DELEGATE; | |
| 80 } | |
| 81 | |
| 82 infobars::InfoBarDelegate::Type | |
| 83 AutofillCCInfoBarDelegate::GetInfoBarType() const { | |
| 84 return PAGE_ACTION_TYPE; | |
| 85 } | |
| 86 | |
| 87 gfx::VectorIconId AutofillCCInfoBarDelegate::GetVectorIconId() const { | |
| 88 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID) | |
| 89 return gfx::VectorIconId::AUTOFILL; | |
| 90 #else | |
| 91 return gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 92 #endif | |
| 93 } | |
| 94 | |
| 95 bool AutofillCCInfoBarDelegate::ShouldExpire( | |
| 96 const NavigationDetails& details) const { | |
| 97 // The user has submitted a form, causing the page to navigate elsewhere. We | |
| 98 // don't want the infobar to be expired at this point, because the user won't | |
| 99 // get a chance to answer the question. | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 103 void AutofillCCInfoBarDelegate::InfoBarDismissed() { | |
| 104 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | |
| 105 } | |
| 106 | |
| 107 base::string16 AutofillCCInfoBarDelegate::GetButtonLabel( | |
| 108 InfoBarButton button) const { | |
| 109 return l10n_util::GetStringUTF16(button == BUTTON_OK | |
| 110 ? IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT | |
| 111 : IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY); | |
| 112 } | |
| 113 | |
| 114 bool AutofillCCInfoBarDelegate::Accept() { | |
| 115 save_card_callback_.Run(); | |
| 116 save_card_callback_.Reset(); | |
| 117 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 bool AutofillCCInfoBarDelegate::Cancel() { | |
| 122 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | |
| 123 return true; | |
| 124 } | |
| 125 | |
| 126 GURL AutofillCCInfoBarDelegate::GetLinkURL() const { | |
| 127 return GURL(kHelpURL); | |
| 128 } | |
| 129 | |
| 130 } // namespace autofill | |
| OLD | NEW |