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/extensions/signin/scoped_gaia_auth_extension.h"
14 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
15 #include "components/web_modal/popup_manager.h"
16 #include "components/web_modal/web_contents_modal_dialog_host.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/web_contents_delegate.h"
20 #include "content/public/browser/web_contents_observer.h"
21 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
22 #include "ui/views/widget/widget.h"
23 #include "ui/views/widget/widget_delegate.h"
39 // View used to render a WebUI supporting Widget. This widget is used for the
40 // WebUI based start up and lock screens. It contains a WebView.
41 class WebUILoginView : public views::View,
42 public content::WebContentsDelegate,
43 public content::WebContentsObserver,
44 public content::NotificationObserver,
45 public ChromeWebModalDialogManagerDelegate,
46 public web_modal::WebContentsModalDialogHost {
50 // Called when a frame failed to load.
51 virtual void OnFrameError(const std::string& frame_unique_name) = 0;
54 // Internal class name.
55 static const char kViewClassName[];
58 virtual ~WebUILoginView();
60 // Initializes the webui login view.
63 // Overridden from views::View:
64 virtual bool AcceleratorPressed(
65 const ui::Accelerator& accelerator) OVERRIDE;
66 virtual const char* GetClassName() const OVERRIDE;
67 virtual void RequestFocus() OVERRIDE;
69 // Overridden from ChromeWebModalDialogManagerDelegate:
70 virtual web_modal::WebContentsModalDialogHost*
71 GetWebContentsModalDialogHost() OVERRIDE;
73 // Overridden from web_modal::WebContentsModalDialogHost:
74 virtual gfx::NativeView GetHostView() const OVERRIDE;
75 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
76 virtual gfx::Size GetMaximumDialogSize() OVERRIDE;
77 virtual void AddObserver(
78 web_modal::ModalDialogHostObserver* observer) OVERRIDE;
79 virtual void RemoveObserver(
80 web_modal::ModalDialogHostObserver* observer) OVERRIDE;
82 // Gets the native window from the view widget.
83 gfx::NativeWindow GetNativeWindow() const;
85 // Loads given page. Should be called after Init() has been called.
86 void LoadURL(const GURL& url);
88 // Returns current WebUI.
89 content::WebUI* GetWebUI();
91 // Returns current WebContents.
92 content::WebContents* GetWebContents();
94 // Opens proxy settings dialog.
95 void OpenProxySettings();
97 // Called when WebUI is being shown after being initilized hidden.
98 void OnPostponedShow();
100 // Toggles status area visibility.
101 void SetStatusAreaVisible(bool visible);
103 // Sets whether UI should be enabled.
104 void SetUIEnabled(bool enabled);
106 void set_is_hidden(bool hidden) { is_hidden_ = hidden; }
108 bool webui_visible() const { return webui_visible_; }
110 // Let suppress emission of this signal.
111 void set_should_emit_login_prompt_visible(bool emit) {
112 should_emit_login_prompt_visible_ = emit;
115 void AddFrameObserver(FrameObserver* frame_observer);
116 void RemoveFrameObserver(FrameObserver* frame_observer);
119 // Overridden from views::View:
120 virtual void Layout() OVERRIDE;
121 virtual void OnLocaleChanged() OVERRIDE;
122 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
123 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
125 // Overridden from content::NotificationObserver.
126 virtual void Observe(int type,
127 const content::NotificationSource& source,
128 const content::NotificationDetails& details) OVERRIDE;
130 // WebView for rendering a webpage as a webui login.
131 views::WebView* webui_login_;
134 // Map type for the accelerator-to-identifier map.
135 typedef std::map<ui::Accelerator, std::string> AccelMap;
137 // Overridden from content::WebContentsDelegate.
138 virtual bool HandleContextMenu(
139 const content::ContextMenuParams& params) OVERRIDE;
140 virtual void HandleKeyboardEvent(
141 content::WebContents* source,
142 const content::NativeWebKeyboardEvent& event) OVERRIDE;
143 virtual bool IsPopupOrPanel(
144 const content::WebContents* source) const OVERRIDE;
145 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
146 virtual void RequestMediaAccessPermission(
147 content::WebContents* web_contents,
148 const content::MediaStreamRequest& request,
149 const content::MediaResponseCallback& callback) OVERRIDE;
150 virtual bool PreHandleGestureEvent(
151 content::WebContents* source,
152 const blink::WebGestureEvent& event) OVERRIDE;
154 // Overridden from content::WebContentsObserver.
155 virtual void DidFailProvisionalLoad(
156 content::RenderFrameHost* render_frame_host,
157 const GURL& validated_url,
159 const base::string16& error_description) OVERRIDE;
161 // Performs series of actions when login prompt is considered
162 // to be ready and visible.
163 // 1. Emits LoginPromptVisible signal if needed
164 // 2. Notifies OOBE/sign classes.
165 void OnLoginPromptVisible();
167 // Called when focus is returned from status area.
168 // |reverse| is true when focus is traversed backwards (using Shift-Tab).
169 void ReturnFocus(bool reverse);
171 content::NotificationRegistrar registrar_;
173 // Converts keyboard events on the WebContents to accelerators.
174 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
176 // Maps installed accelerators to OOBE webui accelerator identifiers.
179 // True when WebUI is being initialized hidden.
182 // True when the WebUI has finished initializing and is visible.
185 // Should we emit the login-prompt-visible signal when the login page is
187 bool should_emit_login_prompt_visible_;
189 // True to forward keyboard event.
190 bool forward_keyboard_event_;
192 scoped_ptr<ScopedGaiaAuthExtension> auth_extension_;
194 ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
195 ObserverList<FrameObserver> frame_observer_list_;
197 // Manage popups appearing over the login window.
198 // TODO(gbillock): See if we can get rid of this. Perhaps in favor of
199 // in-content styled popups or something? There oughtta be a way...
200 scoped_ptr<web_modal::PopupManager> popup_manager_;
202 DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
205 } // namespace chromeos
207 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_