summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/autofill/new_credit_card_bubble_controller.h
blob: ca5d6e1afee2d5ee3b1647bf5cb848945f2782a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_
#define CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "ui/gfx/image/image.h"

class Profile;

namespace content {
class WebContents;
}

namespace autofill {

class NewCreditCardBubbleView;
class AutofillProfile;
class CreditCard;

// A simple wrapper that contains descriptive information about a credit card
// that should be shown in the content of the bubble.
struct CreditCardDescription {
 CreditCardDescription();
 ~CreditCardDescription();
 // The icon of the credit card issuer (i.e. Visa, Mastercard).
 gfx::Image icon;
 // The display name of the card. Shown next to the icon.
 base::string16 name;
 // A longer description of the card being shown in the bubble.
 base::string16 description;
};

////////////////////////////////////////////////////////////////////////////////
//
// NewCreditCardBubbleController
//
//  A class to control showing/hiding a bubble after saved a new card in Chrome.
//  Here's a visual reference to what this bubble looks like:
//
//  @----------------------------------------@
//  |  Bubble title text                     |
//  |                                        |
//  |  [ Card icon ] Card name               |
//  |  Card description that will probably   |
//  |  also span multiple lines.             |
//  |                                        |
//  |  Learn more link                       |
//  @----------------------------------------@
//
////////////////////////////////////////////////////////////////////////////////
class NewCreditCardBubbleController {
 public:
  virtual ~NewCreditCardBubbleController();

  // Show a bubble informing the user that new credit card data has been saved.
  // This bubble points to the settings menu. Ownership of |new_card|
  // and |billing_profile| are transferred by this call.
  static void Show(content::WebContents* web_contents,
                   scoped_ptr<CreditCard> new_card,
                   scoped_ptr<AutofillProfile> billing_profile);

  // The bubble's title text.
  const base::string16& TitleText() const;

  // A card description to show in the bubble.
  const CreditCardDescription& CardDescription() const;

  // The text of the link shown at the bubble of the bubble.
  const base::string16& LinkText() const;

  // Called when |bubble_| is destroyed.
  void OnBubbleDestroyed();

  // Called when the link at the bottom of the bubble is clicked.
  void OnLinkClicked();

  // Returns the profile this bubble is associated with.
  Profile* profile() { return profile_; }

  // Returns the WebContents this bubble is associated with.
  content::WebContents* web_contents() { return web_contents_; }

 protected:
  // Create a bubble attached to |profile|.
  explicit NewCreditCardBubbleController(content::WebContents* web_contents);

  // Creates and returns an Autofill credit card bubble. Exposed for testing.
  virtual base::WeakPtr<NewCreditCardBubbleView> CreateBubble();

  // Returns a weak reference to |bubble_|. May be invalid/NULL.
  virtual base::WeakPtr<NewCreditCardBubbleView> bubble();

  // Show a bubble notifying the user that new credit card data has been saved.
  // Exposed for testing.
  virtual void SetupAndShow(scoped_ptr<CreditCard> new_card,
                            scoped_ptr<AutofillProfile> billing_profile);

 private:
  friend class NewCreditCardBubbleCocoaUnitTest;

  // Hides |bubble_| if it exists.
  void Hide();

  // The profile this bubble is associated with.
  // TODO(dbeam): Break Views dependency on Profile and remove |profile_|.
  Profile* const profile_;

  // The web contents associated with this bubble.
  content::WebContents* const web_contents_;

  // The newly saved credit card and assocated billing information.
  scoped_ptr<CreditCard> new_card_;
  scoped_ptr<AutofillProfile> billing_profile_;

  // The title text of the bubble.
  const base::string16 title_text_;

  // The bubble's link text.
  const base::string16 link_text_;

  // Strings and descriptions that are generated based on |new_card_| and
  // |billing_profile_|.
  struct CreditCardDescription card_desc_;

  // A bubble view that's created by calling either |Show*()| method; owned by
  // the native widget/hierarchy, not this class (though this class must outlive
  // |bubble_|). NULL in many cases.
  base::WeakPtr<NewCreditCardBubbleView> bubble_;

  // A weak pointer factory for |Create()|.
  base::WeakPtrFactory<NewCreditCardBubbleController> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(NewCreditCardBubbleController);
};

}  // namespace autofill

#endif  // CHROME_BROWSER_UI_AUTOFILL_NEW_CREDIT_CARD_BUBBLE_CONTROLLER_H_