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_
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"
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
{
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
[];
57 virtual ~WebUILoginView();
59 // Initializes the webui login view.
62 // Overridden from views::View:
63 virtual bool AcceleratorPressed(
64 const ui::Accelerator
& accelerator
) override
;
65 virtual const char* GetClassName() const override
;
66 virtual void RequestFocus() override
;
68 // Overridden from ChromeWebModalDialogManagerDelegate:
69 virtual web_modal::WebContentsModalDialogHost
*
70 GetWebContentsModalDialogHost() override
;
72 // Overridden from web_modal::WebContentsModalDialogHost:
73 virtual gfx::NativeView
GetHostView() const override
;
74 virtual gfx::Point
GetDialogPosition(const gfx::Size
& size
) override
;
75 virtual gfx::Size
GetMaximumDialogSize() override
;
76 virtual void AddObserver(
77 web_modal::ModalDialogHostObserver
* observer
) override
;
78 virtual void RemoveObserver(
79 web_modal::ModalDialogHostObserver
* observer
) override
;
81 // Gets the native window from the view widget.
82 gfx::NativeWindow
GetNativeWindow() const;
84 // Loads given page. Should be called after Init() has been called.
85 void LoadURL(const GURL
& url
);
87 // Returns current WebUI.
88 content::WebUI
* GetWebUI();
90 // Returns current WebContents.
91 content::WebContents
* GetWebContents();
93 // Opens proxy settings dialog.
94 void OpenProxySettings();
96 // Called when WebUI is being shown after being initilized hidden.
97 void OnPostponedShow();
99 // Toggles status area visibility.
100 void SetStatusAreaVisible(bool visible
);
102 // Sets whether UI should be enabled.
103 void SetUIEnabled(bool enabled
);
105 void set_is_hidden(bool hidden
) { is_hidden_
= hidden
; }
107 bool webui_visible() const { return webui_visible_
; }
109 // Let suppress emission of this signal.
110 void set_should_emit_login_prompt_visible(bool emit
) {
111 should_emit_login_prompt_visible_
= emit
;
114 void AddFrameObserver(FrameObserver
* frame_observer
);
115 void RemoveFrameObserver(FrameObserver
* frame_observer
);
118 // Overridden from views::View:
119 virtual void Layout() override
;
120 virtual void OnLocaleChanged() override
;
121 virtual void ChildPreferredSizeChanged(View
* child
) override
;
122 virtual void AboutToRequestFocusFromTabTraversal(bool reverse
) override
;
124 // Overridden from content::NotificationObserver.
125 virtual void Observe(int type
,
126 const content::NotificationSource
& source
,
127 const content::NotificationDetails
& details
) override
;
129 // WebView for rendering a webpage as a webui login.
130 views::WebView
* webui_login_
;
133 // Map type for the accelerator-to-identifier map.
134 typedef std::map
<ui::Accelerator
, std::string
> AccelMap
;
136 // Overridden from content::WebContentsDelegate.
137 virtual bool HandleContextMenu(
138 const content::ContextMenuParams
& params
) override
;
139 virtual void HandleKeyboardEvent(
140 content::WebContents
* source
,
141 const content::NativeWebKeyboardEvent
& event
) override
;
142 virtual bool IsPopupOrPanel(
143 const content::WebContents
* source
) const override
;
144 virtual bool TakeFocus(content::WebContents
* source
, bool reverse
) override
;
145 virtual void RequestMediaAccessPermission(
146 content::WebContents
* web_contents
,
147 const content::MediaStreamRequest
& request
,
148 const content::MediaResponseCallback
& callback
) override
;
149 virtual bool CheckMediaAccessPermission(
150 content::WebContents
* web_contents
,
151 const GURL
& security_origin
,
152 content::MediaStreamType type
) override
;
153 virtual bool PreHandleGestureEvent(
154 content::WebContents
* source
,
155 const blink::WebGestureEvent
& event
) override
;
157 // Overridden from content::WebContentsObserver.
158 virtual void DidFailProvisionalLoad(
159 content::RenderFrameHost
* render_frame_host
,
160 const GURL
& validated_url
,
162 const base::string16
& error_description
) override
;
164 // Performs series of actions when login prompt is considered
165 // to be ready and visible.
166 // 1. Emits LoginPromptVisible signal if needed
167 // 2. Notifies OOBE/sign classes.
168 void OnLoginPromptVisible();
170 // Called when focus is returned from status area.
171 // |reverse| is true when focus is traversed backwards (using Shift-Tab).
172 void ReturnFocus(bool reverse
);
174 content::NotificationRegistrar registrar_
;
176 // Converts keyboard events on the WebContents to accelerators.
177 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_
;
179 // Maps installed accelerators to OOBE webui accelerator identifiers.
182 // True when WebUI is being initialized hidden.
185 // True when the WebUI has finished initializing and is visible.
188 // Should we emit the login-prompt-visible signal when the login page is
190 bool should_emit_login_prompt_visible_
;
192 // True to forward keyboard event.
193 bool forward_keyboard_event_
;
195 ObserverList
<web_modal::ModalDialogHostObserver
> observer_list_
;
196 ObserverList
<FrameObserver
> frame_observer_list_
;
198 // Manage popups appearing over the login window.
199 // TODO(gbillock): See if we can get rid of this. Perhaps in favor of
200 // in-content styled popups or something? There oughtta be a way...
201 scoped_ptr
<web_modal::PopupManager
> popup_manager_
;
203 DISALLOW_COPY_AND_ASSIGN(WebUILoginView
);
206 } // namespace chromeos
208 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_