Home | History | Annotate | Download | only in browser
      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 EXTENSIONS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
      6 #define EXTENSIONS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "extensions/shell/browser/desktop_controller.h"
     12 #include "ui/aura/client/window_tree_client.h"
     13 #include "ui/aura/window_tree_host_observer.h"
     14 
     15 #if defined(OS_CHROMEOS)
     16 #include "chromeos/dbus/power_manager_client.h"
     17 #include "ui/display/chromeos/display_configurator.h"
     18 #endif
     19 
     20 namespace aura {
     21 class TestScreen;
     22 class Window;
     23 class WindowTreeHost;
     24 namespace client {
     25 class DefaultCaptureClient;
     26 class FocusClient;
     27 }
     28 }
     29 
     30 namespace content {
     31 class BrowserContext;
     32 }
     33 
     34 namespace gfx {
     35 class Size;
     36 }
     37 
     38 #if defined(OS_CHROMEOS)
     39 namespace ui {
     40 class UserActivityPowerManagerNotifier;
     41 }
     42 #endif
     43 
     44 namespace wm {
     45 class CompoundEventFilter;
     46 class CursorManager;
     47 class InputMethodEventFilter;
     48 class UserActivityDetector;
     49 }
     50 
     51 namespace extensions {
     52 class AppWindowClient;
     53 class Extension;
     54 
     55 // Handles desktop-related tasks for app_shell.
     56 class ShellDesktopController : public DesktopController,
     57                                public aura::client::WindowTreeClient,
     58 #if defined(OS_CHROMEOS)
     59                                public chromeos::PowerManagerClient::Observer,
     60                                public ui::DisplayConfigurator::Observer,
     61 #endif
     62                                public aura::WindowTreeHostObserver {
     63  public:
     64   ShellDesktopController();
     65   virtual ~ShellDesktopController();
     66 
     67   // DesktopController:
     68   virtual aura::WindowTreeHost* GetHost() OVERRIDE;
     69   virtual AppWindow* CreateAppWindow(content::BrowserContext* context,
     70                                      const Extension* extension) OVERRIDE;
     71   virtual void AddAppWindow(aura::Window* window) OVERRIDE;
     72   virtual void CloseAppWindows() OVERRIDE;
     73 
     74   // aura::client::WindowTreeClient overrides:
     75   virtual aura::Window* GetDefaultParent(aura::Window* context,
     76                                          aura::Window* window,
     77                                          const gfx::Rect& bounds) OVERRIDE;
     78 
     79 #if defined(OS_CHROMEOS)
     80   // chromeos::PowerManagerClient::Observer overrides:
     81   virtual void PowerButtonEventReceived(bool down,
     82                                         const base::TimeTicks& timestamp)
     83       OVERRIDE;
     84 
     85   // ui::DisplayConfigurator::Observer overrides.
     86   virtual void OnDisplayModeChanged(const std::vector<
     87       ui::DisplayConfigurator::DisplayState>& displays) OVERRIDE;
     88 #endif
     89 
     90   // aura::WindowTreeHostObserver overrides:
     91   virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) OVERRIDE;
     92 
     93  protected:
     94   // Creates and sets the aura clients and window manager stuff. Subclass may
     95   // initialize different sets of the clients.
     96   virtual void InitWindowManager();
     97 
     98  private:
     99   // Creates the window that hosts the app.
    100   void CreateRootWindow();
    101 
    102   // Closes and destroys the root window hosting the app.
    103   void DestroyRootWindow();
    104 
    105   // Returns the dimensions (in pixels) of the primary display, or an empty size
    106   // if the dimensions can't be determined or no display is connected.
    107   gfx::Size GetPrimaryDisplaySize();
    108 
    109 #if defined(OS_CHROMEOS)
    110   scoped_ptr<ui::DisplayConfigurator> display_configurator_;
    111 #endif
    112 
    113   scoped_ptr<aura::TestScreen> test_screen_;
    114 
    115   scoped_ptr<aura::WindowTreeHost> host_;
    116 
    117   scoped_ptr<wm::CompoundEventFilter> root_window_event_filter_;
    118 
    119   scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
    120 
    121   scoped_ptr<wm::InputMethodEventFilter> input_method_filter_;
    122 
    123   scoped_ptr<aura::client::FocusClient> focus_client_;
    124 
    125   scoped_ptr<wm::CursorManager> cursor_manager_;
    126 
    127   scoped_ptr<wm::UserActivityDetector> user_activity_detector_;
    128 #if defined(OS_CHROMEOS)
    129   scoped_ptr<ui::UserActivityPowerManagerNotifier> user_activity_notifier_;
    130 #endif
    131 
    132   scoped_ptr<AppWindowClient> app_window_client_;
    133 
    134   // The desktop supports a single app window.
    135   AppWindow* app_window_;  // NativeAppWindow::Close() deletes this.
    136 
    137   DISALLOW_COPY_AND_ASSIGN(ShellDesktopController);
    138 };
    139 
    140 }  // namespace extensions
    141 
    142 #endif  // EXTENSIONS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
    143