manage_passwords_bubble_view.h revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
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 private: 142 ManagePasswordsBubbleView(content::WebContents* web_contents, 143 ManagePasswordsIconView* anchor_view, 144 DisplayReason reason); 145 virtual ~ManagePasswordsBubbleView(); 146 147 // If the bubble is not anchored to a view, places the bubble in the top 148 // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s 149 // browser window. Because the positioning is based on the size of the 150 // bubble, this must be called after the bubble is created. 151 void AdjustForFullscreen(const gfx::Rect& screen_bounds); 152 153 // Close the bubble. 154 void Close(); 155 156 // Refreshes the bubble's state: called to display a confirmation screen after 157 // a user selects "Never for this site", for instance. 158 void Refresh(); 159 160 // Called from PendingView if the user clicks on "Never for this site" in 161 // order to display a confirmation screen. 162 void NotifyNeverForThisSiteClicked(); 163 164 // Called from ConfirmNeverView if the user confirms her intention to never 165 // save passwords, and remove existing passwords, for a site. 166 void NotifyConfirmedNeverForThisSite(); 167 168 // Called from ConfirmNeverView if the user clicks on "Undo" in order to 169 // undo the action and refresh to PendingView. 170 void NotifyUndoNeverForThisSite(); 171 172 // views::BubbleDelegateView: 173 virtual void Init() OVERRIDE; 174 virtual void WindowClosing() OVERRIDE; 175 176 // Singleton instance of the Password bubble. The Password bubble can only be 177 // shown on the active browser window, so there is no case in which it will be 178 // shown twice at the same time. 179 static ManagePasswordsBubbleView* manage_passwords_bubble_; 180 181 ManagePasswordsIconView* anchor_view_; 182 183 // If true upon destruction, the user has confirmed that she never wants to 184 // save passwords for a particular site. 185 bool never_save_passwords_; 186 187 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView); 188}; 189 190#endif // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_ 191