blob: 364bc3f31d0442c3f7305cf611f398a068bc198a [file] [log] [blame]
[email protected]cf8ebbb2010-07-08 22:34:381// 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]eb36f0d2010-07-29 20:54:209#include "base/histogram.h"
[email protected]71f7579b2010-07-17 07:45:1910#include "chrome/browser/autofill/autofill_cc_infobar.h"
[email protected]cf8ebbb2010-07-08 22:34:3811#include "chrome/browser/autofill/autofill_manager.h"
[email protected]37858e52010-08-26 00:22:0212#include "chrome/browser/prefs/pref_service.h"
[email protected]cf8ebbb2010-07-08 22:34:3813#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
22AutoFillCCInfoBarDelegate::AutoFillCCInfoBarDelegate(TabContents* tab_contents,
23 AutoFillManager* host)
24 : ConfirmInfoBarDelegate(tab_contents),
[email protected]cf8ebbb2010-07-08 22:34:3825 host_(host) {
[email protected]cf8ebbb2010-07-08 22:34:3826}
27
28AutoFillCCInfoBarDelegate::~AutoFillCCInfoBarDelegate() {
29}
30
31bool 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
39void AutoFillCCInfoBarDelegate::InfoBarClosed() {
40 if (host_) {
41 host_->OnInfoBarClosed(false);
42 host_ = NULL;
43 }
[email protected]0d04639d2010-09-21 20:14:2644 delete this;
[email protected]cf8ebbb2010-07-08 22:34:3845}
46
[email protected]e23d3a32010-08-13 19:39:5847string16 AutoFillCCInfoBarDelegate::GetMessageText() const {
48 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT);
[email protected]cf8ebbb2010-07-08 22:34:3849}
50
51SkBitmap* AutoFillCCInfoBarDelegate::GetIcon() const {
52 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
53 IDR_INFOBAR_AUTOFILL);
54}
55
56int AutoFillCCInfoBarDelegate::GetButtons() const {
57 return BUTTON_OK | BUTTON_CANCEL;
58}
59
[email protected]e23d3a32010-08-13 19:39:5860string16 AutoFillCCInfoBarDelegate::GetButtonLabel(
[email protected]cf8ebbb2010-07-08 22:34:3861 ConfirmInfoBarDelegate::InfoBarButton button) const {
62 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:5863 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_ACCEPT);
[email protected]cf8ebbb2010-07-08 22:34:3864 else if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:5865 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_DENY);
[email protected]cf8ebbb2010-07-08 22:34:3866 else
67 NOTREACHED();
68
[email protected]e23d3a32010-08-13 19:39:5869 return string16();
[email protected]cf8ebbb2010-07-08 22:34:3870}
71
72bool AutoFillCCInfoBarDelegate::Accept() {
[email protected]eb36f0d2010-07-29 20:54:2073 UMA_HISTOGRAM_COUNTS("AutoFill.CCInfoBarAccepted", 1);
[email protected]cf8ebbb2010-07-08 22:34:3874 if (host_) {
75 host_->OnInfoBarClosed(true);
76 host_ = NULL;
77 }
78 return true;
79}
80
81bool AutoFillCCInfoBarDelegate::Cancel() {
[email protected]eb36f0d2010-07-29 20:54:2082 UMA_HISTOGRAM_COUNTS("AutoFill.CCInfoBarDenied", 1);
[email protected]cf8ebbb2010-07-08 22:34:3883 if (host_) {
84 host_->OnInfoBarClosed(false);
85 host_ = NULL;
86 }
87 return true;
88}
89
[email protected]e23d3a32010-08-13 19:39:5890string16 AutoFillCCInfoBarDelegate::GetLinkText() {
91 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_LEARN_MORE);
[email protected]cf8ebbb2010-07-08 22:34:3892}
93
94bool AutoFillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
[email protected]b283a7532010-08-12 21:24:5995 host_->tab_contents()->OpenURL(GURL(kAutoFillLearnMoreUrl), GURL(),
96 NEW_FOREGROUND_TAB, PageTransition::TYPED);
[email protected]cf8ebbb2010-07-08 22:34:3897 return false;
98}
99
[email protected]71f7579b2010-07-17 07:45:19100#if defined(OS_WIN)
101InfoBar* AutoFillCCInfoBarDelegate::CreateInfoBar() {
102 return CreateAutofillCcInfoBar(this);
103}
104#endif // defined(OS_WIN)
105