Home | History | Annotate | Download | only in ui
      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/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 
     24 class GURL;
     25 
     26 namespace content {
     27 class WebUI;
     28 }
     29 
     30 namespace views {
     31 class View;
     32 class WebView;
     33 class Widget;
     34 }
     35 
     36 namespace 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.
     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 {
     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   virtual void RequestFocus() OVERRIDE;
     61 
     62   // Overridden from ChromeWebModalDialogManagerDelegate:
     63   virtual web_modal::WebContentsModalDialogHost*
     64       GetWebContentsModalDialogHost() OVERRIDE;
     65 
     66   // Overridden from web_modal::WebContentsModalDialogHost:
     67   virtual gfx::NativeView GetHostView() const OVERRIDE;
     68   virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
     69   virtual gfx::Size GetMaximumDialogSize() OVERRIDE;
     70   virtual void AddObserver(
     71       web_modal::ModalDialogHostObserver* observer) OVERRIDE;
     72   virtual void RemoveObserver(
     73       web_modal::ModalDialogHostObserver* observer) OVERRIDE;
     74 
     75   // Gets the native window from the view widget.
     76   gfx::NativeWindow GetNativeWindow() const;
     77 
     78   // Loads given page. Should be called after Init() has been called.
     79   void LoadURL(const GURL& url);
     80 
     81   // Returns current WebUI.
     82   content::WebUI* GetWebUI();
     83 
     84   // Returns current WebContents.
     85   content::WebContents* GetWebContents();
     86 
     87   // Opens proxy settings dialog.
     88   void OpenProxySettings();
     89 
     90   // Called when WebUI is being shown after being initilized hidden.
     91   void OnPostponedShow();
     92 
     93   // Toggles status area visibility.
     94   void SetStatusAreaVisible(bool visible);
     95 
     96   // Sets whether UI should be enabled.
     97   void SetUIEnabled(bool enabled);
     98 
     99   void set_is_hidden(bool hidden) { is_hidden_ = hidden; }
    100 
    101   bool webui_visible() const { return webui_visible_; }
    102 
    103   // Let suppress emission of this signal.
    104   void set_should_emit_login_prompt_visible(bool emit) {
    105     should_emit_login_prompt_visible_ = emit;
    106   }
    107 
    108  protected:
    109   // Overridden from views::View:
    110   virtual void Layout() OVERRIDE;
    111   virtual void OnLocaleChanged() OVERRIDE;
    112   virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
    113   virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
    114 
    115   // Overridden from content::NotificationObserver.
    116   virtual void Observe(int type,
    117                        const content::NotificationSource& source,
    118                        const content::NotificationDetails& details) OVERRIDE;
    119 
    120   // WebView for rendering a webpage as a webui login.
    121   views::WebView* webui_login_;
    122 
    123  private:
    124   // Map type for the accelerator-to-identifier map.
    125   typedef std::map<ui::Accelerator, std::string> AccelMap;
    126 
    127   // Overridden from content::WebContentsDelegate.
    128   virtual bool HandleContextMenu(
    129       const content::ContextMenuParams& params) OVERRIDE;
    130   virtual void HandleKeyboardEvent(
    131       content::WebContents* source,
    132       const content::NativeWebKeyboardEvent& event) OVERRIDE;
    133   virtual bool IsPopupOrPanel(
    134       const content::WebContents* source) const OVERRIDE;
    135   virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
    136   virtual void RequestMediaAccessPermission(
    137       content::WebContents* web_contents,
    138       const content::MediaStreamRequest& request,
    139       const content::MediaResponseCallback& callback) OVERRIDE;
    140   virtual bool PreHandleGestureEvent(
    141       content::WebContents* source,
    142       const blink::WebGestureEvent& event) OVERRIDE;
    143 
    144   // Overridden from content::WebContentsObserver.
    145   virtual void DidFailProvisionalLoad(
    146       int64 frame_id,
    147       const base::string16& frame_unique_name,
    148       bool is_main_frame,
    149       const GURL& validated_url,
    150       int error_code,
    151       const base::string16& error_description,
    152       content::RenderViewHost* render_view_host) OVERRIDE;
    153 
    154   // Performs series of actions when login prompt is considered
    155   // to be ready and visible.
    156   // 1. Emits LoginPromptVisible signal if needed
    157   // 2. Notifies OOBE/sign classes.
    158   void OnLoginPromptVisible();
    159 
    160   // Called when focus is returned from status area.
    161   // |reverse| is true when focus is traversed backwards (using Shift-Tab).
    162   void ReturnFocus(bool reverse);
    163 
    164   content::NotificationRegistrar registrar_;
    165 
    166   // Converts keyboard events on the WebContents to accelerators.
    167   views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
    168 
    169   // Maps installed accelerators to OOBE webui accelerator identifiers.
    170   AccelMap accel_map_;
    171 
    172   // True when WebUI is being initialized hidden.
    173   bool is_hidden_;
    174 
    175   // True when the WebUI has finished initializing and is visible.
    176   bool webui_visible_;
    177 
    178   // Should we emit the login-prompt-visible signal when the login page is
    179   // displayed?
    180   bool should_emit_login_prompt_visible_;
    181 
    182   // True to forward keyboard event.
    183   bool forward_keyboard_event_;
    184 
    185   scoped_ptr<ScopedGaiaAuthExtension> auth_extension_;
    186 
    187   ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
    188 
    189   DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
    190 };
    191 
    192 }  // namespace chromeos
    193 
    194 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEBUI_LOGIN_VIEW_H_
    195