webui_login_view.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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.
4
5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_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/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"
23
24class GURL;
25
26namespace content {
27class WebUI;
28}
29
30namespace views {
31class View;
32class WebView;
33class Widget;
34}
35
36namespace chromeos {
37
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.
40class WebUILoginView : public views::View,
41                       public content::WebContentsDelegate,
42                       public content::WebContentsObserver,
43                       public content::NotificationObserver,
44                       public ChromeWebModalDialogManagerDelegate,
45                       public web_modal::WebContentsModalDialogHost {
46 public:
47  // Internal class name.
48  static const char kViewClassName[];
49
50  WebUILoginView();
51  virtual ~WebUILoginView();
52
53  // Initializes the webui login view.
54  virtual void Init();
55
56  // Overridden from views::View:
57  virtual bool AcceleratorPressed(
58      const ui::Accelerator& accelerator) OVERRIDE;
59  virtual const char* GetClassName() const OVERRIDE;
60
61  // Overridden from ChromeWebModalDialogManagerDelegate:
62  virtual web_modal::WebContentsModalDialogHost*
63      GetWebContentsModalDialogHost() OVERRIDE;
64
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;
73
74  // Gets the native window from the view widget.
75  gfx::NativeWindow GetNativeWindow() const;
76
77  // Loads given page. Should be called after Init() has been called.
78  void LoadURL(const GURL& url);
79
80  // Returns current WebUI.
81  content::WebUI* GetWebUI();
82
83  // Returns current WebContents.
84  content::WebContents* GetWebContents();
85
86  // Opens proxy settings dialog.
87  void OpenProxySettings();
88
89  // Called when WebUI is being shown after being initilized hidden.
90  void OnPostponedShow();
91
92  // Toggles status area visibility.
93  void SetStatusAreaVisible(bool visible);
94
95  // Sets whether UI should be enabled.
96  void SetUIEnabled(bool enabled);
97
98  void set_is_hidden(bool hidden) { is_hidden_ = hidden; }
99
100  bool webui_visible() const { return webui_visible_; }
101
102  // Let suppress emission of this signal.
103  void set_should_emit_login_prompt_visible(bool emit) {
104    should_emit_login_prompt_visible_ = emit;
105  }
106
107 protected:
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;
113
114  // Overridden from content::NotificationObserver.
115  virtual void Observe(int type,
116                       const content::NotificationSource& source,
117                       const content::NotificationDetails& details) OVERRIDE;
118
119  // WebView for rendering a webpage as a webui login.
120  views::WebView* webui_login_;
121
122 private:
123  // Map type for the accelerator-to-identifier map.
124  typedef std::map<ui::Accelerator, std::string> AccelMap;
125
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;
139
140  // Overridden from content::WebContentsObserver.
141  virtual void DidFailProvisionalLoad(
142      int64 frame_id,
143      const string16& frame_unique_name,
144      bool is_main_frame,
145      const GURL& validated_url,
146      int error_code,
147      const string16& error_description,
148      content::RenderViewHost* render_view_host) OVERRIDE;
149
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();
155
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);
159
160  content::NotificationRegistrar registrar_;
161
162  // Converts keyboard events on the WebContents to accelerators.
163  views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
164
165  // Maps installed accelerators to OOBE webui accelerator identifiers.
166  AccelMap accel_map_;
167
168  // True when WebUI is being initialized hidden.
169  bool is_hidden_;
170
171  // True when the WebUI has finished initializing and is visible.
172  bool webui_visible_;
173
174  // Should we emit the login-prompt-visible signal when the login page is
175  // displayed?
176  bool should_emit_login_prompt_visible_;
177
178  // True to forward keyboard event.
179  bool forward_keyboard_event_;
180
181  scoped_ptr<ScopedGaiaAuthExtension> auth_extension_;
182
183  ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
184
185  DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
186};
187
188}  // namespace chromeos
189
190#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
191