Upstream version 5.34.104.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(OS_TIZEN)
23 #include "xwalk/runtime/renderer/tizen/xwalk_content_renderer_client_tizen.h"
24 #endif
25
26 namespace xwalk {
27
28 XWalkMainDelegate::XWalkMainDelegate()
29     : content_client_(new XWalkContentClient) {
30 }
31
32 XWalkMainDelegate::~XWalkMainDelegate() {}
33
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());
39 #if defined(OS_WIN)
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();
46 #endif
47   return false;
48 }
49
50 void XWalkMainDelegate::PreSandboxStartup() {
51 #if defined(OS_MACOSX)
52   OverrideFrameworkBundlePath();
53   OverrideChildProcessPath();
54 #endif  // OS_MACOSX
55
56   RegisterPathProvider();
57   InitializeResourceBundle();
58 }
59
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.
65   return -1;
66 }
67
68 // static
69 void XWalkMainDelegate::InitializeResourceBundle() {
70   base::FilePath pak_file;
71 #if defined(OS_MACOSX)
72   pak_file = GetResourcesPakFilePath();
73 #else
74   base::FilePath pak_dir;
75   PathService::Get(base::DIR_MODULE, &pak_dir);
76   DCHECK(!pak_dir.empty());
77
78   pak_file = pak_dir.Append(FILE_PATH_LITERAL("xwalk.pak"));
79 #endif
80   ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
81 }
82
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
86   // Browser Process.
87   xwalk_runner_ = XWalkRunner::Create();
88   return xwalk_runner_->GetContentBrowserClient();
89 }
90
91 content::ContentRendererClient*
92     XWalkMainDelegate::CreateContentRendererClient() {
93 #if defined(OS_TIZEN)
94   renderer_client_.reset(new XWalkContentRendererClientTizen());
95 #else
96   renderer_client_.reset(new XWalkContentRendererClient());
97 #endif
98   return renderer_client_.get();
99 }
100
101 }  // namespace xwalk