Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / extensions / shell / app / shell_main_delegate.cc
blob69f0e6181b661fb1d15aec4b6a4fca096d28abe4
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(DISABLE_NACL)
26 #include "components/nacl/common/nacl_switches.h"
27 #if defined(OS_LINUX)
28 #include "components/nacl/common/nacl_paths.h"
29 #endif // OS_LINUX
30 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
31 #include "components/nacl/zygote/nacl_fork_delegate_linux.h"
32 #endif // OS_POSIX && !OS_MACOSX && !OS_ANDROID
33 #endif // !DISABLE_NACL
35 namespace {
37 void InitLogging() {
38 base::FilePath log_filename;
39 PathService::Get(base::DIR_EXE, &log_filename);
40 log_filename = log_filename.AppendASCII("app_shell.log");
41 logging::LoggingSettings settings;
42 settings.logging_dest = logging::LOG_TO_ALL;
43 settings.log_file = log_filename.value().c_str();
44 settings.delete_old = logging::DELETE_OLD_LOG_FILE;
45 logging::InitLogging(settings);
46 logging::SetLogItems(true, true, true, true);
49 } // namespace
51 namespace extensions {
53 ShellMainDelegate::ShellMainDelegate() {
56 ShellMainDelegate::~ShellMainDelegate() {
59 bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
60 InitLogging();
61 content_client_.reset(CreateContentClient());
62 SetContentClient(content_client_.get());
64 #if defined(OS_CHROMEOS)
65 chromeos::RegisterPathProvider();
66 #endif
67 #if !defined(DISABLE_NACL) && defined(OS_LINUX)
68 nacl::RegisterPathProvider();
69 #endif
70 extensions::RegisterPathProvider();
71 return false;
74 void ShellMainDelegate::PreSandboxStartup() {
75 std::string process_type =
76 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
77 switches::kProcessType);
78 if (ProcessNeedsResourceBundle(process_type))
79 InitializeResourceBundle();
82 content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() {
83 browser_client_.reset(CreateShellContentBrowserClient());
84 return browser_client_.get();
87 content::ContentRendererClient*
88 ShellMainDelegate::CreateContentRendererClient() {
89 renderer_client_.reset(CreateShellContentRendererClient());
90 return renderer_client_.get();
93 content::ContentUtilityClient* ShellMainDelegate::CreateContentUtilityClient() {
94 utility_client_.reset(CreateShellContentUtilityClient());
95 return utility_client_.get();
98 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
99 void ShellMainDelegate::ZygoteStarting(
100 ScopedVector<content::ZygoteForkDelegate>* delegates) {
101 #if !defined(DISABLE_NACL)
102 nacl::AddNaClZygoteForkDelegates(delegates);
103 #endif // DISABLE_NACL
105 #endif // OS_POSIX && !OS_MACOSX && !OS_ANDROID
107 content::ContentClient* ShellMainDelegate::CreateContentClient() {
108 return new ShellContentClient();
111 content::ContentBrowserClient*
112 ShellMainDelegate::CreateShellContentBrowserClient() {
113 return new ShellContentBrowserClient(new DefaultShellBrowserMainDelegate());
116 content::ContentRendererClient*
117 ShellMainDelegate::CreateShellContentRendererClient() {
118 return new ShellContentRendererClient();
121 content::ContentUtilityClient*
122 ShellMainDelegate::CreateShellContentUtilityClient() {
123 return new ShellContentUtilityClient();
126 void ShellMainDelegate::InitializeResourceBundle() {
127 base::FilePath extensions_shell_and_test_pak_path;
128 PathService::Get(base::DIR_MODULE, &extensions_shell_and_test_pak_path);
129 ui::ResourceBundle::InitSharedInstanceWithPakPath(
130 extensions_shell_and_test_pak_path.AppendASCII(
131 "extensions_shell_and_test.pak"));
134 // static
135 bool ShellMainDelegate::ProcessNeedsResourceBundle(
136 const std::string& process_type) {
137 // The browser process has no process type flag, but needs resources.
138 // On Linux the zygote process opens the resources for the renderers.
139 return process_type.empty() ||
140 process_type == switches::kZygoteProcess ||
141 process_type == switches::kRendererProcess ||
142 #if !defined(DISABLE_NACL)
143 process_type == switches::kNaClLoaderProcess ||
144 #endif
145 #if defined(OS_MACOSX)
146 process_type == switches::kGpuProcess ||
147 #endif
148 process_type == switches::kUtilityProcess;
151 } // namespace extensions