1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// found in the LICENSE file. 4cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/activity/public/activity_factory.h" 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/activity/public/activity_manager.h" 76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "athena/content/public/web_contents_view_delegate_creator.h" 81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/env/public/athena_env.h" 91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/extensions/public/extensions_delegate.h" 101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/main/athena_content_client.h" 111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/main/athena_renderer_pdf_helper.h" 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/main/public/athena_launcher.h" 13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "athena/screen/public/screen_manager.h" 14f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "base/command_line.h" 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/files/file_util.h" 16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/path_service.h" 171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/pdf/renderer/ppb_pdf_impl.h" 18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/public/app/content_main.h" 1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/public/browser/browser_thread.h" 201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window.h" 211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window_client.h" 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/app/shell_main_delegate.h" 231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/shell/browser/desktop_controller.h" 241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/shell/browser/shell_app_delegate.h" 255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/browser/shell_browser_main_delegate.h" 265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/browser/shell_content_browser_client.h" 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/browser/shell_extension_system.h" 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/shell/browser/shell_native_app_window.h" 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/shell/common/shell_content_client.h" 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/shell/common/switches.h" 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/shell/renderer/shell_content_renderer_client.h" 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ppapi/c/private/ppb_pdf.h" 33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/aura/window_tree_host.h" 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/base/resource/resource_bundle.h" 35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/wm/core/visibility_controller.h" 36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 37f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace { 386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 396d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// We want to load the sample calculator app by default, for a while. Expecting 406d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// to run athena_main at src/ 416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)const char kDefaultAppPath[] = 426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) "chrome/common/extensions/docs/examples/apps/calculator/app"; 43f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} // namespace 45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass AthenaDesktopController : public extensions::DesktopController { 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public: 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AthenaDesktopController() {} 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~AthenaDesktopController() {} 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // extensions::DesktopController: 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual aura::WindowTreeHost* GetHost() OVERRIDE { 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return athena::AthenaEnv::Get()->GetHost(); 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Creates a new app window and adds it to the desktop. The desktop maintains 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // ownership of the window. 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // TODO(jamescook|oshima): Is this function needed? 601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual extensions::AppWindow* CreateAppWindow( 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::BrowserContext* context, 621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const extensions::Extension* extension) OVERRIDE { 631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci NOTIMPLEMENTED(); 641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return NULL; 6503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 6603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Adds the window to the desktop. 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void AddAppWindow(aura::Window* window) OVERRIDE { 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci NOTIMPLEMENTED(); 7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Closes and destroys the app windows. 731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void CloseAppWindows() OVERRIDE {} 7403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController); 7603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}; 7703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate { 79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public: 80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AthenaBrowserMainDelegate() {} 81cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual ~AthenaBrowserMainDelegate() {} 82cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // extensions::ShellBrowserMainDelegate: 84cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void Start(content::BrowserContext* context) OVERRIDE { 85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) base::FilePath app_dir = base::FilePath::FromUTF8Unsafe( 885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) command_line->HasSwitch(extensions::switches::kAppShellAppPath) 895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ? command_line->GetSwitchValueNative( 905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) extensions::switches::kAppShellAppPath) 915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : kDefaultAppPath); 926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 936d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir); 946d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) if (base::DirectoryExists(app_absolute_dir)) { 95f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) extensions::ShellExtensionSystem* extension_system = 96f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) static_cast<extensions::ShellExtensionSystem*>( 97f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) extensions::ExtensionSystem::Get(context)); 98f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) extension_system->LoadApp(app_absolute_dir); 99f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 100f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci athena::StartAthenaEnv(content::BrowserThread::GetBlockingPool()-> 1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci GetTaskRunnerWithShutdownBehavior( 1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci athena::ExtensionsDelegate::CreateExtensionsDelegateForShell(context); 1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci athena::CreateVirtualKeyboardWithContext(context); 10603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) athena::StartAthenaSessionWithContext(context); 107cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 109116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void Shutdown() OVERRIDE { 1101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci athena::AthenaEnv::Get()->OnTerminating(); 111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch athena::ShutdownAthena(); 112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 113cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual extensions::DesktopController* CreateDesktopController() OVERRIDE { 1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return new AthenaDesktopController(); 11646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 11746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private: 119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); 120cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}; 121cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class AthenaContentBrowserClient 1235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : public extensions::ShellContentBrowserClient { 124116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public: 125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AthenaContentBrowserClient() 1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) { 1275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~AthenaContentBrowserClient() {} 129116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // content::ContentBrowserClient: 131116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( 132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch content::WebContents* web_contents) OVERRIDE { 1336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return athena::CreateWebContentsViewDelegate(web_contents); 134116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 135116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 136116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 137116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DISALLOW_COPY_AND_ASSIGN(AthenaContentBrowserClient); 138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 139116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass AthenaContentRendererClient 1411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci : public extensions::ShellContentRendererClient { 1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public: 1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci AthenaContentRendererClient() {} 1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual ~AthenaContentRendererClient() {} 1451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // content::ContentRendererClient: 1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE { 1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci new athena::AthenaRendererPDFHelper(render_frame); 1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci extensions::ShellContentRendererClient::RenderFrameCreated(render_frame); 1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual const void* CreatePPAPIInterface( 1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const std::string& interface_name) OVERRIDE { 1541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (interface_name == PPB_PDF_INTERFACE) 1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return pdf::PPB_PDF_Impl::GetInterface(); 1561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return extensions::ShellContentRendererClient::CreatePPAPIInterface( 1571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci interface_name); 1581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 1591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}; 1601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class AthenaMainDelegate : public extensions::ShellMainDelegate { 162cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public: 163cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AthenaMainDelegate() {} 164cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual ~AthenaMainDelegate() {} 165cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 166cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private: 1675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // extensions::ShellMainDelegate: 1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual content::ContentClient* CreateContentClient() OVERRIDE { 1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return new athena::AthenaContentClient(); 1701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 171116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual content::ContentBrowserClient* CreateShellContentBrowserClient() 172cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) OVERRIDE { 173116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return new AthenaContentBrowserClient(); 174cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 175cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual content::ContentRendererClient* CreateShellContentRendererClient() 1771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci OVERRIDE { 1781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return new AthenaContentRendererClient(); 1791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 1801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 181116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void InitializeResourceBundle() OVERRIDE { 182116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::FilePath pak_dir; 183116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch PathService::Get(base::DIR_MODULE, &pak_dir); 184116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::FilePath pak_file = 185116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch pak_dir.Append(FILE_PATH_LITERAL("athena_resources.pak")); 186116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); 187116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 188116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 189cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate); 190cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}; 191cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 192cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)int main(int argc, const char** argv) { 193cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AthenaMainDelegate delegate; 194cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) content::ContentMainParams params(&delegate); 195cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 196cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) params.argc = argc; 197cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) params.argv = argv; 198cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 199cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return content::ContentMain(params); 200cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 201