Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / ui / webui_login_view.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_
7
8 #include <map>
9 #include <string>
10
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"
24
25 class GURL;
26
27 namespace content {
28 class WebUI;
29 }
30
31 namespace views {
32 class View;
33 class WebView;
34 class Widget;
35 }
36
37 namespace chromeos {
38
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 {
47  public:
48   class FrameObserver {
49    public:
50     // Called when a frame failed to load.
51     virtual void OnFrameError(const std::string& frame_unique_name) = 0;
52   };
53
54   // Internal class name.
55   static const char kViewClassName[];
56
57   WebUILoginView();
58   virtual ~WebUILoginView();
59
60   // Initializes the webui login view.
61   virtual void Init();
62
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;
68
69   // Overridden from ChromeWebModalDialogManagerDelegate:
70   virtual web_modal::WebContentsModalDialogHost*
71       GetWebContentsModalDialogHost() OVERRIDE;
72
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;
81
82   // Gets the native window from the view widget.
83   gfx::NativeWindow GetNativeWindow() const;
84
85   // Loads given page. Should be called after Init() has been called.
86   void LoadURL(const GURL& url);
87
88   // Returns current WebUI.
89   content::WebUI* GetWebUI();
90
91   // Returns current WebContents.
92   content::WebContents* GetWebContents();
93
94   // Opens proxy settings dialog.
95   void OpenProxySettings();
96
97   // Called when WebUI is being shown after being initilized hidden.
98   void OnPostponedShow();
99
100   // Toggles status area visibility.
101   void SetStatusAreaVisible(bool visible);
102
103   // Sets whether UI should be enabled.
104   void SetUIEnabled(bool enabled);
105
106   void set_is_hidden(bool hidden) { is_hidden_ = hidden; }
107
108   bool webui_visible() const { return webui_visible_; }
109
110   // Let suppress emission of this signal.
111   void set_should_emit_login_prompt_visible(bool emit) {
112     should_emit_login_prompt_visible_ = emit;
113   }
114
115   void AddFrameObserver(FrameObserver* frame_observer);
116   void RemoveFrameObserver(FrameObserver* frame_observer);
117
118  protected:
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;
124
125   // Overridden from content::NotificationObserver.
126   virtual void Observe(int type,
127                        const content::NotificationSource& source,
128                        const content::NotificationDetails& details) OVERRIDE;
129
130   // WebView for rendering a webpage as a webui login.
131   views::WebView* webui_login_;
132
133  private:
134   // Map type for the accelerator-to-identifier map.
135   typedef std::map<ui::Accelerator, std::string> AccelMap;
136
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;
153
154   // Overridden from content::WebContentsObserver.
155   virtual void DidFailProvisionalLoad(
156       content::RenderFrameHost* render_frame_host,
157       const GURL& validated_url,
158       int error_code,
159       const base::string16& error_description) OVERRIDE;
160
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();
166
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);
170
171   content::NotificationRegistrar registrar_;
172
173   // Converts keyboard events on the WebContents to accelerators.
174   views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
175
176   // Maps installed accelerators to OOBE webui accelerator identifiers.
177   AccelMap accel_map_;
178
179   // True when WebUI is being initialized hidden.
180   bool is_hidden_;
181
182   // True when the WebUI has finished initializing and is visible.
183   bool webui_visible_;
184
185   // Should we emit the login-prompt-visible signal when the login page is
186   // displayed?
187   bool should_emit_login_prompt_visible_;
188
189   // True to forward keyboard event.
190   bool forward_keyboard_event_;
191
192   scoped_ptr<ScopedGaiaAuthExtension> auth_extension_;
193
194   ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
195   ObserverList<FrameObserver> frame_observer_list_;
196
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_;
201
202   DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
203 };
204
205 }  // namespace chromeos
206
207 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_