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

Side by Side Diff: chrome/browser/ui/autofill/generated_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: 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 #ifndef CHROME_BROWSER_UI_AUTOFILL_GENERATED_CREDIT_CARD_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_GENERATED_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 #include "ui/base/range/range.h"
17 #include "ui/gfx/image/image.h"
18
19 namespace content {
20 class WebContents;
21 }
22
23 namespace user_prefs {
24 class PrefRegistrySyncable;
25 }
26
27 namespace autofill {
28
29 class GeneratedCreditCardBubble;
30
31 // A simple struct of text highlighting range information. If |is_link| is true
32 // this portion of the text should be clickable (and trigger |OnLinkClicked()|).
33 // If |is_link| is false, the text denoted by |range| should be bolded.
34 struct TextRange {
35 // The range of text this TextRange applies to (start and end).
36 ui::Range range;
37 // Whether this text range should be styled like a link (e.g. clickable).
38 bool is_link;
39 // An equality operator for testing.
40 bool operator==(const TextRange& other) const;
41 };
42
43 ////////////////////////////////////////////////////////////////////////////////
44 //
45 // GeneratedCreditCardBubbleController
46 //
47 // A class to control showing and hiding a bubble after a credit card is
48 // generated.
49 //
50 ////////////////////////////////////////////////////////////////////////////////
51 class GeneratedCreditCardBubbleController
52 : public content::WebContentsObserver,
53 public content::WebContentsUserData<GeneratedCreditCardBubbleController> {
54 public:
55 virtual ~GeneratedCreditCardBubbleController();
56
57 // Registers preferences this class cares about.
58 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
59
60 // Show a bubble to educate the user about generated (fronting) cards and how
61 // they are used to bill their original (backing) card.
62 static void Show(content::WebContents* contents,
63 const base::string16& backing_card_name,
64 const base::string16& fronting_card_name);
65
66 // content::WebContentsObserver:
67 virtual void DidNavigateMainFrame(
68 const content::LoadCommittedDetails& details,
69 const content::FrameNavigateParams& params) OVERRIDE;
70
71 // Whether |bubble_| is currently in the process of hiding.
72 bool IsHiding() const;
73
74 // An image that should be shown as an icon in the omnibox and pointed to by
75 // the bubble.
76 gfx::Image AnchorIcon() const;
77
78 // The title of the bubble.
79 const base::string16& TitleText() const;
80
81 // Text in the contents of the bubble.
82 const base::string16& ContentsText() const;
83
84 // Ranges of text styles in the bubble's main content.
85 const std::vector<TextRange>& ContentsTextRanges() const;
86
87 // Called when the anchor for this bubble is clicked.
88 void OnAnchorClicked();
89
90 // Called when the link at the bottom of the bubble is clicked.
91 void OnLinkClicked();
92
93 // The web contents that successfully submitted the Autofill dialog (causing
94 // this bubble to show).
95 content::WebContents* web_contents() { return web_contents_; }
96 const content::WebContents* web_contents() const { return web_contents_; }
97
98 protected:
99 // Creates a bubble connected to |web_contents|.
100 explicit GeneratedCreditCardBubbleController(content::WebContents* contents);
101
102 // Returns a base::WeakPtr that references |this|. Exposed for testing.
103 base::WeakPtr<GeneratedCreditCardBubbleController> GetWeakPtr();
104
105 // Creates and returns an Autofill credit card bubble. Exposed for testing.
106 virtual base::WeakPtr<GeneratedCreditCardBubble> CreateBubble();
107
108 // Returns a weak reference to |bubble_|. May be invalid/NULL.
109 virtual base::WeakPtr<GeneratedCreditCardBubble> bubble();
110
111 // Whether the bubble can show currently.
112 virtual bool CanShow() const;
113
114 // Whether the generated card bubble should be shown initially when showing
115 // the anchor icon. This does not affect whether the generated card's icon
116 // will show in the omnibox.
117 bool ShouldDisplayBubbleInitially() const;
118
119 // Show a bubble to educate the user about generated (fronting) cards and how
120 // they are used to bill their original (backing) card. Exposed for testing.
121 virtual void SetupAndShow(const base::string16& backing_card_name,
122 const base::string16& fronting_card_name);
123
124 private:
125 friend class
126 content::WebContentsUserData<GeneratedCreditCardBubbleController>;
127
128 // An internal helper to show the bubble.
129 void Show(bool was_anchor_click);
130
131 // Updates the omnibox icon that |bubble_| is anchored to.
132 void UpdateAnchor();
133
134 // Hides |bubble_| (if it exists and isn't already hiding).
135 void Hide();
136
137 // The web contents associated with this bubble.
138 content::WebContents* const web_contents_;
139
140 // The generated credit card number and associated backing card.
141 base::string16 fronting_card_name_;
142 base::string16 backing_card_name_;
143
144 // Strings and ranges generated based on |backing_card_name_| and
145 // |fronting_card_name_|.
146 base::string16 title_text_;
147 base::string16 contents_text_;
148 std::vector<TextRange> contents_text_ranges_;
149
150 // A bubble view that's created by calling either |Show*()| method; owned by
151 // the native widget/hierarchy, not this class (though this class must outlive
152 // |bubble_|). NULL in many cases.
153 base::WeakPtr<GeneratedCreditCardBubble> bubble_;
154
155 // Whether the anchor should currently be showing.
156 bool should_show_anchor_;
157
158 // A weak pointer factory for |Create()|.
159 base::WeakPtrFactory<GeneratedCreditCardBubbleController> weak_ptr_factory_;
160
161 DISALLOW_COPY_AND_ASSIGN(GeneratedCreditCardBubbleController);
162 };
163
164 } // namespace autofill
165
166 #endif // CHROME_BROWSER_UI_AUTOFILL_GENERATED_CREDIT_CARD_BUBBLE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698