Home | History | Annotate | Download | only in autofill
      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/logging.h"
      8 #include "chrome/browser/autofill/credit_card.h"
      9 #include "chrome/browser/autofill/personal_data_manager.h"
     10 #include "chrome/browser/ui/browser.h"
     11 #include "chrome/browser/ui/browser_list.h"
     12 #include "grit/generated_resources.h"
     13 #include "grit/theme_resources.h"
     14 #include "ui/base/l10n/l10n_util.h"
     15 #include "ui/base/resource/resource_bundle.h"
     16 
     17 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
     18     TabContents* tab_contents,
     19     const CreditCard* credit_card,
     20     PersonalDataManager* personal_data,
     21     const AutofillMetrics* metric_logger)
     22     : ConfirmInfoBarDelegate(tab_contents),
     23       credit_card_(credit_card),
     24       personal_data_(personal_data),
     25       metric_logger_(metric_logger),
     26       had_user_interaction_(false) {
     27   metric_logger_->Log(AutofillMetrics::CREDIT_CARD_INFOBAR_SHOWN);
     28 }
     29 
     30 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() {
     31 }
     32 
     33 void AutofillCCInfoBarDelegate::LogUserAction(
     34     AutofillMetrics::CreditCardInfoBarMetric user_action) {
     35   DCHECK(!had_user_interaction_);
     36 
     37   metric_logger_->Log(user_action);
     38   had_user_interaction_ = true;
     39 }
     40 
     41 bool AutofillCCInfoBarDelegate::ShouldExpire(
     42     const NavigationController::LoadCommittedDetails& details) const {
     43   // The user has submitted a form, causing the page to navigate elsewhere. We
     44   // don't want the infobar to be expired at this point, because the user won't
     45   // get a chance to answer the question.
     46   return false;
     47 }
     48 
     49 void AutofillCCInfoBarDelegate::InfoBarClosed() {
     50   if (!had_user_interaction_)
     51     LogUserAction(AutofillMetrics::CREDIT_CARD_INFOBAR_IGNORED);
     52 
     53   delete this;
     54 }
     55 
     56 void AutofillCCInfoBarDelegate::InfoBarDismissed() {
     57   LogUserAction(AutofillMetrics::CREDIT_CARD_INFOBAR_DENIED);
     58 }
     59 
     60 SkBitmap* AutofillCCInfoBarDelegate::GetIcon() const {
     61   return ResourceBundle::GetSharedInstance().GetBitmapNamed(
     62       IDR_INFOBAR_AUTOFILL);
     63 }
     64 
     65 InfoBarDelegate::Type AutofillCCInfoBarDelegate::GetInfoBarType() const {
     66   return PAGE_ACTION_TYPE;
     67 }
     68 
     69 string16 AutofillCCInfoBarDelegate::GetMessageText() const {
     70   return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT);
     71 }
     72 
     73 string16 AutofillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const {
     74   return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
     75       IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY);
     76 }
     77 
     78 bool AutofillCCInfoBarDelegate::Accept() {
     79   personal_data_->SaveImportedCreditCard(*credit_card_);
     80   LogUserAction(AutofillMetrics::CREDIT_CARD_INFOBAR_ACCEPTED);
     81   return true;
     82 }
     83 
     84 bool AutofillCCInfoBarDelegate::Cancel() {
     85   LogUserAction(AutofillMetrics::CREDIT_CARD_INFOBAR_DENIED);
     86   return true;
     87 }
     88 
     89 string16 AutofillCCInfoBarDelegate::GetLinkText() {
     90   return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
     91 }
     92 
     93 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
     94   Browser* browser = BrowserList::GetLastActive();
     95   DCHECK(browser);
     96   browser->OpenAutofillHelpTabAndActivate();
     97   return false;
     98 }
     99