Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / passwords / manage_passwords_bubble_view.h
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 "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "ui/views/bubble/bubble_delegate.h"
12
13 class ManagePasswordsIconView;
14
15 namespace content {
16 class WebContents;
17 }
18
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:
22 //
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.
26 //
27 class ManagePasswordsBubbleView : public ManagePasswordsBubble,
28                                   public views::BubbleDelegateView,
29                                   public content::NotificationObserver {
30  public:
31   // Shows the bubble.
32   static void ShowBubble(content::WebContents* web_contents,
33                          DisplayReason reason);
34
35   // Closes the existing bubble.
36   static void CloseBubble();
37
38   // Makes the bubble the foreground window.
39   static void ActivateBubble();
40
41   // Whether the bubble is currently showing.
42   static bool IsShowing();
43
44   // Returns a pointer to the bubble.
45   static const ManagePasswordsBubbleView* manage_password_bubble() {
46     return manage_passwords_bubble_;
47   }
48
49   content::WebContents* web_contents() const;
50
51   const View* initially_focused_view() const {
52     return initially_focused_view_;
53   }
54
55  private:
56   class BlacklistedView;
57   class ConfirmNeverView;
58   class ManageView;
59   class PendingView;
60   class SaveConfirmationView;
61
62   ManagePasswordsBubbleView(content::WebContents* web_contents,
63                             ManagePasswordsIconView* anchor_view,
64                             DisplayReason reason);
65   ~ManagePasswordsBubbleView() override;
66
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);
72
73   // Close the bubble.
74   void Close();
75
76   // Refreshes the bubble's state: called to display a confirmation screen after
77   // a user selects "Never for this site", for instance.
78   void Refresh();
79
80   // Called from PendingView if the user clicks on "Never for this site" in
81   // order to display a confirmation screen.
82   void NotifyNeverForThisSiteClicked();
83
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();
87
88   // Called from ConfirmNeverView if the user clicks on "Undo" in order to
89   // undo the action and refresh to PendingView.
90   void NotifyUndoNeverForThisSite();
91
92   // views::BubbleDelegateView:
93   void Init() override;
94   void WindowClosing() override;
95
96   // views::WidgetDelegate:
97   views::View* GetInitiallyFocusedView() override;
98
99   // content::NotificationObserver:
100   void Observe(int type,
101                const content::NotificationSource& source,
102                const content::NotificationDetails& details) override;
103
104   void set_initially_focused_view(views::View* view) {
105     DCHECK(!initially_focused_view_);
106     initially_focused_view_ = view;
107   }
108
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_;
114
115   ManagePasswordsIconView* anchor_view_;
116
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_;
120
121   views::View* initially_focused_view_;
122
123   // A helper to intercept mouse click events on the web contents.
124   class WebContentMouseHandler;
125   scoped_ptr<WebContentMouseHandler> mouse_handler_;
126
127   // Used to register for fullscreen change notifications.
128   content::NotificationRegistrar registrar_;
129
130   DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView);
131 };
132
133 #endif  // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_