manage_passwords_bubble_view.h revision 010d83a9304c5a91596085d917d248abff47903a
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 a list of her currently saved credentials
72  // for the current page, along with a "Manage passwords" link and a
73  // "Done" button.
74  class ManageView : public views::View,
75                     public views::ButtonListener,
76                     public views::LinkListener {
77   public:
78    explicit ManageView(ManagePasswordsBubbleView* parent);
79    virtual ~ManageView();
80
81   private:
82    // views::ButtonListener:
83    virtual void ButtonPressed(views::Button* sender,
84                               const ui::Event& event) OVERRIDE;
85
86    // views::LinkListener:
87    virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
88
89    ManagePasswordsBubbleView* parent_;
90
91    views::Link* manage_link_;
92    views::LabelButton* done_button_;
93  };
94
95  // A view offering the user the ability to re-enable the password manager for
96  // a specific site after she's decided to "never save passwords".
97  class BlacklistedView : public views::View, public views::ButtonListener {
98   public:
99    explicit BlacklistedView(ManagePasswordsBubbleView* parent);
100    virtual ~BlacklistedView();
101
102   private:
103    // views::ButtonListener:
104    virtual void ButtonPressed(views::Button* sender,
105                               const ui::Event& event) OVERRIDE;
106
107    ManagePasswordsBubbleView* parent_;
108
109    views::BlueButton* unblacklist_button_;
110    views::LabelButton* done_button_;
111  };
112
113  // Shows the bubble.
114  static void ShowBubble(content::WebContents* web_contents,
115                         DisplayReason reason);
116
117  // Closes any existing bubble.
118  static void CloseBubble();
119
120  // Whether the bubble is currently showing.
121  static bool IsShowing();
122
123 private:
124  ManagePasswordsBubbleView(content::WebContents* web_contents,
125                            views::View* anchor_view,
126                            DisplayReason reason);
127  virtual ~ManagePasswordsBubbleView();
128
129  // If the bubble is not anchored to a view, places the bubble in the top
130  // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
131  // browser window. Because the positioning is based on the size of the
132  // bubble, this must be called after the bubble is created.
133  void AdjustForFullscreen(const gfx::Rect& screen_bounds);
134
135  // Close the bubble.
136  void Close();
137
138  // views::BubbleDelegateView:
139  virtual void Init() OVERRIDE;
140  virtual void WindowClosing() OVERRIDE;
141
142  // Singleton instance of the Password bubble. The Password bubble can only be
143  // shown on the active browser window, so there is no case in which it will be
144  // shown twice at the same time.
145  static ManagePasswordsBubbleView* manage_passwords_bubble_;
146
147  DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView);
148};
149
150#endif  // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
151