manage_passwords_bubble_view.h revision 116680a4aac90f2aa7413d9095a592090648e557
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_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
7
8#include "base/basictypes.h"
9#include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
10#include "chrome/browser/ui/views/passwords/save_password_refusal_combobox_model.h"
11#include "ui/views/bubble/bubble_delegate.h"
12#include "ui/views/controls/button/button.h"
13#include "ui/views/controls/combobox/combobox.h"
14#include "ui/views/controls/combobox/combobox_listener.h"
15#include "ui/views/controls/link.h"
16#include "ui/views/controls/link_listener.h"
17
18class ManagePasswordsIconView;
19
20namespace content {
21class WebContents;
22}
23
24namespace views {
25class BlueButton;
26class LabelButton;
27class GridLayout;
28}
29
30// The ManagePasswordsBubbleView controls the contents of the bubble which
31// pops up when Chrome offers to save a user's password, or when the user
32// interacts with the Omnibox icon. It has two distinct states:
33//
34// 1. PendingView: Offers the user the possibility of saving credentials.
35// 2. ManageView: Displays the current page's saved credentials.
36// 3. BlacklistedView: Informs the user that the current page is blacklisted.
37//
38class ManagePasswordsBubbleView : public ManagePasswordsBubble,
39                                  public views::BubbleDelegateView {
40 public:
41  // A view offering the user the ability to save credentials. Contains a
42  // single ManagePasswordItemView, along with a "Save Passwords" button
43  // and a rejection combobox.
44  class PendingView : public views::View,
45                      public views::ButtonListener,
46                      public views::ComboboxListener {
47   public:
48    explicit PendingView(ManagePasswordsBubbleView* parent);
49    virtual ~PendingView();
50
51   private:
52    // views::ButtonListener:
53    virtual void ButtonPressed(views::Button* sender,
54                               const ui::Event& event) OVERRIDE;
55
56    // Handles the event when the user changes an index of a combobox.
57    virtual void OnPerformAction(views::Combobox* source) OVERRIDE;
58
59    ManagePasswordsBubbleView* parent_;
60
61    views::BlueButton* save_button_;
62
63    // The combobox doesn't take ownership of its model. If we created a
64    // combobox we need to ensure that we delete the model here, and because the
65    // combobox uses the model in it's destructor, we need to make sure we
66    // delete the model _after_ the combobox itself is deleted.
67    scoped_ptr<SavePasswordRefusalComboboxModel> combobox_model_;
68    scoped_ptr<views::Combobox> refuse_combobox_;
69  };
70
71  // A view offering the user the ability to undo her decision to never save
72  // passwords for a particular site.
73  class ConfirmNeverView : public views::View, public views::ButtonListener {
74   public:
75    explicit ConfirmNeverView(ManagePasswordsBubbleView* parent);
76    virtual ~ConfirmNeverView();
77
78   private:
79    // views::ButtonListener:
80    virtual void ButtonPressed(views::Button* sender,
81                               const ui::Event& event) OVERRIDE;
82
83    ManagePasswordsBubbleView* parent_;
84
85    views::LabelButton* confirm_button_;
86    views::LabelButton* undo_button_;
87  };
88
89  // A view offering the user a list of her currently saved credentials
90  // for the current page, along with a "Manage passwords" link and a
91  // "Done" button.
92  class ManageView : public views::View,
93                     public views::ButtonListener,
94                     public views::LinkListener {
95   public:
96    explicit ManageView(ManagePasswordsBubbleView* parent);
97    virtual ~ManageView();
98
99   private:
100    // views::ButtonListener:
101    virtual void ButtonPressed(views::Button* sender,
102                               const ui::Event& event) OVERRIDE;
103
104    // views::LinkListener:
105    virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
106
107    ManagePasswordsBubbleView* parent_;
108
109    views::Link* manage_link_;
110    views::LabelButton* done_button_;
111  };
112
113  // A view offering the user the ability to re-enable the password manager for
114  // a specific site after she's decided to "never save passwords".
115  class BlacklistedView : public views::View, public views::ButtonListener {
116   public:
117    explicit BlacklistedView(ManagePasswordsBubbleView* parent);
118    virtual ~BlacklistedView();
119
120   private:
121    // views::ButtonListener:
122    virtual void ButtonPressed(views::Button* sender,
123                               const ui::Event& event) OVERRIDE;
124
125    ManagePasswordsBubbleView* parent_;
126
127    views::BlueButton* unblacklist_button_;
128    views::LabelButton* done_button_;
129  };
130
131  // Shows the bubble.
132  static void ShowBubble(content::WebContents* web_contents,
133                         DisplayReason reason);
134
135  // Closes any existing bubble.
136  static void CloseBubble();
137
138  // Whether the bubble is currently showing.
139  static bool IsShowing();
140
141  // Returns a pointer to the bubble.
142  static const ManagePasswordsBubbleView* Bubble();
143
144 private:
145  ManagePasswordsBubbleView(content::WebContents* web_contents,
146                            ManagePasswordsIconView* anchor_view,
147                            DisplayReason reason);
148  virtual ~ManagePasswordsBubbleView();
149
150  // If the bubble is not anchored to a view, places the bubble in the top
151  // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
152  // browser window. Because the positioning is based on the size of the
153  // bubble, this must be called after the bubble is created.
154  void AdjustForFullscreen(const gfx::Rect& screen_bounds);
155
156  // Close the bubble.
157  void Close();
158
159  // Refreshes the bubble's state: called to display a confirmation screen after
160  // a user selects "Never for this site", for instance.
161  void Refresh();
162
163  // Called from PendingView if the user clicks on "Never for this site" in
164  // order to display a confirmation screen.
165  void NotifyNeverForThisSiteClicked();
166
167  // Called from ConfirmNeverView if the user confirms her intention to never
168  // save passwords, and remove existing passwords, for a site.
169  void NotifyConfirmedNeverForThisSite();
170
171  // Called from ConfirmNeverView if the user clicks on "Undo" in order to
172  // undo the action and refresh to PendingView.
173  void NotifyUndoNeverForThisSite();
174
175  // views::BubbleDelegateView:
176  virtual void Init() OVERRIDE;
177  virtual void WindowClosing() OVERRIDE;
178
179  // Singleton instance of the Password bubble. The Password bubble can only be
180  // shown on the active browser window, so there is no case in which it will be
181  // shown twice at the same time.
182  static ManagePasswordsBubbleView* manage_passwords_bubble_;
183
184  ManagePasswordsIconView* anchor_view_;
185
186  // If true upon destruction, the user has confirmed that she never wants to
187  // save passwords for a particular site.
188  bool never_save_passwords_;
189
190  DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView);
191};
192
193#endif  // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
194