OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "ash/shell/content_client/shell_main_delegate.h" |
| 6 |
| 7 #include "ash/shell/content_client/shell_content_browser_client.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" |
| 10 #include "base/path_service.h" |
| 11 #include "content/public/browser/browser_main_runner.h" |
| 12 #include "content/public/common/content_switches.h" |
| 13 #include "content/shell/shell_content_plugin_client.h" |
| 14 #include "content/shell/shell_content_renderer_client.h" |
| 15 #include "content/shell/shell_content_utility_client.h" |
| 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/base/ui_base_paths.h" |
| 18 |
| 19 namespace ash { |
| 20 namespace shell { |
| 21 namespace { |
| 22 |
| 23 int ShellBrowserMain( |
| 24 const content::MainFunctionParams& main_function_params) { |
| 25 scoped_ptr<content::BrowserMainRunner> main_runner( |
| 26 content::BrowserMainRunner::Create()); |
| 27 int exit_code = main_runner->Initialize(main_function_params); |
| 28 if (exit_code >= 0) |
| 29 return exit_code; |
| 30 exit_code = main_runner->Run(); |
| 31 main_runner->Shutdown(); |
| 32 return exit_code; |
| 33 } |
| 34 |
| 35 } |
| 36 |
| 37 ShellMainDelegate::ShellMainDelegate() { |
| 38 } |
| 39 |
| 40 ShellMainDelegate::~ShellMainDelegate() { |
| 41 } |
| 42 |
| 43 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { |
| 44 return false; |
| 45 } |
| 46 |
| 47 void ShellMainDelegate::PreSandboxStartup() { |
| 48 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 49 std::string process_type = |
| 50 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 51 |
| 52 content::SetContentClient(&content_client_); |
| 53 InitializeShellContentClient(process_type); |
| 54 |
| 55 InitializeResourceBundle(); |
| 56 } |
| 57 |
| 58 void ShellMainDelegate::SandboxInitialized(const std::string& process_type) { |
| 59 } |
| 60 |
| 61 int ShellMainDelegate::RunProcess( |
| 62 const std::string& process_type, |
| 63 const content::MainFunctionParams& main_function_params) { |
| 64 if (process_type != "") |
| 65 return -1; |
| 66 |
| 67 return ShellBrowserMain(main_function_params); |
| 68 } |
| 69 |
| 70 void ShellMainDelegate::ProcessExiting(const std::string& process_type) { |
| 71 } |
| 72 |
| 73 #if defined(OS_POSIX) |
| 74 content::ZygoteForkDelegate* ShellMainDelegate::ZygoteStarting() { |
| 75 return NULL; |
| 76 } |
| 77 |
| 78 void ShellMainDelegate::ZygoteForked() { |
| 79 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 80 std::string process_type = |
| 81 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 82 InitializeShellContentClient(process_type); |
| 83 } |
| 84 #endif |
| 85 |
| 86 void ShellMainDelegate::InitializeShellContentClient( |
| 87 const std::string& process_type) { |
| 88 if (process_type.empty()) { |
| 89 browser_client_.reset(new ShellContentBrowserClient); |
| 90 content::GetContentClient()->set_browser(browser_client_.get()); |
| 91 } else if (process_type == switches::kRendererProcess) { |
| 92 renderer_client_.reset(new content::ShellContentRendererClient); |
| 93 content::GetContentClient()->set_renderer(renderer_client_.get()); |
| 94 } else if (process_type == switches::kPluginProcess) { |
| 95 plugin_client_.reset(new content::ShellContentPluginClient); |
| 96 content::GetContentClient()->set_plugin(plugin_client_.get()); |
| 97 } else if (process_type == switches::kUtilityProcess) { |
| 98 utility_client_.reset(new content::ShellContentUtilityClient); |
| 99 content::GetContentClient()->set_utility(utility_client_.get()); |
| 100 } |
| 101 } |
| 102 |
| 103 void ShellMainDelegate::InitializeResourceBundle() { |
| 104 ui::ResourceBundle::InitSharedInstanceWithLocale("en-US"); |
| 105 } |
| 106 |
| 107 } // namespace shell |
| 108 } // namespace ash |
OLD | NEW |