Home | History | Annotate | Download | only in autofill
      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 autofill {
     18 
     19 class NewCreditCardBubbleView;
     20 class AutofillProfile;
     21 class CreditCard;
     22 
     23 // A simple wrapper that contains descriptive information about a credit card
     24 // that should be shown in the content of the bubble.
     25 struct CreditCardDescription {
     26  CreditCardDescription();
     27  ~CreditCardDescription();
     28  // The icon of the credit card issuer (i.e. Visa, Mastercard).
     29  gfx::Image icon;
     30  // The display name of the card. Shown next to the icon.
     31  base::string16 name;
     32  // A longer description of the card being shown in the bubble.
     33  base::string16 description;
     34 };
     35 
     36 ////////////////////////////////////////////////////////////////////////////////
     37 //
     38 // NewCreditCardBubbleController
     39 //
     40 //  A class to control showing/hiding a bubble after saved a new card in Chrome.
     41 //  Here's a visual reference to what this bubble looks like:
     42 //
     43 //  @----------------------------------------@
     44 //  |  Bubble title text                     |
     45 //  |                                        |
     46 //  |  [ Card icon ] Card name               |
     47 //  |  Card description that will probably   |
     48 //  |  also span multiple lines.             |
     49 //  |                                        |
     50 //  |  Learn more link                       |
     51 //  @----------------------------------------@
     52 //
     53 ////////////////////////////////////////////////////////////////////////////////
     54 class NewCreditCardBubbleController {
     55  public:
     56   virtual ~NewCreditCardBubbleController();
     57 
     58   // Show a bubble informing the user that new credit card data has been saved.
     59   // This bubble points to the settings menu. Ownership of |new_card|
     60   // and |billing_profile| are transferred by this call.
     61   static void Show(Profile* profile,
     62                    scoped_ptr<CreditCard> new_card,
     63                    scoped_ptr<AutofillProfile> billing_profile);
     64 
     65   // The bubble's title text.
     66   const base::string16& TitleText() const;
     67 
     68   // A card description to show in the bubble.
     69   const CreditCardDescription& CardDescription() const;
     70 
     71   // The text of the link shown at the bubble of the bubble.
     72   const base::string16& LinkText() const;
     73 
     74   // Called when |bubble_| is destroyed.
     75   void OnBubbleDestroyed();
     76 
     77   // Called when the link at the bottom of the bubble is clicked.
     78   void OnLinkClicked();
     79 
     80   // Returns the profile this bubble is associated with.
     81   Profile* profile() { return profile_; }
     82 
     83  protected:
     84   // Create a bubble attached to |profile|.
     85   explicit NewCreditCardBubbleController(Profile* profile);
     86 
     87   // Creates and returns an Autofill credit card bubble. Exposed for testing.
     88   virtual base::WeakPtr<NewCreditCardBubbleView> CreateBubble();
     89 
     90   // Returns a weak reference to |bubble_|. May be invalid/NULL.
     91   virtual base::WeakPtr<NewCreditCardBubbleView> bubble();
     92 
     93   // Show a bubble notifying the user that new credit card data has been saved.
     94   // Exposed for testing.
     95   virtual void SetupAndShow(scoped_ptr<CreditCard> new_card,
     96                             scoped_ptr<AutofillProfile> billing_profile);
     97 
     98  private:
     99   // Hides |bubble_| if it exists.
    100   void Hide();
    101 
    102   // The profile this bubble is associated with.
    103   Profile* const profile_;
    104 
    105   // The newly saved credit card and assocated billing information.
    106   scoped_ptr<CreditCard> new_card_;
    107   scoped_ptr<AutofillProfile> billing_profile_;
    108 
    109   // The title text of the bubble.
    110   const base::string16 title_text_;
    111 
    112   // The bubble's link text.
    113   const base::string16 link_text_;
    114 
    115   // Strings and descriptions that are generated based on |new_card_| and
    116   // |billing_profile_|.
    117   struct CreditCardDescription card_desc_;
    118 
    119   // A bubble view that's created by calling either |Show*()| method; owned by
    120   // the native widget/hierarchy, not this class (though this class must outlive
    121   // |bubble_|). NULL in many cases.
    122   base::WeakPtr<NewCreditCardBubbleView> bubble_;
    123 
    124   // A weak pointer factory for |Create()|.
    125   base::WeakPtrFactory<NewCreditCardBubbleController> weak_ptr_factory_;
    126 
    127   DISALLOW_COPY_AND_ASSIGN(NewCreditCardBubbleController);
    128 };
    129 
    130 }  // namespace autofill
    131 
    132 #endif  // CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_
    133