2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
20 #include <TapiUtility.h>
24 #include "browser-config.h"
25 #include "browser-class.h"
28 Evas_Object *main_win;
30 Evas_Object *main_layout;
31 Evas_Object *navi_bar;
32 Elm_Theme *browser_theme;
34 Browser_Class *browser_instance;
39 static void __br_set_env(void)
41 #if !defined(TIZEN_PUBLIC)
42 /* manual enabling of CoreGL fastpath */
43 setenv("COREGL_FASTPATH", "1", 1);
46 /* set image cache suze */
47 if (setenv("ELM_IMAGE_CACHE", "0", 1))
48 BROWSER_LOGD("ELM_IMAGE_CACHE is set to 1MB");
50 /* This is because of showing navigation bar more quickly. */
51 if (setenv("ELM_BRING_IN_SCROLL_FRICTION", "0.2", 1))
52 BROWSER_LOGD("ELM_BRING_IN_SCROLL_FRICTION is set");
54 if (setenv("ELM_PAGE_SCROLL_FRICTION", "0.4", 1))
55 BROWSER_LOGD("ELM_PAGE_SCROLL_FRICTION is set");
57 if (setenv("ELM_THUMBSCROLL_BOUNCE_FRICTION", "0.2", 1))
58 BROWSER_LOGD("ELM_THUMBSCROLL_BOUNCE_FRICTION is set");
61 static void __br_destroy(void *data)
63 BROWSER_LOGD("[%s]", __func__);
67 static void __main_win_del_cb(void *data, Evas_Object *obj, void *event)
69 BROWSER_LOGD("[Browser-Launching time measure]<< window delete callback >>");
72 static bool __init_preference()
74 BROWSER_LOGD("[%s]", __func__);
76 if (!br_preference_create_bool(SHOW_MY_SITES_GUIDE, true))
78 if (!br_preference_create_str(LAST_VISITED_URL_KEY, ""))
80 #if defined(FEATURE_MOST_VISITED_SITES)
81 if (!br_preference_create_str(HOMEPAGE_KEY, MOST_VISITED_SITES))
84 if (!br_preference_create_str(HOMEPAGE_KEY, USER_HOMEPAGE))
87 if (!br_preference_create_str(USER_HOMEPAGE_KEY, BROWSER_DEFAULT_USER_HOMEPAGE))
89 if (!br_preference_create_str(SEARCHURL_KEY, "http://search.yahoo.com/search?p="))
91 if (!br_preference_create_str(DEFAULT_VIEW_LEVEL_KEY, READABLE))
93 if (!br_preference_create_bool(RUN_JAVASCRIPT_KEY, true))
95 if (!br_preference_create_bool(DISPLAY_IMAGES_KEY, true))
97 if (!br_preference_create_bool(BLOCK_POPUP_KEY, true))
99 if (!br_preference_create_bool(SHOW_SECURITY_WARNINGS_KEY, true))
101 if (!br_preference_create_bool(ACCEPT_COOKIES_KEY, true))
103 if (!br_preference_create_bool(ENABLE_LOCATION_KEY, true))
106 if (!br_preference_create_bool(ZOOM_BUTTON_KEY, true))
112 static Evas_Object *__create_main_win(void *app_data)
114 Evas_Object *window = elm_win_add(NULL, BROWSER_PACKAGE_NAME, ELM_WIN_BASIC);
118 elm_win_title_set(window, BROWSER_PACKAGE_NAME);
119 elm_win_borderless_set(window, EINA_TRUE);
120 elm_win_conformant_set(window, EINA_TRUE);
121 evas_object_smart_callback_add(window, "delete,request",
122 __main_win_del_cb, app_data);
123 ecore_x_window_size_get(ecore_x_window_root_first_get(),
125 evas_object_resize(window, w, h);
126 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
127 evas_object_show(window);
133 static Evas_Object *__create_bg(Evas_Object *win)
136 bg = elm_bg_add(win);
140 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
141 elm_win_resize_object_add(win, bg);
142 evas_object_show(bg);
147 static Evas_Object *__create_main_layout(Evas_Object *win)
150 layout = elm_layout_add(win);
154 if (!elm_layout_theme_set(layout, "layout", "application", "default"))
155 BROWSER_LOGE("elm_layout_theme_set is failed.\n");
157 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
158 elm_win_resize_object_add(win, layout);
159 edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,show,indicator", "elm");
160 evas_object_show(layout);
165 static Evas_Object *__create_navi_bar(void *app_data)
167 BROWSER_LOGD("[%s]", __func__);
168 Evas_Object *navi_bar;
169 struct browser_data *ad = (struct browser_data *)app_data;
170 navi_bar = elm_naviframe_add(ad->main_layout);
172 elm_object_theme_set(navi_bar, ad->browser_theme);
173 elm_object_style_set(navi_bar, "browser");
174 elm_object_part_content_set(ad->main_layout, "elm.swallow.content", navi_bar);
175 evas_object_show(navi_bar);
181 static Eina_Bool __process_app_service(service_h service, void *app_data)
183 BROWSER_LOGD("[%s]", __func__);
184 struct browser_data *ad = (struct browser_data *)app_data;
186 char *operation = NULL;
187 char *request_uri = NULL;
188 char *request_mime_type = NULL;
190 if (service_get_operation(service, &operation) != SERVICE_ERROR_NONE) {
191 BROWSER_LOGD("get service operation failed");
195 if (service_get_uri(service, &request_uri) != SERVICE_ERROR_NONE) {
196 BROWSER_LOGD("get service uri failed");
199 if (service_get_mime(service, &request_mime_type) != SERVICE_ERROR_NONE) {
200 BROWSER_LOGD("get service mime failed");
203 if (!operation && !request_uri && !request_mime_type) {
204 BROWSER_LOGD("Not app svc");
208 BROWSER_LOGD("operation[%s], request_uri[%s], request_mime_type[%s]", operation, request_uri, request_mime_type);
210 std::string full_path;
212 if (request_mime_type) {
213 if (!strncmp(request_mime_type, "application/x-shockwave-flash", strlen("application/x-shockwave-flash"))
214 || !strncmp(request_mime_type, "image/svg+xml", strlen("image/svg+xml"))
215 || !strncmp(request_mime_type, "text/html", strlen("text/html"))
216 || !strncmp(request_mime_type, "application/xml", strlen("application/xml"))) {
218 full_path = std::string(request_uri);
220 BROWSER_LOGD("Not allowed mime type : [%s]", request_mime_type);
223 } else if (request_uri) {
224 full_path = std::string(request_uri);
227 BROWSER_LOGD("url=[%s]", full_path.c_str());
230 elm_win_activate(ad->main_win);
232 ad->browser_instance->launch(full_path.c_str(), EINA_TRUE);
237 static void __br_load_url(service_h service, void *app_data)
239 BROWSER_LOGD("[%s]", __func__);
240 struct browser_data *ad = (struct browser_data *)app_data;
242 if (__process_app_service(service, app_data)) {
243 BROWSER_LOGD("app service");
247 std::string full_path;
248 char *mime_type = NULL;
249 char *search_keyword = NULL;
250 char *goto_url = NULL;
253 if (service_get_uri(service, &url) != SERVICE_ERROR_NONE) {
254 BROWSER_LOGD("get service uri failed");
257 if (service_get_mime(service, &mime_type) != SERVICE_ERROR_NONE) {
258 BROWSER_LOGD("get service mime failed");
261 if (service_get_extra_data(service, "search_keyword", &search_keyword) != SERVICE_ERROR_NONE) {
262 BROWSER_LOGD("get service extra data(search keyword) failed");
265 if (service_get_extra_data(service, "goto_url", &search_keyword) != SERVICE_ERROR_NONE) {
266 BROWSER_LOGD("get service extra data(search keyword) failed");
269 if (mime_type && url) {
270 BROWSER_LOGD("mime type=[%s], url=[%s]", mime_type, url);
271 if (!strcmp(mime_type, "application/x-shockwave-flash")
272 || !strcmp(mime_type, "image/svg+xml")
273 || !strcmp(mime_type, "text/html")
274 || !strcmp(mime_type, "application/xml")) {
275 full_path = std::string(url);
277 } else if (search_keyword) {
278 BROWSER_LOGD("search_keyword=[%s]", search_keyword);
279 if (search_keyword) {
280 char *search_url = NULL;
281 if (br_preference_get_str(SEARCHURL_KEY, &search_url) == false) {
282 BROWSER_LOGE("failed to get %s preference\n", SEARCHURL_KEY);
286 full_path = std::string(search_url) + std::string(search_keyword);
290 } else if (goto_url || url) {
291 BROWSER_LOGD("goto_url=[%s], url=[%s]", goto_url, url);
293 full_path = goto_url;
297 BROWSER_LOGD("url=[%s]", full_path.c_str());
300 elm_win_activate(ad->main_win);
302 ad->browser_instance->launch(full_path.c_str(), EINA_TRUE);
305 static Eina_Bool __br_keydown_event(void *data, int type, void *event)
307 BROWSER_LOGD("[%s]", __func__);
308 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
310 if (!strcmp(ev->keyname, KEY_END)) {
317 #if defined(HORIZONTAL_UI)
318 static void __br_rotate_cb(app_device_orientation_e mode, void *data)
320 BROWSER_LOGD("[%s] rotation mode = %d", __func__, mode);
321 struct browser_data *ad = (struct browser_data *)data;
325 case APP_DEVICE_ORIENTATION_0:
327 ug_send_event(UG_EVENT_ROTATE_PORTRAIT);
329 case APP_DEVICE_ORIENTATION_90:
331 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN);
333 case APP_DEVICE_ORIENTATION_180:
334 rotation_value = 180;
335 ug_send_event(UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN);
337 case APP_DEVICE_ORIENTATION_270:
338 rotation_value = 270;
339 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE);
346 if (rotation_value >= 0 && ad->browser_instance) {
347 if (ad->browser_instance->is_available_to_rotate()) {
348 elm_win_rotation_with_resize_set(ad->main_win, rotation_value);
349 ad->browser_instance->rotate(rotation_value);
355 static void __br_low_memory_cb(void* data)
357 BROWSER_LOGD("[%s]", __func__);
359 struct browser_data *ad = (struct browser_data *)data;
361 if (ad && ad->browser_instance)
362 ad->browser_instance->clean_up_windows();
365 static void __br_low_battery_cb(void* data)
367 BROWSER_LOGD("[%s]", __func__);
372 static void __br_lang_changed_cb(void *data)
374 BROWSER_LOGD("[%s]", __func__);
379 static void __br_region_changed_cb(void *data)
381 BROWSER_LOGD("[%s]", __func__);
386 static void __br_register_system_event(void *app_data)
389 struct browser_data *ad = (struct browser_data *)app_data;
392 static int __browser_set_i18n(const char *domain, const char *dir)
396 if (domain == NULL) {
397 BROWSER_LOGE("domain is NULL");
401 r = setlocale(LC_ALL, "");
403 /* if locale is not set properly, try again to set as language base */
405 char *lang_set = vconf_get_str(VCONFKEY_LANGSET);
406 if (!lang_set && strlen(lang_set) > 0)
407 r = setlocale(LC_ALL, lang_set);
409 BROWSER_LOGE("setlocale as [%s]", r);
415 BROWSER_LOGE("setlocale failed");
419 r = bindtextdomain(domain, dir);
421 BROWSER_LOGE("bindtextdomain failed");
425 r = textdomain(domain);
427 BROWSER_LOGE("textdomain failed");
434 static bool __br_app_create(void *app_data)
436 BROWSER_LOGD("[Browser-Launching time measure] << theme extenstion >>");
437 struct browser_data *ad = (struct browser_data *)app_data;
439 elm_config_preferred_engine_set("opengl_x11");
441 if(!__init_preference())
444 ad->browser_theme = elm_theme_new();
445 elm_theme_ref_set(ad->browser_theme, NULL);
446 elm_theme_extension_add(ad->browser_theme, BROWSER_NAVIFRAME_THEME);
447 elm_theme_extension_add(ad->browser_theme, BROWSER_CONTROLBAR_THEME);
448 elm_theme_extension_add(ad->browser_theme, BROWSER_BUTTON_THEME);
449 elm_theme_extension_add(ad->browser_theme, BROWSER_PROGRESSBAR_THEME);
450 elm_theme_extension_add(ad->browser_theme, BROWSER_URL_LAYOUT_THEME);
451 elm_theme_extension_add(ad->browser_theme, BROWSER_PREDICTIVE_HISTORY_THEME);
452 elm_theme_extension_add(ad->browser_theme, BROWSER_SETTINGS_THEME);
453 elm_theme_extension_add(ad->browser_theme, BROWSER_BOOKMARK_THEME);
454 elm_theme_extension_add(ad->browser_theme, BROWSER_FIND_WORD_LAYOUT_THEME);
456 BROWSER_LOGD("[Browser-Launching time measure] << create main window >>");
457 ad->main_win = __create_main_win(ad);
459 BROWSER_LOGE("fail to create window");
463 BROWSER_LOGD("[Browser-Launching time measure] << create background >>");
464 ad->bg = __create_bg(ad->main_win);
466 BROWSER_LOGE("fail to create bg");
470 BROWSER_LOGD("[Browser-Launching time measure] << create layout main >>");
471 ad->main_layout = __create_main_layout(ad->main_win);
472 if (!ad->main_layout) {
473 BROWSER_LOGE("fail to create main layout");
477 ad->navi_bar = __create_navi_bar(ad);
479 BROWSER_LOGE("fail to create navi bar");
483 /* create browser instance & init */
484 ad->browser_instance = new(nothrow) Browser_Class(ad->main_win, ad->navi_bar, ad->bg);
485 if (!ad->browser_instance) {
486 BROWSER_LOGE("fail to Browser_Class");
489 if (ad->browser_instance->init() == EINA_FALSE) {
490 BROWSER_LOGE("fail to browser init");
494 /* init internationalization */
495 int ret = __browser_set_i18n(BROWSER_PACKAGE_NAME, BROWSER_LOCALE_DIR);
497 BROWSER_LOGE("fail to __browser_set_i18n");
501 #if defined(HORIZONTAL_UI)
502 app_device_orientation_e rotation_value = app_get_device_orientation();
504 if (rotation_value != APP_DEVICE_ORIENTATION_0) {
505 elm_win_rotation_with_resize_set(ad->main_win, rotation_value);
506 ad->browser_instance->rotate(rotation_value);
513 /* GCF test requirement */
514 static void __send_termination_event_to_tapi(void)
516 BROWSER_LOGD("[%s]", __func__);
517 int ret = TAPI_API_SUCCESS;
519 TelSatEventDownloadReqInfo_t event_data;
520 event_data.eventDownloadType = TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION;
521 event_data.u.browserTerminationEventReqInfo.browserTerminationCause = TAPI_SAT_BROWSER_TERMINATED_BY_USER;
523 TapiHandle *handle = NULL;
524 handle = tel_init(NULL);
526 ret = tel_download_sat_event(handle, &event_data, NULL, NULL);
527 if(ret != TAPI_API_SUCCESS && ret != TAPI_API_SAT_EVENT_NOT_REQUIRED_BY_USIM)
528 BROWSER_LOGE("failed to tel_download_sat_event");
533 static void __br_app_terminate(void *app_data)
535 BROWSER_LOGD("[%s]", __func__);
536 struct browser_data *ad = (struct browser_data *)app_data;
538 elm_theme_extension_del(ad->browser_theme, BROWSER_NAVIFRAME_THEME);
539 elm_theme_extension_del(ad->browser_theme, BROWSER_CONTROLBAR_THEME);
540 elm_theme_extension_del(ad->browser_theme, BROWSER_BUTTON_THEME);
541 elm_theme_extension_del(ad->browser_theme, BROWSER_URL_LAYOUT_THEME);
542 elm_theme_extension_del(ad->browser_theme, BROWSER_PROGRESSBAR_THEME);
543 elm_theme_extension_del(ad->browser_theme, BROWSER_PREDICTIVE_HISTORY_THEME);
544 elm_theme_extension_del(ad->browser_theme, BROWSER_SETTINGS_THEME);
545 elm_theme_extension_del(ad->browser_theme, BROWSER_BOOKMARK_THEME);
546 elm_theme_extension_del(ad->browser_theme, BROWSER_FIND_WORD_LAYOUT_THEME);
547 elm_theme_free(ad->browser_theme);
549 /* GCF test requirement */
550 __send_termination_event_to_tapi();
553 evas_object_del(ad->main_win);
555 if (ad->browser_instance)
556 delete ad->browser_instance;
558 BROWSER_LOGD("[Browser-Launching time measure] << __br_app_terminate ends >>");
561 static void __br_app_pause(void *app_data)
563 BROWSER_LOGD("[%s]", __func__);
564 struct browser_data *ad = (struct browser_data *)app_data;
566 if (!ad || !ad->browser_instance)
569 ad->browser_instance->pause();
571 ad->is_paused = EINA_TRUE;
574 static void __br_app_resume(void *app_data)
576 BROWSER_LOGD("[%s]", __func__);
577 struct browser_data *ad = (struct browser_data *)app_data;
579 if (!ad || !ad->browser_instance)
582 ad->browser_instance->resume();
584 ad->is_paused = EINA_FALSE;
587 static void __br_app_reset(service_h service, void *app_data)
589 struct browser_data *ad = (struct browser_data *)app_data;
590 BROWSER_LOGD("[%s]", __func__);
592 ad->browser_instance->reset();
594 __br_load_url(service, app_data);
596 ad->is_paused = EINA_FALSE;
599 int main(int argc, char *argv[])
603 app_event_callback_s ops;
604 memset(&ops, 0x0, sizeof(app_event_callback_s));
606 ops.create = __br_app_create;
607 ops.terminate = __br_app_terminate;
608 ops.pause = __br_app_pause;
609 ops.resume = __br_app_resume;
610 ops.service = __br_app_reset;
611 ops.low_memory = __br_low_memory_cb;
612 ops.low_battery = __br_low_battery_cb;
613 #if defined(HORIZONTAL_UI)
614 ops.device_orientation = __br_rotate_cb;
616 ops.language_changed = __br_lang_changed_cb;
617 ops.region_format_changed = __br_region_changed_cb;
619 struct browser_data ad;
620 memset(&ad, 0x0, sizeof(struct browser_data));
622 int ret = app_efl_main(&argc, &argv, &ops, &ad);