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(InfoBarService* infobar_service, |
| 22 InfoBarService* infobar_service, | 22 const AutofillMetrics* metric_logger, |
| 23 const CreditCard* credit_card, | 23 const base::Closure& import_callback) { |
| 24 PersonalDataManager* personal_data, | |
| 25 const AutofillMetrics* metric_logger) { | |
| 26 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 24 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 27 new AutofillCCInfoBarDelegate(infobar_service, credit_card, personal_data, | 25 new AutofillCCInfoBarDelegate( |
| 28 metric_logger))); | 26 infobar_service, metric_logger, import_callback))); |
| 27 metric_logger->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
|
Ilya Sherman
2013/03/06 09:13:24
Hmm, why did you move this out of the constructor?
kaiwang
2013/03/06 18:25:04
Creating an infobar delegate does not mean showing
| |
| 28 } | |
| 29 | |
| 30 // static | |
| 31 scoped_ptr<ConfirmInfoBarDelegate> AutofillCCInfoBarDelegate::CreateForTesting( | |
| 32 const AutofillMetrics* metric_logger, | |
| 33 const base::Closure& import_callback) { | |
| 34 metric_logger->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
| 35 return scoped_ptr<ConfirmInfoBarDelegate>( | |
| 36 new AutofillCCInfoBarDelegate(NULL, metric_logger, import_callback)); | |
| 29 } | 37 } |
| 30 | 38 |
| 31 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( | 39 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( |
| 32 InfoBarService* infobar_service, | 40 InfoBarService* infobar_service, |
| 33 const CreditCard* credit_card, | 41 const AutofillMetrics* metric_logger, |
| 34 PersonalDataManager* personal_data, | 42 const base::Closure& import_callback) |
| 35 const AutofillMetrics* metric_logger) | |
| 36 : ConfirmInfoBarDelegate(infobar_service), | 43 : ConfirmInfoBarDelegate(infobar_service), |
| 37 credit_card_(credit_card), | |
| 38 personal_data_(personal_data), | |
| 39 metric_logger_(metric_logger), | 44 metric_logger_(metric_logger), |
| 40 had_user_interaction_(false) { | 45 import_callback_(import_callback), |
| 41 metric_logger_->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | 46 had_user_interaction_(false) {} |
| 42 } | |
| 43 | 47 |
| 44 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { | 48 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { |
| 45 if (!had_user_interaction_) | 49 if (!had_user_interaction_) |
| 46 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | 50 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); |
| 47 } | 51 } |
| 48 | 52 |
| 49 void AutofillCCInfoBarDelegate::LogUserAction( | 53 void AutofillCCInfoBarDelegate::LogUserAction( |
| 50 AutofillMetrics::InfoBarMetric user_action) { | 54 AutofillMetrics::InfoBarMetric user_action) { |
| 51 DCHECK(!had_user_interaction_); | 55 DCHECK(!had_user_interaction_); |
| 52 | 56 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 78 string16 AutofillCCInfoBarDelegate::GetMessageText() const { | 82 string16 AutofillCCInfoBarDelegate::GetMessageText() const { |
| 79 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); | 83 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); |
| 80 } | 84 } |
| 81 | 85 |
| 82 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { | 86 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { |
| 83 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 87 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 84 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); | 88 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); |
| 85 } | 89 } |
| 86 | 90 |
| 87 bool AutofillCCInfoBarDelegate::Accept() { | 91 bool AutofillCCInfoBarDelegate::Accept() { |
| 88 personal_data_->SaveImportedCreditCard(*credit_card_); | 92 import_callback_.Run(); |
| 93 import_callback_.Reset(); | |
| 89 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | 94 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); |
| 90 return true; | 95 return true; |
| 91 } | 96 } |
| 92 | 97 |
| 93 bool AutofillCCInfoBarDelegate::Cancel() { | 98 bool AutofillCCInfoBarDelegate::Cancel() { |
| 94 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | 99 LogUserAction(AutofillMetrics::INFOBAR_DENIED); |
| 95 return true; | 100 return true; |
| 96 } | 101 } |
| 97 | 102 |
| 98 string16 AutofillCCInfoBarDelegate::GetLinkText() const { | 103 string16 AutofillCCInfoBarDelegate::GetLinkText() const { |
| 99 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 104 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 100 } | 105 } |
| 101 | 106 |
| 102 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 107 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 103 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( | 108 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( |
| 104 owner()->GetWebContents(), | 109 owner()->GetWebContents(), |
| 105 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), | 110 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), |
| 106 content::Referrer(), | 111 content::Referrer(), |
| 107 NEW_FOREGROUND_TAB, | 112 NEW_FOREGROUND_TAB, |
| 108 content::PAGE_TRANSITION_LINK, | 113 content::PAGE_TRANSITION_LINK, |
| 109 false)); | 114 false)); |
| 110 return false; | 115 return false; |
| 111 } | 116 } |
| OLD | NEW |