1 // Copyright (c) 2013 Intel Corporation. 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 "xwalk/runtime/app/xwalk_main_delegate.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "content/public/browser/browser_main_runner.h"
11 #include "content/public/common/content_switches.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/base/ui_base_paths.h"
14 #include "xwalk/extensions/common/xwalk_extension_switches.h"
15 #include "xwalk/extensions/extension_process/xwalk_extension_process_main.h"
16 #include "xwalk/runtime/browser/xwalk_runner.h"
17 #include "xwalk/runtime/browser/ui/taskbar_util.h"
18 #include "xwalk/runtime/common/paths_mac.h"
19 #include "xwalk/runtime/common/xwalk_paths.h"
20 #include "xwalk/runtime/renderer/xwalk_content_renderer_client.h"
22 #if !defined(DISABLE_NACL) && defined(OS_LINUX)
23 #include "components/nacl/common/nacl_paths.h"
24 #include "components/nacl/zygote/nacl_fork_delegate_linux.h"
28 #include "xwalk/runtime/renderer/tizen/xwalk_content_renderer_client_tizen.h"
33 XWalkMainDelegate::XWalkMainDelegate()
34 : content_client_(new XWalkContentClient) {
37 XWalkMainDelegate::~XWalkMainDelegate() {}
39 bool XWalkMainDelegate::BasicStartupComplete(int* exit_code) {
40 logging::LoggingSettings loggingSettings;
41 loggingSettings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
42 logging::InitLogging(loggingSettings);
43 SetContentClient(content_client_.get());
44 #if defined(OS_MACOSX)
45 OverrideFrameworkBundlePath();
46 OverrideChildProcessPath();
48 CommandLine* command_line = CommandLine::ForCurrentProcess();
49 std::string process_type =
50 command_line->GetSwitchValueASCII(switches::kProcessType);
51 // Only set the id for browser process
52 if (process_type.empty())
53 SetTaskbarGroupIdForProcess();
56 #if !defined(DISABLE_NACL) && defined(OS_LINUX)
57 nacl::RegisterPathProvider();
63 void XWalkMainDelegate::PreSandboxStartup() {
64 RegisterPathProvider();
65 InitializeResourceBundle();
68 int XWalkMainDelegate::RunProcess(const std::string& process_type,
69 const content::MainFunctionParams& main_function_params) {
70 if (process_type == switches::kXWalkExtensionProcess)
71 return XWalkExtensionProcessMain(main_function_params);
72 // Tell content to use default process main entries by returning -1.
76 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
77 void XWalkMainDelegate::ZygoteStarting(
78 ScopedVector<content::ZygoteForkDelegate>* delegates) {
79 #if !defined(DISABLE_NACL)
80 nacl::AddNaClZygoteForkDelegates(delegates);
84 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
87 void XWalkMainDelegate::InitializeResourceBundle() {
88 base::FilePath pak_file;
89 #if defined(OS_MACOSX)
90 pak_file = GetResourcesPakFilePath();
92 base::FilePath pak_dir;
93 PathService::Get(base::DIR_MODULE, &pak_dir);
94 DCHECK(!pak_dir.empty());
96 pak_file = pak_dir.Append(FILE_PATH_LITERAL("xwalk.pak"));
98 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
101 content::ContentBrowserClient* XWalkMainDelegate::CreateContentBrowserClient() {
102 // This will only be called from the Browser Process, so it is a convenient
103 // location to initialize the XWalkRunner, which is our main entry point in
105 xwalk_runner_ = XWalkRunner::Create();
106 return xwalk_runner_->GetContentBrowserClient();
109 content::ContentRendererClient*
110 XWalkMainDelegate::CreateContentRendererClient() {
111 #if defined(OS_TIZEN)
112 renderer_client_.reset(new XWalkContentRendererClientTizen());
114 renderer_client_.reset(new XWalkContentRendererClient());
116 return renderer_client_.get();