OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "athena/activity/public/activity_factory.h" |
| 6 #include "athena/activity/public/activity_manager.h" |
5 #include "athena/content/public/web_contents_view_delegate_creator.h" | 7 #include "athena/content/public/web_contents_view_delegate_creator.h" |
6 #include "athena/main/athena_app_window_controller.h" | 8 #include "athena/env/public/athena_env.h" |
7 #include "athena/main/athena_launcher.h" | 9 #include "athena/main/athena_launcher.h" |
8 #include "athena/screen/public/screen_manager.h" | 10 #include "athena/screen/public/screen_manager.h" |
9 #include "athena/screen/public/screen_manager_delegate.h" | |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "content/public/app/content_main.h" | 14 #include "content/public/app/content_main.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "extensions/shell/app/shell_main_delegate.h" | 16 #include "extensions/shell/app/shell_main_delegate.h" |
| 17 #include "extensions/shell/browser/desktop_controller.h" |
| 18 #include "extensions/shell/browser/shell_app_window.h" |
16 #include "extensions/shell/browser/shell_browser_main_delegate.h" | 19 #include "extensions/shell/browser/shell_browser_main_delegate.h" |
17 #include "extensions/shell/browser/shell_content_browser_client.h" | 20 #include "extensions/shell/browser/shell_content_browser_client.h" |
18 #include "extensions/shell/browser/shell_desktop_controller.h" | |
19 #include "extensions/shell/browser/shell_extension_system.h" | 21 #include "extensions/shell/browser/shell_extension_system.h" |
20 #include "extensions/shell/common/switches.h" | 22 #include "extensions/shell/common/switches.h" |
21 #include "ui/aura/window_tree_host.h" | 23 #include "ui/aura/window_tree_host.h" |
22 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/wm/core/visibility_controller.h" | 25 #include "ui/wm/core/visibility_controller.h" |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 // We want to load the sample calculator app by default, for a while. Expecting | 29 // We want to load the sample calculator app by default, for a while. Expecting |
28 // to run athena_main at src/ | 30 // to run athena_main at src/ |
29 const char kDefaultAppPath[] = | 31 const char kDefaultAppPath[] = |
30 "chrome/common/extensions/docs/examples/apps/calculator/app"; | 32 "chrome/common/extensions/docs/examples/apps/calculator/app"; |
31 | 33 |
32 } // namespace athena | 34 } // namespace athena |
33 | 35 |
34 class AthenaDesktopController : public extensions::ShellDesktopController { | 36 class AthenaDesktopController : public extensions::DesktopController { |
35 public: | 37 public: |
36 AthenaDesktopController() {} | 38 AthenaDesktopController() {} |
37 virtual ~AthenaDesktopController() {} | 39 virtual ~AthenaDesktopController() {} |
38 | 40 |
39 private: | 41 private: |
40 // extensions::ShellDesktopController: | 42 // extensions::DesktopController: |
41 virtual wm::FocusRules* CreateFocusRules() OVERRIDE { | 43 virtual aura::WindowTreeHost* GetHost() OVERRIDE { |
42 return athena::ScreenManager::CreateFocusRules(); | 44 return athena::AthenaEnv::Get()->GetHost(); |
43 } | 45 } |
44 | 46 |
| 47 // Creates a new app window and adds it to the desktop. The desktop maintains |
| 48 // ownership of the window. |
| 49 virtual extensions::ShellAppWindow* CreateAppWindow( |
| 50 content::BrowserContext* context, |
| 51 const extensions::Extension* extension) OVERRIDE { |
| 52 extensions::ShellAppWindow* app_window = new extensions::ShellAppWindow(); |
| 53 app_window->Init(context, extension, gfx::Size(100, 100)); |
| 54 athena::ActivityManager::Get()->AddActivity( |
| 55 athena::ActivityFactory::Get()->CreateAppActivity(app_window)); |
| 56 return app_window; |
| 57 } |
| 58 |
| 59 // Closes and destroys the app windows. |
| 60 virtual void CloseAppWindows() OVERRIDE {} |
| 61 |
45 DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController); | 62 DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController); |
46 }; | 63 }; |
47 | 64 |
48 class AthenaScreenManagerDelegate : public athena::ScreenManagerDelegate { | |
49 public: | |
50 explicit AthenaScreenManagerDelegate( | |
51 extensions::ShellDesktopController* controller) | |
52 : controller_(controller) { | |
53 } | |
54 | |
55 virtual ~AthenaScreenManagerDelegate() { | |
56 } | |
57 | |
58 private: | |
59 // athena::ScreenManagerDelegate: | |
60 virtual void SetWorkAreaInsets(const gfx::Insets& insets) OVERRIDE { | |
61 controller_->SetDisplayWorkAreaInsets(insets); | |
62 } | |
63 | |
64 // Not owned. | |
65 extensions::ShellDesktopController* controller_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(AthenaScreenManagerDelegate); | |
68 }; | |
69 | |
70 class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate { | 65 class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate { |
71 public: | 66 public: |
72 AthenaBrowserMainDelegate() {} | 67 AthenaBrowserMainDelegate() {} |
73 virtual ~AthenaBrowserMainDelegate() {} | 68 virtual ~AthenaBrowserMainDelegate() {} |
74 | 69 |
75 // extensions::ShellBrowserMainDelegate: | 70 // extensions::ShellBrowserMainDelegate: |
76 virtual void Start(content::BrowserContext* context) OVERRIDE { | 71 virtual void Start(content::BrowserContext* context) OVERRIDE { |
77 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 72 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
78 | 73 |
79 base::FilePath app_dir = base::FilePath::FromUTF8Unsafe( | 74 base::FilePath app_dir = base::FilePath::FromUTF8Unsafe( |
80 command_line->HasSwitch(extensions::switches::kAppShellAppPath) | 75 command_line->HasSwitch(extensions::switches::kAppShellAppPath) |
81 ? command_line->GetSwitchValueNative( | 76 ? command_line->GetSwitchValueNative( |
82 extensions::switches::kAppShellAppPath) | 77 extensions::switches::kAppShellAppPath) |
83 : kDefaultAppPath); | 78 : kDefaultAppPath); |
84 | 79 |
85 base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir); | 80 base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir); |
86 if (base::DirectoryExists(app_absolute_dir)) { | 81 if (base::DirectoryExists(app_absolute_dir)) { |
87 extensions::ShellExtensionSystem* extension_system = | 82 extensions::ShellExtensionSystem* extension_system = |
88 static_cast<extensions::ShellExtensionSystem*>( | 83 static_cast<extensions::ShellExtensionSystem*>( |
89 extensions::ExtensionSystem::Get(context)); | 84 extensions::ExtensionSystem::Get(context)); |
90 extension_system->LoadApp(app_absolute_dir); | 85 extension_system->LoadApp(app_absolute_dir); |
91 } | 86 } |
92 | 87 |
93 extensions::ShellDesktopController* desktop_controller = | 88 athena::StartAthenaEnv(content::BrowserThread::GetMessageLoopProxyForThread( |
94 extensions::ShellDesktopController::instance(); | 89 content::BrowserThread::FILE)); |
95 screen_manager_delegate_.reset( | |
96 new AthenaScreenManagerDelegate(desktop_controller)); | |
97 athena::StartAthenaEnv(desktop_controller->host()->window(), | |
98 screen_manager_delegate_.get(), | |
99 content::BrowserThread::GetMessageLoopProxyForThread( | |
100 content::BrowserThread::FILE)); | |
101 athena::StartAthenaSessionWithContext(context); | 90 athena::StartAthenaSessionWithContext(context); |
102 } | 91 } |
103 | 92 |
104 virtual void Shutdown() OVERRIDE { | 93 virtual void Shutdown() OVERRIDE { |
105 athena::ShutdownAthena(); | 94 athena::ShutdownAthena(); |
106 } | 95 } |
107 | 96 |
108 virtual extensions::ShellDesktopController* CreateDesktopController() | 97 virtual extensions::DesktopController* CreateDesktopController() OVERRIDE { |
109 OVERRIDE { | 98 return new AthenaDesktopController(); |
110 // TODO(mukai): create Athena's own ShellDesktopController subclass so that | |
111 // it can initialize its own window manager logic. | |
112 extensions::ShellDesktopController* desktop = new AthenaDesktopController(); | |
113 desktop->SetAppWindowController(new athena::AthenaAppWindowController()); | |
114 return desktop; | |
115 } | 99 } |
116 | 100 |
117 private: | 101 private: |
118 scoped_ptr<AthenaScreenManagerDelegate> screen_manager_delegate_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); | 102 DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); |
121 }; | 103 }; |
122 | 104 |
123 class AthenaContentBrowserClient | 105 class AthenaContentBrowserClient |
124 : public extensions::ShellContentBrowserClient { | 106 : public extensions::ShellContentBrowserClient { |
125 public: | 107 public: |
126 AthenaContentBrowserClient() | 108 AthenaContentBrowserClient() |
127 : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) { | 109 : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) { |
128 } | 110 } |
129 virtual ~AthenaContentBrowserClient() {} | 111 virtual ~AthenaContentBrowserClient() {} |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 145 |
164 int main(int argc, const char** argv) { | 146 int main(int argc, const char** argv) { |
165 AthenaMainDelegate delegate; | 147 AthenaMainDelegate delegate; |
166 content::ContentMainParams params(&delegate); | 148 content::ContentMainParams params(&delegate); |
167 | 149 |
168 params.argc = argc; | 150 params.argc = argc; |
169 params.argv = argv; | 151 params.argv = argv; |
170 | 152 |
171 return content::ContentMain(params); | 153 return content::ContentMain(params); |
172 } | 154 } |
OLD | NEW |