manage_passwords_bubble_view.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 "chrome/browser/ui/passwords/manage_passwords_bubble.h" 9#include "ui/views/bubble/bubble_delegate.h" 10 11class ManagePasswordsIconView; 12 13namespace content { 14class WebContents; 15} 16 17// The ManagePasswordsBubbleView controls the contents of the bubble which 18// pops up when Chrome offers to save a user's password, or when the user 19// interacts with the Omnibox icon. It has two distinct states: 20// 21// 1. PendingView: Offers the user the possibility of saving credentials. 22// 2. ManageView: Displays the current page's saved credentials. 23// 3. BlacklistedView: Informs the user that the current page is blacklisted. 24// 25class ManagePasswordsBubbleView : public ManagePasswordsBubble, 26 public views::BubbleDelegateView { 27 public: 28 // Shows the bubble. 29 static void ShowBubble(content::WebContents* web_contents, 30 DisplayReason reason); 31 32 // Closes the existing bubble. 33 static void CloseBubble(); 34 35 // Makes the bubble the foreground window. 36 static void ActivateBubble(); 37 38 // Whether the bubble is currently showing. 39 static bool IsShowing(); 40 41 // Returns a pointer to the bubble. 42 static const ManagePasswordsBubbleView* manage_password_bubble() { 43 return manage_passwords_bubble_; 44 } 45 46 content::WebContents* web_contents() const; 47 48 const View* initially_focused_view() const { 49 return initially_focused_view_; 50 } 51 52 private: 53 class BlacklistedView; 54 class ConfirmNeverView; 55 class ManageView; 56 class PendingView; 57 class SaveConfirmationView; 58 59 ManagePasswordsBubbleView(content::WebContents* web_contents, 60 ManagePasswordsIconView* anchor_view, 61 DisplayReason reason); 62 virtual ~ManagePasswordsBubbleView(); 63 64 // If the bubble is not anchored to a view, places the bubble in the top 65 // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s 66 // browser window. Because the positioning is based on the size of the 67 // bubble, this must be called after the bubble is created. 68 void AdjustForFullscreen(const gfx::Rect& screen_bounds); 69 70 // Close the bubble. 71 void Close(); 72 73 // Refreshes the bubble's state: called to display a confirmation screen after 74 // a user selects "Never for this site", for instance. 75 void Refresh(); 76 77 // Called from PendingView if the user clicks on "Never for this site" in 78 // order to display a confirmation screen. 79 void NotifyNeverForThisSiteClicked(); 80 81 // Called from ConfirmNeverView if the user confirms her intention to never 82 // save passwords, and remove existing passwords, for a site. 83 void NotifyConfirmedNeverForThisSite(); 84 85 // Called from ConfirmNeverView if the user clicks on "Undo" in order to 86 // undo the action and refresh to PendingView. 87 void NotifyUndoNeverForThisSite(); 88 89 // views::BubbleDelegateView: 90 virtual void Init() OVERRIDE; 91 virtual void WindowClosing() OVERRIDE; 92 93 // views::WidgetDelegate 94 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 95 96 void set_initially_focused_view(views::View* view) { 97 DCHECK(!initially_focused_view_); 98 initially_focused_view_ = view; 99 } 100 101 // Singleton instance of the Password bubble. The Password bubble can only be 102 // shown on the active browser window, so there is no case in which it will be 103 // shown twice at the same time. The instance is owned by the Bubble and will 104 // be deleted when the bubble closes. 105 static ManagePasswordsBubbleView* manage_passwords_bubble_; 106 107 ManagePasswordsIconView* anchor_view_; 108 109 // If true upon destruction, the user has confirmed that she never wants to 110 // save passwords for a particular site. 111 bool never_save_passwords_; 112 113 views::View* initially_focused_view_; 114 115 // A helper to intercept mouse click events on the web contents. 116 class WebContentMouseHandler; 117 scoped_ptr<WebContentMouseHandler> mouse_handler_; 118 119 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView); 120}; 121 122#endif // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_ 123