autofill_cc_infobar_delegate.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2011 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 "base/metrics/histogram.h" 8#include "chrome/browser/autofill/autofill_cc_infobar.h" 9#include "chrome/browser/autofill/autofill_manager.h" 10#include "chrome/browser/browser_list.h" 11#include "grit/generated_resources.h" 12#include "grit/theme_resources.h" 13#include "ui/base/l10n/l10n_util.h" 14#include "ui/base/resource/resource_bundle.h" 15 16AutoFillCCInfoBarDelegate::AutoFillCCInfoBarDelegate(TabContents* tab_contents, 17 AutoFillManager* host) 18 : ConfirmInfoBarDelegate(tab_contents), 19 host_(host) { 20} 21 22AutoFillCCInfoBarDelegate::~AutoFillCCInfoBarDelegate() { 23} 24 25bool AutoFillCCInfoBarDelegate::ShouldExpire( 26 const NavigationController::LoadCommittedDetails& details) const { 27 // The user has submitted a form, causing the page to navigate elsewhere. We 28 // don't want the infobar to be expired at this point, because the user won't 29 // get a chance to answer the question. 30 return false; 31} 32 33void AutoFillCCInfoBarDelegate::InfoBarClosed() { 34 if (host_) { 35 host_->OnInfoBarClosed(false); 36 host_ = NULL; 37 } 38 delete this; 39} 40 41SkBitmap* AutoFillCCInfoBarDelegate::GetIcon() const { 42 return ResourceBundle::GetSharedInstance().GetBitmapNamed( 43 IDR_INFOBAR_AUTOFILL); 44} 45 46InfoBarDelegate::Type AutoFillCCInfoBarDelegate::GetInfoBarType() const { 47 return PAGE_ACTION_TYPE; 48} 49 50string16 AutoFillCCInfoBarDelegate::GetMessageText() const { 51 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); 52} 53 54string16 AutoFillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { 55 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? 56 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); 57} 58 59bool AutoFillCCInfoBarDelegate::Accept() { 60 UMA_HISTOGRAM_COUNTS("AutoFill.CCInfoBarAccepted", 1); 61 if (host_) { 62 host_->OnInfoBarClosed(true); 63 host_ = NULL; 64 } 65 return true; 66} 67 68bool AutoFillCCInfoBarDelegate::Cancel() { 69 UMA_HISTOGRAM_COUNTS("AutoFill.CCInfoBarDenied", 1); 70 return true; 71} 72 73string16 AutoFillCCInfoBarDelegate::GetLinkText() { 74 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_LEARN_MORE); 75} 76 77bool AutoFillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { 78 Browser* browser = BrowserList::GetLastActive(); 79 DCHECK(browser); 80 browser->OpenAutoFillHelpTabAndActivate(); 81 return false; 82} 83 84#if defined(OS_WIN) 85InfoBar* AutoFillCCInfoBarDelegate::CreateInfoBar() { 86 return CreateAutofillCcInfoBar(this); 87} 88#endif // defined(OS_WIN) 89