Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / browser / chromeos / login / ui / webui_login_view.h
blob9e9119595d49defde47e8af7dc90c454fec25db2
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/observer_list.h"
12 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
13 #include "components/web_modal/web_contents_modal_dialog_host.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_contents_delegate.h"
17 #include "content/public/browser/web_contents_observer.h"
18 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
19 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_delegate.h"
22 class GURL;
24 namespace content {
25 class WebUI;
28 namespace views {
29 class View;
30 class WebView;
31 class Widget;
34 namespace chromeos {
36 // View used to render a WebUI supporting Widget. This widget is used for the
37 // WebUI based start up and lock screens. It contains a WebView.
38 class WebUILoginView : public views::View,
39 public content::WebContentsDelegate,
40 public content::WebContentsObserver,
41 public content::NotificationObserver,
42 public ChromeWebModalDialogManagerDelegate,
43 public web_modal::WebContentsModalDialogHost {
44 public:
45 class FrameObserver {
46 public:
47 // Called when a frame failed to load.
48 virtual void OnFrameError(const std::string& frame_unique_name) = 0;
51 // Internal class name.
52 static const char kViewClassName[];
54 WebUILoginView();
55 ~WebUILoginView() override;
57 // Initializes the webui login view.
58 virtual void Init();
60 // Overridden from views::View:
61 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
62 const char* GetClassName() const override;
63 void RequestFocus() override;
65 // Overridden from ChromeWebModalDialogManagerDelegate:
66 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
67 override;
69 // Overridden from web_modal::WebContentsModalDialogHost:
70 gfx::NativeView GetHostView() const override;
71 gfx::Point GetDialogPosition(const gfx::Size& size) override;
72 gfx::Size GetMaximumDialogSize() override;
73 void AddObserver(web_modal::ModalDialogHostObserver* observer) override;
74 void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override;
76 // Gets the native window from the view widget.
77 gfx::NativeWindow GetNativeWindow() const;
79 // Loads given page. Should be called after Init() has been called.
80 void LoadURL(const GURL& url);
82 // Returns current WebUI.
83 content::WebUI* GetWebUI();
85 // Returns current WebContents.
86 content::WebContents* GetWebContents();
88 // Opens proxy settings dialog.
89 void OpenProxySettings();
91 // Called when WebUI is being shown after being initilized hidden.
92 void OnPostponedShow();
94 // Toggles status area visibility.
95 void SetStatusAreaVisible(bool visible);
97 // Sets whether UI should be enabled.
98 void SetUIEnabled(bool enabled);
100 void set_is_hidden(bool hidden) { is_hidden_ = hidden; }
102 bool webui_visible() const { return webui_visible_; }
104 // Let suppress emission of this signal.
105 void set_should_emit_login_prompt_visible(bool emit) {
106 should_emit_login_prompt_visible_ = emit;
109 void AddFrameObserver(FrameObserver* frame_observer);
110 void RemoveFrameObserver(FrameObserver* frame_observer);
112 protected:
113 // Overridden from views::View:
114 void Layout() override;
115 void OnLocaleChanged() override;
116 void ChildPreferredSizeChanged(View* child) override;
117 void AboutToRequestFocusFromTabTraversal(bool reverse) override;
119 // Overridden from content::NotificationObserver.
120 void Observe(int type,
121 const content::NotificationSource& source,
122 const content::NotificationDetails& details) override;
124 // WebView for rendering a webpage as a webui login.
125 views::WebView* webui_login_;
127 private:
128 // Map type for the accelerator-to-identifier map.
129 typedef std::map<ui::Accelerator, std::string> AccelMap;
131 // Overridden from content::WebContentsDelegate.
132 bool HandleContextMenu(const content::ContextMenuParams& params) override;
133 void HandleKeyboardEvent(
134 content::WebContents* source,
135 const content::NativeWebKeyboardEvent& event) override;
136 bool IsPopupOrPanel(const content::WebContents* source) const override;
137 bool TakeFocus(content::WebContents* source, bool reverse) override;
138 void RequestMediaAccessPermission(
139 content::WebContents* web_contents,
140 const content::MediaStreamRequest& request,
141 const content::MediaResponseCallback& callback) override;
142 bool CheckMediaAccessPermission(content::WebContents* web_contents,
143 const GURL& security_origin,
144 content::MediaStreamType type) override;
145 bool PreHandleGestureEvent(content::WebContents* source,
146 const blink::WebGestureEvent& event) override;
148 // Overridden from content::WebContentsObserver.
149 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
150 const GURL& validated_url,
151 int error_code,
152 const base::string16& error_description,
153 bool was_ignored_by_handler) override;
155 // Performs series of actions when login prompt is considered
156 // to be ready and visible.
157 // 1. Emits LoginPromptVisible signal if needed
158 // 2. Notifies OOBE/sign classes.
159 void OnLoginPromptVisible();
161 // Called when focus is returned from status area.
162 // |reverse| is true when focus is traversed backwards (using Shift-Tab).
163 void ReturnFocus(bool reverse);
165 content::NotificationRegistrar registrar_;
167 // Converts keyboard events on the WebContents to accelerators.
168 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
170 // Maps installed accelerators to OOBE webui accelerator identifiers.
171 AccelMap accel_map_;
173 // True when WebUI is being initialized hidden.
174 bool is_hidden_;
176 // True when the WebUI has finished initializing and is visible.
177 bool webui_visible_;
179 // Should we emit the login-prompt-visible signal when the login page is
180 // displayed?
181 bool should_emit_login_prompt_visible_;
183 // True to forward keyboard event.
184 bool forward_keyboard_event_;
186 base::ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
187 base::ObserverList<FrameObserver> frame_observer_list_;
189 DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
192 } // namespace chromeos
194 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_