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 "runtime/browser/runtime.h"
32 #include "runtime/common/constants.h"
33 #include "runtime/browser/prelauncher.h"
34 #include "runtime/browser/preload_manager.h"
36 #include "runtime/browser/ui_runtime.h"
38 bool g_prelaunch = false;
40 #ifdef WATCH_FACE_FEATURE_SUPPORT
41 static int setWatchEnv(int argc, char **argv) {
43 char *wayland_display = NULL;
44 char *xdg_runtime_dir = NULL;
45 char *width_str = NULL;
46 char *height_str = NULL;
48 if (argc <= 0 || argv == NULL) {
50 LOGGER(ERROR) << "argument are invalid";
54 kb = bundle_import_from_argv(argc, argv);
56 bundle_get_str(kb, "XDG_RUNTIME_DIR", &xdg_runtime_dir);
57 bundle_get_str(kb, "WAYLAND_DISPLAY", &wayland_display);
58 bundle_get_str(kb, "WATCH_WIDTH", &width_str);
59 bundle_get_str(kb, "WATCH_HEIGHT", &height_str);
61 if (xdg_runtime_dir) {
62 LOGGER(DEBUG) << "senenv: " << xdg_runtime_dir;
63 setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
65 LOGGER(ERROR) << "failed to get xdgruntimedir";
68 if (wayland_display) {
69 LOGGER(DEBUG) << "setenv: " << wayland_display;
70 setenv("WAYLAND_DISPLAY", wayland_display, 1);
72 LOGGER(ERROR) << "failed to get waylanddisplay";
76 LOGGER(ERROR) << "failed to get launch argv";
80 #endif // WATCH_FACE_FEATURE_SUPPORT
82 int real_main(int argc, char* argv[]) {
83 STEP_PROFILE_START("Start -> Launch Completed");
84 STEP_PROFILE_START("Start -> OnCreate");
86 common::CommandLine::Init(argc, argv);
88 common::CommandLine* cmd = common::CommandLine::ForCurrentProcess();
89 std::string appid = cmd->GetAppIdFromCommandLine(runtime::kRuntimeExecName);
92 auto appdata_manager = common::ApplicationDataManager::GetInstance();
93 common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid);
94 if (!appdata->LoadManifestData()) {
98 #ifdef WATCH_FACE_FEATURE_SUPPORT
99 if (appdata->app_type() == common::ApplicationData::WATCH) {
100 setWatchEnv(argc, argv);
102 #endif // WATCH_FACE_FEATURE_SUPPORT
104 // Default behavior, run as runtime.
105 LOGGER(INFO) << "Runtime process has been created.";
108 char* chromium_arg_options[] = {
110 const_cast<char*>("--no-sandbox"),
111 const_cast<char*>("--enable-file-cookies"),
112 const_cast<char*>("--allow-file-access-from-files"),
113 const_cast<char*>("--allow-universal-access-from-files"),
114 const_cast<char*>("--single-process")
116 const int chromium_arg_cnt =
117 sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
118 ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
119 #ifdef WATCH_FACE_FEATURE_SUPPORT
121 if (appdata->app_type() == common::ApplicationData::WATCH) {
122 // Below code will be enabled after testing
123 //ecore_wl_shutdown();
124 //ecore_wl_init(NULL);
126 #endif // WATCH_FACE_FEATURE_SUPPORT
130 // Runtime's destructor should be called before ewk_shutdown()
132 std::unique_ptr<runtime::Runtime> runtime =
133 runtime::Runtime::MakeRuntime(appdata);
134 ret = runtime->Exec(argc, argv);
135 if (runtime->is_on_terminate_called) {
136 LOGGER(INFO) << "Defer termination of main loop";
137 ecore_main_loop_begin();
148 __attribute__((visibility("default")))
149 int main(int argc, char* argv[]) {
150 if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
151 elm_init(argc, argv);
152 elm_config_cache_flush_enabled_set(EINA_TRUE);
153 auto preload = [argv](void) {
156 char* chromium_arg_options[] = {
158 const_cast<char*>("--no-sandbox"),
159 const_cast<char*>("--enable-file-cookies"),
160 const_cast<char*>("--allow-file-access-from-files"),
161 const_cast<char*>("--allow-universal-access-from-files"),
162 const_cast<char*>("--single-process")
164 const int chromium_arg_cnt =
165 sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
166 ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
167 runtime::PreloadManager::GetInstance()->CreateCacheComponet();
169 auto did_launch = [](const std::string& app_path) {
171 auto prelaunch = runtime::PreLauncher::Prelaunch;
172 return prelaunch(argc, argv, preload, did_launch, real_main);
174 return real_main(argc, argv);