1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <ewk_chromium.h>
7 #include <Elementary.h>
12 #include <appfw/app.h>
18 // Default command line flags added by default when
19 // ubrowser is started with --mobile|-m flag.
20 const char* kMobileFlags[] = {
21 "use-mobile-user-agent",
22 "enable-overlay-scrollbar",
24 "enable-prefer-compositing-to-lcd-text",
25 "ewk-enable-mobile-features-for-desktop",
28 extern int logger_show_trace;
29 extern int logger_use_color;
37 AppData() : browser(nullptr), ewk_initialized(false) { }
39 std::vector<std::string> urls;
44 void show_help_and_exit(const char* app_name) {
45 printf("Usage: %s [OPTION]... [URL]...\n\n", app_name);
46 printf("Available options:\n");
47 printf(" -v, --verbose Print verbose application logs\n");
48 printf(" -n, --no-color Don't use colors in application logs\n");
49 printf(" -d, --desktop Run application UI in desktop mode\n");
50 printf(" -m, --mobile Run application UI in mobile mode\n");
51 printf(" -h, --help Show this help message\n");
55 void parse_options(int argc, char** argv) {
60 static struct option long_options[] = {
61 {"verbose", no_argument, &logger_show_trace, 1},
62 {"no-color", no_argument, &logger_use_color, 0},
63 {"desktop", no_argument, &desktop_ui, 1},
64 {"mobile", no_argument, &desktop_ui, 0},
65 {"help", no_argument, &show_help, 1},
70 c = getopt_long (argc, argv, "vndmh", long_options, &option_index);
77 logger_show_trace = 1;
92 // Ignore EFL or chromium specific options,
93 // ewk_set_arguments should handle them
99 show_help_and_exit(argv[0]);
102 static bool app_create(void* data) {
103 AppData* app_data = static_cast<AppData*>(data);
108 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
110 app_data->browser = new Browser(desktop_ui);
111 std::vector<std::string>::iterator it = app_data->urls.begin();
112 for (;it != app_data->urls.end(); ++it)
113 app_data->browser->CreateWindow().LoadURL(*it);
114 app_data->urls.clear();
115 app_data->ewk_initialized = true;
119 static void app_terminate(void* data) {
120 AppData* app_data = static_cast<AppData*>(data);
121 if (app_data->browser)
122 delete app_data->browser;
123 if (app_data->ewk_initialized)
127 #if defined(OS_TIZEN) && defined(TIZEN_APP)
128 static void app_pause(void* data) {
129 log_debug("Tizen uBrowser pause");
132 static void app_resume(void* data) {
133 log_debug("Tizen uBrowser resume");
137 int main(int argc, char** argv) {
140 for (int i = 1; i < argc; ++i)
141 if (argv[i][0] != '-')
142 data.urls.push_back(std::string(argv[i]));
144 if (data.urls.empty())
145 data.urls.push_back("http://www.google.com");
147 ewk_set_arguments(argc, argv);
148 elm_init(argc, argv);
149 elm_config_accel_preference_set("opengl");
150 parse_options(argc, argv);
152 // Do not propagate mobile flags for all TIZEN builds.
153 // They are controlled by command_line_efl.cc.
154 #if !defined(OS_TIZEN)
156 int size = sizeof(kMobileFlags) / sizeof(kMobileFlags[0]);
157 for (int i = 0; i < size; ++i)
158 ewk_chromium_append_command_line_flag(kMobileFlags[i]);
163 // Enable the section below once ubrowser is ready
164 // to replace mini_browser. For the code below to work
165 // proper manifest needs to be added to the rpm package
166 #if defined(OS_TIZEN) && defined(TIZEN_APP)
167 ui_app_lifecycle_callback_s ops;
169 memset(&ops, 0, sizeof(ops));
170 ops.create = app_create;
171 ops.terminate = app_terminate;
172 ops.pause = app_pause;
173 ops.resume = app_resume;
175 ret = ui_app_main(argc, argv, &ops, &data)
177 if (!app_create(&data))
182 app_terminate(&data);