Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/autofill/autofill_cc_infobar_delegate.h" | 5 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/api/infobars/infobar_service.h" | 8 #include "chrome/browser/api/infobars/infobar_service.h" |
| 9 #include "chrome/browser/autofill/credit_card.h" | 9 #include "chrome/browser/autofill/credit_card.h" |
| 10 #include "chrome/browser/autofill/personal_data_manager.h" | 10 #include "chrome/browser/autofill/personal_data_manager.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "content/public/browser/page_navigator.h" | 12 #include "content/public/browser/page_navigator.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/browser/web_contents_delegate.h" | 14 #include "content/public/browser/web_contents_delegate.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 void AutofillCCInfoBarDelegate::Create( | 21 void AutofillCCInfoBarDelegate::Create( |
| 22 InfoBarService* infobar_service, | 22 InfoBarService* infobar_service, |
| 23 const CreditCard* credit_card, | 23 const AutofillMetrics* metric_logger, |
| 24 PersonalDataManager* personal_data, | 24 const base::Closure& save_card_callback) { |
| 25 const AutofillMetrics* metric_logger) { | |
| 26 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 25 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 27 new AutofillCCInfoBarDelegate(infobar_service, credit_card, personal_data, | 26 new AutofillCCInfoBarDelegate( |
| 28 metric_logger))); | 27 infobar_service, metric_logger, save_card_callback))); |
| 28 metric_logger->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
| 29 } | |
| 30 | |
| 31 // static | |
| 32 scoped_ptr<ConfirmInfoBarDelegate> AutofillCCInfoBarDelegate::CreateForTesting( | |
| 33 const AutofillMetrics* metric_logger, | |
| 34 const base::Closure& save_card_callback) { | |
| 35 metric_logger->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
| 36 return scoped_ptr<ConfirmInfoBarDelegate>( | |
| 37 new AutofillCCInfoBarDelegate(NULL, metric_logger, save_card_callback)); | |
| 29 } | 38 } |
| 30 | 39 |
| 31 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( | 40 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( |
| 32 InfoBarService* infobar_service, | 41 InfoBarService* infobar_service, |
| 33 const CreditCard* credit_card, | 42 const AutofillMetrics* metric_logger, |
| 34 PersonalDataManager* personal_data, | 43 const base::Closure& save_card_callback) |
| 35 const AutofillMetrics* metric_logger) | |
| 36 : ConfirmInfoBarDelegate(infobar_service), | 44 : ConfirmInfoBarDelegate(infobar_service), |
| 37 credit_card_(credit_card), | |
| 38 personal_data_(personal_data), | |
| 39 metric_logger_(metric_logger), | 45 metric_logger_(metric_logger), |
| 40 had_user_interaction_(false) { | 46 save_card_callback_(save_card_callback), |
| 41 metric_logger_->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | 47 had_user_interaction_(false) {} |
| 42 } | |
| 43 | 48 |
| 44 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { | 49 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { |
| 45 if (!had_user_interaction_) | 50 if (!had_user_interaction_) |
| 46 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | 51 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); |
| 47 } | 52 } |
| 48 | 53 |
| 49 void AutofillCCInfoBarDelegate::LogUserAction( | 54 void AutofillCCInfoBarDelegate::LogUserAction( |
| 50 AutofillMetrics::InfoBarMetric user_action) { | 55 AutofillMetrics::InfoBarMetric user_action) { |
| 51 DCHECK(!had_user_interaction_); | 56 DCHECK(!had_user_interaction_); |
| 52 | 57 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 78 string16 AutofillCCInfoBarDelegate::GetMessageText() const { | 83 string16 AutofillCCInfoBarDelegate::GetMessageText() const { |
| 79 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); | 84 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); |
| 80 } | 85 } |
| 81 | 86 |
| 82 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { | 87 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { |
| 83 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 88 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 84 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); | 89 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); |
| 85 } | 90 } |
| 86 | 91 |
| 87 bool AutofillCCInfoBarDelegate::Accept() { | 92 bool AutofillCCInfoBarDelegate::Accept() { |
| 88 personal_data_->SaveImportedCreditCard(*credit_card_); | 93 save_card_callback_.Run(); |
| 94 save_card_callback_.Reset(); | |
|
Justin Donnelly
2016/03/09 03:33:35
Question arose about this arose in https://coderev
| |
| 89 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | 95 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); |
| 90 return true; | 96 return true; |
| 91 } | 97 } |
| 92 | 98 |
| 93 bool AutofillCCInfoBarDelegate::Cancel() { | 99 bool AutofillCCInfoBarDelegate::Cancel() { |
| 94 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | 100 LogUserAction(AutofillMetrics::INFOBAR_DENIED); |
| 95 return true; | 101 return true; |
| 96 } | 102 } |
| 97 | 103 |
| 98 string16 AutofillCCInfoBarDelegate::GetLinkText() const { | 104 string16 AutofillCCInfoBarDelegate::GetLinkText() const { |
| 99 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 105 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 100 } | 106 } |
| 101 | 107 |
| 102 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 108 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 103 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( | 109 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( |
| 104 owner()->GetWebContents(), | 110 owner()->GetWebContents(), |
| 105 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), | 111 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), |
| 106 content::Referrer(), | 112 content::Referrer(), |
| 107 NEW_FOREGROUND_TAB, | 113 NEW_FOREGROUND_TAB, |
| 108 content::PAGE_TRANSITION_LINK, | 114 content::PAGE_TRANSITION_LINK, |
| 109 false)); | 115 false)); |
| 110 return false; | 116 return false; |
| 111 } | 117 } |
| OLD | NEW |