Update broken references to image assets
[chromium-blink-merge.git] / extensions / shell / app / shell_main_delegate.cc
blobfb762e9e66b08048a083fbe7ea2440e31b84a317
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.
5 #include "extensions/shell/app/shell_main_delegate.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.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 "extensions/common/extension_paths.h"
14 #include "extensions/shell/browser/default_shell_browser_main_delegate.h"
15 #include "extensions/shell/browser/shell_content_browser_client.h"
16 #include "extensions/shell/common/shell_content_client.h"
17 #include "extensions/shell/renderer/shell_content_renderer_client.h"
18 #include "extensions/shell/utility/shell_content_utility_client.h"
19 #include "ui/base/resource/resource_bundle.h"
21 #if defined(OS_CHROMEOS)
22 #include "chromeos/chromeos_paths.h"
23 #endif
25 #if defined(OS_MACOSX)
26 #include "base/mac/foundation_util.h"
27 #include "extensions/shell/app/paths_mac.h"
28 #endif
30 #if !defined(DISABLE_NACL)
31 #include "components/nacl/common/nacl_switches.h"
32 #if defined(OS_LINUX)
33 #include "components/nacl/common/nacl_paths.h"
34 #endif // OS_LINUX
35 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
36 #include "components/nacl/zygote/nacl_fork_delegate_linux.h"
37 #endif // OS_POSIX && !OS_MACOSX && !OS_ANDROID
38 #endif // !DISABLE_NACL
40 namespace {
42 void InitLogging() {
43 base::FilePath log_filename;
44 PathService::Get(base::DIR_EXE, &log_filename);
45 log_filename = log_filename.AppendASCII("app_shell.log");
46 logging::LoggingSettings settings;
47 settings.logging_dest = logging::LOG_TO_ALL;
48 settings.log_file = log_filename.value().c_str();
49 settings.delete_old = logging::DELETE_OLD_LOG_FILE;
50 logging::InitLogging(settings);
51 logging::SetLogItems(true, true, true, true);
54 // Returns the path to the extensions_shell_and_test.pak file.
55 base::FilePath GetResourcesPakFilePath() {
56 #if defined(OS_MACOSX)
57 return base::mac::PathForFrameworkBundleResource(
58 CFSTR("extensions_shell_and_test.pak"));
59 #else
60 base::FilePath extensions_shell_and_test_pak_path;
61 PathService::Get(base::DIR_MODULE, &extensions_shell_and_test_pak_path);
62 extensions_shell_and_test_pak_path =
63 extensions_shell_and_test_pak_path.AppendASCII(
64 "extensions_shell_and_test.pak");
65 return extensions_shell_and_test_pak_path;
66 #endif // OS_MACOSX
69 } // namespace
71 namespace extensions {
73 ShellMainDelegate::ShellMainDelegate() {
76 ShellMainDelegate::~ShellMainDelegate() {
79 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
80 InitLogging();
81 content_client_.reset(CreateContentClient());
82 SetContentClient(content_client_.get());
84 #if defined(OS_MACOSX)
85 OverrideChildProcessFilePath();
86 // This must happen before InitializeResourceBundle.
87 OverrideFrameworkBundlePath();
88 #endif
90 #if defined(OS_CHROMEOS)
91 chromeos::RegisterPathProvider();
92 #endif
93 #if !defined(DISABLE_NACL) && defined(OS_LINUX)
94 nacl::RegisterPathProvider();
95 #endif
96 extensions::RegisterPathProvider();
97 return false;
100 void ShellMainDelegate::PreSandboxStartup() {
101 std::string process_type =
102 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
103 switches::kProcessType);
104 if (ProcessNeedsResourceBundle(process_type))
105 InitializeResourceBundle();
108 content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() {
109 browser_client_.reset(CreateShellContentBrowserClient());
110 return browser_client_.get();
113 content::ContentRendererClient*
114 ShellMainDelegate::CreateContentRendererClient() {
115 renderer_client_.reset(CreateShellContentRendererClient());
116 return renderer_client_.get();
119 content::ContentUtilityClient* ShellMainDelegate::CreateContentUtilityClient() {
120 utility_client_.reset(CreateShellContentUtilityClient());
121 return utility_client_.get();
124 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
125 void ShellMainDelegate::ZygoteStarting(
126 ScopedVector<content::ZygoteForkDelegate>* delegates) {
127 #if !defined(DISABLE_NACL)
128 nacl::AddNaClZygoteForkDelegates(delegates);
129 #endif // DISABLE_NACL
131 #endif // OS_POSIX && !OS_MACOSX && !OS_ANDROID
133 content::ContentClient* ShellMainDelegate::CreateContentClient() {
134 return new ShellContentClient();
137 content::ContentBrowserClient*
138 ShellMainDelegate::CreateShellContentBrowserClient() {
139 return new ShellContentBrowserClient(new DefaultShellBrowserMainDelegate());
142 content::ContentRendererClient*
143 ShellMainDelegate::CreateShellContentRendererClient() {
144 return new ShellContentRendererClient();
147 content::ContentUtilityClient*
148 ShellMainDelegate::CreateShellContentUtilityClient() {
149 return new ShellContentUtilityClient();
152 void ShellMainDelegate::InitializeResourceBundle() {
153 ui::ResourceBundle::InitSharedInstanceWithPakPath(
154 GetResourcesPakFilePath());
157 // static
158 bool ShellMainDelegate::ProcessNeedsResourceBundle(
159 const std::string& process_type) {
160 // The browser process has no process type flag, but needs resources.
161 // On Linux the zygote process opens the resources for the renderers.
162 return process_type.empty() ||
163 process_type == switches::kZygoteProcess ||
164 process_type == switches::kRendererProcess ||
165 #if !defined(DISABLE_NACL)
166 process_type == switches::kNaClLoaderProcess ||
167 #endif
168 #if defined(OS_MACOSX)
169 process_type == switches::kGpuProcess ||
170 #endif
171 process_type == switches::kUtilityProcess;
174 } // namespace extensions