OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "athena/main/athena_main_delegate.h" | |
6 | |
7 #include "athena/content/public/web_contents_view_delegate_creator.h" | |
8 #include "athena/env/public/athena_env.h" | |
9 #include "athena/main/athena_content_client.h" | |
10 #include "athena/main/athena_renderer_pdf_helper.h" | |
11 #include "athena/main/public/athena_launcher.h" | |
12 #include "base/command_line.h" | |
13 #include "base/files/file_util.h" | |
14 #include "base/path_service.h" | |
15 #include "components/pdf/renderer/ppb_pdf_impl.h" | |
16 #include "content/public/app/content_main.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "extensions/common/switches.h" | |
19 #include "extensions/shell/browser/desktop_controller.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/shell_content_client.h" | |
24 #include "extensions/shell/common/switches.h" | |
25 #include "extensions/shell/renderer/shell_content_renderer_client.h" | |
26 #include "ppapi/c/private/ppb_pdf.h" | |
27 #include "ui/aura/window.h" | |
28 #include "ui/aura/window_tree_host.h" | |
29 #include "ui/base/resource/resource_bundle.h" | |
30 #include "ui/gfx/geometry/size.h" | |
31 | |
32 namespace athena { | |
33 namespace { | |
34 | |
35 // We want to load the sample calculator app by default, for a while. Expecting | |
36 // to run athena_main at src/ | |
37 const char kDefaultAppPath[] = | |
38 "chrome/common/extensions/docs/examples/apps/calculator/app"; | |
39 | |
40 class AthenaDesktopController : public extensions::DesktopController { | |
41 public: | |
42 AthenaDesktopController() {} | |
43 ~AthenaDesktopController() override {} | |
44 | |
45 private: | |
46 // extensions::DesktopController: | |
47 virtual gfx::Size GetWindowSize() override { | |
48 return athena::AthenaEnv::Get()->GetHost()->window()->bounds().size(); | |
49 } | |
50 | |
51 // Creates a new app window and adds it to the desktop. The desktop maintains | |
52 // ownership of the window. | |
53 // TODO(jamescook|oshima): Is this function needed? | |
54 virtual extensions::AppWindow* CreateAppWindow( | |
55 content::BrowserContext* context, | |
56 const extensions::Extension* extension) override { | |
57 NOTIMPLEMENTED(); | |
58 return nullptr; | |
59 } | |
60 | |
61 // Adds the window to the desktop. | |
62 virtual void AddAppWindow(aura::Window* window) override { NOTIMPLEMENTED(); } | |
63 | |
64 virtual void RemoveAppWindow(extensions::AppWindow* window) override {} | |
65 | |
66 // Closes and destroys the app windows. | |
67 virtual void CloseAppWindows() override {} | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController); | |
70 }; | |
71 | |
72 class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate { | |
73 public: | |
74 AthenaBrowserMainDelegate() {} | |
75 ~AthenaBrowserMainDelegate() override {} | |
76 | |
77 // extensions::ShellBrowserMainDelegate: | |
78 virtual void Start(content::BrowserContext* context) override { | |
79 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
80 | |
81 base::FilePath app_dir = base::FilePath::FromUTF8Unsafe( | |
82 command_line->HasSwitch(extensions::switches::kLoadApps) | |
83 ? command_line->GetSwitchValueNative( | |
84 extensions::switches::kLoadApps) | |
85 : kDefaultAppPath); | |
86 | |
87 base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir); | |
88 if (base::DirectoryExists(app_absolute_dir)) { | |
89 extensions::ShellExtensionSystem* extension_system = | |
90 static_cast<extensions::ShellExtensionSystem*>( | |
91 extensions::ExtensionSystem::Get(context)); | |
92 extension_system->LoadApp(app_absolute_dir); | |
93 } | |
94 | |
95 athena::StartAthenaEnv( | |
96 content::BrowserThread::GetBlockingPool() | |
97 ->GetTaskRunnerWithShutdownBehavior( | |
98 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
99 athena::CreateVirtualKeyboardWithContext(context); | |
100 athena::StartAthenaSessionWithContext(context); | |
101 } | |
102 | |
103 virtual void Shutdown() override { | |
104 athena::AthenaEnv::Get()->OnTerminating(); | |
105 athena::ShutdownAthena(); | |
106 } | |
107 | |
108 virtual extensions::DesktopController* CreateDesktopController() override { | |
109 return new AthenaDesktopController(); | |
110 } | |
111 | |
112 private: | |
113 DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); | |
114 }; | |
115 | |
116 class AthenaContentBrowserClient | |
117 : public extensions::ShellContentBrowserClient { | |
118 public: | |
119 AthenaContentBrowserClient() | |
120 : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) { | |
121 } | |
122 ~AthenaContentBrowserClient() override {} | |
123 | |
124 // content::ContentBrowserClient: | |
125 virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( | |
126 content::WebContents* web_contents) override { | |
127 return athena::CreateWebContentsViewDelegate(web_contents); | |
128 } | |
129 | |
130 private: | |
131 DISALLOW_COPY_AND_ASSIGN(AthenaContentBrowserClient); | |
132 }; | |
133 | |
134 class AthenaContentRendererClient | |
135 : public extensions::ShellContentRendererClient { | |
136 public: | |
137 AthenaContentRendererClient() {} | |
138 ~AthenaContentRendererClient() override {} | |
139 | |
140 // content::ContentRendererClient: | |
141 virtual void RenderFrameCreated(content::RenderFrame* render_frame) override { | |
142 new athena::AthenaRendererPDFHelper(render_frame); | |
143 extensions::ShellContentRendererClient::RenderFrameCreated(render_frame); | |
144 } | |
145 | |
146 virtual const void* CreatePPAPIInterface( | |
147 const std::string& interface_name) override { | |
148 if (interface_name == PPB_PDF_INTERFACE) | |
149 return pdf::PPB_PDF_Impl::GetInterface(); | |
150 return extensions::ShellContentRendererClient::CreatePPAPIInterface( | |
151 interface_name); | |
152 } | |
153 }; | |
154 | |
155 } // namespace | |
156 | |
157 content::ContentClient* AthenaMainDelegate::CreateContentClient() { | |
158 return new athena::AthenaContentClient(); | |
159 } | |
160 | |
161 content::ContentBrowserClient* | |
162 AthenaMainDelegate::CreateShellContentBrowserClient() { | |
163 return new AthenaContentBrowserClient(); | |
164 } | |
165 | |
166 content::ContentRendererClient* | |
167 AthenaMainDelegate::CreateShellContentRendererClient() { | |
168 return new AthenaContentRendererClient(); | |
169 } | |
170 | |
171 void AthenaMainDelegate::InitializeResourceBundle() { | |
172 base::FilePath pak_dir; | |
173 PathService::Get(base::DIR_MODULE, &pak_dir); | |
174 base::FilePath pak_file = | |
175 pak_dir.Append(FILE_PATH_LITERAL("athena_resources.pak")); | |
176 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | |
177 } | |
178 | |
179 } // namespace athena | |
OLD | NEW |