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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "chrome/browser/extensions/signin/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 "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
{
47 // Internal class name.
48 static const char kViewClassName
[];
51 virtual ~WebUILoginView();
53 // Initializes the webui login view.
56 // Overridden from views::View:
57 virtual bool AcceleratorPressed(
58 const ui::Accelerator
& accelerator
) OVERRIDE
;
59 virtual const char* GetClassName() const OVERRIDE
;
61 // Overridden from ChromeWebModalDialogManagerDelegate:
62 virtual web_modal::WebContentsModalDialogHost
*
63 GetWebContentsModalDialogHost() OVERRIDE
;
65 // Overridden from web_modal::WebContentsModalDialogHost:
66 virtual gfx::NativeView
GetHostView() const OVERRIDE
;
67 virtual gfx::Point
GetDialogPosition(const gfx::Size
& size
) OVERRIDE
;
68 virtual gfx::Size
GetMaximumDialogSize() OVERRIDE
;
69 virtual void AddObserver(
70 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
71 virtual void RemoveObserver(
72 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
74 // Gets the native window from the view widget.
75 gfx::NativeWindow
GetNativeWindow() const;
77 // Loads given page. Should be called after Init() has been called.
78 void LoadURL(const GURL
& url
);
80 // Returns current WebUI.
81 content::WebUI
* GetWebUI();
83 // Returns current WebContents.
84 content::WebContents
* GetWebContents();
86 // Opens proxy settings dialog.
87 void OpenProxySettings();
89 // Called when WebUI is being shown after being initilized hidden.
90 void OnPostponedShow();
92 // Toggles status area visibility.
93 void SetStatusAreaVisible(bool visible
);
95 // Sets whether UI should be enabled.
96 void SetUIEnabled(bool enabled
);
98 void set_is_hidden(bool hidden
) { is_hidden_
= hidden
; }
100 bool webui_visible() const { return webui_visible_
; }
102 // Let suppress emission of this signal.
103 void set_should_emit_login_prompt_visible(bool emit
) {
104 should_emit_login_prompt_visible_
= emit
;
108 // Overridden from views::View:
109 virtual void Layout() OVERRIDE
;
110 virtual void OnLocaleChanged() OVERRIDE
;
111 virtual void ChildPreferredSizeChanged(View
* child
) OVERRIDE
;
112 virtual void AboutToRequestFocusFromTabTraversal(bool reverse
) OVERRIDE
;
114 // Overridden from content::NotificationObserver.
115 virtual void Observe(int type
,
116 const content::NotificationSource
& source
,
117 const content::NotificationDetails
& details
) OVERRIDE
;
119 // WebView for rendering a webpage as a webui login.
120 views::WebView
* webui_login_
;
123 // Map type for the accelerator-to-identifier map.
124 typedef std::map
<ui::Accelerator
, std::string
> AccelMap
;
126 // Overridden from content::WebContentsDelegate.
127 virtual bool HandleContextMenu(
128 const content::ContextMenuParams
& params
) OVERRIDE
;
129 virtual void HandleKeyboardEvent(
130 content::WebContents
* source
,
131 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
132 virtual bool IsPopupOrPanel(
133 const content::WebContents
* source
) const OVERRIDE
;
134 virtual bool TakeFocus(content::WebContents
* source
, bool reverse
) OVERRIDE
;
135 virtual void RequestMediaAccessPermission(
136 content::WebContents
* web_contents
,
137 const content::MediaStreamRequest
& request
,
138 const content::MediaResponseCallback
& callback
) OVERRIDE
;
140 // Overridden from content::WebContentsObserver.
141 virtual void DidFailProvisionalLoad(
143 const base::string16
& frame_unique_name
,
145 const GURL
& validated_url
,
147 const base::string16
& error_description
,
148 content::RenderViewHost
* render_view_host
) OVERRIDE
;
150 // Performs series of actions when login prompt is considered
151 // to be ready and visible.
152 // 1. Emits LoginPromptVisible signal if needed
153 // 2. Notifies OOBE/sign classes.
154 void OnLoginPromptVisible();
156 // Called when focus is returned from status area.
157 // |reverse| is true when focus is traversed backwards (using Shift-Tab).
158 void ReturnFocus(bool reverse
);
160 content::NotificationRegistrar registrar_
;
162 // Converts keyboard events on the WebContents to accelerators.
163 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_
;
165 // Maps installed accelerators to OOBE webui accelerator identifiers.
168 // True when WebUI is being initialized hidden.
171 // True when the WebUI has finished initializing and is visible.
174 // Should we emit the login-prompt-visible signal when the login page is
176 bool should_emit_login_prompt_visible_
;
178 // True to forward keyboard event.
179 bool forward_keyboard_event_
;
181 scoped_ptr
<ScopedGaiaAuthExtension
> auth_extension_
;
183 ObserverList
<web_modal::ModalDialogHostObserver
> observer_list_
;
185 DISALLOW_COPY_AND_ASSIGN(WebUILoginView
);
188 } // namespace chromeos
190 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_