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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
8 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "ui/views/bubble/bubble_delegate.h"
13 class ManagePasswordsIconView;
19 // The ManagePasswordsBubbleView controls the contents of the bubble which
20 // pops up when Chrome offers to save a user's password, or when the user
21 // interacts with the Omnibox icon. It has two distinct states:
23 // 1. PendingView: Offers the user the possibility of saving credentials.
24 // 2. ManageView: Displays the current page's saved credentials.
25 // 3. BlacklistedView: Informs the user that the current page is blacklisted.
27 class ManagePasswordsBubbleView : public ManagePasswordsBubble,
28 public views::BubbleDelegateView,
29 public content::NotificationObserver {
32 static void ShowBubble(content::WebContents* web_contents,
33 DisplayReason reason);
35 // Closes the existing bubble.
36 static void CloseBubble();
38 // Makes the bubble the foreground window.
39 static void ActivateBubble();
41 // Whether the bubble is currently showing.
42 static bool IsShowing();
44 // Returns a pointer to the bubble.
45 static const ManagePasswordsBubbleView* manage_password_bubble() {
46 return manage_passwords_bubble_;
49 content::WebContents* web_contents() const;
51 const View* initially_focused_view() const {
52 return initially_focused_view_;
56 class BlacklistedView;
57 class ConfirmNeverView;
60 class SaveConfirmationView;
62 ManagePasswordsBubbleView(content::WebContents* web_contents,
63 ManagePasswordsIconView* anchor_view,
64 DisplayReason reason);
65 ~ManagePasswordsBubbleView() override;
67 // If the bubble is not anchored to a view, places the bubble in the top
68 // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
69 // browser window. Because the positioning is based on the size of the
70 // bubble, this must be called after the bubble is created.
71 void AdjustForFullscreen(const gfx::Rect& screen_bounds);
76 // Refreshes the bubble's state: called to display a confirmation screen after
77 // a user selects "Never for this site", for instance.
80 // Called from PendingView if the user clicks on "Never for this site" in
81 // order to display a confirmation screen.
82 void NotifyNeverForThisSiteClicked();
84 // Called from ConfirmNeverView if the user confirms her intention to never
85 // save passwords, and remove existing passwords, for a site.
86 void NotifyConfirmedNeverForThisSite();
88 // Called from ConfirmNeverView if the user clicks on "Undo" in order to
89 // undo the action and refresh to PendingView.
90 void NotifyUndoNeverForThisSite();
92 // views::BubbleDelegateView:
94 void WindowClosing() override;
96 // views::WidgetDelegate:
97 views::View* GetInitiallyFocusedView() override;
99 // content::NotificationObserver:
100 void Observe(int type,
101 const content::NotificationSource& source,
102 const content::NotificationDetails& details) override;
104 void set_initially_focused_view(views::View* view) {
105 DCHECK(!initially_focused_view_);
106 initially_focused_view_ = view;
109 // Singleton instance of the Password bubble. The Password bubble can only be
110 // shown on the active browser window, so there is no case in which it will be
111 // shown twice at the same time. The instance is owned by the Bubble and will
112 // be deleted when the bubble closes.
113 static ManagePasswordsBubbleView* manage_passwords_bubble_;
115 ManagePasswordsIconView* anchor_view_;
117 // If true upon destruction, the user has confirmed that she never wants to
118 // save passwords for a particular site.
119 bool never_save_passwords_;
121 views::View* initially_focused_view_;
123 // A helper to intercept mouse click events on the web contents.
124 class WebContentMouseHandler;
125 scoped_ptr<WebContentMouseHandler> mouse_handler_;
127 // Used to register for fullscreen change notifications.
128 content::NotificationRegistrar registrar_;
130 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView);
133 #endif // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_