OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
16 #include "ui/base/range/range.h" | |
17 #include "ui/gfx/image/image.h" | |
16 | 18 |
17 class Profile; | 19 class Profile; |
18 | 20 |
19 namespace content { | 21 namespace content { |
20 class WebContents; | 22 class WebContents; |
21 } | 23 } |
22 | 24 |
23 namespace gfx { | |
24 class Image; | |
25 } | |
26 | |
27 namespace ui { | |
28 class Range; | |
29 } | |
30 | |
31 namespace user_prefs { | 25 namespace user_prefs { |
32 class PrefRegistrySyncable; | 26 class PrefRegistrySyncable; |
33 } | 27 } |
34 | 28 |
35 namespace autofill { | 29 namespace autofill { |
36 | 30 |
37 class AutofillCreditCardBubble; | 31 class AutofillCreditCardBubble; |
32 class AutofillProfile; | |
33 class CreditCard; | |
34 | |
35 // A simple wrapper that contains descriptive information about a credit card | |
36 // that should be shown in the content of the bubble. | |
37 struct CreditCardDescription { | |
38 CreditCardDescription(); | |
39 ~CreditCardDescription(); | |
40 // The icon of the credit card issuer (i.e. Visa, Mastercard). | |
41 gfx::Image icon; | |
42 // The title text, quickly describing the card, shown next to the icon. | |
43 base::string16 title; | |
44 // A longer description of the card being shown in the bubble. | |
45 base::string16 description; | |
46 }; | |
47 | |
48 // A simple struct of text highlighting range information. If |is_link| is true | |
49 // this portion of the text should be clickable (and trigger |OnLinkClicked()|). | |
50 // If |is_link| is false, the text denoted by |range| should be bolded. | |
51 struct TextRange { | |
52 // The range of text this TextRange applies to (start and end). | |
53 ui::Range range; | |
54 // Whether this text range should be styled like a link (e.g. clickable). | |
55 bool is_link; | |
56 }; | |
38 | 57 |
39 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
40 // | 59 // |
41 // AutofillCreditCardBubbleController | 60 // AutofillCreditCardBubbleController |
42 // | 61 // |
43 // A class to show a bubble after successfully submitting the Autofill dialog. | 62 // 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 | 63 // 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 | 64 // 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 | 65 // bubble, but only has a weak reference to it (it is often owned by the native |
47 // platform's ui toolkit). | 66 // platform's ui toolkit). |
48 // | 67 // |
68 // Here's a visual reference: | |
69 // | |
70 // /---------------------------------------\ | |
71 // | Title text | | |
72 // | | | |
73 // | Header text that will probably span | | |
Evan Stade
2013/08/02 16:29:45
I object to this being called "header" text.
Dan Beam
2013/08/06 02:41:35
Done.
| |
74 // | multiple lines and have bolded text | | |
75 // | or links inline. | | |
76 // | | | |
77 // | [ Card icon ] Card title | | |
78 // | Card description that will probably | | |
79 // | also span multiple lines. | | |
80 // | | | |
81 // | Learn more link | | |
82 // \---------------------------------------/ | |
83 // | |
84 // NOTE: that basically any of these sections can be (and are) empty in some | |
85 // variation of this bubble. | |
86 // | |
49 //////////////////////////////////////////////////////////////////////////////// | 87 //////////////////////////////////////////////////////////////////////////////// |
50 class AutofillCreditCardBubbleController | 88 class AutofillCreditCardBubbleController |
51 : public content::WebContentsObserver, | 89 : public content::WebContentsObserver, |
52 public content::WebContentsUserData<AutofillCreditCardBubbleController> { | 90 public content::WebContentsUserData<AutofillCreditCardBubbleController> { |
53 public: | 91 public: |
54 virtual ~AutofillCreditCardBubbleController(); | 92 virtual ~AutofillCreditCardBubbleController(); |
55 | 93 |
56 // Registers preferences this class cares about. | 94 // Registers preferences this class cares about. |
57 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); | 95 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); |
58 | 96 |
59 // Shows a clickable icon in the omnibox that informs the user about generated | 97 // Show a bubble to educate the user about generated (fronting) cards and how |
60 // (fronting) cards and how they are used to bill their original (backing) | 98 // they are used to bill their original (backing) card. |
61 // card. Additionally, if |ShouldDisplayBubbleInitially()| is true, the bubble | 99 static void ShowGeneratedCardBubble(content::WebContents* contents, |
62 // will be shown initially (doesn't require being clicked). | 100 const base::string16& backing_card_name, |
63 static void ShowGeneratedCardUI(content::WebContents* contents, | 101 const base::string16& fronting_card_name); |
64 const base::string16& backing_card_name, | |
65 const base::string16& fronting_card_name); | |
66 | 102 |
67 // Show a bubble and clickable omnibox icon notifying the user that new credit | 103 // Show a bubble informing the user that new credit card data has been saved. |
68 // card data has been saved. This bubble always shows initially. | 104 // This bubble points to the settings menu. Ownership of |new_card| |
69 static void ShowNewCardSavedBubble(content::WebContents* contents, | 105 // and |billing_profile| are transferred by this call. |
70 const base::string16& new_card_name); | 106 static void ShowNewCardSavedBubble( |
107 content::WebContents* contents, | |
108 scoped_ptr<CreditCard> new_card, | |
109 scoped_ptr<AutofillProfile> billing_profile); | |
71 | 110 |
72 // content::WebContentsObserver implementation. | 111 // content::WebContentsObserver: |
73 virtual void DidNavigateMainFrame( | 112 virtual void DidNavigateMainFrame( |
74 const content::LoadCommittedDetails& details, | 113 const content::LoadCommittedDetails& details, |
75 const content::FrameNavigateParams& params) OVERRIDE; | 114 const content::FrameNavigateParams& params) OVERRIDE; |
76 | 115 |
77 // Whether |bubble_| is currently in the process of hiding. | 116 // Whether |bubble_| is currently in the process of hiding. |
78 bool IsHiding() const; | 117 bool IsHiding() const; |
79 | 118 |
119 // Returns whether the bubble should be anchored to the setting menu or not. | |
120 bool AnchorToSettingsMenu() const; | |
121 | |
80 // An image that should be shown as an icon in the omnibox and pointed to by | 122 // An image that should be shown as an icon in the omnibox and pointed to by |
81 // the bubble. | 123 // the bubble. |
82 gfx::Image AnchorIcon() const; | 124 gfx::Image AnchorIcon() const; |
83 | 125 |
84 // The title of the bubble. May be empty. | 126 // The title of the bubble. May be empty. |
85 base::string16 BubbleTitle() const; | 127 const base::string16& TitleText() const; |
86 | 128 |
87 // The main text of the bubble. | 129 // Text in the contents of the bubble; above any card descriptions. |
88 base::string16 BubbleText() const; | 130 const base::string16& HeaderText() const; |
89 | 131 |
90 // Ranges of text styles in the bubble's main content. | 132 // Ranges of text styles in the bubble's main content. May be empty. |
91 const std::vector<ui::Range>& BubbleTextRanges() const; | 133 const std::vector<TextRange>& HeaderTextRanges() const; |
92 | 134 |
93 // The text of the link shown at the bubble of the bubble. | 135 // A card description to show in the bubble. May be NULL. |
94 base::string16 LinkText() const; | 136 const CreditCardDescription* Description() const; |
137 | |
138 // The text of the link shown at the bubble of the bubble. May be empty. | |
139 const base::string16& LinkText() const; | |
95 | 140 |
96 // Called when the anchor for this bubble is clicked. | 141 // Called when the anchor for this bubble is clicked. |
97 void OnAnchorClicked(); | 142 void OnAnchorClicked(); |
98 | 143 |
144 // Called when |bubble_| is destroyed. | |
145 void OnBubbleDestroyed(); | |
146 | |
99 // Called when the link at the bottom of the bubble is clicked. | 147 // Called when the link at the bottom of the bubble is clicked. |
100 void OnLinkClicked(); | 148 void OnLinkClicked(); |
101 | 149 |
102 // The web contents that successfully submitted the Autofill dialog (causing | 150 // The web contents that successfully submitted the Autofill dialog (causing |
103 // this bubble to show). | 151 // this bubble to show). |
104 content::WebContents* web_contents() { return web_contents_; } | 152 content::WebContents* web_contents() { return web_contents_; } |
105 const content::WebContents* web_contents() const { return web_contents_; } | 153 const content::WebContents* web_contents() const { return web_contents_; } |
106 | 154 |
107 protected: | 155 protected: |
108 // Create a bubble connected to |web_contents|. Its content will be based on | 156 // Create a bubble connected to |web_contents|. Its content will be based on |
(...skipping 18 matching lines...) Expand all Loading... | |
127 bool ShouldDisplayBubbleInitially() const; | 175 bool ShouldDisplayBubbleInitially() const; |
128 | 176 |
129 // Show a bubble to educate the user about generated (fronting) cards and how | 177 // 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. | 178 // they are used to bill their original (backing) card. Exposed for testing. |
131 virtual void ShowAsGeneratedCardBubble( | 179 virtual void ShowAsGeneratedCardBubble( |
132 const base::string16& backing_card_name, | 180 const base::string16& backing_card_name, |
133 const base::string16& fronting_card_name); | 181 const base::string16& fronting_card_name); |
134 | 182 |
135 // Show a bubble notifying the user that new credit card data has been saved. | 183 // Show a bubble notifying the user that new credit card data has been saved. |
136 // Exposed for testing. | 184 // Exposed for testing. |
137 virtual void ShowAsNewCardSavedBubble(const base::string16& new_card_name); | 185 virtual void ShowAsNewCardSavedBubble( |
186 scoped_ptr<CreditCard> new_card, | |
187 scoped_ptr<AutofillProfile> billing_profile); | |
138 | 188 |
139 private: | 189 private: |
140 friend class content::WebContentsUserData<AutofillCreditCardBubbleController>; | 190 friend class content::WebContentsUserData<AutofillCreditCardBubbleController>; |
141 | 191 |
142 // Nukes the state of this controller and hides |bubble_| (if it exists). | 192 // Nukes the state of this controller and hides |bubble_| (if it exists). |
143 void Reset(); | 193 void Reset(); |
144 | 194 |
145 // Generate bubble text and ranges now that this class knows which type of | 195 // Generate bubble text and ranges now that this class knows which type of |
146 // bubble it should be shown as. Called from |ShowAs*()| methods. | 196 // bubble it should be shown as. Called from |ShowAs*()| methods. |
147 void SetUp(); | 197 void SetUp(); |
(...skipping 10 matching lines...) Expand all Loading... | |
158 | 208 |
159 // Update the omnibox icon that |bubble_| will be anchored to. | 209 // Update the omnibox icon that |bubble_| will be anchored to. |
160 void UpdateAnchor(); | 210 void UpdateAnchor(); |
161 | 211 |
162 // Hides |bubble_| (if it exists and isn't already hiding). | 212 // Hides |bubble_| (if it exists and isn't already hiding). |
163 void Hide(); | 213 void Hide(); |
164 | 214 |
165 // The web contents associated with this bubble. | 215 // The web contents associated with this bubble. |
166 content::WebContents* const web_contents_; | 216 content::WebContents* const web_contents_; |
167 | 217 |
168 // The newly saved credit card. | 218 // The newly saved credit card and assocated billing information. |
169 base::string16 new_card_name_; | 219 scoped_ptr<CreditCard> new_card_; |
220 scoped_ptr<AutofillProfile> billing_profile_; | |
170 | 221 |
171 // The generated credit card number and associated backing card. | 222 // The generated credit card number and associated backing card. |
172 base::string16 fronting_card_name_; | 223 base::string16 fronting_card_name_; |
173 base::string16 backing_card_name_; | 224 base::string16 backing_card_name_; |
174 | 225 |
175 // Bubble contents text and text ranges generated in |SetUp()|. | 226 // String, ranges, and descriptions generated in |SetUp()|. |
176 base::string16 bubble_text_; | 227 base::string16 title_text_; |
177 std::vector<ui::Range> bubble_text_ranges_; | 228 base::string16 header_text_; |
229 std::vector<TextRange> header_text_ranges_; | |
230 scoped_ptr<CreditCardDescription> card_desc_; | |
231 base::string16 link_text_; | |
178 | 232 |
179 // A bubble view that's created by calling either |Show*()| method; owned by | 233 // 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 | 234 // the native widget/hierarchy, not this class (though this class must outlive |
181 // |bubble_|). NULL in many cases. | 235 // |bubble_|). NULL in many cases. |
182 base::WeakPtr<AutofillCreditCardBubble> bubble_; | 236 base::WeakPtr<AutofillCreditCardBubble> bubble_; |
183 | 237 |
184 // Whether the anchor should currently be showing. | 238 // Whether the anchor should currently be showing. |
185 bool should_show_anchor_; | 239 bool should_show_anchor_; |
186 | 240 |
187 // A weak pointer factory for |Create()|. | 241 // A weak pointer factory for |Create()|. |
188 base::WeakPtrFactory<AutofillCreditCardBubbleController> weak_ptr_factory_; | 242 base::WeakPtrFactory<AutofillCreditCardBubbleController> weak_ptr_factory_; |
189 | 243 |
190 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardBubbleController); | 244 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardBubbleController); |
191 }; | 245 }; |
192 | 246 |
193 } // namespace autofill | 247 } // namespace autofill |
194 | 248 |
195 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_ | 249 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_CREDIT_CARD_BUBBLE_CONTROLLER_H_ |
OLD | NEW |