Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / athena / main / athena_launcher.cc
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 #include "athena/main/athena_launcher.h"
6
7 #include "athena/activity/public/activity_factory.h"
8 #include "athena/activity/public/activity_manager.h"
9 #include "athena/home/public/home_card.h"
10 #include "athena/input/public/input_manager.h"
11 #include "athena/main/placeholder.h"
12 #include "athena/screen/public/screen_manager.h"
13 #include "athena/system/public/system_ui.h"
14 #include "athena/wm/public/window_manager.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "ui/aura/window_property.h"
18 #include "ui/views/views_delegate.h"
19 #include "ui/wm/core/visibility_controller.h"
20
21 #if defined(USE_X11)
22 #include "ui/events/x/touch_factory_x11.h"
23 #endif
24
25 namespace athena {
26 struct RootWindowState;
27 }
28
29 DECLARE_WINDOW_PROPERTY_TYPE(athena::RootWindowState*);
30
31 namespace athena {
32
33 // Athena's per root window state.
34 struct RootWindowState {
35   scoped_ptr< ::wm::VisibilityController> visibility_client;
36 };
37
38 DEFINE_OWNED_WINDOW_PROPERTY_KEY(athena::RootWindowState,
39                                  kRootWindowStateKey,
40                                  NULL);
41
42 class AthenaViewsDelegate : public views::ViewsDelegate {
43  public:
44   AthenaViewsDelegate() {}
45   virtual ~AthenaViewsDelegate() {}
46
47  private:
48   // views::ViewsDelegate:
49   virtual void OnBeforeWidgetInit(
50       views::Widget::InitParams* params,
51       views::internal::NativeWidgetDelegate* delegate) OVERRIDE {
52   }
53
54   DISALLOW_COPY_AND_ASSIGN(AthenaViewsDelegate);
55 };
56
57 void StartAthena(aura::Window* root_window,
58                  athena::ActivityFactory* activity_factory,
59                  athena::AppModelBuilder* app_model_builder) {
60 #if defined(USE_X11)
61   ui::TouchFactory::SetTouchDeviceListFromCommandLine();
62 #endif
63
64   views::ViewsDelegate::views_delegate = new AthenaViewsDelegate();
65
66   RootWindowState* root_window_state = new RootWindowState;
67   root_window->SetProperty(kRootWindowStateKey, root_window_state);
68
69   root_window_state->visibility_client.reset(new ::wm::VisibilityController);
70   aura::client::SetVisibilityClient(root_window,
71                                     root_window_state->visibility_client.get());
72
73   athena::SystemUI::Create(
74       content::BrowserThread::GetMessageLoopProxyForThread(
75           content::BrowserThread::FILE));
76   athena::InputManager::Create()->OnRootWindowCreated(root_window);
77   athena::ScreenManager::Create(root_window);
78   athena::WindowManager::Create();
79   athena::HomeCard::Create(app_model_builder);
80   athena::ActivityManager::Create();
81   athena::ActivityFactory::RegisterActivityFactory(activity_factory);
82   SetupBackgroundImage();
83 }
84
85 void ShutdownAthena() {
86   athena::ActivityFactory::Shutdown();
87   athena::ActivityManager::Shutdown();
88   athena::HomeCard::Shutdown();
89   athena::WindowManager::Shutdown();
90   athena::ScreenManager::Shutdown();
91   athena::InputManager::Shutdown();
92   athena::SystemUI::Shutdown();
93
94   delete views::ViewsDelegate::views_delegate;
95 }
96
97 }  // namespace athena