d5b143c33a9d8077a104e5291a2455abccdcf01f
[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 <ewk_chromium.h>
18
19 #include <Elementary.h>
20
21 #include "common/application_data.h"
22 #include "common/command_line.h"
23 #include "common/logger.h"
24 #include "common/profiler.h"
25 #include "runtime/browser/runtime.h"
26 #include "runtime/common/constants.h"
27 #include "runtime/browser/prelauncher.h"
28 #include "runtime/browser/preload_manager.h"
29
30 bool g_prelaunch = false;
31
32 int real_main(int argc, char* argv[]) {
33   STEP_PROFILE_START("Start -> Launch Completed");
34   STEP_PROFILE_START("Start -> OnCreate");
35   // Parse commandline.
36   common::CommandLine::Init(argc, argv);
37
38   common::CommandLine* cmd = common::CommandLine::ForCurrentProcess();
39   std::string appid = cmd->GetAppIdFromCommandLine(runtime::kRuntimeExecName);
40
41   // Load Manifest
42   auto appdata_manager = common::ApplicationDataManager::GetInstance();
43   common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid);
44   if (!appdata->LoadManifestData()) {
45     return false;
46   }
47
48   // Default behavior, run as runtime.
49   LOGGER(INFO) << "Runtime process has been created.";
50   if (!g_prelaunch) {
51     ewk_init();
52     char* chromium_arg_options[] = {
53       argv[0],
54       const_cast<char*>("--no-sandbox"),
55       const_cast<char*>("--enable-file-cookies"),
56       const_cast<char*>("--allow-file-access-from-files"),
57       const_cast<char*>("--allow-universal-access-from-files"),
58       const_cast<char*>("--single-process")
59     };
60     const int chromium_arg_cnt =
61         sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
62     ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
63   }
64
65   int ret = 0;
66   // Runtime's destructor should be called before ewk_shutdown()
67   {
68     std::unique_ptr<runtime::Runtime> runtime =
69         runtime::Runtime::MakeRuntime(appdata);
70     ret = runtime->Exec(argc, argv);
71     runtime.reset();
72   }
73   ewk_shutdown();
74   exit(ret);
75
76   return EXIT_SUCCESS;
77 }
78
79 int main(int argc, char* argv[]) {
80   if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
81     elm_init(argc, argv);
82     auto preload = [argv](void) {
83       g_prelaunch = true;
84       ewk_init();
85       char* chromium_arg_options[] = {
86         argv[0],
87         const_cast<char*>("--no-sandbox"),
88         const_cast<char*>("--enable-file-cookies"),
89         const_cast<char*>("--allow-file-access-from-files"),
90         const_cast<char*>("--allow-universal-access-from-files"),
91         const_cast<char*>("--single-process")
92       };
93       const int chromium_arg_cnt =
94           sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
95       ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
96       runtime::PreloadManager::GetInstance()->CreateCacheComponet();
97     };
98     auto did_launch = [](const std::string& app_path) {
99     };
100     auto prelaunch = runtime::PreLauncher::Prelaunch;
101     return prelaunch(argc, argv, preload, did_launch, real_main);
102   } else {
103     return real_main(argc, argv);
104   }
105 }