Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / main / athena_main.cc
blobf003ba5707687604c9b666047ec802cb20c283b9
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/activity/public/activity_factory.h"
6 #include "athena/activity/public/activity_manager.h"
7 #include "athena/content/public/web_contents_view_delegate_creator.h"
8 #include "athena/env/public/athena_env.h"
9 #include "athena/extensions/public/extensions_delegate.h"
10 #include "athena/main/athena_launcher.h"
11 #include "athena/screen/public/screen_manager.h"
12 #include "base/command_line.h"
13 #include "base/file_util.h"
14 #include "base/path_service.h"
15 #include "content/public/app/content_main.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "extensions/shell/app/shell_main_delegate.h"
18 #include "extensions/shell/browser/desktop_controller.h"
19 #include "extensions/shell/browser/shell_app_window.h"
20 #include "extensions/shell/browser/shell_browser_main_delegate.h"
21 #include "extensions/shell/browser/shell_content_browser_client.h"
22 #include "extensions/shell/browser/shell_extension_system.h"
23 #include "extensions/shell/common/switches.h"
24 #include "ui/aura/window_tree_host.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/wm/core/visibility_controller.h"
28 namespace {
30 // We want to load the sample calculator app by default, for a while. Expecting
31 // to run athena_main at src/
32 const char kDefaultAppPath[] =
33 "chrome/common/extensions/docs/examples/apps/calculator/app";
35 } // namespace athena
37 class AthenaDesktopController : public extensions::DesktopController {
38 public:
39 AthenaDesktopController() {}
40 virtual ~AthenaDesktopController() {}
42 private:
43 // extensions::DesktopController:
44 virtual aura::WindowTreeHost* GetHost() OVERRIDE {
45 return athena::AthenaEnv::Get()->GetHost();
48 // Creates a new app window and adds it to the desktop. The desktop maintains
49 // ownership of the window.
50 virtual extensions::ShellAppWindow* CreateAppWindow(
51 content::BrowserContext* context,
52 const extensions::Extension* extension) OVERRIDE {
53 extensions::ShellAppWindow* app_window = new extensions::ShellAppWindow();
54 app_window->Init(context, extension, gfx::Size(100, 100));
55 athena::ActivityManager::Get()->AddActivity(
56 athena::ActivityFactory::Get()->CreateAppActivity(app_window,
57 extension->id()));
58 return app_window;
61 // Closes and destroys the app windows.
62 virtual void CloseAppWindows() OVERRIDE {}
64 DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController);
67 class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate {
68 public:
69 AthenaBrowserMainDelegate() {}
70 virtual ~AthenaBrowserMainDelegate() {}
72 // extensions::ShellBrowserMainDelegate:
73 virtual void Start(content::BrowserContext* context) OVERRIDE {
74 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
76 base::FilePath app_dir = base::FilePath::FromUTF8Unsafe(
77 command_line->HasSwitch(extensions::switches::kAppShellAppPath)
78 ? command_line->GetSwitchValueNative(
79 extensions::switches::kAppShellAppPath)
80 : kDefaultAppPath);
82 base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir);
83 if (base::DirectoryExists(app_absolute_dir)) {
84 extensions::ShellExtensionSystem* extension_system =
85 static_cast<extensions::ShellExtensionSystem*>(
86 extensions::ExtensionSystem::Get(context));
87 extension_system->LoadApp(app_absolute_dir);
90 athena::StartAthenaEnv(content::BrowserThread::GetMessageLoopProxyForThread(
91 content::BrowserThread::FILE));
92 athena::ExtensionsDelegate::CreateExtensionsDelegateForShell(context);
93 athena::StartAthenaSessionWithContext(context);
96 virtual void Shutdown() OVERRIDE {
97 athena::ShutdownAthena();
100 virtual extensions::DesktopController* CreateDesktopController() OVERRIDE {
101 return new AthenaDesktopController();
104 private:
105 DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate);
108 class AthenaContentBrowserClient
109 : public extensions::ShellContentBrowserClient {
110 public:
111 AthenaContentBrowserClient()
112 : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) {
114 virtual ~AthenaContentBrowserClient() {}
116 // content::ContentBrowserClient:
117 virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate(
118 content::WebContents* web_contents) OVERRIDE {
119 return athena::CreateWebContentsViewDelegate(web_contents);
122 private:
123 DISALLOW_COPY_AND_ASSIGN(AthenaContentBrowserClient);
126 class AthenaMainDelegate : public extensions::ShellMainDelegate {
127 public:
128 AthenaMainDelegate() {}
129 virtual ~AthenaMainDelegate() {}
131 private:
132 // extensions::ShellMainDelegate:
133 virtual content::ContentBrowserClient* CreateShellContentBrowserClient()
134 OVERRIDE {
135 return new AthenaContentBrowserClient();
138 virtual void InitializeResourceBundle() OVERRIDE {
139 base::FilePath pak_dir;
140 PathService::Get(base::DIR_MODULE, &pak_dir);
141 base::FilePath pak_file =
142 pak_dir.Append(FILE_PATH_LITERAL("athena_resources.pak"));
143 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
146 DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate);
149 int main(int argc, const char** argv) {
150 AthenaMainDelegate delegate;
151 content::ContentMainParams params(&delegate);
153 params.argc = argc;
154 params.argv = argv;
156 return content::ContentMain(params);