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"
23 #include "xwalk/runtime/renderer/tizen/xwalk_content_renderer_client_tizen.h"
28 XWalkMainDelegate::XWalkMainDelegate()
29 : content_client_(new XWalkContentClient) {
32 XWalkMainDelegate::~XWalkMainDelegate() {}
34 bool XWalkMainDelegate::BasicStartupComplete(int* exit_code) {
35 logging::LoggingSettings loggingSettings;
36 loggingSettings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
37 logging::InitLogging(loggingSettings);
38 SetContentClient(content_client_.get());
40 CommandLine* command_line = CommandLine::ForCurrentProcess();
41 std::string process_type =
42 command_line->GetSwitchValueASCII(switches::kProcessType);
43 // Only set the id for browser process
44 if (process_type.empty())
45 SetTaskbarGroupIdForProcess();
50 void XWalkMainDelegate::PreSandboxStartup() {
51 #if defined(OS_MACOSX)
52 OverrideFrameworkBundlePath();
53 OverrideChildProcessPath();
56 RegisterPathProvider();
57 InitializeResourceBundle();
60 int XWalkMainDelegate::RunProcess(const std::string& process_type,
61 const content::MainFunctionParams& main_function_params) {
62 if (process_type == switches::kXWalkExtensionProcess)
63 return XWalkExtensionProcessMain(main_function_params);
64 // Tell content to use default process main entries by returning -1.
69 void XWalkMainDelegate::InitializeResourceBundle() {
70 base::FilePath pak_file;
71 #if defined(OS_MACOSX)
72 pak_file = GetResourcesPakFilePath();
74 base::FilePath pak_dir;
75 PathService::Get(base::DIR_MODULE, &pak_dir);
76 DCHECK(!pak_dir.empty());
78 pak_file = pak_dir.Append(FILE_PATH_LITERAL("xwalk.pak"));
80 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
83 content::ContentBrowserClient* XWalkMainDelegate::CreateContentBrowserClient() {
84 // This will only be called from the Browser Process, so it is a convenient
85 // location to initialize the XWalkRunner, which is our main entry point in
87 xwalk_runner_ = XWalkRunner::Create();
88 return xwalk_runner_->GetContentBrowserClient();
91 content::ContentRendererClient*
92 XWalkMainDelegate::CreateContentRendererClient() {
94 renderer_client_.reset(new XWalkContentRendererClientTizen());
96 renderer_client_.reset(new XWalkContentRendererClient());
98 return renderer_client_.get();