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/content/public/content_activity_factory.h"
6 #include "athena/content/public/content_app_model_builder.h"
7 #include "athena/content/public/web_contents_view_delegate_creator.h"
8 #include "athena/home/public/home_card.h"
9 #include "athena/main/athena_app_window_controller.h"
10 #include "athena/main/athena_launcher.h"
11 #include "athena/main/debug/debug_window.h"
12 #include "athena/main/placeholder.h"
13 #include "athena/main/url_search_provider.h"
14 #include "athena/screen/public/screen_manager.h"
15 #include "athena/virtual_keyboard/public/virtual_keyboard_manager.h"
16 #include "base/command_line.h"
17 #include "base/file_util.h"
18 #include "base/path_service.h"
19 #include "content/public/app/content_main.h"
20 #include "extensions/shell/app/shell_main_delegate.h"
21 #include "extensions/shell/browser/shell_browser_main_delegate.h"
22 #include "extensions/shell/browser/shell_content_browser_client.h"
23 #include "extensions/shell/browser/shell_desktop_controller.h"
24 #include "extensions/shell/browser/shell_extension_system.h"
25 #include "extensions/shell/common/switches.h"
26 #include "extensions/shell/renderer/shell_renderer_main_delegate.h"
27 #include "ui/app_list/app_list_switches.h"
28 #include "ui/aura/window_tree_host.h"
29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/keyboard/keyboard_controller.h"
31 #include "ui/keyboard/keyboard_controller_observer.h"
32 #include "ui/native_theme/native_theme_switches.h"
33 #include "ui/wm/core/visibility_controller.h"
37 // We want to load the sample calculator app by default, for a while. Expecting
38 // to run athena_main at src/
39 const char kDefaultAppPath[] =
40 "chrome/common/extensions/docs/examples/apps/calculator/app";
43 // This class observes the change of the virtual keyboard and distribute the
44 // change to appropriate modules of athena.
45 // TODO(oshima): move the VK bounds logic to screen manager.
46 class VirtualKeyboardObserver : public keyboard::KeyboardControllerObserver {
48 VirtualKeyboardObserver() {
49 keyboard::KeyboardController::GetInstance()->AddObserver(this);
52 virtual ~VirtualKeyboardObserver() {
53 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
57 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE {
58 athena::HomeCard::Get()->UpdateVirtualKeyboardBounds(new_bounds);
61 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardObserver);
64 class AthenaDesktopController : public extensions::ShellDesktopController {
66 AthenaDesktopController() {}
67 virtual ~AthenaDesktopController() {}
70 // extensions::ShellDesktopController:
71 virtual wm::FocusRules* CreateFocusRules() OVERRIDE {
72 return athena::ScreenManager::CreateFocusRules();
75 DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController);
78 class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate {
80 AthenaBrowserMainDelegate() {}
81 virtual ~AthenaBrowserMainDelegate() {}
83 // extensions::ShellBrowserMainDelegate:
84 virtual void Start(content::BrowserContext* context) OVERRIDE {
85 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
87 // Force showing in the experimental app-list view.
88 command_line->AppendSwitch(app_list::switches::kEnableExperimentalAppList);
89 command_line->AppendSwitch(switches::kEnableOverlayScrollbar);
91 base::FilePath app_dir = base::FilePath::FromUTF8Unsafe(
92 command_line->HasSwitch(extensions::switches::kAppShellAppPath)
93 ? command_line->GetSwitchValueNative(
94 extensions::switches::kAppShellAppPath)
97 base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir);
98 if (base::DirectoryExists(app_absolute_dir)) {
99 extensions::ShellExtensionSystem* extension_system =
100 static_cast<extensions::ShellExtensionSystem*>(
101 extensions::ExtensionSystem::Get(context));
102 extension_system->LoadApp(app_absolute_dir);
106 extensions::ShellDesktopController::instance()->host()->window(),
107 new athena::ContentActivityFactory(),
108 new athena::ContentAppModelBuilder(context));
109 athena::HomeCard::Get()->RegisterSearchProvider(
110 new athena::UrlSearchProvider(context));
111 athena::VirtualKeyboardManager::Create(context);
112 keyboard_observer_.reset(new VirtualKeyboardObserver());
114 CreateTestPages(context);
118 virtual void Shutdown() OVERRIDE {
119 keyboard_observer_.reset();
120 athena::ShutdownAthena();
123 virtual extensions::ShellDesktopController* CreateDesktopController()
125 // TODO(mukai): create Athena's own ShellDesktopController subclass so that
126 // it can initialize its own window manager logic.
127 extensions::ShellDesktopController* desktop = new AthenaDesktopController();
128 desktop->SetAppWindowController(new athena::AthenaAppWindowController());
133 scoped_ptr<VirtualKeyboardObserver> keyboard_observer_;
135 DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate);
138 class AthenaContentBrowserClient
139 : public extensions::ShellContentBrowserClient {
141 AthenaContentBrowserClient()
142 : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) {
144 virtual ~AthenaContentBrowserClient() {}
146 // content::ContentBrowserClient:
147 virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate(
148 content::WebContents* web_contents) OVERRIDE {
149 return athena::CreateWebContentsViewDelegate(web_contents);
153 DISALLOW_COPY_AND_ASSIGN(AthenaContentBrowserClient);
156 class AthenaRendererMainDelegate
157 : public extensions::ShellRendererMainDelegate {
159 AthenaRendererMainDelegate() {}
160 virtual ~AthenaRendererMainDelegate() {}
163 // extensions::ShellRendererMainDelegate:
164 virtual void OnThreadStarted(content::RenderThread* thread) OVERRIDE {}
166 virtual void OnViewCreated(content::RenderView* render_view) OVERRIDE {
169 DISALLOW_COPY_AND_ASSIGN(AthenaRendererMainDelegate);
172 class AthenaMainDelegate : public extensions::ShellMainDelegate {
174 AthenaMainDelegate() {}
175 virtual ~AthenaMainDelegate() {}
178 // extensions::ShellMainDelegate:
179 virtual content::ContentBrowserClient* CreateShellContentBrowserClient()
181 return new AthenaContentBrowserClient();
184 virtual scoped_ptr<extensions::ShellRendererMainDelegate>
185 CreateShellRendererMainDelegate() OVERRIDE {
186 return scoped_ptr<extensions::ShellRendererMainDelegate>(
187 new AthenaRendererMainDelegate());
190 virtual void InitializeResourceBundle() OVERRIDE {
191 base::FilePath pak_dir;
192 PathService::Get(base::DIR_MODULE, &pak_dir);
193 base::FilePath pak_file =
194 pak_dir.Append(FILE_PATH_LITERAL("athena_resources.pak"));
195 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
198 DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate);
201 int main(int argc, const char** argv) {
202 AthenaMainDelegate delegate;
203 content::ContentMainParams params(&delegate);
208 return content::ContentMain(params);