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 "apps/shell/app/shell_main_delegate.h" 6 #include "apps/shell/browser/shell_browser_main_delegate.h" 7 #include "apps/shell/browser/shell_desktop_controller.h" 8 #include "apps/shell/browser/shell_extension_system.h" 9 #include "apps/shell/renderer/shell_renderer_main_delegate.h" 10 #include "athena/content/public/content_activity_factory.h" 11 #include "athena/content/public/content_app_model_builder.h" 12 #include "athena/home/public/home_card.h" 13 #include "athena/main/athena_app_window_controller.h" 14 #include "athena/main/athena_launcher.h" 15 #include "athena/main/placeholder.h" 16 #include "athena/main/url_search_provider.h" 17 #include "athena/virtual_keyboard/public/virtual_keyboard_bindings.h" 18 #include "athena/virtual_keyboard/public/virtual_keyboard_manager.h" 19 #include "base/command_line.h" 20 #include "base/file_util.h" 21 #include "content/public/app/content_main.h" 22 #include "ui/aura/window_tree_host.h" 23 #include "ui/wm/core/visibility_controller.h" 24 25 namespace { 26 const char kAppSwitch[] = "app"; 27 28 // We want to load the sample calculator app by default, for a while. Expecting 29 // to run athena_main at src/ 30 const char kDefaultAppPath[] = 31 "chrome/common/extensions/docs/examples/apps/calculator/app"; 32 } // namespace 33 34 class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate { 35 public: AthenaBrowserMainDelegate()36 AthenaBrowserMainDelegate() {} ~AthenaBrowserMainDelegate()37 virtual ~AthenaBrowserMainDelegate() {} 38 39 // apps::ShellBrowserMainDelegate: Start(content::BrowserContext * context)40 virtual void Start(content::BrowserContext* context) OVERRIDE { 41 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 42 base::FilePath app_dir = base::FilePath::FromUTF8Unsafe( 43 command_line->HasSwitch(kAppSwitch) ? 44 command_line->GetSwitchValueNative(kAppSwitch) : 45 kDefaultAppPath); 46 47 base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir); 48 if (base::DirectoryExists(app_absolute_dir)) { 49 extensions::ShellExtensionSystem* extension_system = 50 static_cast<extensions::ShellExtensionSystem*>( 51 extensions::ExtensionSystem::Get(context)); 52 extension_system->LoadApp(app_absolute_dir); 53 } 54 55 athena::StartAthena( 56 apps::ShellDesktopController::instance()->host()->window(), 57 new athena::ContentActivityFactory(), 58 new athena::ContentAppModelBuilder(context)); 59 athena::HomeCard::Get()->RegisterSearchProvider( 60 new athena::UrlSearchProvider(context)); 61 athena::VirtualKeyboardManager::Create(context); 62 63 CreateTestPages(context); 64 } 65 Shutdown()66 virtual void Shutdown() OVERRIDE { athena::ShutdownAthena(); } 67 CreateDesktopController()68 virtual apps::ShellDesktopController* CreateDesktopController() OVERRIDE { 69 // TODO(mukai): create Athena's own ShellDesktopController subclass so that 70 // it can initialize its own window manager logic. 71 apps::ShellDesktopController* desktop = new apps::ShellDesktopController(); 72 desktop->SetAppWindowController(new athena::AthenaAppWindowController()); 73 return desktop; 74 } 75 76 private: 77 DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); 78 }; 79 80 class AthenaRendererMainDelegate : public apps::ShellRendererMainDelegate { 81 public: AthenaRendererMainDelegate()82 AthenaRendererMainDelegate() {} ~AthenaRendererMainDelegate()83 virtual ~AthenaRendererMainDelegate() {} 84 85 private: 86 // apps::ShellRendererMainDelegate: OnThreadStarted(content::RenderThread * thread)87 virtual void OnThreadStarted(content::RenderThread* thread) OVERRIDE {} 88 OnViewCreated(content::RenderView * render_view)89 virtual void OnViewCreated(content::RenderView* render_view) OVERRIDE { 90 athena::VirtualKeyboardBindings::Create(render_view); 91 } 92 93 DISALLOW_COPY_AND_ASSIGN(AthenaRendererMainDelegate); 94 }; 95 96 class AthenaMainDelegate : public apps::ShellMainDelegate { 97 public: AthenaMainDelegate()98 AthenaMainDelegate() {} ~AthenaMainDelegate()99 virtual ~AthenaMainDelegate() {} 100 101 private: 102 // apps::ShellMainDelegate: CreateShellBrowserMainDelegate()103 virtual apps::ShellBrowserMainDelegate* CreateShellBrowserMainDelegate() 104 OVERRIDE { 105 return new AthenaBrowserMainDelegate(); 106 } 107 108 virtual scoped_ptr<apps::ShellRendererMainDelegate> CreateShellRendererMainDelegate()109 CreateShellRendererMainDelegate() OVERRIDE { 110 return scoped_ptr<apps::ShellRendererMainDelegate>( 111 new AthenaRendererMainDelegate()); 112 } 113 114 DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate); 115 }; 116 main(int argc,const char ** argv)117int main(int argc, const char** argv) { 118 AthenaMainDelegate delegate; 119 content::ContentMainParams params(&delegate); 120 121 params.argc = argc; 122 params.argv = argv; 123 124 return content::ContentMain(params); 125 } 126