[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 1 | // Copyright (c) 2010 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_cc_infobar_delegate.h" | ||||
6 | |||||
7 | #include "app/l10n_util.h" | ||||
8 | #include "app/resource_bundle.h" | ||||
[email protected] | eb36f0d | 2010-07-29 20:54:20 | [diff] [blame] | 9 | #include "base/histogram.h" |
[email protected] | 71f7579b | 2010-07-17 07:45:19 | [diff] [blame] | 10 | #include "chrome/browser/autofill/autofill_cc_infobar.h" |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 11 | #include "chrome/browser/autofill/autofill_manager.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 12 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 13 | #include "chrome/browser/profile.h" |
14 | #include "chrome/browser/tab_contents/tab_contents.h" | ||||
15 | #include "chrome/browser/tab_contents/tab_contents_delegate.h" | ||||
16 | #include "chrome/common/pref_names.h" | ||||
17 | #include "grit/chromium_strings.h" | ||||
18 | #include "grit/generated_resources.h" | ||||
19 | #include "grit/theme_resources.h" | ||||
20 | #include "third_party/skia/include/core/SkBitmap.h" | ||||
21 | |||||
22 | AutoFillCCInfoBarDelegate::AutoFillCCInfoBarDelegate(TabContents* tab_contents, | ||||
23 | AutoFillManager* host) | ||||
24 | : ConfirmInfoBarDelegate(tab_contents), | ||||
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 25 | host_(host) { |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 26 | } |
27 | |||||
28 | AutoFillCCInfoBarDelegate::~AutoFillCCInfoBarDelegate() { | ||||
29 | } | ||||
30 | |||||
31 | bool AutoFillCCInfoBarDelegate::ShouldExpire( | ||||
32 | const NavigationController::LoadCommittedDetails& details) const { | ||||
33 | // The user has submitted a form, causing the page to navigate elsewhere. We | ||||
34 | // don't want the infobar to be expired at this point, because the user won't | ||||
35 | // get a chance to answer the question. | ||||
36 | return false; | ||||
37 | } | ||||
38 | |||||
39 | void AutoFillCCInfoBarDelegate::InfoBarClosed() { | ||||
40 | if (host_) { | ||||
41 | host_->OnInfoBarClosed(false); | ||||
42 | host_ = NULL; | ||||
43 | } | ||||
[email protected] | 0d04639d | 2010-09-21 20:14:26 | [diff] [blame] | 44 | delete this; |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 45 | } |
46 | |||||
[email protected] | e23d3a3 | 2010-08-13 19:39:58 | [diff] [blame] | 47 | string16 AutoFillCCInfoBarDelegate::GetMessageText() const { |
48 | return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); | ||||
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 49 | } |
50 | |||||
51 | SkBitmap* AutoFillCCInfoBarDelegate::GetIcon() const { | ||||
52 | return ResourceBundle::GetSharedInstance().GetBitmapNamed( | ||||
53 | IDR_INFOBAR_AUTOFILL); | ||||
54 | } | ||||
55 | |||||
56 | int AutoFillCCInfoBarDelegate::GetButtons() const { | ||||
57 | return BUTTON_OK | BUTTON_CANCEL; | ||||
58 | } | ||||
59 | |||||
[email protected] | e23d3a3 | 2010-08-13 19:39:58 | [diff] [blame] | 60 | string16 AutoFillCCInfoBarDelegate::GetButtonLabel( |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 61 | ConfirmInfoBarDelegate::InfoBarButton button) const { |
62 | if (button == BUTTON_OK) | ||||
[email protected] | e23d3a3 | 2010-08-13 19:39:58 | [diff] [blame] | 63 | return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_ACCEPT); |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 64 | else if (button == BUTTON_CANCEL) |
[email protected] | e23d3a3 | 2010-08-13 19:39:58 | [diff] [blame] | 65 | return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_DENY); |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 66 | else |
67 | NOTREACHED(); | ||||
68 | |||||
[email protected] | e23d3a3 | 2010-08-13 19:39:58 | [diff] [blame] | 69 | return string16(); |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 70 | } |
71 | |||||
72 | bool AutoFillCCInfoBarDelegate::Accept() { | ||||
[email protected] | eb36f0d | 2010-07-29 20:54:20 | [diff] [blame] | 73 | UMA_HISTOGRAM_COUNTS("AutoFill.CCInfoBarAccepted", 1); |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 74 | if (host_) { |
75 | host_->OnInfoBarClosed(true); | ||||
76 | host_ = NULL; | ||||
77 | } | ||||
78 | return true; | ||||
79 | } | ||||
80 | |||||
81 | bool AutoFillCCInfoBarDelegate::Cancel() { | ||||
[email protected] | eb36f0d | 2010-07-29 20:54:20 | [diff] [blame] | 82 | UMA_HISTOGRAM_COUNTS("AutoFill.CCInfoBarDenied", 1); |
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 83 | if (host_) { |
84 | host_->OnInfoBarClosed(false); | ||||
85 | host_ = NULL; | ||||
86 | } | ||||
87 | return true; | ||||
88 | } | ||||
89 | |||||
[email protected] | e23d3a3 | 2010-08-13 19:39:58 | [diff] [blame] | 90 | string16 AutoFillCCInfoBarDelegate::GetLinkText() { |
91 | return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_LEARN_MORE); | ||||
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 92 | } |
93 | |||||
94 | bool AutoFillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | ||||
[email protected] | b283a753 | 2010-08-12 21:24:59 | [diff] [blame] | 95 | host_->tab_contents()->OpenURL(GURL(kAutoFillLearnMoreUrl), GURL(), |
96 | NEW_FOREGROUND_TAB, PageTransition::TYPED); | ||||
[email protected] | cf8ebbb | 2010-07-08 22:34:38 | [diff] [blame] | 97 | return false; |
98 | } | ||||
99 | |||||
[email protected] | 71f7579b | 2010-07-17 07:45:19 | [diff] [blame] | 100 | #if defined(OS_WIN) |
101 | InfoBar* AutoFillCCInfoBarDelegate::CreateInfoBar() { | ||||
102 | return CreateAutofillCcInfoBar(this); | ||||
103 | } | ||||
104 | #endif // defined(OS_WIN) | ||||
105 |