Add a SetWebSocketHandshakeStreamFactory() method to the HttpTransaction base class...
[chromium-blink-merge.git] / ash / shell.h
blob8d8e3bb708db45dac354858fc3e621f948c65de6
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.
5 #ifndef ASH_SHELL_H_
6 #define ASH_SHELL_H_
8 #include <utility>
9 #include <vector>
11 #include "ash/ash_export.h"
12 #include "ash/shelf/shelf_types.h"
13 #include "ash/system/user/login_status.h"
14 #include "ash/wm/system_modal_container_event_filter_delegate.h"
15 #include "base/basictypes.h"
16 #include "base/compiler_specific.h"
17 #include "base/gtest_prod_util.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h"
20 #include "base/observer_list.h"
21 #include "ui/aura/client/activation_change_observer.h"
22 #include "ui/aura/window.h"
23 #include "ui/base/ui_base_types.h"
24 #include "ui/events/event_target.h"
25 #include "ui/gfx/insets.h"
26 #include "ui/gfx/screen.h"
27 #include "ui/gfx/size.h"
28 #include "ui/views/corewm/cursor_manager.h"
30 class CommandLine;
32 namespace app_list {
33 class AppListView;
35 namespace aura {
36 class EventFilter;
37 class RootWindow;
38 class Window;
39 namespace client {
40 class ActivationClient;
41 class FocusClient;
42 class UserActionClient;
45 namespace chromeos {
46 class OutputConfigurator;
49 namespace gfx {
50 class ImageSkia;
51 class Point;
52 class Rect;
55 namespace keyboard {
56 class KeyboardController;
59 namespace ui {
60 class Layer;
62 namespace views {
63 class NonClientFrameView;
64 class Widget;
65 namespace corewm {
66 class CompoundEventFilter;
67 class InputMethodEventFilter;
68 class ShadowController;
69 class TooltipController;
70 class VisibilityController;
71 class WindowModalityController;
75 namespace ash {
77 class AcceleratorController;
78 class AccessibilityDelegate;
79 class AshNativeCursorManager;
80 class AutoclickController;
81 class CapsLockDelegate;
82 class DesktopBackgroundController;
83 class DisplayController;
84 class FirstRunHelper;
85 class HighContrastController;
86 class Launcher;
87 class LauncherDelegate;
88 class LauncherItemDelegate;
89 class LauncherItemDelegateManager;
90 class LauncherModel;
91 class LockStateController;
92 class MagnificationController;
93 class MediaDelegate;
94 class MruWindowTracker;
95 class NestedDispatcherController;
96 class NewWindowDelegate;
97 class PartialMagnificationController;
98 class PowerButtonController;
99 class RootWindowHostFactory;
100 class ScreenAsh;
101 class SessionStateDelegate;
102 class ShellDelegate;
103 class ShellObserver;
104 class StickyKeys;
105 class SystemTray;
106 class SystemTrayDelegate;
107 class SystemTrayNotifier;
108 class UserActivityDetector;
109 class UserWallpaperDelegate;
110 class VideoDetector;
111 class WebNotificationTray;
112 class WindowCycleController;
113 class WindowPositioner;
114 class WindowSelectorController;
116 namespace internal {
117 class AcceleratorFilter;
118 class AppListController;
119 class CaptureController;
120 class DisplayChangeObserver;
121 class DisplayErrorObserver;
122 class DisplayManager;
123 class DragDropController;
124 class EventClientImpl;
125 class EventRewriterEventFilter;
126 class EventTransformationHandler;
127 class FocusCycler;
128 class KeyboardUMAEventFilter;
129 class LocaleNotificationController;
130 class MouseCursorEventFilter;
131 class OutputConfiguratorAnimation;
132 class OverlayEventFilter;
133 class PowerEventObserver;
134 class ResizeShadowController;
135 class ResolutionNotificationController;
136 class RootWindowController;
137 class ScopedTargetRootWindow;
138 class ScreenPositionController;
139 class SlowAnimationEventFilter;
140 class StatusAreaWidget;
141 class SystemGestureEventFilter;
142 class SystemModalContainerEventFilter;
143 class TouchObserverHUD;
144 class UserActivityNotifier;
145 class VideoActivityNotifier;
148 namespace shell {
149 class WindowWatcher;
152 namespace test {
153 class ShellTestApi;
156 // Shell is a singleton object that presents the Shell API and implements the
157 // RootWindow's delegate interface.
159 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
160 // takes ownership of the Shell.
161 class ASH_EXPORT Shell
162 : public internal::SystemModalContainerEventFilterDelegate,
163 public ui::EventTarget,
164 public aura::client::ActivationChangeObserver {
165 public:
166 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
168 enum Direction {
169 FORWARD,
170 BACKWARD
173 // A shell must be explicitly created so that it can call |Init()| with the
174 // delegate set. |delegate| can be NULL (if not required for initialization).
175 // Takes ownership of |delegate|.
176 static Shell* CreateInstance(ShellDelegate* delegate);
178 // Should never be called before |CreateInstance()|.
179 static Shell* GetInstance();
181 // Returns true if the ash shell has been instantiated.
182 static bool HasInstance();
184 static void DeleteInstance();
186 // Returns the root window controller for the primary root window.
187 // TODO(oshima): move this to |RootWindowController|
188 static internal::RootWindowController* GetPrimaryRootWindowController();
190 // Returns all root window controllers.
191 // TODO(oshima): move this to |RootWindowController|
192 static RootWindowControllerList GetAllRootWindowControllers();
194 // Returns the primary root Window. The primary root Window is the one that
195 // has a launcher.
196 static aura::Window* GetPrimaryRootWindow();
198 // Returns a root Window when used as a target when creating a new window.
199 // The root window of the active window is used in most cases, but can
200 // be overridden by using ScopedTargetRootWindow().
201 // If you want to get the root Window of the active window, just use
202 // |wm::GetActiveWindow()->GetRootWindow()|.
203 static aura::Window* GetTargetRootWindow();
205 // Returns the global Screen object that's always active in ash.
206 static gfx::Screen* GetScreen();
208 // Returns all root windows.
209 static aura::Window::Windows GetAllRootWindows();
211 static aura::Window* GetContainer(aura::Window* root_window,
212 int container_id);
213 static const aura::Window* GetContainer(const aura::Window* root_window,
214 int container_id);
216 // Returns the list of containers that match |container_id| in
217 // all root windows. If |priority_root| is given, the container
218 // in the |priority_root| will be inserted at the top of the list.
219 static std::vector<aura::Window*> GetContainersFromAllRootWindows(
220 int container_id,
221 aura::Window* priority_root);
223 void set_target_root_window(aura::Window* target_root_window) {
224 target_root_window_ = target_root_window;
227 // Shows the context menu for the background and launcher at
228 // |location_in_screen| (in screen coordinates).
229 void ShowContextMenu(const gfx::Point& location_in_screen,
230 ui::MenuSourceType source_type);
232 // Toggles the app list. |window| specifies in which display the app
233 // list should be shown. If this is NULL, the active root window
234 // will be used.
235 void ToggleAppList(aura::Window* anchor);
237 // Returns app list target visibility.
238 bool GetAppListTargetVisibility() const;
240 // Returns app list window or NULL if it is not visible.
241 aura::Window* GetAppListWindow();
243 // Returns app list view or NULL if it is not visible.
244 app_list::AppListView* GetAppListView();
246 // Returns true if a system-modal dialog window is currently open.
247 bool IsSystemModalWindowOpen() const;
249 // For testing only: set simulation that a modal window is open
250 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
251 simulate_modal_window_open_for_testing_ = modal_window_open;
254 // Creates a default views::NonClientFrameView for use by windows in the
255 // Ash environment.
256 views::NonClientFrameView* CreateDefaultNonClientFrameView(
257 views::Widget* widget);
259 // Rotates focus through containers that can receive focus.
260 void RotateFocus(Direction direction);
262 // Sets the work area insets of the display that contains |window|,
263 // this notifies observers too.
264 // TODO(sky): this no longer really replicates what happens and is unreliable.
265 // Remove this.
266 void SetDisplayWorkAreaInsets(aura::Window* window,
267 const gfx::Insets& insets);
269 // Called when the user logs in.
270 void OnLoginStateChanged(user::LoginStatus status);
272 // Called when the login status changes.
273 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
274 void UpdateAfterLoginStatusChange(user::LoginStatus status);
276 // Called when the application is exiting.
277 void OnAppTerminating();
279 // Called when the screen is locked (after the lock window is visible) or
280 // unlocked.
281 void OnLockStateChanged(bool locked);
283 // Initializes |launcher_|. Does nothing if it's already initialized.
284 void CreateLauncher();
286 // Show shelf view if it was created hidden (before session has started).
287 void ShowLauncher();
289 // Adds/removes observer.
290 void AddShellObserver(ShellObserver* observer);
291 void RemoveShellObserver(ShellObserver* observer);
293 keyboard::KeyboardController* keyboard_controller() {
294 return keyboard_controller_.get();
297 AcceleratorController* accelerator_controller() {
298 return accelerator_controller_.get();
301 internal::DisplayManager* display_manager() {
302 return display_manager_.get();
304 views::corewm::InputMethodEventFilter* input_method_filter() {
305 return input_method_filter_.get();
307 views::corewm::CompoundEventFilter* env_filter() {
308 return env_filter_.get();
310 views::corewm::TooltipController* tooltip_controller() {
311 return tooltip_controller_.get();
313 internal::EventRewriterEventFilter* event_rewriter_filter() {
314 return event_rewriter_filter_.get();
316 internal::OverlayEventFilter* overlay_filter() {
317 return overlay_filter_.get();
319 DesktopBackgroundController* desktop_background_controller() {
320 return desktop_background_controller_.get();
322 PowerButtonController* power_button_controller() {
323 return power_button_controller_.get();
325 LockStateController* lock_state_controller() {
326 return lock_state_controller_.get();
328 MruWindowTracker* mru_window_tracker() {
329 return mru_window_tracker_.get();
331 UserActivityDetector* user_activity_detector() {
332 return user_activity_detector_.get();
334 VideoDetector* video_detector() {
335 return video_detector_.get();
337 WindowCycleController* window_cycle_controller() {
338 return window_cycle_controller_.get();
340 WindowSelectorController* window_selector_controller() {
341 return window_selector_controller_.get();
343 internal::FocusCycler* focus_cycler() {
344 return focus_cycler_.get();
346 DisplayController* display_controller() {
347 return display_controller_.get();
349 internal::MouseCursorEventFilter* mouse_cursor_filter() {
350 return mouse_cursor_filter_.get();
352 internal::EventTransformationHandler* event_transformation_handler() {
353 return event_transformation_handler_.get();
355 views::corewm::CursorManager* cursor_manager() { return &cursor_manager_; }
357 ShellDelegate* delegate() { return delegate_.get(); }
359 UserWallpaperDelegate* user_wallpaper_delegate() {
360 return user_wallpaper_delegate_.get();
363 CapsLockDelegate* caps_lock_delegate() {
364 return caps_lock_delegate_.get();
367 SessionStateDelegate* session_state_delegate() {
368 return session_state_delegate_.get();
371 AccessibilityDelegate* accessibility_delegate() {
372 return accessibility_delegate_.get();
375 NewWindowDelegate* new_window_delegate() {
376 return new_window_delegate_.get();
379 MediaDelegate* media_delegate() {
380 return media_delegate_.get();
383 HighContrastController* high_contrast_controller() {
384 return high_contrast_controller_.get();
387 MagnificationController* magnification_controller() {
388 return magnification_controller_.get();
391 PartialMagnificationController* partial_magnification_controller() {
392 return partial_magnification_controller_.get();
395 AutoclickController* autoclick_controller() {
396 return autoclick_controller_.get();
399 aura::client::ActivationClient* activation_client() {
400 return activation_client_;
403 LauncherItemDelegateManager* launcher_item_delegate_manager() {
404 return launcher_item_delegate_manager_.get();
407 ScreenAsh* screen() { return screen_; }
409 // Force the shelf to query for it's current visibility state.
410 void UpdateShelfVisibility();
412 // TODO(oshima): Define an interface to access shelf/launcher
413 // state, or just use Launcher.
415 // Sets/gets the shelf auto-hide behavior on |root_window|.
416 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
417 aura::Window* root_window);
418 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
419 aura::Window* root_window) const;
421 // Sets/gets shelf's alignment on |root_window|.
422 void SetShelfAlignment(ShelfAlignment alignment,
423 aura::Window* root_window);
424 ShelfAlignment GetShelfAlignment(aura::Window* root_window);
426 // Dims or undims the screen.
427 void SetDimming(bool should_dim);
429 // Notifies |observers_| when entering or exiting fullscreen mode in
430 // |root_window|.
431 void NotifyFullscreenStateChange(bool is_fullscreen,
432 aura::Window* root_window);
434 // Creates a modal background (a partially-opaque fullscreen window)
435 // on all displays for |window|.
436 void CreateModalBackground(aura::Window* window);
438 // Called when a modal window is removed. It will activate
439 // another modal window if any, or remove modal screens
440 // on all displays.
441 void OnModalWindowRemoved(aura::Window* removed);
443 // Returns WebNotificationTray on the primary root window.
444 WebNotificationTray* GetWebNotificationTray();
446 // Does the primary display have status area?
447 bool HasPrimaryStatusArea();
449 // Returns the system tray on primary display.
450 SystemTray* GetPrimarySystemTray();
452 SystemTrayDelegate* system_tray_delegate() {
453 return system_tray_delegate_.get();
456 SystemTrayNotifier* system_tray_notifier() {
457 return system_tray_notifier_.get();
460 static void set_initially_hide_cursor(bool hide) {
461 initially_hide_cursor_ = hide;
464 internal::ResizeShadowController* resize_shadow_controller() {
465 return resize_shadow_controller_.get();
468 // Made available for tests.
469 views::corewm::ShadowController* shadow_controller() {
470 return shadow_controller_.get();
473 // Starts the animation that occurs on first login.
474 void DoInitialWorkspaceAnimation();
476 #if defined(OS_CHROMEOS) && defined(USE_X11)
477 // TODO(oshima): Move these objects to DisplayController.
478 chromeos::OutputConfigurator* output_configurator() {
479 return output_configurator_.get();
481 internal::OutputConfiguratorAnimation* output_configurator_animation() {
482 return output_configurator_animation_.get();
484 internal::DisplayErrorObserver* display_error_observer() {
485 return display_error_observer_.get();
487 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
489 internal::ResolutionNotificationController*
490 resolution_notification_controller() {
491 return resolution_notification_controller_.get();
494 RootWindowHostFactory* root_window_host_factory() {
495 return root_window_host_factory_.get();
498 LauncherModel* launcher_model() {
499 return launcher_model_.get();
502 WindowPositioner* window_positioner() {
503 return window_positioner_.get();
506 // Returns the launcher delegate, creating if necesary.
507 LauncherDelegate* GetLauncherDelegate();
509 void SetTouchHudProjectionEnabled(bool enabled);
511 bool is_touch_hud_projection_enabled() const {
512 return is_touch_hud_projection_enabled_;
515 #if defined(OS_CHROMEOS)
516 // Creates instance of FirstRunHelper. Caller is responsible for deleting
517 // returned object.
518 ash::FirstRunHelper* CreateFirstRunHelper();
520 StickyKeys* sticky_keys() {
521 return sticky_keys_.get();
523 #endif // defined(OS_CHROMEOS)
525 private:
526 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
527 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
528 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
529 friend class internal::RootWindowController;
530 friend class internal::ScopedTargetRootWindow;
531 friend class test::ShellTestApi;
532 friend class shell::WindowWatcher;
534 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
536 // Takes ownership of |delegate|.
537 explicit Shell(ShellDelegate* delegate);
538 virtual ~Shell();
540 void Init();
542 // Initializes virtual keyboard controller and attaches it to |root|.
543 void InitKeyboard(internal::RootWindowController* root);
545 // Initializes the root window so that it can host browser windows.
546 void InitRootWindow(aura::Window* root_window);
548 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
549 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
551 // Overridden from ui::EventTarget:
552 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
553 virtual EventTarget* GetParentTarget() OVERRIDE;
554 virtual void OnEvent(ui::Event* event) OVERRIDE;
556 // Overridden from aura::client::ActivationChangeObserver:
557 virtual void OnWindowActivated(aura::Window* gained_active,
558 aura::Window* lost_active) OVERRIDE;
560 static Shell* instance_;
562 // If set before the Shell is initialized, the mouse cursor will be hidden
563 // when the screen is initially created.
564 static bool initially_hide_cursor_;
566 ScreenAsh* screen_;
568 // When no explicit target display/RootWindow is given, new windows are
569 // created on |scoped_target_root_window_| , unless NULL in
570 // which case they are created on |target_root_window_|.
571 // |target_root_window_| never becomes NULL during the session.
572 aura::Window* target_root_window_;
573 aura::Window* scoped_target_root_window_;
575 // The CompoundEventFilter owned by aura::Env object.
576 scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
578 std::vector<WindowAndBoundsPair> to_restore_;
580 scoped_ptr<keyboard::KeyboardController> keyboard_controller_;
581 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
582 scoped_ptr<AcceleratorController> accelerator_controller_;
583 scoped_ptr<ShellDelegate> delegate_;
584 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
585 scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
586 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
587 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
588 scoped_ptr<SessionStateDelegate> session_state_delegate_;
589 scoped_ptr<AccessibilityDelegate> accessibility_delegate_;
590 scoped_ptr<NewWindowDelegate> new_window_delegate_;
591 scoped_ptr<MediaDelegate> media_delegate_;
592 scoped_ptr<LauncherDelegate> launcher_delegate_;
593 scoped_ptr<LauncherItemDelegateManager> launcher_item_delegate_manager_;
595 scoped_ptr<LauncherModel> launcher_model_;
596 scoped_ptr<ash::WindowPositioner> window_positioner_;
598 scoped_ptr<internal::AppListController> app_list_controller_;
600 scoped_ptr<internal::DragDropController> drag_drop_controller_;
601 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
602 scoped_ptr<views::corewm::ShadowController> shadow_controller_;
603 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
604 scoped_ptr<views::corewm::WindowModalityController>
605 window_modality_controller_;
606 scoped_ptr<views::corewm::TooltipController> tooltip_controller_;
607 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
608 scoped_ptr<PowerButtonController> power_button_controller_;
609 scoped_ptr<LockStateController> lock_state_controller_;
610 scoped_ptr<MruWindowTracker> mru_window_tracker_;
611 scoped_ptr<UserActivityDetector> user_activity_detector_;
612 scoped_ptr<VideoDetector> video_detector_;
613 scoped_ptr<WindowCycleController> window_cycle_controller_;
614 scoped_ptr<WindowSelectorController> window_selector_controller_;
615 scoped_ptr<internal::FocusCycler> focus_cycler_;
616 scoped_ptr<DisplayController> display_controller_;
617 scoped_ptr<HighContrastController> high_contrast_controller_;
618 scoped_ptr<MagnificationController> magnification_controller_;
619 scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
620 scoped_ptr<AutoclickController> autoclick_controller_;
621 scoped_ptr<aura::client::FocusClient> focus_client_;
622 scoped_ptr<aura::client::UserActionClient> user_action_client_;
623 aura::client::ActivationClient* activation_client_;
624 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
625 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
626 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
627 scoped_ptr<internal::EventClientImpl> event_client_;
628 scoped_ptr<internal::EventTransformationHandler>
629 event_transformation_handler_;
630 scoped_ptr<RootWindowHostFactory> root_window_host_factory_;
632 // An event filter that rewrites or drops an event.
633 scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_;
635 // An event filter that pre-handles key events while the partial
636 // screenshot UI or the keyboard overlay is active.
637 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
639 // An event filter for logging keyboard-related metrics.
640 scoped_ptr<internal::KeyboardUMAEventFilter> keyboard_metrics_filter_;
642 // An event filter which handles system level gestures
643 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
645 // An event filter that pre-handles global accelerators.
646 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
648 // An event filter that pre-handles all key events to send them to an IME.
649 scoped_ptr<views::corewm::InputMethodEventFilter> input_method_filter_;
651 scoped_ptr<internal::DisplayManager> display_manager_;
652 scoped_ptr<base::WeakPtrFactory<internal::DisplayManager> >
653 weak_display_manager_factory_;
655 scoped_ptr<internal::LocaleNotificationController>
656 locale_notification_controller_;
658 #if defined(OS_CHROMEOS)
659 scoped_ptr<internal::PowerEventObserver> power_event_observer_;
660 scoped_ptr<internal::UserActivityNotifier> user_activity_notifier_;
661 scoped_ptr<internal::VideoActivityNotifier> video_activity_notifier_;
662 scoped_ptr<StickyKeys> sticky_keys_;
663 #if defined(USE_X11)
664 // Controls video output device state.
665 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
666 scoped_ptr<internal::OutputConfiguratorAnimation>
667 output_configurator_animation_;
668 scoped_ptr<internal::DisplayErrorObserver> display_error_observer_;
670 // Listens for output changes and updates the display manager.
671 scoped_ptr<internal::DisplayChangeObserver> display_change_observer_;
672 #endif // defined(USE_X11)
673 #endif // defined(OS_CHROMEOS)
675 scoped_ptr<internal::ResolutionNotificationController>
676 resolution_notification_controller_;
678 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
679 // pointer to vend to test code.
680 AshNativeCursorManager* native_cursor_manager_;
681 views::corewm::CursorManager cursor_manager_;
683 ObserverList<ShellObserver> observers_;
685 // For testing only: simulate that a modal window is open
686 bool simulate_modal_window_open_for_testing_;
688 bool is_touch_hud_projection_enabled_;
690 DISALLOW_COPY_AND_ASSIGN(Shell);
693 } // namespace ash
695 #endif // ASH_SHELL_H_