7f94d15b65ca29e64281acc6f7b7caf6b1cb2421
[platform/framework/web/nwrt.git] / src / runtime / main.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 "common/logger.h"
20 #include "common/constants.h"
21 #include "common/command_line.h"
22 #include "runtime/runtime.h"
23 #include "extension/extension_server.h"
24 #include "common/profiler.h"
25
26 int main(int argc, char* argv[]) {
27   STEP_PROFILE_START("Start -> Launch Completed");
28   STEP_PROFILE_START("Start -> OnCreate");
29   // Parse commandline.
30   wrt::CommandLine::Init(argc, argv);
31
32   wrt::CommandLine* cmd = wrt::CommandLine::ForCurrentProcess();
33   if (cmd->HasOptionName(wrt::kSwitchExtensionServer)) {
34     // If cmd has the switch '--extension-server', run as extension server.
35     LOGGER(INFO) << "Extension server process has been created.";
36     if (!wrt::ExtensionServer::StartExtensionProcess()) {
37       LOGGER(ERROR) << "Failed to start extension server.";
38       exit(EXIT_FAILURE);
39     }
40   } else {
41     // Default behavior, run as runtime.
42     LOGGER(INFO) << "Runtime process has been created.";
43     ewk_init();
44     char* chromium_arg_options[] = {
45       argv[0],
46       const_cast<char*>("--no-sandbox"),
47       const_cast<char*>("--enable-file-cookies"),
48       const_cast<char*>("--allow-file-access-from-files"),
49       const_cast<char*>("--allow-universal-access-from-files")
50     };
51     const int chromium_arg_cnt =
52         sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
53     ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
54
55     int ret = 0;
56     // Runtime's destructor should be called before ewk_shutdown()
57     {
58       wrt::Runtime runtime;
59       ret = runtime.Exec(argc, argv);
60     }
61     ewk_shutdown();
62     exit(ret);
63   }
64
65   return EXIT_SUCCESS;
66 }