BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / autofill / new_credit_card_bubble_controller.cc
blobc61ebbbbfc84e0e51728429b7c15c64186933518
1 // Copyright 2013 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 "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h"
7 #include <string>
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
14 #include "chrome/browser/ui/autofill/new_credit_card_bubble_view.h"
15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/chrome_pages.h"
17 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/chromium_strings.h"
20 #include "chrome/grit/generated_resources.h"
21 #include "components/autofill/core/browser/autofill_profile.h"
22 #include "components/autofill/core/browser/credit_card.h"
23 #include "components/autofill/core/browser/detail_input.h"
24 #include "content/public/browser/web_contents.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h"
28 namespace autofill {
30 CreditCardDescription::CreditCardDescription() {}
31 CreditCardDescription::~CreditCardDescription() {}
33 NewCreditCardBubbleController::~NewCreditCardBubbleController() {
34 Hide();
37 // static
38 void NewCreditCardBubbleController::Show(
39 content::WebContents* web_contents,
40 scoped_ptr<CreditCard> new_card,
41 scoped_ptr<AutofillProfile> billing_profile) {
42 (new NewCreditCardBubbleController(web_contents))->SetupAndShow(
43 new_card.Pass(),
44 billing_profile.Pass());
47 const base::string16& NewCreditCardBubbleController::TitleText() const {
48 return title_text_;
51 const CreditCardDescription& NewCreditCardBubbleController::CardDescription()
52 const {
53 return card_desc_;
56 const base::string16& NewCreditCardBubbleController::LinkText() const {
57 return link_text_;
60 void NewCreditCardBubbleController::OnBubbleDestroyed() {
61 delete this;
64 void NewCreditCardBubbleController::OnLinkClicked() {
65 chrome::ShowSettingsSubPageForProfile(profile_, chrome::kAutofillSubPage);
66 Hide();
69 NewCreditCardBubbleController::NewCreditCardBubbleController(
70 content::WebContents* web_contents)
71 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
72 web_contents_(web_contents),
73 title_text_(l10n_util::GetStringUTF16(
74 IDS_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_TITLE)),
75 link_text_(l10n_util::GetStringUTF16(
76 IDS_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_LINK)),
77 weak_ptr_factory_(this) {}
79 base::WeakPtr<NewCreditCardBubbleView> NewCreditCardBubbleController::
80 CreateBubble() {
81 return NewCreditCardBubbleView::Create(this);
84 base::WeakPtr<NewCreditCardBubbleView> NewCreditCardBubbleController::
85 bubble() {
86 return bubble_;
89 void NewCreditCardBubbleController::SetupAndShow(
90 scoped_ptr<CreditCard> new_card,
91 scoped_ptr<AutofillProfile> billing_profile) {
92 DCHECK(new_card);
93 DCHECK(billing_profile);
95 new_card_ = new_card.Pass();
96 billing_profile_ = billing_profile.Pass();
98 const base::string16 card_number =
99 new_card_->GetRawInfo(CREDIT_CARD_NUMBER);
100 ui::ResourceBundle& rb = ResourceBundle::GetSharedInstance();
101 card_desc_.icon = rb.GetImageNamed(
102 CreditCard::IconResourceId(CreditCard::GetCreditCardType(card_number)));
103 card_desc_.name = new_card_->TypeAndLastFourDigits();
105 AutofillProfileWrapper wrapper(billing_profile_.get());
106 base::string16 unused;
107 wrapper.GetDisplayText(&card_desc_.description, &unused);
109 bubble_ = CreateBubble();
110 if (!bubble_) {
111 // TODO(dbeam): Make a bubble on all applicable platforms.
112 delete this;
113 return;
116 bubble_->Show();
119 void NewCreditCardBubbleController::Hide() {
120 if (bubble_)
121 bubble_->Hide();
124 } // namespace autofill