summaryrefslogtreecommitdiffstats
path: root/athena/main/athena_launcher.cc
blob: 304b0f7966b4b50d81887b8f6a8639712b114a9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "athena/main/public/athena_launcher.h"

#include "athena/activity/public/activity_factory.h"
#include "athena/activity/public/activity_manager.h"
#include "athena/content/public/app_registry.h"
#include "athena/content/public/content_activity_factory_creator.h"
#include "athena/env/public/athena_env.h"
#include "athena/extensions/public/extension_app_model_builder.h"
#include "athena/extensions/public/extensions_delegate.h"
#include "athena/home/public/home_card.h"
#include "athena/input/public/input_manager.h"
#include "athena/main/placeholder.h"
#include "athena/main/placeholder.h"
#include "athena/main/url_search_provider.h"
#include "athena/resource_manager/public/resource_manager.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/system/public/system_ui.h"
#include "athena/virtual_keyboard/public/virtual_keyboard_manager.h"
#include "athena/wm/public/window_manager.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/aura/window_property.h"
#include "ui/aura/window_tree_host.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_controller_observer.h"
#include "ui/native_theme/native_theme_switches.h"
#include "ui/views/views_delegate.h"
#include "ui/wm/core/visibility_controller.h"

#if defined(USE_X11)
#include "ui/events/x/touch_factory_x11.h"
#endif

namespace athena {
struct AthenaEnvState;
}

DECLARE_WINDOW_PROPERTY_TYPE(athena::AthenaEnvState*);

namespace athena {

class VirtualKeyboardObserver;

// Athena's env state.
struct AthenaEnvState {
  scoped_ptr< ::wm::VisibilityController> visibility_client;
  scoped_ptr<VirtualKeyboardObserver> virtual_keyboard_observer;
};

DEFINE_OWNED_WINDOW_PROPERTY_KEY(athena::AthenaEnvState,
                                 kAthenaEnvStateKey,
                                 NULL);

// This class observes the change of the virtual keyboard and distribute the
// change to appropriate modules of athena.
// TODO(oshima): move the VK bounds logic to screen manager.
class VirtualKeyboardObserver : public keyboard::KeyboardControllerObserver {
 public:
  VirtualKeyboardObserver() {
    keyboard::KeyboardController::GetInstance()->AddObserver(this);
  }

  virtual ~VirtualKeyboardObserver() {
    keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
  }

 private:
  virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE {
    HomeCard::Get()->UpdateVirtualKeyboardBounds(new_bounds);
  }

  DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardObserver);
};

class AthenaViewsDelegate : public views::ViewsDelegate {
 public:
  AthenaViewsDelegate() {}
  virtual ~AthenaViewsDelegate() {}

 private:
  // views::ViewsDelegate:
  virtual void OnBeforeWidgetInit(
      views::Widget::InitParams* params,
      views::internal::NativeWidgetDelegate* delegate) OVERRIDE {
    params->context = athena::ScreenManager::Get()->GetContext();
  }

  DISALLOW_COPY_AND_ASSIGN(AthenaViewsDelegate);
};

void StartAthenaEnv(scoped_refptr<base::TaskRunner> file_runner) {
  athena::AthenaEnv::Create();

  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();

  // Force showing in the experimental app-list view.
  command_line->AppendSwitch(app_list::switches::kEnableExperimentalAppList);
  command_line->AppendSwitch(switches::kEnableOverlayScrollbar);

#if defined(USE_X11)
  ui::TouchFactory::SetTouchDeviceListFromCommandLine();
#endif

  views::ViewsDelegate::views_delegate = new AthenaViewsDelegate();

  AthenaEnvState* env_state = new AthenaEnvState;

  // Setup VisibilityClient
  env_state->visibility_client.reset(new ::wm::VisibilityController);
  aura::Window* root_window = athena::AthenaEnv::Get()->GetHost()->window();

  aura::client::SetVisibilityClient(root_window,
                                    env_state->visibility_client.get());

  athena::InputManager::Create()->OnRootWindowCreated(root_window);
  athena::ScreenManager::Create(root_window);
  athena::SystemUI::Create(file_runner);
  athena::WindowManager::Create();
  athena::AppRegistry::Create();
  SetupBackgroundImage();

  athena::ScreenManager::Get()->GetContext()->SetProperty(
      kAthenaEnvStateKey, env_state);
}

void StartAthenaSessionWithContext(content::BrowserContext* context) {
  StartAthenaSession(athena::CreateContentActivityFactory(),
                     new athena::ExtensionAppModelBuilder(context));
  athena::VirtualKeyboardManager::Create(context);
  athena::HomeCard::Get()->RegisterSearchProvider(
      new athena::UrlSearchProvider(context));
  AthenaEnvState* env_state =
      athena::ScreenManager::Get()->GetContext()->GetProperty(
          kAthenaEnvStateKey);

  env_state->virtual_keyboard_observer.reset(new VirtualKeyboardObserver);
  CreateTestPages(context);
}

void StartAthenaSession(athena::ActivityFactory* activity_factory,
                        athena::AppModelBuilder* app_model_builder) {
  athena::HomeCard::Create(app_model_builder);
  athena::ActivityManager::Create();
  athena::ResourceManager::Create();
  athena::ActivityFactory::RegisterActivityFactory(activity_factory);
}

void ShutdownAthena() {
  athena::ActivityFactory::Shutdown();
  athena::ResourceManager::Shutdown();
  athena::ActivityManager::Shutdown();
  athena::HomeCard::Shutdown();
  athena::AppRegistry::ShutDown();
  athena::WindowManager::Shutdown();
  athena::SystemUI::Shutdown();
  athena::ScreenManager::Shutdown();
  athena::InputManager::Shutdown();
  athena::ExtensionsDelegate::Shutdown();
  athena::AthenaEnv::Shutdown();

  delete views::ViewsDelegate::views_delegate;
}

}  // namespace athena