Change dummy object atspi role
[platform/framework/web/crosswalk-tizen.git] / runtime / browser / runtime_process.cc
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <EWebKit.h>
18 #include <EWebKit_internal.h>
19
20 #include <Elementary.h>
21
22 #ifdef WATCH_FACE_FEATURE_SUPPORT
23 #include <bundle_internal.h>
24 #include <Ecore_Wayland.h>
25 #endif  // WATCH_FACE_FEATURE_SUPPORT
26
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"
35
36 bool g_prelaunch = false;
37
38 #ifdef WATCH_FACE_FEATURE_SUPPORT
39 static int setWatchEnv(int argc, char **argv) {
40   bundle *kb = NULL;
41   char *wayland_display = NULL;
42   char *xdg_runtime_dir = NULL;
43   char *width_str = NULL;
44   char *height_str = NULL;
45
46   if (argc <= 0 || argv == NULL) {
47     errno = EINVAL;
48     LOGGER(ERROR) << "argument are invalid";
49     return -1;
50   }
51
52   kb = bundle_import_from_argv(argc, argv);
53   if (kb) {
54     bundle_get_str(kb, "XDG_RUNTIME_DIR", &xdg_runtime_dir);
55     bundle_get_str(kb, "WAYLAND_DISPLAY", &wayland_display);
56     bundle_get_str(kb, "WATCH_WIDTH", &width_str);
57     bundle_get_str(kb, "WATCH_HEIGHT", &height_str);
58
59     if (xdg_runtime_dir) {
60       LOGGER(DEBUG) << "senenv: " << xdg_runtime_dir;
61       setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
62     } else {
63       LOGGER(ERROR) << "failed to get xdgruntimedir";
64     }
65
66     if (wayland_display) {
67       LOGGER(DEBUG) << "setenv: " << wayland_display;
68       setenv("WAYLAND_DISPLAY", wayland_display, 1);
69     } else {
70       LOGGER(ERROR) << "failed to get waylanddisplay";
71     }
72     bundle_free(kb);
73   } else {
74     LOGGER(ERROR) << "failed to get launch argv";
75   }
76   return 0;
77 }
78 #endif  // WATCH_FACE_FEATURE_SUPPORT
79
80 int real_main(int argc, char* argv[]) {
81   STEP_PROFILE_START("Start -> Launch Completed");
82   STEP_PROFILE_START("Start -> OnCreate");
83   // Parse commandline.
84   common::CommandLine::Init(argc, argv);
85
86   common::CommandLine* cmd = common::CommandLine::ForCurrentProcess();
87   std::string appid = cmd->GetAppIdFromCommandLine(runtime::kRuntimeExecName);
88
89   // Load Manifest
90   auto appdata_manager = common::ApplicationDataManager::GetInstance();
91   common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid);
92   if (!appdata->LoadManifestData()) {
93     return false;
94   }
95
96 #ifdef WATCH_FACE_FEATURE_SUPPORT
97   if (appdata->app_type() == common::ApplicationData::WATCH) {
98     setWatchEnv(argc, argv);
99   }
100 #endif  // WATCH_FACE_FEATURE_SUPPORT
101
102   // Default behavior, run as runtime.
103   LOGGER(INFO) << "Runtime process has been created.";
104   if (!g_prelaunch) {
105     ewk_init();
106     char* chromium_arg_options[] = {
107       argv[0],
108       const_cast<char*>("--no-sandbox"),
109       const_cast<char*>("--enable-file-cookies"),
110       const_cast<char*>("--allow-file-access-from-files"),
111       const_cast<char*>("--allow-universal-access-from-files"),
112       const_cast<char*>("--single-process")
113     };
114     const int chromium_arg_cnt =
115         sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
116     ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
117 #ifdef WATCH_FACE_FEATURE_SUPPORT
118   } else {
119     if (appdata->app_type() == common::ApplicationData::WATCH) {
120       // Below code will be enabled after testing
121       //ecore_wl_shutdown();
122       //ecore_wl_init(NULL);
123     }
124 #endif  // WATCH_FACE_FEATURE_SUPPORT
125   }
126
127   int ret = 0;
128   // Runtime's destructor should be called before ewk_shutdown()
129   {
130     std::unique_ptr<runtime::Runtime> runtime =
131         runtime::Runtime::MakeRuntime(appdata);
132     ret = runtime->Exec(argc, argv);
133     runtime.reset();
134   }
135   ewk_shutdown();
136   exit(ret);
137
138   return EXIT_SUCCESS;
139 }
140
141 __attribute__((visibility("default")))
142 int main(int argc, char* argv[]) {
143   if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
144     elm_init(argc, argv);
145     elm_config_cache_flush_enabled_set(EINA_TRUE);
146     auto preload = [argv](void) {
147       g_prelaunch = true;
148       ewk_init();
149       char* chromium_arg_options[] = {
150         argv[0],
151         const_cast<char*>("--no-sandbox"),
152         const_cast<char*>("--enable-file-cookies"),
153         const_cast<char*>("--allow-file-access-from-files"),
154         const_cast<char*>("--allow-universal-access-from-files"),
155         const_cast<char*>("--single-process")
156       };
157       const int chromium_arg_cnt =
158           sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
159       ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
160       runtime::PreloadManager::GetInstance()->CreateCacheComponet();
161     };
162     auto did_launch = [](const std::string& app_path) {
163     };
164     auto prelaunch = runtime::PreLauncher::Prelaunch;
165     return prelaunch(argc, argv, preload, did_launch, real_main);
166   } else {
167     return real_main(argc, argv);
168   }
169 }