Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / app / xwalk_main_delegate.cc
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.
4
5 #include "xwalk/runtime/app/xwalk_main_delegate.h"
6
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"
21
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"
25 #endif
26
27 #if defined(OS_TIZEN)
28 #include "xwalk/runtime/renderer/tizen/xwalk_content_renderer_client_tizen.h"
29 #endif
30
31 namespace xwalk {
32
33 XWalkMainDelegate::XWalkMainDelegate()
34     : content_client_(new XWalkContentClient) {
35 }
36
37 XWalkMainDelegate::~XWalkMainDelegate() {}
38
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();
47 #elif defined(OS_WIN)
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();
54 #endif
55
56 #if !defined(DISABLE_NACL) && defined(OS_LINUX)
57   nacl::RegisterPathProvider();
58 #endif
59
60   return false;
61 }
62
63 void XWalkMainDelegate::PreSandboxStartup() {
64   RegisterPathProvider();
65   InitializeResourceBundle();
66 }
67
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.
73   return -1;
74 }
75
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);
81 #endif
82 }
83
84 #endif  // defined(OS_POSIX) && !defined(OS_ANDROID)
85
86 // static
87 void XWalkMainDelegate::InitializeResourceBundle() {
88   base::FilePath pak_file;
89 #if defined(OS_MACOSX)
90   pak_file = GetResourcesPakFilePath();
91 #else
92   base::FilePath pak_dir;
93   PathService::Get(base::DIR_MODULE, &pak_dir);
94   DCHECK(!pak_dir.empty());
95
96   pak_file = pak_dir.Append(FILE_PATH_LITERAL("xwalk.pak"));
97 #endif
98   ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
99 }
100
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
104   // Browser Process.
105   xwalk_runner_ = XWalkRunner::Create();
106   return xwalk_runner_->GetContentBrowserClient();
107 }
108
109 content::ContentRendererClient*
110     XWalkMainDelegate::CreateContentRendererClient() {
111 #if defined(OS_TIZEN)
112   renderer_client_.reset(new XWalkContentRendererClientTizen());
113 #else
114   renderer_client_.reset(new XWalkContentRendererClient());
115 #endif
116   return renderer_client_.get();
117 }
118
119 }  // namespace xwalk