Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: chrome/browser/ui/autofill/new_credit_card_bubble_controller.cc

Issue 21668003: Implement newly saved card bubble for realz and update generated card bubble to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h"
6
7 #include <string>
8
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/new_credit_card_bubble.h"
14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/chrome_pages.h"
16 #include "chrome/browser/ui/host_desktop.h"
17 #include "chrome/common/url_constants.h"
18 #include "components/autofill/core/browser/autofill_profile.h"
19 #include "components/autofill/core/browser/credit_card.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "grit/theme_resources.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h"
25
26 namespace autofill {
27
28 namespace {
29
30 static const int kMaxGeneratedCardTimesToShow = 5;
31 static const char kWalletGeneratedCardLearnMoreLink[] =
32 "http://support.google.com/wallet/bin/answer.py?hl=en&answer=2740044";
33
34 } // namespace
35
36 CreditCardDescription::CreditCardDescription() {}
37 CreditCardDescription::~CreditCardDescription() {}
38
39 NewCreditCardBubbleController::~NewCreditCardBubbleController() {
40 Hide();
41 }
42
43 // static
44 void NewCreditCardBubbleController::Show(
45 Profile* profile,
46 scoped_ptr<CreditCard> new_card,
47 scoped_ptr<AutofillProfile> billing_profile) {
48 (new NewCreditCardBubbleController(profile))->SetupAndShow(
49 new_card.Pass(),
50 billing_profile.Pass());
51 }
52
53 const base::string16& NewCreditCardBubbleController::ContentsText() const {
54 return contents_text_;
55 }
56
57 const CreditCardDescription& NewCreditCardBubbleController::CardDescription()
58 const {
59 return card_desc_;
60 }
61
62 const base::string16& NewCreditCardBubbleController::LinkText() const {
63 return link_text_;
64 }
65
66 void NewCreditCardBubbleController::OnBubbleDestroyed() {
67 delete this;
68 }
69
70 void NewCreditCardBubbleController::OnLinkClicked() {
71 #if !defined(OS_ANDROID)
Evan Stade 2013/08/06 22:06:25 can you ping aruslan to see what plans if any andr
Dan Beam 2013/08/07 02:30:22 the plan is toasts, which seem to need much less c
72 Browser* browser = chrome::FindTabbedBrowser(profile_, false,
73 chrome::GetActiveDesktop());
74 if (browser)
75 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage);
76 #endif
77 Hide();
78 }
79
80 NewCreditCardBubbleController::NewCreditCardBubbleController(Profile* profile)
81 : profile_(profile),
82 contents_text_(l10n_util::GetStringUTF16(
83 IDS_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTENTS)),
84 link_text_(l10n_util::GetStringUTF16(
85 IDS_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_LINK)),
86 weak_ptr_factory_(this) {}
87
88 base::WeakPtr<NewCreditCardBubbleController>
89 NewCreditCardBubbleController::GetWeakPtr() {
90 return weak_ptr_factory_.GetWeakPtr();
91 }
92
93 base::WeakPtr<NewCreditCardBubble> NewCreditCardBubbleController::
94 CreateBubble() {
95 return NewCreditCardBubble::Create(GetWeakPtr());
96 }
97
98 base::WeakPtr<NewCreditCardBubble> NewCreditCardBubbleController::
99 bubble() {
100 return bubble_;
101 }
102
103 void NewCreditCardBubbleController::SetupAndShow(
104 scoped_ptr<CreditCard> new_card,
105 scoped_ptr<AutofillProfile> billing_profile) {
106 DCHECK(new_card);
107 DCHECK(billing_profile);
108
109 new_card_ = new_card.Pass();
110 billing_profile_ = billing_profile.Pass();
111
112 const base::string16 card_number =
113 new_card_->GetRawInfo(CREDIT_CARD_NUMBER);
114 ui::ResourceBundle& rb = ResourceBundle::GetSharedInstance();
115 card_desc_.icon = rb.GetImageNamed(
116 CreditCard::IconResourceId(CreditCard::GetCreditCardType(card_number)));
117 card_desc_.name = new_card_->TypeAndLastFourDigits();
118
119 const base::string16 kNewLine = ASCIIToUTF16("\n");
120 const std::string& locale = g_browser_process->GetApplicationLocale();
121
122 std::vector<AutofillProfile*> profiles;
123 profiles.push_back(billing_profile_.get());
124
125 std::vector<AutofillFieldType> fields;
Evan Stade 2013/08/06 22:06:25 what you want is to create a DataModelWrapper for
Dan Beam 2013/08/07 02:30:22 Done. (but there's no email...)
126 fields.push_back(NAME_BILLING_FULL);
127 fields.push_back(ADDRESS_BILLING_LINE1);
128 fields.push_back(ADDRESS_BILLING_LINE2);
129 fields.push_back(ADDRESS_BILLING_CITY);
130 fields.push_back(ADDRESS_BILLING_STATE);
131
132 std::vector<base::string16> labels;
133 AutofillProfile::CreateInferredLabels(&profiles, &fields, UNKNOWN_TYPE,
134 fields.size(), &labels);
135
136 card_desc_.description = labels.front() + kNewLine +
137 billing_profile_->GetInfo(EMAIL_ADDRESS, locale) + kNewLine +
138 billing_profile_->GetRawInfo(PHONE_BILLING_WHOLE_NUMBER);
139
140 bubble_ = CreateBubble();
141 if (!bubble_) {
142 // TODO(dbeam): Make a bubble on all applicable platforms.
143 delete this;
144 return;
145 }
146
147 bubble_->Show();
148 }
149
150 void NewCreditCardBubbleController::Hide() {
151 if (bubble_)
152 bubble_->Hide();
153 }
154
155 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698