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.
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13 #include "ui/gfx/image/image.h"
23 class NewCreditCardBubbleView
;
24 class AutofillProfile
;
27 // A simple wrapper that contains descriptive information about a credit card
28 // that should be shown in the content of the bubble.
29 struct CreditCardDescription
{
30 CreditCardDescription();
31 ~CreditCardDescription();
32 // The icon of the credit card issuer (i.e. Visa, Mastercard).
34 // The display name of the card. Shown next to the icon.
36 // A longer description of the card being shown in the bubble.
37 base::string16 description
;
40 ////////////////////////////////////////////////////////////////////////////////
42 // NewCreditCardBubbleController
44 // A class to control showing/hiding a bubble after saved a new card in Chrome.
45 // Here's a visual reference to what this bubble looks like:
47 // @----------------------------------------@
48 // | Bubble title text |
50 // | [ Card icon ] Card name |
51 // | Card description that will probably |
52 // | also span multiple lines. |
54 // | Learn more link |
55 // @----------------------------------------@
57 ////////////////////////////////////////////////////////////////////////////////
58 class NewCreditCardBubbleController
{
60 virtual ~NewCreditCardBubbleController();
62 // Show a bubble informing the user that new credit card data has been saved.
63 // This bubble points to the settings menu. Ownership of |new_card|
64 // and |billing_profile| are transferred by this call.
65 static void Show(content::WebContents
* web_contents
,
66 scoped_ptr
<CreditCard
> new_card
,
67 scoped_ptr
<AutofillProfile
> billing_profile
);
69 // The bubble's title text.
70 const base::string16
& TitleText() const;
72 // A card description to show in the bubble.
73 const CreditCardDescription
& CardDescription() const;
75 // The text of the link shown at the bubble of the bubble.
76 const base::string16
& LinkText() const;
78 // Called when |bubble_| is destroyed.
79 void OnBubbleDestroyed();
81 // Called when the link at the bottom of the bubble is clicked.
84 // Returns the profile this bubble is associated with.
85 Profile
* profile() { return profile_
; }
87 // Returns the WebContents this bubble is associated with.
88 content::WebContents
* web_contents() { return web_contents_
; }
91 // Create a bubble attached to |profile|.
92 explicit NewCreditCardBubbleController(content::WebContents
* web_contents
);
94 // Creates and returns an Autofill credit card bubble. Exposed for testing.
95 virtual base::WeakPtr
<NewCreditCardBubbleView
> CreateBubble();
97 // Returns a weak reference to |bubble_|. May be invalid/NULL.
98 virtual base::WeakPtr
<NewCreditCardBubbleView
> bubble();
100 // Show a bubble notifying the user that new credit card data has been saved.
101 // Exposed for testing.
102 virtual void SetupAndShow(scoped_ptr
<CreditCard
> new_card
,
103 scoped_ptr
<AutofillProfile
> billing_profile
);
106 friend class NewCreditCardBubbleCocoaUnitTest
;
108 // Hides |bubble_| if it exists.
111 // The profile this bubble is associated with.
112 // TODO(dbeam): Break Views dependency on Profile and remove |profile_|.
113 Profile
* const profile_
;
115 // The web contents associated with this bubble.
116 content::WebContents
* const web_contents_
;
118 // The newly saved credit card and assocated billing information.
119 scoped_ptr
<CreditCard
> new_card_
;
120 scoped_ptr
<AutofillProfile
> billing_profile_
;
122 // The title text of the bubble.
123 const base::string16 title_text_
;
125 // The bubble's link text.
126 const base::string16 link_text_
;
128 // Strings and descriptions that are generated based on |new_card_| and
129 // |billing_profile_|.
130 struct CreditCardDescription card_desc_
;
132 // A bubble view that's created by calling either |Show*()| method; owned by
133 // the native widget/hierarchy, not this class (though this class must outlive
134 // |bubble_|). NULL in many cases.
135 base::WeakPtr
<NewCreditCardBubbleView
> bubble_
;
137 // A weak pointer factory for |Create()|.
138 base::WeakPtrFactory
<NewCreditCardBubbleController
> weak_ptr_factory_
;
140 DISALLOW_COPY_AND_ASSIGN(NewCreditCardBubbleController
);
143 } // namespace autofill
145 #endif // CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_