| 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/autofill_cc_import_confirmation_delegate.h" |
| 10 #include "chrome/browser/autofill/personal_data_manager.h" | |
| 11 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 12 #include "content/public/browser/page_navigator.h" | 11 #include "content/public/browser/page_navigator.h" |
| 13 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/browser/web_contents_delegate.h" | 13 #include "content/public/browser/web_contents_delegate.h" |
| 15 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 19 | 18 |
| 19 using autofill::AutofillCCImportConfirmationDelegate; |
| 20 |
| 21 class InfoBarDelegate; |
| 22 |
| 20 // static | 23 // static |
| 21 void AutofillCCInfoBarDelegate::Create( | 24 void AutofillCCInfoBarDelegate::Create( |
| 22 InfoBarService* infobar_service, | 25 InfoBarService* infobar_service, |
| 23 const CreditCard* credit_card, | 26 scoped_ptr<AutofillCCImportConfirmationDelegate> delegate) { |
| 24 PersonalDataManager* personal_data, | 27 AutofillCCImportConfirmationDelegate* confirmation_delegate = delegate.get(); |
| 25 const AutofillMetrics* metric_logger) { | 28 |
| 26 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 29 InfoBarDelegate* infobar_delegate = infobar_service->AddInfoBar( |
| 27 new AutofillCCInfoBarDelegate(infobar_service, credit_card, personal_data, | 30 scoped_ptr<InfoBarDelegate>( |
| 28 metric_logger))); | 31 new AutofillCCInfoBarDelegate(infobar_service, delegate.Pass()))); |
| 32 if (infobar_delegate) |
| 33 confirmation_delegate->DidShowConfirmation(); |
| 29 } | 34 } |
| 30 | 35 |
| 31 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( | 36 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( |
| 32 InfoBarService* infobar_service, | 37 InfoBarService* infobar_service, |
| 33 const CreditCard* credit_card, | 38 scoped_ptr<autofill::AutofillCCImportConfirmationDelegate> delegate) |
| 34 PersonalDataManager* personal_data, | |
| 35 const AutofillMetrics* metric_logger) | |
| 36 : ConfirmInfoBarDelegate(infobar_service), | 39 : ConfirmInfoBarDelegate(infobar_service), |
| 37 credit_card_(credit_card), | 40 delegate_(delegate.Pass()), |
| 38 personal_data_(personal_data), | 41 had_user_interaction_(false) {} |
| 39 metric_logger_(metric_logger), | |
| 40 had_user_interaction_(false) { | |
| 41 metric_logger_->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
| 42 } | |
| 43 | 42 |
| 44 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { | 43 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { |
| 45 if (!had_user_interaction_) | 44 if (!had_user_interaction_) |
| 46 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | 45 delegate_->DidIgnore(); |
| 47 } | |
| 48 | |
| 49 void AutofillCCInfoBarDelegate::LogUserAction( | |
| 50 AutofillMetrics::InfoBarMetric user_action) { | |
| 51 DCHECK(!had_user_interaction_); | |
| 52 | |
| 53 metric_logger_->LogCreditCardInfoBarMetric(user_action); | |
| 54 had_user_interaction_ = true; | |
| 55 } | 46 } |
| 56 | 47 |
| 57 void AutofillCCInfoBarDelegate::InfoBarDismissed() { | 48 void AutofillCCInfoBarDelegate::InfoBarDismissed() { |
| 58 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | 49 DCHECK(!had_user_interaction_); |
| 50 delegate_->DidDeny(); |
| 51 had_user_interaction_ = true; |
| 59 } | 52 } |
| 60 | 53 |
| 61 gfx::Image* AutofillCCInfoBarDelegate::GetIcon() const { | 54 gfx::Image* AutofillCCInfoBarDelegate::GetIcon() const { |
| 62 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 55 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 63 IDR_INFOBAR_AUTOFILL); | 56 IDR_INFOBAR_AUTOFILL); |
| 64 } | 57 } |
| 65 | 58 |
| 66 InfoBarDelegate::Type AutofillCCInfoBarDelegate::GetInfoBarType() const { | 59 InfoBarDelegate::Type AutofillCCInfoBarDelegate::GetInfoBarType() const { |
| 67 return PAGE_ACTION_TYPE; | 60 return PAGE_ACTION_TYPE; |
| 68 } | 61 } |
| 69 | 62 |
| 70 bool AutofillCCInfoBarDelegate::ShouldExpireInternal( | 63 bool AutofillCCInfoBarDelegate::ShouldExpireInternal( |
| 71 const content::LoadCommittedDetails& details) const { | 64 const content::LoadCommittedDetails& details) const { |
| 72 // The user has submitted a form, causing the page to navigate elsewhere. We | 65 // The user has submitted a form, causing the page to navigate elsewhere. We |
| 73 // don't want the infobar to be expired at this point, because the user won't | 66 // don't want the infobar to be expired at this point, because the user won't |
| 74 // get a chance to answer the question. | 67 // get a chance to answer the question. |
| 75 return false; | 68 return false; |
| 76 } | 69 } |
| 77 | 70 |
| 78 string16 AutofillCCInfoBarDelegate::GetMessageText() const { | 71 string16 AutofillCCInfoBarDelegate::GetMessageText() const { |
| 79 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); | 72 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); |
| 80 } | 73 } |
| 81 | 74 |
| 82 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { | 75 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { |
| 83 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 76 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 84 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); | 77 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); |
| 85 } | 78 } |
| 86 | 79 |
| 87 bool AutofillCCInfoBarDelegate::Accept() { | 80 bool AutofillCCInfoBarDelegate::Accept() { |
| 88 personal_data_->SaveImportedCreditCard(*credit_card_); | 81 DCHECK(!had_user_interaction_); |
| 89 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | 82 delegate_->DidAccept(); |
| 83 had_user_interaction_ = true; |
| 90 return true; | 84 return true; |
| 91 } | 85 } |
| 92 | 86 |
| 93 bool AutofillCCInfoBarDelegate::Cancel() { | 87 bool AutofillCCInfoBarDelegate::Cancel() { |
| 94 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | 88 DCHECK(!had_user_interaction_); |
| 89 delegate_->DidCancel(); |
| 90 had_user_interaction_ = true; |
| 95 return true; | 91 return true; |
| 96 } | 92 } |
| 97 | 93 |
| 98 string16 AutofillCCInfoBarDelegate::GetLinkText() const { | 94 string16 AutofillCCInfoBarDelegate::GetLinkText() const { |
| 99 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 95 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 100 } | 96 } |
| 101 | 97 |
| 102 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 98 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 103 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( | 99 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( |
| 104 owner()->GetWebContents(), | 100 owner()->GetWebContents(), |
| 105 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), | 101 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), |
| 106 content::Referrer(), | 102 content::Referrer(), |
| 107 NEW_FOREGROUND_TAB, | 103 NEW_FOREGROUND_TAB, |
| 108 content::PAGE_TRANSITION_LINK, | 104 content::PAGE_TRANSITION_LINK, |
| 109 false)); | 105 false)); |
| 110 return false; | 106 return false; |
| 111 } | 107 } |
| OLD | NEW |