| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/shell/shell_browser_main_parts.h" | 5 #include "apps/shell/shell_browser_main_parts.h" |
| 6 | 6 |
| 7 #include "apps/shell/shell_browser_context.h" | 7 #include "apps/shell/shell_browser_context.h" |
| 8 #include "apps/shell/shell_extension_system.h" | 8 #include "apps/shell/shell_extension_system.h" |
| 9 #include "apps/shell/shell_extensions_browser_client.h" | 9 #include "apps/shell/shell_extensions_browser_client.h" |
| 10 #include "apps/shell/shell_extensions_client.h" | 10 #include "apps/shell/shell_extensions_client.h" |
| 11 #include "apps/shell/web_view_window.h" | 11 #include "apps/shell/web_view_window.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "chrome/browser/extensions/extension_system_factory.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chromeos/chromeos_paths.h" | 18 #include "chromeos/chromeos_paths.h" |
| 19 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 19 #include "content/public/common/result_codes.h" | 20 #include "content/public/common/result_codes.h" |
| 20 #include "extensions/common/extension_paths.h" | 21 #include "extensions/common/extension_paths.h" |
| 21 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
| 22 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
| 23 #include "ui/aura/test/test_screen.h" | 24 #include "ui/aura/test/test_screen.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
| 26 #include "ui/wm/test/wm_test_helper.h" | 27 #include "ui/wm/test/wm_test_helper.h" |
| 27 | 28 |
| 28 using content::BrowserContext; | 29 using content::BrowserContext; |
| 29 using extensions::Extension; | 30 using extensions::Extension; |
| 31 using extensions::ExtensionSystem; |
| 32 using extensions::ShellExtensionSystem; |
| 30 | 33 |
| 31 namespace apps { | 34 namespace apps { |
| 35 namespace { |
| 36 |
| 37 void EnsureBrowserContextKeyedServiceFactoriesBuilt() { |
| 38 // TODO(jamescook): Register additional BrowserContextKeyedService factories |
| 39 // here. See ChromeBrowserMainExtraPartsProfiles for details. |
| 40 } |
| 41 |
| 42 } // namespace |
| 32 | 43 |
| 33 ShellBrowserMainParts::ShellBrowserMainParts( | 44 ShellBrowserMainParts::ShellBrowserMainParts( |
| 34 const content::MainFunctionParams& parameters) | 45 const content::MainFunctionParams& parameters) |
| 35 : extension_system_(NULL) { | 46 : extension_system_(NULL) { |
| 36 } | 47 } |
| 37 | 48 |
| 38 ShellBrowserMainParts::~ShellBrowserMainParts() { | 49 ShellBrowserMainParts::~ShellBrowserMainParts() { |
| 39 } | 50 } |
| 40 | 51 |
| 41 void ShellBrowserMainParts::PreMainMessageLoopStart() { | 52 void ShellBrowserMainParts::PreMainMessageLoopStart() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 70 | 81 |
| 71 // TODO(jamescook): Initialize chromeos::UserManager. | 82 // TODO(jamescook): Initialize chromeos::UserManager. |
| 72 | 83 |
| 73 // Initialize our "profile" equivalent. | 84 // Initialize our "profile" equivalent. |
| 74 browser_context_.reset(new ShellBrowserContext); | 85 browser_context_.reset(new ShellBrowserContext); |
| 75 | 86 |
| 76 extensions_client_.reset(new ShellExtensionsClient()); | 87 extensions_client_.reset(new ShellExtensionsClient()); |
| 77 extensions::ExtensionsClient::Set(extensions_client_.get()); | 88 extensions::ExtensionsClient::Set(extensions_client_.get()); |
| 78 | 89 |
| 79 extensions_browser_client_.reset( | 90 extensions_browser_client_.reset( |
| 80 new ShellExtensionsBrowserClient(browser_context_.get())); | 91 new extensions::ShellExtensionsBrowserClient(browser_context_.get())); |
| 81 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); | 92 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get()); |
| 82 | 93 |
| 83 // TODO(jamescook): Initialize policy::ProfilePolicyConnector. | 94 // Create our custom ExtensionSystem first because other |
| 84 | 95 // BrowserContextKeyedServices depend on it. |
| 85 CreateExtensionSystem(); | 96 CreateExtensionSystem(); |
| 86 | 97 |
| 87 // TODO(jamescook): Create the rest of the services using | 98 EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
| 88 // BrowserContextDependencyManager::CreateBrowserContextServices. | 99 BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( |
| 100 browser_context_.get()); |
| 89 | 101 |
| 90 CreateRootWindow(); | 102 CreateRootWindow(); |
| 91 | 103 |
| 92 const std::string kAppSwitch = "app"; | 104 const std::string kAppSwitch = "app"; |
| 93 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 105 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 94 if (command_line->HasSwitch(kAppSwitch)) { | 106 if (command_line->HasSwitch(kAppSwitch)) { |
| 95 base::FilePath app_dir(command_line->GetSwitchValueNative(kAppSwitch)); | 107 base::FilePath app_dir(command_line->GetSwitchValueNative(kAppSwitch)); |
| 96 extension_system_->LoadAndLaunchApp(app_dir); | 108 extension_system_->LoadAndLaunchApp(app_dir); |
| 97 } else { | 109 } else { |
| 98 // TODO(jamescook): For demo purposes create a window with a WebView just | 110 // TODO(jamescook): For demo purposes create a window with a WebView just |
| 99 // to ensure that the content module is properly initialized. | 111 // to ensure that the content module is properly initialized. |
| 100 ShowWebViewWindow(browser_context_.get(), | 112 ShowWebViewWindow(browser_context_.get(), |
| 101 wm_test_helper_->root_window()->window()); | 113 wm_test_helper_->root_window()->window()); |
| 102 } | 114 } |
| 103 } | 115 } |
| 104 | 116 |
| 105 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { | 117 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 106 base::RunLoop run_loop; | 118 base::RunLoop run_loop; |
| 107 run_loop.Run(); | 119 run_loop.Run(); |
| 108 *result_code = content::RESULT_CODE_NORMAL_EXIT; | 120 *result_code = content::RESULT_CODE_NORMAL_EXIT; |
| 109 return true; | 121 return true; |
| 110 } | 122 } |
| 111 | 123 |
| 112 void ShellBrowserMainParts::PostMainMessageLoopRun() { | 124 void ShellBrowserMainParts::PostMainMessageLoopRun() { |
| 113 DestroyRootWindow(); | 125 DestroyRootWindow(); |
| 114 // TODO(jamescook): Destroy the rest of the services with | 126 BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices( |
| 115 // BrowserContextDependencyManager::DestroyBrowserContextServices. | 127 browser_context_.get()); |
| 128 extension_system_ = NULL; |
| 116 extensions::ExtensionsBrowserClient::Set(NULL); | 129 extensions::ExtensionsBrowserClient::Set(NULL); |
| 117 extensions_browser_client_.reset(); | 130 extensions_browser_client_.reset(); |
| 118 browser_context_.reset(); | 131 browser_context_.reset(); |
| 119 aura::Env::DeleteInstance(); | 132 aura::Env::DeleteInstance(); |
| 120 | |
| 121 LOG(WARNING) << "-----------------------------------"; | |
| 122 LOG(WARNING) << "app_shell is expected to crash now."; | |
| 123 LOG(WARNING) << "-----------------------------------"; | |
| 124 } | 133 } |
| 125 | 134 |
| 126 void ShellBrowserMainParts::OnRootWindowHostCloseRequested( | 135 void ShellBrowserMainParts::OnRootWindowHostCloseRequested( |
| 127 const aura::RootWindow* root) { | 136 const aura::RootWindow* root) { |
| 128 base::MessageLoop::current()->PostTask(FROM_HERE, | 137 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 129 base::MessageLoop::QuitClosure()); | 138 base::MessageLoop::QuitClosure()); |
| 130 } | 139 } |
| 131 | 140 |
| 132 void ShellBrowserMainParts::CreateRootWindow() { | 141 void ShellBrowserMainParts::CreateRootWindow() { |
| 133 test_screen_.reset(aura::TestScreen::Create()); | 142 test_screen_.reset(aura::TestScreen::Create()); |
| 134 // TODO(jamescook): Replace this with a real Screen implementation. | 143 // TODO(jamescook): Replace this with a real Screen implementation. |
| 135 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); | 144 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); |
| 136 // Set up basic pieces of views::corewm. | 145 // Set up basic pieces of views::corewm. |
| 137 wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600))); | 146 wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600))); |
| 138 // Ensure the X window gets mapped. | 147 // Ensure the X window gets mapped. |
| 139 wm_test_helper_->root_window()->host()->Show(); | 148 wm_test_helper_->root_window()->host()->Show(); |
| 140 // Watch for the user clicking the close box. | 149 // Watch for the user clicking the close box. |
| 141 wm_test_helper_->root_window()->AddRootWindowObserver(this); | 150 wm_test_helper_->root_window()->AddRootWindowObserver(this); |
| 142 } | 151 } |
| 143 | 152 |
| 144 void ShellBrowserMainParts::DestroyRootWindow() { | 153 void ShellBrowserMainParts::DestroyRootWindow() { |
| 145 wm_test_helper_->root_window()->RemoveRootWindowObserver(this); | 154 wm_test_helper_->root_window()->RemoveRootWindowObserver(this); |
| 146 wm_test_helper_->root_window()->PrepareForShutdown(); | 155 wm_test_helper_->root_window()->PrepareForShutdown(); |
| 147 wm_test_helper_.reset(); | 156 wm_test_helper_.reset(); |
| 148 } | 157 } |
| 149 | 158 |
| 150 void ShellBrowserMainParts::CreateExtensionSystem() { | 159 void ShellBrowserMainParts::CreateExtensionSystem() { |
| 151 DCHECK(browser_context_); | 160 DCHECK(browser_context_); |
| 152 extension_system_ = | 161 extension_system_ = static_cast<ShellExtensionSystem*>( |
| 153 new extensions::ShellExtensionSystem(browser_context_.get()); | 162 ExtensionSystem::GetForBrowserContext(browser_context_.get())); |
| 154 extensions::ExtensionSystemFactory::GetInstance()->SetCustomInstance( | |
| 155 extension_system_); | |
| 156 // Must occur after setting the instance above, as it will end up calling | |
| 157 // ExtensionSystem::Get(). | |
| 158 extension_system_->InitForRegularProfile(true); | 163 extension_system_->InitForRegularProfile(true); |
| 159 } | 164 } |
| 160 | 165 |
| 161 } // namespace apps | 166 } // namespace apps |
| OLD | NEW |