OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/shell/shell_main_delegate.h" | 5 #include "content/shell/shell_main_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
12 #include "content/shell/shell_browser_main.h" | 12 #include "content/shell/shell_browser_main.h" |
13 #include "content/shell/shell_content_browser_client.h" | 13 #include "content/shell/shell_content_browser_client.h" |
14 #include "content/shell/shell_content_plugin_client.h" | |
15 #include "content/shell/shell_content_renderer_client.h" | 14 #include "content/shell/shell_content_renderer_client.h" |
16 #include "content/shell/shell_content_utility_client.h" | |
17 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/base/ui_base_paths.h" | 16 #include "ui/base/ui_base_paths.h" |
19 | 17 |
20 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
21 #include "content/shell/paths_mac.h" | 19 #include "content/shell/paths_mac.h" |
22 #endif // OS_MACOSX | 20 #endif // OS_MACOSX |
23 | 21 |
24 ShellMainDelegate::ShellMainDelegate() { | 22 ShellMainDelegate::ShellMainDelegate() { |
25 } | 23 } |
26 | 24 |
27 ShellMainDelegate::~ShellMainDelegate() { | 25 ShellMainDelegate::~ShellMainDelegate() { |
28 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
29 NOTREACHED(); | 27 NOTREACHED(); |
30 #endif | 28 #endif |
31 } | 29 } |
32 | 30 |
33 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { | 31 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { |
34 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
35 OverrideFrameworkBundlePath(); | 33 OverrideFrameworkBundlePath(); |
36 #endif | 34 #endif |
37 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
38 std::string process_type = | |
39 command_line.GetSwitchValueASCII(switches::kProcessType); | |
40 content::SetContentClient(&content_client_); | 35 content::SetContentClient(&content_client_); |
41 InitializeShellContentClient(process_type); | |
42 | |
43 return false; | 36 return false; |
44 } | 37 } |
45 | 38 |
46 void ShellMainDelegate::PreSandboxStartup() { | 39 void ShellMainDelegate::PreSandboxStartup() { |
47 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
48 OverrideChildProcessPath(); | 41 OverrideChildProcessPath(); |
49 #endif // OS_MACOSX | 42 #endif // OS_MACOSX |
50 InitializeResourceBundle(); | 43 InitializeResourceBundle(); |
51 } | 44 } |
52 | 45 |
53 int ShellMainDelegate::RunProcess( | 46 int ShellMainDelegate::RunProcess( |
54 const std::string& process_type, | 47 const std::string& process_type, |
55 const content::MainFunctionParams& main_function_params) { | 48 const content::MainFunctionParams& main_function_params) { |
56 if (process_type != "") | 49 if (process_type != "") |
57 return -1; | 50 return -1; |
58 | 51 |
59 return ShellBrowserMain(main_function_params); | 52 return ShellBrowserMain(main_function_params); |
60 } | 53 } |
61 | 54 |
62 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | |
63 void ShellMainDelegate::ZygoteForked() { | |
64 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
65 std::string process_type = | |
66 command_line.GetSwitchValueASCII(switches::kProcessType); | |
67 InitializeShellContentClient(process_type); | |
68 } | |
69 #endif | |
70 | |
71 void ShellMainDelegate::InitializeShellContentClient( | |
72 const std::string& process_type) { | |
73 if (process_type.empty()) { | |
74 browser_client_.reset(new content::ShellContentBrowserClient); | |
75 content::GetContentClient()->set_browser(browser_client_.get()); | |
76 } | |
77 | |
78 if (process_type == switches::kRendererProcess || | |
79 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { | |
80 renderer_client_.reset(new content::ShellContentRendererClient); | |
81 content::GetContentClient()->set_renderer(renderer_client_.get()); | |
82 } else if (process_type == switches::kPluginProcess) { | |
83 plugin_client_.reset(new content::ShellContentPluginClient); | |
84 content::GetContentClient()->set_plugin(plugin_client_.get()); | |
85 } else if (process_type == switches::kUtilityProcess) { | |
86 utility_client_.reset(new content::ShellContentUtilityClient); | |
87 content::GetContentClient()->set_utility(utility_client_.get()); | |
88 } | |
89 } | |
90 | |
91 void ShellMainDelegate::InitializeResourceBundle() { | 55 void ShellMainDelegate::InitializeResourceBundle() { |
92 FilePath pak_file; | 56 FilePath pak_file; |
93 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
94 pak_file = GetResourcesPakFilePath(); | 58 pak_file = GetResourcesPakFilePath(); |
95 #else | 59 #else |
96 FilePath pak_dir; | 60 FilePath pak_dir; |
97 | 61 |
98 #if defined(OS_ANDROID) | 62 #if defined(OS_ANDROID) |
99 DCHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir)); | 63 DCHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir)); |
100 pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); | 64 pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); |
101 #else | 65 #else |
102 PathService::Get(base::DIR_MODULE, &pak_dir); | 66 PathService::Get(base::DIR_MODULE, &pak_dir); |
103 #endif | 67 #endif |
104 | 68 |
105 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); | 69 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); |
106 #endif | 70 #endif |
107 ui::ResourceBundle::InitSharedInstanceWithPakFile(pak_file); | 71 ui::ResourceBundle::InitSharedInstanceWithPakFile(pak_file); |
108 } | 72 } |
73 | |
74 content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { | |
75 browser_client_.reset(new content::ShellContentBrowserClient); | |
76 return browser_client_.get(); | |
77 } | |
78 | |
79 content::ContentRendererClient* | |
80 ShellMainDelegate::CreateContentRendererClient() { | |
81 renderer_client_.reset(new content::ShellContentRendererClient); | |
82 return renderer_client_.get(); | |
83 | |
Jói
2012/06/05 11:26:54
nit: weird blank line
| |
84 } | |
OLD | NEW |