ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / ui / webui_login_view.h
blobc11164e41eea0406fd281db825d04ba68946db6a
1 // Copyright 2014 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_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
14 #include "components/web_modal/popup_manager.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 "content/public/browser/web_contents_observer.h"
20 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
21 #include "ui/views/widget/widget.h"
22 #include "ui/views/widget/widget_delegate.h"
24 class GURL;
26 namespace content {
27 class WebUI;
30 namespace views {
31 class View;
32 class WebView;
33 class Widget;
36 namespace chromeos {
38 // View used to render a WebUI supporting Widget. This widget is used for the
39 // WebUI based start up and lock screens. It contains a WebView.
40 class WebUILoginView : public views::View,
41 public content::WebContentsDelegate,
42 public content::WebContentsObserver,
43 public content::NotificationObserver,
44 public ChromeWebModalDialogManagerDelegate,
45 public web_modal::WebContentsModalDialogHost {
46 public:
47 class FrameObserver {
48 public:
49 // Called when a frame failed to load.
50 virtual void OnFrameError(const std::string& frame_unique_name) = 0;
53 // Internal class name.
54 static const char kViewClassName[];
56 WebUILoginView();
57 ~WebUILoginView() override;
59 // Initializes the webui login view.
60 virtual void Init();
62 // Overridden from views::View:
63 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
64 const char* GetClassName() const override;
65 void RequestFocus() override;
67 // Overridden from ChromeWebModalDialogManagerDelegate:
68 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
69 override;
71 // Overridden from web_modal::WebContentsModalDialogHost:
72 gfx::NativeView GetHostView() const override;
73 gfx::Point GetDialogPosition(const gfx::Size& size) override;
74 gfx::Size GetMaximumDialogSize() override;
75 void AddObserver(web_modal::ModalDialogHostObserver* observer) override;
76 void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override;
78 // Gets the native window from the view widget.
79 gfx::NativeWindow GetNativeWindow() const;
81 // Loads given page. Should be called after Init() has been called.
82 void LoadURL(const GURL& url);
84 // Returns current WebUI.
85 content::WebUI* GetWebUI();
87 // Returns current WebContents.
88 content::WebContents* GetWebContents();
90 // Opens proxy settings dialog.
91 void OpenProxySettings();
93 // Called when WebUI is being shown after being initilized hidden.
94 void OnPostponedShow();
96 // Toggles status area visibility.
97 void SetStatusAreaVisible(bool visible);
99 // Sets whether UI should be enabled.
100 void SetUIEnabled(bool enabled);
102 void set_is_hidden(bool hidden) { is_hidden_ = hidden; }
104 bool webui_visible() const { return webui_visible_; }
106 // Let suppress emission of this signal.
107 void set_should_emit_login_prompt_visible(bool emit) {
108 should_emit_login_prompt_visible_ = emit;
111 void AddFrameObserver(FrameObserver* frame_observer);
112 void RemoveFrameObserver(FrameObserver* frame_observer);
114 protected:
115 // Overridden from views::View:
116 void Layout() override;
117 void OnLocaleChanged() override;
118 void ChildPreferredSizeChanged(View* child) override;
119 void AboutToRequestFocusFromTabTraversal(bool reverse) override;
121 // Overridden from content::NotificationObserver.
122 void Observe(int type,
123 const content::NotificationSource& source,
124 const content::NotificationDetails& details) override;
126 // WebView for rendering a webpage as a webui login.
127 views::WebView* webui_login_;
129 private:
130 // Map type for the accelerator-to-identifier map.
131 typedef std::map<ui::Accelerator, std::string> AccelMap;
133 // Overridden from content::WebContentsDelegate.
134 bool HandleContextMenu(const content::ContextMenuParams& params) override;
135 void HandleKeyboardEvent(
136 content::WebContents* source,
137 const content::NativeWebKeyboardEvent& event) override;
138 bool IsPopupOrPanel(const content::WebContents* source) const override;
139 bool TakeFocus(content::WebContents* source, bool reverse) override;
140 void RequestMediaAccessPermission(
141 content::WebContents* web_contents,
142 const content::MediaStreamRequest& request,
143 const content::MediaResponseCallback& callback) override;
144 bool CheckMediaAccessPermission(content::WebContents* web_contents,
145 const GURL& security_origin,
146 content::MediaStreamType type) override;
147 bool PreHandleGestureEvent(content::WebContents* source,
148 const blink::WebGestureEvent& event) override;
150 // Overridden from content::WebContentsObserver.
151 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
152 const GURL& validated_url,
153 int error_code,
154 const base::string16& error_description) override;
156 // Performs series of actions when login prompt is considered
157 // to be ready and visible.
158 // 1. Emits LoginPromptVisible signal if needed
159 // 2. Notifies OOBE/sign classes.
160 void OnLoginPromptVisible();
162 // Called when focus is returned from status area.
163 // |reverse| is true when focus is traversed backwards (using Shift-Tab).
164 void ReturnFocus(bool reverse);
166 content::NotificationRegistrar registrar_;
168 // Converts keyboard events on the WebContents to accelerators.
169 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
171 // Maps installed accelerators to OOBE webui accelerator identifiers.
172 AccelMap accel_map_;
174 // True when WebUI is being initialized hidden.
175 bool is_hidden_;
177 // True when the WebUI has finished initializing and is visible.
178 bool webui_visible_;
180 // Should we emit the login-prompt-visible signal when the login page is
181 // displayed?
182 bool should_emit_login_prompt_visible_;
184 // True to forward keyboard event.
185 bool forward_keyboard_event_;
187 ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
188 ObserverList<FrameObserver> frame_observer_list_;
190 // Manage popups appearing over the login window.
191 // TODO(gbillock): See if we can get rid of this. Perhaps in favor of
192 // in-content styled popups or something? There oughtta be a way...
193 scoped_ptr<web_modal::PopupManager> popup_manager_;
195 DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
198 } // namespace chromeos
200 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_