e6343cb7755dce39d7fe0b2a653adf1615a7d2cb
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_webview_app / app.c
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.
4
5 #define _DEFAULT_SOURCE
6
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"
22
23 #include <Ecore.h>
24 #include <Ecore_Evas.h>
25 #include <Ecore_File.h>
26 #include <Ecore_Getopt.h>
27 #include "ecore_x_wayland_wrapper.h"
28 #include <Evas.h>
29 #include <Elementary.h>
30
31 #if defined(OS_TIZEN)
32 #include <device/haptic.h>
33 #endif
34
35 #include <unistd.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 static Ecore_Evas* ee;
40 static Evas* e;
41 static Evas_Object* view;
42 static Evas_Object *popup;
43
44 uint64_t current_notification_id;
45
46 static Ewk_Auth_Challenge* auth_challenge_holder = NULL;
47 static Evas_Object* credentials[2] = {0};//username and password
48
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;
64
65 #if defined(OS_TIZEN)
66 static haptic_device_h g_haptic_handle;
67 static Ecore_Timer *g_haptic_timer_id;
68 static haptic_effect_h g_haptic_effect;
69 #endif
70
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);
115
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);
133
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);
138 #endif
139
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);
147
148 enum {
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
156 };
157
158 static const Ecore_Getopt options = {
159   .prog = "efl_webview_app",
160   .usage = "%prog [options] [url]",
161   .strict = EINA_FALSE,
162   .descs = {
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",
170                                NULL),
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,
174   }
175 };
176
177 static Eina_Bool _util_print_hit_test_result_hash_fn(const Eina_Hash *hash, const void *key, void *data, void *fdata)
178 {
179   printf("HitTest attribute (%s): (%s)\n", (const char*)key, (char *)data);
180   return EINA_TRUE;
181 }
182
183
184 static void on_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
185 {
186     Evas_Event_Key_Down *ev = (Evas_Event_Key_Down*) event_info;
187     static int scroll_x = 0;
188     static int scroll_y = 0;
189
190     if (strcmp(ev->key, "XF86Back") == 0 || strcmp(ev->key, "XF86Stop") == 0)
191     {
192       if (ewk_view_text_selection_clear(view))
193         return;
194     }
195
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/");
199     }
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));
204     }
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));
209     }
210     else if (!strcmp(ev->key, "F4")) {
211       ewk_view_command_execute(view, "Undo", NULL);
212     }
213     else if (!strcmp(ev->key, "F5")) {
214         printf("selection text \"%s\"\n", ewk_view_text_selection_text_get(view));
215     }
216     else if (!strcmp(ev->key, "F6")) {
217         ewk_view_stop(view);
218     }
219     else if (!strcmp(ev->key, "F7")) {
220         static Eina_Bool visibility = EINA_TRUE;
221         visibility = !visibility;
222         ewk_view_visibility_set(view, visibility);
223     }
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");
226     }
227     else if (!strcmp(ev->key, "F9")) {
228         static int x;
229         static int y;
230         ewk_view_scroll_pos_get(view, &x, &y);
231         printf("scroll_pos_get %d, %d \n",x,y);
232     }
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");
236         else
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");
240         else
241             printf("\nEWK_VIEW_PLAIN_TEXT_GET_1 SUCCESS\n");
242     }
243     else if (!strcmp(ev->key, "F11")) {
244       ewk_view_command_execute(view, "Redo", NULL);
245     }
246     else if (evas_key_modifier_is_set(ev->modifiers, "Control")) {
247         if (!strcmp(ev->key, "f") || !strcmp(ev->key, "F"))
248             show_search_popup();
249         else if (!strcmp(ev->key, "s") || !strcmp(ev->key, "S"))
250           ewk_view_mhtml_data_get(view, __mhtml_save_cb, NULL);
251     }
252     else if (!strcmp(ev->key, "w") || !strcmp(ev->key, "W")) {
253         if(scroll_y >= 0) {
254           scroll_y -= 2;
255           ewk_view_scroll_set(view, scroll_x, scroll_y);
256           printf("scroll_set  %d, %d \n", scroll_x, scroll_y);
257         }
258     }
259     else if (!strcmp(ev->key, "s") || !strcmp(ev->key, "S")) {
260         scroll_y += 2;
261         ewk_view_scroll_set(view, scroll_x, scroll_y);
262         printf("scroll_set  %d, %d \n", scroll_x, scroll_y);
263     }
264     else if (!strcmp(ev->key, "d") || !strcmp(ev->key, "D")) {
265         scroll_x += 2;
266         ewk_view_scroll_set(view, scroll_x, scroll_y);
267         printf("scroll_set  %d, %d \n", scroll_x, scroll_y);
268     }
269     else if (!strcmp(ev->key, "a") || !strcmp(ev->key, "A")) {
270         if(scroll_x >= 0) {
271           scroll_x -= 2;
272           ewk_view_scroll_set(view, scroll_x, scroll_y);
273           printf("scroll_set  %d, %d \n", scroll_x, scroll_y);
274         }
275     }
276     else if (!strcmp(ev->key, "BackSpace") || !strcmp(ev->key, "XF86Back") ||
277         !strcmp(ev->key, "XF86Stop")) {
278         ewk_view_back(data);
279     }
280 }
281
282 static void on_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info)
283 {
284     Evas_Event_Mouse_Wheel* event = (Evas_Event_Mouse_Wheel*)event_info;
285     static double scale_factor = 1.0;
286
287     if (evas_key_modifier_is_set(event->modifiers, "Control"))
288     {
289         if (event->z == -1)
290             scale_factor += 0.1;
291         else
292             scale_factor -= 0.1;
293
294         printf("ewk_view_scale_set() : %lf (%d, %d)\n", scale_factor, event->output.x, event->output.y);
295
296         ewk_view_scale_set(view, scale_factor, event->output.x, event->output.y);
297     }
298 }
299
300 static Eina_Strbuf* create_url_with_scheme(const char* base_url, const char* scheme)
301 {
302   Eina_Strbuf* buffer = eina_strbuf_new();
303   eina_strbuf_append(buffer, scheme);
304   eina_strbuf_append(buffer, base_url);
305   return buffer;
306 }
307
308 static void set_url_from_user_input(Evas_Object* view, const char* url)
309 {
310   if (strstr(url, "://")) {
311     ewk_view_url_set(view, url);
312     return;
313   }
314
315   // Add scheme.
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://");
320     free(realpath);
321   } else {
322     full_url = create_url_with_scheme(url, "http://");
323   }
324
325   ewk_view_url_set(view, eina_strbuf_string_get(full_url));
326
327   eina_strbuf_free(full_url);
328 }
329
330 //set cache policy as per command line arguments
331 static void set_cache_policy(Ewk_Context* context)
332 {
333   if(!cache_policy) {
334     ewk_context_cache_model_set(context, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
335     return;
336   }
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);
343 }
344
345 static void set_csp(Evas_Object *ewk_view)
346 {
347   if(!ewk_view || !content_security_policy_type)
348     return;
349
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);
354 }
355
356 static void disable_cache_for_context(Ewk_Context* context)
357 {
358   ewk_context_cache_disabled_set(context, EINA_TRUE);
359 }
360
361 static void _evas_close_cb(Ecore_Evas* ee)
362 {
363   ecore_main_loop_quit();
364 }
365
366 int main(int argc, char** argv)
367 {
368   // Make sure this happens just once.
369   // By default the web process is the same program.
370   fprintf(stderr, "efl_webview_app starting...\n");
371
372   if (IsDesktopProfile()) {
373     fprintf(stderr, "Runtime Profile : DESKTOP\n");
374   } else if (IsMobileProfile()) {
375     fprintf(stderr, "Runtime Profile : MOBILE\n");
376   } else if (IsTvProfile()) {
377     fprintf(stderr, "Runtime Profile : TV\n");
378   } else if (IsWearableProfile()) {
379     fprintf(stderr, "Runtime Profile : WEARABLE\n");
380   } else if (IsIviProfile()) {
381     fprintf(stderr, "Runtime Profile : IVI\n");
382   } else if (IsCommonProfile()) {
383     fprintf(stderr, "Runtime Profile : COMMON\n");
384   } else {
385     fprintf(stderr, "Runtime Profile : UNKNOWN\n");
386   }
387
388   if (IsEmulatorArch()) {
389     fprintf(stderr, "Runtime Architecture : EMULATOR\n");
390   }
391
392   ewk_set_arguments(argc, argv);
393   setenv("ELM_ENGINE", "gl", 1);
394   elm_init(0,NULL);
395   if (!ewk_init())
396     return EXIT_FAILURE;
397   elm_init(0, NULL);
398   Ecore_Getopt_Value values[] = {
399     ECORE_GETOPT_VALUE_BOOL(fullscreen_enabled),
400     ECORE_GETOPT_VALUE_BOOL(clear_cache),
401     ECORE_GETOPT_VALUE_BOOL(test_cookie),
402     ECORE_GETOPT_VALUE_STR(cache_policy),
403     ECORE_GETOPT_VALUE_STR(content_security_policy),
404     ECORE_GETOPT_VALUE_STR(content_security_policy_type),
405     ECORE_GETOPT_VALUE_BOOL(disable_cache),
406     ECORE_GETOPT_VALUE_STR(pdf_filename),
407     ECORE_GETOPT_VALUE_NONE,
408   };
409
410   Eina_Bool incognito = EINA_FALSE;
411   int idx = ecore_getopt_parse(&options, values, argc, argv);
412   for (; idx < argc; ++idx) {
413     // Treat first argument not starting with - as the url to load
414     if (argv[idx][0] != '-') {
415       start_url = strdup(argv[idx]);
416     } else if (strcmp(argv[idx], "--incognito") == 0) {
417       incognito = EINA_TRUE;
418     }
419   }
420
421   if (!start_url) {
422     start_url = strdup("http://www.google.com");
423   }
424
425   Ewk_Context* context = NULL;
426
427   // TODO : ewk content creation for incognito mode also has to be moved here.
428   if (incognito == EINA_FALSE) {
429     context = ewk_context_default_get();
430   }
431
432   int width = 800;
433   int height = 600;
434
435 #if defined(USE_WAYLAND)
436   ee = ecore_evas_new("wayland_egl", 0, 0, width, height, 0);
437 #else
438   ee = ecore_evas_new("opengl_x11", 0, 0, width, height, 0);
439 #endif
440   e = ecore_evas_get(ee);
441
442   ecore_evas_callback_delete_request_set(ee, _evas_close_cb);
443
444 #if defined(OS_TIZEN)
445   // Ignore fullscreen option, we should always go fullscreen on device.
446   Eina_Bool use_fullscreen = EINA_TRUE;
447 #else
448   Eina_Bool use_fullscreen = fullscreen_enabled;
449 #endif
450
451   if (incognito == EINA_TRUE) {
452     fprintf(stderr, "Creating incognito web view\n");
453     view = ewk_view_add_in_incognito_mode(e);
454     context = ewk_view_context_get(view);
455   } else {
456     fprintf(stderr, "Creating normal web view\n");
457     view = ewk_view_add_with_context(e, context);
458   }
459
460   if (use_fullscreen) {
461     ecore_evas_fullscreen_set(ee, EINA_TRUE);
462     // When in fullscreen, we don't need to manually specify the dimensions of
463     // EwkView.
464   } else {
465     evas_object_resize(view, width, height);
466   }
467
468   ecore_evas_callback_resize_set(ee, &on_evas_resize);
469
470   evas_object_event_callback_add(view, EVAS_CALLBACK_KEY_DOWN, on_key_down, view);
471   evas_object_event_callback_add(view, EVAS_CALLBACK_MOUSE_WHEEL, on_mouse_wheel, view);
472   evas_object_event_callback_add(view, EVAS_CALLBACK_MOUSE_UP , on_mouse_up, 0);
473   evas_object_show(view);
474   evas_object_focus_set(view, EINA_TRUE);
475   set_cache_policy(context);
476   if (disable_cache) {
477     disable_cache_for_context(context);
478   }
479   set_csp(view);
480
481   evas_object_smart_callback_add(view, "load,finished", __load_finished_cb, context);
482   evas_object_smart_callback_add(view, "load,error", __load_error_cb, 0);
483   evas_object_smart_callback_add(view, "url,changed", __uri_changed_cb,0);
484   evas_object_smart_callback_add(view, "usermedia,permission,request", __usermedia_permission_request_cb, NULL);
485   evas_object_smart_callback_add(view, "title,changed", __title_changed_cb,0);
486   evas_object_smart_callback_add(view, "load,progress", __load_progress_cb,0);
487   evas_object_smart_callback_add(view, "load,progress,started", __load_progress_started_cb,0);
488   evas_object_smart_callback_add(view, "load,progress,finished", __load_progress_finished_cb,0);
489   evas_object_smart_callback_add(view, "editorclient,ime,opened", __ime_input_panel_show_cb,0);
490   evas_object_smart_callback_add(view, "editorclient,ime,closed", __ime_input_panel_hide_cb,0);
491   evas_object_smart_callback_add(view, "editorclient,candidate,opened", __ime_candidate_panel_show_cb,0);
492   evas_object_smart_callback_add(view, "editorclient,candidate,closed", __ime_candidate_panel_hide_cb,0);
493   evas_object_smart_callback_add(view, "create,window", __create_window_cb, 0);
494   evas_object_smart_callback_add(view, "inputmethod,changed", __imf_input_method_changed_cb, 0);
495   evas_object_smart_callback_add(view, "load,committed", __did_commit_load_for_frame, 0);
496   evas_object_smart_callback_add(view, "load,provisional,started", __did_start_provisional_load_for_frame_cb, 0);
497   evas_object_smart_callback_add(view, "geolocation,permission,request", __geoLocation_popup_display_cb,0);
498   evas_object_smart_callback_add(view, "authentication,challenge", __auth_challenge_cb, 0);
499   evas_object_smart_callback_add(view, "policy,response,decide", __policy_response_decide_cb, 0);
500   evas_object_smart_callback_add(view, "contextmenu,customize", __customize_context_menu_cb, 0);
501   evas_object_smart_callback_add(view, "contextmenu,selected", __customize_context_menu_item_selected_cb, 0);
502   evas_object_smart_callback_add(view, "policy,navigation,decide", __navigation_policy_decide_cb,0);
503   evas_object_smart_callback_add(view, "text,found", __text_found_cb, 0);
504   evas_object_smart_callback_add(view, "policy,newwindow,decide", __newwindow_policy_cb,0);
505   evas_object_smart_callback_add(view, "load,nonemptylayout,finished", __load_nonemptylayout_finished_cb, 0);
506   evas_object_smart_callback_add(view, "popup,reply,wait,start", __popup_wait_start_cb,0);
507   evas_object_smart_callback_add(view, "popup,reply,wait,finish", __popup_wait_finish_cb,0);
508   evas_object_smart_callback_add(view, "clipboard,opened", __clipboard_opened_cb, 0);
509   ewk_context_did_start_download_callback_set(context, __download_callback, NULL);
510   evas_object_smart_callback_add(view, "frame,rendered", __frame_rendered_cb, 0);
511   evas_object_smart_callback_add(view, "load,started", __load_started_cb, context);
512   evas_object_smart_callback_add(view, "edge,left", __edge_left_cb, 0);
513   evas_object_smart_callback_add(view, "edge,right", __edge_right_cb, 0);
514   evas_object_smart_callback_add(view, "edge,top", __edge_top_cb, 0);
515   evas_object_smart_callback_add(view, "edge,bottom", __edge_bottom_cb, 0);
516   evas_object_smart_callback_add(view, "text,style,state", __text_style_state_changed_cb, 0);
517   evas_object_smart_callback_add(view, "back,forward,list,changed", __back_forward_list_changed_cb, 0);
518   evas_object_smart_callback_add(view, "webprocess,crashed", __webprocess_crashed_cb, 0);
519   evas_object_smart_callback_add(view, "undo,size", __undo_size_cb, 0);
520   evas_object_smart_callback_add(view, "redo,size", __redo_size_cb, 0);
521
522   ewk_notification_callbacks_set(__notification_show_cb, __notification_cancel_cb, 0);
523   ewk_view_custom_header_add(view, "X-Test-header", "X-Value-1");
524
525   ewk_view_notification_permission_callback_set(view, __notification_permission_cb, 0);
526
527 #if defined(OS_TIZEN)
528   if (IsMobileProfile() || IsWearableProfile()) {
529     ewk_context_vibration_client_callbacks_set(context, __vibration_on_cb, __vibration_off_cb, NULL);
530   }
531 #endif
532
533   ewk_context_mime_override_callback_set(context, __mime_override_cb, 0);
534   ewk_view_javascript_alert_callback_set(view, __ewk_view_javascript_alert_cb, 0);
535   ewk_view_javascript_confirm_callback_set(view, __ewk_view_javascript_confirm_cb, 0);
536   ewk_view_javascript_prompt_callback_set(view, __ewk_view_javascript_prompt_cb, 0);
537   evas_object_smart_callback_add(view, "console,message", __console_message_cb, 0);
538
539   if(test_cookie) {
540     set_cookie_policy = EWK_COOKIE_ACCEPT_POLICY_NEVER;
541     ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context),
542                                          set_cookie_policy);
543   }
544
545   set_url_from_user_input(view, start_url);
546
547   ecore_evas_show(ee);
548   ewk_view_script_execute(view, "console.log(\"Executed test script\");", __script_executed_cb, 0);
549   ecore_main_loop_begin();
550   ewk_context_unref(context);
551   // deleting view will release context
552   evas_object_del(view);
553   ewk_shutdown();
554
555   free(start_url);
556
557   return 0;
558 }
559
560 static void on_evas_resize(Ecore_Evas* ee)
561 {
562   int width, height;
563   ecore_evas_geometry_get(ee, NULL, NULL, &width, &height);
564   evas_object_resize(view, width, height);
565 }
566
567 void __ewk_cookie_manager_async_hostnames_get_cb(Eina_List *hostnames, Ewk_Error *error, void *event_info)
568 {
569   printf ("APP.C callback called __ewk_cookie_manager_async_hostnames_get_cb \n");
570   int host_count = eina_list_count(hostnames);
571   printf("APP.c total hosts received:%d\n",host_count);
572   if (clear_cookie_called) {
573     if (host_count)
574       printf("APP.C clear cookie call did not delete cookies\n");
575     else
576       printf("APP.c all cookies cleared\n");
577   }
578
579   Ewk_Context* context = ewk_context_default_get();
580   if (host_count) {
581     printf("APP.C  calling ewk_cookie_manager_cookies_clear\n");
582     if (!clear_cookie_called) {
583       clear_cookie_called = EINA_TRUE;
584       printf("APP.c calling ewk_view_get_cookies_for_url:%s\n",ewk_view_get_cookies_for_url(view, start_url));
585       ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
586       printf("APP.c calling ewk_cookie_manager_async_hostnames_with_cookies_get\n");
587       ewk_cookie_manager_async_hostnames_with_cookies_get(ewk_context_cookie_manager_get(context),
588                                                           __ewk_cookie_manager_async_hostnames_get_cb,
589                                                           NULL);
590     }
591   } else if ( EWK_COOKIE_ACCEPT_POLICY_NEVER == set_cookie_policy) {
592     printf("APP.C  cookie policy was set to never now going to set accept except third party\n");
593     set_cookie_policy = EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY;
594     ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), set_cookie_policy);
595     printf("APP.C Reload called from __ewk_cookie_manager_async_policy_get_cb\n");
596     ewk_view_reload(view);
597   } else {
598     if (!clear_cookie_called)
599       printf("APP.cc cookie count is 0 although policy was to accept\n");
600   }
601 }
602
603 const char* printCookiePolicy(Ewk_Cookie_Accept_Policy policy)
604 {
605   switch(policy) {
606     case EWK_COOKIE_ACCEPT_POLICY_ALWAYS :
607       return (" Accept Always ");
608     case EWK_COOKIE_ACCEPT_POLICY_NEVER :
609       return (" Accept Never ");
610     case EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY :
611       return (" No third party ");
612   }
613   return ("");
614 }
615
616 void __ewk_cookie_manager_async_policy_get_cb(Ewk_Cookie_Accept_Policy policy,
617                                               void *event_info) {
618   printf ("APP.C callback called __ewk_cookie_manager_async_policy_get_cb \n");
619   if (set_cookie_policy != policy) {
620     printf("error in setting cookie policy");
621   }
622   else {
623     Ewk_Context* context = ewk_context_default_get();
624     printf("APP.C cookie policy is set properly:%s\n", printCookiePolicy(policy));
625     printf("APP.c calling ewk_cookie_manager_async_hostnames_with_cookies_get\n");
626     ewk_cookie_manager_async_hostnames_with_cookies_get(ewk_context_cookie_manager_get(context),
627                                                         __ewk_cookie_manager_async_hostnames_get_cb,
628                                                         NULL);
629   }
630 }
631
632 void __load_finished_cb(void *data, Evas_Object *obj, void *event_info)
633 {
634   printf ("APP.C callback called __load_finished_cb \n");
635
636   if(clear_cache)
637     ewk_context_cache_clear((Ewk_Context*)data);
638
639   if(test_cookie) {
640     printf("calling get cookie policy async\n");
641     Ewk_Context* context = ewk_context_default_get();
642     ewk_cookie_manager_accept_policy_async_get(
643         ewk_context_cookie_manager_get(context),
644         __ewk_cookie_manager_async_policy_get_cb,
645         NULL);
646   }
647
648 }
649
650 void __load_error_cb(void *data, Evas_Object *obj, void *event_info)
651 {
652   Ewk_Error* error = (Ewk_Error*)event_info;
653   printf("APP.C callback called __load_error_cb\n");
654   printf("error url : %s\n", ewk_error_url_get(error));
655 }
656
657 void __uri_changed_cb(void *data, Evas_Object *obj, void *event_info)
658 {
659   printf ("APP.C callback called __uri_changed_cb URI is = %s \n", (const char *)event_info);
660 }
661
662 void __title_changed_cb(void *data, Evas_Object *obj, void *event_info)
663 {
664   printf ("APP.C callback called __title_changed_cb URI is = %s \n", (const char *)event_info);
665 }
666
667 void __load_progress_cb(void *data, Evas_Object *obj, void *event_info)
668 {
669   printf ("APP.C callback called __load_progress_cb value is = %f \n", *((double *)event_info));
670 }
671
672 void __load_progress_started_cb(void *data, Evas_Object *obj, void *event_info)
673 {
674   printf ("APP.C callback called __load_progress_started_cb \n");
675 }
676
677 void __load_progress_finished_cb(void *data, Evas_Object *obj, void *event_info)
678 {
679   printf ("APP.C callback called __load_progress_finsihed_cb \n");
680   ewk_view_custom_header_remove(view, "X-Test-header");
681
682   int width, height;
683   ewk_view_contents_size_get(view, &width, &height);
684   printf("APP.c called ewk_view_contents_size_get. width = %d, height = %d\n", width, height);
685   ewk_view_scroll_size_get(view, &width, &height);
686   printf("APP.c called ewk_view_scroll_size_get. width = %d, height = %d\n", width, height);
687   printf("APP.c called ewk_view_load_progress_get : %f3\n", ewk_view_load_progress_get(obj));
688   printf("APP.c called ewk_view_title_get   : %s\n", ewk_view_title_get(view));
689 }
690
691 void __ime_input_panel_show_cb(void* data, Evas_Object *obj, void* event_info)
692 {
693   printf ("APP.C callback called __ime_input_panel_show_cb \n");
694 }
695
696 void __ime_input_panel_hide_cb(void* data, Evas_Object *obj, void* event_info)
697 {
698   printf ("APP.C callback called __ime_input_panel_hide_cb \n");
699 }
700
701 void __ime_candidate_panel_show_cb(void* data, Evas_Object *obj, void* event_info)
702 {
703   printf ("APP.C callback called __ime_candidate_panel_show_cb \n");
704 }
705
706 void __ime_candidate_panel_hide_cb(void* data, Evas_Object *obj, void* event_info)
707 {
708   printf ("APP.C callback called __ime_candidate_panel_hide_cb \n");
709 }
710
711 void delete_popup_window(Ecore_Evas* ee)
712 {
713   ecore_evas_free(ee);
714 }
715
716 void __create_window_cb(void *data, Evas_Object *obj, void *event_info)
717 {
718   printf ("APP.C callback called __create_window_cb \n");
719
720   // We have no information about preferred size with the current API.
721   const int default_width = 300;
722   const int default_height =  400;
723
724 #if defined(USE_WAYLAND)
725   Ecore_Evas* ee = ecore_evas_new("wayland_egl", 0, 0, default_width, default_height, 0);
726 #else
727   Ecore_Evas* ee = ecore_evas_new("opengl_x11", 0, 0, default_width, default_height, 0);
728 #endif
729   Evas* e = ecore_evas_get(ee);
730
731   Evas_Object* view = ewk_view_add(e);
732   evas_object_resize(view, default_width, default_height);
733   evas_object_show(view);
734   evas_object_focus_set(view, EINA_TRUE);
735   ecore_evas_show(ee);
736
737   evas_object_smart_callback_add(view, "close,window", __window_closed_cb, 0);
738
739   // Override default handler because it terminates the event loop.
740   ecore_evas_callback_delete_request_set(ee, delete_popup_window);
741
742   Evas_Object** result = (Evas_Object**) event_info;
743   *result = view;
744 }
745
746 void __window_closed_cb(void *data, Evas_Object *view, void *event_info)
747 {
748   printf ("APP.C callback called __close_window_cb \n");
749
750   Evas* e = evas_object_evas_get(view);
751   Ecore_Evas* ee = ecore_evas_ecore_evas_get(e);
752   evas_object_hide(view);
753   evas_object_focus_set(view, EINA_FALSE);
754   evas_object_del(view);
755
756   ecore_evas_ews_delete_request(ee);
757 }
758
759 void __imf_input_method_changed_cb(void *data, Evas_Object *obj, void *event_info)
760 {
761   Eina_Rectangle *rect = (Eina_Rectangle*)event_info;
762   printf ("APP.C callback called __imf_input_method_changed_cb Rect values are x = %d, y= %d, height = %d, width = %d\n",
763            rect->x, rect->y, rect->h, rect->w);
764 }
765
766 void __script_executed_cb(Evas_Object *obj, const char *javascript_result, void *data)
767 {
768   printf ("APP.C callback called __script_executed_cb called with result : %s\n", javascript_result);
769 }
770
771 void __did_start_provisional_load_for_frame_cb(void *data, Evas_Object *obj, void *event_info)
772 {
773   printf ("APP.C callback called __did_start_provisional_load_for_frame_cb \n");
774 }
775
776 void __did_commit_load_for_frame(void *data, Evas_Object *obj, void *event_info)
777 {
778   printf ("APP.C callback called __did_commit_load_for_frame \n");
779 }
780
781 void __geoLocation_popup_display_cb(void *data, Evas_Object *obj, void *event_info)
782 {
783   Ewk_Geolocation_Permission_Request *request = (Ewk_Geolocation_Permission_Request*)event_info;
784   if (request) {
785       const Ewk_Security_Origin * sec_origin = ewk_geolocation_permission_request_origin_get((const Ewk_Geolocation_Permission_Request*)request);
786       if (sec_origin) {
787           printf("APP.C callback called __geoLocation_popup_display_cb URL = %s, protocol = %s, port = %d\n",
788           ewk_security_origin_host_get(sec_origin), ewk_security_origin_protocol_get(sec_origin),ewk_security_origin_port_get(sec_origin));
789           printf ("APP.C callback called __geoLocation_popup_display_cb Setting permission\n");
790           ewk_geolocation_permission_request_set(request, 1);
791       }
792   }
793   printf ("APP.C callback called __geoLocation_popup_display_cb \n");
794 }
795
796 void __navigation_policy_decide_cb(void *data, Evas_Object *obj, void *event_info)
797 {
798   Ewk_Policy_Decision* decision = (Ewk_Policy_Decision*)event_info;
799   printf("APP.C callback called __navigation_policy_decide_cb \n");
800   printf("URL: %s\n", ewk_policy_decision_url_get(decision));
801   printf("Navigation type: %d", ewk_policy_decision_navigation_type_get(decision));
802   // we only set USE
803   // download needs to be handled and ignore wont have any visible difference.
804   printf("Decision: USE\n");
805   ewk_policy_decision_use(decision);
806 }
807
808 void __auth_challenge_cb(void* data, Evas_Object *obj, void *event_info)
809 {
810   printf("APP.C callback called __auth_challenge_cb \n");
811   Ewk_Auth_Challenge* auth_challenge = (Ewk_Auth_Challenge*)event_info;
812   auth_challenge_holder = auth_challenge;
813   if (!auth_challenge)
814     fprintf(stderr, "auth_challenge NULL\n");
815
816   const char* realm = ewk_auth_challenge_realm_get(auth_challenge);
817   const char* url = ewk_auth_challenge_url_get(auth_challenge);
818   if (!realm || !url)
819     fprintf(stderr, "realm or url NULL\n");
820
821   ewk_auth_challenge_suspend(auth_challenge);
822   show_userid_password_popup(url);
823 }
824
825 void show_userid_password_popup(const char* msg)
826 {
827   Evas_Object *popup = elm_win_util_standard_add("auth-window", msg);
828   if (!popup) {
829     fprintf(stderr,"Pop-up window creation failed");
830     return;
831   }
832   elm_win_modal_set(popup, EINA_TRUE);
833   evas_object_size_hint_weight_set(popup , EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
834   evas_object_size_hint_align_set(popup , EVAS_HINT_FILL, EVAS_HINT_FILL);
835   evas_object_resize(popup, 400, 300);
836   evas_object_show(popup);
837
838   Evas_Object* box = elm_box_add(popup);
839   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
840   evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
841   elm_win_resize_object_add(popup, box);
842   evas_object_show(box);
843
844   Evas_Object *user_name_lable = elm_label_add(popup);
845   elm_object_text_set(user_name_lable, "User name");
846   elm_box_pack_end(box, user_name_lable);
847   evas_object_show(user_name_lable);
848
849   Evas_Object *user_name_entry = elm_entry_add(popup);
850   elm_entry_single_line_set(user_name_entry, EINA_TRUE);
851   elm_object_text_set(user_name_entry, "Delete this and enter user name");
852   elm_object_focus_set(user_name_entry, EINA_TRUE);
853   elm_box_pack_end(box, user_name_entry);
854   evas_object_show(user_name_entry);
855
856   Evas_Object *password_lable = elm_label_add(popup);
857   elm_object_text_set(password_lable, "Password");
858   elm_box_pack_end(box, password_lable);
859   evas_object_show(password_lable);
860
861   Evas_Object *password_entry = elm_entry_add(popup);
862   elm_entry_single_line_set(password_entry, EINA_TRUE);
863   elm_entry_password_set(password_entry, EINA_TRUE);
864   elm_box_pack_end(box, password_entry);
865   evas_object_show(password_entry);
866
867   credentials[0] = user_name_entry;
868   credentials[1] = password_entry;
869
870   Evas_Object *login_button = elm_button_add(popup);
871   elm_object_text_set(login_button, "Login");
872   elm_box_pack_end(box, login_button);
873   evas_object_show(login_button);
874
875   evas_object_smart_callback_add(popup, "delete,request", __auth_close_button_cb, 0);
876   evas_object_smart_callback_add(login_button, "clicked", __auth_login_button_cb, popup);
877 }
878
879 void show_search_popup(void)
880 {
881   Evas_Object *popup = elm_win_util_standard_add("search-text", "Search Text");
882   if (!popup) {
883     fprintf(stderr,"Pop-up window creation failed");
884     return;
885   }
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);
890
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);
896
897   Evas_Object *search_text_label = elm_label_add(popup);
898   elm_object_text_set(search_text_label, "Search Text: ");
899   elm_box_pack_end(box, search_text_label);
900   evas_object_show(search_text_label);
901
902   Evas_Object *search_text_entry = elm_entry_add(popup);
903   elm_entry_single_line_set(search_text_entry, EINA_TRUE);
904   elm_object_text_set(search_text_entry, "input search text");
905   elm_object_focus_set(search_text_entry, EINA_TRUE);
906   elm_box_pack_end(box, search_text_entry);
907   evas_object_show(search_text_entry);
908
909   Evas_Object *search_button = elm_button_add(popup);
910   elm_object_text_set(search_button, "Search");
911   elm_box_pack_end(box, search_button);
912   evas_object_show(search_button);
913
914
915   evas_object_smart_callback_add(popup, "delete,request", __search_closed_cb, 0);
916   evas_object_smart_callback_add(search_text_entry, "focused", __search_focused_cb, search_text_entry);
917   evas_object_smart_callback_add(search_text_entry, "unfocused", __search_unfocused_cb, search_text_entry);
918   evas_object_smart_callback_add(search_text_entry, "activated", __search_clicked_cb, search_text_entry);
919   evas_object_smart_callback_add(search_button, "clicked", __search_clicked_cb, search_text_entry);
920 }
921
922 void __search_closed_cb(void *data, Evas_Object *obj, void *event_info)
923 {
924   evas_object_del(obj);
925 }
926
927 void __search_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
928 {
929   Evas_Object* entry = data;
930   if (strcmp("", elm_entry_entry_get(entry)) == 0)
931     elm_entry_entry_set(entry, "input search text");
932 }
933
934 // Callback for showing permission request for media request
935 void __usermedia_permission_request_cb(void *data, Evas_Object *obj, void *event_info)
936 {
937   Ewk_User_Media_Permission_Request* permissionRequest=
938       (Ewk_User_Media_Permission_Request*)event_info;
939   // Simulating the User Pemission request for Allowing the media request.
940   ewk_user_media_permission_request_set(permissionRequest,EINA_TRUE);
941   printf("APP.C __usermedia_permission_request_cb Allowed User Media Request: \n");
942 }
943
944 void __search_focused_cb(void *data, Evas_Object *obj, void *event_info)
945 {
946   Evas_Object* entry = data;
947   if (strcmp("input search text", elm_entry_entry_get(entry)) == 0)
948     elm_entry_entry_set(entry, "");
949 }
950
951 void __search_clicked_cb(void *data, Evas_Object *obj, void *event_info)
952 {
953   Evas_Object* entry = data;
954   if (strcmp("input search text", elm_entry_entry_get(entry)) != 0)
955     ewk_view_text_find(view, elm_entry_entry_get(entry), EWK_FIND_OPTIONS_CASE_INSENSITIVE, 0);
956 }
957
958 void __auth_login_button_cb(void *data, Evas_Object *obj, void *event_info)
959 {
960   Evas_Object* popup_window = data;
961   const char* username = elm_entry_entry_get(credentials[0]);
962   const char* password = elm_entry_entry_get(credentials[1]);
963   ewk_auth_challenge_credential_use(auth_challenge_holder, username, password);
964   evas_object_del(popup_window);
965 }
966
967 void __auth_close_button_cb(void *data, Evas_Object *obj, void *event_info)
968 {
969   ewk_auth_challenge_credential_cancel(auth_challenge_holder);
970   evas_object_del(obj);
971 }
972
973 void __notification_cancel_byuser_cb(void *data, Evas_Object *obj, void *event_info)
974 {
975    ewk_notification_closed(current_notification_id, EINA_TRUE);
976    current_notification_id = 0;
977    evas_object_hide(popup);
978    evas_object_del(popup);
979 }
980
981 void __notification_show_cb(Ewk_Notification* current_notification, void* event_info)
982 {
983   if (current_notification) {
984     printf("APP.C callback _notification_show_cb Details: \n");
985     printf("APP.C callback Body = %s \n",ewk_notification_body_get(current_notification));
986     printf("APP.C callback Title = %s\n",ewk_notification_title_get(current_notification));
987     const Ewk_Security_Origin *org = ewk_notification_security_origin_get((const Ewk_Notification*)current_notification);
988     printf("APP.C callback Origin Host = %s\n",ewk_security_origin_host_get(org));
989     printf("APP.C callback Origin Protocol = %s\n",ewk_security_origin_protocol_get(org));
990     printf("APP.C callback Origin Port = %d\n",ewk_security_origin_port_get(org));
991     // Adding pop up code
992     popup = elm_popup_add(view);
993     Evas_Object* icon = ewk_notification_icon_get(current_notification, evas_object_evas_get(popup));
994
995     elm_popup_allow_events_set(popup, EINA_TRUE);
996     elm_object_text_set(popup,ewk_notification_body_get(current_notification));
997     elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
998     elm_object_part_text_set(popup, "title,text", ewk_notification_title_get(current_notification));
999     elm_object_part_content_set(popup, "title,icon", icon);
1000     evas_object_show(popup);
1001
1002     Evas_Object *btn1 = elm_button_add(popup);
1003     elm_object_text_set(btn1, "CLOSE");
1004     elm_object_part_content_set(popup, "button1", btn1);
1005     current_notification_id = ewk_notification_id_get(current_notification);
1006     evas_object_smart_callback_add(btn1, "clicked", __notification_cancel_byuser_cb, 0);
1007   }
1008   printf ("APP.C callback called __notification_show_cb \n");
1009 }
1010
1011 Eina_Bool __notification_permission_cb(Evas_Object* o, Ewk_Notification_Permission_Request* request, void* user_data)
1012 {
1013   if(request) {
1014     const Ewk_Security_Origin *sec_origin = ewk_notification_permission_request_origin_get((const Ewk_Notification_Permission_Request*)request);
1015     if (sec_origin) {
1016         printf("APP.C callback called __notification_permission_cb URL = %s, protocol = %s, port = %d\n",
1017         ewk_security_origin_host_get(sec_origin), ewk_security_origin_protocol_get(sec_origin),ewk_security_origin_port_get(sec_origin));
1018     }
1019     ewk_notification_permission_reply(request, EINA_TRUE);
1020   }
1021   return EINA_FALSE;
1022 }
1023
1024 void __notification_cancel_cb(uint64_t notification_id, void* event_info)
1025 {
1026   evas_object_del(popup);
1027   printf("APP.C callback  __notification_cancel_cb with notification id = %Lu\n", (long long unsigned int)notification_id);
1028 }
1029
1030 void __policy_response_decide_cb(void *data, Evas_Object *obj, void *event_info)
1031 {
1032   printf("APP.C callback called __policy_response_decide_cb \n");
1033   Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
1034   Ewk_Policy_Decision_Type policy_type = ewk_policy_decision_type_get(policy_decision);
1035   const char *uri = ewk_policy_decision_url_get(policy_decision);
1036   const char *cookie = ewk_policy_decision_cookie_get(policy_decision);
1037   const char *mime = ewk_policy_decision_response_mime_get(policy_decision);
1038   printf("APP.C URL : %s\n", uri);
1039   printf("APP.C cookie : %s\n", cookie);
1040   printf("APP.C mime type : %s\n", mime);
1041   printf("APP.C policy type : %d\n", policy_type);
1042   ewk_policy_decision_use(policy_decision);
1043 }
1044
1045 void __customize_context_menu_cb(void* data, Evas_Object *obj, void *event_info)
1046 {
1047   Ewk_Context_Menu *context_menu = (Ewk_Context_Menu*)event_info;
1048   ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_GO_BACK, "Back", 1);
1049   ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_GO_FORWARD, "Forward", 1);
1050   ewk_context_menu_item_append_as_action(context_menu, EWK_CONTEXT_MENU_ITEM_TAG_RELOAD, "Reload", 1);
1051   ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR, "Bk_fwd_clear", 1);
1052   ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_CACHE_RUN, "Run App Cache Test", 1);
1053   ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_APPLICATION_CACHE_DELETE_ALL, "Delete All App Cache", 1);
1054   ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_GRAB_SNAPSHOT, "Take Snapshot", 1);
1055   ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_WEB_DATABASE_GET_ORIGINS, "Get WebDB", 1);
1056   ewk_context_menu_item_append_as_action(context_menu, FOR_TEST_WEB_DATABASE_DELETE_ALL, "Clear WebDB", 1);
1057   printf("APP.C callback __customize_context_menu_cb \n");
1058 }
1059
1060 static void get_app_cache_usage_cb(int64_t usage, void* user_data)
1061 {
1062   static unsigned int count_usage_callback = 0;
1063   Ewk_Security_Origin* origin = (Ewk_Security_Origin*)user_data;
1064   printf("AppCache usage for %s is %ld\n", ewk_security_origin_host_get(origin), (long int)usage);
1065   ewk_context_application_cache_delete(ewk_context_default_get(), origin);
1066   if (eina_list_count(application_cache_origins) == ++count_usage_callback) {
1067     ewk_context_origins_free(application_cache_origins);
1068     count_usage_callback = 0;
1069     application_cache_origins = NULL;
1070   }
1071 }
1072
1073 static void get_origins_for_cache_cb(Eina_List* origins, void* user_data)
1074 {
1075   if (!origins)
1076     return;
1077   Eina_List* list_iterator = NULL;
1078   void* data = NULL;
1079   if (application_cache_origins) {
1080     fprintf(stderr, "APP/ERROR: First cache usage-delete cycle is still running.\n");
1081     return;
1082   }
1083
1084   application_cache_origins = origins;
1085   EINA_LIST_FOREACH(origins, list_iterator, data) {
1086     Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(data);
1087     ewk_context_application_cache_usage_for_origin_get(ewk_context_default_get(), origin,
1088                                                        get_app_cache_usage_cb, origin);
1089   }
1090 }
1091
1092 static void get_origins_for_webDB_cb(Eina_List* origins, void* user_data)
1093 {
1094   if (!origins)
1095     return;
1096
1097   if (web_database_origins)
1098     return;
1099
1100   Eina_List* list_iterator = NULL;
1101   void* data = NULL;
1102   web_database_origins = origins;
1103   static unsigned int flag = 0;
1104   EINA_LIST_FOREACH(origins, list_iterator, data) {
1105     Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(data);
1106     printf("Web Database origin : %s\n", ewk_security_origin_host_get(origin));
1107     flag++;
1108   }
1109   if(eina_list_count(web_database_origins) == flag) {
1110     flag = 0;
1111     ewk_context_origins_free(web_database_origins);
1112     web_database_origins = NULL;
1113   }
1114 }
1115
1116 void __customize_context_menu_item_selected_cb(void* data, Evas_Object *obj, void *event_info)
1117 {
1118   Ewk_Context_Menu_Item* item = (Ewk_Context_Menu_Item*)event_info;
1119   switch (ewk_context_menu_item_tag_get(item)) {
1120     case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW:
1121       printf("APP.C callback __customize_context_menu_item_selected_cb : Open In new Window Selected\n");
1122
1123       const int default_width = 300;
1124       const int default_height =  400;
1125
1126       Ecore_Evas* ee = ecore_evas_new("software_x11", 0, 0, default_width, default_height, 0);
1127       Evas* e = ecore_evas_get(ee);
1128
1129       Evas_Object* new_view = ewk_view_add(e);
1130       ewk_view_url_set(new_view, ewk_context_menu_item_link_url_get(item));
1131       evas_object_resize(new_view, default_width, default_height);
1132       evas_object_show(new_view);
1133       evas_object_focus_set(new_view, EINA_TRUE);
1134       ecore_evas_show(ee);
1135       evas_object_smart_callback_add(new_view, "close,window", __window_closed_cb, 0);
1136       ecore_evas_callback_delete_request_set(ee, delete_popup_window);
1137       break;
1138     case FOR_TEST_APPLICATION_CACHE_RUN:
1139       if (ewk_context_application_cache_origins_get(ewk_context_default_get(),
1140                                                     get_origins_for_cache_cb, NULL)) {
1141         printf("Getting origins for Application Cache\n");
1142       }
1143       break;
1144     case FOR_TEST_APPLICATION_CACHE_DELETE_ALL:
1145       if (ewk_context_application_cache_delete_all(ewk_context_default_get()))
1146         printf("All app cache deleted\n");
1147       break;
1148     case FOR_TEST_APPLICATION_BACK_FORWAD_CLEAR:
1149       printf("APP.C callback Bk_fwd_clear callback item selected cb\n");
1150       ewk_view_back_forward_list_clear(view);
1151       break;
1152     case FOR_TEST_GRAB_SNAPSHOT:
1153       printf("APP.C GRAB_SNAPSHOT selected\n");
1154       Eina_Rectangle snapshot_rect;
1155       snapshot_rect.x = snapshot_rect.y = 0;
1156       evas_object_geometry_get(view, NULL, NULL, &snapshot_rect.w, &snapshot_rect.h);
1157       Evas_Object* snapshot = ewk_view_screenshot_contents_get(view, snapshot_rect, 1.0, evas_object_evas_get(view));
1158       if(!snapshot) {
1159         fprintf(stderr, "Failed to get snapshot\n");
1160         break;
1161       }
1162       static char snapshot_filename[256];
1163       static int snapshot_count = 1;
1164       sprintf(snapshot_filename, "snapshot_img%04d.%s", snapshot_count++, "png");
1165       if (evas_object_image_save(snapshot, snapshot_filename, 0, 0))
1166         printf("Snapshot image saved in %s\n", snapshot_filename);
1167       else
1168         printf("Snapshot image could not be saved\n");
1169       break;
1170     case FOR_TEST_WEB_DATABASE_GET_ORIGINS:
1171       if (ewk_context_web_database_origins_get(ewk_context_default_get(),
1172                                                get_origins_for_webDB_cb, NULL)) {
1173         printf("Getting Origins for Web Database\n");
1174       }
1175       break;
1176     case FOR_TEST_WEB_DATABASE_DELETE_ALL:
1177       if (ewk_context_web_database_delete_all(ewk_context_default_get()))
1178         printf("All Web Databases deleted\n");
1179       break;
1180     default:
1181       break;
1182   }
1183 }
1184
1185 void __text_found_cb(void *data, Evas_Object *obj, void *event_info)
1186 {
1187   printf("text found : %u\n", *((unsigned int*)(event_info)));
1188 }
1189
1190 void __newwindow_policy_cb(void *data, Evas_Object *obj, void* policy)
1191 {
1192   printf ("APP.C __newwindow_policy_cb called \n");
1193   Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)policy;
1194   const char* url = ewk_policy_decision_url_get(policy_decision);
1195   printf("APP.C url for new window: %s \n", url);
1196   ewk_policy_decision_use(policy_decision);
1197 }
1198
1199 void __load_nonemptylayout_finished_cb(void *data, Evas_Object *obj, void *event_info)
1200 {
1201   printf ("APP.C callback called __load_nonemptylayout_finished_cb \n");
1202 }
1203
1204 void __popup_wait_start_cb(void *data, Evas_Object *obj, void* policy)
1205 {
1206   printf("Popup wait start\n");
1207 }
1208
1209 void __popup_wait_finish_cb(void *data, Evas_Object *obj, void* policy)
1210 {
1211   printf("Popup wait finish\n");
1212 }
1213
1214 void __download_callback(const char* download_url, void* user_data)
1215 {
1216   printf("new download start callback is triggered:%s\n", download_url);
1217 }
1218
1219 void __frame_rendered_cb(void* data, Evas_Object* obj, void* event_info)
1220 {
1221   printf ("APP.C callback called __frame_rendered_cb \n");
1222
1223   if (pdf_filename) {
1224     int width, height;
1225     evas_object_geometry_get(obj, NULL, NULL, &width, &height);
1226     if (ewk_view_contents_pdf_get(obj, width, height, pdf_filename))
1227       printf("\"Save as PDF\" request sent\n");
1228     else
1229       printf("Failed to send \"Save as PDF\" request\n");
1230   }
1231 }
1232
1233 void __ewk_view_plain_text_get_cb(Evas_Object* o, const char* content_text, void* user_data)
1234 {
1235   if (content_text)
1236     printf("__ewk_view_plain_text_get_cb callback success --\n%s\n---user_data--%d\n",content_text,*(int*)(user_data));
1237 }
1238
1239 void __ewk_view_plain_text_get_cb_1(Evas_Object* o, const char* content_text, void* user_data)
1240 {
1241   if (content_text)
1242     printf("__ewk_view_plain_text_get_cb_1 callback success --\n%s\n---user_data--%d\n",content_text,*(int*)(user_data));
1243 }
1244
1245 void __load_started_cb(void *data, Evas_Object *obj, void *event_info)
1246 {
1247   printf("APP.c __load_started_cb called \n");
1248 }
1249
1250 void __edge_left_cb(void* data, Evas_Object* obj, void* event_info)
1251 {
1252   printf("Edge_Left Notification\n");
1253 }
1254
1255 void __edge_right_cb(void* data, Evas_Object* obj, void* event_info)
1256 {
1257   printf("Edge_Right Notification\n");
1258 }
1259
1260 void __edge_top_cb(void* data, Evas_Object* obj, void* event_info)
1261 {
1262   printf("Edge_Top Notification\n");
1263 }
1264
1265 void __edge_bottom_cb(void* data, Evas_Object* obj, void* event_info)
1266 {
1267   printf("Edge_Bottom Notification\n");
1268 }
1269
1270 #if defined(OS_TIZEN)
1271 Eina_Bool __vibration_timeout_cb(void *data)
1272 {
1273   if (IsMobileProfile() || IsWearableProfile()) {
1274     g_haptic_timer_id = NULL;
1275     if (g_haptic_handle) {
1276       device_haptic_stop(g_haptic_handle, g_haptic_effect);
1277       device_haptic_close(g_haptic_handle);
1278       g_haptic_handle = NULL;
1279     }
1280
1281     return ECORE_CALLBACK_CANCEL;
1282   } else {
1283     return EINA_TRUE;
1284   }
1285 }
1286
1287 void __vibration_on_cb(uint64_t vibration_time, void *data)
1288 {
1289   if (IsMobileProfile() || IsWearableProfile()) {
1290     printf("__vibration_on_cb called");
1291     uint64_t duration = vibration_time;
1292
1293     if (g_haptic_timer_id) {
1294       ecore_timer_del(g_haptic_timer_id);
1295       g_haptic_timer_id = NULL;
1296     }
1297
1298     if (g_haptic_handle) {
1299       device_haptic_stop(g_haptic_handle, g_haptic_effect);
1300       device_haptic_close(g_haptic_handle);
1301       g_haptic_handle = NULL;
1302     }
1303
1304     if (device_haptic_open(0, &g_haptic_handle) != DEVICE_ERROR_NONE) {
1305       printf("__vibration_on_cb:device_haptic_open failed");
1306       return;
1307     }
1308
1309     device_haptic_vibrate(g_haptic_handle, duration, 100, &g_haptic_effect);
1310     double in = (double)((double)(duration) / (double)(1000));
1311     printf("__vibration_on_cb:duration=%f", in);
1312
1313     g_haptic_timer_id = ecore_timer_add(in, __vibration_timeout_cb, NULL);
1314   }
1315 }
1316
1317 void __vibration_off_cb(void *data)
1318 {
1319   if (IsMobileProfile() || IsWearableProfile()) {
1320     printf("__vibration_off_cb called");
1321     if (g_haptic_timer_id) {
1322       ecore_timer_del(g_haptic_timer_id);
1323       g_haptic_timer_id = NULL;
1324     }
1325
1326     if (g_haptic_handle) {
1327       device_haptic_stop(g_haptic_handle, g_haptic_effect);
1328       device_haptic_close(g_haptic_handle);
1329       g_haptic_handle = NULL;
1330     }
1331   }
1332 }
1333 #endif
1334
1335 void __text_style_state_changed_cb(void *data, Evas_Object *obj, void *event_info)
1336 {
1337   Evas_Point start_point, end_point;
1338   int r, g, b, a;
1339   Ewk_Text_Style *style = (Ewk_Text_Style*)event_info;
1340   printf ("APP.C __text_style_state_changed_cb called \n");
1341   printf ("APP.c ewk_text_style_underline_get = %d \n",ewk_text_style_underline_get(style));
1342   printf ("APP.c ewk_text_style_italic_get = %d \n",ewk_text_style_italic_get(style));
1343   printf ("APP.c ewk_text_style_bold_get = %d \n",ewk_text_style_bold_get(style));
1344   printf ("APP.c ewk_text_style_ordered_list_get = %d \n",ewk_text_style_ordered_list_get(style));
1345   printf ("APP.c ewk_text_style_unordered_list_get = %d \n",ewk_text_style_unordered_list_get(style));
1346
1347   ewk_text_style_position_get(style, &start_point, &end_point);
1348   printf ("APP.c ewk_text_style_position_get start x = %d, y = %d, end x = %d, y = %d\n",
1349       start_point.x, start_point.y, end_point.x, end_point.y);
1350
1351   ewk_text_style_bg_color_get(style, &r, &g, &b, &a);
1352   printf ("APP.c ewk_text_style_bg_color_get r = %d, g =%d, b = %d, a = %d\n", r, g ,b ,a);
1353   printf ("APP.c ewk_text_style_has_composition_get = %d \n",ewk_text_style_has_composition_get(style));
1354   printf ("APP.c ewk_text_style_align_center_get = %d \n",ewk_text_style_align_center_get(style));
1355   printf ("APP.c ewk_text_style_align_left_get = %d \n",ewk_text_style_align_left_get(style));
1356   printf ("APP.c ewk_text_style_align_right_get = %d \n",ewk_text_style_align_right_get(style));
1357   printf ("APP.c ewk_text_style_align_full_get = %d \n",ewk_text_style_align_full_get(style));
1358 }
1359
1360 void __hit_test_request_cb(Evas_Object* o, int x, int y, int hit_test_mode, Ewk_Hit_Test* ht, void* user_data)
1361 {
1362   printf("HitTest: context %d\n", ewk_hit_test_result_context_get(ht));
1363   printf("HitTest: link uri %s\n", ewk_hit_test_link_uri_get(ht));
1364   printf("HitTest: link title %s\n", ewk_hit_test_link_title_get(ht));
1365   printf("HitTest: link label %s\n",ewk_hit_test_link_label_get(ht));
1366   printf("HitTest: image uri %s\n", ewk_hit_test_image_uri_get(ht));
1367 #if !defined(EWK_BRINGUP)
1368   printf("HitTest: media uri %s\n", ewk_hit_test_media_uri_get(ht));
1369 #endif
1370   printf("HitTest: tag name %s\n", ewk_hit_test_tag_name_get(ht));
1371   printf("HitTest: node value %s\n", ewk_hit_test_node_value_get(ht));
1372   printf("HitTest: image length %d\n", ewk_hit_test_image_buffer_length_get(ht));
1373   printf("HitTest: filename extension %s\n", ewk_hit_test_image_file_name_extension_get(ht));
1374   if (ewk_hit_test_image_buffer_length_get(ht)) {
1375     // To verify the buffer, we write to file.
1376     // App might use its own engine to encode, we use evas API.
1377     Evas_Object* image = evas_object_image_add(e);
1378     evas_object_image_colorspace_set(image, EVAS_COLORSPACE_ARGB8888);
1379     evas_object_image_alpha_set(image, EINA_TRUE);
1380     evas_object_image_data_copy_set(image, ewk_hit_test_image_buffer_get(ht));
1381     static char filename_buffer[256];
1382     static int count = 1;
1383     sprintf(filename_buffer, "hit_test_img%04d.%s", count++, ewk_hit_test_image_file_name_extension_get(ht));
1384     if (evas_object_image_save(image, filename_buffer, 0, 0))
1385       printf("Hit test image saved in %s\n", filename_buffer);
1386     else
1387       printf("Hit test image could not be saved\n");
1388   }
1389
1390   Eina_Hash *attr_hash = ewk_hit_test_attribute_hash_get(ht);
1391   if (attr_hash) {
1392     eina_hash_foreach(attr_hash, _util_print_hit_test_result_hash_fn, NULL);
1393   }
1394
1395 }
1396
1397 void on_mouse_up(void* data, Evas* canvas, Evas_Object* obj, void* event_info)
1398 {
1399   Evas_Event_Mouse_Up* event = (Evas_Event_Mouse_Up*)event_info;
1400   if (!evas_key_modifier_is_set(event->modifiers, "Shift"))
1401       return;
1402
1403   ewk_view_hit_test_request(obj, event->canvas.x, event->canvas.y, EWK_HIT_TEST_MODE_ALL, __hit_test_request_cb, NULL);
1404 }
1405
1406 void __undo_size_cb(void* data, Evas_Object* obj, void* event_info)
1407 {
1408   printf ("APP.C callback called __undo_size_cb\n");
1409 }
1410
1411 void __redo_size_cb(void* data, Evas_Object* obj, void* event_info)
1412 {
1413   printf ("APP.C callback called __redo_size_cb \n");
1414 }
1415
1416 void __mhtml_save_cb(Evas_Object *obj, const char *mhtml_data, void *data)
1417 {
1418   printf("APP.C __mhtml_save_cb callback called\n");
1419   printf("APP.C Data is \n %s \n\n", mhtml_data);
1420 }
1421
1422 void __clipboard_opened_cb(void* data, Evas_Object* view, void* event_info)
1423 {
1424   printf("APP.C clipboard window opened\n");
1425 }
1426
1427 void __back_forward_list_changed_cb(void *data, Evas_Object *obj, void *event_info)
1428 {
1429   printf("APP.C Back Forward List Changed Notification\n");
1430 }
1431
1432 Eina_Bool __ewk_view_javascript_alert_cb(Evas_Object* o, const char* alert_text, void* user_data)
1433 {
1434   printf("APP.C javascript alert opened\n");
1435
1436   return EINA_TRUE;
1437 }
1438
1439 Eina_Bool __ewk_view_javascript_confirm_cb(Evas_Object* o, const char* message, void* user_data)
1440 {
1441   printf("APP.C javascript confirm popup opened\n");
1442
1443   return EINA_TRUE;
1444 }
1445
1446 Eina_Bool __ewk_view_javascript_prompt_cb(Evas_Object* o, const char* message, const char* default_value, void* user_data)
1447 {
1448   printf("APP.C javascript prompt popup opened\n");
1449
1450   return EINA_TRUE;
1451 }
1452
1453 void __webprocess_crashed_cb(void* data, Evas_Object* obj, void* event_info)
1454 {
1455   printf("APP.C callback __webprocess_crashed_cb \n");
1456   const char* message = "<html><body><h1>The renderer process has crashed!</h1>"
1457       "<a href=\"https://google.com\">Open google</a></body></html>";
1458   ewk_view_html_string_load(view, message, 0, 0);
1459   Eina_Bool* handled = (Eina_Bool*)event_info;
1460   *handled = EINA_TRUE;
1461 }
1462
1463 Eina_Bool __mime_override_cb(const char* url, const char *mime, char **new_mime, void* user_data)
1464 {
1465   printf("APP.C callback %s, url: %s, mime: %s\n", __func__, url, mime);
1466   /* Example:
1467   if (strcmp(url, "file://mytest.abc") == 0 ||
1468       strcmp(mime, "application/x-php") == 0) {
1469     *new_mime = strdup("text/html");
1470     return EINA_TRUE;
1471   }
1472   */
1473   return EINA_FALSE;
1474 }
1475
1476 void __console_message_cb(void *data, Evas_Object *obj, void *event_info)
1477 {
1478   Ewk_Console_Message* console_message = (Ewk_Console_Message*)event_info;
1479   printf("APP.C callback called __console_message_cb\n");
1480   printf("console message:%s:", ewk_console_message_source_get(console_message));
1481   printf("%d:", ewk_console_message_line_get(console_message));
1482   printf("%d:", ewk_console_message_level_get(console_message));
1483   printf("%s\n", ewk_console_message_text_get(console_message));
1484 }