webui_login_view.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1// Copyright (c) 2012 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_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
7
8#include <map>
9#include <string>
10
11#include "base/memory/scoped_ptr.h"
12#include "base/observer_list.h"
13#include "chrome/browser/extensions/scoped_gaia_auth_extension.h"
14#include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
15#include "components/web_modal/web_contents_modal_dialog_host.h"
16#include "content/public/browser/notification_observer.h"
17#include "content/public/browser/notification_registrar.h"
18#include "content/public/browser/web_contents_delegate.h"
19#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
20#include "ui/views/widget/widget.h"
21#include "ui/views/widget/widget_delegate.h"
22
23class GURL;
24
25namespace content {
26class WebUI;
27}
28
29namespace views {
30class View;
31class WebView;
32class Widget;
33}
34
35namespace chromeos {
36
37// View used to render a WebUI supporting Widget. This widget is used for the
38// WebUI based start up and lock screens. It contains a WebView.
39class WebUILoginView : public views::View,
40                       public content::WebContentsDelegate,
41                       public content::NotificationObserver,
42                       public ChromeWebModalDialogManagerDelegate,
43                       public web_modal::WebContentsModalDialogHost {
44 public:
45  // Internal class name.
46  static const char kViewClassName[];
47
48  WebUILoginView();
49  virtual ~WebUILoginView();
50
51  // Initializes the webui login view.
52  virtual void Init();
53
54  // Overridden from views::View:
55  virtual bool AcceleratorPressed(
56      const ui::Accelerator& accelerator) OVERRIDE;
57  virtual const char* GetClassName() const OVERRIDE;
58
59  // Overridden from ChromeWebModalDialogManagerDelegate:
60  virtual web_modal::WebContentsModalDialogHost*
61      GetWebContentsModalDialogHost() OVERRIDE;
62
63  // Overridden from web_modal::WebContentsModalDialogHost:
64  virtual gfx::NativeView GetHostView() const OVERRIDE;
65  virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
66  virtual gfx::Size GetMaximumDialogSize() OVERRIDE;
67  virtual void AddObserver(
68      web_modal::ModalDialogHostObserver* observer) OVERRIDE;
69  virtual void RemoveObserver(
70      web_modal::ModalDialogHostObserver* observer) OVERRIDE;
71
72  // Gets the native window from the view widget.
73  gfx::NativeWindow GetNativeWindow() const;
74
75  // Loads given page. Should be called after Init() has been called.
76  void LoadURL(const GURL& url);
77
78  // Returns current WebUI.
79  content::WebUI* GetWebUI();
80
81  // Returns current WebContents.
82  content::WebContents* GetWebContents();
83
84  // Opens proxy settings dialog.
85  void OpenProxySettings();
86
87  // Called when WebUI is being shown after being initilized hidden.
88  void OnPostponedShow();
89
90  // Toggles status area visibility.
91  void SetStatusAreaVisible(bool visible);
92
93  // Sets whether UI should be enabled.
94  void SetUIEnabled(bool enabled);
95
96  void set_is_hidden(bool hidden) { is_hidden_ = hidden; }
97
98  bool webui_visible() const { return webui_visible_; }
99
100  // Let suppress emission of this signal.
101  void set_should_emit_login_prompt_visible(bool emit) {
102    should_emit_login_prompt_visible_ = emit;
103  }
104
105 protected:
106  // Overridden from views::View:
107  virtual void Layout() OVERRIDE;
108  virtual void OnLocaleChanged() OVERRIDE;
109  virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
110  virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
111
112  // Overridden from content::NotificationObserver.
113  virtual void Observe(int type,
114                       const content::NotificationSource& source,
115                       const content::NotificationDetails& details) OVERRIDE;
116
117  // WebView for rendering a webpage as a webui login.
118  views::WebView* webui_login_;
119
120 private:
121  // Map type for the accelerator-to-identifier map.
122  typedef std::map<ui::Accelerator, std::string> AccelMap;
123
124  // Overridden from content::WebContentsDelegate.
125  virtual bool HandleContextMenu(
126      const content::ContextMenuParams& params) OVERRIDE;
127  virtual void HandleKeyboardEvent(
128      content::WebContents* source,
129      const content::NativeWebKeyboardEvent& event) OVERRIDE;
130  virtual bool IsPopupOrPanel(
131      const content::WebContents* source) const OVERRIDE;
132  virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
133  virtual void RequestMediaAccessPermission(
134      content::WebContents* web_contents,
135      const content::MediaStreamRequest& request,
136      const content::MediaResponseCallback& callback) OVERRIDE;
137
138  // Performs series of actions when login prompt is considered
139  // to be ready and visible.
140  // 1. Emits LoginPromptVisible signal if needed
141  // 2. Notifies OOBE/sign classes.
142  void OnLoginPromptVisible();
143
144  // Called when focus is returned from status area.
145  // |reverse| is true when focus is traversed backwards (using Shift-Tab).
146  void ReturnFocus(bool reverse);
147
148  content::NotificationRegistrar registrar_;
149
150  // Converts keyboard events on the WebContents to accelerators.
151  views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
152
153  // Maps installed accelerators to OOBE webui accelerator identifiers.
154  AccelMap accel_map_;
155
156  // True when WebUI is being initialized hidden.
157  bool is_hidden_;
158
159  // True when the WebUI has finished initializing and is visible.
160  bool webui_visible_;
161
162  // Should we emit the login-prompt-visible signal when the login page is
163  // displayed?
164  bool should_emit_login_prompt_visible_;
165
166  // True to forward keyboard event.
167  bool forward_keyboard_event_;
168
169  scoped_ptr<ScopedGaiaAuthExtension> auth_extension_;
170
171  ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
172
173  DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
174};
175
176}  // namespace chromeos
177
178#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
179