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
131 // Runtime's destructor should be called before ewk_shutdown()
133 std::unique_ptr<runtime::Runtime> runtime =
134 runtime::Runtime::MakeRuntime(appdata);
135 if (runtime->Exec(argc, argv))
136 LOGGER(ERROR) << "Exec returns non zero.";
137 runtime->Terminate();
140 LOGGER(DEBUG) << "ewk_shutdown";
145 LOGGER(DEBUG) << "EXIT_SUCCESS";
149 __attribute__((visibility("default")))
150 int main(int argc, char* argv[]) {
151 if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
152 elm_init(argc, argv);
153 elm_config_cache_flush_enabled_set(EINA_TRUE);
154 auto preload = [argv](void) {
157 char* chromium_arg_options[] = {
159 const_cast<char*>("--no-sandbox"),
160 const_cast<char*>("--enable-file-cookies"),
161 const_cast<char*>("--allow-file-access-from-files"),
162 const_cast<char*>("--allow-universal-access-from-files"),
163 const_cast<char*>("--single-process")
165 const int chromium_arg_cnt =
166 sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
167 ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
168 runtime::PreloadManager::GetInstance()->CreateCacheComponet();
170 auto did_launch = [](const std::string& app_path) {
172 auto prelaunch = runtime::PreLauncher::Prelaunch;
173 return prelaunch(argc, argv, preload, did_launch, real_main);
175 return real_main(argc, argv);