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 #define _DEFAULT_SOURCE
8 #include <Ecore_Evas.h>
9 #include <Ecore_File.h>
10 #include <Ecore_Getopt.h>
11 #include "ecore_x_wayland_wrapper.h"
13 #include <Elementary.h>
16 #include <device/haptic.h>
23 #include "public/EWebKit.h"
24 #include "public/EWebKit_internal.h"
25 #include "public/EWebKit_product.h"
26 #include "tizen/system_info.h"
28 static Ecore_Evas* ee;
30 static Evas_Object* view;
31 static Evas_Object *popup;
33 uint64_t current_notification_id;
35 static Ewk_Auth_Challenge* auth_challenge_holder = NULL;
36 static Evas_Object* credentials[2] = {0};//username and password
38 static Eina_Bool fullscreen_enabled;
39 static Eina_Bool clear_cache;
40 static Eina_Bool disable_cache = EINA_FALSE;
41 static char* pdf_filename = NULL;
42 static char* cache_policy = NULL;
43 static char* content_security_policy = NULL;
44 static char* content_security_policy_type = NULL;
45 static char* start_url = NULL;
46 static int content_text_callback_data = 10;
47 static int content_text_callback_data_1 = 20;
48 static Eina_Bool test_cookie;
49 static Eina_Bool clear_cookie_called;
50 static Ewk_Cookie_Accept_Policy set_cookie_policy;
51 static Eina_List* application_cache_origins = NULL;
52 static Eina_List* web_database_origins = NULL;
55 static haptic_device_h g_haptic_handle;
56 static Ecore_Timer *g_haptic_timer_id;
57 static haptic_effect_h g_haptic_effect;
60 static void show_userid_password_popup(const char* msg);
61 static void show_search_popup(void);
62 static void on_mouse_up(void* data, Evas* canvas, Evas_Object* obj, void* event_info);
63 static void __search_closed_cb(void *data, Evas_Object *obj, void *event_info);
64 static void __search_focused_cb(void *data, Evas_Object *obj, void *event_info);
65 static void __search_unfocused_cb(void *data, Evas_Object *obj, void *event_info);
66 static void __search_clicked_cb(void *data, Evas_Object *obj, void *event_info);
67 static void __auth_login_button_cb(void *data, Evas_Object *obj, void *event_info);
68 static void __auth_close_button_cb(void *data, Evas_Object *obj, void *event_info);
69 static void __load_finished_cb(void *data, Evas_Object *obj, void *event_info);
70 static void __load_error_cb(void *data, Evas_Object *obj, void *event_info);
71 static void __uri_changed_cb(void *data, Evas_Object *obj, void *event_info);
72 static void __title_changed_cb(void *data, Evas_Object *obj, void *event_info);
73 static void __load_progress_cb(void *data, Evas_Object *obj, void *event_info);
74 static void __load_progress_started_cb(void *data, Evas_Object *obj, void *event_info);
75 static void __load_progress_finished_cb(void *data, Evas_Object *obj, void *event_info);
76 static void __ime_input_panel_show_cb(void* data, Evas_Object *obj, void* event_info);
77 static void __ime_input_panel_hide_cb(void* data, Evas_Object *obj, void* event_info);
78 static void __ime_candidate_panel_show_cb(void* data, Evas_Object *obj, void* event_info);
79 static void __ime_candidate_panel_hide_cb(void* data, Evas_Object *obj, void* event_info);
80 static void __create_window_cb(void *data, Evas_Object *obj, void *event_info);
81 static void __window_closed_cb(void *data, Evas_Object *obj, void *event_info);
82 static void __imf_input_method_changed_cb(void *data, Evas_Object *obj, void *event_info);
83 static void __did_start_provisional_load_for_frame_cb(void *data, Evas_Object *obj, void *event_info);
84 static void __did_commit_load_for_frame(void *data, Evas_Object *obj, void *event_info);
85 static void __geoLocation_popup_display_cb(void *data, Evas_Object *obj, void *event_info);
86 void __script_executed_cb(Evas_Object *obj, const char *javascript_result, void *data);
87 static void __auth_challenge_cb(void* data, Evas_Object *obj, void *event_info);
88 static void __policy_response_decide_cb(void *data, Evas_Object *obj, void *event_info);
89 static void __customize_context_menu_cb(void* data, Evas_Object *obj, void *event_info);
90 static void __customize_context_menu_item_selected_cb(void* data, Evas_Object *obj, void *event_info);
91 static void __usermedia_permission_request_cb(void *data, Evas_Object *obj, void *event_info);
92 static void __navigation_policy_decide_cb(void *data, Evas_Object *obj, void *event_info);
93 static void __text_found_cb(void *data, Evas_Object *obj, void *event_info);
94 static void __newwindow_policy_cb(void *data, Evas_Object *obj, void* policy);
95 static void __load_nonemptylayout_finished_cb(void* data, Evas_Object *obj, void *event_info);
96 static void __popup_wait_start_cb(void *data, Evas_Object *obj, void* policy);
97 static void __popup_wait_finish_cb(void *data, Evas_Object *obj, void* policy);
98 static void __edge_left_cb(void* data, Evas_Object* obj, void* event_info);
99 static void __edge_right_cb(void* data, Evas_Object* obj, void* event_info);
100 static void __edge_top_cb(void* data, Evas_Object* obj, void* event_info);
101 static void __edge_bottom_cb(void* data, Evas_Object* obj, void* event_info);
102 static void __hit_test_request_cb(Evas_Object* o, int x, int y, int hit_test_mode, Ewk_Hit_Test*, void* user_data);
103 static void __webprocess_crashed_cb(void* data, Evas_Object* obj, void* event_info);
105 static void on_evas_resize(Ecore_Evas*);
106 static void __notification_show_cb(Ewk_Notification*, void* event_info);
107 static Eina_Bool __notification_permission_cb(Evas_Object*, Ewk_Notification_Permission_Request*, void*);
108 static void __notification_cancel_cb(uint64_t notification_id, void* event_info);
109 static void __notification_cancel_byuser_cb(void *data, Evas_Object *obj, void *event_info);
110 static void __download_callback(const char*download_url, void* user_data);
111 static void __frame_rendered_cb(void* data, Evas_Object* obj, void* event_info);
112 static void __ewk_view_plain_text_get_cb(Evas_Object* o, const char* content_text, void* user_data);
113 static void __ewk_view_plain_text_get_cb_1(Evas_Object* o, const char* content_text, void* user_data);
114 static void __load_started_cb(void *data, Evas_Object *obj, void *event_info);
115 static void __ewk_cookie_manager_async_policy_get_cb(
116 Ewk_Cookie_Accept_Policy policy, void *event_info);
117 static void __ewk_cookie_manager_async_hostnames_get_cb(Eina_List *hostnames, Ewk_Error *error, void *event_info);
118 static void __back_forward_list_changed_cb(void *data, Evas_Object *obj, void *event_info);
119 static Eina_Bool __mime_override_cb(const char* url, const char *mime, char **new_mime, void* user_data);
120 static void __console_message_cb(void *data, Evas_Object *obj, void *event_info);
122 #if defined(OS_TIZEN)
123 static Eina_Bool __vibration_timeout_cb(void *data);
124 static void __vibration_on_cb(uint64_t vibration_time, void *data);
125 static void __vibration_off_cb(void *data);
128 static void __undo_size_cb(void* data, Evas_Object* obj, void* event_info);
129 static void __redo_size_cb(void* data, Evas_Object* obj, void* event_info);
130 void __mhtml_save_cb(Evas_Object *obj, const char *mhtml_data, void *data);
131 static void __clipboard_opened_cb(void* data, Evas_Object* view, void* event_info);
132 static Eina_Bool __ewk_view_javascript_alert_cb(Evas_Object* o, const char* alert_text, void* user_data);
133 static Eina_Bool __ewk_view_javascript_confirm_cb(Evas_Object* o, const char* message, void* user_data);
134 static Eina_Bool __ewk_view_javascript_prompt_cb(Evas_Object* o, const char* message, const char* default_value, void* user_data);
137 FOR_TEST_APPLICATION_CACHE_RUN = EWK_CONTEXT_MENU_ITEM_BASE_APPLICATION_TAG + 1,
138 FOR_TEST_APPLICATION_CACHE_DELETE_ALL,
139 FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR,
140 FOR_TEST_GRAB_SNAPSHOT,
141 FOR_TEST_WEB_DATABASE_GET_ORIGINS,
142 FOR_TEST_WEB_DATABASE_DELETE_ALL
143 // New context menu items can be added here
146 static const Ecore_Getopt options = {
147 .prog = "efl_webview_app",
148 .usage = "%prog [options] [url]",
149 .strict = EINA_FALSE,
151 ECORE_GETOPT_STORE_DEF_BOOL('F', "full-screen", "start in full-screen", EINA_TRUE),
152 ECORE_GETOPT_STORE_DEF_BOOL('c', "clear-cache", "clear cache on every page load finished", EINA_TRUE),
153 ECORE_GETOPT_STORE_DEF_BOOL('k', "test-cookie", "test cookie on every page load finished", EINA_TRUE),
154 ECORE_GETOPT_STORE_DEF_STR('s', "set-cache-policy", "set cache policy", "viewer"),
155 ECORE_GETOPT_STORE_DEF_STR('p', "set-content-security-policy", "set content security policy", NULL),
156 ECORE_GETOPT_STORE_DEF_STR('t', "content-security-policy-type",
157 "Type of content security policy only applicable if policy is defined",
159 ECORE_GETOPT_STORE_DEF_BOOL('d', "disable-cache", "Disable network cache", EINA_FALSE),
160 ECORE_GETOPT_STORE_DEF_STR('w', "save-pdf", "Save as PDF", "webpage.pdf"),
161 ECORE_GETOPT_SENTINEL,
165 static Eina_Bool _util_print_hit_test_result_hash_fn(const Eina_Hash *hash, const void *key, void *data, void *fdata)
167 printf("HitTest attribute (%s): (%s)\n", (const char*)key, (char *)data);
172 static void on_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
174 Evas_Event_Key_Down *ev = (Evas_Event_Key_Down*) event_info;
175 static int scroll_x = 0;
176 static int scroll_y = 0;
178 if (strcmp(ev->key, "XF86Back") == 0 || strcmp(ev->key, "XF86Stop") == 0)
180 if (ewk_view_text_selection_clear(view))
184 if (!strcmp(ev->key, "F1")) {
185 fprintf(stderr, "[on_key_down] (F1) pressed. Go to wikipedia.com\n");
186 ewk_view_url_set(view, "http://www.wikipedia.com/");
188 else if (!strcmp(ev->key, "F2")) {
189 double level = ewk_view_text_zoom_get(view) + 0.1;
190 ewk_view_text_zoom_set(view, level);
191 printf("current text zoom level %lf\n", ewk_view_text_zoom_get(view));
193 else if (!strcmp(ev->key, "F3")) {
194 double level = ewk_view_text_zoom_get(view) - 0.1;
195 ewk_view_text_zoom_set(view, level);
196 printf("current text zoom level %lf\n", ewk_view_text_zoom_get(view));
198 else if (!strcmp(ev->key, "F4")) {
199 ewk_view_command_execute(view, "Undo", NULL);
201 else if (!strcmp(ev->key, "F5")) {
202 printf("selection text \"%s\"\n", ewk_view_text_selection_text_get(view));
204 else if (!strcmp(ev->key, "F6")) {
207 else if (!strcmp(ev->key, "F7")) {
208 static Eina_Bool visibility = EINA_TRUE;
209 visibility = !visibility;
210 ewk_view_visibility_set(view, visibility);
212 else if (!strcmp(ev->key, "F8")) {
213 ewk_view_contents_set(view, "ewk Data Set API Test!!!!", 25, "text/plain", NULL, "http://www.naver.com");
215 else if (!strcmp(ev->key, "F9")) {
218 ewk_view_scroll_pos_get(view, &x, &y);
219 printf("scroll_pos_get %d, %d \n",x,y);
221 else if (!strcmp(ev->key, "F10")) {
222 if (!(ewk_view_plain_text_get(view, __ewk_view_plain_text_get_cb, &content_text_callback_data)))
223 printf("\nEWK_VIEW_PLAIN_TEXT_GET FAILURE\n");
225 printf("\nEWK_VIEW_PLAIN_TEXT_GET SUCCESS\n");
226 if (!(ewk_view_plain_text_get(view, __ewk_view_plain_text_get_cb_1, &content_text_callback_data_1)))
227 printf("\nEWK_VIEW_PLAIN_TEXT_GET_1 FAILURE\n");
229 printf("\nEWK_VIEW_PLAIN_TEXT_GET_1 SUCCESS\n");
231 else if (!strcmp(ev->key, "F11")) {
232 ewk_view_command_execute(view, "Redo", NULL);
234 else if (evas_key_modifier_is_set(ev->modifiers, "Control")) {
235 if (!strcmp(ev->key, "f") || !strcmp(ev->key, "F"))
237 else if (!strcmp(ev->key, "s") || !strcmp(ev->key, "S"))
238 ewk_view_mhtml_data_get(view, __mhtml_save_cb, NULL);
240 else if (!strcmp(ev->key, "w") || !strcmp(ev->key, "W")) {
243 ewk_view_scroll_set(view, scroll_x, scroll_y);
244 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
247 else if (!strcmp(ev->key, "s") || !strcmp(ev->key, "S")) {
249 ewk_view_scroll_set(view, scroll_x, scroll_y);
250 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
252 else if (!strcmp(ev->key, "d") || !strcmp(ev->key, "D")) {
254 ewk_view_scroll_set(view, scroll_x, scroll_y);
255 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
257 else if (!strcmp(ev->key, "a") || !strcmp(ev->key, "A")) {
260 ewk_view_scroll_set(view, scroll_x, scroll_y);
261 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
264 else if (!strcmp(ev->key, "BackSpace") || !strcmp(ev->key, "XF86Back") ||
265 !strcmp(ev->key, "XF86Stop")) {
270 static void on_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info)
272 Evas_Event_Mouse_Wheel* event = (Evas_Event_Mouse_Wheel*)event_info;
273 static double scale_factor = 1.0;
275 if (evas_key_modifier_is_set(event->modifiers, "Control"))
282 printf("ewk_view_scale_set() : %lf (%d, %d)\n", scale_factor, event->output.x, event->output.y);
284 ewk_view_scale_set(view, scale_factor, event->output.x, event->output.y);
288 static Eina_Strbuf* create_url_with_scheme(const char* base_url, const char* scheme)
290 Eina_Strbuf* buffer = eina_strbuf_new();
291 eina_strbuf_append(buffer, scheme);
292 eina_strbuf_append(buffer, base_url);
296 static void set_url_from_user_input(Evas_Object* view, const char* url)
298 if (strstr(url, "://")) {
299 ewk_view_url_set(view, url);
304 Eina_Strbuf* full_url;
305 if (ecore_file_exists(url)) {
306 char* realpath = ecore_file_realpath(url);
307 full_url = create_url_with_scheme(realpath, "file://");
310 full_url = create_url_with_scheme(url, "http://");
313 ewk_view_url_set(view, eina_strbuf_string_get(full_url));
315 eina_strbuf_free(full_url);
318 //set cache policy as per command line arguments
319 static void set_cache_policy(Ewk_Context* context)
322 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
325 if (!strcmp(cache_policy, "browser"))
326 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_DOCUMENT_BROWSER);
327 else if (!strcmp(cache_policy, "webbrowser"))
328 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
329 else if(!strcmp(cache_policy, "viewer"))
330 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
333 static void set_csp(Evas_Object *ewk_view)
335 if(!ewk_view || !content_security_policy_type)
338 if(!strcmp(content_security_policy_type, "report"))
339 ewk_view_content_security_policy_set(ewk_view, content_security_policy, EWK_REPORT_ONLY);
340 else if(!strcmp(content_security_policy_type, "enforce"))
341 ewk_view_content_security_policy_set(ewk_view, content_security_policy, EWK_ENFORCE_POLICY);
344 static void disable_cache_for_context(Ewk_Context* context)
346 ewk_context_cache_disabled_set(context, EINA_TRUE);
349 static void _evas_close_cb(Ecore_Evas* ee)
351 ecore_main_loop_quit();
354 #if defined(OS_TIZEN_TV_PRODUCT)
355 static void _create_mouse_cursor(Evas_Object* window) {
356 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
357 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
358 struct wl_display* display = ecore_wl2_display_get(wl2_display);
359 Eina_Iterator* globals = ecore_wl2_display_globals_get(wl2_display);
360 struct wl_registry* registry = ecore_wl2_display_registry_get(wl2_display);
361 struct wl_seat* seat =
362 ecore_wl2_input_seat_get(ecore_wl2_input_default_input_get(wl2_display));
364 Ecore_Wl2_Global* global;
365 EINA_ITERATOR_FOREACH(globals, global) {
366 if (!strcmp(global->interface, "tizen_cursor"))
367 if (!CursorModule_Initialize(display, registry, seat, global->id))
368 fprintf(stderr, "CursorModule_Initialize() Failed!\n");
370 eina_iterator_free(globals);
372 struct wl_surface* const surface =
373 ecore_wl2_window_surface_get(ecore_evas_wayland2_window_get(
374 ecore_evas_ecore_evas_get(evas_object_evas_get(window))));
377 if (!Cursor_Set_Config(surface, TIZEN_CURSOR_CONFIG_CURSOR_AVAILABLE, NULL))
378 fprintf(stderr, "Cursor_Set_Config() Failed!\n");
379 CursorModule_Finalize();
381 const char* t_cursor = "tizen_cursor";
382 Ecore_Wl_Global* global_data = NULL;
383 unsigned int cursormgr_id = 0;
385 EINA_INLIST_FOREACH(ecore_wl_globals_get(), global_data) {
386 if (0 == strncmp(global_data->interface, t_cursor, strlen(t_cursor))) {
387 cursormgr_id = global_data->id; // to get the id of cursormgr object
392 struct wl_surface* const surface =
393 ecore_wl_window_surface_get(elm_win_wl_window_get(window));
396 const int ret_cursormod = CursorModule_Initialize(
397 ecore_wl_display_get(), ecore_wl_registry_get(),
398 ecore_wl_input_seat_get(ecore_wl_input_get()), cursormgr_id);
400 Cursor_Set_Config(surface, TIZEN_CURSOR_CONFIG_CURSOR_AVAILABLE, NULL);
402 CursorModule_Finalize();
403 #endif // TIZEN_VERSION_AT_LEAST(5, 0, 0)
407 int main(int argc, char** argv)
409 // Make sure this happens just once.
410 // By default the web process is the same program.
411 fprintf(stderr, "efl_webview_app starting...\n");
413 if (IsDesktopProfile()) {
414 fprintf(stderr, "Runtime Profile : DESKTOP\n");
415 } else if (IsMobileProfile()) {
416 fprintf(stderr, "Runtime Profile : MOBILE\n");
417 } else if (IsTvProfile()) {
418 fprintf(stderr, "Runtime Profile : TV\n");
419 } else if (IsWearableProfile()) {
420 fprintf(stderr, "Runtime Profile : WEARABLE\n");
421 } else if (IsIviProfile()) {
422 fprintf(stderr, "Runtime Profile : IVI\n");
423 } else if (IsCommonProfile()) {
424 fprintf(stderr, "Runtime Profile : COMMON\n");
426 fprintf(stderr, "Runtime Profile : UNKNOWN\n");
429 if (IsEmulatorArch()) {
430 fprintf(stderr, "Runtime Architecture : EMULATOR\n");
433 ewk_set_arguments(argc, argv);
434 setenv("ELM_ENGINE", "gl", 1);
439 Ecore_Getopt_Value values[] = {
440 ECORE_GETOPT_VALUE_BOOL(fullscreen_enabled),
441 ECORE_GETOPT_VALUE_BOOL(clear_cache),
442 ECORE_GETOPT_VALUE_BOOL(test_cookie),
443 ECORE_GETOPT_VALUE_STR(cache_policy),
444 ECORE_GETOPT_VALUE_STR(content_security_policy),
445 ECORE_GETOPT_VALUE_STR(content_security_policy_type),
446 ECORE_GETOPT_VALUE_BOOL(disable_cache),
447 ECORE_GETOPT_VALUE_STR(pdf_filename),
448 ECORE_GETOPT_VALUE_NONE,
451 Eina_Bool incognito = EINA_FALSE;
452 int idx = ecore_getopt_parse(&options, values, argc, argv);
453 for (; idx < argc; ++idx) {
454 // Treat first argument not starting with - as the url to load
455 if (argv[idx][0] != '-') {
456 start_url = strdup(argv[idx]);
457 } else if (strcmp(argv[idx], "--incognito") == 0) {
458 incognito = EINA_TRUE;
463 start_url = strdup("http://www.google.com");
466 Ewk_Context* context = NULL;
468 // TODO : ewk content creation for incognito mode also has to be moved here.
469 if (incognito == EINA_FALSE) {
470 context = ewk_context_default_get();
476 #if defined(USE_WAYLAND)
477 ee = ecore_evas_new("wayland_egl", 0, 0, width, height, 0);
479 ee = ecore_evas_new("opengl_x11", 0, 0, width, height, 0);
481 e = ecore_evas_get(ee);
483 ecore_evas_callback_delete_request_set(ee, _evas_close_cb);
485 #if defined(OS_TIZEN)
486 // Ignore fullscreen option, we should always go fullscreen on device.
487 Eina_Bool use_fullscreen = EINA_TRUE;
489 Eina_Bool use_fullscreen = fullscreen_enabled;
492 if (incognito == EINA_TRUE) {
493 fprintf(stderr, "Creating incognito web view\n");
494 view = ewk_view_add_in_incognito_mode(e);
495 context = ewk_view_context_get(view);
497 fprintf(stderr, "Creating normal web view\n");
498 view = ewk_view_add_with_context(e, context);
501 if (use_fullscreen) {
502 ecore_evas_fullscreen_set(ee, EINA_TRUE);
503 // When in fullscreen, we don't need to manually specify the dimensions of
506 evas_object_resize(view, width, height);
509 ecore_evas_callback_resize_set(ee, &on_evas_resize);
511 evas_object_event_callback_add(view, EVAS_CALLBACK_KEY_DOWN, on_key_down, view);
512 evas_object_event_callback_add(view, EVAS_CALLBACK_MOUSE_WHEEL, on_mouse_wheel, view);
513 evas_object_event_callback_add(view, EVAS_CALLBACK_MOUSE_UP , on_mouse_up, 0);
514 evas_object_show(view);
515 evas_object_focus_set(view, EINA_TRUE);
516 set_cache_policy(context);
518 disable_cache_for_context(context);
522 evas_object_smart_callback_add(view, "load,finished", __load_finished_cb, context);
523 evas_object_smart_callback_add(view, "load,error", __load_error_cb, 0);
524 evas_object_smart_callback_add(view, "url,changed", __uri_changed_cb,0);
525 evas_object_smart_callback_add(view, "usermedia,permission,request", __usermedia_permission_request_cb, NULL);
526 evas_object_smart_callback_add(view, "title,changed", __title_changed_cb,0);
527 evas_object_smart_callback_add(view, "load,progress", __load_progress_cb,0);
528 evas_object_smart_callback_add(view, "load,progress,started", __load_progress_started_cb,0);
529 evas_object_smart_callback_add(view, "load,progress,finished", __load_progress_finished_cb,0);
530 evas_object_smart_callback_add(view, "editorclient,ime,opened", __ime_input_panel_show_cb,0);
531 evas_object_smart_callback_add(view, "editorclient,ime,closed", __ime_input_panel_hide_cb,0);
532 evas_object_smart_callback_add(view, "editorclient,candidate,opened", __ime_candidate_panel_show_cb,0);
533 evas_object_smart_callback_add(view, "editorclient,candidate,closed", __ime_candidate_panel_hide_cb,0);
534 evas_object_smart_callback_add(view, "create,window", __create_window_cb, 0);
535 evas_object_smart_callback_add(view, "inputmethod,changed", __imf_input_method_changed_cb, 0);
536 evas_object_smart_callback_add(view, "load,committed", __did_commit_load_for_frame, 0);
537 evas_object_smart_callback_add(view, "load,provisional,started", __did_start_provisional_load_for_frame_cb, 0);
538 evas_object_smart_callback_add(view, "geolocation,permission,request", __geoLocation_popup_display_cb,0);
539 evas_object_smart_callback_add(view, "authentication,challenge", __auth_challenge_cb, 0);
540 evas_object_smart_callback_add(view, "policy,response,decide", __policy_response_decide_cb, 0);
541 evas_object_smart_callback_add(view, "contextmenu,customize", __customize_context_menu_cb, 0);
542 evas_object_smart_callback_add(view, "contextmenu,selected", __customize_context_menu_item_selected_cb, 0);
543 evas_object_smart_callback_add(view, "policy,navigation,decide", __navigation_policy_decide_cb,0);
544 evas_object_smart_callback_add(view, "text,found", __text_found_cb, 0);
545 evas_object_smart_callback_add(view, "policy,newwindow,decide", __newwindow_policy_cb,0);
546 evas_object_smart_callback_add(view, "load,nonemptylayout,finished", __load_nonemptylayout_finished_cb, 0);
547 evas_object_smart_callback_add(view, "popup,reply,wait,start", __popup_wait_start_cb,0);
548 evas_object_smart_callback_add(view, "popup,reply,wait,finish", __popup_wait_finish_cb,0);
549 evas_object_smart_callback_add(view, "clipboard,opened", __clipboard_opened_cb, 0);
550 ewk_context_did_start_download_callback_set(context, __download_callback, NULL);
551 evas_object_smart_callback_add(view, "frame,rendered", __frame_rendered_cb, 0);
552 evas_object_smart_callback_add(view, "load,started", __load_started_cb, context);
553 evas_object_smart_callback_add(view, "edge,left", __edge_left_cb, 0);
554 evas_object_smart_callback_add(view, "edge,right", __edge_right_cb, 0);
555 evas_object_smart_callback_add(view, "edge,top", __edge_top_cb, 0);
556 evas_object_smart_callback_add(view, "edge,bottom", __edge_bottom_cb, 0);
557 evas_object_smart_callback_add(view, "back,forward,list,changed", __back_forward_list_changed_cb, 0);
558 evas_object_smart_callback_add(view, "webprocess,crashed", __webprocess_crashed_cb, 0);
559 evas_object_smart_callback_add(view, "undo,size", __undo_size_cb, 0);
560 evas_object_smart_callback_add(view, "redo,size", __redo_size_cb, 0);
562 ewk_notification_callbacks_set(__notification_show_cb, __notification_cancel_cb, 0);
563 ewk_view_custom_header_add(view, "X-Test-header", "X-Value-1");
565 ewk_view_notification_permission_callback_set(view, __notification_permission_cb, 0);
567 #if defined(OS_TIZEN)
568 if (IsMobileProfile() || IsWearableProfile()) {
569 ewk_context_vibration_client_callbacks_set(context, __vibration_on_cb, __vibration_off_cb, NULL);
573 ewk_context_mime_override_callback_set(context, __mime_override_cb, 0);
574 ewk_view_javascript_alert_callback_set(view, __ewk_view_javascript_alert_cb, 0);
575 ewk_view_javascript_confirm_callback_set(view, __ewk_view_javascript_confirm_cb, 0);
576 ewk_view_javascript_prompt_callback_set(view, __ewk_view_javascript_prompt_cb, 0);
577 evas_object_smart_callback_add(view, "console,message", __console_message_cb, 0);
580 set_cookie_policy = EWK_COOKIE_ACCEPT_POLICY_NEVER;
581 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context),
585 set_url_from_user_input(view, start_url);
588 ewk_view_script_execute(view, "console.log(\"Executed test script\");", __script_executed_cb, 0);
589 ecore_main_loop_begin();
590 ewk_context_unref(context);
591 // deleting view will release context
592 evas_object_del(view);
600 static void on_evas_resize(Ecore_Evas* ee)
603 ecore_evas_geometry_get(ee, NULL, NULL, &width, &height);
604 evas_object_resize(view, width, height);
607 void __ewk_cookie_manager_async_hostnames_get_cb(Eina_List *hostnames, Ewk_Error *error, void *event_info)
609 printf ("APP.C callback called __ewk_cookie_manager_async_hostnames_get_cb \n");
610 int host_count = eina_list_count(hostnames);
611 printf("APP.c total hosts received:%d\n",host_count);
612 if (clear_cookie_called) {
614 printf("APP.C clear cookie call did not delete cookies\n");
616 printf("APP.c all cookies cleared\n");
619 Ewk_Context* context = ewk_context_default_get();
621 printf("APP.C calling ewk_cookie_manager_cookies_clear\n");
622 if (!clear_cookie_called) {
623 clear_cookie_called = EINA_TRUE;
624 printf("APP.c calling ewk_view_get_cookies_for_url:%s\n",ewk_view_get_cookies_for_url(view, start_url));
625 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
626 printf("APP.c calling ewk_cookie_manager_async_hostnames_with_cookies_get\n");
627 ewk_cookie_manager_async_hostnames_with_cookies_get(ewk_context_cookie_manager_get(context),
628 __ewk_cookie_manager_async_hostnames_get_cb,
631 } else if ( EWK_COOKIE_ACCEPT_POLICY_NEVER == set_cookie_policy) {
632 printf("APP.C cookie policy was set to never now going to set accept except third party\n");
633 set_cookie_policy = EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY;
634 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), set_cookie_policy);
635 printf("APP.C Reload called from __ewk_cookie_manager_async_policy_get_cb\n");
636 ewk_view_reload(view);
638 if (!clear_cookie_called)
639 printf("APP.cc cookie count is 0 although policy was to accept\n");
643 const char* printCookiePolicy(Ewk_Cookie_Accept_Policy policy)
646 case EWK_COOKIE_ACCEPT_POLICY_ALWAYS :
647 return (" Accept Always ");
648 case EWK_COOKIE_ACCEPT_POLICY_NEVER :
649 return (" Accept Never ");
650 case EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY :
651 return (" No third party ");
656 void __ewk_cookie_manager_async_policy_get_cb(Ewk_Cookie_Accept_Policy policy,
658 printf ("APP.C callback called __ewk_cookie_manager_async_policy_get_cb \n");
659 if (set_cookie_policy != policy) {
660 printf("error in setting cookie policy");
663 Ewk_Context* context = ewk_context_default_get();
664 printf("APP.C cookie policy is set properly:%s\n", printCookiePolicy(policy));
665 printf("APP.c calling ewk_cookie_manager_async_hostnames_with_cookies_get\n");
666 ewk_cookie_manager_async_hostnames_with_cookies_get(ewk_context_cookie_manager_get(context),
667 __ewk_cookie_manager_async_hostnames_get_cb,
672 void __load_finished_cb(void *data, Evas_Object *obj, void *event_info)
674 printf ("APP.C callback called __load_finished_cb \n");
677 ewk_context_cache_clear((Ewk_Context*)data);
680 printf("calling get cookie policy async\n");
681 Ewk_Context* context = ewk_context_default_get();
682 ewk_cookie_manager_accept_policy_async_get(
683 ewk_context_cookie_manager_get(context),
684 __ewk_cookie_manager_async_policy_get_cb,
690 void __load_error_cb(void *data, Evas_Object *obj, void *event_info)
692 Ewk_Error* error = (Ewk_Error*)event_info;
693 printf("APP.C callback called __load_error_cb\n");
694 printf("error url : %s\n", ewk_error_url_get(error));
697 void __uri_changed_cb(void *data, Evas_Object *obj, void *event_info)
699 printf ("APP.C callback called __uri_changed_cb URI is = %s \n", (const char *)event_info);
702 void __title_changed_cb(void *data, Evas_Object *obj, void *event_info)
704 printf ("APP.C callback called __title_changed_cb URI is = %s \n", (const char *)event_info);
707 void __load_progress_cb(void *data, Evas_Object *obj, void *event_info)
709 printf ("APP.C callback called __load_progress_cb value is = %f \n", *((double *)event_info));
712 void __load_progress_started_cb(void *data, Evas_Object *obj, void *event_info)
714 printf ("APP.C callback called __load_progress_started_cb \n");
717 void __load_progress_finished_cb(void *data, Evas_Object *obj, void *event_info)
719 printf ("APP.C callback called __load_progress_finsihed_cb \n");
720 ewk_view_custom_header_remove(view, "X-Test-header");
723 ewk_view_contents_size_get(view, &width, &height);
724 printf("APP.c called ewk_view_contents_size_get. width = %d, height = %d\n", width, height);
725 ewk_view_scroll_size_get(view, &width, &height);
726 printf("APP.c called ewk_view_scroll_size_get. width = %d, height = %d\n", width, height);
727 printf("APP.c called ewk_view_load_progress_get : %f3\n", ewk_view_load_progress_get(obj));
728 printf("APP.c called ewk_view_title_get : %s\n", ewk_view_title_get(view));
731 void __ime_input_panel_show_cb(void* data, Evas_Object *obj, void* event_info)
733 printf ("APP.C callback called __ime_input_panel_show_cb \n");
736 void __ime_input_panel_hide_cb(void* data, Evas_Object *obj, void* event_info)
738 printf ("APP.C callback called __ime_input_panel_hide_cb \n");
741 void __ime_candidate_panel_show_cb(void* data, Evas_Object *obj, void* event_info)
743 printf ("APP.C callback called __ime_candidate_panel_show_cb \n");
746 void __ime_candidate_panel_hide_cb(void* data, Evas_Object *obj, void* event_info)
748 printf ("APP.C callback called __ime_candidate_panel_hide_cb \n");
751 void delete_popup_window(Ecore_Evas* ee)
756 void __create_window_cb(void *data, Evas_Object *obj, void *event_info)
758 printf ("APP.C callback called __create_window_cb \n");
760 // We have no information about preferred size with the current API.
761 const int default_width = 300;
762 const int default_height = 400;
764 #if defined(USE_WAYLAND)
765 Ecore_Evas* ee = ecore_evas_new("wayland_egl", 0, 0, default_width, default_height, 0);
767 Ecore_Evas* ee = ecore_evas_new("opengl_x11", 0, 0, default_width, default_height, 0);
769 Evas* e = ecore_evas_get(ee);
771 Evas_Object* view = ewk_view_add(e);
772 evas_object_resize(view, default_width, default_height);
773 evas_object_show(view);
774 evas_object_focus_set(view, EINA_TRUE);
777 evas_object_smart_callback_add(view, "close,window", __window_closed_cb, 0);
779 // Override default handler because it terminates the event loop.
780 ecore_evas_callback_delete_request_set(ee, delete_popup_window);
782 Evas_Object** result = (Evas_Object**) event_info;
786 void __window_closed_cb(void *data, Evas_Object *view, void *event_info)
788 printf ("APP.C callback called __close_window_cb \n");
790 Evas* e = evas_object_evas_get(view);
791 Ecore_Evas* ee = ecore_evas_ecore_evas_get(e);
792 evas_object_hide(view);
793 evas_object_focus_set(view, EINA_FALSE);
794 evas_object_del(view);
796 ecore_evas_ews_delete_request(ee);
799 void __imf_input_method_changed_cb(void *data, Evas_Object *obj, void *event_info)
801 Eina_Rectangle *rect = (Eina_Rectangle*)event_info;
802 printf ("APP.C callback called __imf_input_method_changed_cb Rect values are x = %d, y= %d, height = %d, width = %d\n",
803 rect->x, rect->y, rect->h, rect->w);
806 void __script_executed_cb(Evas_Object *obj, const char *javascript_result, void *data)
808 printf ("APP.C callback called __script_executed_cb called with result : %s\n", javascript_result);
811 void __did_start_provisional_load_for_frame_cb(void *data, Evas_Object *obj, void *event_info)
813 printf ("APP.C callback called __did_start_provisional_load_for_frame_cb \n");
816 void __did_commit_load_for_frame(void *data, Evas_Object *obj, void *event_info)
818 printf ("APP.C callback called __did_commit_load_for_frame \n");
821 void __geoLocation_popup_display_cb(void *data, Evas_Object *obj, void *event_info)
823 Ewk_Geolocation_Permission_Request *request = (Ewk_Geolocation_Permission_Request*)event_info;
825 const Ewk_Security_Origin * sec_origin = ewk_geolocation_permission_request_origin_get((const Ewk_Geolocation_Permission_Request*)request);
827 printf("APP.C callback called __geoLocation_popup_display_cb URL = %s, protocol = %s, port = %d\n",
828 ewk_security_origin_host_get(sec_origin), ewk_security_origin_protocol_get(sec_origin),ewk_security_origin_port_get(sec_origin));
829 printf ("APP.C callback called __geoLocation_popup_display_cb Setting permission\n");
830 ewk_geolocation_permission_request_set(request, 1);
833 printf ("APP.C callback called __geoLocation_popup_display_cb \n");
836 void __navigation_policy_decide_cb(void *data, Evas_Object *obj, void *event_info)
838 Ewk_Policy_Decision* decision = (Ewk_Policy_Decision*)event_info;
839 printf("APP.C callback called __navigation_policy_decide_cb \n");
840 printf("URL: %s\n", ewk_policy_decision_url_get(decision));
841 printf("Navigation type: %d", ewk_policy_decision_navigation_type_get(decision));
843 // download needs to be handled and ignore wont have any visible difference.
844 printf("Decision: USE\n");
845 ewk_policy_decision_use(decision);
848 void __auth_challenge_cb(void* data, Evas_Object *obj, void *event_info)
850 printf("APP.C callback called __auth_challenge_cb \n");
851 Ewk_Auth_Challenge* auth_challenge = (Ewk_Auth_Challenge*)event_info;
852 auth_challenge_holder = auth_challenge;
854 fprintf(stderr, "auth_challenge NULL\n");
856 const char* realm = ewk_auth_challenge_realm_get(auth_challenge);
857 const char* url = ewk_auth_challenge_url_get(auth_challenge);
859 fprintf(stderr, "realm or url NULL\n");
861 ewk_auth_challenge_suspend(auth_challenge);
862 show_userid_password_popup(url);
865 void show_userid_password_popup(const char* msg)
867 Evas_Object *popup = elm_win_util_standard_add("auth-window", msg);
869 fprintf(stderr,"Pop-up window creation failed");
872 elm_win_modal_set(popup, EINA_TRUE);
873 evas_object_size_hint_weight_set(popup , EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
874 evas_object_size_hint_align_set(popup , EVAS_HINT_FILL, EVAS_HINT_FILL);
875 evas_object_resize(popup, 400, 300);
876 evas_object_show(popup);
878 Evas_Object* box = elm_box_add(popup);
879 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
880 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
881 elm_win_resize_object_add(popup, box);
882 evas_object_show(box);
884 Evas_Object *user_name_lable = elm_label_add(popup);
885 elm_object_text_set(user_name_lable, "User name");
886 elm_box_pack_end(box, user_name_lable);
887 evas_object_show(user_name_lable);
889 Evas_Object *user_name_entry = elm_entry_add(popup);
890 elm_entry_single_line_set(user_name_entry, EINA_TRUE);
891 elm_object_text_set(user_name_entry, "Delete this and enter user name");
892 elm_object_focus_set(user_name_entry, EINA_TRUE);
893 elm_box_pack_end(box, user_name_entry);
894 evas_object_show(user_name_entry);
896 Evas_Object *password_lable = elm_label_add(popup);
897 elm_object_text_set(password_lable, "Password");
898 elm_box_pack_end(box, password_lable);
899 evas_object_show(password_lable);
901 Evas_Object *password_entry = elm_entry_add(popup);
902 elm_entry_single_line_set(password_entry, EINA_TRUE);
903 elm_entry_password_set(password_entry, EINA_TRUE);
904 elm_box_pack_end(box, password_entry);
905 evas_object_show(password_entry);
907 credentials[0] = user_name_entry;
908 credentials[1] = password_entry;
910 Evas_Object *login_button = elm_button_add(popup);
911 elm_object_text_set(login_button, "Login");
912 elm_box_pack_end(box, login_button);
913 evas_object_show(login_button);
915 evas_object_smart_callback_add(popup, "delete,request", __auth_close_button_cb, 0);
916 evas_object_smart_callback_add(login_button, "clicked", __auth_login_button_cb, popup);
919 void show_search_popup(void)
921 Evas_Object *popup = elm_win_util_standard_add("search-text", "Search Text");
923 fprintf(stderr,"Pop-up window creation failed");
926 evas_object_size_hint_weight_set(popup , EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
927 evas_object_size_hint_align_set(popup , EVAS_HINT_FILL, EVAS_HINT_FILL);
928 evas_object_resize(popup, 400, 300);
929 evas_object_show(popup);
931 Evas_Object* box = elm_box_add(popup);
932 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
933 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
934 elm_win_resize_object_add(popup, box);
935 evas_object_show(box);
937 Evas_Object *search_text_label = elm_label_add(popup);
938 elm_object_text_set(search_text_label, "Search Text: ");
939 elm_box_pack_end(box, search_text_label);
940 evas_object_show(search_text_label);
942 Evas_Object *search_text_entry = elm_entry_add(popup);
943 elm_entry_single_line_set(search_text_entry, EINA_TRUE);
944 elm_object_text_set(search_text_entry, "input search text");
945 elm_object_focus_set(search_text_entry, EINA_TRUE);
946 elm_box_pack_end(box, search_text_entry);
947 evas_object_show(search_text_entry);
949 Evas_Object *search_button = elm_button_add(popup);
950 elm_object_text_set(search_button, "Search");
951 elm_box_pack_end(box, search_button);
952 evas_object_show(search_button);
955 evas_object_smart_callback_add(popup, "delete,request", __search_closed_cb, 0);
956 evas_object_smart_callback_add(search_text_entry, "focused", __search_focused_cb, search_text_entry);
957 evas_object_smart_callback_add(search_text_entry, "unfocused", __search_unfocused_cb, search_text_entry);
958 evas_object_smart_callback_add(search_text_entry, "activated", __search_clicked_cb, search_text_entry);
959 evas_object_smart_callback_add(search_button, "clicked", __search_clicked_cb, search_text_entry);
962 void __search_closed_cb(void *data, Evas_Object *obj, void *event_info)
964 evas_object_del(obj);
967 void __search_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
969 Evas_Object* entry = data;
970 if (strcmp("", elm_entry_entry_get(entry)) == 0)
971 elm_entry_entry_set(entry, "input search text");
974 // Callback for showing permission request for media request
975 void __usermedia_permission_request_cb(void *data, Evas_Object *obj, void *event_info)
977 Ewk_User_Media_Permission_Request* permissionRequest=
978 (Ewk_User_Media_Permission_Request*)event_info;
979 // Simulating the User Pemission request for Allowing the media request.
980 ewk_user_media_permission_request_set(permissionRequest,EINA_TRUE);
981 printf("APP.C __usermedia_permission_request_cb Allowed User Media Request: \n");
984 void __search_focused_cb(void *data, Evas_Object *obj, void *event_info)
986 Evas_Object* entry = data;
987 if (strcmp("input search text", elm_entry_entry_get(entry)) == 0)
988 elm_entry_entry_set(entry, "");
991 void __search_clicked_cb(void *data, Evas_Object *obj, void *event_info)
993 Evas_Object* entry = data;
994 if (strcmp("input search text", elm_entry_entry_get(entry)) != 0)
995 ewk_view_text_find(view, elm_entry_entry_get(entry), EWK_FIND_OPTIONS_CASE_INSENSITIVE, 0);
998 void __auth_login_button_cb(void *data, Evas_Object *obj, void *event_info)
1000 Evas_Object* popup_window = data;
1001 const char* username = elm_entry_entry_get(credentials[0]);
1002 const char* password = elm_entry_entry_get(credentials[1]);
1003 ewk_auth_challenge_credential_use(auth_challenge_holder, username, password);
1004 evas_object_del(popup_window);
1007 void __auth_close_button_cb(void *data, Evas_Object *obj, void *event_info)
1009 ewk_auth_challenge_credential_cancel(auth_challenge_holder);
1010 evas_object_del(obj);
1013 void __notification_cancel_byuser_cb(void *data, Evas_Object *obj, void *event_info)
1015 ewk_notification_closed(current_notification_id, EINA_TRUE);
1016 current_notification_id = 0;
1017 evas_object_hide(popup);
1018 evas_object_del(popup);
1021 void __notification_show_cb(Ewk_Notification* current_notification, void* event_info)
1023 if (current_notification) {
1024 printf("APP.C callback _notification_show_cb Details: \n");
1025 printf("APP.C callback Body = %s \n",ewk_notification_body_get(current_notification));
1026 printf("APP.C callback Title = %s\n",ewk_notification_title_get(current_notification));
1027 const Ewk_Security_Origin *org = ewk_notification_security_origin_get((const Ewk_Notification*)current_notification);
1028 printf("APP.C callback Origin Host = %s\n",ewk_security_origin_host_get(org));
1029 printf("APP.C callback Origin Protocol = %s\n",ewk_security_origin_protocol_get(org));
1030 printf("APP.C callback Origin Port = %d\n",ewk_security_origin_port_get(org));
1031 // Adding pop up code
1032 popup = elm_popup_add(view);
1033 Evas_Object* icon = ewk_notification_icon_get(current_notification, evas_object_evas_get(popup));
1035 elm_popup_allow_events_set(popup, EINA_TRUE);
1036 elm_object_text_set(popup,ewk_notification_body_get(current_notification));
1037 elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
1038 elm_object_part_text_set(popup, "title,text", ewk_notification_title_get(current_notification));
1039 elm_object_part_content_set(popup, "title,icon", icon);
1040 evas_object_show(popup);
1042 Evas_Object *btn1 = elm_button_add(popup);
1043 elm_object_text_set(btn1, "CLOSE");
1044 elm_object_part_content_set(popup, "button1", btn1);
1045 current_notification_id = ewk_notification_id_get(current_notification);
1046 evas_object_smart_callback_add(btn1, "clicked", __notification_cancel_byuser_cb, 0);
1048 printf ("APP.C callback called __notification_show_cb \n");
1051 Eina_Bool __notification_permission_cb(Evas_Object* o, Ewk_Notification_Permission_Request* request, void* user_data)
1054 const Ewk_Security_Origin *sec_origin = ewk_notification_permission_request_origin_get((const Ewk_Notification_Permission_Request*)request);
1056 printf("APP.C callback called __notification_permission_cb URL = %s, protocol = %s, port = %d\n",
1057 ewk_security_origin_host_get(sec_origin), ewk_security_origin_protocol_get(sec_origin),ewk_security_origin_port_get(sec_origin));
1059 ewk_notification_permission_reply(request, EINA_TRUE);
1064 void __notification_cancel_cb(uint64_t notification_id, void* event_info)
1066 evas_object_del(popup);
1067 printf("APP.C callback __notification_cancel_cb with notification id = %Lu\n", (long long unsigned int)notification_id);
1070 void __policy_response_decide_cb(void *data, Evas_Object *obj, void *event_info)
1072 printf("APP.C callback called __policy_response_decide_cb \n");
1073 Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
1074 Ewk_Policy_Decision_Type policy_type = ewk_policy_decision_type_get(policy_decision);
1075 const char *uri = ewk_policy_decision_url_get(policy_decision);
1076 const char *cookie = ewk_policy_decision_cookie_get(policy_decision);
1077 const char *mime = ewk_policy_decision_response_mime_get(policy_decision);
1078 printf("APP.C URL : %s\n", uri);
1079 printf("APP.C cookie : %s\n", cookie);
1080 printf("APP.C mime type : %s\n", mime);
1081 printf("APP.C policy type : %d\n", policy_type);
1082 ewk_policy_decision_use(policy_decision);
1085 void __customize_context_menu_cb(void* data, Evas_Object *obj, void *event_info)
1087 Ewk_Context_Menu *context_menu = (Ewk_Context_Menu*)event_info;
1088 ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_GO_BACK, "Back", 1);
1089 ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_GO_FORWARD, "Forward", 1);
1090 ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_RELOAD, "Reload", 1);
1091 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR, "Bk_fwd_clear", 1);
1092 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_CACHE_RUN, "Run App Cache Test", 1);
1093 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_CACHE_DELETE_ALL, "Delete All App Cache", 1);
1094 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_GRAB_SNAPSHOT, "Take Snapshot", 1);
1095 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_WEB_DATABASE_GET_ORIGINS, "Get WebDB", 1);
1096 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_WEB_DATABASE_DELETE_ALL, "Clear WebDB", 1);
1097 printf("APP.C callback __customize_context_menu_cb \n");
1100 static void get_app_cache_usage_cb(int64_t usage, void* user_data)
1102 static unsigned int count_usage_callback = 0;
1103 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)user_data;
1104 printf("AppCache usage for %s is %ld\n", ewk_security_origin_host_get(origin), (long int)usage);
1105 ewk_context_application_cache_delete(ewk_context_default_get(), origin);
1106 if (eina_list_count(application_cache_origins) == ++count_usage_callback) {
1107 ewk_context_origins_free(application_cache_origins);
1108 count_usage_callback = 0;
1109 application_cache_origins = NULL;
1113 static void get_origins_for_cache_cb(Eina_List* origins, void* user_data)
1117 Eina_List* list_iterator = NULL;
1119 if (application_cache_origins) {
1120 fprintf(stderr, "APP/ERROR: First cache usage-delete cycle is still running.\n");
1124 application_cache_origins = origins;
1125 EINA_LIST_FOREACH(origins, list_iterator, data) {
1126 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(data);
1127 ewk_context_application_cache_usage_for_origin_get(ewk_context_default_get(), origin,
1128 get_app_cache_usage_cb, origin);
1132 static void get_origins_for_webDB_cb(Eina_List* origins, void* user_data)
1137 if (web_database_origins)
1140 Eina_List* list_iterator = NULL;
1142 web_database_origins = origins;
1143 static unsigned int flag = 0;
1144 EINA_LIST_FOREACH(origins, list_iterator, data) {
1145 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(data);
1146 printf("Web Database origin : %s\n", ewk_security_origin_host_get(origin));
1149 if(eina_list_count(web_database_origins) == flag) {
1151 ewk_context_origins_free(web_database_origins);
1152 web_database_origins = NULL;
1156 void __customize_context_menu_item_selected_cb(void* data, Evas_Object *obj, void *event_info)
1158 Ewk_Context_Menu_Item* item = (Ewk_Context_Menu_Item*)event_info;
1159 switch (ewk_context_menu_item_tag_get(item)) {
1160 case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW:
1161 printf("APP.C callback __customize_context_menu_item_selected_cb : Open In new Window Selected\n");
1163 const int default_width = 300;
1164 const int default_height = 400;
1166 Ecore_Evas* ee = ecore_evas_new("software_x11", 0, 0, default_width, default_height, 0);
1167 Evas* e = ecore_evas_get(ee);
1169 Evas_Object* new_view = ewk_view_add(e);
1170 ewk_view_url_set(new_view, ewk_context_menu_item_link_url_get(item));
1171 evas_object_resize(new_view, default_width, default_height);
1172 evas_object_show(new_view);
1173 evas_object_focus_set(new_view, EINA_TRUE);
1174 ecore_evas_show(ee);
1175 evas_object_smart_callback_add(new_view, "close,window", __window_closed_cb, 0);
1176 ecore_evas_callback_delete_request_set(ee, delete_popup_window);
1178 case FOR_TEST_APPLICATION_CACHE_RUN:
1179 if (ewk_context_application_cache_origins_get(ewk_context_default_get(),
1180 get_origins_for_cache_cb, NULL)) {
1181 printf("Getting origins for Application Cache\n");
1184 case FOR_TEST_APPLICATION_CACHE_DELETE_ALL:
1185 if (ewk_context_application_cache_delete_all(ewk_context_default_get()))
1186 printf("All app cache deleted\n");
1188 case FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR:
1189 printf("APP.C callback Bk_fwd_clear callback item selected cb\n");
1190 ewk_view_back_forward_list_clear(view);
1192 case FOR_TEST_GRAB_SNAPSHOT:
1193 printf("APP.C GRAB_SNAPSHOT selected\n");
1194 Eina_Rectangle snapshot_rect;
1195 snapshot_rect.x = snapshot_rect.y = 0;
1196 evas_object_geometry_get(view, NULL, NULL, &snapshot_rect.w, &snapshot_rect.h);
1197 Evas_Object* snapshot = ewk_view_screenshot_contents_get(view, snapshot_rect, 1.0, evas_object_evas_get(view));
1199 fprintf(stderr, "Failed to get snapshot\n");
1202 static char snapshot_filename[256];
1203 static int snapshot_count = 1;
1204 sprintf(snapshot_filename, "snapshot_img%04d.%s", snapshot_count++, "png");
1205 if (evas_object_image_save(snapshot, snapshot_filename, 0, 0))
1206 printf("Snapshot image saved in %s\n", snapshot_filename);
1208 printf("Snapshot image could not be saved\n");
1210 case FOR_TEST_WEB_DATABASE_GET_ORIGINS:
1211 if (ewk_context_web_database_origins_get(ewk_context_default_get(),
1212 get_origins_for_webDB_cb, NULL)) {
1213 printf("Getting Origins for Web Database\n");
1216 case FOR_TEST_WEB_DATABASE_DELETE_ALL:
1217 if (ewk_context_web_database_delete_all(ewk_context_default_get()))
1218 printf("All Web Databases deleted\n");
1225 void __text_found_cb(void *data, Evas_Object *obj, void *event_info)
1227 printf("text found : %u\n", *((unsigned int*)(event_info)));
1230 void __newwindow_policy_cb(void *data, Evas_Object *obj, void* policy)
1232 printf ("APP.C __newwindow_policy_cb called \n");
1233 Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)policy;
1234 const char* url = ewk_policy_decision_url_get(policy_decision);
1235 printf("APP.C url for new window: %s \n", url);
1236 ewk_policy_decision_use(policy_decision);
1239 void __load_nonemptylayout_finished_cb(void *data, Evas_Object *obj, void *event_info)
1241 printf ("APP.C callback called __load_nonemptylayout_finished_cb \n");
1244 void __popup_wait_start_cb(void *data, Evas_Object *obj, void* policy)
1246 printf("Popup wait start\n");
1249 void __popup_wait_finish_cb(void *data, Evas_Object *obj, void* policy)
1251 printf("Popup wait finish\n");
1254 void __download_callback(const char* download_url, void* user_data)
1256 printf("new download start callback is triggered:%s\n", download_url);
1259 void __frame_rendered_cb(void* data, Evas_Object* obj, void* event_info)
1261 printf ("APP.C callback called __frame_rendered_cb \n");
1265 evas_object_geometry_get(obj, NULL, NULL, &width, &height);
1266 if (ewk_view_contents_pdf_get(obj, width, height, pdf_filename))
1267 printf("\"Save as PDF\" request sent\n");
1269 printf("Failed to send \"Save as PDF\" request\n");
1273 void __ewk_view_plain_text_get_cb(Evas_Object* o, const char* content_text, void* user_data)
1276 printf("__ewk_view_plain_text_get_cb callback success --\n%s\n---user_data--%d\n",content_text,*(int*)(user_data));
1279 void __ewk_view_plain_text_get_cb_1(Evas_Object* o, const char* content_text, void* user_data)
1282 printf("__ewk_view_plain_text_get_cb_1 callback success --\n%s\n---user_data--%d\n",content_text,*(int*)(user_data));
1285 void __load_started_cb(void *data, Evas_Object *obj, void *event_info)
1287 printf("APP.c __load_started_cb called \n");
1290 void __edge_left_cb(void* data, Evas_Object* obj, void* event_info)
1292 printf("Edge_Left Notification\n");
1295 void __edge_right_cb(void* data, Evas_Object* obj, void* event_info)
1297 printf("Edge_Right Notification\n");
1300 void __edge_top_cb(void* data, Evas_Object* obj, void* event_info)
1302 printf("Edge_Top Notification\n");
1305 void __edge_bottom_cb(void* data, Evas_Object* obj, void* event_info)
1307 printf("Edge_Bottom Notification\n");
1310 #if defined(OS_TIZEN)
1311 Eina_Bool __vibration_timeout_cb(void *data)
1313 if (IsMobileProfile() || IsWearableProfile()) {
1314 g_haptic_timer_id = NULL;
1315 if (g_haptic_handle) {
1316 device_haptic_stop(g_haptic_handle, g_haptic_effect);
1317 device_haptic_close(g_haptic_handle);
1318 g_haptic_handle = NULL;
1321 return ECORE_CALLBACK_CANCEL;
1327 void __vibration_on_cb(uint64_t vibration_time, void *data)
1329 if (IsMobileProfile() || IsWearableProfile()) {
1330 printf("__vibration_on_cb called");
1331 uint64_t duration = vibration_time;
1333 if (g_haptic_timer_id) {
1334 ecore_timer_del(g_haptic_timer_id);
1335 g_haptic_timer_id = NULL;
1338 if (g_haptic_handle) {
1339 device_haptic_stop(g_haptic_handle, g_haptic_effect);
1340 device_haptic_close(g_haptic_handle);
1341 g_haptic_handle = NULL;
1344 if (device_haptic_open(0, &g_haptic_handle) != DEVICE_ERROR_NONE) {
1345 printf("__vibration_on_cb:device_haptic_open failed");
1349 device_haptic_vibrate(g_haptic_handle, duration, 100, &g_haptic_effect);
1350 double in = (double)((double)(duration) / (double)(1000));
1351 printf("__vibration_on_cb:duration=%f", in);
1353 g_haptic_timer_id = ecore_timer_add(in, __vibration_timeout_cb, NULL);
1357 void __vibration_off_cb(void *data)
1359 if (IsMobileProfile() || IsWearableProfile()) {
1360 printf("__vibration_off_cb called");
1361 if (g_haptic_timer_id) {
1362 ecore_timer_del(g_haptic_timer_id);
1363 g_haptic_timer_id = NULL;
1366 if (g_haptic_handle) {
1367 device_haptic_stop(g_haptic_handle, g_haptic_effect);
1368 device_haptic_close(g_haptic_handle);
1369 g_haptic_handle = NULL;
1375 void __hit_test_request_cb(Evas_Object* o, int x, int y, int hit_test_mode, Ewk_Hit_Test* ht, void* user_data)
1377 printf("HitTest: context %d\n", ewk_hit_test_result_context_get(ht));
1378 printf("HitTest: link uri %s\n", ewk_hit_test_link_uri_get(ht));
1379 printf("HitTest: link title %s\n", ewk_hit_test_link_title_get(ht));
1380 printf("HitTest: link label %s\n",ewk_hit_test_link_label_get(ht));
1381 printf("HitTest: image uri %s\n", ewk_hit_test_image_uri_get(ht));
1382 #if !defined(EWK_BRINGUP)
1383 printf("HitTest: media uri %s\n", ewk_hit_test_media_uri_get(ht));
1385 printf("HitTest: tag name %s\n", ewk_hit_test_tag_name_get(ht));
1386 printf("HitTest: node value %s\n", ewk_hit_test_node_value_get(ht));
1387 printf("HitTest: image length %d\n", ewk_hit_test_image_buffer_length_get(ht));
1388 printf("HitTest: filename extension %s\n", ewk_hit_test_image_file_name_extension_get(ht));
1389 if (ewk_hit_test_image_buffer_length_get(ht)) {
1390 // To verify the buffer, we write to file.
1391 // App might use its own engine to encode, we use evas API.
1392 Evas_Object* image = evas_object_image_add(e);
1393 evas_object_image_colorspace_set(image, EVAS_COLORSPACE_ARGB8888);
1394 evas_object_image_alpha_set(image, EINA_TRUE);
1395 evas_object_image_data_copy_set(image, ewk_hit_test_image_buffer_get(ht));
1396 static char filename_buffer[256];
1397 static int count = 1;
1398 sprintf(filename_buffer, "hit_test_img%04d.%s", count++, ewk_hit_test_image_file_name_extension_get(ht));
1399 if (evas_object_image_save(image, filename_buffer, 0, 0))
1400 printf("Hit test image saved in %s\n", filename_buffer);
1402 printf("Hit test image could not be saved\n");
1405 Eina_Hash *attr_hash = ewk_hit_test_attribute_hash_get(ht);
1407 eina_hash_foreach(attr_hash, _util_print_hit_test_result_hash_fn, NULL);
1412 void on_mouse_up(void* data, Evas* canvas, Evas_Object* obj, void* event_info)
1414 Evas_Event_Mouse_Up* event = (Evas_Event_Mouse_Up*)event_info;
1415 if (!evas_key_modifier_is_set(event->modifiers, "Shift"))
1418 ewk_view_hit_test_request(obj, event->canvas.x, event->canvas.y, EWK_HIT_TEST_MODE_ALL, __hit_test_request_cb, NULL);
1421 void __undo_size_cb(void* data, Evas_Object* obj, void* event_info)
1423 printf ("APP.C callback called __undo_size_cb\n");
1426 void __redo_size_cb(void* data, Evas_Object* obj, void* event_info)
1428 printf ("APP.C callback called __redo_size_cb \n");
1431 void __mhtml_save_cb(Evas_Object *obj, const char *mhtml_data, void *data)
1433 printf("APP.C __mhtml_save_cb callback called\n");
1434 printf("APP.C Data is \n %s \n\n", mhtml_data);
1437 void __clipboard_opened_cb(void* data, Evas_Object* view, void* event_info)
1439 printf("APP.C clipboard window opened\n");
1442 void __back_forward_list_changed_cb(void *data, Evas_Object *obj, void *event_info)
1444 printf("APP.C Back Forward List Changed Notification\n");
1447 Eina_Bool __ewk_view_javascript_alert_cb(Evas_Object* o, const char* alert_text, void* user_data)
1449 printf("APP.C javascript alert opened\n");
1454 Eina_Bool __ewk_view_javascript_confirm_cb(Evas_Object* o, const char* message, void* user_data)
1456 printf("APP.C javascript confirm popup opened\n");
1461 Eina_Bool __ewk_view_javascript_prompt_cb(Evas_Object* o, const char* message, const char* default_value, void* user_data)
1463 printf("APP.C javascript prompt popup opened\n");
1468 void __webprocess_crashed_cb(void* data, Evas_Object* obj, void* event_info)
1470 printf("APP.C callback __webprocess_crashed_cb \n");
1471 const char* message = "<html><body><h1>The renderer process has crashed!</h1>"
1472 "<a href=\"https://google.com\">Open google</a></body></html>";
1473 ewk_view_html_string_load(view, message, 0, 0);
1474 Eina_Bool* handled = (Eina_Bool*)event_info;
1475 *handled = EINA_TRUE;
1478 Eina_Bool __mime_override_cb(const char* url, const char *mime, char **new_mime, void* user_data)
1480 printf("APP.C callback %s, url: %s, mime: %s\n", __func__, url, mime);
1482 if (strcmp(url, "file://mytest.abc") == 0 ||
1483 strcmp(mime, "application/x-php") == 0) {
1484 *new_mime = strdup("text/html");
1491 void __console_message_cb(void *data, Evas_Object *obj, void *event_info)
1493 Ewk_Console_Message* console_message = (Ewk_Console_Message*)event_info;
1494 printf("APP.C callback called __console_message_cb\n");
1495 printf("console message:%s:", ewk_console_message_source_get(console_message));
1496 printf("%d:", ewk_console_message_line_get(console_message));
1497 printf("%d:", ewk_console_message_level_get(console_message));
1498 printf("%s\n", ewk_console_message_text_get(console_message));