2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <EWebKit_internal.h>
20 #include <Elementary.h>
22 #ifdef WATCH_FACE_FEATURE_SUPPORT
23 #include <bundle_internal.h>
24 #include <Ecore_Wayland.h>
25 #endif // WATCH_FACE_FEATURE_SUPPORT
27 #include "common/application_data.h"
28 #include "common/command_line.h"
29 #include "common/logger.h"
30 #include "common/profiler.h"
31 #include "extensions/renderer/xwalk_extension_renderer_controller.h"
32 #include "runtime/browser/runtime.h"
33 #include "runtime/common/constants.h"
34 #include "runtime/browser/prelauncher.h"
35 #include "runtime/browser/preload_manager.h"
37 #include "runtime/browser/ui_runtime.h"
39 using namespace extensions;
40 bool g_prelaunch = false;
42 #ifdef WATCH_FACE_FEATURE_SUPPORT
43 static int setWatchEnv(int argc, char **argv) {
45 char *wayland_display = NULL;
46 char *xdg_runtime_dir = NULL;
47 char *width_str = NULL;
48 char *height_str = NULL;
50 if (argc <= 0 || argv == NULL) {
52 LOGGER(ERROR) << "argument are invalid";
56 kb = bundle_import_from_argv(argc, argv);
58 bundle_get_str(kb, "XDG_RUNTIME_DIR", &xdg_runtime_dir);
59 bundle_get_str(kb, "WAYLAND_DISPLAY", &wayland_display);
60 bundle_get_str(kb, "WATCH_WIDTH", &width_str);
61 bundle_get_str(kb, "WATCH_HEIGHT", &height_str);
63 if (xdg_runtime_dir) {
64 LOGGER(DEBUG) << "senenv: " << xdg_runtime_dir;
65 setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
67 LOGGER(ERROR) << "failed to get xdgruntimedir";
70 if (wayland_display) {
71 LOGGER(DEBUG) << "setenv: " << wayland_display;
72 setenv("WAYLAND_DISPLAY", wayland_display, 1);
74 LOGGER(ERROR) << "failed to get waylanddisplay";
78 LOGGER(ERROR) << "failed to get launch argv";
82 #endif // WATCH_FACE_FEATURE_SUPPORT
84 int real_main(int argc, char* argv[]) {
85 STEP_PROFILE_START("Start -> Launch Completed");
86 STEP_PROFILE_START("Start -> OnCreate");
88 common::CommandLine::Init(argc, argv);
90 common::CommandLine* cmd = common::CommandLine::ForCurrentProcess();
91 std::string appid = cmd->GetAppIdFromCommandLine(runtime::kRuntimeExecName);
94 auto appdata_manager = common::ApplicationDataManager::GetInstance();
95 common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid);
96 if (!appdata->LoadManifestData()) {
100 #ifdef WATCH_FACE_FEATURE_SUPPORT
101 if (appdata->app_type() == common::ApplicationData::WATCH) {
102 setWatchEnv(argc, argv);
104 #endif // WATCH_FACE_FEATURE_SUPPORT
106 // Default behavior, run as runtime.
107 LOGGER(INFO) << "Runtime process has been created.";
110 char* chromium_arg_options[] = {
112 const_cast<char*>("--no-sandbox"),
113 const_cast<char*>("--enable-file-cookies"),
114 const_cast<char*>("--allow-file-access-from-files"),
115 const_cast<char*>("--allow-universal-access-from-files"),
116 const_cast<char*>("--single-process")
118 const int chromium_arg_cnt =
119 sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
120 ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
121 #ifdef WATCH_FACE_FEATURE_SUPPORT
123 if (appdata->app_type() == common::ApplicationData::WATCH) {
124 // Below code will be enabled after testing
125 //ecore_wl_shutdown();
126 //ecore_wl_init(NULL);
128 #endif // WATCH_FACE_FEATURE_SUPPORT
132 // Runtime's destructor should be called before ewk_shutdown()
134 std::unique_ptr<runtime::Runtime> runtime =
135 runtime::Runtime::MakeRuntime(appdata);
136 ret = runtime->Exec(argc, argv);
138 LOGGER(ERROR) << "Exec returns non zero.";
139 LOGGER(DEBUG) << "plugin_session_count : " <<
140 XWalkExtensionRendererController::plugin_session_count;
141 if (XWalkExtensionRendererController::plugin_session_count > 0) {
142 LOGGER(DEBUG) << "Defer termination of main loop";
143 ecore_main_loop_begin();
147 LOGGER(DEBUG) << "ewk_shutdown";
152 LOGGER(DEBUG) << "EXIT_SUCCESS";
156 __attribute__((visibility("default")))
157 int main(int argc, char* argv[]) {
158 if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
159 elm_init(argc, argv);
160 elm_config_cache_flush_enabled_set(EINA_TRUE);
161 auto preload = [argv](void) {
164 char* chromium_arg_options[] = {
166 const_cast<char*>("--no-sandbox"),
167 const_cast<char*>("--enable-file-cookies"),
168 const_cast<char*>("--allow-file-access-from-files"),
169 const_cast<char*>("--allow-universal-access-from-files"),
170 const_cast<char*>("--single-process")
172 const int chromium_arg_cnt =
173 sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
174 ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
175 runtime::PreloadManager::GetInstance()->CreateCacheComponet();
177 auto did_launch = [](const std::string& app_path) {
179 auto prelaunch = runtime::PreLauncher::Prelaunch;
180 return prelaunch(argc, argv, preload, did_launch, real_main);
182 return real_main(argc, argv);