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_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_ 7 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" 14 15 class Profile; 16 17 namespace content { 18 class WebContents; 19 } 20 21 namespace autofill { 22 23 class NewCreditCardBubbleView; 24 class AutofillProfile; 25 class CreditCard; 26 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). 33 gfx::Image icon; 34 // The display name of the card. Shown next to the icon. 35 base::string16 name; 36 // A longer description of the card being shown in the bubble. 37 base::string16 description; 38 }; 39 40 //////////////////////////////////////////////////////////////////////////////// 41 // 42 // NewCreditCardBubbleController 43 // 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: 46 // 47 // @----------------------------------------@ 48 // | Bubble title text | 49 // | | 50 // | [ Card icon ] Card name | 51 // | Card description that will probably | 52 // | also span multiple lines. | 53 // | | 54 // | Learn more link | 55 // @----------------------------------------@ 56 // 57 //////////////////////////////////////////////////////////////////////////////// 58 class NewCreditCardBubbleController { 59 public: 60 virtual ~NewCreditCardBubbleController(); 61 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); 68 69 // The bubble's title text. 70 const base::string16& TitleText() const; 71 72 // A card description to show in the bubble. 73 const CreditCardDescription& CardDescription() const; 74 75 // The text of the link shown at the bubble of the bubble. 76 const base::string16& LinkText() const; 77 78 // Called when |bubble_| is destroyed. 79 void OnBubbleDestroyed(); 80 81 // Called when the link at the bottom of the bubble is clicked. 82 void OnLinkClicked(); 83 84 // Returns the profile this bubble is associated with. profile()85 Profile* profile() { return profile_; } 86 87 // Returns the WebContents this bubble is associated with. web_contents()88 content::WebContents* web_contents() { return web_contents_; } 89 90 protected: 91 // Create a bubble attached to |profile|. 92 explicit NewCreditCardBubbleController(content::WebContents* web_contents); 93 94 // Creates and returns an Autofill credit card bubble. Exposed for testing. 95 virtual base::WeakPtr<NewCreditCardBubbleView> CreateBubble(); 96 97 // Returns a weak reference to |bubble_|. May be invalid/NULL. 98 virtual base::WeakPtr<NewCreditCardBubbleView> bubble(); 99 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); 104 105 private: 106 friend class NewCreditCardBubbleCocoaUnitTest; 107 108 // Hides |bubble_| if it exists. 109 void Hide(); 110 111 // The profile this bubble is associated with. 112 // TODO(dbeam): Break Views dependency on Profile and remove |profile_|. 113 Profile* const profile_; 114 115 // The web contents associated with this bubble. 116 content::WebContents* const web_contents_; 117 118 // The newly saved credit card and assocated billing information. 119 scoped_ptr<CreditCard> new_card_; 120 scoped_ptr<AutofillProfile> billing_profile_; 121 122 // The title text of the bubble. 123 const base::string16 title_text_; 124 125 // The bubble's link text. 126 const base::string16 link_text_; 127 128 // Strings and descriptions that are generated based on |new_card_| and 129 // |billing_profile_|. 130 struct CreditCardDescription card_desc_; 131 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_; 136 137 // A weak pointer factory for |Create()|. 138 base::WeakPtrFactory<NewCreditCardBubbleController> weak_ptr_factory_; 139 140 DISALLOW_COPY_AND_ASSIGN(NewCreditCardBubbleController); 141 }; 142 143 } // namespace autofill 144 145 #endif // CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_ 146