Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / autofill / core / browser / autofill_cc_infobar_delegate.cc
blob0c6e909944433a93cdcbcc005a47d436f7219af4
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.
5 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h"
7 #include "base/logging.h"
8 #include "components/autofill/core/browser/autofill_client.h"
9 #include "components/autofill/core/browser/credit_card.h"
10 #include "components/autofill/core/browser/personal_data_manager.h"
11 #include "components/autofill/core/common/autofill_constants.h"
12 #include "components/infobars/core/infobar.h"
13 #include "components/infobars/core/infobar_manager.h"
14 #include "grit/components_scaled_resources.h"
15 #include "grit/components_strings.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/vector_icons_public.h"
18 #include "url/gurl.h"
20 namespace autofill {
22 // static
23 void AutofillCCInfoBarDelegate::Create(
24 infobars::InfoBarManager* infobar_manager,
25 AutofillClient* autofill_client,
26 const base::Closure& save_card_callback) {
27 infobar_manager->AddInfoBar(
28 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
29 new AutofillCCInfoBarDelegate(autofill_client, save_card_callback))));
32 AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
33 AutofillClient* autofill_client,
34 const base::Closure& save_card_callback)
35 : ConfirmInfoBarDelegate(),
36 autofill_client_(autofill_client),
37 save_card_callback_(save_card_callback),
38 had_user_interaction_(false) {
39 AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN);
42 AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() {
43 if (!had_user_interaction_)
44 LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
47 void AutofillCCInfoBarDelegate::LogUserAction(
48 AutofillMetrics::InfoBarMetric user_action) {
49 DCHECK(!had_user_interaction_);
51 AutofillMetrics::LogCreditCardInfoBarMetric(user_action);
52 had_user_interaction_ = true;
55 infobars::InfoBarDelegate::Type
56 AutofillCCInfoBarDelegate::GetInfoBarType() const {
57 return PAGE_ACTION_TYPE;
60 int AutofillCCInfoBarDelegate::GetIconId() const {
61 return IDR_INFOBAR_AUTOFILL_CC;
64 gfx::VectorIconId AutofillCCInfoBarDelegate::GetVectorIconId() const {
65 #if !defined(OS_MACOSX) && !defined(OS_IOS) && !defined(OS_ANDROID)
66 return gfx::VectorIconId::AUTOFILL;
67 #else
68 return gfx::VectorIconId::VECTOR_ICON_NONE;
69 #endif
72 bool AutofillCCInfoBarDelegate::ShouldExpire(
73 const NavigationDetails& details) const {
74 // The user has submitted a form, causing the page to navigate elsewhere. We
75 // don't want the infobar to be expired at this point, because the user won't
76 // get a chance to answer the question.
77 return false;
80 void AutofillCCInfoBarDelegate::InfoBarDismissed() {
81 LogUserAction(AutofillMetrics::INFOBAR_DENIED);
84 base::string16 AutofillCCInfoBarDelegate::GetMessageText() const {
85 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT);
88 base::string16 AutofillCCInfoBarDelegate::GetButtonLabel(
89 InfoBarButton button) const {
90 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
91 IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY);
94 bool AutofillCCInfoBarDelegate::Accept() {
95 save_card_callback_.Run();
96 save_card_callback_.Reset();
97 LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED);
98 return true;
101 bool AutofillCCInfoBarDelegate::Cancel() {
102 LogUserAction(AutofillMetrics::INFOBAR_DENIED);
103 return true;
106 base::string16 AutofillCCInfoBarDelegate::GetLinkText() const {
107 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
110 bool AutofillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
111 autofill_client_->LinkClicked(
112 GURL(autofill::kHelpURL),
113 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition);
115 return false;
118 } // namespace autofill