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 "chrome/browser/autofill/autofill_flow_infobar_delegate.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/api/infobars/infobar_service.h" | |
10 #include "chrome/browser/autofill/autofill_flow_util.h" | |
11 #include "chrome/browser/autofill/autofill_manager.h" | |
12 #include "chrome/common/form_data.h" | |
Ilya Sherman
2013/01/15 06:31:52
nit: Already included in the header file.
Raman Kakilate
2013/01/15 23:02:33
Done.
| |
13 #include "chrome/common/url_constants.h" | |
14 #include "content/public/browser/page_navigator.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "content/public/browser/web_contents_delegate.h" | |
17 #include "googleurl/src/gurl.h" | |
Ilya Sherman
2013/01/15 06:31:52
nit: Already included in the header file.
Raman Kakilate
2013/01/15 23:02:33
Done.
| |
18 #include "grit/generated_resources.h" | |
19 #include "grit/theme_resources.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 #include "ui/base/resource/resource_bundle.h" | |
22 | |
23 // static | |
24 void AutofillFlowInfoBarDelegate::Create( | |
25 InfoBarService* infobar_service, | |
26 AutofillManager* autofill_manager, | |
27 const AutofillMetrics* metric_logger, | |
28 const GURL& source_url, | |
29 const content::SSLStatus& ssl_status) { | |
30 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | |
31 new AutofillFlowInfoBarDelegate(infobar_service, autofill_manager, | |
32 metric_logger, source_url, ssl_status))); | |
33 } | |
34 | |
35 AutofillFlowInfoBarDelegate::AutofillFlowInfoBarDelegate( | |
36 InfoBarService* infobar_service, | |
37 AutofillManager* autofill_manager, | |
38 const AutofillMetrics* metric_logger, | |
39 const GURL& source_url, | |
40 const content::SSLStatus& ssl_status) | |
41 : ConfirmInfoBarDelegate(infobar_service), | |
42 metric_logger_(metric_logger), | |
43 autofill_manager_(autofill_manager), | |
44 source_url_(source_url), | |
45 ssl_status_(ssl_status), | |
46 had_user_interaction_(false) { | |
47 metric_logger_->LogAutofillFlowInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); | |
48 autofill_flow_form_data_ = autofill::BuildAutofillFlowFormData(); | |
Ilya Sherman
2013/01/15 06:31:52
Why cache this, rather than just passing it to Sho
Raman Kakilate
2013/01/15 23:02:33
Done.
| |
49 } | |
50 | |
51 AutofillFlowInfoBarDelegate::~AutofillFlowInfoBarDelegate() { | |
52 if (!had_user_interaction_) | |
53 LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | |
54 } | |
55 | |
56 void AutofillFlowInfoBarDelegate::LogUserAction( | |
57 AutofillMetrics::InfoBarMetric user_action) { | |
58 DCHECK(!had_user_interaction_); | |
59 metric_logger_->LogAutofillFlowInfoBarMetric(user_action); | |
60 had_user_interaction_ = true; | |
61 } | |
62 | |
63 void AutofillFlowInfoBarDelegate::InfoBarDismissed() { | |
64 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | |
65 } | |
66 | |
67 gfx::Image* AutofillFlowInfoBarDelegate::GetIcon() const { | |
68 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
69 IDR_INFOBAR_AUTOFILL); | |
70 } | |
71 | |
72 InfoBarDelegate::Type AutofillFlowInfoBarDelegate::GetInfoBarType() const { | |
73 return PAGE_ACTION_TYPE; | |
74 } | |
75 | |
76 bool AutofillFlowInfoBarDelegate::ShouldExpireInternal( | |
77 const content::LoadCommittedDetails& details) const { | |
78 // The user has submitted a form, causing the page to navigate elsewhere. We | |
79 // want the infobar to be expired at this point, because the user has | |
80 // potentially started the checkout flow manually. | |
81 return true; | |
82 } | |
83 | |
84 | |
85 string16 AutofillFlowInfoBarDelegate::GetMessageText() const { | |
86 return l10n_util::GetStringUTF16(IDS_AUTOFILL_FLOW_INFOBAR_TEXT); | |
87 } | |
88 | |
89 string16 AutofillFlowInfoBarDelegate::GetButtonLabel( | |
90 InfoBarButton button) const { | |
91 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
92 IDS_AUTOFILL_FLOW_INFOBAR_ACCEPT : IDS_AUTOFILL_FLOW_INFOBAR_DENY); | |
93 } | |
94 | |
95 bool AutofillFlowInfoBarDelegate::Accept() { | |
96 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | |
97 GURL frame_url; | |
98 content::SSLStatus ssl_status; | |
Ilya Sherman
2013/01/15 06:31:52
nit: Remove these two locals, as they're not used.
Raman Kakilate
2013/01/15 23:02:33
My bad, Removed.
| |
99 | |
100 autofill_manager_->ShowAutofillFlowDialog(autofill_flow_form_data_, | |
101 source_url_, ssl_status_); | |
102 return true; | |
103 } | |
104 | |
105 bool AutofillFlowInfoBarDelegate::Cancel() { | |
106 LogUserAction(AutofillMetrics::INFOBAR_DENIED); | |
107 return true; | |
108 } | |
109 | |
110 string16 AutofillFlowInfoBarDelegate::GetLinkText() const { | |
111 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
112 } | |
113 | |
114 bool AutofillFlowInfoBarDelegate::LinkClicked( | |
115 WindowOpenDisposition disposition) { | |
116 // TODO(ramankk): Fix the help URL when we have one. | |
117 owner()->GetWebContents()->GetDelegate()->OpenURLFromTab( | |
118 owner()->GetWebContents(), | |
119 content::OpenURLParams(GURL(chrome::kAutofillHelpURL), | |
120 content::Referrer(), | |
121 NEW_FOREGROUND_TAB, | |
122 content::PAGE_TRANSITION_LINK, | |
123 false)); | |
124 return false; | |
125 } | |
126 | |
OLD | NEW |