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
7 #include "public/ewk_auth_challenge.h"
8 #include "public/ewk_context.h"
9 #include "public/ewk_main.h"
10 #include "public/ewk_view.h"
11 #include "public/ewk_geolocation.h"
12 #include "public/ewk_security_origin.h"
13 #include "public/ewk_error.h"
14 #include "public/ewk_notification.h"
15 #include "public/ewk_policy_decision.h"
16 #include "public/ewk_context_menu.h"
17 #include "public/ewk_text_style.h"
18 #include "public/ewk_cookie_manager.h"
19 #include "public/ewk_console_message.h"
20 #include "public/ewk_user_media.h"
21 #include "tizen/system_info.h"
24 #include <Ecore_Evas.h>
25 #include <Ecore_File.h>
26 #include <Ecore_Getopt.h>
27 #include "ecore_x_wayland_wrapper.h"
29 #include <Elementary.h>
32 #include <device/haptic.h>
39 static Ecore_Evas* ee;
41 static Evas_Object* view;
42 static Evas_Object *popup;
44 uint64_t current_notification_id;
46 static Ewk_Auth_Challenge* auth_challenge_holder = NULL;
47 static Evas_Object* credentials[2] = {0};//username and password
49 static Eina_Bool fullscreen_enabled;
50 static Eina_Bool clear_cache;
51 static Eina_Bool disable_cache = EINA_FALSE;
52 static char* pdf_filename = NULL;
53 static char* cache_policy = NULL;
54 static char* content_security_policy = NULL;
55 static char* content_security_policy_type = NULL;
56 static char* start_url = NULL;
57 static int content_text_callback_data = 10;
58 static int content_text_callback_data_1 = 20;
59 static Eina_Bool test_cookie;
60 static Eina_Bool clear_cookie_called;
61 static Ewk_Cookie_Accept_Policy set_cookie_policy;
62 static Eina_List* application_cache_origins = NULL;
63 static Eina_List* web_database_origins = NULL;
66 static haptic_device_h g_haptic_handle;
67 static Ecore_Timer *g_haptic_timer_id;
68 static haptic_effect_h g_haptic_effect;
71 static void show_userid_password_popup(const char* msg);
72 static void show_search_popup(void);
73 static void on_mouse_up(void* data, Evas* canvas, Evas_Object* obj, void* event_info);
74 static void __search_closed_cb(void *data, Evas_Object *obj, void *event_info);
75 static void __search_focused_cb(void *data, Evas_Object *obj, void *event_info);
76 static void __search_unfocused_cb(void *data, Evas_Object *obj, void *event_info);
77 static void __search_clicked_cb(void *data, Evas_Object *obj, void *event_info);
78 static void __auth_login_button_cb(void *data, Evas_Object *obj, void *event_info);
79 static void __auth_close_button_cb(void *data, Evas_Object *obj, void *event_info);
80 static void __load_finished_cb(void *data, Evas_Object *obj, void *event_info);
81 static void __load_error_cb(void *data, Evas_Object *obj, void *event_info);
82 static void __uri_changed_cb(void *data, Evas_Object *obj, void *event_info);
83 static void __title_changed_cb(void *data, Evas_Object *obj, void *event_info);
84 static void __load_progress_cb(void *data, Evas_Object *obj, void *event_info);
85 static void __load_progress_started_cb(void *data, Evas_Object *obj, void *event_info);
86 static void __load_progress_finished_cb(void *data, Evas_Object *obj, void *event_info);
87 static void __ime_input_panel_show_cb(void* data, Evas_Object *obj, void* event_info);
88 static void __ime_input_panel_hide_cb(void* data, Evas_Object *obj, void* event_info);
89 static void __ime_candidate_panel_show_cb(void* data, Evas_Object *obj, void* event_info);
90 static void __ime_candidate_panel_hide_cb(void* data, Evas_Object *obj, void* event_info);
91 static void __create_window_cb(void *data, Evas_Object *obj, void *event_info);
92 static void __window_closed_cb(void *data, Evas_Object *obj, void *event_info);
93 static void __imf_input_method_changed_cb(void *data, Evas_Object *obj, void *event_info);
94 static void __did_start_provisional_load_for_frame_cb(void *data, Evas_Object *obj, void *event_info);
95 static void __did_commit_load_for_frame(void *data, Evas_Object *obj, void *event_info);
96 static void __geoLocation_popup_display_cb(void *data, Evas_Object *obj, void *event_info);
97 void __script_executed_cb(Evas_Object *obj, const char *javascript_result, void *data);
98 static void __auth_challenge_cb(void* data, Evas_Object *obj, void *event_info);
99 static void __policy_response_decide_cb(void *data, Evas_Object *obj, void *event_info);
100 static void __customize_context_menu_cb(void* data, Evas_Object *obj, void *event_info);
101 static void __customize_context_menu_item_selected_cb(void* data, Evas_Object *obj, void *event_info);
102 static void __usermedia_permission_request_cb(void *data, Evas_Object *obj, void *event_info);
103 static void __navigation_policy_decide_cb(void *data, Evas_Object *obj, void *event_info);
104 static void __text_found_cb(void *data, Evas_Object *obj, void *event_info);
105 static void __newwindow_policy_cb(void *data, Evas_Object *obj, void* policy);
106 static void __load_nonemptylayout_finished_cb(void* data, Evas_Object *obj, void *event_info);
107 static void __popup_wait_start_cb(void *data, Evas_Object *obj, void* policy);
108 static void __popup_wait_finish_cb(void *data, Evas_Object *obj, void* policy);
109 static void __edge_left_cb(void* data, Evas_Object* obj, void* event_info);
110 static void __edge_right_cb(void* data, Evas_Object* obj, void* event_info);
111 static void __edge_top_cb(void* data, Evas_Object* obj, void* event_info);
112 static void __edge_bottom_cb(void* data, Evas_Object* obj, void* event_info);
113 static void __hit_test_request_cb(Evas_Object* o, int x, int y, int hit_test_mode, Ewk_Hit_Test*, void* user_data);
114 static void __webprocess_crashed_cb(void* data, Evas_Object* obj, void* event_info);
116 static void on_evas_resize(Ecore_Evas*);
117 static void __notification_show_cb(Ewk_Notification*, void* event_info);
118 static Eina_Bool __notification_permission_cb(Evas_Object*, Ewk_Notification_Permission_Request*, void*);
119 static void __notification_cancel_cb(uint64_t notification_id, void* event_info);
120 static void __notification_cancel_byuser_cb(void *data, Evas_Object *obj, void *event_info);
121 static void __download_callback(const char*download_url, void* user_data);
122 static void __frame_rendered_cb(void* data, Evas_Object* obj, void* event_info);
123 static void __ewk_view_plain_text_get_cb(Evas_Object* o, const char* content_text, void* user_data);
124 static void __ewk_view_plain_text_get_cb_1(Evas_Object* o, const char* content_text, void* user_data);
125 static void __load_started_cb(void *data, Evas_Object *obj, void *event_info);
126 static void __text_style_state_changed_cb(void *data, Evas_Object *obj, void *event_info);
127 static void __ewk_cookie_manager_async_policy_get_cb(
128 Ewk_Cookie_Accept_Policy policy, void *event_info);
129 static void __ewk_cookie_manager_async_hostnames_get_cb(Eina_List *hostnames, Ewk_Error *error, void *event_info);
130 static void __back_forward_list_changed_cb(void *data, Evas_Object *obj, void *event_info);
131 static Eina_Bool __mime_override_cb(const char* url, const char *mime, char **new_mime, void* user_data);
132 static void __console_message_cb(void *data, Evas_Object *obj, void *event_info);
134 #if defined(OS_TIZEN)
135 static Eina_Bool __vibration_timeout_cb(void *data);
136 static void __vibration_on_cb(uint64_t vibration_time, void *data);
137 static void __vibration_off_cb(void *data);
140 static void __undo_size_cb(void* data, Evas_Object* obj, void* event_info);
141 static void __redo_size_cb(void* data, Evas_Object* obj, void* event_info);
142 void __mhtml_save_cb(Evas_Object *obj, const char *mhtml_data, void *data);
143 static void __clipboard_opened_cb(void* data, Evas_Object* view, void* event_info);
144 static Eina_Bool __ewk_view_javascript_alert_cb(Evas_Object* o, const char* alert_text, void* user_data);
145 static Eina_Bool __ewk_view_javascript_confirm_cb(Evas_Object* o, const char* message, void* user_data);
146 static Eina_Bool __ewk_view_javascript_prompt_cb(Evas_Object* o, const char* message, const char* default_value, void* user_data);
149 FOR_TEST_APPLICATION_CACHE_RUN = EWK_CONTEXT_MENU_ITEM_BASE_APPLICATION_TAG + 1,
150 FOR_TEST_APPLICATION_CACHE_DELETE_ALL,
151 FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR,
152 FOR_TEST_GRAB_SNAPSHOT,
153 FOR_TEST_WEB_DATABASE_GET_ORIGINS,
154 FOR_TEST_WEB_DATABASE_DELETE_ALL
155 // New context menu items can be added here
158 static const Ecore_Getopt options = {
159 .prog = "efl_webview_app",
160 .usage = "%prog [options] [url]",
161 .strict = EINA_FALSE,
163 ECORE_GETOPT_STORE_DEF_BOOL('F', "full-screen", "start in full-screen", EINA_TRUE),
164 ECORE_GETOPT_STORE_DEF_BOOL('c', "clear-cache", "clear cache on every page load finished", EINA_TRUE),
165 ECORE_GETOPT_STORE_DEF_BOOL('k', "test-cookie", "test cookie on every page load finished", EINA_TRUE),
166 ECORE_GETOPT_STORE_DEF_STR('s', "set-cache-policy", "set cache policy", "viewer"),
167 ECORE_GETOPT_STORE_DEF_STR('p', "set-content-security-policy", "set content security policy", NULL),
168 ECORE_GETOPT_STORE_DEF_STR('t', "content-security-policy-type",
169 "Type of content security policy only applicable if policy is defined",
171 ECORE_GETOPT_STORE_DEF_BOOL('d', "disable-cache", "Disable network cache", EINA_FALSE),
172 ECORE_GETOPT_STORE_DEF_STR('w', "save-pdf", "Save as PDF", "webpage.pdf"),
173 ECORE_GETOPT_SENTINEL,
177 static Eina_Bool _util_print_hit_test_result_hash_fn(const Eina_Hash *hash, const void *key, void *data, void *fdata)
179 printf("HitTest attribute (%s): (%s)\n", (const char*)key, (char *)data);
184 static void on_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
186 Evas_Event_Key_Down *ev = (Evas_Event_Key_Down*) event_info;
187 static int scroll_x = 0;
188 static int scroll_y = 0;
190 if (strcmp(ev->key, "XF86Back") == 0 || strcmp(ev->key, "XF86Stop") == 0)
192 if (ewk_view_text_selection_clear(view))
196 if (!strcmp(ev->key, "F1")) {
197 fprintf(stderr, "[on_key_down] (F1) pressed. Go to wikipedia.com\n");
198 ewk_view_url_set(view, "http://www.wikipedia.com/");
200 else if (!strcmp(ev->key, "F2")) {
201 double level = ewk_view_text_zoom_get(view) + 0.1;
202 ewk_view_text_zoom_set(view, level);
203 printf("current text zoom level %lf\n", ewk_view_text_zoom_get(view));
205 else if (!strcmp(ev->key, "F3")) {
206 double level = ewk_view_text_zoom_get(view) - 0.1;
207 ewk_view_text_zoom_set(view, level);
208 printf("current text zoom level %lf\n", ewk_view_text_zoom_get(view));
210 else if (!strcmp(ev->key, "F4")) {
211 ewk_view_command_execute(view, "Undo", NULL);
213 else if (!strcmp(ev->key, "F5")) {
214 printf("selection text \"%s\"\n", ewk_view_text_selection_text_get(view));
216 else if (!strcmp(ev->key, "F6")) {
219 else if (!strcmp(ev->key, "F7")) {
220 static Eina_Bool visibility = EINA_TRUE;
221 visibility = !visibility;
222 ewk_view_visibility_set(view, visibility);
224 else if (!strcmp(ev->key, "F8")) {
225 ewk_view_contents_set(view, "ewk Data Set API Test!!!!", 25, "text/plain", NULL, "http://www.naver.com");
227 else if (!strcmp(ev->key, "F9")) {
230 ewk_view_scroll_pos_get(view, &x, &y);
231 printf("scroll_pos_get %d, %d \n",x,y);
233 else if (!strcmp(ev->key, "F10")) {
234 if (!(ewk_view_plain_text_get(view, __ewk_view_plain_text_get_cb, &content_text_callback_data)))
235 printf("\nEWK_VIEW_PLAIN_TEXT_GET FAILURE\n");
237 printf("\nEWK_VIEW_PLAIN_TEXT_GET SUCCESS\n");
238 if (!(ewk_view_plain_text_get(view, __ewk_view_plain_text_get_cb_1, &content_text_callback_data_1)))
239 printf("\nEWK_VIEW_PLAIN_TEXT_GET_1 FAILURE\n");
241 printf("\nEWK_VIEW_PLAIN_TEXT_GET_1 SUCCESS\n");
243 else if (!strcmp(ev->key, "F11")) {
244 ewk_view_command_execute(view, "Redo", NULL);
246 else if (evas_key_modifier_is_set(ev->modifiers, "Control")) {
247 if (!strcmp(ev->key, "f") || !strcmp(ev->key, "F"))
249 else if (!strcmp(ev->key, "s") || !strcmp(ev->key, "S"))
250 ewk_view_mhtml_data_get(view, __mhtml_save_cb, NULL);
252 else if (!strcmp(ev->key, "w") || !strcmp(ev->key, "W")) {
255 ewk_view_scroll_set(view, scroll_x, scroll_y);
256 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
259 else if (!strcmp(ev->key, "s") || !strcmp(ev->key, "S")) {
261 ewk_view_scroll_set(view, scroll_x, scroll_y);
262 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
264 else if (!strcmp(ev->key, "d") || !strcmp(ev->key, "D")) {
266 ewk_view_scroll_set(view, scroll_x, scroll_y);
267 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
269 else if (!strcmp(ev->key, "a") || !strcmp(ev->key, "A")) {
272 ewk_view_scroll_set(view, scroll_x, scroll_y);
273 printf("scroll_set %d, %d \n", scroll_x, scroll_y);
276 else if (!strcmp(ev->key, "BackSpace") || !strcmp(ev->key, "XF86Back") ||
277 !strcmp(ev->key, "XF86Stop")) {
282 static void on_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info)
284 Evas_Event_Mouse_Wheel* event = (Evas_Event_Mouse_Wheel*)event_info;
285 static double scale_factor = 1.0;
287 if (evas_key_modifier_is_set(event->modifiers, "Control"))
294 printf("ewk_view_scale_set() : %lf (%d, %d)\n", scale_factor, event->output.x, event->output.y);
296 ewk_view_scale_set(view, scale_factor, event->output.x, event->output.y);
300 static Eina_Strbuf* create_url_with_scheme(const char* base_url, const char* scheme)
302 Eina_Strbuf* buffer = eina_strbuf_new();
303 eina_strbuf_append(buffer, scheme);
304 eina_strbuf_append(buffer, base_url);
308 static void set_url_from_user_input(Evas_Object* view, const char* url)
310 if (strstr(url, "://")) {
311 ewk_view_url_set(view, url);
316 Eina_Strbuf* full_url;
317 if (ecore_file_exists(url)) {
318 char* realpath = ecore_file_realpath(url);
319 full_url = create_url_with_scheme(realpath, "file://");
322 full_url = create_url_with_scheme(url, "http://");
325 ewk_view_url_set(view, eina_strbuf_string_get(full_url));
327 eina_strbuf_free(full_url);
330 //set cache policy as per command line arguments
331 static void set_cache_policy(Ewk_Context* context)
334 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
337 if (!strcmp(cache_policy, "browser"))
338 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_DOCUMENT_BROWSER);
339 else if (!strcmp(cache_policy, "webbrowser"))
340 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
341 else if(!strcmp(cache_policy, "viewer"))
342 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
345 static void set_csp(Evas_Object *ewk_view)
347 if(!ewk_view || !content_security_policy_type)
350 if(!strcmp(content_security_policy_type, "report"))
351 ewk_view_content_security_policy_set(ewk_view, content_security_policy, EWK_REPORT_ONLY);
352 else if(!strcmp(content_security_policy_type, "enforce"))
353 ewk_view_content_security_policy_set(ewk_view, content_security_policy, EWK_ENFORCE_POLICY);
356 static void disable_cache_for_context(Ewk_Context* context)
358 ewk_context_cache_disabled_set(context, EINA_TRUE);
361 static void _evas_close_cb(Ecore_Evas* ee)
363 ecore_main_loop_quit();
366 #if defined(OS_TIZEN_TV_PRODUCT)
367 static void _create_mouse_cursor(Evas_Object* window) {
368 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
369 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
370 struct wl_display* display = ecore_wl2_display_get(wl2_display);
371 Eina_Iterator* globals = ecore_wl2_display_globals_get(wl2_display);
372 struct wl_registry* registry = ecore_wl2_display_registry_get(wl2_display);
373 struct wl_seat* seat =
374 ecore_wl2_input_seat_get(ecore_wl2_input_default_input_get(wl2_display));
376 Ecore_Wl2_Global* global;
377 EINA_ITERATOR_FOREACH(globals, global) {
378 if (!strcmp(global->interface, "tizen_cursor"))
379 if (!CursorModule_Initialize(display, registry, seat, global->id))
380 fprintf(stderr, "CursorModule_Initialize() Failed!\n");
382 eina_iterator_free(globals);
384 struct wl_surface* const surface =
385 ecore_wl2_window_surface_get(ecore_evas_wayland2_window_get(
386 ecore_evas_ecore_evas_get(evas_object_evas_get(window))));
389 if (!Cursor_Set_Config(surface, TIZEN_CURSOR_CONFIG_CURSOR_AVAILABLE, NULL))
390 fprintf(stderr, "Cursor_Set_Config() Failed!\n");
391 CursorModule_Finalize();
393 const char* t_cursor = "tizen_cursor";
394 Ecore_Wl_Global* global_data = NULL;
395 unsigned int cursormgr_id = 0;
397 EINA_INLIST_FOREACH(ecore_wl_globals_get(), global_data) {
398 if (0 == strncmp(global_data->interface, t_cursor, strlen(t_cursor))) {
399 cursormgr_id = global_data->id; // to get the id of cursormgr object
404 struct wl_surface* const surface =
405 ecore_wl_window_surface_get(elm_win_wl_window_get(window));
408 const int ret_cursormod = CursorModule_Initialize(
409 ecore_wl_display_get(), ecore_wl_registry_get(),
410 ecore_wl_input_seat_get(ecore_wl_input_get()), cursormgr_id);
412 Cursor_Set_Config(surface, TIZEN_CURSOR_CONFIG_CURSOR_AVAILABLE, NULL);
414 CursorModule_Finalize();
415 #endif // TIZEN_VERSION_AT_LEAST(5, 0, 0)
419 int main(int argc, char** argv)
421 // Make sure this happens just once.
422 // By default the web process is the same program.
423 fprintf(stderr, "efl_webview_app starting...\n");
425 if (IsDesktopProfile()) {
426 fprintf(stderr, "Runtime Profile : DESKTOP\n");
427 } else if (IsMobileProfile()) {
428 fprintf(stderr, "Runtime Profile : MOBILE\n");
429 } else if (IsTvProfile()) {
430 fprintf(stderr, "Runtime Profile : TV\n");
431 } else if (IsWearableProfile()) {
432 fprintf(stderr, "Runtime Profile : WEARABLE\n");
433 } else if (IsIviProfile()) {
434 fprintf(stderr, "Runtime Profile : IVI\n");
435 } else if (IsCommonProfile()) {
436 fprintf(stderr, "Runtime Profile : COMMON\n");
438 fprintf(stderr, "Runtime Profile : UNKNOWN\n");
441 if (IsEmulatorArch()) {
442 fprintf(stderr, "Runtime Architecture : EMULATOR\n");
445 ewk_set_arguments(argc, argv);
446 setenv("ELM_ENGINE", "gl", 1);
451 Ecore_Getopt_Value values[] = {
452 ECORE_GETOPT_VALUE_BOOL(fullscreen_enabled),
453 ECORE_GETOPT_VALUE_BOOL(clear_cache),
454 ECORE_GETOPT_VALUE_BOOL(test_cookie),
455 ECORE_GETOPT_VALUE_STR(cache_policy),
456 ECORE_GETOPT_VALUE_STR(content_security_policy),
457 ECORE_GETOPT_VALUE_STR(content_security_policy_type),
458 ECORE_GETOPT_VALUE_BOOL(disable_cache),
459 ECORE_GETOPT_VALUE_STR(pdf_filename),
460 ECORE_GETOPT_VALUE_NONE,
463 Eina_Bool incognito = EINA_FALSE;
464 int idx = ecore_getopt_parse(&options, values, argc, argv);
465 for (; idx < argc; ++idx) {
466 // Treat first argument not starting with - as the url to load
467 if (argv[idx][0] != '-') {
468 start_url = strdup(argv[idx]);
469 } else if (strcmp(argv[idx], "--incognito") == 0) {
470 incognito = EINA_TRUE;
475 start_url = strdup("http://www.google.com");
478 Ewk_Context* context = NULL;
480 // TODO : ewk content creation for incognito mode also has to be moved here.
481 if (incognito == EINA_FALSE) {
482 context = ewk_context_default_get();
488 #if defined(USE_WAYLAND)
489 ee = ecore_evas_new("wayland_egl", 0, 0, width, height, 0);
491 ee = ecore_evas_new("opengl_x11", 0, 0, width, height, 0);
493 e = ecore_evas_get(ee);
495 ecore_evas_callback_delete_request_set(ee, _evas_close_cb);
497 #if defined(OS_TIZEN)
498 // Ignore fullscreen option, we should always go fullscreen on device.
499 Eina_Bool use_fullscreen = EINA_TRUE;
501 Eina_Bool use_fullscreen = fullscreen_enabled;
504 if (incognito == EINA_TRUE) {
505 fprintf(stderr, "Creating incognito web view\n");
506 view = ewk_view_add_in_incognito_mode(e);
507 context = ewk_view_context_get(view);
509 fprintf(stderr, "Creating normal web view\n");
510 view = ewk_view_add_with_context(e, context);
513 if (use_fullscreen) {
514 ecore_evas_fullscreen_set(ee, EINA_TRUE);
515 // When in fullscreen, we don't need to manually specify the dimensions of
518 evas_object_resize(view, width, height);
521 ecore_evas_callback_resize_set(ee, &on_evas_resize);
523 evas_object_event_callback_add(view, EVAS_CALLBACK_KEY_DOWN, on_key_down, view);
524 evas_object_event_callback_add(view, EVAS_CALLBACK_MOUSE_WHEEL, on_mouse_wheel, view);
525 evas_object_event_callback_add(view, EVAS_CALLBACK_MOUSE_UP , on_mouse_up, 0);
526 evas_object_show(view);
527 evas_object_focus_set(view, EINA_TRUE);
528 set_cache_policy(context);
530 disable_cache_for_context(context);
534 evas_object_smart_callback_add(view, "load,finished", __load_finished_cb, context);
535 evas_object_smart_callback_add(view, "load,error", __load_error_cb, 0);
536 evas_object_smart_callback_add(view, "url,changed", __uri_changed_cb,0);
537 evas_object_smart_callback_add(view, "usermedia,permission,request", __usermedia_permission_request_cb, NULL);
538 evas_object_smart_callback_add(view, "title,changed", __title_changed_cb,0);
539 evas_object_smart_callback_add(view, "load,progress", __load_progress_cb,0);
540 evas_object_smart_callback_add(view, "load,progress,started", __load_progress_started_cb,0);
541 evas_object_smart_callback_add(view, "load,progress,finished", __load_progress_finished_cb,0);
542 evas_object_smart_callback_add(view, "editorclient,ime,opened", __ime_input_panel_show_cb,0);
543 evas_object_smart_callback_add(view, "editorclient,ime,closed", __ime_input_panel_hide_cb,0);
544 evas_object_smart_callback_add(view, "editorclient,candidate,opened", __ime_candidate_panel_show_cb,0);
545 evas_object_smart_callback_add(view, "editorclient,candidate,closed", __ime_candidate_panel_hide_cb,0);
546 evas_object_smart_callback_add(view, "create,window", __create_window_cb, 0);
547 evas_object_smart_callback_add(view, "inputmethod,changed", __imf_input_method_changed_cb, 0);
548 evas_object_smart_callback_add(view, "load,committed", __did_commit_load_for_frame, 0);
549 evas_object_smart_callback_add(view, "load,provisional,started", __did_start_provisional_load_for_frame_cb, 0);
550 evas_object_smart_callback_add(view, "geolocation,permission,request", __geoLocation_popup_display_cb,0);
551 evas_object_smart_callback_add(view, "authentication,challenge", __auth_challenge_cb, 0);
552 evas_object_smart_callback_add(view, "policy,response,decide", __policy_response_decide_cb, 0);
553 evas_object_smart_callback_add(view, "contextmenu,customize", __customize_context_menu_cb, 0);
554 evas_object_smart_callback_add(view, "contextmenu,selected", __customize_context_menu_item_selected_cb, 0);
555 evas_object_smart_callback_add(view, "policy,navigation,decide", __navigation_policy_decide_cb,0);
556 evas_object_smart_callback_add(view, "text,found", __text_found_cb, 0);
557 evas_object_smart_callback_add(view, "policy,newwindow,decide", __newwindow_policy_cb,0);
558 evas_object_smart_callback_add(view, "load,nonemptylayout,finished", __load_nonemptylayout_finished_cb, 0);
559 evas_object_smart_callback_add(view, "popup,reply,wait,start", __popup_wait_start_cb,0);
560 evas_object_smart_callback_add(view, "popup,reply,wait,finish", __popup_wait_finish_cb,0);
561 evas_object_smart_callback_add(view, "clipboard,opened", __clipboard_opened_cb, 0);
562 ewk_context_did_start_download_callback_set(context, __download_callback, NULL);
563 evas_object_smart_callback_add(view, "frame,rendered", __frame_rendered_cb, 0);
564 evas_object_smart_callback_add(view, "load,started", __load_started_cb, context);
565 evas_object_smart_callback_add(view, "edge,left", __edge_left_cb, 0);
566 evas_object_smart_callback_add(view, "edge,right", __edge_right_cb, 0);
567 evas_object_smart_callback_add(view, "edge,top", __edge_top_cb, 0);
568 evas_object_smart_callback_add(view, "edge,bottom", __edge_bottom_cb, 0);
569 evas_object_smart_callback_add(view, "text,style,state", __text_style_state_changed_cb, 0);
570 evas_object_smart_callback_add(view, "back,forward,list,changed", __back_forward_list_changed_cb, 0);
571 evas_object_smart_callback_add(view, "webprocess,crashed", __webprocess_crashed_cb, 0);
572 evas_object_smart_callback_add(view, "undo,size", __undo_size_cb, 0);
573 evas_object_smart_callback_add(view, "redo,size", __redo_size_cb, 0);
575 ewk_notification_callbacks_set(__notification_show_cb, __notification_cancel_cb, 0);
576 ewk_view_custom_header_add(view, "X-Test-header", "X-Value-1");
578 ewk_view_notification_permission_callback_set(view, __notification_permission_cb, 0);
580 #if defined(OS_TIZEN)
581 if (IsMobileProfile() || IsWearableProfile()) {
582 ewk_context_vibration_client_callbacks_set(context, __vibration_on_cb, __vibration_off_cb, NULL);
586 ewk_context_mime_override_callback_set(context, __mime_override_cb, 0);
587 ewk_view_javascript_alert_callback_set(view, __ewk_view_javascript_alert_cb, 0);
588 ewk_view_javascript_confirm_callback_set(view, __ewk_view_javascript_confirm_cb, 0);
589 ewk_view_javascript_prompt_callback_set(view, __ewk_view_javascript_prompt_cb, 0);
590 evas_object_smart_callback_add(view, "console,message", __console_message_cb, 0);
593 set_cookie_policy = EWK_COOKIE_ACCEPT_POLICY_NEVER;
594 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context),
598 set_url_from_user_input(view, start_url);
601 ewk_view_script_execute(view, "console.log(\"Executed test script\");", __script_executed_cb, 0);
602 ecore_main_loop_begin();
603 ewk_context_unref(context);
604 // deleting view will release context
605 evas_object_del(view);
613 static void on_evas_resize(Ecore_Evas* ee)
616 ecore_evas_geometry_get(ee, NULL, NULL, &width, &height);
617 evas_object_resize(view, width, height);
620 void __ewk_cookie_manager_async_hostnames_get_cb(Eina_List *hostnames, Ewk_Error *error, void *event_info)
622 printf ("APP.C callback called __ewk_cookie_manager_async_hostnames_get_cb \n");
623 int host_count = eina_list_count(hostnames);
624 printf("APP.c total hosts received:%d\n",host_count);
625 if (clear_cookie_called) {
627 printf("APP.C clear cookie call did not delete cookies\n");
629 printf("APP.c all cookies cleared\n");
632 Ewk_Context* context = ewk_context_default_get();
634 printf("APP.C calling ewk_cookie_manager_cookies_clear\n");
635 if (!clear_cookie_called) {
636 clear_cookie_called = EINA_TRUE;
637 printf("APP.c calling ewk_view_get_cookies_for_url:%s\n",ewk_view_get_cookies_for_url(view, start_url));
638 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
639 printf("APP.c calling ewk_cookie_manager_async_hostnames_with_cookies_get\n");
640 ewk_cookie_manager_async_hostnames_with_cookies_get(ewk_context_cookie_manager_get(context),
641 __ewk_cookie_manager_async_hostnames_get_cb,
644 } else if ( EWK_COOKIE_ACCEPT_POLICY_NEVER == set_cookie_policy) {
645 printf("APP.C cookie policy was set to never now going to set accept except third party\n");
646 set_cookie_policy = EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY;
647 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), set_cookie_policy);
648 printf("APP.C Reload called from __ewk_cookie_manager_async_policy_get_cb\n");
649 ewk_view_reload(view);
651 if (!clear_cookie_called)
652 printf("APP.cc cookie count is 0 although policy was to accept\n");
656 const char* printCookiePolicy(Ewk_Cookie_Accept_Policy policy)
659 case EWK_COOKIE_ACCEPT_POLICY_ALWAYS :
660 return (" Accept Always ");
661 case EWK_COOKIE_ACCEPT_POLICY_NEVER :
662 return (" Accept Never ");
663 case EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY :
664 return (" No third party ");
669 void __ewk_cookie_manager_async_policy_get_cb(Ewk_Cookie_Accept_Policy policy,
671 printf ("APP.C callback called __ewk_cookie_manager_async_policy_get_cb \n");
672 if (set_cookie_policy != policy) {
673 printf("error in setting cookie policy");
676 Ewk_Context* context = ewk_context_default_get();
677 printf("APP.C cookie policy is set properly:%s\n", printCookiePolicy(policy));
678 printf("APP.c calling ewk_cookie_manager_async_hostnames_with_cookies_get\n");
679 ewk_cookie_manager_async_hostnames_with_cookies_get(ewk_context_cookie_manager_get(context),
680 __ewk_cookie_manager_async_hostnames_get_cb,
685 void __load_finished_cb(void *data, Evas_Object *obj, void *event_info)
687 printf ("APP.C callback called __load_finished_cb \n");
690 ewk_context_cache_clear((Ewk_Context*)data);
693 printf("calling get cookie policy async\n");
694 Ewk_Context* context = ewk_context_default_get();
695 ewk_cookie_manager_accept_policy_async_get(
696 ewk_context_cookie_manager_get(context),
697 __ewk_cookie_manager_async_policy_get_cb,
703 void __load_error_cb(void *data, Evas_Object *obj, void *event_info)
705 Ewk_Error* error = (Ewk_Error*)event_info;
706 printf("APP.C callback called __load_error_cb\n");
707 printf("error url : %s\n", ewk_error_url_get(error));
710 void __uri_changed_cb(void *data, Evas_Object *obj, void *event_info)
712 printf ("APP.C callback called __uri_changed_cb URI is = %s \n", (const char *)event_info);
715 void __title_changed_cb(void *data, Evas_Object *obj, void *event_info)
717 printf ("APP.C callback called __title_changed_cb URI is = %s \n", (const char *)event_info);
720 void __load_progress_cb(void *data, Evas_Object *obj, void *event_info)
722 printf ("APP.C callback called __load_progress_cb value is = %f \n", *((double *)event_info));
725 void __load_progress_started_cb(void *data, Evas_Object *obj, void *event_info)
727 printf ("APP.C callback called __load_progress_started_cb \n");
730 void __load_progress_finished_cb(void *data, Evas_Object *obj, void *event_info)
732 printf ("APP.C callback called __load_progress_finsihed_cb \n");
733 ewk_view_custom_header_remove(view, "X-Test-header");
736 ewk_view_contents_size_get(view, &width, &height);
737 printf("APP.c called ewk_view_contents_size_get. width = %d, height = %d\n", width, height);
738 ewk_view_scroll_size_get(view, &width, &height);
739 printf("APP.c called ewk_view_scroll_size_get. width = %d, height = %d\n", width, height);
740 printf("APP.c called ewk_view_load_progress_get : %f3\n", ewk_view_load_progress_get(obj));
741 printf("APP.c called ewk_view_title_get : %s\n", ewk_view_title_get(view));
744 void __ime_input_panel_show_cb(void* data, Evas_Object *obj, void* event_info)
746 printf ("APP.C callback called __ime_input_panel_show_cb \n");
749 void __ime_input_panel_hide_cb(void* data, Evas_Object *obj, void* event_info)
751 printf ("APP.C callback called __ime_input_panel_hide_cb \n");
754 void __ime_candidate_panel_show_cb(void* data, Evas_Object *obj, void* event_info)
756 printf ("APP.C callback called __ime_candidate_panel_show_cb \n");
759 void __ime_candidate_panel_hide_cb(void* data, Evas_Object *obj, void* event_info)
761 printf ("APP.C callback called __ime_candidate_panel_hide_cb \n");
764 void delete_popup_window(Ecore_Evas* ee)
769 void __create_window_cb(void *data, Evas_Object *obj, void *event_info)
771 printf ("APP.C callback called __create_window_cb \n");
773 // We have no information about preferred size with the current API.
774 const int default_width = 300;
775 const int default_height = 400;
777 #if defined(USE_WAYLAND)
778 Ecore_Evas* ee = ecore_evas_new("wayland_egl", 0, 0, default_width, default_height, 0);
780 Ecore_Evas* ee = ecore_evas_new("opengl_x11", 0, 0, default_width, default_height, 0);
782 Evas* e = ecore_evas_get(ee);
784 Evas_Object* view = ewk_view_add(e);
785 evas_object_resize(view, default_width, default_height);
786 evas_object_show(view);
787 evas_object_focus_set(view, EINA_TRUE);
790 evas_object_smart_callback_add(view, "close,window", __window_closed_cb, 0);
792 // Override default handler because it terminates the event loop.
793 ecore_evas_callback_delete_request_set(ee, delete_popup_window);
795 Evas_Object** result = (Evas_Object**) event_info;
799 void __window_closed_cb(void *data, Evas_Object *view, void *event_info)
801 printf ("APP.C callback called __close_window_cb \n");
803 Evas* e = evas_object_evas_get(view);
804 Ecore_Evas* ee = ecore_evas_ecore_evas_get(e);
805 evas_object_hide(view);
806 evas_object_focus_set(view, EINA_FALSE);
807 evas_object_del(view);
809 ecore_evas_ews_delete_request(ee);
812 void __imf_input_method_changed_cb(void *data, Evas_Object *obj, void *event_info)
814 Eina_Rectangle *rect = (Eina_Rectangle*)event_info;
815 printf ("APP.C callback called __imf_input_method_changed_cb Rect values are x = %d, y= %d, height = %d, width = %d\n",
816 rect->x, rect->y, rect->h, rect->w);
819 void __script_executed_cb(Evas_Object *obj, const char *javascript_result, void *data)
821 printf ("APP.C callback called __script_executed_cb called with result : %s\n", javascript_result);
824 void __did_start_provisional_load_for_frame_cb(void *data, Evas_Object *obj, void *event_info)
826 printf ("APP.C callback called __did_start_provisional_load_for_frame_cb \n");
829 void __did_commit_load_for_frame(void *data, Evas_Object *obj, void *event_info)
831 printf ("APP.C callback called __did_commit_load_for_frame \n");
834 void __geoLocation_popup_display_cb(void *data, Evas_Object *obj, void *event_info)
836 Ewk_Geolocation_Permission_Request *request = (Ewk_Geolocation_Permission_Request*)event_info;
838 const Ewk_Security_Origin * sec_origin = ewk_geolocation_permission_request_origin_get((const Ewk_Geolocation_Permission_Request*)request);
840 printf("APP.C callback called __geoLocation_popup_display_cb URL = %s, protocol = %s, port = %d\n",
841 ewk_security_origin_host_get(sec_origin), ewk_security_origin_protocol_get(sec_origin),ewk_security_origin_port_get(sec_origin));
842 printf ("APP.C callback called __geoLocation_popup_display_cb Setting permission\n");
843 ewk_geolocation_permission_request_set(request, 1);
846 printf ("APP.C callback called __geoLocation_popup_display_cb \n");
849 void __navigation_policy_decide_cb(void *data, Evas_Object *obj, void *event_info)
851 Ewk_Policy_Decision* decision = (Ewk_Policy_Decision*)event_info;
852 printf("APP.C callback called __navigation_policy_decide_cb \n");
853 printf("URL: %s\n", ewk_policy_decision_url_get(decision));
854 printf("Navigation type: %d", ewk_policy_decision_navigation_type_get(decision));
856 // download needs to be handled and ignore wont have any visible difference.
857 printf("Decision: USE\n");
858 ewk_policy_decision_use(decision);
861 void __auth_challenge_cb(void* data, Evas_Object *obj, void *event_info)
863 printf("APP.C callback called __auth_challenge_cb \n");
864 Ewk_Auth_Challenge* auth_challenge = (Ewk_Auth_Challenge*)event_info;
865 auth_challenge_holder = auth_challenge;
867 fprintf(stderr, "auth_challenge NULL\n");
869 const char* realm = ewk_auth_challenge_realm_get(auth_challenge);
870 const char* url = ewk_auth_challenge_url_get(auth_challenge);
872 fprintf(stderr, "realm or url NULL\n");
874 ewk_auth_challenge_suspend(auth_challenge);
875 show_userid_password_popup(url);
878 void show_userid_password_popup(const char* msg)
880 Evas_Object *popup = elm_win_util_standard_add("auth-window", msg);
882 fprintf(stderr,"Pop-up window creation failed");
885 elm_win_modal_set(popup, EINA_TRUE);
886 evas_object_size_hint_weight_set(popup , EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
887 evas_object_size_hint_align_set(popup , EVAS_HINT_FILL, EVAS_HINT_FILL);
888 evas_object_resize(popup, 400, 300);
889 evas_object_show(popup);
891 Evas_Object* box = elm_box_add(popup);
892 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
893 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
894 elm_win_resize_object_add(popup, box);
895 evas_object_show(box);
897 Evas_Object *user_name_lable = elm_label_add(popup);
898 elm_object_text_set(user_name_lable, "User name");
899 elm_box_pack_end(box, user_name_lable);
900 evas_object_show(user_name_lable);
902 Evas_Object *user_name_entry = elm_entry_add(popup);
903 elm_entry_single_line_set(user_name_entry, EINA_TRUE);
904 elm_object_text_set(user_name_entry, "Delete this and enter user name");
905 elm_object_focus_set(user_name_entry, EINA_TRUE);
906 elm_box_pack_end(box, user_name_entry);
907 evas_object_show(user_name_entry);
909 Evas_Object *password_lable = elm_label_add(popup);
910 elm_object_text_set(password_lable, "Password");
911 elm_box_pack_end(box, password_lable);
912 evas_object_show(password_lable);
914 Evas_Object *password_entry = elm_entry_add(popup);
915 elm_entry_single_line_set(password_entry, EINA_TRUE);
916 elm_entry_password_set(password_entry, EINA_TRUE);
917 elm_box_pack_end(box, password_entry);
918 evas_object_show(password_entry);
920 credentials[0] = user_name_entry;
921 credentials[1] = password_entry;
923 Evas_Object *login_button = elm_button_add(popup);
924 elm_object_text_set(login_button, "Login");
925 elm_box_pack_end(box, login_button);
926 evas_object_show(login_button);
928 evas_object_smart_callback_add(popup, "delete,request", __auth_close_button_cb, 0);
929 evas_object_smart_callback_add(login_button, "clicked", __auth_login_button_cb, popup);
932 void show_search_popup(void)
934 Evas_Object *popup = elm_win_util_standard_add("search-text", "Search Text");
936 fprintf(stderr,"Pop-up window creation failed");
939 evas_object_size_hint_weight_set(popup , EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
940 evas_object_size_hint_align_set(popup , EVAS_HINT_FILL, EVAS_HINT_FILL);
941 evas_object_resize(popup, 400, 300);
942 evas_object_show(popup);
944 Evas_Object* box = elm_box_add(popup);
945 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
946 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
947 elm_win_resize_object_add(popup, box);
948 evas_object_show(box);
950 Evas_Object *search_text_label = elm_label_add(popup);
951 elm_object_text_set(search_text_label, "Search Text: ");
952 elm_box_pack_end(box, search_text_label);
953 evas_object_show(search_text_label);
955 Evas_Object *search_text_entry = elm_entry_add(popup);
956 elm_entry_single_line_set(search_text_entry, EINA_TRUE);
957 elm_object_text_set(search_text_entry, "input search text");
958 elm_object_focus_set(search_text_entry, EINA_TRUE);
959 elm_box_pack_end(box, search_text_entry);
960 evas_object_show(search_text_entry);
962 Evas_Object *search_button = elm_button_add(popup);
963 elm_object_text_set(search_button, "Search");
964 elm_box_pack_end(box, search_button);
965 evas_object_show(search_button);
968 evas_object_smart_callback_add(popup, "delete,request", __search_closed_cb, 0);
969 evas_object_smart_callback_add(search_text_entry, "focused", __search_focused_cb, search_text_entry);
970 evas_object_smart_callback_add(search_text_entry, "unfocused", __search_unfocused_cb, search_text_entry);
971 evas_object_smart_callback_add(search_text_entry, "activated", __search_clicked_cb, search_text_entry);
972 evas_object_smart_callback_add(search_button, "clicked", __search_clicked_cb, search_text_entry);
975 void __search_closed_cb(void *data, Evas_Object *obj, void *event_info)
977 evas_object_del(obj);
980 void __search_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
982 Evas_Object* entry = data;
983 if (strcmp("", elm_entry_entry_get(entry)) == 0)
984 elm_entry_entry_set(entry, "input search text");
987 // Callback for showing permission request for media request
988 void __usermedia_permission_request_cb(void *data, Evas_Object *obj, void *event_info)
990 Ewk_User_Media_Permission_Request* permissionRequest=
991 (Ewk_User_Media_Permission_Request*)event_info;
992 // Simulating the User Pemission request for Allowing the media request.
993 ewk_user_media_permission_request_set(permissionRequest,EINA_TRUE);
994 printf("APP.C __usermedia_permission_request_cb Allowed User Media Request: \n");
997 void __search_focused_cb(void *data, Evas_Object *obj, void *event_info)
999 Evas_Object* entry = data;
1000 if (strcmp("input search text", elm_entry_entry_get(entry)) == 0)
1001 elm_entry_entry_set(entry, "");
1004 void __search_clicked_cb(void *data, Evas_Object *obj, void *event_info)
1006 Evas_Object* entry = data;
1007 if (strcmp("input search text", elm_entry_entry_get(entry)) != 0)
1008 ewk_view_text_find(view, elm_entry_entry_get(entry), EWK_FIND_OPTIONS_CASE_INSENSITIVE, 0);
1011 void __auth_login_button_cb(void *data, Evas_Object *obj, void *event_info)
1013 Evas_Object* popup_window = data;
1014 const char* username = elm_entry_entry_get(credentials[0]);
1015 const char* password = elm_entry_entry_get(credentials[1]);
1016 ewk_auth_challenge_credential_use(auth_challenge_holder, username, password);
1017 evas_object_del(popup_window);
1020 void __auth_close_button_cb(void *data, Evas_Object *obj, void *event_info)
1022 ewk_auth_challenge_credential_cancel(auth_challenge_holder);
1023 evas_object_del(obj);
1026 void __notification_cancel_byuser_cb(void *data, Evas_Object *obj, void *event_info)
1028 ewk_notification_closed(current_notification_id, EINA_TRUE);
1029 current_notification_id = 0;
1030 evas_object_hide(popup);
1031 evas_object_del(popup);
1034 void __notification_show_cb(Ewk_Notification* current_notification, void* event_info)
1036 if (current_notification) {
1037 printf("APP.C callback _notification_show_cb Details: \n");
1038 printf("APP.C callback Body = %s \n",ewk_notification_body_get(current_notification));
1039 printf("APP.C callback Title = %s\n",ewk_notification_title_get(current_notification));
1040 const Ewk_Security_Origin *org = ewk_notification_security_origin_get((const Ewk_Notification*)current_notification);
1041 printf("APP.C callback Origin Host = %s\n",ewk_security_origin_host_get(org));
1042 printf("APP.C callback Origin Protocol = %s\n",ewk_security_origin_protocol_get(org));
1043 printf("APP.C callback Origin Port = %d\n",ewk_security_origin_port_get(org));
1044 // Adding pop up code
1045 popup = elm_popup_add(view);
1046 Evas_Object* icon = ewk_notification_icon_get(current_notification, evas_object_evas_get(popup));
1048 elm_popup_allow_events_set(popup, EINA_TRUE);
1049 elm_object_text_set(popup,ewk_notification_body_get(current_notification));
1050 elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
1051 elm_object_part_text_set(popup, "title,text", ewk_notification_title_get(current_notification));
1052 elm_object_part_content_set(popup, "title,icon", icon);
1053 evas_object_show(popup);
1055 Evas_Object *btn1 = elm_button_add(popup);
1056 elm_object_text_set(btn1, "CLOSE");
1057 elm_object_part_content_set(popup, "button1", btn1);
1058 current_notification_id = ewk_notification_id_get(current_notification);
1059 evas_object_smart_callback_add(btn1, "clicked", __notification_cancel_byuser_cb, 0);
1061 printf ("APP.C callback called __notification_show_cb \n");
1064 Eina_Bool __notification_permission_cb(Evas_Object* o, Ewk_Notification_Permission_Request* request, void* user_data)
1067 const Ewk_Security_Origin *sec_origin = ewk_notification_permission_request_origin_get((const Ewk_Notification_Permission_Request*)request);
1069 printf("APP.C callback called __notification_permission_cb URL = %s, protocol = %s, port = %d\n",
1070 ewk_security_origin_host_get(sec_origin), ewk_security_origin_protocol_get(sec_origin),ewk_security_origin_port_get(sec_origin));
1072 ewk_notification_permission_reply(request, EINA_TRUE);
1077 void __notification_cancel_cb(uint64_t notification_id, void* event_info)
1079 evas_object_del(popup);
1080 printf("APP.C callback __notification_cancel_cb with notification id = %Lu\n", (long long unsigned int)notification_id);
1083 void __policy_response_decide_cb(void *data, Evas_Object *obj, void *event_info)
1085 printf("APP.C callback called __policy_response_decide_cb \n");
1086 Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
1087 Ewk_Policy_Decision_Type policy_type = ewk_policy_decision_type_get(policy_decision);
1088 const char *uri = ewk_policy_decision_url_get(policy_decision);
1089 const char *cookie = ewk_policy_decision_cookie_get(policy_decision);
1090 const char *mime = ewk_policy_decision_response_mime_get(policy_decision);
1091 printf("APP.C URL : %s\n", uri);
1092 printf("APP.C cookie : %s\n", cookie);
1093 printf("APP.C mime type : %s\n", mime);
1094 printf("APP.C policy type : %d\n", policy_type);
1095 ewk_policy_decision_use(policy_decision);
1098 void __customize_context_menu_cb(void* data, Evas_Object *obj, void *event_info)
1100 Ewk_Context_Menu *context_menu = (Ewk_Context_Menu*)event_info;
1101 ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_GO_BACK, "Back", 1);
1102 ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_GO_FORWARD, "Forward", 1);
1103 ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_RELOAD, "Reload", 1);
1104 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR, "Bk_fwd_clear", 1);
1105 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_CACHE_RUN, "Run App Cache Test", 1);
1106 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_CACHE_DELETE_ALL, "Delete All App Cache", 1);
1107 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_GRAB_SNAPSHOT, "Take Snapshot", 1);
1108 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_WEB_DATABASE_GET_ORIGINS, "Get WebDB", 1);
1109 ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_WEB_DATABASE_DELETE_ALL, "Clear WebDB", 1);
1110 printf("APP.C callback __customize_context_menu_cb \n");
1113 static void get_app_cache_usage_cb(int64_t usage, void* user_data)
1115 static unsigned int count_usage_callback = 0;
1116 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)user_data;
1117 printf("AppCache usage for %s is %ld\n", ewk_security_origin_host_get(origin), (long int)usage);
1118 ewk_context_application_cache_delete(ewk_context_default_get(), origin);
1119 if (eina_list_count(application_cache_origins) == ++count_usage_callback) {
1120 ewk_context_origins_free(application_cache_origins);
1121 count_usage_callback = 0;
1122 application_cache_origins = NULL;
1126 static void get_origins_for_cache_cb(Eina_List* origins, void* user_data)
1130 Eina_List* list_iterator = NULL;
1132 if (application_cache_origins) {
1133 fprintf(stderr, "APP/ERROR: First cache usage-delete cycle is still running.\n");
1137 application_cache_origins = origins;
1138 EINA_LIST_FOREACH(origins, list_iterator, data) {
1139 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(data);
1140 ewk_context_application_cache_usage_for_origin_get(ewk_context_default_get(), origin,
1141 get_app_cache_usage_cb, origin);
1145 static void get_origins_for_webDB_cb(Eina_List* origins, void* user_data)
1150 if (web_database_origins)
1153 Eina_List* list_iterator = NULL;
1155 web_database_origins = origins;
1156 static unsigned int flag = 0;
1157 EINA_LIST_FOREACH(origins, list_iterator, data) {
1158 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(data);
1159 printf("Web Database origin : %s\n", ewk_security_origin_host_get(origin));
1162 if(eina_list_count(web_database_origins) == flag) {
1164 ewk_context_origins_free(web_database_origins);
1165 web_database_origins = NULL;
1169 void __customize_context_menu_item_selected_cb(void* data, Evas_Object *obj, void *event_info)
1171 Ewk_Context_Menu_Item* item = (Ewk_Context_Menu_Item*)event_info;
1172 switch (ewk_context_menu_item_tag_get(item)) {
1173 case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW:
1174 printf("APP.C callback __customize_context_menu_item_selected_cb : Open In new Window Selected\n");
1176 const int default_width = 300;
1177 const int default_height = 400;
1179 Ecore_Evas* ee = ecore_evas_new("software_x11", 0, 0, default_width, default_height, 0);
1180 Evas* e = ecore_evas_get(ee);
1182 Evas_Object* new_view = ewk_view_add(e);
1183 ewk_view_url_set(new_view, ewk_context_menu_item_link_url_get(item));
1184 evas_object_resize(new_view, default_width, default_height);
1185 evas_object_show(new_view);
1186 evas_object_focus_set(new_view, EINA_TRUE);
1187 ecore_evas_show(ee);
1188 evas_object_smart_callback_add(new_view, "close,window", __window_closed_cb, 0);
1189 ecore_evas_callback_delete_request_set(ee, delete_popup_window);
1191 case FOR_TEST_APPLICATION_CACHE_RUN:
1192 if (ewk_context_application_cache_origins_get(ewk_context_default_get(),
1193 get_origins_for_cache_cb, NULL)) {
1194 printf("Getting origins for Application Cache\n");
1197 case FOR_TEST_APPLICATION_CACHE_DELETE_ALL:
1198 if (ewk_context_application_cache_delete_all(ewk_context_default_get()))
1199 printf("All app cache deleted\n");
1201 case FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR:
1202 printf("APP.C callback Bk_fwd_clear callback item selected cb\n");
1203 ewk_view_back_forward_list_clear(view);
1205 case FOR_TEST_GRAB_SNAPSHOT:
1206 printf("APP.C GRAB_SNAPSHOT selected\n");
1207 Eina_Rectangle snapshot_rect;
1208 snapshot_rect.x = snapshot_rect.y = 0;
1209 evas_object_geometry_get(view, NULL, NULL, &snapshot_rect.w, &snapshot_rect.h);
1210 Evas_Object* snapshot = ewk_view_screenshot_contents_get(view, snapshot_rect, 1.0, evas_object_evas_get(view));
1212 fprintf(stderr, "Failed to get snapshot\n");
1215 static char snapshot_filename[256];
1216 static int snapshot_count = 1;
1217 sprintf(snapshot_filename, "snapshot_img%04d.%s", snapshot_count++, "png");
1218 if (evas_object_image_save(snapshot, snapshot_filename, 0, 0))
1219 printf("Snapshot image saved in %s\n", snapshot_filename);
1221 printf("Snapshot image could not be saved\n");
1223 case FOR_TEST_WEB_DATABASE_GET_ORIGINS:
1224 if (ewk_context_web_database_origins_get(ewk_context_default_get(),
1225 get_origins_for_webDB_cb, NULL)) {
1226 printf("Getting Origins for Web Database\n");
1229 case FOR_TEST_WEB_DATABASE_DELETE_ALL:
1230 if (ewk_context_web_database_delete_all(ewk_context_default_get()))
1231 printf("All Web Databases deleted\n");
1238 void __text_found_cb(void *data, Evas_Object *obj, void *event_info)
1240 printf("text found : %u\n", *((unsigned int*)(event_info)));
1243 void __newwindow_policy_cb(void *data, Evas_Object *obj, void* policy)
1245 printf ("APP.C __newwindow_policy_cb called \n");
1246 Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)policy;
1247 const char* url = ewk_policy_decision_url_get(policy_decision);
1248 printf("APP.C url for new window: %s \n", url);
1249 ewk_policy_decision_use(policy_decision);
1252 void __load_nonemptylayout_finished_cb(void *data, Evas_Object *obj, void *event_info)
1254 printf ("APP.C callback called __load_nonemptylayout_finished_cb \n");
1257 void __popup_wait_start_cb(void *data, Evas_Object *obj, void* policy)
1259 printf("Popup wait start\n");
1262 void __popup_wait_finish_cb(void *data, Evas_Object *obj, void* policy)
1264 printf("Popup wait finish\n");
1267 void __download_callback(const char* download_url, void* user_data)
1269 printf("new download start callback is triggered:%s\n", download_url);
1272 void __frame_rendered_cb(void* data, Evas_Object* obj, void* event_info)
1274 printf ("APP.C callback called __frame_rendered_cb \n");
1278 evas_object_geometry_get(obj, NULL, NULL, &width, &height);
1279 if (ewk_view_contents_pdf_get(obj, width, height, pdf_filename))
1280 printf("\"Save as PDF\" request sent\n");
1282 printf("Failed to send \"Save as PDF\" request\n");
1286 void __ewk_view_plain_text_get_cb(Evas_Object* o, const char* content_text, void* user_data)
1289 printf("__ewk_view_plain_text_get_cb callback success --\n%s\n---user_data--%d\n",content_text,*(int*)(user_data));
1292 void __ewk_view_plain_text_get_cb_1(Evas_Object* o, const char* content_text, void* user_data)
1295 printf("__ewk_view_plain_text_get_cb_1 callback success --\n%s\n---user_data--%d\n",content_text,*(int*)(user_data));
1298 void __load_started_cb(void *data, Evas_Object *obj, void *event_info)
1300 printf("APP.c __load_started_cb called \n");
1303 void __edge_left_cb(void* data, Evas_Object* obj, void* event_info)
1305 printf("Edge_Left Notification\n");
1308 void __edge_right_cb(void* data, Evas_Object* obj, void* event_info)
1310 printf("Edge_Right Notification\n");
1313 void __edge_top_cb(void* data, Evas_Object* obj, void* event_info)
1315 printf("Edge_Top Notification\n");
1318 void __edge_bottom_cb(void* data, Evas_Object* obj, void* event_info)
1320 printf("Edge_Bottom Notification\n");
1323 #if defined(OS_TIZEN)
1324 Eina_Bool __vibration_timeout_cb(void *data)
1326 if (IsMobileProfile() || IsWearableProfile()) {
1327 g_haptic_timer_id = NULL;
1328 if (g_haptic_handle) {
1329 device_haptic_stop(g_haptic_handle, g_haptic_effect);
1330 device_haptic_close(g_haptic_handle);
1331 g_haptic_handle = NULL;
1334 return ECORE_CALLBACK_CANCEL;
1340 void __vibration_on_cb(uint64_t vibration_time, void *data)
1342 if (IsMobileProfile() || IsWearableProfile()) {
1343 printf("__vibration_on_cb called");
1344 uint64_t duration = vibration_time;
1346 if (g_haptic_timer_id) {
1347 ecore_timer_del(g_haptic_timer_id);
1348 g_haptic_timer_id = NULL;
1351 if (g_haptic_handle) {
1352 device_haptic_stop(g_haptic_handle, g_haptic_effect);
1353 device_haptic_close(g_haptic_handle);
1354 g_haptic_handle = NULL;
1357 if (device_haptic_open(0, &g_haptic_handle) != DEVICE_ERROR_NONE) {
1358 printf("__vibration_on_cb:device_haptic_open failed");
1362 device_haptic_vibrate(g_haptic_handle, duration, 100, &g_haptic_effect);
1363 double in = (double)((double)(duration) / (double)(1000));
1364 printf("__vibration_on_cb:duration=%f", in);
1366 g_haptic_timer_id = ecore_timer_add(in, __vibration_timeout_cb, NULL);
1370 void __vibration_off_cb(void *data)
1372 if (IsMobileProfile() || IsWearableProfile()) {
1373 printf("__vibration_off_cb called");
1374 if (g_haptic_timer_id) {
1375 ecore_timer_del(g_haptic_timer_id);
1376 g_haptic_timer_id = NULL;
1379 if (g_haptic_handle) {
1380 device_haptic_stop(g_haptic_handle, g_haptic_effect);
1381 device_haptic_close(g_haptic_handle);
1382 g_haptic_handle = NULL;
1388 void __text_style_state_changed_cb(void *data, Evas_Object *obj, void *event_info)
1390 Evas_Point start_point, end_point;
1392 Ewk_Text_Style *style = (Ewk_Text_Style*)event_info;
1393 printf ("APP.C __text_style_state_changed_cb called \n");
1394 printf ("APP.c ewk_text_style_underline_get = %d \n",ewk_text_style_underline_get(style));
1395 printf ("APP.c ewk_text_style_italic_get = %d \n",ewk_text_style_italic_get(style));
1396 printf ("APP.c ewk_text_style_bold_get = %d \n",ewk_text_style_bold_get(style));
1397 printf ("APP.c ewk_text_style_ordered_list_get = %d \n",ewk_text_style_ordered_list_get(style));
1398 printf ("APP.c ewk_text_style_unordered_list_get = %d \n",ewk_text_style_unordered_list_get(style));
1400 ewk_text_style_position_get(style, &start_point, &end_point);
1401 printf ("APP.c ewk_text_style_position_get start x = %d, y = %d, end x = %d, y = %d\n",
1402 start_point.x, start_point.y, end_point.x, end_point.y);
1404 ewk_text_style_bg_color_get(style, &r, &g, &b, &a);
1405 printf ("APP.c ewk_text_style_bg_color_get r = %d, g =%d, b = %d, a = %d\n", r, g ,b ,a);
1406 printf ("APP.c ewk_text_style_has_composition_get = %d \n",ewk_text_style_has_composition_get(style));
1407 printf ("APP.c ewk_text_style_align_center_get = %d \n",ewk_text_style_align_center_get(style));
1408 printf ("APP.c ewk_text_style_align_left_get = %d \n",ewk_text_style_align_left_get(style));
1409 printf ("APP.c ewk_text_style_align_right_get = %d \n",ewk_text_style_align_right_get(style));
1410 printf ("APP.c ewk_text_style_align_full_get = %d \n",ewk_text_style_align_full_get(style));
1413 void __hit_test_request_cb(Evas_Object* o, int x, int y, int hit_test_mode, Ewk_Hit_Test* ht, void* user_data)
1415 printf("HitTest: context %d\n", ewk_hit_test_result_context_get(ht));
1416 printf("HitTest: link uri %s\n", ewk_hit_test_link_uri_get(ht));
1417 printf("HitTest: link title %s\n", ewk_hit_test_link_title_get(ht));
1418 printf("HitTest: link label %s\n",ewk_hit_test_link_label_get(ht));
1419 printf("HitTest: image uri %s\n", ewk_hit_test_image_uri_get(ht));
1420 #if !defined(EWK_BRINGUP)
1421 printf("HitTest: media uri %s\n", ewk_hit_test_media_uri_get(ht));
1423 printf("HitTest: tag name %s\n", ewk_hit_test_tag_name_get(ht));
1424 printf("HitTest: node value %s\n", ewk_hit_test_node_value_get(ht));
1425 printf("HitTest: image length %d\n", ewk_hit_test_image_buffer_length_get(ht));
1426 printf("HitTest: filename extension %s\n", ewk_hit_test_image_file_name_extension_get(ht));
1427 if (ewk_hit_test_image_buffer_length_get(ht)) {
1428 // To verify the buffer, we write to file.
1429 // App might use its own engine to encode, we use evas API.
1430 Evas_Object* image = evas_object_image_add(e);
1431 evas_object_image_colorspace_set(image, EVAS_COLORSPACE_ARGB8888);
1432 evas_object_image_alpha_set(image, EINA_TRUE);
1433 evas_object_image_data_copy_set(image, ewk_hit_test_image_buffer_get(ht));
1434 static char filename_buffer[256];
1435 static int count = 1;
1436 sprintf(filename_buffer, "hit_test_img%04d.%s", count++, ewk_hit_test_image_file_name_extension_get(ht));
1437 if (evas_object_image_save(image, filename_buffer, 0, 0))
1438 printf("Hit test image saved in %s\n", filename_buffer);
1440 printf("Hit test image could not be saved\n");
1443 Eina_Hash *attr_hash = ewk_hit_test_attribute_hash_get(ht);
1445 eina_hash_foreach(attr_hash, _util_print_hit_test_result_hash_fn, NULL);
1450 void on_mouse_up(void* data, Evas* canvas, Evas_Object* obj, void* event_info)
1452 Evas_Event_Mouse_Up* event = (Evas_Event_Mouse_Up*)event_info;
1453 if (!evas_key_modifier_is_set(event->modifiers, "Shift"))
1456 ewk_view_hit_test_request(obj, event->canvas.x, event->canvas.y, EWK_HIT_TEST_MODE_ALL, __hit_test_request_cb, NULL);
1459 void __undo_size_cb(void* data, Evas_Object* obj, void* event_info)
1461 printf ("APP.C callback called __undo_size_cb\n");
1464 void __redo_size_cb(void* data, Evas_Object* obj, void* event_info)
1466 printf ("APP.C callback called __redo_size_cb \n");
1469 void __mhtml_save_cb(Evas_Object *obj, const char *mhtml_data, void *data)
1471 printf("APP.C __mhtml_save_cb callback called\n");
1472 printf("APP.C Data is \n %s \n\n", mhtml_data);
1475 void __clipboard_opened_cb(void* data, Evas_Object* view, void* event_info)
1477 printf("APP.C clipboard window opened\n");
1480 void __back_forward_list_changed_cb(void *data, Evas_Object *obj, void *event_info)
1482 printf("APP.C Back Forward List Changed Notification\n");
1485 Eina_Bool __ewk_view_javascript_alert_cb(Evas_Object* o, const char* alert_text, void* user_data)
1487 printf("APP.C javascript alert opened\n");
1492 Eina_Bool __ewk_view_javascript_confirm_cb(Evas_Object* o, const char* message, void* user_data)
1494 printf("APP.C javascript confirm popup opened\n");
1499 Eina_Bool __ewk_view_javascript_prompt_cb(Evas_Object* o, const char* message, const char* default_value, void* user_data)
1501 printf("APP.C javascript prompt popup opened\n");
1506 void __webprocess_crashed_cb(void* data, Evas_Object* obj, void* event_info)
1508 printf("APP.C callback __webprocess_crashed_cb \n");
1509 const char* message = "<html><body><h1>The renderer process has crashed!</h1>"
1510 "<a href=\"https://google.com\">Open google</a></body></html>";
1511 ewk_view_html_string_load(view, message, 0, 0);
1512 Eina_Bool* handled = (Eina_Bool*)event_info;
1513 *handled = EINA_TRUE;
1516 Eina_Bool __mime_override_cb(const char* url, const char *mime, char **new_mime, void* user_data)
1518 printf("APP.C callback %s, url: %s, mime: %s\n", __func__, url, mime);
1520 if (strcmp(url, "file://mytest.abc") == 0 ||
1521 strcmp(mime, "application/x-php") == 0) {
1522 *new_mime = strdup("text/html");
1529 void __console_message_cb(void *data, Evas_Object *obj, void *event_info)
1531 Ewk_Console_Message* console_message = (Ewk_Console_Message*)event_info;
1532 printf("APP.C callback called __console_message_cb\n");
1533 printf("console message:%s:", ewk_console_message_source_get(console_message));
1534 printf("%d:", ewk_console_message_line_get(console_message));
1535 printf("%d:", ewk_console_message_level_get(console_message));
1536 printf("%s\n", ewk_console_message_text_get(console_message));