Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/autofill/autofill_cc_infobar_delegate.cc

Issue 12378055: Make autofill stop depending on InfoBarService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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->DidShow();
34 }
35
36 // static
37 scoped_ptr<ConfirmInfoBarDelegate> AutofillCCInfoBarDelegate::Create(
38 scoped_ptr<AutofillCCImportConfirmationDelegate> delegate) {
39 delegate->DidShow();
40 return scoped_ptr<ConfirmInfoBarDelegate>(
41 new AutofillCCInfoBarDelegate(NULL, delegate.Pass()));
29 } 42 }
30 43
31 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( 44 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
32 InfoBarService* infobar_service, 45 InfoBarService* infobar_service,
33 const CreditCard* credit_card, 46 scoped_ptr<autofill::AutofillCCImportConfirmationDelegate> delegate)
34 PersonalDataManager* personal_data,
35 const AutofillMetrics* metric_logger)
36 : ConfirmInfoBarDelegate(infobar_service), 47 : ConfirmInfoBarDelegate(infobar_service),
37 credit_card_(credit_card), 48 delegate_(delegate.Pass()) {}
38 personal_data_(personal_data),
39 metric_logger_(metric_logger),
40 had_user_interaction_(false) {
41 metric_logger_->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN);
42 }
43 49
44 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { 50 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() {}
45 if (!had_user_interaction_)
46 LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
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 }
56 51
57 void AutofillCCInfoBarDelegate::InfoBarDismissed() { 52 void AutofillCCInfoBarDelegate::InfoBarDismissed() {
58 LogUserAction(AutofillMetrics::INFOBAR_DENIED); 53 delegate_->DidDismiss();
59 } 54 }
60 55
61 gfx::Image* AutofillCCInfoBarDelegate::GetIcon() const { 56 gfx::Image* AutofillCCInfoBarDelegate::GetIcon() const {
62 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 57 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
63 IDR_INFOBAR_AUTOFILL); 58 IDR_INFOBAR_AUTOFILL);
64 } 59 }
65 60
66 InfoBarDelegate::Type AutofillCCInfoBarDelegate::GetInfoBarType() const { 61 InfoBarDelegate::Type AutofillCCInfoBarDelegate::GetInfoBarType() const {
67 return PAGE_ACTION_TYPE; 62 return PAGE_ACTION_TYPE;
68 } 63 }
69 64
70 bool AutofillCCInfoBarDelegate::ShouldExpireInternal( 65 bool AutofillCCInfoBarDelegate::ShouldExpireInternal(
71 const content::LoadCommittedDetails& details) const { 66 const content::LoadCommittedDetails& details) const {
72 // The user has submitted a form, causing the page to navigate elsewhere. We 67 // 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 68 // don't want the infobar to be expired at this point, because the user won't
74 // get a chance to answer the question. 69 // get a chance to answer the question.
75 return false; 70 return false;
76 } 71 }
77 72
78 string16 AutofillCCInfoBarDelegate::GetMessageText() const { 73 string16 AutofillCCInfoBarDelegate::GetMessageText() const {
79 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); 74 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT);
80 } 75 }
81 76
82 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { 77 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const {
83 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? 78 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
84 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); 79 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY);
85 } 80 }
86 81
87 bool AutofillCCInfoBarDelegate::Accept() { 82 bool AutofillCCInfoBarDelegate::Accept() {
88 personal_data_->SaveImportedCreditCard(*credit_card_); 83 delegate_->DidAccept();
89 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED);
90 return true; 84 return true;
91 } 85 }
92 86
93 bool AutofillCCInfoBarDelegate::Cancel() { 87 bool AutofillCCInfoBarDelegate::Cancel() {
94 LogUserAction(AutofillMetrics::INFOBAR_DENIED); 88 delegate_->DidCancel();
95 return true; 89 return true;
96 } 90 }
97 91
98 string16 AutofillCCInfoBarDelegate::GetLinkText() const { 92 string16 AutofillCCInfoBarDelegate::GetLinkText() const {
99 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 93 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
100 } 94 }
101 95
102 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { 96 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
103 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( 97 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab(
104 owner()->GetWebContents(), 98 owner()->GetWebContents(),
105 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), 99 content::OpenURLParams(GURL(chrome::kAutofillHelpURL),
106 content::Referrer(), 100 content::Referrer(),
107 NEW_FOREGROUND_TAB, 101 NEW_FOREGROUND_TAB,
108 content::PAGE_TRANSITION_LINK, 102 content::PAGE_TRANSITION_LINK,
109 false)); 103 false));
110 return false; 104 return false;
111 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698