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

Side by Side Diff: chrome/browser/ui/autofill/autofill_credit_card_bubble_controller.h

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: merge 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 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string16.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h"
16
17 class Profile;
18
19 namespace content {
20 class WebContents;
21 }
22
23 namespace gfx {
24 class Image;
25 }
26
27 namespace ui {
28 class Range;
29 }
30
31 namespace user_prefs {
32 class PrefRegistrySyncable;
33 }
34
35 namespace autofill {
36
37 class AutofillCreditCardBubble;
38
39 ////////////////////////////////////////////////////////////////////////////////
40 //
41 // AutofillCreditCardBubbleController
42 //
43 // A class to show a bubble after successfully submitting the Autofill dialog.
44 // The bubble is shown when a new credit card is saved locally or to explain
45 // generated Online Wallet cards to the user. This class does not own the shown
46 // bubble, but only has a weak reference to it (it is often owned by the native
47 // platform's ui toolkit).
48 //
49 ////////////////////////////////////////////////////////////////////////////////
50 class AutofillCreditCardBubbleController
51 : public content::WebContentsObserver,
52 public content::WebContentsUserData<AutofillCreditCardBubbleController> {
53 public:
54 virtual ~AutofillCreditCardBubbleController();
55
56 // Registers preferences this class cares about.
57 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
58
59 // Shows a clickable icon in the omnibox that informs the user about generated
60 // (fronting) cards and how they are used to bill their original (backing)
61 // card. Additionally, if |ShouldDisplayBubbleInitially()| is true, the bubble
62 // will be shown initially (doesn't require being clicked).
63 static void ShowGeneratedCardUI(content::WebContents* contents,
64 const base::string16& backing_card_name,
65 const base::string16& fronting_card_name);
66
67 // Show a bubble and clickable omnibox icon notifying the user that new credit
68 // card data has been saved. This bubble always shows initially.
69 static void ShowNewCardSavedBubble(content::WebContents* contents,
70 const base::string16& new_card_name);
71
72 // content::WebContentsObserver implementation.
73 virtual void DidNavigateMainFrame(
74 const content::LoadCommittedDetails& details,
75 const content::FrameNavigateParams& params) OVERRIDE;
76
77 // Returns whether |bubble_| is currently in the process of hiding.
78 bool IsHiding() const;
79
80 // The image that should be shown as an icon in the omnibox.
81 gfx::Image AnchorIcon() const;
82
83 // The title of the bubble. May be empty.
84 base::string16 BubbleTitle() const;
85
86 // The main text of the bubble.
87 base::string16 BubbleText() const;
88
89 // Ranges of text styles in the bubble's main content.
90 const std::vector<ui::Range>& BubbleTextRanges() const;
91
92 // The text of the link shown at the bubble of the bubble.
93 base::string16 LinkText() const;
94
95 // Called when the anchor for this bubble is clicked. Shows a new bubble.
96 void OnAnchorClicked();
97
98 // Called when the link at the bottom of the bubble is clicked. Opens and
99 // navigates a new tab to an informational page and hides the bubble.
100 void OnLinkClicked();
101
102 // The web contents that successfully submitted the Autofill dialog (causing
103 // this bubble to show).
104 content::WebContents* web_contents() { return web_contents_; }
105 const content::WebContents* web_contents() const { return web_contents_; }
106
107 protected:
108 // Creates a bubble connected to |web_contents|. Its content will be based on
109 // which |ShowAs*()| method is called.
110 explicit AutofillCreditCardBubbleController(content::WebContents* contents);
111
112 // Returns a base::WeakPtr that references |this|. Exposed for testing.
113 base::WeakPtr<AutofillCreditCardBubbleController> GetWeakPtr();
114
115 // Creates and returns an Autofill credit card bubble. Exposed for testing.
116 virtual base::WeakPtr<AutofillCreditCardBubble> CreateBubble();
117
118 // Returns a weak reference to |bubble_|. May be invalid/NULL.
119 virtual base::WeakPtr<AutofillCreditCardBubble> bubble();
120
121 // Returns whether the bubble can currently show itself.
122 virtual bool CanShow() const;
123
124 // Whether the generated card bubble should be shown initially when showing
125 // the anchor icon. This does not affect whether the generated card's icon
126 // will show in the omnibox.
127 bool ShouldDisplayBubbleInitially() const;
128
129 // Show a bubble to educate the user about generated (fronting) cards and how
130 // they are used to bill their original (backing) card. Exposed for testing.
131 virtual void ShowAsGeneratedCardBubble(
132 const base::string16& backing_card_name,
133 const base::string16& fronting_card_name);
134
135 // Shows a bubble notifying the user that new credit card data has been saved.
136 // Exposed for testing.
137 virtual void ShowAsNewCardSavedBubble(const base::string16& new_card_name);
138
139 private:
140 friend class content::WebContentsUserData<AutofillCreditCardBubbleController>;
141
142 // Nukes the state of this controller and hides |bubble_| (if it exists).
143 void Reset();
144
145 // Generates the correct bubble text and text highlighting ranges for the
146 // types of bubble being shown. Must be called before showing the bubble.
147 void SetUp();
148
149 // Returns whether the controller has been setup as a certain type of bubble.
150 bool IsSetUp() const;
151
152 // Returns whether the bubble is an educational bubble about generated cards.
153 bool IsGeneratedCardBubble() const;
154
155 // Hides any existing bubbles and creates and shows a new one. Called in
156 // response to successful Autofill dialog submission or anchor click.
157 void Show(bool was_anchor_click);
158
159 // Updates the omnibox icon that |bubble_| will be anchored to.
160 void UpdateAnchor();
161
162 // Hides |bubble_| (if it exists and isn't already hiding).
163 void Hide();
164
165 // The web contents associated with this bubble.
166 content::WebContents* const web_contents_;
167
168 // The newly saved credit card.
169 base::string16 new_card_name_;
170
171 // The generated credit card number and associated backing card.
172 base::string16 fronting_card_name_;
173 base::string16 backing_card_name_;
174
175 // Bubble contents text and text ranges generated in |SetUp()|.
176 base::string16 bubble_text_;
177 std::vector<ui::Range> bubble_text_ranges_;
178
179 // A bubble view that's created by calling either |Show*()| method; owned by
180 // the native widget/hierarchy, not this class (though this class must outlive
181 // |bubble_|). NULL in many cases.
182 base::WeakPtr<AutofillCreditCardBubble> bubble_;
183
184 // Whether the anchor should currently be showing.
185 bool should_show_anchor_;
186
187 // A weak pointer factory for |Create()|.
188 base::WeakPtrFactory<AutofillCreditCardBubbleController> weak_ptr_factory_;
189
190 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardBubbleController);
191 };
192
193 } // namespace autofill
194
195 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698