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(AUTO_SAVE_ID_PASSWORD_KEY, false))
105 if (!br_preference_create_bool(AUTO_SAVE_FORM_DATA_KEY, false))
107 if (!br_preference_create_bool(ENABLE_LOCATION_KEY, true))
110 if (!br_preference_create_bool(ZOOM_BUTTON_KEY, true))
116 static Evas_Object *__create_main_win(void *app_data)
118 Evas_Object *window = elm_win_add(NULL, BROWSER_PACKAGE_NAME, ELM_WIN_BASIC);
122 elm_win_title_set(window, BROWSER_PACKAGE_NAME);
123 elm_win_borderless_set(window, EINA_TRUE);
124 elm_win_conformant_set(window, EINA_TRUE);
125 evas_object_smart_callback_add(window, "delete,request",
126 __main_win_del_cb, app_data);
127 ecore_x_window_size_get(ecore_x_window_root_first_get(),
129 evas_object_resize(window, w, h);
130 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
131 evas_object_show(window);
137 static Evas_Object *__create_bg(Evas_Object *win)
140 bg = elm_bg_add(win);
144 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
145 elm_win_resize_object_add(win, bg);
146 evas_object_show(bg);
151 static Evas_Object *__create_main_layout(Evas_Object *win)
154 layout = elm_layout_add(win);
158 if (!elm_layout_theme_set(layout, "layout", "application", "default"))
159 BROWSER_LOGE("elm_layout_theme_set is failed.\n");
161 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
162 elm_win_resize_object_add(win, layout);
163 edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,show,indicator", "elm");
164 evas_object_show(layout);
169 static Evas_Object *__create_navi_bar(void *app_data)
171 BROWSER_LOGD("[%s]", __func__);
172 Evas_Object *navi_bar;
173 struct browser_data *ad = (struct browser_data *)app_data;
174 navi_bar = elm_naviframe_add(ad->main_layout);
176 elm_object_theme_set(navi_bar, ad->browser_theme);
177 elm_object_style_set(navi_bar, "browser");
178 elm_object_part_content_set(ad->main_layout, "elm.swallow.content", navi_bar);
179 evas_object_show(navi_bar);
185 static Eina_Bool __process_app_service(service_h service, void *app_data)
187 BROWSER_LOGD("[%s]", __func__);
188 struct browser_data *ad = (struct browser_data *)app_data;
190 char *operation = NULL;
191 char *request_uri = NULL;
192 char *request_mime_type = NULL;
194 if (service_get_operation(service, &operation) != SERVICE_ERROR_NONE) {
195 BROWSER_LOGD("get service operation failed");
199 if (service_get_uri(service, &request_uri) != SERVICE_ERROR_NONE) {
200 BROWSER_LOGD("get service uri failed");
203 if (service_get_mime(service, &request_mime_type) != SERVICE_ERROR_NONE) {
204 BROWSER_LOGD("get service mime failed");
207 if (!operation && !request_uri && !request_mime_type) {
208 BROWSER_LOGD("Not app svc");
212 BROWSER_LOGD("operation[%s], request_uri[%s], request_mime_type[%s]", operation, request_uri, request_mime_type);
214 std::string full_path;
216 if (request_mime_type) {
217 if (!strncmp(request_mime_type, "application/x-shockwave-flash", strlen("application/x-shockwave-flash"))
218 || !strncmp(request_mime_type, "image/svg+xml", strlen("image/svg+xml"))
219 || !strncmp(request_mime_type, "text/html", strlen("text/html"))
220 || !strncmp(request_mime_type, "application/xml", strlen("application/xml"))) {
222 full_path = std::string(request_uri);
224 BROWSER_LOGD("Not allowed mime type : [%s]", request_mime_type);
227 } else if (request_uri) {
228 full_path = std::string(request_uri);
231 BROWSER_LOGD("url=[%s]", full_path.c_str());
234 elm_win_activate(ad->main_win);
236 ad->browser_instance->launch(full_path.c_str(), EINA_TRUE);
241 static void __br_load_url(service_h service, void *app_data)
243 BROWSER_LOGD("[%s]", __func__);
244 struct browser_data *ad = (struct browser_data *)app_data;
246 if (__process_app_service(service, app_data)) {
247 BROWSER_LOGD("app service");
251 std::string full_path;
252 char *mime_type = NULL;
253 char *search_keyword = NULL;
254 char *goto_url = NULL;
257 if (service_get_uri(service, &url) != SERVICE_ERROR_NONE) {
258 BROWSER_LOGD("get service uri failed");
261 if (service_get_mime(service, &mime_type) != SERVICE_ERROR_NONE) {
262 BROWSER_LOGD("get service mime failed");
265 if (service_get_extra_data(service, "search_keyword", &search_keyword) != SERVICE_ERROR_NONE) {
266 BROWSER_LOGD("get service extra data(search keyword) failed");
269 if (service_get_extra_data(service, "goto_url", &search_keyword) != SERVICE_ERROR_NONE) {
270 BROWSER_LOGD("get service extra data(search keyword) failed");
273 if (mime_type && url) {
274 BROWSER_LOGD("mime type=[%s], url=[%s]", mime_type, url);
275 if (!strcmp(mime_type, "application/x-shockwave-flash")
276 || !strcmp(mime_type, "image/svg+xml")
277 || !strcmp(mime_type, "text/html")
278 || !strcmp(mime_type, "application/xml")) {
279 full_path = std::string(url);
281 } else if (search_keyword) {
282 BROWSER_LOGD("search_keyword=[%s]", search_keyword);
283 if (search_keyword) {
284 char *search_url = NULL;
285 if (br_preference_get_str(SEARCHURL_KEY, &search_url) == false) {
286 BROWSER_LOGE("failed to get %s preference\n", SEARCHURL_KEY);
290 full_path = std::string(search_url) + std::string(search_keyword);
294 } else if (goto_url || url) {
295 BROWSER_LOGD("goto_url=[%s], url=[%s]", goto_url, url);
297 full_path = goto_url;
301 BROWSER_LOGD("url=[%s]", full_path.c_str());
304 elm_win_activate(ad->main_win);
306 ad->browser_instance->launch(full_path.c_str(), EINA_TRUE);
309 static Eina_Bool __br_keydown_event(void *data, int type, void *event)
311 BROWSER_LOGD("[%s]", __func__);
312 Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
314 if (!strcmp(ev->keyname, KEY_END)) {
321 #if defined(HORIZONTAL_UI)
322 static void __br_rotate_cb(app_device_orientation_e mode, void *data)
324 BROWSER_LOGD("[%s] rotation mode = %d", __func__, mode);
325 struct browser_data *ad = (struct browser_data *)data;
329 case APP_DEVICE_ORIENTATION_0:
331 ug_send_event(UG_EVENT_ROTATE_PORTRAIT);
333 case APP_DEVICE_ORIENTATION_90:
335 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN);
337 case APP_DEVICE_ORIENTATION_180:
338 rotation_value = 180;
339 ug_send_event(UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN);
341 case APP_DEVICE_ORIENTATION_270:
342 rotation_value = 270;
343 ug_send_event(UG_EVENT_ROTATE_LANDSCAPE);
350 if (rotation_value >= 0 && ad->browser_instance) {
351 if (ad->browser_instance->is_available_to_rotate()) {
352 elm_win_rotation_with_resize_set(ad->main_win, rotation_value);
353 ad->browser_instance->rotate(rotation_value);
359 static void __br_low_memory_cb(void* data)
361 BROWSER_LOGD("[%s]", __func__);
363 struct browser_data *ad = (struct browser_data *)data;
365 if (ad && ad->browser_instance)
366 ad->browser_instance->clean_up_windows();
369 static void __br_low_battery_cb(void* data)
371 BROWSER_LOGD("[%s]", __func__);
376 static void __br_lang_changed_cb(void *data)
378 BROWSER_LOGD("[%s]", __func__);
383 static void __br_region_changed_cb(void *data)
385 BROWSER_LOGD("[%s]", __func__);
390 static void __br_register_system_event(void *app_data)
393 struct browser_data *ad = (struct browser_data *)app_data;
396 static int __browser_set_i18n(const char *domain, const char *dir)
400 if (domain == NULL) {
401 BROWSER_LOGE("domain is NULL");
405 r = setlocale(LC_ALL, "");
407 /* if locale is not set properly, try again to set as language base */
409 char *lang_set = vconf_get_str(VCONFKEY_LANGSET);
410 if (!lang_set && strlen(lang_set) > 0)
411 r = setlocale(LC_ALL, lang_set);
413 BROWSER_LOGE("setlocale as [%s]", r);
419 BROWSER_LOGE("setlocale failed");
423 r = bindtextdomain(domain, dir);
425 BROWSER_LOGE("bindtextdomain failed");
429 r = textdomain(domain);
431 BROWSER_LOGE("textdomain failed");
438 static bool __br_app_create(void *app_data)
440 BROWSER_LOGD("[Browser-Launching time measure] << theme extenstion >>");
441 struct browser_data *ad = (struct browser_data *)app_data;
443 elm_config_preferred_engine_set("opengl_x11");
445 if(!__init_preference())
448 ad->browser_theme = elm_theme_new();
449 elm_theme_ref_set(ad->browser_theme, NULL);
450 elm_theme_extension_add(ad->browser_theme, BROWSER_NAVIFRAME_THEME);
451 elm_theme_extension_add(ad->browser_theme, BROWSER_CONTROLBAR_THEME);
452 elm_theme_extension_add(ad->browser_theme, BROWSER_BUTTON_THEME);
453 elm_theme_extension_add(ad->browser_theme, BROWSER_PROGRESSBAR_THEME);
454 elm_theme_extension_add(ad->browser_theme, BROWSER_URL_LAYOUT_THEME);
455 elm_theme_extension_add(ad->browser_theme, BROWSER_PREDICTIVE_HISTORY_THEME);
456 elm_theme_extension_add(ad->browser_theme, BROWSER_SETTINGS_THEME);
457 elm_theme_extension_add(ad->browser_theme, BROWSER_BOOKMARK_THEME);
458 elm_theme_extension_add(ad->browser_theme, BROWSER_FIND_WORD_LAYOUT_THEME);
460 BROWSER_LOGD("[Browser-Launching time measure] << create main window >>");
461 ad->main_win = __create_main_win(ad);
463 BROWSER_LOGE("fail to create window");
467 BROWSER_LOGD("[Browser-Launching time measure] << create background >>");
468 ad->bg = __create_bg(ad->main_win);
470 BROWSER_LOGE("fail to create bg");
474 BROWSER_LOGD("[Browser-Launching time measure] << create layout main >>");
475 ad->main_layout = __create_main_layout(ad->main_win);
476 if (!ad->main_layout) {
477 BROWSER_LOGE("fail to create main layout");
481 ad->navi_bar = __create_navi_bar(ad);
483 BROWSER_LOGE("fail to create navi bar");
487 /* create browser instance & init */
488 ad->browser_instance = new(nothrow) Browser_Class(ad->main_win, ad->navi_bar, ad->bg);
489 if (!ad->browser_instance) {
490 BROWSER_LOGE("fail to Browser_Class");
493 if (ad->browser_instance->init() == EINA_FALSE) {
494 BROWSER_LOGE("fail to browser init");
498 /* init internationalization */
499 int ret = __browser_set_i18n(BROWSER_PACKAGE_NAME, BROWSER_LOCALE_DIR);
501 BROWSER_LOGE("fail to __browser_set_i18n");
505 #if defined(HORIZONTAL_UI)
506 app_device_orientation_e rotation_value = app_get_device_orientation();
508 if (rotation_value != APP_DEVICE_ORIENTATION_0) {
509 elm_win_rotation_with_resize_set(ad->main_win, rotation_value);
510 ad->browser_instance->rotate(rotation_value);
517 /* GCF test requirement */
518 static void __send_termination_event_to_tapi(void)
520 BROWSER_LOGD("[%s]", __func__);
521 int ret = TAPI_API_SUCCESS;
523 TelSatEventDownloadReqInfo_t event_data;
524 event_data.eventDownloadType = TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION;
525 event_data.u.browserTerminationEventReqInfo.browserTerminationCause = TAPI_SAT_BROWSER_TERMINATED_BY_USER;
527 TapiHandle *handle = NULL;
528 handle = tel_init(NULL);
530 ret = tel_download_sat_event(handle, &event_data, NULL, NULL);
531 if(ret != TAPI_API_SUCCESS && ret != TAPI_API_SAT_EVENT_NOT_REQUIRED_BY_USIM)
532 BROWSER_LOGE("failed to tel_download_sat_event");
537 static void __br_app_terminate(void *app_data)
539 BROWSER_LOGD("[%s]", __func__);
540 struct browser_data *ad = (struct browser_data *)app_data;
542 elm_theme_extension_del(ad->browser_theme, BROWSER_NAVIFRAME_THEME);
543 elm_theme_extension_del(ad->browser_theme, BROWSER_CONTROLBAR_THEME);
544 elm_theme_extension_del(ad->browser_theme, BROWSER_BUTTON_THEME);
545 elm_theme_extension_del(ad->browser_theme, BROWSER_URL_LAYOUT_THEME);
546 elm_theme_extension_del(ad->browser_theme, BROWSER_PROGRESSBAR_THEME);
547 elm_theme_extension_del(ad->browser_theme, BROWSER_PREDICTIVE_HISTORY_THEME);
548 elm_theme_extension_del(ad->browser_theme, BROWSER_SETTINGS_THEME);
549 elm_theme_extension_del(ad->browser_theme, BROWSER_BOOKMARK_THEME);
550 elm_theme_extension_del(ad->browser_theme, BROWSER_FIND_WORD_LAYOUT_THEME);
551 elm_theme_free(ad->browser_theme);
553 /* GCF test requirement */
554 __send_termination_event_to_tapi();
557 evas_object_del(ad->main_win);
559 if (ad->browser_instance)
560 delete ad->browser_instance;
562 BROWSER_LOGD("[Browser-Launching time measure] << __br_app_terminate ends >>");
565 static void __br_app_pause(void *app_data)
567 BROWSER_LOGD("[%s]", __func__);
568 struct browser_data *ad = (struct browser_data *)app_data;
570 if (!ad || !ad->browser_instance)
573 ad->browser_instance->pause();
575 ad->is_paused = EINA_TRUE;
578 static void __br_app_resume(void *app_data)
580 BROWSER_LOGD("[%s]", __func__);
581 struct browser_data *ad = (struct browser_data *)app_data;
583 if (!ad || !ad->browser_instance)
586 ad->browser_instance->resume();
588 ad->is_paused = EINA_FALSE;
591 static void __br_app_reset(service_h service, void *app_data)
593 struct browser_data *ad = (struct browser_data *)app_data;
594 BROWSER_LOGD("[%s]", __func__);
596 ad->browser_instance->reset();
598 __br_load_url(service, app_data);
600 ad->is_paused = EINA_FALSE;
603 int main(int argc, char *argv[])
607 app_event_callback_s ops;
608 memset(&ops, 0x0, sizeof(app_event_callback_s));
610 ops.create = __br_app_create;
611 ops.terminate = __br_app_terminate;
612 ops.pause = __br_app_pause;
613 ops.resume = __br_app_resume;
614 ops.service = __br_app_reset;
615 ops.low_memory = __br_low_memory_cb;
616 ops.low_battery = __br_low_battery_cb;
617 #if defined(HORIZONTAL_UI)
618 ops.device_orientation = __br_rotate_cb;
620 ops.language_changed = __br_lang_changed_cb;
621 ops.region_format_changed = __br_region_changed_cb;
623 struct browser_data ad;
624 memset(&ad, 0x0, sizeof(struct browser_data));
626 int ret = app_efl_main(&argc, &argv, &ops, &ad);