[docs] omnibox. Must escape XML entities inside SuggestResult
[chromium-blink-merge.git] / athena / main / athena_launcher.cc
blobe85327fd1a461bb263f7767cae326b868adb2475
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.
5 #include "athena/main/public/athena_launcher.h"
7 #include "athena/activity/public/activity_factory.h"
8 #include "athena/activity/public/activity_manager.h"
9 #include "athena/content/public/app_registry.h"
10 #include "athena/content/public/content_activity_factory_creator.h"
11 #include "athena/env/public/athena_env.h"
12 #include "athena/extensions/public/extension_app_model_builder.h"
13 #include "athena/extensions/public/extensions_delegate.h"
14 #include "athena/home/public/home_card.h"
15 #include "athena/input/public/input_manager.h"
16 #include "athena/main/athena_views_delegate.h"
17 #include "athena/main/placeholder.h"
18 #include "athena/main/placeholder.h"
19 #include "athena/main/url_search_provider.h"
20 #include "athena/resource_manager/public/resource_manager.h"
21 #include "athena/screen/public/screen_manager.h"
22 #include "athena/system/public/system_ui.h"
23 #include "athena/virtual_keyboard/public/virtual_keyboard_manager.h"
24 #include "athena/wm/public/window_manager.h"
25 #include "base/command_line.h"
26 #include "base/memory/scoped_ptr.h"
27 #include "content/public/common/content_switches.h"
28 #include "ui/app_list/app_list_switches.h"
29 #include "ui/aura/window_property.h"
30 #include "ui/aura/window_tree_host.h"
31 #include "ui/keyboard/keyboard_controller.h"
32 #include "ui/keyboard/keyboard_controller_observer.h"
33 #include "ui/native_theme/native_theme_switches.h"
34 #include "ui/wm/core/visibility_controller.h"
36 #if defined(USE_X11)
37 #include "ui/events/x/touch_factory_x11.h"
38 #endif
40 namespace athena {
41 struct AthenaEnvState;
44 DECLARE_WINDOW_PROPERTY_TYPE(athena::AthenaEnvState*);
46 namespace athena {
48 namespace {
50 bool session_started = false;
52 } // namespace
54 class VirtualKeyboardObserver;
56 // Athena's env state.
57 struct AthenaEnvState {
58 scoped_ptr< ::wm::VisibilityController> visibility_client;
59 scoped_ptr<VirtualKeyboardObserver> virtual_keyboard_observer;
62 DEFINE_OWNED_WINDOW_PROPERTY_KEY(athena::AthenaEnvState,
63 kAthenaEnvStateKey,
64 NULL);
66 // This class observes the change of the virtual keyboard and distribute the
67 // change to appropriate modules of athena.
68 // TODO(oshima): move the VK bounds logic to screen manager.
69 class VirtualKeyboardObserver : public keyboard::KeyboardControllerObserver {
70 public:
71 VirtualKeyboardObserver() {
72 keyboard::KeyboardController::GetInstance()->AddObserver(this);
75 virtual ~VirtualKeyboardObserver() {
76 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
79 private:
80 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override {
81 HomeCard::Get()->UpdateVirtualKeyboardBounds(new_bounds);
84 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardObserver);
87 void StartAthenaEnv(scoped_refptr<base::TaskRunner> blocking_task_runner) {
88 athena::AthenaEnv::Create();
90 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
92 // Force showing in the experimental app-list view.
93 command_line->AppendSwitch(app_list::switches::kEnableExperimentalAppList);
94 command_line->AppendSwitch(switches::kEnableOverlayScrollbar);
96 // Enable vertical overscroll.
97 command_line->AppendSwitchASCII(switches::kScrollEndEffect, "1");
99 #if defined(USE_X11)
100 ui::TouchFactory::SetTouchDeviceListFromCommandLine();
101 #endif
103 CreateAthenaViewsDelegate();
105 AthenaEnvState* env_state = new AthenaEnvState;
107 // Setup VisibilityClient
108 env_state->visibility_client.reset(new ::wm::VisibilityController);
109 aura::Window* root_window = athena::AthenaEnv::Get()->GetHost()->window();
111 aura::client::SetVisibilityClient(root_window,
112 env_state->visibility_client.get());
114 athena::InputManager::Create()->OnRootWindowCreated(root_window);
115 athena::ScreenManager::Create(root_window);
116 athena::SystemUI::Create(blocking_task_runner);
117 athena::WindowManager::Create();
118 athena::AppRegistry::Create();
119 SetupBackgroundImage();
121 athena::ScreenManager::Get()->GetContext()->SetProperty(
122 kAthenaEnvStateKey, env_state);
125 void CreateVirtualKeyboardWithContext(content::BrowserContext* context) {
126 athena::VirtualKeyboardManager::Create(context);
129 void StartAthenaSessionWithContext(content::BrowserContext* context) {
130 athena::ExtensionsDelegate::CreateExtensionsDelegate(context);
131 StartAthenaSession(athena::CreateContentActivityFactory(),
132 new athena::ExtensionAppModelBuilder(context));
133 athena::HomeCard::Get()->RegisterSearchProvider(
134 new athena::UrlSearchProvider(context));
135 AthenaEnvState* env_state =
136 athena::ScreenManager::Get()->GetContext()->GetProperty(
137 kAthenaEnvStateKey);
139 env_state->virtual_keyboard_observer.reset(new VirtualKeyboardObserver);
140 CreateTestPages(context);
143 void StartAthenaSession(athena::ActivityFactory* activity_factory,
144 athena::AppModelBuilder* app_model_builder) {
145 DCHECK(!session_started);
146 session_started = true;
147 athena::HomeCard::Create(app_model_builder);
148 athena::ActivityManager::Create();
149 athena::ResourceManager::Create();
150 athena::ActivityFactory::RegisterActivityFactory(activity_factory);
153 void ShutdownAthena() {
154 if (session_started) {
155 athena::ActivityFactory::Shutdown();
156 athena::ResourceManager::Shutdown();
157 athena::ActivityManager::Shutdown();
158 athena::HomeCard::Shutdown();
159 athena::ExtensionsDelegate::Shutdown();
160 session_started = false;
162 athena::AppRegistry::ShutDown();
163 athena::WindowManager::Shutdown();
164 athena::SystemUI::Shutdown();
165 athena::ScreenManager::Shutdown();
166 athena::InputManager::Shutdown();
167 athena::AthenaEnv::Shutdown();
169 ShutdownAthenaViewsDelegate();
172 } // namespace athena