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

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: 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_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 GeneratedCreditCardBubbleView;
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 // Returns whether |bubble_| is currently in the process of hiding.
72 bool IsHiding() const;
73
74 // Returns the image that should be shown as an icon in the omnibox.
75 gfx::Image AnchorIcon() const;
76
77 // The title of the bubble.
78 const base::string16& TitleText() const;
79
80 // Text in the contents of the bubble.
81 const base::string16& ContentsText() const;
82
83 // Ranges of text styles in the bubble's main content.
84 const std::vector<TextRange>& ContentsTextRanges() const;
85
86 // Called when the anchor for this bubble is clicked. Shows a new bubble.
87 void OnAnchorClicked();
88
89 // Called when the link at the bottom of the bubble is clicked. Opens and
90 // navigates a new tab to an informational page and hides the bubble.
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<GeneratedCreditCardBubbleView> CreateBubble();
107
108 // Returns a weak reference to |bubble_|. May be invalid/NULL.
109 virtual base::WeakPtr<GeneratedCreditCardBubbleView> bubble();
110
111 // Returns whether the bubble can currently show itself.
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 // Generates the correct bubble text and text highlighting ranges and shows a
120 // bubble to educate the user about generated (fronting) cards and how they
121 // are used to bill their original (backing) card. Exposed for testing.
122 virtual void SetupAndShow(const base::string16& backing_card_name,
123 const base::string16& fronting_card_name);
124
125 private:
126 friend class
127 content::WebContentsUserData<GeneratedCreditCardBubbleController>;
128
129 // An internal helper to show the bubble.
130 void Show(bool was_anchor_click);
131
132 // Updates the omnibox icon that |bubble_| is anchored to.
133 void UpdateAnchor();
134
135 // Hides |bubble_| (if it exists and isn't already hiding).
136 void Hide();
137
138 // The web contents associated with this bubble.
139 content::WebContents* const web_contents_;
140
141 // The generated credit card number and associated backing card.
142 base::string16 fronting_card_name_;
143 base::string16 backing_card_name_;
144
145 // The title text of the bubble.
146 const base::string16 title_text_;
147
148 // Strings and ranges generated based on |backing_card_name_| and
149 // |fronting_card_name_|.
150 base::string16 contents_text_;
151 std::vector<TextRange> contents_text_ranges_;
152
153 // A bubble view that's created by calling either |Show*()| method; owned by
154 // the native widget/hierarchy, not this class (though this class must outlive
155 // |bubble_|). NULL in many cases.
156 base::WeakPtr<GeneratedCreditCardBubbleView> bubble_;
157
158 // Whether the anchor should currently be showing.
159 bool should_show_anchor_;
160
161 // A weak pointer factory for |Create()|.
162 base::WeakPtrFactory<GeneratedCreditCardBubbleController> weak_ptr_factory_;
163
164 DISALLOW_COPY_AND_ASSIGN(GeneratedCreditCardBubbleController);
165 };
166
167 } // namespace autofill
168
169 #endif // CHROME_BROWSER_UI_AUTOFILL_GENERATED_CREDIT_CARD_BUBBLE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698