Fixed Hangeul title is not displayed properly in WebClip Livebox.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_view.cpp
1 /*
2    Copyright (C) 2011 Samsung Electronics
3    Copyright (C) 2012 Intel Corporation. All rights reserved.
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22 #include "ewk_view.h"
23
24 #include "EwkViewImpl.h"
25 #include "FindClientEfl.h"
26 #include "FormClientEfl.h"
27 #include "LayerTreeCoordinatorProxy.h"
28 #include "InputMethodContextEfl.h"
29 #include "NativeWebKeyboardEvent.h"
30 #include "NativeWebMouseEvent.h"
31 #include "NativeWebWheelEvent.h"
32 #include "PageClientImpl.h"
33 #include "PageLoadClientEfl.h"
34 #include "PagePolicyClientEfl.h"
35 #include "PageUIClientEfl.h"
36 #include "ResourceLoadClientEfl.h"
37 #include "WKAPICast.h"
38 #include "WKEinaSharedString.h"
39 #include "WKFindOptions.h"
40 #include "WKRetainPtr.h"
41 #include "WKString.h"
42 #include "WebContext.h"
43 #include "WebData.h"
44 #include "WebPageGroup.h"
45 #include "WebPopupItem.h"
46 #include "WebPopupMenuProxyEfl.h"
47 #include "WebPreferences.h"
48 #include "ewk_back_forward_list_private.h"
49 #include "ewk_context.h"
50 #include "ewk_context_private.h"
51 #include "ewk_favicon_database_private.h"
52 #include "ewk_intent_private.h"
53 #include "ewk_popup_menu_item_private.h"
54 #include "ewk_private.h"
55 #include "ewk_settings_private.h"
56 #include "ewk_view_private.h"
57 #include <Ecore_Evas.h>
58 #include <Ecore_X.h>
59 #include <WebKit2/WKPageGroup.h>
60 #include <wtf/text/CString.h>
61
62 #if ENABLE(FULLSCREEN_API)
63 #include "WebFullScreenManagerProxy.h"
64 #endif
65
66 #if ENABLE(TIZEN_WEBKIT2_DDK_CHECK)
67 namespace EGL {
68 #include <EGL/egl.h>
69 }
70 #endif
71
72 #if OS(TIZEN)
73 #include "DrawingAreaProxyImpl.h"
74 #include "WKArray.h"
75 #include "WKData.h"
76 #include "WKDownload.h"
77 #include "WKError.h"
78 #include "WKGeolocationPermissionRequest.h"
79 #include "WKImageCairo.h"
80 #include "WKOpenPanelParameters.h"
81 #include "WKOpenPanelResultListener.h"
82 #include "WKPage.h"
83 #include "WKPageGroup.h"
84 #include "WKView.h"
85 #include "WKPageTizen.h"
86 #include "WKPreferences.h"
87 #include "WKSerializedScriptValue.h"
88 #include "WKString.h"
89 #include "WKURLRequest.h"
90 #include "ewk_context_menu_private.h"
91 #include "ewk_error.h"
92 #include "ewk_error_private.h"
93 #include "ewk_history_private.h"
94 #include "ewk_popup_menu_item.h"
95 #include "ewk_popup_menu_item_private.h"
96 #include "ewk_view_context_menu_client.h"
97 #include "ewk_view_icondatabase_client.h"
98 #include "ewk_view_tizen_client.h"
99 #include <Ecore.h>
100 #include <Elementary.h>
101 #include <WebCore/EflScreenUtilities.h>
102 #include <WebCore/NotImplemented.h>
103 #include <cairo.h>
104
105 #if ENABLE(TIZEN_ICON_DATABASE)
106 #include "WKContextPrivate.h"
107 #endif
108
109 #if ENABLE(TIZEN_GEOLOCATION)
110 #include "ewk_geolocation_private.h"
111 #include "ewk_security_origin.h"
112 #include "ewk_view_geolocation_provider.h"
113 #endif
114
115 #if ENABLE(TOUCH_EVENTS)
116 #include "NativeWebTouchEvent.h"
117 #include "WebEvent.h"
118 #endif
119
120 #if ENABLE(TIZEN_ISF_PORT)
121 #include <Ecore_IMF.h>
122 #endif
123
124 #if ENABLE(TIZEN_NOTIFICATIONS)
125 #include "WKArray.h"
126 #include "WKNotificationManager.h"
127 #include "WKNumber.h"
128 #include "ewk_notification_private.h"
129 #include "ewk_view_notification_provider.h"
130 #endif
131
132 #if ENABLE(TIZEN_MEDIA_STREAM)
133 #include "WKUserMediaPermissionRequest.h"
134 #include "ewk_user_media_private.h"
135 #endif
136
137 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
138 #include "WebPageGroup.h"
139 #include "WebPreferences.h"
140 #endif
141
142 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
143 #include "ewk_hit_test_private.h"
144 #endif
145
146 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
147 #include "ewk_text_style.h"
148 #endif
149
150 #if ENABLE(TIZEN_SCREEN_READER)
151 #include "ScreenReaderProxy.h"
152 #endif
153
154 #if ENABLE(TIZEN_CSP)
155 #include <WebCore/ContentSecurityPolicy.h>
156 #endif
157
158 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
159 #include "WKDictionary.h"
160 #include "ewk_web_application_icon_data_private.h"
161 #endif
162 #endif // #if OS(TIZEN)
163
164 using namespace WebKit;
165 using namespace WebCore;
166
167 static const char EWK_VIEW_TYPE_STR[] = "EWK2_View";
168
169 #define EWK_VIEW_TYPE_CHECK(ewkView, result)                                   \
170     bool result = true;                                                        \
171     do {                                                                       \
172         if (!ewkView) {                                                        \
173             EINA_LOG_CRIT("null is not a ewk_view");                           \
174             result = false;                                                    \
175             break;                                                             \
176         }                                                                      \
177         const char* _tmp_otype = evas_object_type_get(ewkView);                \
178         const Evas_Smart* _tmp_s = evas_object_smart_smart_get(ewkView);       \
179         if (EINA_UNLIKELY(!_tmp_s)) {                                          \
180             EINA_LOG_CRIT                                                      \
181                 ("%p (%s) is not a smart object!",                             \
182                  ewkView, _tmp_otype ? _tmp_otype : "(null)");                 \
183             result = false;                                                    \
184             break;                                                             \
185         }                                                                      \
186         const Evas_Smart_Class* _tmp_sc = evas_smart_class_get(_tmp_s);        \
187         if (EINA_UNLIKELY(!_tmp_sc)) {                                         \
188             EINA_LOG_CRIT                                                      \
189                 ("%p (%s) is not a smart object!",                             \
190                  ewkView, _tmp_otype ? _tmp_otype : "(null)");                 \
191             result = false;                                                    \
192             break;                                                             \
193         }                                                                      \
194         else if (EINA_UNLIKELY(_tmp_sc->data != EWK_VIEW_TYPE_STR)) {               \
195             EINA_LOG_CRIT                                                      \
196                 ("%p (%s) is not of an ewk_view (need %p, got %p)!",           \
197                  ewkView, _tmp_otype ? _tmp_otype : "(null)",                  \
198                  EWK_VIEW_TYPE_STR, _tmp_sc->data);                            \
199             result = false;                                                    \
200         }                                                                      \
201     } while (0)
202
203 #define EWK_VIEW_SD_GET(ewkView, smartData)                                    \
204     EWK_VIEW_TYPE_CHECK(ewkView, _tmp_result);                                 \
205     Ewk_View_Smart_Data* smartData = 0;                                        \
206     if (_tmp_result)                                                           \
207         smartData = (Ewk_View_Smart_Data*)evas_object_smart_data_get(ewkView)
208
209 #define EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, ...)                     \
210     EWK_VIEW_SD_GET(ewkView, smartData);                                       \
211     do {                                                                       \
212         if (!smartData) {                                                      \
213             EINA_LOG_CRIT("no smart data for object %p (%s)",                  \
214                      ewkView, evas_object_type_get(ewkView));                  \
215             return __VA_ARGS__;                                                \
216         }                                                                      \
217     } while (0)
218
219 #if OS(TIZEN)
220 static Eina_Bool _ewk_view_default_javascript_alert(Evas_Object*, const char* alertText, void* userData);
221 static Eina_Bool _ewk_view_default_javascript_confirm(Evas_Object*, const char* message, void* userData);
222 static Eina_Bool _ewk_view_default_javascript_prompt(Evas_Object*, const char* message, const char* defaultValue, void* userData);
223 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
224 static Eina_Bool _ewk_view_default_before_unload_confirm_panel(Evas_Object*, const char* message, void* userData);
225 #endif
226 static Eina_Bool _ewk_view_default_open_panel(Evas_Object*, Eina_Bool allow_multiple_files, Eina_List *accepted_mime_types, const char* capture, void* userData);
227
228 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
229 Eina_Bool _ewk_view_popup_menu_show(Ewk_View_Smart_Data*, Eina_Rectangle, Ewk_Text_Direction, double page_scale_factor, Eina_List* items, int selectedIndex);
230 #if ENABLE(TIZEN_MULTIPLE_SELECT)
231 Eina_Bool _ewk_view_multiple_popup_menu_show(Ewk_View_Smart_Data*, Eina_Rectangle, Ewk_Text_Direction, double page_scale_factor, Eina_List* items);
232 #endif
233 Eina_Bool _ewk_view_popup_menu_hide(Ewk_View_Smart_Data*);
234 Eina_Bool _ewk_view_popup_menu_update(Ewk_View_Smart_Data*, Eina_Rectangle, Ewk_Text_Direction, Eina_List*, int);
235 #endif
236 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
237 Eina_Bool _ewk_orientation_lock(Ewk_View_Smart_Data *sd, int orientations);
238 void _ewk_orientation_unlock(Ewk_View_Smart_Data *sd);
239 #endif
240
241 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
242 static Eina_Bool _ewk_view_input_picker_show(Ewk_View_Smart_Data*, Ewk_Input_Type, const char* inputValue);
243 #endif
244
245 #if ENABLE(TIZEN_DATALIST_ELEMENT)
246 static Eina_Bool _ewk_view_data_list_show(Ewk_View_Smart_Data*, Ewk_Input_Type, Eina_List*);
247 static Eina_Bool _ewk_view_data_list_hide(Ewk_View_Smart_Data*, Ewk_Input_Type);
248 #endif
249
250 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
251 static Eina_Bool _ewk_input_picker_color_request(Ewk_View_Smart_Data*, int, int, int, int);
252 static Eina_Bool _ewk_input_picker_color_dismiss(Ewk_View_Smart_Data*);
253 #endif
254 #endif // #if OS(TIZEN)
255
256 static void _ewk_view_smart_changed(Ewk_View_Smart_Data* smartData)
257 {
258     if (smartData->changed.any)
259         return;
260     smartData->changed.any = true;
261     evas_object_smart_changed(smartData->self);
262 }
263
264 #if !ENABLE(TIZEN_ICON_DATABASE)
265 static void _ewk_view_on_favicon_changed(const char* pageURL, void* eventInfo)
266 {
267     Evas_Object* ewkView = static_cast<Evas_Object*>(eventInfo);
268     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
269     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
270
271     const char* viewURL = ewk_view_url_get(ewkView);
272     if (!viewURL || strcasecmp(viewURL, pageURL))
273         return;
274
275     impl->informIconChange();
276 }
277 #endif
278
279 // Default Event Handling.
280 static Eina_Bool _ewk_view_smart_focus_in(Ewk_View_Smart_Data* smartData)
281 {
282     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
283     TIZEN_LOGI("");
284
285 #if OS(TIZEN)
286     impl->pageClient->setViewFocused(true);
287 #endif // #if OS(TIZEN)
288     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
289 #if ENABLE(TIZEN_ISF_PORT)
290     if (impl->inputMethodContext())
291         impl->inputMethodContext()->onFocusIn();
292 #endif
293     return true;
294 }
295
296 static Eina_Bool _ewk_view_smart_focus_out(Ewk_View_Smart_Data* smartData)
297 {
298     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
299     TIZEN_LOGI("");
300
301 #if OS(TIZEN)
302 #if ENABLE(TIZEN_ISF_PORT)
303     // Keypad should be hidden rapidly when moving focus on elementary
304     // because Ecore-ime doesn't support it.
305     if (impl->inputMethodContext())
306         impl->inputMethodContext()->onFocusOut();
307 #endif
308
309 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
310     if (impl->pageClient->isTextSelectionMode())
311         impl->pageClient->setIsTextSelectionMode(false);
312 #endif
313
314 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
315     if (impl->pageClient->isContextMenuVisible())
316         impl->pageProxy->hideContextMenu();
317 #endif
318
319 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
320     if (impl->pageClient->isClipboardWindowOpened())
321         impl->pageClient->closeClipboardWindow();
322 #endif
323
324 #if ENABLE(TIZEN_DRAG_SUPPORT)
325     if (impl->pageClient->isDragMode())
326         impl->pageClient->setDragMode(false);
327 #endif
328
329 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
330     if (smartData->api->formdata_candidate_is_showing(smartData))
331         smartData->api->formdata_candidate_hide(smartData);
332 #endif
333
334     impl->pageClient->setViewFocused(false);
335 #endif // #if OS(TIZEN)
336     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
337     return true;
338 }
339
340 static Eina_Bool _ewk_view_smart_mouse_wheel(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Wheel* wheelEvent)
341 {
342     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
343
344     impl->page()->handleWheelEvent(NativeWebWheelEvent(wheelEvent, impl->transformFromScene(), impl->transformToScreen()));
345     return true;
346 }
347
348 static Eina_Bool _ewk_view_smart_mouse_down(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Down* downEvent)
349 {
350     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
351
352     impl->page()->handleMouseEvent(NativeWebMouseEvent(downEvent, impl->transformFromScene(), impl->transformToScreen()));
353     return true;
354 }
355
356 static Eina_Bool _ewk_view_smart_mouse_up(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Up* upEvent)
357 {
358     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
359
360     impl->page()->handleMouseEvent(NativeWebMouseEvent(upEvent, impl->transformFromScene(), impl->transformToScreen()));
361
362     InputMethodContextEfl* inputMethodContext = impl->inputMethodContext();
363     if (inputMethodContext)
364         inputMethodContext->handleMouseUpEvent(upEvent);
365
366     return true;
367 }
368
369 static Eina_Bool _ewk_view_smart_mouse_move(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Move* moveEvent)
370 {
371     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
372
373     // FIXME: impl->page() is used in the webkit opensource, but tizen webkit does not use it yet.
374     impl->page()->handleMouseEvent(NativeWebMouseEvent(moveEvent, impl->transformFromScene(), impl->transformToScreen()));
375     return true;
376 }
377
378 static Eina_Bool _ewk_view_smart_key_down(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Down* downEvent)
379 {
380     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
381
382     bool isFiltered = false;
383     InputMethodContextEfl* inputMethodContext = impl->inputMethodContext();
384     if (inputMethodContext)
385         inputMethodContext->handleKeyDownEvent(downEvent, &isFiltered);
386
387     impl->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(downEvent, isFiltered));
388     return true;
389 }
390
391 static Eina_Bool _ewk_view_smart_key_up(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Up* upEvent)
392 {
393     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
394
395     impl->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(upEvent));
396     return true;
397 }
398
399 #if OS(TIZEN)
400 static Eina_Bool _ewk_view_smart_gesture_start(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
401 {
402 #if ENABLE(TIZEN_GESTURE)
403     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
404
405 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
406     if (impl->pageClient->isTextSelectionMode() && impl->pageClient->isTextSelectionHandleDowned())
407         return true;
408 #endif
409
410 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
411     if (impl->focusRing) {
412         if (event->type == EWK_GESTURE_TAP && event->count == 1) {
413             impl->focusRing->requestToShow(IntPoint(event->position.x, event->position.y));
414         } else if (event->type == EWK_GESTURE_PAN) {
415             if (impl->exceedTouchMoveThreshold)
416                 impl->focusRing->hide();
417         } else {
418             if (event->type != EWK_GESTURE_LONG_PRESS) {
419 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
420                 if (!impl->pageClient->isContextMenuVisible())
421 #endif
422                     impl->focusRing->hide();
423             }
424         }
425     }
426 #endif
427
428 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
429     if (smartData->api->formdata_candidate_is_showing(smartData))
430         smartData->api->formdata_candidate_hide(smartData);
431 #endif
432
433     switch (event->type) {
434     case EWK_GESTURE_TAP:
435         impl->gestureClient->startTap(IntPoint(event->position.x, event->position.y));
436         break;
437     case EWK_GESTURE_LONG_PRESS: {
438 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
439 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
440         if (ewk_settings_text_selection_enabled_get(impl->settings()))
441             impl->pageClient->setIsTextSelectionMode(false);
442 #endif
443         IntPoint scenePoint(event->position.x, event->position.y);
444         IntPoint contentsPoint = impl->transformFromScene().mapPoint(scenePoint);
445         WebHitTestResult::Data hitTestResultData = impl->pageProxy->hitTestResultAtPoint(contentsPoint);
446 #if ENABLE(TIZEN_DRAG_SUPPORT)
447         // 1. Check to start dragging.
448         if (hitTestResultData.isDragSupport) {
449             impl->pageClient->setDragPoint(scenePoint);
450 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
451             if (impl->focusRing)
452                 impl->focusRing->show(IntRect(), true);
453 #endif
454             impl->gestureClient->showContextMenu(scenePoint);
455             break;
456         }
457 #endif
458         // 2. Check to show context menu.
459         if (!hitTestResultData.absoluteImageURL.isEmpty()
460             || !hitTestResultData.absoluteLinkURL.isEmpty()
461             || !hitTestResultData.absoluteMediaURL.isEmpty()) {
462 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
463             if (impl->focusRing)
464                 impl->focusRing->show(IntRect(), true);
465 #endif
466             impl->gestureClient->showContextMenu(scenePoint);
467             break;
468         }
469 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
470         // 3. Check for text selection.
471         if (ewk_settings_text_selection_enabled_get(impl->settings())) {
472             // Process gesture_end(EWK_GESTURE_TAP) to activate the editing if node under point is editable.
473             if (hitTestResultData.context & WebHitTestResult::HitTestResultContextEditable) {
474                 if (smartData->api && smartData->api->gesture_end) {
475                     Ewk_Event_Gesture tapEvent = {EWK_GESTURE_TAP, event->position, {0, 0}, 0, 1, ecore_time_get() * 1000};
476                     smartData->api->gesture_end(smartData, &tapEvent);
477                 }
478             }
479
480             if (impl->pageClient->textSelectionDown(scenePoint)) {
481                 impl->gestureClient->setGestureEnabled(false);
482                 impl->feedTouchEventsByType(EWK_TOUCH_CANCEL);
483             }
484         }
485 #endif
486         break;
487 #endif // #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
488     }
489     case EWK_GESTURE_PAN:
490         impl->gestureClient->startPan(IntPoint(event->position.x, event->position.y));
491         break;
492     case EWK_GESTURE_FLICK:
493         impl->gestureClient->startFlick(IntPoint(event->position.x, event->position.y), IntPoint(event->velocity.x, event->velocity.y));
494         break;
495     case EWK_GESTURE_PINCH:
496         if (impl->pageClient->viewportConstraints().userScalable)
497             impl->gestureClient->startPinch(IntPoint(event->position.x, event->position.y), event->scale);
498         break;
499     default:
500         ASSERT_NOT_REACHED();
501         break;
502     }
503
504     return true;
505 #else
506     return false;
507 #endif // #if ENABLE(TIZEN_GESTURE)
508 }
509
510 static Eina_Bool _ewk_view_smart_gesture_end(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
511 {
512 #if ENABLE(TIZEN_GESTURE)
513     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
514
515 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
516     if (impl->pageClient->isTextSelectionMode() && impl->pageClient->isTextSelectionHandleDowned())
517         return true;
518 #endif
519
520 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
521     if (impl->focusRing) {
522 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
523         if (!impl->pageClient->isContextMenuVisible())
524 #endif
525             impl->focusRing->hide();
526     }
527 #endif
528
529     switch (event->type) {
530     case EWK_GESTURE_TAP:
531         if (event->count == 1) {
532 #if ENABLE(TIZEN_DRAG_SUPPORT)
533         if (impl->pageClient->isDragMode())
534             impl->pageClient->setDragMode(false);
535 #endif
536 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
537             if (impl->pageClient->isTextSelectionMode())
538                 impl->pageClient->setIsTextSelectionMode(false);
539 #endif
540
541 #if ENABLE(TIZEN_ISF_PORT)
542             if (impl->inputMethodContext()->isIMEPostion(event->position.x, event->position.y))
543                 return false;
544 #endif
545
546             impl->gestureClient->endTap(IntPoint(event->position.x, event->position.y));
547 #if ENABLE(TIZEN_ISF_PORT)
548             evas_object_focus_set(smartData->self, true);
549 #endif
550         } else if (event->count == 2)
551             impl->gestureClient->endDoubleTap(IntPoint(event->position.x, event->position.y));
552         break;
553     case EWK_GESTURE_LONG_PRESS:
554 #if ENABLE(TIZEN_DRAG_SUPPORT)
555         if (impl->pageClient->isDragMode())
556             impl->pageClient->setDragMode(false);
557 #endif
558         // Prcess endTap for LONG_PRESS gesture if text-selection and context menu did not work
559         impl->gestureClient->endTap(IntPoint(event->position.x, event->position.y));
560         break;
561     case EWK_GESTURE_PAN:
562         impl->gestureClient->endPan(IntPoint(event->position.x, event->position.y));
563         break;
564     case EWK_GESTURE_FLICK:
565         impl->gestureClient->endFlick(IntPoint(event->position.x, event->position.y), IntPoint(event->velocity.x, event->velocity.y));
566         break;
567     case EWK_GESTURE_PINCH:
568         impl->gestureClient->endPinch(IntPoint(event->position.x, event->position.y), event->scale);
569         break;
570     default:
571         ASSERT_NOT_REACHED();
572         break;
573     }
574
575     return true;
576 #else
577     return false;
578 #endif // #if ENABLE(TIZEN_GESTURE)
579 }
580
581 static Eina_Bool _ewk_view_smart_gesture_move(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
582 {
583 #if ENABLE(TIZEN_GESTURE)
584     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
585
586 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
587     if (impl->pageClient->isTextSelectionMode() && impl->pageClient->isTextSelectionHandleDowned())
588         return true;
589 #endif
590
591 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
592     if (impl->focusRing && !(event->type == EWK_GESTURE_PAN && !impl->exceedTouchMoveThreshold))
593         impl->focusRing->hide();
594 #endif
595
596     switch (event->type) {
597     case EWK_GESTURE_PAN:
598         impl->gestureClient->movePan(IntPoint(event->position.x, event->position.y));
599         break;
600     case EWK_GESTURE_TAP:
601     case EWK_GESTURE_LONG_PRESS:
602     case EWK_GESTURE_FLICK:
603         break;
604     case EWK_GESTURE_PINCH:
605         if (impl->pageClient->viewportConstraints().userScalable)
606             impl->gestureClient->movePinch(IntPoint(event->position.x, event->position.y), event->scale);
607         break;
608     default:
609         ASSERT_NOT_REACHED();
610         break;
611     }
612
613     return true;
614 #else
615     return false;
616 #endif // #if ENABLE(TIZEN_GESTURE)
617 }
618 #endif //#if OS(TIZEN)
619
620 // Event Handling.
621 static void _ewk_view_on_focus_in(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
622 {
623     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
624     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
625     EINA_SAFETY_ON_NULL_RETURN(smartData->api->focus_in);
626     smartData->api->focus_in(smartData);
627 }
628
629 static void _ewk_view_on_focus_out(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
630 {
631     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
632     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
633     EINA_SAFETY_ON_NULL_RETURN(smartData->api->focus_out);
634     smartData->api->focus_out(smartData);
635 }
636
637 static void _ewk_view_on_mouse_wheel(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
638 {
639     Evas_Event_Mouse_Wheel* wheelEvent = static_cast<Evas_Event_Mouse_Wheel*>(eventInfo);
640     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
641     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
642     EINA_SAFETY_ON_NULL_RETURN(smartData->api->mouse_wheel);
643     smartData->api->mouse_wheel(smartData, wheelEvent);
644 }
645
646 static void _ewk_view_on_key_down(void* data, Evas*, Evas_Object*, void* eventInfo)
647 {
648     Evas_Event_Key_Down* downEvent = static_cast<Evas_Event_Key_Down*>(eventInfo);
649     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
650     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
651     EINA_SAFETY_ON_NULL_RETURN(smartData->api->key_down);
652     smartData->api->key_down(smartData, downEvent);
653 }
654
655 static void _ewk_view_on_key_up(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
656 {
657     Evas_Event_Key_Up* upEvent = static_cast<Evas_Event_Key_Up*>(eventInfo);
658     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
659     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
660     EINA_SAFETY_ON_NULL_RETURN(smartData->api->key_up);
661     smartData->api->key_up(smartData, upEvent);
662 }
663
664 static void _ewk_view_on_show(void* data, Evas*, Evas_Object*, void* /*eventInfo*/)
665 {
666     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
667     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
668     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible);
669 }
670
671 static void _ewk_view_on_hide(void* data, Evas*, Evas_Object*, void* /*eventInfo*/)
672 {
673     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
674     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
675
676     // This call may look wrong, but we really need to pass ViewIsVisible here.
677     // viewStateDidChange() itself is responsible for actually setting the visibility to Visible or Hidden
678     // depending on what WebPageProxy::isViewVisible() returns, this simply triggers the process.
679     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible);
680 }
681
682 #if OS(TIZEN)
683 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
684 Eina_Bool _ewk_view_text_selection_down(Ewk_View_Smart_Data* smartData, int x, int y)
685 {
686     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
687
688     return impl->pageClient->textSelectionDown(IntPoint(x, y), true);
689 }
690
691 Eina_Bool _ewk_view_text_selection_move(Ewk_View_Smart_Data* smartData, int x, int y)
692 {
693     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
694
695     IntPoint point(x, y);
696     impl->pageClient->textSelectionMove(point, true);
697
698     return true;
699 }
700
701 Eina_Bool _ewk_view_text_selection_up(Ewk_View_Smart_Data* smartData, int x, int y)
702 {
703     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
704
705     IntPoint point(x, y);
706     impl->pageClient->textSelectionUp(point, true);
707
708     return true;
709 }
710 #endif
711
712 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
713 Eina_Bool _ewk_view_smart_formdata_candidate_show(Ewk_View_Smart_Data* smartData, int x, int y, int w, int h)
714 {
715     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
716
717     impl->pageClient->showFormDataCandidate(IntRect(x, y, w, h));
718
719     return true;
720 }
721
722 Eina_Bool _ewk_view_smart_formdata_candidate_hide(Ewk_View_Smart_Data* smartData)
723 {
724     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
725
726     impl->pageClient->hideFormDataCandidate();
727
728     return true;
729 }
730
731 Eina_Bool _ewk_view_smart_formdata_candidate_update_data(Ewk_View_Smart_Data* smartData, Eina_List* dataList)
732 {
733     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
734
735     Vector<String> formData;
736     Eina_List* list;
737     void* data;
738     EINA_LIST_FOREACH(dataList, list, data)
739         formData.append(String::fromUTF8(static_cast<char*>(data)));
740
741     impl->pageClient->updateFormDataCandidate(formData);
742
743     return true;
744 }
745
746 Eina_Bool _ewk_view_smart_formdata_candidate_is_showing(Ewk_View_Smart_Data* smartData)
747 {
748     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
749
750     return impl->pageClient->isShowingFormDataCandidate();
751 }
752 #endif
753
754 #if ENABLE(TIZEN_SCREEN_READER)
755 Eina_Bool _ewk_view_screen_reader_command_execute(Ewk_View_Smart_Data* smartData, unsigned int command, int data1, int data2)
756 {
757     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
758
759     return ScreenReaderProxy::screenReader().executeCommand(impl, command, data1, data2);
760 }
761 #endif
762 #endif // #if OS(TIZEN)
763
764 static Evas_Smart_Class g_parentSmartClass = EVAS_SMART_CLASS_INIT_NULL;
765
766 static void _ewk_view_impl_del(EwkViewImpl* impl)
767 {
768 #if !ENABLE(TIZEN_ICON_DATABASE)
769     /* Unregister icon change callback */
770     Ewk_Favicon_Database* iconDatabase = impl->context->faviconDatabase();
771     iconDatabase->unwatchChanges(_ewk_view_on_favicon_changed);
772 #endif
773
774     delete impl;
775 }
776
777 static void _ewk_view_smart_add(Evas_Object* ewkView)
778 {
779     const Evas_Smart* smart = evas_object_smart_smart_get(ewkView);
780     const Evas_Smart_Class* smartClass = evas_smart_class_get(smart);
781     const Ewk_View_Smart_Class* api = reinterpret_cast<const Ewk_View_Smart_Class*>(smartClass);
782     EWK_VIEW_SD_GET(ewkView, smartData);
783
784     if (!smartData) {
785         smartData = static_cast<Ewk_View_Smart_Data*>(calloc(1, sizeof(Ewk_View_Smart_Data)));
786         if (!smartData) {
787             EINA_LOG_CRIT("could not allocate Ewk_View_Smart_Data");
788             return;
789         }
790         evas_object_smart_data_set(ewkView, smartData);
791     }
792
793     smartData->self = ewkView;
794     smartData->api = api;
795
796     g_parentSmartClass.add(ewkView);
797
798     smartData->priv = new EwkViewImpl(ewkView);
799     if (!smartData->priv) {
800         EINA_LOG_CRIT("could not allocate EwkViewImpl");
801         evas_object_smart_data_set(ewkView, 0);
802         free(smartData);
803         return;
804     }
805
806     // Create evas_object_image to draw web contents.
807     smartData->image = evas_object_image_add(smartData->base.evas);
808     evas_object_image_alpha_set(smartData->image, false);
809     evas_object_image_filled_set(smartData->image, true);
810     evas_object_smart_member_add(smartData->image, ewkView);
811
812 #if OS(TIZEN)
813 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
814     Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
815     const char *engine = ecore_evas_engine_name_get(ee);
816     if (engine && !strcmp(engine, "opengl_x11"))
817         evas_object_image_content_hint_set(smartData->image, EVAS_IMAGE_CONTENT_HINT_DYNAMIC);
818 #endif
819     ewk_view_mouse_events_enabled_set(ewkView, false);
820     ewk_view_touch_events_enabled_set(ewkView, true);
821
822     // FIXME: This code should be removed if side effect occur.
823     // WebView does not have focus after url loading.
824     // If focus is set as true to webview,
825     // elementary steal webview's focus during mouse up event
826     // So, added code that events are not propagated to smart parent according to guide from EFL
827     evas_object_propagate_events_set(ewkView, false);
828
829 #if ENABLE(TIZEN_SCREEN_READER)
830     ScreenReaderProxy::screenReader().addView(smartData->priv);
831 #endif
832 #endif // #if OS(TIZEN)
833
834 #define CONNECT(s, c) evas_object_event_callback_add(ewkView, s, c, smartData)
835     CONNECT(EVAS_CALLBACK_FOCUS_IN, _ewk_view_on_focus_in);
836     CONNECT(EVAS_CALLBACK_FOCUS_OUT, _ewk_view_on_focus_out);
837     CONNECT(EVAS_CALLBACK_MOUSE_WHEEL, _ewk_view_on_mouse_wheel);
838     CONNECT(EVAS_CALLBACK_KEY_DOWN, _ewk_view_on_key_down);
839     CONNECT(EVAS_CALLBACK_KEY_UP, _ewk_view_on_key_up);
840     CONNECT(EVAS_CALLBACK_SHOW, _ewk_view_on_show);
841     CONNECT(EVAS_CALLBACK_HIDE, _ewk_view_on_hide);
842 #undef CONNECT
843 }
844
845 static void _ewk_view_smart_del(Evas_Object* ewkView)
846 {
847     EwkViewImpl::removeFromPageViewMap(ewkView);
848     EWK_VIEW_SD_GET(ewkView, smartData);
849 #if ENABLE(TIZEN_SCREEN_READER)
850     ScreenReaderProxy::screenReader().removeView(smartData->priv);
851 #endif
852     if (smartData && smartData->priv)
853         _ewk_view_impl_del(smartData->priv);
854
855     g_parentSmartClass.del(ewkView);
856 }
857
858 static Eina_Bool _ewk_view_composite(void* data);
859
860 static void _ewk_view_smart_resize(Evas_Object* ewkView, Evas_Coord width, Evas_Coord height)
861 {
862     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
863
864     evas_object_resize(smartData->image, width, height);
865     evas_object_image_size_set(smartData->image, width, height);
866     evas_object_image_fill_set(smartData->image, 0, 0, width, height);
867 #if OS(TIZEN)
868     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
869 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
870     evas_object_image_native_surface_set(smartData->image, 0);
871
872 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
873     if (!ewk_view_is_opengl_backend(ewkView))
874         _ewk_view_composite(smartData);
875     else // OpenGL backend
876 #endif
877     impl->pageClient->displayViewport();
878 #endif
879 #endif // #if OS(TIZEN)
880
881     smartData->changed.size = true;
882     _ewk_view_smart_changed(smartData);
883 }
884
885 static void _ewk_view_smart_move(Evas_Object* ewkView, Evas_Coord x, Evas_Coord y)
886 {
887     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
888
889     smartData->changed.position = true;
890     _ewk_view_smart_changed(smartData);
891 }
892
893 static void _ewk_view_smart_calculate(Evas_Object* ewkView)
894 {
895     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
896     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
897
898     Evas_Coord x, y, width, height;
899
900     smartData->changed.any = false;
901
902     evas_object_geometry_get(ewkView, &x, &y, &width, &height);
903
904     if (smartData->changed.size) {
905 #if !OS(TIZEN)
906 #if USE(COORDINATED_GRAPHICS)
907         impl->pageViewportControllerClient->updateViewportSize(IntSize(width, height));
908 #endif
909 #if USE(ACCELERATED_COMPOSITING)
910         needsNewSurface = impl->evasGlSurface;
911 #endif
912
913         if (impl->pageProxy->drawingArea())
914             impl->pageProxy->drawingArea()->setSize(IntSize(width, height), IntSize());
915
916 #if USE(ACCELERATED_COMPOSITING)
917         if (!impl->evasGlSurface)
918             return;
919         evas_gl_surface_destroy(impl->evasGl, impl->evasGlSurface);
920         impl->evasGlSurface = 0;
921         ewk_view_create_gl_surface(ewkView, IntSize(width, height));
922         ewk_view_display(ewkView, IntRect(IntPoint(), IntSize(width, height)));
923 #endif
924 #endif // #if !OS(TIZEN)
925
926         smartData->view.w = width;
927         smartData->view.h = height;
928         smartData->changed.size = false;
929
930 #if OS(TIZEN)
931         if (impl->pageClient) {
932             if (DrawingAreaProxy* drawingArea = impl->pageProxy->drawingArea()) {
933 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
934                 if (impl->pageProxy->isViewVisible())
935                     drawingArea->setSize(IntSize(width, height), IntSize());
936 #else
937                 drawingArea->setSize(IntSize(width, height), IntSize());
938 #endif
939 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE) && !ENABLE(TIZEN_WEBKIT2_EFL_WTR)
940                 impl->pageClient->updateViewportSize(IntSize(width, height));
941                 if (ewk_view_is_opengl_backend(ewkView))
942                     impl->pageClient->displayViewport();
943 #endif
944             }
945 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
946             impl->pageClient->frameRectChanged();
947 #endif
948         }
949 #endif // #if OS(TIZEN)
950     }
951
952     if (smartData->changed.position) {
953         evas_object_move(smartData->image, x, y);
954         smartData->view.x = x;
955         smartData->view.y = y;
956         smartData->changed.position = false;
957 #if OS(TIZEN)
958 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
959         impl->pageClient->frameRectChanged();
960 #endif
961 #if ENABLE(TIZEN_SCREEN_READER)
962         impl->pageProxy->recalcScreenReaderFocusRect();
963 #endif
964 #endif // #if OS(TIZEN)
965     }
966 #if OS(TIZEN)
967     if (impl->popupPicker)
968         ewk_popup_picker_resize(impl->popupPicker);
969 #endif // #if OS(TIZEN)
970 }
971
972 static void _ewk_view_smart_show(Evas_Object* ewkView)
973 {
974     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
975     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
976
977     if (evas_object_clipees_get(smartData->base.clipper))
978         evas_object_show(smartData->base.clipper);
979     evas_object_show(smartData->image);
980 }
981
982 static void _ewk_view_smart_hide(Evas_Object* ewkView)
983 {
984     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
985
986     evas_object_hide(smartData->base.clipper);
987     evas_object_hide(smartData->image);
988 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
989     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
990     if (impl->pageClient->isTextSelectionMode())
991         impl->pageClient->setIsTextSelectionMode(false);
992 #endif
993 }
994
995 static void _ewk_view_smart_color_set(Evas_Object* ewkView, int red, int green, int blue, int alpha)
996 {
997     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
998     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
999
1000     if (alpha < 0)
1001         alpha = 0;
1002     else if (alpha > 255)
1003         alpha = 255;
1004
1005 #define CHECK_COLOR(color, alpha) \
1006     if (color < 0)                \
1007         color = 0;                \
1008     else if (color > alpha)       \
1009         color = alpha;
1010     CHECK_COLOR(red, alpha);
1011     CHECK_COLOR(green, alpha);
1012     CHECK_COLOR(blue, alpha);
1013 #undef CHECK_COLOR
1014
1015     evas_object_image_alpha_set(smartData->image, alpha < 255);
1016     impl->pageProxy->setDrawsBackground(red || green || blue);
1017     impl->pageProxy->setDrawsTransparentBackground(alpha < 255);
1018     impl->pageClient->setBackgroundColor(red/255.0, green/255.0, blue/255.0, alpha/255.0);
1019
1020 #if !OS(TIZEN)
1021     g_parentSmartClass.color_set(ewkView, red, green, blue, alpha);
1022 #endif
1023 }
1024
1025 Eina_Bool ewk_view_smart_class_set(Ewk_View_Smart_Class* api)
1026 {
1027     EINA_SAFETY_ON_NULL_RETURN_VAL(api, false);
1028
1029     if (api->version != EWK_VIEW_SMART_CLASS_VERSION) {
1030         EINA_LOG_CRIT("Ewk_View_Smart_Class %p is version %lu while %lu was expected.",
1031              api, api->version, EWK_VIEW_SMART_CLASS_VERSION);
1032         return false;
1033     }
1034
1035     if (EINA_UNLIKELY(!g_parentSmartClass.add))
1036         evas_object_smart_clipped_smart_set(&g_parentSmartClass);
1037
1038     evas_object_smart_clipped_smart_set(&api->sc);
1039
1040     // Set Evas_Smart_Class functions.
1041     api->sc.add = _ewk_view_smart_add;
1042     api->sc.del = _ewk_view_smart_del;
1043     api->sc.move = _ewk_view_smart_move;
1044     api->sc.resize = _ewk_view_smart_resize;
1045     api->sc.show = _ewk_view_smart_show;
1046     api->sc.hide = _ewk_view_smart_hide;
1047     api->sc.color_set = _ewk_view_smart_color_set;
1048     api->sc.calculate = _ewk_view_smart_calculate;
1049     api->sc.data = EWK_VIEW_TYPE_STR; // It is used by type checking.
1050
1051     // Set Ewk_View_Smart_Class functions.
1052     api->focus_in = _ewk_view_smart_focus_in;
1053     api->focus_out = _ewk_view_smart_focus_out;
1054     api->mouse_wheel = _ewk_view_smart_mouse_wheel;
1055     api->mouse_down = _ewk_view_smart_mouse_down;
1056     api->mouse_up = _ewk_view_smart_mouse_up;
1057     api->mouse_move = _ewk_view_smart_mouse_move;
1058     api->key_down = _ewk_view_smart_key_down;
1059     api->key_up = _ewk_view_smart_key_up;
1060 #if OS(TIZEN)
1061     api->gesture_start = _ewk_view_smart_gesture_start;
1062     api->gesture_end = _ewk_view_smart_gesture_end;
1063     api->gesture_move = _ewk_view_smart_gesture_move;
1064
1065 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1066     api->popup_menu_show = _ewk_view_popup_menu_show;
1067 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1068     api->multiple_popup_menu_show = _ewk_view_multiple_popup_menu_show;
1069 #endif
1070     api->popup_menu_hide = _ewk_view_popup_menu_hide;
1071     api->popup_menu_update = _ewk_view_popup_menu_update;
1072 #endif
1073 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1074     api->text_selection_down = _ewk_view_text_selection_down;
1075     api->text_selection_move = _ewk_view_text_selection_move;
1076     api->text_selection_up = _ewk_view_text_selection_up;
1077 #endif
1078 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1079     api->input_picker_show = _ewk_view_input_picker_show;
1080 #endif
1081 #if ENABLE(TIZEN_DATALIST_ELEMENT)
1082     api->data_list_show = _ewk_view_data_list_show;
1083     api->data_list_hide = _ewk_view_data_list_hide;
1084 #endif
1085 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
1086     api->orientation_lock = _ewk_orientation_lock;
1087     api->orientation_unlock = _ewk_orientation_unlock;
1088 #endif
1089 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
1090     api->input_picker_color_request = _ewk_input_picker_color_request;
1091     api->input_picker_color_dismiss = _ewk_input_picker_color_dismiss;
1092 #endif
1093 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1094     api->formdata_candidate_show = _ewk_view_smart_formdata_candidate_show;
1095     api->formdata_candidate_hide = _ewk_view_smart_formdata_candidate_hide;
1096     api->formdata_candidate_update_data = _ewk_view_smart_formdata_candidate_update_data;
1097     api->formdata_candidate_is_showing = _ewk_view_smart_formdata_candidate_is_showing;
1098 #endif
1099 #if ENABLE(TIZEN_SCREEN_READER)
1100     api->screen_reader_command_execute = _ewk_view_screen_reader_command_execute;
1101 #endif
1102 #endif //#if OS(TIZEN)
1103
1104     return true;
1105 }
1106
1107 static inline Evas_Smart* _ewk_view_smart_class_new(void)
1108 {
1109     static Ewk_View_Smart_Class api = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("Ewk_View");
1110     static Evas_Smart* smart = 0;
1111
1112     if (EINA_UNLIKELY(!smart)) {
1113         ewk_view_smart_class_set(&api);
1114         smart = evas_smart_class_new(&api.sc);
1115     }
1116
1117     return smart;
1118 }
1119
1120 static void _ewk_view_initialize(Evas_Object* ewkView, PassRefPtr<Ewk_Context> context, WKPageGroupRef pageGroupRef)
1121 {
1122     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1123     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1124     EINA_SAFETY_ON_NULL_RETURN(context);
1125
1126     if (impl->pageClient)
1127         return;
1128
1129 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
1130     bool isOpenGL = ewk_view_is_opengl_backend(ewkView);
1131     if (isOpenGL)
1132         impl->pageClient = PageClientEvasGL::create(impl);
1133     else
1134         impl->pageClient = PageClientImpl::create(impl);
1135 #else
1136     impl->pageClient = PageClientImpl::create(impl);
1137 #endif
1138
1139     if (pageGroupRef)
1140         impl->pageProxy = toImpl(context->wkContext())->createWebPage(impl->pageClient.get(), toImpl(pageGroupRef));
1141     else
1142         impl->pageProxy = toImpl(context->wkContext())->createWebPage(impl->pageClient.get(), WebPageGroup::create().get());
1143
1144     EwkViewImpl::addToPageViewMap(ewkView);
1145
1146 #if OS(TIZEN)
1147     impl->pageProxy->pageGroup()->preferences()->setAcceleratedCompositingEnabled(true);
1148     impl->pageProxy->pageGroup()->preferences()->setForceCompositingMode(true);
1149     impl->pageProxy->pageGroup()->preferences()->setFrameFlatteningEnabled(true);
1150     impl->pageProxy->pageGroup()->preferences()->setAllowUniversalAccessFromFileURLs(true);
1151
1152     int deviceWidth, deviceHeight;
1153     ecore_evas_screen_geometry_get(ecore_evas_ecore_evas_get(evas_object_evas_get(ewkView)), 0, 0, &deviceWidth, &deviceHeight);
1154     impl->pageProxy->pageGroup()->preferences()->setDeviceWidth(deviceWidth);
1155     impl->pageProxy->pageGroup()->preferences()->setDeviceHeight(deviceHeight);
1156 #endif
1157
1158     impl->pageProxy->initializeWebPage();
1159
1160 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
1161     impl->pageProxy->setCustomDeviceScaleFactor((float)getMobileDPI() / 160);
1162 #else
1163     impl->pageProxy->setCustomDeviceScaleFactor((float)getDPI() / 160);
1164 #endif
1165
1166 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE) && !ENABLE(TIZEN_WEBKIT2_EFL_WTR)
1167     impl->pageProxy->setUseFixedLayout(true);
1168 #endif
1169 #if ENABLE(FULLSCREEN_API)
1170     impl->pageProxy->fullScreenManager()->setWebView(ewkView);
1171 #endif
1172
1173 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
1174     if (isOpenGL)
1175         impl->pageProxy->drawingArea()->layerTreeCoordinatorProxy()->initializeAcceleratedCompositingMode(true);
1176     else {
1177         impl->pageProxy->pageGroup()->preferences()->setAcceleratedCompositingEnabled(false);
1178         impl->pageProxy->pageGroup()->preferences()->setWebGLEnabled(false);
1179         impl->pageProxy->drawingArea()->layerTreeCoordinatorProxy()->initializeAcceleratedCompositingMode(false);
1180     }
1181 #endif
1182
1183     impl->backForwardList = Ewk_Back_Forward_List::create(toAPI(impl->pageProxy->backForwardList()));
1184
1185     impl->context = context;
1186
1187 #if OS(TIZEN)
1188     ewkViewContextMenuClientAttachClient(ewkView);
1189     ewkViewTizenClientAttachClient(ewkView);
1190
1191 #if ENABLE(TIZEN_GEOLOCATION)
1192     ewkViewGeolocationProviderAttachProvider(ewkView, impl->context->wkContext());
1193 #endif
1194
1195 #if ENABLE(TIZEN_NOTIFICATIONS)
1196     ewkViewNotificationProviderAttachProvider(ewkView, impl->context->wkContext());
1197 #endif
1198
1199 #if ENABLE(TIZEN_ICON_DATABASE)
1200     ewk_view_icondatabase_client_attach(ewkView, impl->context->wkContext());
1201 #endif
1202
1203     ewk_view_javascript_alert_callback_set(ewkView, _ewk_view_default_javascript_alert, 0);
1204     ewk_view_javascript_confirm_callback_set(ewkView, _ewk_view_default_javascript_confirm, 0);
1205     ewk_view_javascript_prompt_callback_set(ewkView, _ewk_view_default_javascript_prompt, 0);
1206 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
1207     ewk_view_before_unload_confirm_panel_callback_set(ewkView, _ewk_view_default_before_unload_confirm_panel, 0);
1208 #endif
1209     ewk_view_open_panel_callback_set(ewkView, _ewk_view_default_open_panel, 0);
1210 #else // #if OS(TIZEN)
1211 #if USE(COORDINATED_GRAPHICS)
1212     impl->viewportHandler = EflViewportHandler::create(impl->pageClient.get());
1213 #endif
1214 #endif // #if OS(TIZEN)
1215
1216 #if ENABLE(FULLSCREEN_API)
1217     impl->pageProxy->fullScreenManager()->setWebView(ewkView);
1218     impl->pageProxy->pageGroup()->preferences()->setFullScreenEnabled(true);
1219 #endif
1220
1221     // Initialize page clients.
1222     impl->pageLoadClient = PageLoadClientEfl::create(impl);
1223     impl->pagePolicyClient = PagePolicyClientEfl::create(impl);
1224     impl->pageUIClient = PageUIClientEfl::create(impl);
1225     impl->resourceLoadClient = ResourceLoadClientEfl::create(impl);
1226     impl->findClient = FindClientEfl::create(impl);
1227     impl->formClient = FormClientEfl::create(impl);
1228 #if !ENABLE(TIZEN_ICON_DATABASE)
1229     /* Listen for favicon changes */
1230     Ewk_Favicon_Database* iconDatabase = impl->context->faviconDatabase();
1231     iconDatabase->watchChanges(IconChangeCallbackData(_ewk_view_on_favicon_changed, ewkView));
1232 #endif
1233 #if ENABLE(TIZEN_WEBKIT2_THEME_SET_INTERNAL)
1234     ewk_view_theme_set(ewkView, "/usr/share/edje/webkit.edj");
1235 #endif
1236
1237 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
1238     if (!impl->context->xWindow())
1239         impl->context->setXWindow(elm_win_xwindow_get(ewkView));
1240 #endif
1241
1242 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1243     impl->focusRing = FocusRing::create(impl);
1244 #endif
1245 }
1246
1247 static Evas_Object* _ewk_view_add_with_smart(Evas* canvas, Evas_Smart* smart)
1248 {
1249     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1250     EINA_SAFETY_ON_NULL_RETURN_VAL(smart, 0);
1251
1252 #if ENABLE(TIZEN_WEBKIT2_DDK_CHECK)
1253     {
1254         using namespace EGL;
1255         if(!eglGetDisplay(EGL_DEFAULT_DISPLAY)) {
1256             EINA_LOG_CRIT("Fail in initiziling view because No DDK is installed.");
1257             return 0;
1258         }
1259     }
1260 #endif
1261
1262     Evas_Object* ewkView = evas_object_smart_add(canvas, smart);
1263     if (!ewkView)
1264         return 0;
1265
1266     EWK_VIEW_SD_GET(ewkView, smartData);
1267     if (!smartData) {
1268         evas_object_del(ewkView);
1269         return 0;
1270     }
1271
1272     EWK_VIEW_IMPL_GET(smartData, impl);
1273     if (!impl) {
1274         evas_object_del(ewkView);
1275         return 0;
1276     }
1277
1278     return ewkView;
1279 }
1280
1281 /**
1282  * @internal
1283  * Constructs a ewk_view Evas_Object with WKType parameters.
1284  */
1285 Evas_Object* ewk_view_base_add(Evas* canvas, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
1286 {
1287     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1288     EINA_SAFETY_ON_NULL_RETURN_VAL(contextRef, 0);
1289
1290     Evas_Object* ewkView = _ewk_view_add_with_smart(canvas, _ewk_view_smart_class_new());
1291     if (!ewkView)
1292         return 0;
1293
1294     _ewk_view_initialize(ewkView, Ewk_Context::create(contextRef), pageGroupRef);
1295
1296     return ewkView;
1297 }
1298
1299 Evas_Object* ewk_view_smart_add(Evas* canvas, Evas_Smart* smart, Ewk_Context* context)
1300 {
1301     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1302     EINA_SAFETY_ON_NULL_RETURN_VAL(smart, 0);
1303     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1304
1305     Evas_Object* ewkView = _ewk_view_add_with_smart(canvas, smart);
1306     if (!ewkView)
1307         return 0;
1308
1309 #if ENABLE(TIZEN_ICON_DATABASE)
1310     //set default iconDatabasePath
1311     WKContextRef contextRef = context->wkContext();
1312     toImpl(contextRef)->setIconDatabasePath(toImpl(contextRef)->iconDatabasePath());
1313 #endif
1314
1315 #if ENABLE(TIZEN_WEBKIT2_CREATE_VIEW_WITH_CREATED_PAGE_GROUP_WITH_IDENTIFIER)
1316     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1317     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1318     _ewk_view_initialize(ewkView, context, toAPI(impl->pageGroup.get()));
1319 #else
1320     _ewk_view_initialize(ewkView, context, 0);
1321 #endif
1322
1323     return ewkView;
1324 }
1325
1326 Evas_Object* ewk_view_add_with_context(Evas* canvas, Ewk_Context* context)
1327 {
1328     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1329     return ewk_view_smart_add(canvas, _ewk_view_smart_class_new(), context);
1330 }
1331
1332 Evas_Object* ewk_view_add(Evas* canvas)
1333 {
1334     return ewk_view_add_with_context(canvas, ewk_context_default_get());
1335 }
1336
1337 Ewk_Context* ewk_view_context_get(const Evas_Object* ewkView)
1338 {
1339     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1340     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1341
1342     return impl->ewkContext();
1343 }
1344
1345 Eina_Bool ewk_view_url_set(Evas_Object* ewkView, const char* url)
1346 {
1347     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1348     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1349     EINA_SAFETY_ON_NULL_RETURN_VAL(url, false);
1350
1351     impl->pageProxy->loadURL(String::fromUTF8(url));
1352     impl->informURLChange();
1353
1354     return true;
1355 }
1356
1357 const char* ewk_view_url_get(const Evas_Object* ewkView)
1358 {
1359     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1360     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1361
1362     return impl->url();
1363 }
1364
1365 const char *ewk_view_icon_url_get(const Evas_Object *ewkView)
1366 {
1367     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1368     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1369
1370     return impl->faviconURL();
1371 }
1372
1373 Eina_Bool ewk_view_reload(Evas_Object* ewkView)
1374 {
1375     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1376     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1377
1378     impl->pageProxy->reload(/*reloadFromOrigin*/ false);
1379     impl->informURLChange();
1380
1381     return true;
1382 }
1383
1384 Eina_Bool ewk_view_reload_bypass_cache(Evas_Object* ewkView)
1385 {
1386     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1387     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1388
1389     impl->pageProxy->reload(/*reloadFromOrigin*/ true);
1390     impl->informURLChange();
1391
1392     return true;
1393 }
1394
1395 Eina_Bool ewk_view_stop(Evas_Object* ewkView)
1396 {
1397     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1398     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1399
1400     impl->pageProxy->stopLoading();
1401
1402     return true;
1403 }
1404
1405 Ewk_Settings* ewk_view_settings_get(const Evas_Object* ewkView)
1406 {
1407     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1408     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1409
1410     return impl->settings();
1411 }
1412
1413 const char* ewk_view_title_get(const Evas_Object* ewkView)
1414 {
1415     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1416     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1417
1418     return impl->title();
1419 }
1420
1421 /**
1422  * @internal
1423  * Reports that the requested text was found.
1424  *
1425  * Emits signal: "text,found" with the number of matches.
1426  */
1427 void ewk_view_text_found(Evas_Object* ewkView, unsigned int matchCount)
1428 {
1429     evas_object_smart_callback_call(ewkView, "text,found", &matchCount);
1430 }
1431
1432 double ewk_view_load_progress_get(const Evas_Object* ewkView)
1433 {
1434     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1.0);
1435     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, -1.0);
1436
1437     return impl->pageProxy->estimatedProgress();
1438 }
1439
1440 Eina_Bool ewk_view_scale_set(Evas_Object* ewkView, double scaleFactor, int x, int y)
1441 {
1442     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1443     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1444
1445 #if OS(TIZEN)
1446     // FIXME
1447     int centerX = x;
1448     int centerY = y;
1449     scaleFactor = impl->pageClient->adjustScaleWithViewport(scaleFactor);
1450
1451     IntPoint scrollPosition = impl->pageClient->scrollPosition();
1452     double scaleDifference = scaleFactor / impl->pageClient->scaleFactor();
1453     int newScrollX = (scrollPosition.x() + centerX - smartData->view.x) * scaleDifference - (centerX - smartData->view.x);
1454     int newScrollY = (scrollPosition.y() + centerY - smartData->view.y) * scaleDifference - (centerY - smartData->view.y);
1455
1456     impl->pageProxy->scale(scaleFactor, IntPoint(newScrollX, newScrollY));
1457 #else
1458     impl->pageProxy->scalePage(scaleFactor, IntPoint(x, y));
1459 #endif
1460     return true;
1461 }
1462
1463 double ewk_view_scale_get(const Evas_Object* ewkView)
1464 {
1465     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1);
1466     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, -1);
1467
1468 #if OS(TIZEN)
1469     return impl->pageProxy->scaleFactor();
1470 #else
1471     return impl->pageProxy->pageScaleFactor();
1472 #endif
1473 }
1474
1475 Eina_Bool ewk_view_device_pixel_ratio_set(Evas_Object* ewkView, float ratio)
1476 {
1477     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1478     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1479
1480     impl->pageProxy->setCustomDeviceScaleFactor(ratio);
1481
1482     return true;
1483 }
1484
1485 float ewk_view_device_pixel_ratio_get(const Evas_Object* ewkView)
1486 {
1487     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1.0);
1488     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, -1.0);
1489
1490     return impl->pageProxy->deviceScaleFactor();
1491 }
1492
1493 void ewk_view_theme_set(Evas_Object* ewkView, const char* path)
1494 {
1495     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1496     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1497
1498     impl->setThemePath(path);
1499 }
1500
1501 const char* ewk_view_theme_get(const Evas_Object* ewkView)
1502 {
1503     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1504     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1505
1506     return impl->themePath();
1507 }
1508
1509 Eina_Bool ewk_view_back(Evas_Object* ewkView)
1510 {
1511     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1512     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1513
1514     WebPageProxy* page = impl->pageProxy.get();
1515     if (page->canGoBack()) {
1516         page->goBack();
1517         return true;
1518     }
1519
1520     return false;
1521 }
1522
1523 Eina_Bool ewk_view_forward(Evas_Object* ewkView)
1524 {
1525     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1526     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1527
1528     WebPageProxy* page = impl->pageProxy.get();
1529     if (page->canGoForward()) {
1530         page->goForward();
1531         return true;
1532     }
1533
1534     return false;
1535 }
1536
1537 Eina_Bool ewk_view_intent_deliver(Evas_Object* ewkView, Ewk_Intent* intent)
1538 {
1539 #if ENABLE(WEB_INTENTS)
1540     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1541     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1542     EINA_SAFETY_ON_NULL_RETURN_VAL(intent, false);
1543
1544     WebPageProxy* page = impl->pageProxy.get();
1545     page->deliverIntentToFrame(page->mainFrame(), intent->webIntentData());
1546
1547     return true;
1548 #else
1549     return false;
1550 #endif
1551 }
1552
1553 Eina_Bool ewk_view_back_possible(Evas_Object* ewkView)
1554 {
1555     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1556     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1557
1558     return impl->pageProxy->canGoBack();
1559 }
1560
1561 Eina_Bool ewk_view_forward_possible(Evas_Object* ewkView)
1562 {
1563     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1564     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1565
1566     return impl->pageProxy->canGoForward();
1567 }
1568
1569 Ewk_Back_Forward_List* ewk_view_back_forward_list_get(const Evas_Object* ewkView)
1570 {
1571     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1572     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1573
1574     return impl->backForwardList.get();
1575 }
1576
1577 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1578 void ewk_view_text_change_in_textfield(Evas_Object* ewkView, const String& name, const String& value)
1579 {
1580     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1581     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1582
1583     if (!ewk_settings_form_candidate_data_enabled_get(ewk_view_settings_get(ewkView)))
1584         return;
1585
1586     InputMethodContextEfl* imfContext = impl->inputMethodContext();
1587     if (!imfContext || !imfContext->isShow())
1588         return;
1589
1590     if (value.isEmpty()) {
1591         if(smartData->api->formdata_candidate_is_showing(smartData))
1592             smartData->api->formdata_candidate_hide(smartData);
1593         return;
1594     }
1595
1596     Vector<String> popupCandidates;
1597     ewk_view_form_candidate_data_get(ewkView, name, popupCandidates);
1598     std::sort(popupCandidates.begin(), popupCandidates.end(), WTF::codePointCompareLessThan);
1599
1600     Eina_List* candidateList = 0;
1601     for (size_t i = 0; i < popupCandidates.size(); ++i) {
1602         if (popupCandidates[i].startsWith(value, false))
1603             candidateList = eina_list_append(candidateList, eina_stringshare_add(popupCandidates[i].utf8().data()));
1604     }
1605
1606     if (!eina_list_count(candidateList)) {
1607         if(smartData->api->formdata_candidate_is_showing(smartData))
1608             smartData->api->formdata_candidate_hide(smartData);
1609         return;
1610     }
1611
1612     smartData->api->formdata_candidate_update_data(smartData, candidateList);
1613
1614     if (!smartData->api->formdata_candidate_is_showing(smartData))
1615         smartData->api->formdata_candidate_hide(smartData);
1616
1617     IntRect inputFieldRect = impl->pageClient->focusedNodeRect();
1618     smartData->api->formdata_candidate_show(smartData, inputFieldRect.x(), inputFieldRect.y(), inputFieldRect.width(), inputFieldRect.height());
1619 }
1620
1621 void ewk_view_form_data_add(Evas_Object* ewkView, WKDictionaryRef& formData, bool isPasswordForm)
1622 {
1623     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1624     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1625     if (!ewk_settings_autofill_password_form_enabled_get(ewk_view_settings_get(ewkView))
1626         && !ewk_settings_form_candidate_data_enabled_get(ewk_view_settings_get(ewkView)))
1627         return;
1628     ewk_view_context_get(ewkView)->addFormData(impl->url(), formData, isPasswordForm);
1629 }
1630
1631 void ewk_view_form_password_data_fill(Evas_Object* ewkView)
1632 {
1633     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1634     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1635
1636     if (!ewk_settings_autofill_password_form_enabled_get(ewk_view_settings_get(ewkView)))
1637         return;
1638
1639     Vector<std::pair<String, String> > passwordFormData;
1640     ewk_view_context_get(ewkView)->passwordFormData(impl->url(), passwordFormData);
1641
1642     if (!passwordFormData.size())
1643         return;
1644
1645     String passwordFormAutofill = "try { function passwordFormAutofill() { var inputFields;";
1646     for (size_t i = 0; i < passwordFormData.size(); i++) {
1647         passwordFormAutofill += String::format(" inputFields = document.getElementsByName(\"%s\");"
1648             " for (var i = 0; i < inputFields.length; i++)"
1649             " if (inputFields[i].tagName.toLowerCase() == \"input\" && (inputFields[i].type.toLowerCase() == \"text\" || inputFields[i].type.toLowerCase() == \"password\" || inputFields[i].type.toLowerCase() == \"email\"))"
1650             " inputFields[i].value = \"%s\";",
1651             passwordFormData[i].first.utf8().data(), passwordFormData[i].second.utf8().data());
1652     }
1653     passwordFormAutofill += "} passwordFormAutofill(); } catch(e) { }";
1654     ewk_view_script_execute(ewkView, passwordFormAutofill.utf8().data(), 0, 0);
1655 }
1656
1657 void ewk_view_form_candidate_data_get(Evas_Object* ewkView, const String& name, Vector<String>& candidates)
1658 {
1659     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1660     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1661     ewk_view_context_get(ewkView)->candidateFormData(name, candidates);
1662 }
1663 #endif
1664
1665 Eina_Bool ewk_view_html_string_load(Evas_Object* ewkView, const char* html, const char* baseUrl, const char* unreachableUrl)
1666 {
1667     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1668     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1669     EINA_SAFETY_ON_NULL_RETURN_VAL(html, false);
1670
1671     if (unreachableUrl && *unreachableUrl)
1672         impl->pageProxy->loadAlternateHTMLString(String::fromUTF8(html), baseUrl ? String::fromUTF8(baseUrl) : "", String::fromUTF8(unreachableUrl));
1673     else
1674         impl->pageProxy->loadHTMLString(String::fromUTF8(html), baseUrl ? String::fromUTF8(baseUrl) : "");
1675
1676     impl->informURLChange();
1677
1678     return true;
1679 }
1680
1681 const char* ewk_view_custom_encoding_get(const Evas_Object* ewkView)
1682 {
1683     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1684     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1685
1686     return impl->customTextEncodingName();
1687 }
1688
1689 Eina_Bool ewk_view_custom_encoding_set(Evas_Object* ewkView, const char* encoding)
1690 {
1691     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1692     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1693
1694     impl->setCustomTextEncodingName(encoding);
1695
1696     return true;
1697 }
1698
1699 #if OS(TIZEN)
1700 // FIXME: It should be removed.
1701 WKPageRef ewk_view_WKPage_get(Evas_Object* ewkView)
1702 {
1703     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1704     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1705
1706     return toAPI(impl->pageProxy.get());
1707 }
1708
1709 Eina_Bool ewk_view_mouse_events_enabled_set(Evas_Object* ewkView, Eina_Bool enabled)
1710 {
1711     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1712     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1713
1714     impl->setMouseEventsEnabled(!!enabled);
1715
1716     return true;
1717 }
1718
1719 Eina_Bool ewk_view_mouse_events_enabled_get(const Evas_Object* ewkView)
1720 {
1721     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1722     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1723
1724     return impl->mouseEventsEnabled();
1725 }
1726
1727 Eina_Bool ewk_view_color_picker_color_set(Evas_Object* ewkView, int r, int g, int b, int a)
1728 {
1729 #if ENABLE(INPUT_TYPE_COLOR)
1730     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1731     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1732
1733     return impl->setColorPickerColor(WebCore::Color(r, g, b, a));
1734 #else
1735     return false;
1736 #endif
1737 }
1738
1739 static Eina_Bool _ewk_view_default_javascript_alert(Evas_Object* ewkView, const char* alertText, void* userData)
1740 {
1741     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1742     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1743
1744     return impl->javascriptPopup->alert(alertText);
1745 }
1746
1747 static Eina_Bool _ewk_view_default_javascript_confirm(Evas_Object* ewkView, const char* message, void* userData)
1748 {
1749     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1750     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1751
1752     return impl->javascriptPopup->confirm(message);
1753 }
1754
1755 static Eina_Bool _ewk_view_default_javascript_prompt(Evas_Object* ewkView, const char* message, const char* defaultValue, void* userData)
1756 {
1757     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1758     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1759
1760     return impl->javascriptPopup->prompt(message, defaultValue);
1761 }
1762
1763 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
1764 static Eina_Bool _ewk_view_default_before_unload_confirm_panel(Evas_Object* ewkView, const char* message, void* userData)
1765 {
1766     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1767     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1768
1769     return impl->javascriptPopup->beforeUnloadConfirmPanel(message);
1770 }
1771 #endif
1772
1773 static Eina_Bool _ewk_view_default_open_panel(Evas_Object* ewkView, Eina_Bool allow_multiple_files, Eina_List *accepted_mime_types, const char* capture, void* userData)
1774 {
1775     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1776     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1777
1778     return impl->openPanel->openPanel(ewkView, allow_multiple_files, accepted_mime_types, capture, impl);
1779 }
1780
1781 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1782 Eina_Bool _ewk_view_popup_menu_show(Ewk_View_Smart_Data* smartData, Eina_Rectangle rect, Ewk_Text_Direction text_direction, double page_scale_factor, Eina_List* items, int selectedIndex)
1783 {
1784     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1785
1786     if (impl->popupPicker)
1787         ewk_popup_picker_del(impl->popupPicker);
1788
1789 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1790     impl->popupPicker = ewk_popup_picker_new(smartData->self, items, selectedIndex, false);
1791 #else
1792     impl->popupPicker = ewk_popup_picker_new(smartData->self, items, selectedIndex);
1793 #endif
1794
1795     return true;
1796 }
1797
1798 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1799 Eina_Bool _ewk_view_multiple_popup_menu_show(Ewk_View_Smart_Data* smartData, Eina_Rectangle rect, Ewk_Text_Direction text_direction, double page_scale_factor, Eina_List* items)
1800 {
1801     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1802
1803     if (impl->popupPicker)
1804         ewk_popup_picker_del(impl->popupPicker);
1805
1806     impl->popupPicker = ewk_popup_picker_new(smartData->self, items, 0, true);
1807
1808     return true;
1809 }
1810 #endif
1811
1812 Eina_Bool _ewk_view_popup_menu_hide(Ewk_View_Smart_Data* smartData)
1813 {
1814     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1815
1816     if (!impl->popupPicker)
1817         return false;
1818
1819     ewk_popup_picker_del(impl->popupPicker);
1820     impl->popupPicker = 0;
1821
1822     return true;
1823 }
1824
1825 Eina_Bool _ewk_view_popup_menu_update(Ewk_View_Smart_Data* smartData, Eina_Rectangle rect, Ewk_Text_Direction text_direction, Eina_List* items, int selectedIndex)
1826 {
1827     // FIXME: The rect should be updated if it was changed
1828
1829     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1830
1831     if (!impl->popupPicker)
1832         return false;
1833
1834     ewk_popup_picker_update(smartData->self, impl->popupPicker, items, selectedIndex);
1835
1836     return true;
1837 }
1838 #endif
1839
1840 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1841 static Eina_Bool _ewk_view_input_picker_show(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType, const char* inputValue)
1842 {
1843     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1844
1845     impl->inputPicker->show(inputType, inputValue);
1846     return true;
1847 }
1848 #endif
1849
1850 #if ENABLE(TIZEN_DATALIST_ELEMENT)
1851 static Eina_Bool _ewk_view_data_list_show(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType, Eina_List* optionList)
1852 {
1853     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1854
1855     impl->inputPicker->showDataList(inputType, optionList);
1856     return true;
1857 }
1858
1859 static Eina_Bool _ewk_view_data_list_hide(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType)
1860 {
1861     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1862
1863     impl->inputPicker->hideDataList(inputType);
1864     return true;
1865 }
1866 #endif
1867
1868 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
1869 static Eina_Bool _ewk_input_picker_color_request(Ewk_View_Smart_Data* smartData, int r, int g, int b, int a)
1870 {
1871     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1872
1873     impl->inputPicker->showColorPicker(r, g, b, a);
1874     return true;
1875 }
1876
1877 static Eina_Bool _ewk_input_picker_color_dismiss(Ewk_View_Smart_Data* smartData)
1878 {
1879     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1880
1881     impl->inputPicker->hideColorPicker();
1882     return true;
1883 }
1884 #endif
1885
1886 PageClientImpl* ewkViewGetPageClient(const Evas_Object* ewkView)
1887 {
1888     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1889     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1890
1891     return impl->pageClient.get();
1892 }
1893
1894 double ewk_view_text_zoom_get(const Evas_Object* ewkView)
1895 {
1896     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 1);
1897     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 1);
1898
1899     return WKPageGetTextZoomFactor(toAPI(impl->pageProxy.get()));
1900 }
1901
1902 Eina_Bool ewk_view_text_zoom_set(Evas_Object* ewkView, double textZoomFactor)
1903 {
1904     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1905     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1906
1907     WKPageSetTextZoomFactor(toAPI(impl->pageProxy.get()), textZoomFactor);
1908     return true;
1909 }
1910
1911 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1912 FocusRing* ewkViewGetFocusRing(Evas_Object* ewkView)
1913 {
1914     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1915     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1916
1917     return impl->focusRing.get();
1918 }
1919 #endif
1920
1921 Ewk_Frame_Ref ewk_view_main_frame_get(Evas_Object* ewkView)
1922 {
1923     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1924     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1925
1926     return static_cast<Ewk_Frame_Ref>(WKPageGetMainFrame(toAPI(impl->pageProxy.get())));
1927 }
1928
1929 Ewk_Frame_Ref ewk_view_focused_frame_get(Evas_Object* ewkView)
1930 {
1931     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1932     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1933
1934     return static_cast<Ewk_Frame_Ref>(WKPageGetFocusedFrame(toAPI(impl->pageProxy.get())));
1935 }
1936
1937 JSGlobalContextRef ewkViewGetJavascriptGlobalContext(Evas_Object* ewkView)
1938 {
1939     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1940     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1941
1942     if (!impl->javascriptGlobalContext)
1943         impl->javascriptGlobalContext = JSGlobalContextCreate(0);
1944     return impl->javascriptGlobalContext;
1945 }
1946
1947 void ewkViewLoadCommitted(Evas_Object* ewkView)
1948 {
1949 #if ENABLE(TIZEN_GESTURE)
1950     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1951     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1952     impl->gestureClient->reset();
1953 #endif
1954 #if ENABLE(TIZEN_ISF_PORT)
1955     impl->inputMethodContext()->hideIMFContext();
1956 #endif
1957     impl->informURLChange();
1958     evas_object_smart_callback_call(ewkView, "load,committed", 0);
1959 }
1960
1961 void ewkViewLoadError(Evas_Object* ewkView, WKErrorRef error)
1962 {
1963     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1964     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1965
1966     OwnPtr<Ewk_Error> ewkError = Ewk_Error::create(error);
1967     ewk_error_load_error_page(ewkError.get(), toAPI(impl->pageProxy.get()));
1968     evas_object_smart_callback_call(ewkView, "load,error", ewkError.get());
1969 }
1970
1971 void ewkViewDidFirstVisuallyNonEmptyLayout(Evas_Object* ewkView)
1972 {
1973 #if ENABLE(TIZEN_GESTURE)
1974     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1975     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1976     impl->gestureClient->reset();
1977 #endif
1978     evas_object_smart_callback_call(ewkView, "load,nonemptylayout,finished", 0);
1979 }
1980
1981 void ewkViewDidReceiveAuthenticationChallenge(Evas_Object* ewkView, Ewk_Auth_Challenge* authChallenge)
1982 {
1983     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1984     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1985
1986     if (impl->authChallenge)
1987         ewkAuthChallengeDelete(impl->authChallenge);
1988     impl->authChallenge = authChallenge;
1989
1990     evas_object_smart_callback_call(ewkView, "authentication,challenge", impl->authChallenge);
1991 }
1992
1993 void ewk_view_process_crashed(Evas_Object* ewkView)
1994 {
1995     bool handled = false;
1996     evas_object_smart_callback_call(ewkView, "process,crashed", &handled);
1997
1998     if (!handled)
1999         exit(0);
2000 }
2001
2002 #if ENABLE(TIZEN_SQL_DATABASE)
2003 bool ewkViewExceededDatabaseQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, WKStringRef databaseName, unsigned long long expectedUsage)
2004 {
2005     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2006     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2007
2008     if (!impl->exceededDatabaseQuotaContext || !impl->exceededDatabaseQuotaContext->exceededDatabaseQuotaCallback)
2009         return false;
2010
2011     TIZEN_LOGI("No error in prameter. Request to display user confirm popup. expectedUsage(%llu)", expectedUsage);
2012     impl->isWaitingForExceededQuotaPopupReply = true;
2013     if (impl->exceededQuotaOrigin)
2014         deleteSecurityOrigin(impl->exceededQuotaOrigin);
2015     impl->exceededQuotaOrigin = createSecurityOrigin(origin);
2016
2017     int length = WKStringGetMaximumUTF8CStringSize(databaseName);
2018     OwnArrayPtr<char> databaseNameBuffer = adoptArrayPtr(new char[length]);
2019     WKStringGetUTF8CString(databaseName, databaseNameBuffer.get(), length);
2020
2021     return impl->exceededDatabaseQuotaContext->exceededDatabaseQuotaCallback(ewkView, impl->exceededQuotaOrigin, databaseNameBuffer.get(), expectedUsage, impl->exceededDatabaseQuotaContext->userData) == EINA_TRUE;
2022 }
2023 #endif
2024
2025 #if ENABLE(TIZEN_NOTIFICATIONS)
2026 void ewkViewCancelNotification(Evas_Object* ewkView, uint64_t notificationID)
2027 {
2028     TIZEN_LOGI("notification,cancel");
2029     evas_object_smart_callback_call(ewkView, "notification,cancel", &notificationID);
2030 }
2031
2032 void ewkViewRequestNotificationPermission(Evas_Object* ewkView, Ewk_Notification_Permission_Request* notificationPermissionRequest)
2033 {
2034     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2035     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2036
2037     TIZEN_LOGI("notification,permission,request");
2038     impl->notificationPermissionRequests = eina_list_append(impl->notificationPermissionRequests, notificationPermissionRequest);
2039     evas_object_smart_callback_call(ewkView, "notification,permission,request", notificationPermissionRequest);
2040 }
2041
2042 void ewkViewShowNotification(Evas_Object* ewkView, Ewk_Notification* notification)
2043 {
2044     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2045     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2046
2047     TIZEN_LOGI("notification,show");
2048     Eina_List* listIterator=0;
2049     void* data=0;
2050     const char* replaceID = ewkNotificationGetReplaceID(notification);
2051     if(strlen(replaceID)) {
2052         EINA_LIST_FOREACH(impl->notifications, listIterator, data) {
2053             Ewk_Notification* notificationForReplace = static_cast<Ewk_Notification*>(data);
2054             if(!strcmp(ewkNotificationGetReplaceID(notificationForReplace), replaceID))
2055                 ewkViewCancelNotification(ewkView, ewk_notification_id_get(notificationForReplace));
2056         }
2057     }
2058
2059     impl->notifications = eina_list_append(impl->notifications, notification);
2060     evas_object_smart_callback_call(ewkView, "notification,show", notification);
2061 }
2062
2063 void ewkViewDeleteNotificationPermissionRequest(Evas_Object* ewkView, Ewk_Notification_Permission_Request* ewkNotificationPermissionRequest)
2064 {
2065     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2066     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2067
2068     impl->notificationPermissionRequests = eina_list_remove(impl->notificationPermissionRequests, ewkNotificationPermissionRequest);
2069 }
2070 #endif
2071
2072 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER)
2073 void ewkViewRegisterProtocolHandlers(Evas_Object* ewkView, const char* scheme, const char* baseUrl, const char* url, const char* title)
2074 {
2075     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2076
2077     TIZEN_LOGI("protocolhandler,registration,requested");
2078     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(scheme, baseUrl, url, title);
2079     evas_object_smart_callback_call(ewkView, "protocolhandler,registration,requested", static_cast<void*>(customHandlersData));
2080     ewkCustomHandlersDeleteData(customHandlersData);
2081 }
2082 #endif
2083
2084 #if ENABLE(TIZEN_CUSTOM_SCHEME_HANDLER)
2085 Ewk_Custom_Handlers_State ewkViewIsProtocolHandlerRegistered(Evas_Object* ewkView, const char* scheme, const char* baseURL, const char* url)
2086 {
2087     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, EWK_CUSTOM_HANDLERS_DECLINED);
2088
2089     TIZEN_LOGI("protocolhandler,isregistered");
2090     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(scheme, baseURL, url);
2091     evas_object_smart_callback_call(ewkView, "protocolhandler,isregistered", static_cast<void*>(customHandlersData));
2092
2093     Ewk_Custom_Handlers_State result;
2094     result = ewkGetCustomHandlersDataResult(customHandlersData);
2095     ewkCustomHandlersDeleteData(customHandlersData);
2096
2097     return result;
2098 }
2099
2100 void ewkViewUnregisterProtocolHandlers(Evas_Object* ewkView, const char* scheme, const char* baseURL, const char* url)
2101 {
2102     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2103
2104     TIZEN_LOGI("protocolhandler,unregistration,requested");
2105     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(scheme, baseURL, url);
2106     evas_object_smart_callback_call(ewkView, "protocolhandler,unregistration,requested", static_cast<void*>(customHandlersData));
2107     ewkCustomHandlersDeleteData(customHandlersData);
2108 }
2109 #endif
2110
2111 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
2112 void ewkViewRegisterContentHandlers(Evas_Object* ewkView, const char* mimeType, const char* baseUrl, const char* url, const char* title)
2113 {
2114     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2115
2116     TIZEN_LOGI("contenthandler,registration,requested");
2117     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(mimeType, baseUrl, url, title);
2118     evas_object_smart_callback_call(ewkView, "contenthandler,registration,requested", static_cast<void*>(customHandlersData));
2119     ewkCustomHandlersDeleteData(customHandlersData);
2120 }
2121
2122 Ewk_Custom_Handlers_State ewkViewIsContentHandlerRegistered(Evas_Object* ewkView, const char* mimeType, const char* baseURL, const char* url)
2123 {
2124     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, EWK_CUSTOM_HANDLERS_DECLINED);
2125
2126     TIZEN_LOGI("contenthandler,isregistered");
2127     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(mimeType, baseURL, url);
2128     evas_object_smart_callback_call(ewkView, "contenthandler,isregistered", static_cast<void*>(customHandlersData));
2129
2130     Ewk_Custom_Handlers_State result;
2131     result = ewkGetCustomHandlersDataResult(customHandlersData);
2132     ewkCustomHandlersDeleteData(customHandlersData);
2133
2134     return result;
2135 }
2136
2137 void ewkViewUnregisterContentHandlers(Evas_Object* ewkView, const char* mimeType, const char* baseURL, const char* url)
2138 {
2139     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2140
2141     TIZEN_LOGI("contenthandler,unregistration,requested");
2142     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(mimeType, baseURL, url);
2143     evas_object_smart_callback_call(ewkView, "contenthandler,unregistration,requested", static_cast<void*>(customHandlersData));
2144     ewkCustomHandlersDeleteData(customHandlersData);
2145 }
2146 #endif
2147
2148 #if ENABLE(TIZEN_SEARCH_PROVIDER)
2149 void ewkViewAddSearchProvider(Evas_Object* ewkView, const char* baseURL, const char* engineURL)
2150 {
2151     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2152
2153     TIZEN_LOGI("searchProvider,add");
2154     Ewk_Search_Provider_Data* searchProviderData = ewkSearchProviderCreateData(baseURL, engineURL);
2155     evas_object_smart_callback_call(ewkView, "searchProvider,add", static_cast<void*>(searchProviderData));
2156     ewkSearchProviderDeleteData(searchProviderData);
2157 }
2158
2159 unsigned long ewkViewIsSearchProviderInstalled(Evas_Object* ewkView, const char* baseURL, const char* engineURL)
2160 {
2161     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, 0);
2162
2163     TIZEN_LOGI("searchProvider,installed");
2164     Ewk_Search_Provider_Data* searchProviderData = ewkSearchProviderCreateData(baseURL, engineURL);
2165     evas_object_smart_callback_call(ewkView, "searchProvider,installed", static_cast<void*>(searchProviderData));
2166     unsigned long result;
2167     result = ewkGetSearchProviderResult(searchProviderData);
2168     ewkSearchProviderDeleteData(searchProviderData);
2169     return result;
2170 }
2171 #endif
2172
2173 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
2174 bool ewkViewGetStandaloneStatus(Evas_Object* ewkView)
2175 {
2176     TIZEN_LOGI("webapp,metatag,standalone");
2177     bool standalone = true;
2178     evas_object_smart_callback_call(ewkView, "webapp,metatag,standalone", (void*)&standalone);
2179     return standalone;
2180 }
2181 #endif
2182
2183 #if ENABLE(TIZEN_MEDIA_STREAM)
2184 void ewkViewRequestUserMediaPermission(Evas_Object* ewkView, Ewk_User_Media_Permission_Request* userMediaPermission)
2185 {
2186     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2187     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2188
2189     impl->userMediaPermissionRequests = eina_list_append(impl->userMediaPermissionRequests, userMediaPermission);
2190     evas_object_smart_callback_call(ewkView, "usermedia,permission,request", userMediaPermission);
2191 }
2192
2193 void ewkViewDeleteUserMediaPermissionRequest(Evas_Object* ewkView, Ewk_User_Media_Permission_Request* permission)
2194 {
2195     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2196     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2197
2198     impl->userMediaPermissionRequests = eina_list_remove(impl->userMediaPermissionRequests, permission);
2199 }
2200
2201 #endif
2202
2203 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
2204 void ewkViewProcessJSBridgePlugin(Evas_Object* ewkView, WKStringRef request, WKStringRef message)
2205 {
2206     int requestLength = WKStringGetMaximumUTF8CStringSize(request);
2207     OwnArrayPtr<char> requestBuffer = adoptArrayPtr(new char[requestLength]);
2208     int messageLength = WKStringGetMaximumUTF8CStringSize(message);
2209     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[messageLength]);
2210     WKStringGetUTF8CString(request, requestBuffer.get(), requestLength);
2211     WKStringGetUTF8CString(message, messageBuffer.get(), messageLength);
2212
2213     evas_object_smart_callback_call(ewkView, requestBuffer.get(), static_cast<void*>(messageBuffer.get()));
2214 }
2215 #endif
2216
2217 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
2218 void ewkViewRequestCertificateConfirm(Evas_Object* ewkView, Ewk_Certificate_Policy_Decision* certificatePolicyDecision)
2219 {
2220     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2221     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2222     if (impl->certificatePolicyDecision)
2223         ewkCertificatePolicyDecisionDelete(impl->certificatePolicyDecision);
2224     impl->certificatePolicyDecision = certificatePolicyDecision;
2225
2226     evas_object_smart_callback_call(ewkView, "request,certificate,confirm", certificatePolicyDecision);
2227 }
2228 #endif
2229
2230 void ewkViewCustomizeContextMenu(Evas_Object* ewkView, Ewk_Context_Menu* menu)
2231 {
2232     evas_object_smart_callback_call(ewkView, "contextmenu,customize", static_cast<void*>(menu));
2233 }
2234
2235 void ewkViewCustomContextMenuItemSelected(Evas_Object* ewkView, Ewk_Context_Menu_Item* item)
2236 {
2237     evas_object_smart_callback_call(ewkView, "contextmenu,selected", static_cast<void*>(item));
2238 }
2239
2240 #if ENABLE(TIZEN_GEOLOCATION)
2241 void ewkViewRequestGeolocationPermission(Evas_Object* ewkView, Ewk_Geolocation_Permission_Request* geolocationPermissionRequest)
2242 {
2243     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2244     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2245
2246     TIZEN_LOGI("geolocation,permission,request");
2247     impl->geolocationPermissionRequests = eina_list_append(impl->geolocationPermissionRequests, geolocationPermissionRequest);
2248     evas_object_smart_callback_call(ewkView, "geolocation,permission,request", geolocationPermissionRequest);
2249 }
2250
2251 void ewkViewDeleteGeolocationPermission(Evas_Object* ewkView, Ewk_Geolocation_Permission_Request* geolocationPermissionRequest)
2252 {
2253     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2254     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2255
2256     impl->geolocationPermissionRequests = eina_list_remove(impl->geolocationPermissionRequests, geolocationPermissionRequest);
2257 }
2258
2259 void ewkViewSetGeolocation(Evas_Object* ewkView, Ewk_Geolocation* geolocation)
2260 {
2261     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2262     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2263
2264     impl->geolocation = geolocation;
2265 }
2266
2267 Ewk_Geolocation* ewkViewGetGeolocation(Evas_Object* ewkView)
2268 {
2269     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2270     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2271
2272     return impl->geolocation;
2273 }
2274
2275 bool ewkViewIsValidLocationService(Evas_Object* ewkView)
2276 {
2277     TIZEN_LOGI("geolocation,valid");
2278
2279     bool valid = true;
2280     evas_object_smart_callback_call(ewkView, "geolocation,valid", &valid);
2281     return valid;
2282 }
2283 #endif
2284
2285 void ewkViewFormSubmit(Evas_Object* ewkView, Ewk_Form_Data* formData)
2286 {
2287     evas_object_smart_callback_call(ewkView, "form,submit", formData);
2288 }
2289
2290 void ewkViewPolicyNavigationDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2291 {
2292     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2293     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2294     if (impl->policyDecision)
2295         ewkPolicyDecisionDelete(impl->policyDecision);
2296     impl->policyDecision = policyDecision;
2297
2298     evas_object_smart_callback_call(ewkView, "policy,navigation,decide", impl->policyDecision);
2299 }
2300
2301 void ewkViewPolicyNewWindowDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2302 {
2303     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2304     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2305     if (impl->policyDecision)
2306         ewkPolicyDecisionDelete(impl->policyDecision);
2307     impl->policyDecision = policyDecision;
2308
2309     evas_object_smart_callback_call(ewkView, "policy,newwindow,decide", impl->policyDecision);
2310 }
2311
2312 void ewkViewPolicyResponseDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2313 {
2314     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2315     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2316     if (impl->policyDecision)
2317         ewkPolicyDecisionDelete(impl->policyDecision);
2318     impl->policyDecision = policyDecision;
2319
2320     evas_object_smart_callback_call(ewkView, "policy,response,decide", impl->policyDecision);
2321 }
2322
2323 void ewkViewSendScrollEvent(Evas_Object* ewkView, int deltaX, int deltaY)
2324 {
2325     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2326     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2327
2328     IntPoint scrollPosition = impl->pageClient->scrollPosition();
2329     IntSize contentsSize = impl->pageProxy->contentsSize();
2330 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2331     contentsSize.scale(impl->pageClient->scaleFactor());
2332 #endif
2333
2334     // some website's contents size is smaller than view size,
2335     // so we have to adjust contents size to view size for that case.
2336     if (contentsSize.width() < smartData->view.w)
2337         contentsSize.setWidth(smartData->view.w);
2338     if (contentsSize.height() < smartData->view.h)
2339         contentsSize.setHeight(smartData->view.h);
2340
2341     // Call "scroll,down" if webview can be scrolled down.
2342     if (deltaY > 0 && (scrollPosition.y() + smartData->view.h) < contentsSize.height())
2343         evas_object_smart_callback_call(ewkView, "scroll,down", 0);
2344     // Call "scroll,up" if webview can be scrolled up.
2345     else if (deltaY < 0 && scrollPosition.y() > 0)
2346         evas_object_smart_callback_call(ewkView, "scroll,up", 0);
2347
2348     // Call "scroll,right" if webview can be scrolled down.
2349     if (deltaX > 0 && (scrollPosition.x() + smartData->view.w) < contentsSize.width())
2350         evas_object_smart_callback_call(ewkView, "scroll,right", 0);
2351     // Call "scroll,left" if webview can be scrolled up.
2352     else if (deltaX < 0 && scrollPosition.x() > 0)
2353         evas_object_smart_callback_call(ewkView, "scroll,left", 0);
2354 }
2355
2356 void ewkViewSendEdgeEvent(Evas_Object* ewkView, const IntPoint& scrollPosition, int deltaX, int deltaY)
2357 {
2358     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2359     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2360
2361     IntSize contentsSize = impl->pageProxy->contentsSize();
2362 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2363     contentsSize.scale(impl->pageClient->scaleFactor());
2364 #endif
2365
2366     int maxScrollY = contentsSize.height() - smartData->view.h;
2367     if (!impl->isVerticalEdge) {
2368         if (deltaY < 0 && (scrollPosition.y() + deltaY) <= 0) {
2369             evas_object_smart_callback_call(ewkView, "edge,top", NULL);
2370             impl->isVerticalEdge = true;
2371         } else if (deltaY > 0 && (scrollPosition.y() + deltaY) >= maxScrollY) {
2372             evas_object_smart_callback_call(ewkView, "edge,bottom", NULL);
2373             impl->isVerticalEdge = true;
2374         }
2375     } else {
2376         if (maxScrollY && ((scrollPosition.y() == 0 && deltaY > 0)
2377                            || (scrollPosition.y() == maxScrollY && deltaY < 0)))
2378             impl->isVerticalEdge = false;
2379     }
2380
2381     int maxScrollX = contentsSize.width() - smartData->view.w;
2382     if (!impl->isHorizontalEdge) {
2383         if (deltaX < 0 && (scrollPosition.x() + deltaX) <= 0) {
2384             evas_object_smart_callback_call(ewkView, "edge,left", NULL);
2385             impl->isHorizontalEdge = true;
2386         } else if (deltaX > 0 && (scrollPosition.x() + deltaX) >= maxScrollX) {
2387             evas_object_smart_callback_call(ewkView, "edge,right", NULL);
2388             impl->isHorizontalEdge = true;
2389         }
2390     } else {
2391         if (maxScrollX && ((scrollPosition.x() == 0 && deltaX > 0)
2392                            || (scrollPosition.x() == maxScrollX && deltaX < 0)))
2393             impl->isHorizontalEdge = false;
2394     }
2395 }
2396
2397 void ewkViewClearEdges(Evas_Object* ewkView)
2398 {
2399     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2400     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2401
2402     impl->isVerticalEdge = false;
2403     impl->isHorizontalEdge = false;
2404 }
2405
2406 void ewk_view_scale_range_get(Evas_Object* ewkView, double* minimumScale, double* maximumScale)
2407 {
2408     EWK_VIEW_SD_GET(ewkView, smartData);
2409     if (!smartData || !smartData->priv) {
2410         if (minimumScale)
2411             *minimumScale = -1;
2412         if (maximumScale)
2413             *maximumScale = -1;
2414         return;
2415     }
2416
2417     PageClientImpl::ViewportConstraints constraints = smartData->priv->pageClient->viewportConstraints();
2418     if (minimumScale)
2419         *minimumScale = constraints.minimumScale;
2420     if (maximumScale)
2421         *maximumScale = constraints.maximumScale;
2422 }
2423
2424 bool ewk_view_focused_node_adjust(Evas_Object* ewkView, Eina_Bool adjustForExternalKeyboard)
2425 {
2426     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2427     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2428
2429     double scaleFactor = impl->pageClient->scaleFactor();
2430     IntSize contentsSize = impl->pageProxy->contentsSize();
2431
2432     double newScaleFactor = scaleFactor;
2433     // Readable zoom value is dependent on device DPI
2434     if (scaleFactor < impl->pageProxy->deviceScaleFactor()
2435         && impl->pageClient->viewportConstraints().userScalable)
2436         newScaleFactor = impl->pageProxy->deviceScaleFactor();
2437
2438     // Readable zoom value should be inside of viewport scale range
2439     newScaleFactor = impl->pageClient->adjustScaleWithViewport(newScaleFactor);
2440
2441     // scale contents' size with new scale factor
2442 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2443     contentsSize.scale(newScaleFactor);
2444 #else
2445     contentsSize.scale(newScaleFactor / scaleFactor);
2446 #endif
2447
2448 #if ENABLE(TIZEN_ISF_PORT)
2449     Ecore_X_Window rootWin = ecore_x_window_root_first_get();
2450     ecore_x_event_mask_set(rootWin, ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
2451     Ecore_X_Atom xAtom = ecore_x_atom_get("X External Keyboard Exist");
2452     unsigned int connectedKeyboardNum = 0;
2453     bool isExternalKeyboardConnected = false;
2454
2455     // get connected keyboard number
2456     if (ecore_x_window_prop_card32_get(rootWin, xAtom, &connectedKeyboardNum, 1)
2457         && connectedKeyboardNum)
2458         isExternalKeyboardConnected = true;
2459
2460     // We should treat both of ECORE_IMF_INPUT_PANEL_STATE_SHOW and ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW
2461     // as IME is shown. ECORE_IMF_INPUT_PANEL_STATE_HIDE is ignored at here.
2462     // input field zoom should not work with below conditions
2463     // 1. view is not focused
2464     // 2. external keyboard is not connected(if adjustForExternalKeyboard is true)
2465     // 3. imfContext is null(if adjustForExternalKeyboard is false)
2466     // 4. input panel state is hidden(if adjustForExternalKeyboard is false)
2467     if ((!(static_cast<PageClient*>(impl->pageClient.get()))->isViewFocused()
2468         || (adjustForExternalKeyboard && !isExternalKeyboardConnected)
2469         || (!adjustForExternalKeyboard && !impl->inputMethodContext())
2470         || (!adjustForExternalKeyboard && !impl->inputMethodContext()->isShow()))
2471 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
2472         && !(impl->pageClient->isClipboardWindowOpened())
2473 #endif
2474         )
2475         return false;
2476 #endif
2477
2478     // caret position can be outside of visible rect.
2479     // we need to consider it.
2480     IntRect selectionRect = impl->pageProxy->getSelectionRect(true);
2481     IntRect focusedNodeRect = impl->pageClient->focusedNodeRect();
2482 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2483     selectionRect.scale(newScaleFactor);
2484     focusedNodeRect.scale(newScaleFactor);
2485 #else
2486     selectionRect.scale(newScaleFactor / scaleFactor);
2487     focusedNodeRect.scale(newScaleFactor / scaleFactor);
2488 #endif
2489     if (selectionRect.isEmpty())
2490         return false;
2491
2492     IntRect visibleRect = impl->pageClient->visibleContentRect();
2493     IntPoint scrollPosition = visibleRect.location();
2494     // Do not adjust scroll position if selection rect (caret) is visible after scaling.
2495     if (!visibleRect.contains(selectionRect)) {
2496         // set paddings
2497         scrollPosition = IntPoint(selectionRect.x() - visibleRect.width() / 3, selectionRect.y() - visibleRect.height() / 3);
2498         // If both input field's position x and selection rect can be displayed together,
2499         // adjust scroll position to input field's position x.
2500         if (!focusedNodeRect.isEmpty() && selectionRect.x() - focusedNodeRect.x() < visibleRect.width() * 4 / 5)
2501             scrollPosition.setX(focusedNodeRect.x());
2502     }
2503
2504 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2505     impl->pageClient->setVisibleContentRect(IntRect(scrollPosition, impl->size()), newScaleFactor);
2506 #else
2507     if (newScaleFactor != scaleFactor)
2508         impl->pageProxy->scalePage(newScaleFactor, scrollPosition);
2509     else
2510         impl->pageProxy->scrollMainFrameTo(scrollPosition);
2511 #endif
2512     evas_object_move(smartData->image, smartData->view.x, smartData->view.y);
2513     return true;
2514 }
2515
2516 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
2517 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
2518 static Eina_Bool _ewk_view_composite(void* data)
2519 {
2520     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
2521     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2522
2523     if (!evas_object_visible_get(smartData->image))
2524         return ECORE_CALLBACK_CANCEL;
2525
2526     Evas_Coord ow, oh;
2527     evas_object_image_size_get(smartData->image, &ow, &oh);
2528     uint8_t* pixels = static_cast<uint8_t*>(evas_object_image_data_get(smartData->image, true));
2529
2530     RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_ARGB32, ow, oh, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ow)));
2531     RefPtr<cairo_t> context = adoptRef(cairo_create(surface.get()));
2532
2533     cairo_save(context.get());
2534     cairo_set_operator(context.get(), CAIRO_OPERATOR_CLEAR);
2535     cairo_rectangle(context.get(), 0, 0, ow, oh);
2536     cairo_fill(context.get());
2537     cairo_restore(context.get());
2538
2539     impl->pageClient->drawContents(context.get());
2540
2541     evas_object_image_data_set(smartData->image, pixels);
2542     evas_object_image_data_update_add(smartData->image, 0, 0, ow, oh);
2543
2544     ewkViewFrameRendered(smartData->self);
2545
2546     impl->compositionAnimator = 0;
2547
2548     return ECORE_CALLBACK_CANCEL;
2549 }
2550 #endif
2551
2552 void ewk_view_mark_for_sync(Evas_Object* ewkView)
2553 {
2554     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2555     EINA_SAFETY_ON_NULL_RETURN(smartData->image);
2556
2557 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
2558     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2559
2560     if (!ewk_view_is_opengl_backend(ewkView)) {
2561         if (!impl->compositionAnimator)
2562             impl->compositionAnimator = ecore_animator_add(_ewk_view_composite, smartData);
2563         return;
2564     }
2565 #endif
2566
2567     evas_object_image_pixels_dirty_set(smartData->image, true);
2568 }
2569
2570 static void on_pixels_for_accelerated_compositing(void* data, Evas_Object* obj)
2571 {
2572     Evas_Object* ewkView = static_cast<Evas_Object*>(data);
2573     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2574     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2575     impl->pageClient->drawContents();
2576 }
2577
2578 bool ewk_view_image_native_surface_set(Evas_Object* ewkView, Evas_Native_Surface* nativeSurface)
2579 {
2580     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2581     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2582
2583     if (!smartData->image)
2584         return false;
2585
2586     evas_object_image_native_surface_set(smartData->image, nativeSurface);
2587     evas_object_image_pixels_get_callback_set(smartData->image, on_pixels_for_accelerated_compositing, ewkView);
2588
2589     return true;
2590 }
2591 #endif
2592
2593 void _ewk_view_suspend_painting(Evas_Object* ewkView)
2594 {
2595     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2596     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2597
2598     if (!impl->suspendedPainting) {
2599         impl->pageProxy->suspendPainting();
2600         impl->suspendedPainting = true;
2601     }
2602 }
2603
2604 void _ewk_view_resume_painting(Evas_Object* ewkView)
2605 {
2606     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2607     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2608
2609     if (impl->suspendedPainting) {
2610         impl->pageProxy->resumePainting();
2611         impl->suspendedPainting = false;
2612     }
2613 }
2614
2615 void ewk_view_suspend(Evas_Object* ewkView)
2616 {
2617     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2618     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2619
2620     if (impl->pageProxy->estimatedProgress() < 1.0) {
2621         impl->suspendRequested = true;
2622         return;
2623     }
2624     impl->suspendRequested = false;
2625
2626     _ewk_view_suspend_painting(ewkView);
2627
2628     // FIXME Workaround for suspend/resume while javascript popup is displayed.
2629     // condition ' && !private->isWaitingForJavaScriptPopupReply' is added to
2630     // skip suspendJavaScriptAndResource to prevent multiple ActiveDOMObject
2631     // suspend.
2632     // During the javascript popup is displayed, PageGroupLoadDeferrer is activated,
2633     // which suspends resource loading and scheduled tasks, including ActiveDOMObject.
2634     // When ewk_view_suspend() is called during the javascript popup, scheduled tasks
2635     // will be suspended again.
2636     // Multiple suspend of ActiveDOMObject makes unintended suspend/resume status of
2637     // the ActiveDOMObject.
2638     if (!impl->suspendedResources && (!impl->isWaitingForJavaScriptPopupReply || !impl->isWaitingForApplicationCachePermission || !impl->isWaitingForExceededQuotaPopupReply)) {
2639         impl->pageProxy->suspendJavaScriptAndResource();
2640         impl->suspendedResources = true;
2641     }
2642
2643 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
2644     impl->pageProxy->suspendPlugin();
2645 #endif
2646 }
2647
2648 void ewk_view_resume(Evas_Object* ewkView)
2649 {
2650     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2651     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2652
2653     if (impl->suspendRequested) {
2654         impl->suspendRequested = false;
2655         return;
2656     }
2657
2658     _ewk_view_resume_painting(ewkView);
2659
2660     // FIXME Workaround for suspend/resume while javascript popup is displayed.
2661     // condition ' && !private->isWaitingForJavaScriptPopupReply' is added to
2662     // skip suspendJavaScriptAndResource to prevent multiple ActiveDOMObject
2663     // suspend.
2664     // During the javascript popup is displayed, PageGroupLoadDeferrer is activated,
2665     // which suspends resource loading and scheduled tasks, including ActiveDOMObject.
2666     // When ewk_view_suspend() is called during the javascript popup, scheduled tasks
2667     // will be suspended again.
2668     // Multiple suspend of ActiveDOMObject makes unintended suspend/resume status of
2669     // the ActiveDOMObject.
2670     if (impl->suspendedResources && (!impl->isWaitingForJavaScriptPopupReply || !impl->isWaitingForApplicationCachePermission || !impl->isWaitingForExceededQuotaPopupReply)) {
2671         impl->pageProxy->resumeJavaScriptAndResource();
2672         impl->suspendedResources = false;
2673     }
2674
2675 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
2676     impl->pageProxy->resumePlugin();
2677 #endif
2678 }
2679
2680 Eina_Bool ewk_view_url_request_set(Evas_Object* ewkView, const char* url, Ewk_Http_Method method, Eina_Hash* headers, const char* body)
2681 {
2682     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2683     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2684     EINA_SAFETY_ON_NULL_RETURN_VAL(url, false);
2685
2686     ResourceRequest request(String::fromUTF8(url));
2687
2688     switch (method) {
2689     case EWK_HTTP_METHOD_GET:
2690         request.setHTTPMethod("GET");
2691         break;
2692     case EWK_HTTP_METHOD_HEAD:
2693         request.setHTTPMethod("HEAD");
2694         break;
2695     case EWK_HTTP_METHOD_POST:
2696         request.setHTTPMethod("POST");
2697         break;
2698     case EWK_HTTP_METHOD_PUT:
2699         request.setHTTPMethod("PUT");
2700         break;
2701     case EWK_HTTP_METHOD_DELETE:
2702         request.setHTTPMethod("DELETE");
2703         break;
2704     default:
2705         return false;
2706     }
2707
2708     if (headers) {
2709         Eina_Iterator* it = eina_hash_iterator_tuple_new(headers);
2710         void* data;
2711         while (eina_iterator_next(it, &data)) {
2712             Eina_Hash_Tuple* t = static_cast<Eina_Hash_Tuple*>(data);
2713             const char* name = static_cast<const char*>(t->key);
2714             const char* value = static_cast<const char*>(t->data);
2715             request.addHTTPHeaderField(name, value);
2716         }
2717         eina_iterator_free(it);
2718     }
2719
2720     if (body)
2721         request.setHTTPBody(FormData::create(body));
2722
2723     WKRetainPtr<WKURLRequestRef> urlRequest(AdoptWK,toAPI(WebURLRequest::create(request).leakRef()));
2724     WKPageLoadURLRequest(toAPI(impl->pageProxy.get()), urlRequest.get());
2725
2726     return true;
2727 }
2728
2729 Eina_Bool ewk_view_plain_text_set(Evas_Object* ewkView, const char* plainText)
2730 {
2731     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2732     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2733
2734     WKRetainPtr<WKStringRef> plainTextRef(AdoptWK, WKStringCreateWithUTF8CString(plainText));
2735     WKPageLoadPlainTextString(toAPI(impl->pageProxy.get()), plainTextRef.get());
2736
2737     return true;
2738 }
2739
2740 Eina_Bool ewk_view_contents_set(Evas_Object* ewkView, const char* contents, size_t contentsSize, char* mimeType, char* encoding, char* baseUri)
2741 {
2742     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2743     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2744     EINA_SAFETY_ON_NULL_RETURN_VAL(contents, false);
2745
2746     if (contentsSize == 0)
2747         return false;
2748
2749     String mimeTypeString;
2750     if (mimeType)
2751         mimeTypeString = String::fromUTF8(mimeType);
2752     else
2753         mimeTypeString = String::fromUTF8("text/html");
2754
2755     String encodingString;
2756     if (encoding)
2757         encodingString = String::fromUTF8(encoding);
2758     else
2759         encodingString = String::fromUTF8("UTF-8");
2760
2761     String baseUriString;
2762     if (baseUri)
2763         baseUriString = String::fromUTF8(baseUri);
2764     else
2765         baseUriString = String::fromUTF8("about:blank");
2766
2767     WKRetainPtr<WKDataRef> contentsRef(AdoptWK, WKDataCreate(reinterpret_cast<const unsigned char*>(contents), contentsSize));
2768     impl->pageProxy->loadContentsbyMimeType(toImpl(contentsRef.get()), mimeTypeString, encodingString, baseUriString);
2769
2770     return true;
2771 }
2772
2773 Eina_Bool ewk_view_html_contents_set(Evas_Object* ewkView, const char* html, const char* baseUri)
2774 {
2775     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2776     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2777
2778     WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(html));
2779     WKRetainPtr<WKURLRef> baseURL(AdoptWK, WKURLCreateWithUTF8CString(baseUri));
2780
2781     WKPageLoadHTMLString(toAPI(impl->pageProxy.get()), htmlString.get(), baseURL.get());
2782
2783     return true;
2784 }
2785
2786 Eina_Bool ewk_view_page_visibility_state_set(Evas_Object* ewkView, Ewk_Page_Visibility_State pageVisibilityState, Eina_Bool initialState)
2787 {
2788     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2789     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2790
2791     TIZEN_LOGI("initialState (%d)", initialState);
2792 #if ENABLE(TIZEN_PAGE_VISIBILITY_API)
2793     WKPageSetPageVisibility(toAPI(impl->pageProxy.get()), static_cast<WKPageVisibilityState>(pageVisibilityState), initialState);
2794     return true;
2795 #else
2796     return false;
2797 #endif
2798 }
2799
2800 Eina_Bool ewk_view_user_agent_set(Evas_Object* ewkView, const char* userAgent)
2801 {
2802     EINA_SAFETY_ON_NULL_RETURN_VAL(userAgent, false);
2803
2804     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2805     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2806
2807     impl->userAgent = userAgent;
2808
2809     WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKStringCreateWithUTF8CString(userAgent));
2810     WKPageSetCustomUserAgent(toAPI(impl->pageProxy.get()), userAgentString.get());
2811
2812     return true;
2813 }
2814
2815 const char* ewk_view_user_agent_get(const Evas_Object* ewkView)
2816 {
2817     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2818     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2819
2820     if (!impl->userAgent) {
2821         WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKPageCopyUserAgent(toAPI(impl->pageProxy.get())));
2822
2823         int length = WKStringGetMaximumUTF8CStringSize(userAgentString.get());
2824         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
2825         WKStringGetUTF8CString(userAgentString.get(), buffer.get(), length);
2826         impl->userAgent = buffer.get();
2827     }
2828
2829     return impl->userAgent;
2830 }
2831 Eina_Bool ewk_view_custom_header_add(const Evas_Object* ewkView, const char* name, const char* value)
2832 {
2833 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2834     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2835     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2836
2837     WKRetainPtr<WKStringRef> customHeaderName(AdoptWK, WKStringCreateWithUTF8CString(name));
2838     WKRetainPtr<WKStringRef> customHeaderValue(AdoptWK, WKStringCreateWithUTF8CString(value));
2839
2840     WKPageAddCustomHeader(toAPI(impl->pageProxy.get()), customHeaderName.get(), customHeaderValue.get());
2841     return true;
2842 #else
2843     ERR("TIZEN_CUSTOM_HEADERS not enabled!");
2844     return false;
2845 #endif
2846 }
2847
2848 Eina_Bool ewk_view_custom_header_remove(const Evas_Object* ewkView, const char* name)
2849 {
2850 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2851     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2852     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2853
2854     WKRetainPtr<WKStringRef> customHeaderName(AdoptWK, WKStringCreateWithUTF8CString(name));
2855
2856     WKPageRemoveCustomHeader(toAPI(impl->pageProxy.get()), customHeaderName.get());
2857     return true;
2858 #else
2859     ERR("TIZEN_CUSTOM_HEADERS not enabled!");
2860     return false;
2861 #endif
2862 }
2863
2864 Eina_Bool ewk_view_custom_header_clear(const Evas_Object* ewkView)
2865 {
2866 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2867     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2868     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2869
2870     WKPageClearCustomHeaders(toAPI(impl->pageProxy.get()));
2871     return true;
2872 #else
2873     ERR("TIZEN_CUSTOM_HEADERS not enabled!");
2874     return false;
2875 #endif
2876 }
2877
2878 #if ENABLE(TIZEN_WEBKIT2_VIEW_VISIBILITY)
2879 Eina_Bool ewk_view_visibility_set(Evas_Object* ewkView, Eina_Bool enable)
2880 {
2881     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2882     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2883
2884 #if ENABLE(TIZEN_DRAG_SUPPORT)
2885     if (impl->pageClient->isDragMode())
2886         impl->pageClient->setDragMode(false);
2887 #endif
2888
2889     impl->pageClient->setIsVisible(enable);
2890     return true;
2891 }
2892 #endif
2893
2894 Evas_Object* ewk_view_screenshot_contents_get(const Evas_Object* ewkView, Eina_Rectangle viewArea, float scaleFactor, Evas* canvas)
2895 {
2896     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
2897
2898     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2899     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2900
2901     WKRect rect;
2902     rect.origin.x = viewArea.x;
2903     rect.origin.y = viewArea.y;
2904     rect.size.width = viewArea.w;
2905     rect.size.height = viewArea.h;
2906
2907     WKRetainPtr<WKImageRef> snapshot(AdoptWK, WKPageCreateSnapshot(toAPI(impl->pageProxy.get()), rect, scaleFactor));
2908     if (!snapshot.get())
2909         return 0;
2910
2911     RefPtr<cairo_surface_t> screenshotSurface = adoptRef(WKImageCreateCairoSurface(snapshot.get()));
2912
2913     Evas_Object* screenshotImage = evas_object_image_add(canvas);
2914     int surfaceWidth = cairo_image_surface_get_width(screenshotSurface.get());
2915     int surfaceHeight = cairo_image_surface_get_height(screenshotSurface.get());
2916     evas_object_image_size_set(screenshotImage, surfaceWidth, surfaceHeight);
2917     evas_object_image_colorspace_set(screenshotImage, EVAS_COLORSPACE_ARGB8888);
2918
2919     uint8_t* pixels = static_cast<uint8_t*>(evas_object_image_data_get(screenshotImage, true));
2920
2921     RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_RGB24, surfaceWidth, surfaceHeight, cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, surfaceWidth)));
2922     RefPtr<cairo_t> cairo = adoptRef(cairo_create(imageSurface.get()));
2923
2924     cairo_set_source_surface(cairo.get(), screenshotSurface.get(), 0, 0);
2925     cairo_rectangle(cairo.get(), 0, 0, surfaceWidth, surfaceHeight);
2926     cairo_fill(cairo.get());
2927
2928     evas_object_image_smooth_scale_set(screenshotImage, true);
2929     evas_object_size_hint_min_set(screenshotImage, surfaceWidth, surfaceHeight);
2930     evas_object_resize(screenshotImage, surfaceWidth, surfaceHeight);
2931     evas_object_image_fill_set(screenshotImage, 0, 0, surfaceWidth, surfaceHeight);
2932     evas_object_image_data_set(screenshotImage, pixels);
2933
2934     return screenshotImage;
2935 }
2936
2937 unsigned int ewk_view_inspector_server_start(Evas_Object* ewkView, unsigned int port)
2938 {
2939 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
2940     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd, 0);
2941     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl, 0);
2942
2943     return impl->pageProxy->startInspectorServer(port);
2944 #else
2945     LOG_ERROR("TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR is disabled.\n");
2946     return 0;
2947 #endif
2948 }
2949
2950 Eina_Bool ewk_view_inspector_server_stop(Evas_Object* ewkView)
2951 {
2952 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
2953     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd, false);
2954     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl, false);
2955
2956     return impl->pageProxy->stopInspectorServer();
2957 #else
2958     LOG_ERROR("TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR is disabled.\n");
2959     return false;
2960 #endif
2961 }
2962
2963 void ewk_view_scroll_by(Evas_Object* ewkView, int deltaX, int deltaY)
2964 {
2965     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2966     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2967
2968     WKPageScrollBy(toAPI(impl->pageProxy.get()), toAPI(IntSize(deltaX, deltaY)));
2969 }
2970
2971 Eina_Bool ewk_view_scroll_pos_get(Evas_Object* ewkView, int* x, int* y)
2972 {
2973     if (x)
2974         *x = 0;
2975     if (y)
2976         *y = 0;
2977     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2978     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2979
2980     IntPoint scrollPosition = impl->pageClient->scrollPosition();
2981     if (x)
2982         *x = scrollPosition.x();
2983     if (y)
2984         *y = scrollPosition.y();
2985
2986     return true;
2987 }
2988
2989 Eina_Bool ewk_view_scroll_set(Evas_Object* ewkView, int x, int y)
2990 {
2991     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2992     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2993
2994     impl->pageProxy->scrollMainFrameTo(IntPoint(x, y));
2995     return true;
2996 }
2997
2998 Eina_Bool ewk_view_scroll_size_get(const Evas_Object* ewkView, int* width, int* height)
2999 {
3000     if (width)
3001         *width = 0;
3002     if (height)
3003         *height = 0;
3004     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3005     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3006
3007     IntSize contentsSize = impl->pageProxy->contentsSize();
3008 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
3009     contentsSize.scale(impl->pageClient->scaleFactor());
3010 #endif
3011
3012     if (width && contentsSize.width() > smartData->view.w)
3013         *width = contentsSize.width() - smartData->view.w;
3014     if (height && contentsSize.height() > smartData->view.h)
3015         *height = contentsSize.height() - smartData->view.h;
3016     return true;
3017 }
3018
3019 bool ewkViewRunJavaScriptAlert(Evas_Object* ewkView, WKStringRef alertText)
3020 {
3021     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3022     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3023     if (!impl->alertContext || !impl->alertContext->javascriptAlertCallback)
3024         return false;
3025     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->alertContext->ewkView == ewkView, false);
3026
3027     impl->isWaitingForJavaScriptPopupReply = true;
3028     int length = WKStringGetMaximumUTF8CStringSize(alertText);
3029     OwnArrayPtr<char> alertTextBuffer = adoptArrayPtr(new char[length]);
3030     WKStringGetUTF8CString(alertText, alertTextBuffer.get(), length);
3031     return impl->alertContext->javascriptAlertCallback(impl->alertContext->ewkView, alertTextBuffer.get(), impl->alertContext->userData) == EINA_TRUE;
3032 }
3033
3034 bool ewkViewRunJavaScriptConfirm(Evas_Object* ewkView, WKStringRef message)
3035 {
3036     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3037     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3038     if (!impl->confirmContext || !impl->confirmContext->javascriptConfirmCallback)
3039         return false;
3040     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->confirmContext->ewkView == ewkView, false);
3041
3042     impl->isWaitingForJavaScriptPopupReply = true;
3043     int length = WKStringGetMaximumUTF8CStringSize(message);
3044     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
3045     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3046     return impl->confirmContext->javascriptConfirmCallback(impl->confirmContext->ewkView, messageBuffer.get(), impl->confirmContext->userData) == EINA_TRUE;
3047 }
3048
3049 bool ewkViewRunJavaScriptPrompt(Evas_Object* ewkView, WKStringRef message, WKStringRef defaultValue)
3050 {
3051     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3052     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3053     if (!impl->promptContext || !impl->promptContext->javascriptPromptCallback)
3054         return false;
3055     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->promptContext->ewkView == ewkView, false);
3056
3057     impl->isWaitingForJavaScriptPopupReply = true;
3058     int length = WKStringGetMaximumUTF8CStringSize(message);
3059     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
3060     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3061     length = WKStringGetMaximumUTF8CStringSize(defaultValue);
3062     OwnArrayPtr<char> defaultValueBuffer = adoptArrayPtr(new char[length]);
3063     WKStringGetUTF8CString(defaultValue, defaultValueBuffer.get(), length);
3064     return impl->promptContext->javascriptPromptCallback(impl->promptContext->ewkView, messageBuffer.get(), defaultValueBuffer.get(), impl->promptContext->userData) == EINA_TRUE;
3065 }
3066
3067 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
3068 bool ewk_view_run_before_unload_confirm_panel(Evas_Object* ewkView, WKStringRef message)
3069 {
3070     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3071     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3072     if (!impl->beforeUnloadConfirmPanelContext || !impl->beforeUnloadConfirmPanelContext->beforeUnloadConfirmPanelCallback)
3073         return false;
3074     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->beforeUnloadConfirmPanelContext->ewkView == ewkView, false);
3075
3076     impl->isWaitingForJavaScriptPopupReply = true;
3077     int length = WKStringGetMaximumUTF8CStringSize(message);
3078     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
3079     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3080     bool result = impl->beforeUnloadConfirmPanelContext->beforeUnloadConfirmPanelCallback(impl->beforeUnloadConfirmPanelContext->ewkView, messageBuffer.get(), impl->beforeUnloadConfirmPanelContext->userData) == EINA_TRUE;
3081     return result;
3082 }
3083 #endif
3084
3085 bool ewkViewRunOpenPanel(Evas_Object* ewkView, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener)
3086 {
3087     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3088     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3089     if (!impl->openpanelContext || !impl->openpanelContext->openPanelCallback)
3090         return false;
3091
3092     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->openpanelContext->ewkView == ewkView, false);
3093
3094     impl->openPanelListener = listener;
3095
3096     Eina_Bool allowMultipleFiles = WKOpenPanelParametersGetAllowsMultipleFiles(parameters) ? EINA_TRUE : EINA_FALSE;
3097     Eina_List* acceptedMimeTypes = 0;
3098     WKRetainPtr<WKArrayRef> array(AdoptWK, WKOpenPanelParametersCopyAcceptedMIMETypes(parameters));
3099     size_t len = WKArrayGetSize(array.get());
3100     for (size_t i = 0; i < len; i++) {
3101         WKTypeRef item = WKArrayGetItemAtIndex(array.get(), i);
3102         if (WKGetTypeID(item) != WKStringGetTypeID())
3103             continue;
3104         WKStringRef mime = static_cast<WKStringRef>(item);
3105         int length = WKStringGetMaximumUTF8CStringSize(mime);
3106         char* buffer = new char[length];
3107         WKStringGetUTF8CString(mime, buffer, length);
3108         acceptedMimeTypes = eina_list_append(acceptedMimeTypes, static_cast<const void*>(const_cast<const char*>(buffer)));
3109     }
3110     const char* capture = 0;
3111 #if ENABLE(MEDIA_CAPTURE)
3112     WKRetainPtr<WKStringRef> captureRef(AdoptWK, WKOpenPanelParametersCopyCapture(parameters));
3113     capture = eina_stringshare_add(toImpl(captureRef.get())->string().utf8().data());
3114 #endif
3115     bool result = impl->openpanelContext->openPanelCallback(impl->openpanelContext->ewkView, allowMultipleFiles, acceptedMimeTypes, capture, 0);
3116     if (!acceptedMimeTypes)
3117         return result;
3118
3119     Eina_List* list;
3120     void* data = 0;
3121     EINA_LIST_FOREACH(acceptedMimeTypes, list, data)
3122         delete[] (char*)data;
3123     eina_list_free(acceptedMimeTypes);
3124     return result;
3125 }
3126
3127 void ewk_view_javascript_alert_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Alert_Callback callback, void* userData)
3128 {
3129     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3130     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3131
3132     if (!impl->alertContext)
3133         impl->alertContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3134     impl->alertContext->javascriptAlertCallback = callback;
3135     impl->alertContext->ewkView = ewkView;
3136     impl->alertContext->userData = userData;
3137 }
3138
3139 void ewk_view_javascript_alert_reply(Evas_Object* ewkView)
3140 {
3141     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3142     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3143
3144     WKPageReplyJavaScriptAlert(toAPI(impl->page()));
3145     impl->isWaitingForJavaScriptPopupReply = false;
3146 }
3147
3148 void ewk_view_javascript_confirm_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Confirm_Callback callback, void* userData)
3149 {
3150     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3151     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3152
3153     if (!impl->confirmContext)
3154         impl->confirmContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3155     impl->confirmContext->javascriptConfirmCallback = callback;
3156     impl->confirmContext->ewkView = ewkView;
3157     impl->confirmContext->userData = userData;
3158 }
3159
3160 void ewk_view_javascript_confirm_reply(Evas_Object* ewkView, Eina_Bool result)
3161 {
3162     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3163     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3164
3165     WKPageReplyJavaScriptConfirm(toAPI(impl->page()), result == EINA_TRUE);
3166     impl->isWaitingForJavaScriptPopupReply = false;
3167 }
3168
3169 void ewk_view_javascript_prompt_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Prompt_Callback callback, void* userData)
3170 {
3171     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3172     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3173
3174     if (!impl->promptContext)
3175         impl->promptContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3176     impl->promptContext->javascriptPromptCallback = callback;
3177     impl->promptContext->ewkView = ewkView;
3178     impl->promptContext->userData = userData;
3179 }
3180
3181 void ewk_view_javascript_prompt_reply(Evas_Object* ewkView, const char* result)
3182 {
3183     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3184     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3185
3186     WKRetainPtr<WKStringRef> resultString(AdoptWK, WKStringCreateWithUTF8CString(result));
3187     WKPageReplyJavaScriptPrompt(toAPI(impl->page()), result ? resultString.get() : 0);
3188     impl->isWaitingForJavaScriptPopupReply = false;
3189 }
3190
3191 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
3192 void ewk_view_before_unload_confirm_panel_callback_set(Evas_Object* ewkView, Ewk_View_Before_Unload_Confirm_Panel_Callback callback, void* userData)
3193 {
3194     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3195     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3196
3197     if (!impl->beforeUnloadConfirmPanelContext)
3198         impl->beforeUnloadConfirmPanelContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3199     impl->beforeUnloadConfirmPanelContext->beforeUnloadConfirmPanelCallback = callback;
3200     impl->beforeUnloadConfirmPanelContext->ewkView = ewkView;
3201     impl->beforeUnloadConfirmPanelContext->userData = userData;
3202 }
3203
3204 void ewk_view_before_unload_confirm_panel_reply(Evas_Object* ewkView, Eina_Bool result)
3205 {
3206     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3207     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3208
3209     WKPageReplyBeforeUnloadConfirmPanel(toAPI(impl->page()), result == EINA_TRUE);
3210     impl->isWaitingForJavaScriptPopupReply = false;
3211 }
3212 #endif
3213
3214 void ewk_view_open_panel_callback_set(Evas_Object* ewkView, Ewk_View_Open_Panel_Callback callback, void* userData)
3215 {
3216     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3217     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3218
3219     if (!impl->openpanelContext)
3220         impl->openpanelContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3221
3222     impl->openpanelContext->openPanelCallback = callback;
3223     impl->openpanelContext->ewkView = ewkView;
3224     impl->openpanelContext->userData = userData;
3225 }
3226
3227 void ewk_view_open_panel_reply(Evas_Object* ewkView, Eina_List* fileUrls, Eina_Bool result)
3228 {
3229     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3230     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3231
3232     if (!impl->openPanelListener)
3233         return;
3234
3235     unsigned int size = eina_list_count(fileUrls);
3236     if ((result == EINA_FALSE) || (size == 0)) {
3237         WKOpenPanelResultListenerCancel(impl->openPanelListener);
3238         impl->openPanelListener = 0;
3239         return;
3240     }
3241
3242     WKTypeRef* items = new WKTypeRef[size];
3243     Eina_List* list;
3244     void* data;
3245     unsigned int i = 0;
3246     KURL base(KURL(), "file://");
3247     EINA_LIST_FOREACH(fileUrls, list, data) {
3248         KURL url(base, static_cast<char*>(data));
3249         items[i++] = WKURLCreateWithUTF8CString(url.string().utf8().data());
3250     }
3251     WKRetainPtr<WKArrayRef> filesArray(AdoptWK, WKArrayCreate(items, size));
3252     WKOpenPanelResultListenerChooseFiles(impl->openPanelListener, filesArray.get());
3253     impl->openPanelListener = 0;
3254     delete [] items;
3255     eina_list_free(fileUrls);
3256 }
3257
3258 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3259 static void didGetWebAppCapable(WKBooleanRef capable, WKErrorRef, void* context)
3260 {
3261     EINA_SAFETY_ON_NULL_RETURN(capable);
3262     EINA_SAFETY_ON_NULL_RETURN(context);
3263
3264     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3265
3266     ASSERT(webAppContext->webAppCapableCallback);
3267
3268     TIZEN_LOGI("webAppCapableCallback exist. capable(%b)", capable);
3269     if (capable)
3270         webAppContext->webAppCapableCallback(toImpl(capable)->value(), webAppContext->userData);
3271     else
3272         webAppContext->webAppCapableCallback(0, webAppContext->userData);
3273
3274     delete webAppContext;
3275 }
3276
3277 static void didGetWebAppIconURL(WKStringRef iconURL, WKErrorRef, void* context)
3278 {
3279     EINA_SAFETY_ON_NULL_RETURN(iconURL);
3280     EINA_SAFETY_ON_NULL_RETURN(context);
3281
3282     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3283
3284     EWK_VIEW_SD_GET_OR_RETURN(webAppContext->ewkView, smartData);
3285     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3286
3287     ASSERT(webAppContext->webAppIconURLCallback);
3288
3289     if (iconURL) {
3290         impl->webAppIconURL = toImpl(iconURL)->string().utf8().data();
3291         webAppContext->webAppIconURLCallback(impl->webAppIconURL, webAppContext->userData);
3292     } else
3293         webAppContext->webAppIconURLCallback(0, webAppContext->userData);
3294
3295     delete webAppContext;
3296 }
3297
3298 static void didGetWebAppIconURLs(WKDictionaryRef iconURLs, WKErrorRef, void* context)
3299 {
3300     EINA_SAFETY_ON_NULL_RETURN(iconURLs);
3301     EINA_SAFETY_ON_NULL_RETURN(context);
3302
3303     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3304
3305     EWK_VIEW_SD_GET_OR_RETURN(webAppContext->ewkView, smartData);
3306     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3307
3308     ASSERT(webAppContext->webAppIconURLsCallback);
3309
3310     if (impl->webAppIconURLs) {
3311         void* data = 0;
3312         EINA_LIST_FREE(impl->webAppIconURLs, data)
3313             ewkWebAppIconDataDelete(static_cast<Ewk_Web_App_Icon_Data*>(data));
3314     }
3315
3316     WKRetainPtr<WKArrayRef> wkKeys(AdoptWK, WKDictionaryCopyKeys(iconURLs));
3317     size_t iconURLCount = WKArrayGetSize(wkKeys.get());
3318     for (size_t i = 0; i < iconURLCount; i++) {
3319         WKStringRef urlRef = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkKeys.get(), i));
3320         WKStringRef sizeRef = static_cast<WKStringRef>(WKDictionaryGetItemForKey(iconURLs, urlRef));
3321         impl->webAppIconURLs = eina_list_append(impl->webAppIconURLs, ewkWebAppIconDataCreate(sizeRef, urlRef));
3322     }
3323     TIZEN_LOGI("webAppIconURLsCallback exist. found %d icon urls", iconURLCount);
3324
3325     webAppContext->webAppIconURLsCallback(impl->webAppIconURLs, webAppContext->userData);
3326     delete webAppContext;
3327 }
3328 #endif
3329
3330 Eina_Bool ewk_view_web_application_capable_get(Evas_Object* ewkView, Ewk_Web_App_Capable_Get_Callback callback, void* userData)
3331 {
3332 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3333     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3334     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3335     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3336
3337     TIZEN_LOGI("callback(%d), userData(%d)", callback, userData);
3338     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3339     context->webAppCapableCallback = callback;
3340     context->ewkView = ewkView;
3341     context->userData = userData;
3342
3343     WKPageGetWebAppCapable(toAPI(impl->pageProxy.get()), context, didGetWebAppCapable);
3344
3345     return true;
3346 #else
3347     return false;
3348 #endif
3349 }
3350
3351 Eina_Bool ewk_view_web_application_icon_url_get(Evas_Object* ewkView, Ewk_Web_App_Icon_URL_Get_Callback callback, void* userData)
3352 {
3353 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3354     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3355     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3356     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3357
3358     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3359     context->webAppIconURLCallback = callback;
3360     context->ewkView = ewkView;
3361     context->userData = userData;
3362
3363     WKPageGetWebAppIconURL(toAPI(impl->page()), context, didGetWebAppIconURL);
3364
3365     return true;
3366 #else
3367     return 0;
3368 #endif
3369 }
3370
3371 Eina_Bool ewk_view_web_application_icon_urls_get(Evas_Object* ewkView, Ewk_Web_App_Icon_URLs_Get_Callback callback, void* userData)
3372 {
3373 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3374     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3375     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3376     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3377
3378     TIZEN_LOGI("callback(%d), userData(%d)", callback, userData);
3379     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3380     context->webAppIconURLsCallback = callback;
3381     context->ewkView = ewkView;
3382     context->userData = userData;
3383
3384     WKPageGetWebAppIconURLs(toAPI(impl->page()), context, didGetWebAppIconURLs);
3385
3386     return true;
3387 #else
3388     UNUSED_PARAM(ewkView);
3389     UNUSED_PARAM(callback);
3390     UNUSED_PARAM(userData);
3391     return 0;
3392 #endif
3393 }
3394
3395 Eina_Bool ewk_view_command_execute(Evas_Object* ewkView, const char* command, const char* value)
3396 {
3397     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3398     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3399     EINA_SAFETY_ON_NULL_RETURN_VAL(command, false);
3400
3401     WKRetainPtr<WKStringRef> commandString(AdoptWK, WKStringCreateWithUTF8CString(command));
3402     WKRetainPtr<WKStringRef> valueString(AdoptWK, WKStringCreateWithUTF8CString(value));
3403     WKPageExecuteCommandWithArgument(toAPI(impl->pageProxy.get()), commandString.get(), valueString.get());
3404
3405     return true;
3406 }
3407
3408 Eina_Bool ewk_view_contents_size_get(Evas_Object* ewkView, Evas_Coord* width, Evas_Coord* height)
3409 {
3410     if (width)
3411         *width = 0;
3412     if (height)
3413         *height = 0;
3414
3415     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3416     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3417
3418     IntSize contentsSize = impl->pageProxy->contentsSize();
3419
3420     if (width)
3421         *width = contentsSize.width();
3422     if (height)
3423         *height = contentsSize.height();
3424
3425     return true;
3426 }
3427
3428 Eina_Bool ewk_view_contents_pdf_get_temp(Evas_Object* ewkView, int width, int height, const char* fileName)
3429 {
3430 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
3431     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3432     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3433     EINA_SAFETY_ON_NULL_RETURN_VAL(fileName, false);
3434
3435     IntSize contentsSize = impl->pageProxy->contentsSize();
3436     WKPageGetSnapshotPdfFile(toAPI(impl->pageProxy.get()), toAPI(IntSize(width, height)), toAPI(IntSize(contentsSize.width(), contentsSize.height())), WKStringCreateWithUTF8CString(fileName));
3437
3438     return true;
3439 #else
3440     return false;
3441 #endif
3442 }
3443
3444 Eina_Bool ewk_view_contents_pdf_get(Evas_Object* ewkView, int width, int height, const char* fileName)
3445 {
3446 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
3447     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3448     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3449     EINA_SAFETY_ON_NULL_RETURN_VAL(fileName, false);
3450
3451     IntSize contentsSize = impl->pageProxy->contentsSize();
3452     WKPageGetSnapshotPdfFile(toAPI(impl->pageProxy.get()), toAPI(IntSize(width, height)), toAPI(IntSize(contentsSize.width(), contentsSize.height())), WKStringCreateWithUTF8CString(fileName));
3453
3454     return true;
3455 #else
3456     return false;
3457 #endif
3458 }
3459
3460 static void runJavaScriptCallback(WKSerializedScriptValueRef scriptValue, WKErrorRef error, void* context)
3461 {
3462     EINA_SAFETY_ON_NULL_RETURN(context);
3463     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3464
3465     if (!callbackContext->scriptExecuteCallback) {
3466         delete callbackContext;
3467         return;
3468     }
3469
3470     JSGlobalContextRef jsGlobalContext = ewkViewGetJavascriptGlobalContext(callbackContext->ewkView);
3471
3472     if (scriptValue) {
3473         JSValueRef value = WKSerializedScriptValueDeserialize(scriptValue, jsGlobalContext, 0);
3474         JSRetainPtr<JSStringRef> jsStringValue(JSValueToStringCopy(jsGlobalContext, value, 0));
3475         size_t length = JSStringGetMaximumUTF8CStringSize(jsStringValue.get());
3476         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
3477         JSStringGetUTF8CString(jsStringValue.get(), buffer.get(), length);
3478         callbackContext->scriptExecuteCallback(callbackContext->ewkView, buffer.get(), callbackContext->userData);
3479     } else
3480         callbackContext->scriptExecuteCallback(callbackContext->ewkView, 0, callbackContext->userData);
3481
3482     delete callbackContext;
3483 }
3484
3485 Eina_Bool ewk_view_script_execute(Evas_Object* ewkView, const char* script, Ewk_View_Script_Execute_Callback callback, void* user_data)
3486 {
3487     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3488     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3489     EINA_SAFETY_ON_NULL_RETURN_VAL(script, false);
3490     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->pageClient, false);
3491
3492     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3493     context->scriptExecuteCallback = callback;
3494     context->ewkView = ewkView;
3495     context->userData = user_data;
3496     WKRetainPtr<WKStringRef> scriptString(AdoptWK, WKStringCreateWithUTF8CString(script));
3497     WKPageRunJavaScriptInMainFrame(toAPI(impl->pageProxy.get()), scriptString.get(), context, runJavaScriptCallback);
3498
3499     return true;
3500 }
3501
3502 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
3503 static void didGetWebStorageQuota(WKUInt32Ref quota, WKErrorRef error, void* context)
3504 {
3505     Ewk_View_Callback_Context* storageContext = static_cast<Ewk_View_Callback_Context*>(context);
3506
3507     if (quota)
3508         storageContext->webStorageQuotaCallback(toImpl(quota)->value(), storageContext->userData);
3509     else
3510         storageContext->webStorageQuotaCallback(0, storageContext->userData);
3511
3512     delete storageContext;
3513 }
3514 #endif
3515
3516 Eina_Bool ewk_view_web_storage_quota_get(const Evas_Object* ewkView, Ewk_Web_Storage_Quota_Get_Callback resultCallback, void* userData)
3517 {
3518 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
3519     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, false);
3520     EINA_SAFETY_ON_NULL_RETURN_VAL(resultCallback, false);
3521     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3522     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3523     TIZEN_LOGI("resultCallback (%p)", resultCallback);
3524
3525     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3526     context->webStorageQuotaCallback = resultCallback;
3527     context->userData = userData;
3528
3529     WKPageRef pageRef = toAPI(impl->page());
3530     WKPageGetWebStorageQuota(pageRef, context, didGetWebStorageQuota);
3531
3532     return true;
3533 #else
3534     return false;
3535 #endif
3536 }
3537
3538 Eina_Bool ewk_view_web_storage_quota_set(Evas_Object* ewkView, uint32_t quota)
3539 {
3540 #if ENABLE(TIZEN_WEB_STORAGE)
3541     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, false);
3542     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3543     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3544
3545     TIZEN_LOGI("quota (%d)", quota);
3546     WKPageRef pageRef = toAPI(impl->page());
3547     WKPageSetWebStorageQuota(pageRef, quota);
3548
3549     return true;
3550 #else
3551     return false;
3552 #endif
3553 }
3554
3555 static void getContentsAsStringCallback(WKStringRef plain_text, WKErrorRef error, void* context)
3556 {
3557     EINA_SAFETY_ON_NULL_RETURN(context);
3558     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3559
3560     ASSERT(callbackContext->plainTextGetCallback);
3561
3562     if (plain_text) {
3563         size_t length = WKStringGetMaximumUTF8CStringSize(plain_text);
3564         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
3565         WKStringGetUTF8CString(plain_text, buffer.get(), length);
3566
3567         callbackContext->plainTextGetCallback(callbackContext->ewkView, buffer.get(), callbackContext->userData);
3568     } else
3569         callbackContext->plainTextGetCallback(callbackContext->ewkView, 0, callbackContext->userData);
3570
3571     delete callbackContext;
3572 }
3573
3574 Eina_Bool ewk_view_plain_text_get(Evas_Object* ewkView, Ewk_View_Plain_Text_Get_Callback callback, void* user_data)
3575 {
3576     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3577     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3578     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3579     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->pageClient, false);
3580
3581     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3582     context->plainTextGetCallback = callback;
3583     context->ewkView = ewkView;
3584     context->userData = user_data;
3585     WKPageGetContentsAsString(toAPI(impl->pageProxy.get()), context, getContentsAsStringCallback);
3586
3587     return true;
3588 }
3589
3590 #if ENABLE(TIZEN_SUPPORT_MHTML)
3591 /**
3592  * @internal
3593  * Callback function used for ewk_view_mhtml_data_get().
3594  */
3595 static void getContentsAsMHTMLCallback(WKDataRef wkData, WKErrorRef, void* context)
3596 {
3597     EINA_SAFETY_ON_NULL_RETURN(context);
3598     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3599
3600     ASSERT(callbackContext->mhtmlDataGetCallback);
3601
3602     callbackContext->mhtmlDataGetCallback(callbackContext->ewkView, reinterpret_cast<const char*>(WKDataGetBytes(wkData)), callbackContext->userData);
3603
3604     delete callbackContext;
3605 }
3606
3607 Eina_Bool ewk_view_mhtml_data_get(Evas_Object* ewkView, Ewk_View_MHTML_Data_Get_Callback callback, void* user_data)
3608 {
3609     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3610     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3611     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3612
3613     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3614     context->mhtmlDataGetCallback = callback;
3615     context->ewkView = ewkView;
3616     context->userData = user_data;
3617
3618     WKPageGetContentsAsMHTMLData(toAPI(impl->page()), false, context, getContentsAsMHTMLCallback);
3619
3620     return true;
3621 }
3622 #endif // ENABLE(TIZEN_SUPPORT_MHTML)
3623
3624 Ewk_Hit_Test* ewk_view_hit_test_new(Evas_Object* ewkView, int x, int y, int hitTestMode)
3625 {
3626 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
3627     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3628     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3629
3630     IntPoint pointForHitTest = impl->transformFromScene().mapPoint(IntPoint(x, y));
3631     WebHitTestResult::Data hitTestResultData = impl->pageProxy->hitTestResultAtPoint(pointForHitTest, hitTestMode);
3632     Ewk_Hit_Test* hitTest = ewkHitTestCreate(hitTestResultData);
3633
3634     return hitTest;
3635 #else
3636     return 0;
3637 #endif
3638 }
3639
3640 Ewk_History* ewk_view_history_get(Evas_Object* ewkView)
3641 {
3642     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, 0);
3643     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3644     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3645     WebPageProxy* page = impl->page();
3646     EINA_SAFETY_ON_NULL_RETURN_VAL(page, 0);
3647
3648     return ewkHistoryCreate(WKPageGetBackForwardList(toAPI(page)));
3649 }
3650
3651 Eina_Bool ewk_view_recording_surface_enable_set(Evas_Object* ewkView, Eina_Bool enable)
3652 {
3653     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3654     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3655
3656     WKPageRecordingSurfaceSetEnable(toAPI(impl->pageProxy.get()), enable);
3657
3658     return true;
3659 }
3660
3661 Eina_Bool ewk_view_notification_closed(Evas_Object* ewkView, Eina_List* ewkNotifications)
3662 {
3663 #if ENABLE(TIZEN_NOTIFICATIONS)
3664     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3665     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3666     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->context, false);
3667
3668     TIZEN_LOGI("ewkNotifications (%p)", ewkNotifications);
3669     if (!eina_list_count(ewkNotifications))
3670         return false;
3671
3672     Eina_List* listIterator = 0;
3673     void* data = 0;
3674     Vector<WKTypeRef> ids;
3675     EINA_LIST_FOREACH(ewkNotifications, listIterator, data) {
3676         Ewk_Notification* notification = static_cast<Ewk_Notification*>(data);
3677         WKUInt64Ref idRef = WKUInt64Create(ewk_notification_id_get(notification));
3678         ids.append(idRef);
3679         impl->notifications = eina_list_remove(impl->notifications, notification);
3680     }
3681
3682     WKRetainPtr<WKArrayRef> notificationIDsArray(AdoptWK, WKArrayCreate(ids.data(), ids.size()));
3683     WKNotificationManagerRef notificationManager = WKContextGetNotificationManager(impl->context->wkContext());
3684     WKNotificationManagerProviderDidCloseNotifications(notificationManager, notificationIDsArray.get());
3685     ewkNotificationDeleteNotificationList(ewkNotifications);
3686
3687     return true;
3688 #else
3689     return false;
3690 #endif
3691 }
3692
3693 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
3694 static Eina_List* createPopupMenuList(const Vector<WebPopupItem>& items)
3695 {
3696     Eina_List* popupItems = 0;
3697     size_t size = items.size();
3698     for (size_t i = 0; i < size; ++i)
3699         popupItems = eina_list_append(popupItems, Ewk_Popup_Menu_Item::create(items[i]).leakPtr());
3700     TIZEN_LOGI("size : %d", size);
3701     return popupItems;
3702 }
3703
3704 static void releasePopupMenuList(Eina_List* popupMenuItems)
3705 {
3706     if (!popupMenuItems)
3707         return;
3708
3709     void* item;
3710     EINA_LIST_FREE(popupMenuItems, item)
3711         delete static_cast<Ewk_Popup_Menu_Item*>(item);
3712 }
3713 #endif
3714
3715 Eina_Bool ewk_view_popup_menu_close(Evas_Object* ewkView)
3716 {
3717     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3718     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3719     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api, false);
3720 #if OS(TIZEN)
3721     TIZEN_LOGI("proxy : %p", impl->popupMenuProxy);
3722 #endif
3723
3724     if (!impl->popupMenuProxy)
3725         return false;
3726
3727     impl->popupMenuProxy = 0;
3728
3729     if (smartData->api->popup_menu_hide)
3730         smartData->api->popup_menu_hide(smartData);
3731 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
3732     ewk_view_touch_events_enabled_set(ewkView, true);
3733
3734     releasePopupMenuList(impl->popupMenuItems);
3735     impl->popupMenuItems = 0;
3736 #else
3737     void* item;
3738     EINA_LIST_FREE(impl->popupMenuItems, item)
3739         delete static_cast<Ewk_Popup_Menu_Item*>(item);
3740 #endif
3741
3742     return true;
3743 }
3744
3745 Eina_Bool ewk_view_popup_menu_select(Evas_Object* ewkView, unsigned int selectedIndex)
3746 {
3747     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3748     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3749     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->popupMenuProxy, false);
3750 #if OS(TIZEN)
3751     TIZEN_LOGI("proxy : %p / index : %d", impl->popupMenuProxy, selectedIndex);
3752
3753     if (!impl->popupMenuItems)
3754         return false;
3755 #endif
3756
3757     if (selectedIndex >= eina_list_count(impl->popupMenuItems))
3758         return false;
3759
3760     impl->popupMenuProxy->valueChanged(selectedIndex);
3761
3762     return true;
3763 }
3764
3765 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
3766 void ewk_view_popup_menu_update(Evas_Object* ewkView, TextDirection textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex)
3767 {
3768     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3769     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3770     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3771     TIZEN_LOGI("proxy : %p", impl->popupMenuProxy);
3772
3773     if (!impl->popupMenuProxy)
3774         return;
3775
3776     if (!smartData->api->popup_menu_update)
3777         return;
3778
3779     releasePopupMenuList(impl->popupMenuItems);
3780     impl->popupMenuItems = createPopupMenuList(items);
3781
3782     // TODO: Instead of passing a dummy rect, updated rect should be coming from WebProcess
3783     smartData->api->popup_menu_update(smartData, IntRect(), static_cast<Ewk_Text_Direction>(textDirection), impl->popupMenuItems, selectedIndex);
3784 }
3785 #endif
3786
3787 #if ENABLE(TIZEN_MULTIPLE_SELECT)
3788 Eina_Bool ewk_view_popup_menu_multiple_select(Evas_Object* ewkView, Eina_Inarray* changeList)
3789 {
3790     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3791     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3792     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->popupMenuProxy, false);
3793
3794     Vector<int> selectedIndex;
3795
3796     if (!impl->popupMenuItems)
3797         return false;
3798
3799     Eina_Iterator* itr;
3800     void* data;
3801     itr = eina_inarray_iterator_new(changeList);
3802     EINA_ITERATOR_FOREACH(itr, data)
3803     {
3804         int* pData = static_cast<int*>(data);
3805         selectedIndex.append(*pData);
3806     }
3807     eina_iterator_free(itr);
3808
3809     impl->popupMenuProxy->multipleValueChanged(selectedIndex);
3810     return true;
3811 }
3812 #endif
3813
3814 void ewk_view_orientation_send(Evas_Object* ewkView, int orientation)
3815 {
3816 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
3817     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3818     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3819     TIZEN_LOGI("orientation : %d", orientation);
3820
3821     if (orientation != 0 && orientation != 90 && orientation != -90 && orientation != 180)
3822         return;
3823
3824     if (impl->orientation == orientation)
3825         return;
3826
3827     impl->orientation = orientation;
3828
3829     impl->pageProxy->sendOrientationChangeEvent(orientation);
3830 #endif
3831 }
3832
3833 void ewkViewFrameRendered(Evas_Object* ewkView)
3834 {
3835     evas_object_smart_callback_call(ewkView, "frame,rendered", 0);
3836 }
3837
3838 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3839 Eina_Bool ewk_view_text_selection_enable_set(Evas_Object* ewkView, Eina_Bool enable)
3840 {
3841     return ewk_settings_text_selection_enabled_set(ewk_view_settings_get(ewkView), enable);
3842 }
3843
3844 Eina_Bool ewk_view_text_selection_range_get(Evas_Object* ewkView, Eina_Rectangle* leftRect, Eina_Rectangle* rightRect)
3845 {
3846     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3847     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3848
3849     IntRect leftSelectionRect;
3850     IntRect rightSelectionRect;
3851     if (!impl->pageProxy->getSelectionHandlers(leftSelectionRect, rightSelectionRect)) {
3852         leftRect->x = 0;
3853         leftRect->y = 0;
3854         leftRect->w = 0;
3855         leftRect->h = 0;
3856
3857         rightRect->x = 0;
3858         rightRect->y = 0;
3859         rightRect->w = 0;
3860         rightRect->h = 0;
3861         return false;
3862     }
3863
3864     AffineTransform contentToScreen = impl->transformToScene();
3865     leftSelectionRect = contentToScreen.mapRect(leftSelectionRect);
3866     rightSelectionRect = contentToScreen.mapRect(rightSelectionRect);
3867
3868     leftRect->x = leftSelectionRect.x();
3869     leftRect->y = leftSelectionRect.y();
3870     leftRect->w = leftSelectionRect.width();
3871     leftRect->h = leftSelectionRect.height();
3872
3873     rightRect->x = rightSelectionRect.x();
3874     rightRect->y = rightSelectionRect.y();
3875     rightRect->w = rightSelectionRect.width();
3876     rightRect->h = rightSelectionRect.height();
3877
3878     return true;;
3879 }
3880
3881 const char* ewk_view_text_selection_text_get(Evas_Object* ewkView)
3882 {
3883     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3884     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3885
3886     const CString selectedString = impl->pageProxy->getSelectionText().utf8();
3887     impl->selectedText = selectedString.data();
3888
3889     return impl->selectedText;
3890 }
3891
3892 Eina_Bool ewk_view_auto_clear_text_selection_mode_set(Evas_Object* ewkView, Eina_Bool enable)
3893 {
3894     return ewk_settings_clear_text_selection_automatically_set(ewk_view_settings_get(ewkView), enable);
3895 }
3896
3897 Eina_Bool ewk_view_auto_clear_text_selection_mode_get(Evas_Object* ewkView)
3898 {
3899     return ewk_settings_clear_text_selection_automatically_get(ewk_view_settings_get(ewkView));
3900 }
3901 #endif // #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3902
3903 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3904 void ewkViewInputPickerRequest(Evas_Object* ewkView, Ewk_Input_Type inputType, const String& inputValue)
3905 {
3906     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3907     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3908     EINA_SAFETY_ON_NULL_RETURN(smartData->api->input_picker_show);
3909
3910     smartData->api->input_picker_show(smartData, inputType, inputValue.utf8().data());
3911 }
3912 #endif
3913
3914 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
3915 void ewkViewGetWindowFrame(Evas_Object* ewkView, int *x, int *y, int *w, int *h)
3916 {
3917     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3918     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3919     IntPoint drawingPosition = (IntPoint)(impl->pageClient->visibleContentRect().location() - impl->pageClient->scrollPosition());
3920     if (x)
3921         *x = drawingPosition.x();
3922     if (y)
3923         *y = drawingPosition.y();
3924     if (w)
3925         *w = impl->pageClient->visibleContentRect().width();
3926     if (h)
3927         *h = impl->pageClient->visibleContentRect().height();
3928 }
3929 #endif
3930
3931 void ewk_view_focused_input_element_value_set(Evas_Object* ewkView, const char* value)
3932 {
3933 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3934     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3935     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3936
3937     impl->pageProxy->setFocusedInputElementValue(String::fromUTF8(value));
3938 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3939 }
3940
3941 const char* ewk_view_focused_input_element_value_get(Evas_Object* ewkView)
3942 {
3943 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3944     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3945     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3946
3947     impl->inputValue = impl->pageProxy->getFocusedInputElementValue().utf8().data();
3948     return impl->inputValue;
3949 #else
3950     return 0;
3951 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3952 }
3953
3954 #if ENABLE(TIZEN_DATALIST_ELEMENT)
3955 void ewkViewDataListShowRequest(Evas_Object* ewkView, Ewk_Input_Type inputType, Vector<String> optionList)
3956 {
3957     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3958     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3959     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3960     EINA_SAFETY_ON_NULL_RETURN(smartData->api->data_list_show);
3961
3962     if (impl->dataList)
3963         ewkViewDataListHideRequest(ewkView, inputType);
3964
3965     for (Vector<String>::const_iterator it = optionList.begin(); it != optionList.end(); ++it) {
3966         String value = *it;
3967         impl->dataList = eina_list_append(impl->dataList, eina_stringshare_add(value.utf8().data()));
3968     }
3969
3970     smartData->api->data_list_show(smartData, inputType, impl->dataList);
3971 }
3972
3973 void ewkViewDataListHideRequest(Evas_Object* ewkView, Ewk_Input_Type inputType)
3974 {
3975     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3976     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3977     EINA_SAFETY_ON_NULL_RETURN(impl->dataList);
3978     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3979     EINA_SAFETY_ON_NULL_RETURN(smartData->api->data_list_hide);
3980
3981     impl->deleteDataList();
3982
3983     smartData->api->data_list_hide(smartData, inputType);
3984 }
3985 #endif
3986
3987 void ewk_view_data_list_close(Evas_Object* ewkView, const char* value)
3988 {
3989 #if ENABLE(TIZEN_DATALIST_ELEMENT)
3990     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3991     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3992
3993     impl->deleteDataList();
3994
3995     ewk_view_focused_input_element_value_set(ewkView, value);
3996 #endif
3997 }
3998
3999 Eina_Bool ewk_view_horizontal_panning_hold_get(Evas_Object* ewkView)
4000 {
4001 #if ENABLE(TIZEN_GESTURE)
4002     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4003     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4004     return impl->holdHorizontalPanning;
4005 #else
4006     return false;
4007 #endif
4008 }
4009
4010 void ewk_view_horizontal_panning_hold_set(Evas_Object* ewkView, Eina_Bool hold)
4011 {
4012 #if ENABLE(TIZEN_GESTURE)
4013     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4014     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4015     impl->holdHorizontalPanning = hold;
4016 #endif
4017 }
4018
4019 Eina_Bool ewk_view_vertical_panning_hold_get(Evas_Object* ewkView)
4020 {
4021 #if ENABLE(TIZEN_GESTURE)
4022     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4023     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4024     return impl->holdVerticalPanning;
4025 #else
4026     return false;
4027 #endif
4028 }
4029
4030 void ewk_view_vertical_panning_hold_set(Evas_Object* ewkView, Eina_Bool hold)
4031 {
4032 #if ENABLE(TIZEN_GESTURE)
4033     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4034     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4035     impl->holdVerticalPanning = hold;
4036 #endif
4037 }
4038
4039 void ewk_view_touch_event_handler_result_set(Evas_Object* ewkView, WebKit::WebEvent::Type type, bool wasHandled)
4040 {
4041 #if ENABLE(TIZEN_GESTURE)
4042     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4043     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4044
4045 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
4046     if (impl->focusRing && wasHandled)
4047         impl->focusRing->hide();
4048 #endif // #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
4049
4050     if (impl->mouseEventsEnabled())
4051         return;
4052
4053 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
4054     if (wasHandled && impl->pageClient->isTextSelectionMode()) {
4055         if (type == WebEvent::TouchStart)
4056             impl->pageClient->updateTextSelectionHandlesAndContextMenu(false);
4057         else if (type == WebEvent::TouchMove)
4058             impl->pageClient->updateTextSelectionHandlesAndContextMenu(false);
4059         else if (type == WebEvent::TouchEnd)
4060             impl->pageClient->requestToShowTextSelectionHandlesAndContextMenu();
4061     }
4062 #endif
4063
4064     // We have to check TouchStart, TouchMove and TouchEnd with handled.
4065     // The Pan and Flick will be enabled if Touch Start was not handled,
4066     // and Touch Move was not handled or did not occur.
4067     // Tap will be enabled if Touch Start and End was not handled
4068     // and Touch Move did not occur.
4069     // The gestures are disabled as a default.
4070     // o: handled, x: not handled
4071     // ------------------------------------------------------------
4072     // Touch Start | Touch Move | Touch End ||   Tap   | Pan, Flick
4073     // ------------------------------------------------------------
4074     //      o      |   o or x   |   o or x  || disable |  disable
4075     //      x      |      o     |   o or x  || disable |  disable
4076     //      x      |      x     |   o or x  || disable |  enable
4077     //      x      |not occured |     x     || enable  |  enable
4078     // ------------------------------------------------------------
4079     if (type == WebEvent::TouchStart) {
4080         impl->gestureClient->setGestureEnabled(!wasHandled);
4081         impl->wasHandledTouchStart = wasHandled;
4082
4083         // Initialize wasHandledTouchMove to true and notify that to the application
4084         // to prevent applications scrolling at the beginning of touch.
4085         impl->wasHandledTouchMove = true;
4086         evas_object_smart_callback_call(ewkView, "touchmove,handled", static_cast<void*>(&impl->wasHandledTouchMove));
4087     } else if (type == WebEvent::TouchMove) {
4088         impl->gestureClient->setMovingEnabled(!wasHandled);
4089
4090         // We have to set wasHandled to true if touchstart was handled even though current touchmove was not handled.
4091         if (impl->wasHandledTouchStart)
4092             wasHandled = true;
4093
4094         // Notify the result of touchmove to applications when handled value is changed
4095         // in order to make applications to choose whether scrolling its scrollable objects or not.
4096         if (impl->wasHandledTouchMove != wasHandled)
4097             evas_object_smart_callback_call(ewkView, "touchmove,handled", static_cast<void*>(&wasHandled));
4098         impl->wasHandledTouchMove = wasHandled;
4099     } else if (type == WebEvent::TouchEnd && !impl->exceedTouchMoveThreshold && !wasHandled) {
4100         impl->gestureClient->setMovingEnabled(!wasHandled);
4101         impl->gestureClient->setTapEnabled(!wasHandled);
4102     }
4103 #endif
4104 }
4105
4106 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
4107 void  ewkViewDidGetTextStyleStateForSelection(Evas_Object* ewkView, int underlineState, int italicState, int boldState, const IntPoint& startPoint, const IntPoint& endPoint)
4108 {
4109     Ewk_Text_Style* textStyle = ewkTextStyleCreate(underlineState, italicState, boldState, startPoint, endPoint);
4110     evas_object_smart_callback_call(ewkView, "text,style,state", static_cast<void*>(textStyle));
4111     ewkTextStyleDelete(textStyle);
4112 }
4113 #endif
4114
4115 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
4116 bool ewk_view_orientation_lock(Evas_Object* ewkView, int willLockOrientation)
4117 {
4118     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4119     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api, false);
4120
4121     TIZEN_LOGI("willLockOrientation (%d)", willLockOrientation);
4122     if (!smartData->api->orientation_lock) {
4123         TIZEN_LOGE("fail");
4124         return false;
4125     }
4126
4127     return smartData->api->orientation_lock(smartData, willLockOrientation);
4128 }
4129
4130 void ewk_view_orientation_unlock(Evas_Object* ewkView)
4131 {
4132     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4133     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
4134
4135     TIZEN_LOGI("ewkView (%p)", ewkView);
4136     if (!smartData->api->orientation_unlock) {
4137         TIZEN_LOGE("fail");
4138         return;
4139     }
4140
4141     smartData->api->orientation_unlock(smartData);
4142 }
4143 #endif
4144
4145 void ewk_view_orientation_lock_callback_set(Evas_Object* ewkView, Ewk_Orientation_Lock_Cb func, void* data)
4146 {
4147 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
4148     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4149     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4150     TIZEN_LOGI("callbacks: %p / data: %p", func, data);
4151
4152     impl->orientationLock.callback = func;
4153     impl->orientationLock.data = data;
4154 #endif
4155 }
4156
4157 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
4158 Eina_Bool _ewk_orientation_lock(Ewk_View_Smart_Data *sd, int orientations)
4159 {
4160     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl, false);
4161     TIZEN_LOGI("locked orientations : %d", orientations);
4162
4163     if (impl->orientationLock.callback)
4164         return impl->orientationLock.callback(sd->self, true, orientations, impl->orientationLock.data);
4165
4166     return false;
4167 }
4168
4169 void _ewk_orientation_unlock(Ewk_View_Smart_Data *sd)
4170 {
4171     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
4172     TIZEN_LOGI("unlock is requested");
4173
4174     if (impl->orientationLock.callback)
4175         impl->orientationLock.callback(sd->self, false, 0, impl->orientationLock.data);
4176 }
4177 #endif
4178
4179 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
4180 bool ewk_view_is_opengl_backend(Evas_Object* ewkView)
4181 {
4182     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4183
4184     Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
4185     const char *engine = ecore_evas_engine_name_get(ee);
4186     if (engine && !strcmp(engine, "opengl_x11"))
4187         return true;
4188     return false;
4189 }
4190 #endif
4191
4192 void ewk_view_zoomable_area_set(Evas_Object* ewkView, const IntPoint& target, const IntRect& area)
4193 {
4194 #if ENABLE(TIZEN_GESTURE)
4195     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4196     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4197
4198     impl->gestureClient->setZoomableArea(target, area);
4199 #endif
4200 }
4201
4202 #if ENABLE(TIZEN_BACKFORWARD_LIST_CLEAR)
4203 void ewk_view_back_forward_list_clear(const Evas_Object* ewkView)
4204 {
4205     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4206     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4207
4208     WKBackForwardListClearBackForwardList(WKPageGetBackForwardList(toAPI(impl->pageProxy.get())));
4209 }
4210 #endif
4211
4212 #if ENABLE(TIZEN_SIGNAL_APP_BACK_FORWARD_LIST_CHANGED)
4213 void ewkViewBackForwardListChanged(Evas_Object* ewkView)
4214 {
4215     evas_object_smart_callback_call(ewkView, "back,forward,list,changed", 0);
4216 }
4217 #endif
4218
4219 #if ENABLE(TIZEN_ICON_DATABASE)
4220 void ewkViewIconReceived(Evas_Object* ewkView)
4221 {
4222     if (!ewkView)
4223         return;
4224     evas_object_smart_callback_call(ewkView, "icon,received", 0);
4225 }
4226 #endif
4227
4228 #endif // #if OS(TIZEN)
4229
4230 Eina_Bool ewk_view_feed_touch_event(Evas_Object* ewkView, Ewk_Touch_Event_Type type, const Eina_List* points, const Evas_Modifier* modifiers)
4231 {
4232 #if ENABLE(TOUCH_EVENTS)
4233     EINA_SAFETY_ON_NULL_RETURN_VAL(points, false);
4234     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4235     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4236
4237 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
4238     if (impl->pageClient->isTextSelectionMode() && eina_list_count(points) == 1) {
4239         Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(eina_list_data_get(points));
4240         IntPoint handlePoint(point->x, point->y);
4241
4242         if (type == EWK_TOUCH_START)
4243             impl->pageClient->textSelectonHandleDown(handlePoint);
4244         else if (type == EWK_TOUCH_MOVE)
4245             impl->pageClient->textSelectonHandleMove(handlePoint);
4246         else
4247             impl->pageClient->textSelectonHandleUp();
4248     }
4249 #endif
4250
4251 #if ENABLE(TIZEN_GESTURE)
4252 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
4253     // We don't want to process touch event when context menu is shown.
4254     if (impl->pageClient->isContextMenuVisible() && type != EWK_TOUCH_CANCEL)
4255         return true;
4256 #endif
4257 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
4258     if (impl->pageClient->isTextSelectionDowned() && type != EWK_TOUCH_CANCEL)
4259         return true;
4260 #endif
4261
4262     if (type == EWK_TOUCH_START) {
4263         if (eina_list_count(points) == 1) {
4264             impl->gestureClient->reset();
4265             Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(eina_list_data_get(points));
4266             impl->touchDownPoint.x = point->x;
4267             impl->touchDownPoint.y = point->y;
4268             impl->exceedTouchMoveThreshold = false;
4269         }
4270     } else if (type == EWK_TOUCH_MOVE && !impl->exceedTouchMoveThreshold) {
4271         if (eina_list_count(points) == 1) {
4272             unsigned int threshold = elm_config_scroll_thumbscroll_threshold_get();
4273             Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(eina_list_data_get(points));
4274             int diffX = impl->touchDownPoint.x - point->x;
4275             int diffY = impl->touchDownPoint.y - point->y;
4276             if (static_cast<unsigned int>(diffX * diffX + diffY * diffY) > threshold * threshold)
4277                 impl->exceedTouchMoveThreshold = true;
4278             else
4279                 return true;
4280         } else {
4281             impl->exceedTouchMoveThreshold = true;
4282         }
4283     }
4284 #endif // #if ENABLE(TIZEN_GESTURE)
4285
4286     // FIXME: impl is used in the webkit opensource, but tizen webkit does not use it yet.
4287     //impl->page()->handleTouchEvent(NativeWebTouchEvent(type, points, modifiers, impl->transformFromScene(), impl->transformToScreen(), ecore_time_get()));
4288     impl->pageProxy->handleTouchEvent(NativeWebTouchEvent(type, points, modifiers, impl->transformFromScene(), impl->transformToScreen(), ecore_time_get()));
4289
4290     return true;
4291 #else
4292     return false;
4293 #endif
4294 }
4295
4296 Eina_Bool ewk_view_touch_events_enabled_set(Evas_Object* ewkView, Eina_Bool enabled)
4297 {
4298 #if ENABLE(TOUCH_EVENTS)
4299     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4300     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4301
4302     impl->setTouchEventsEnabled(!!enabled);
4303
4304     return true;
4305 #else
4306     return false;
4307 #endif
4308 }
4309
4310 Eina_Bool ewk_view_touch_events_enabled_get(const Evas_Object* ewkView)
4311 {
4312 #if ENABLE(TOUCH_EVENTS)
4313     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4314     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4315
4316     return impl->touchEventsEnabled();
4317 #else
4318     return false;
4319 #endif
4320 }
4321
4322 Eina_Bool ewk_view_main_frame_scrollbar_visible_set(Evas_Object* ewkView, Eina_Bool visible)
4323 {
4324 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
4325     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4326     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4327
4328     impl->mainFrameScrollbarVisibility = visible;
4329     impl->pageClient->updateVisibility();
4330
4331     return true;
4332 #else
4333     return false;
4334 #endif
4335 }
4336
4337 Eina_Bool ewk_view_main_frame_scrollbar_visible_get(const Evas_Object* ewkView)
4338 {
4339 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
4340     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4341     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4342
4343     return impl->mainFrameScrollbarVisibility;
4344 #else
4345     return false;
4346 #endif
4347 }
4348
4349 Eina_Bool ewk_view_page_save(Evas_Object* ewkView, const char* path)
4350 {
4351 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
4352     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4353     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4354     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
4355
4356     String title = ewk_view_title_get(ewkView);
4357     String url = ewk_view_url_get(ewkView);
4358     String directoryPath(path);
4359     impl->pageClient->startOfflinePageSave(directoryPath, url, title);
4360
4361     return true;
4362 #else
4363     UNUSED_PARAM(ewkView);
4364     UNUSED_PARAM(path);
4365     return false;
4366 #endif
4367 }
4368
4369 /**
4370  * @internal
4371  * Callback function used for ewk_view_page_contents_get().
4372  */
4373 static void ewkViewPageContentsAsMHTMLCallback(WKDataRef wkData, WKErrorRef, void* context)
4374 {
4375     EINA_SAFETY_ON_NULL_RETURN(context);
4376
4377     RefPtr<WebData> webData = toImpl(wkData);
4378     Ewk_Page_Contents_Context* contentsContext= static_cast<Ewk_Page_Contents_Context*>(context);
4379     contentsContext->callback(contentsContext->type, reinterpret_cast<const char*>(webData->bytes()));
4380 }
4381
4382 /**
4383  * @internal
4384  * Callback function used for ewk_view_page_contents_get().
4385  */
4386 static void ewkViewPageContentsAsStringCallback(WKStringRef wkString, WKErrorRef, void* context)
4387 {
4388     EINA_SAFETY_ON_NULL_RETURN(context);
4389
4390     RefPtr<WebString> webString = toImpl(wkString);
4391     Ewk_Page_Contents_Context* contentsContext= static_cast<Ewk_Page_Contents_Context*>(context);
4392     contentsContext->callback(contentsContext->type, webString->string().utf8().data());
4393 }
4394
4395 Eina_Bool ewk_view_page_contents_get(const Evas_Object* ewkView, Ewk_Page_Contents_Context* context)
4396 {
4397     EINA_SAFETY_ON_NULL_RETURN_VAL(context, false);
4398     EINA_SAFETY_ON_NULL_RETURN_VAL(context->callback, false);
4399     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4400     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4401
4402     switch (context->type) {
4403     case EWK_PAGE_CONTENTS_TYPE_MHTML:
4404         impl->pageProxy->getContentsAsMHTMLData(DataCallback::create(context, ewkViewPageContentsAsMHTMLCallback), false);
4405         break;
4406
4407     case EWK_PAGE_CONTENTS_TYPE_STRING:
4408         impl->pageProxy->getContentsAsString(StringCallback::create(context, ewkViewPageContentsAsStringCallback));
4409         break;
4410
4411     default:
4412         ASSERT_NOT_REACHED();
4413         return false;
4414     }
4415
4416     return true;
4417 }
4418
4419 Eina_Bool ewk_view_animated_scroll_set(Evas_Object* ewkView, int x, int y)
4420 {
4421 #if ENABLE(TIZEN_GESTURE)
4422     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4423     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4424
4425     return impl->gestureClient->scrollToWithAnimation(x, y);
4426 #else
4427     UNUSED_PARAM(ewkView);
4428     UNUSED_PARAM(x);
4429     UNUSED_PARAM(y);
4430     return false;
4431 #endif
4432 }
4433
4434 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
4435 void ewkViewFocusRingHide(Evas_Object* ewkView)
4436 {
4437     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4438     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4439
4440     if (impl->focusRing)
4441         impl->focusRing->hide();
4442 }
4443 #endif
4444
4445 void ewk_view_content_security_policy_set(Evas_Object* ewkView, const char* policy, Ewk_CSP_Header_Type type)
4446 {
4447 #if ENABLE(TIZEN_CSP)
4448     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
4449     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
4450
4451     TIZEN_LOGI("policy(%s), type(%d)\n", policy, type);
4452     impl->pageProxy->setContentSecurityPolicy(String::fromUTF8(policy), static_cast<WebCore::ContentSecurityPolicy::HeaderType>(type));
4453 #endif
4454 }
4455
4456 #if ENABLE(TIZEN_APPLICATION_CACHE)
4457 Eina_Bool ewkViewRequestApplicationCachePermission(Evas_Object* ewkView, WKSecurityOriginRef origin)
4458 {
4459     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4460     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4461
4462     if (!impl->applicationCachePermissionContext || !impl->applicationCachePermissionContext->applicationCachePermissionCallback)
4463         return false;
4464
4465     impl->isWaitingForApplicationCachePermission = true;
4466     if (impl->applicationCachePermissionOrigin)
4467         deleteSecurityOrigin(impl->applicationCachePermissionOrigin);
4468     impl->applicationCachePermissionOrigin = createSecurityOrigin(origin);
4469
4470     return impl->applicationCachePermissionContext->applicationCachePermissionCallback(ewkView, impl->applicationCachePermissionOrigin, impl->applicationCachePermissionContext->userData) == EINA_TRUE;
4471 }
4472 #endif
4473
4474 void ewk_view_application_cache_permission_callback_set(Evas_Object* ewkView, Ewk_View_Applicacion_Cache_Permission_Callback callback, void* userData)
4475 {
4476 #if ENABLE(TIZEN_APPLICATION_CACHE)
4477     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4478     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4479
4480     if (!impl->applicationCachePermissionContext)
4481         impl->applicationCachePermissionContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4482     impl->applicationCachePermissionContext->applicationCachePermissionCallback = callback;
4483     impl->applicationCachePermissionContext->userData = userData;
4484 #else
4485     UNUSED_PARAM(ewkView);
4486     UNUSED_PARAM(callback);
4487     UNUSED_PARAM(userData);
4488 #endif
4489 }
4490
4491 void ewk_view_application_cache_permission_reply(Evas_Object* ewkView, Eina_Bool allow)
4492 {
4493 #if ENABLE(TIZEN_APPLICATION_CACHE)
4494     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4495     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4496
4497     TIZEN_LOGI("allow %d", allow);
4498     WKPageReplyApplicationCachePermission(toAPI(impl->page()), allow);
4499     if (impl->applicationCachePermissionOrigin)
4500         deleteSecurityOrigin(impl->applicationCachePermissionOrigin);
4501     impl->applicationCachePermissionOrigin = 0;
4502     impl->isWaitingForApplicationCachePermission = false;
4503 #else
4504     UNUSED_PARAM(ewkView);
4505     UNUSED_PARAM(allow);
4506 #endif
4507 }
4508
4509 #if ENABLE(TIZEN_INDEXED_DATABASE)
4510 bool ewkViewExceededIndexedDatabaseQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, long long currentUsage)
4511 {
4512     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4513     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4514
4515     if (!impl->exceededIndexedDatabaseQuotaContext || !impl->exceededIndexedDatabaseQuotaContext->exceededIndexedDatabaseQuotaCallback)
4516         return false;
4517
4518     impl->isWaitingForExceededQuotaPopupReply = true;
4519     if (impl->exceededQuotaOrigin)
4520         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4521     impl->exceededQuotaOrigin = createSecurityOrigin(origin);
4522
4523     TIZEN_LOGI("currentUsage(%lld)", currentUsage);
4524
4525     return impl->exceededIndexedDatabaseQuotaContext->exceededIndexedDatabaseQuotaCallback(ewkView, impl->exceededQuotaOrigin, currentUsage, impl->exceededIndexedDatabaseQuotaContext->userData) == EINA_TRUE;
4526 }
4527 #endif
4528
4529 void ewk_view_exceeded_indexed_database_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback, void* userData)
4530 {
4531 #if ENABLE(TIZEN_INDEXED_DATABASE)
4532     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4533     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4534
4535     if (!impl->exceededIndexedDatabaseQuotaContext)
4536         impl->exceededIndexedDatabaseQuotaContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4537     impl->exceededIndexedDatabaseQuotaContext->exceededIndexedDatabaseQuotaCallback = callback;
4538     impl->exceededIndexedDatabaseQuotaContext->userData = userData;
4539 #else
4540     UNUSED_PARAM(ewkView);
4541     UNUSED_PARAM(callback);
4542     UNUSED_PARAM(userData);
4543 #endif
4544 }
4545
4546 void ewk_view_exceeded_indexed_database_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
4547 {
4548 #if ENABLE(TIZEN_INDEXED_DATABASE)
4549     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4550     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4551
4552     TIZEN_LOGI("allow %d", allow);
4553     WKPageReplyExceededIndexedDatabaseQuota(toAPI(impl->page()), allow == EINA_TRUE);
4554     if (impl->exceededQuotaOrigin)
4555         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4556     impl->exceededQuotaOrigin = 0;
4557     impl->isWaitingForExceededQuotaPopupReply = false;
4558 #else
4559     UNUSED_PARAM(ewkView);
4560     UNUSED_PARAM(allow);
4561 #endif
4562 }
4563
4564 // EwkFindOptions should be matched up orders with WkFindOptions.
4565 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_CASE_INSENSITIVE, kWKFindOptionsCaseInsensitive);
4566 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_AT_WORD_STARTS, kWKFindOptionsAtWordStarts);
4567 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, kWKFindOptionsTreatMedialCapitalAsWordStart);
4568 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_BACKWARDS, kWKFindOptionsBackwards);
4569 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_WRAP_AROUND, kWKFindOptionsWrapAround);
4570 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_OVERLAY, kWKFindOptionsShowOverlay);
4571 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_FIND_INDICATOR, kWKFindOptionsShowFindIndicator);
4572 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_HIGHLIGHT, kWKFindOptionsShowHighlight);
4573
4574 Eina_Bool ewk_view_text_find(Evas_Object* ewkView, const char* text, Ewk_Find_Options options, unsigned maxMatchCount)
4575 {
4576     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4577     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4578     EINA_SAFETY_ON_NULL_RETURN_VAL(text, false);
4579
4580     impl->pageProxy->findString(String::fromUTF8(text), static_cast<WebKit::FindOptions>(options), maxMatchCount);
4581
4582     return true;
4583 }
4584
4585 Eina_Bool ewk_view_text_find_highlight_clear(Evas_Object* ewkView)
4586 {
4587     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4588     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4589
4590     impl->pageProxy->hideFindUI();
4591
4592     return true;
4593 }
4594
4595 Eina_Bool ewk_view_text_matches_count(Evas_Object* ewkView, const char* text, Ewk_Find_Options options, unsigned maxMatchCount)
4596 {
4597     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4598     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4599     EINA_SAFETY_ON_NULL_RETURN_VAL(text, false);
4600
4601     impl->pageProxy->countStringMatches(String::fromUTF8(text), static_cast<WebKit::FindOptions>(options), maxMatchCount);
4602
4603     return true;
4604 }
4605
4606 void ewk_view_exceeded_database_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Database_Quota_Callback callback, void* userData)
4607 {
4608 #if ENABLE(TIZEN_SQL_DATABASE)
4609     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4610     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4611
4612     if (!impl->exceededDatabaseQuotaContext)
4613         impl->exceededDatabaseQuotaContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4614     impl->exceededDatabaseQuotaContext->exceededDatabaseQuotaCallback = callback;
4615     impl->exceededDatabaseQuotaContext->userData = userData;
4616 #else
4617     UNUSED_PARAM(ewkView);
4618     UNUSED_PARAM(callback);
4619     UNUSED_PARAM(userData);
4620 #endif
4621 }
4622
4623 void ewk_view_exceeded_database_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
4624 {
4625 #if ENABLE(TIZEN_SQL_DATABASE)
4626     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4627     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4628
4629     TIZEN_LOGI("allow %d", allow);
4630     WKPageReplyExceededDatabaseQuota(toAPI(impl->page()), allow == EINA_TRUE);
4631     if (impl->exceededQuotaOrigin)
4632         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4633     impl->exceededQuotaOrigin = 0;
4634     impl->isWaitingForExceededQuotaPopupReply = false;
4635 #else
4636     UNUSED_PARAM(ewkView);
4637     UNUSED_PARAM(allow);
4638 #endif
4639 }
4640
4641 #if ENABLE(TIZEN_FILE_SYSTEM)
4642 bool ewkViewExceededLocalFileSystemQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, long long currentUsage)
4643 {
4644     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4645     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4646
4647     if (!impl->exceededLocalFileSystemQuotaContext || !impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback)
4648         return false;
4649
4650     impl->isWaitingForExceededQuotaPopupReply = true;
4651     if (impl->exceededQuotaOrigin)
4652         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4653     impl->exceededQuotaOrigin = createSecurityOrigin(origin);
4654
4655     TIZEN_LOGI("currentUsage(%lld)", currentUsage);
4656
4657     return impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback(ewkView, impl->exceededQuotaOrigin , currentUsage, impl->exceededLocalFileSystemQuotaContext->userData) == EINA_TRUE;
4658 }
4659 #endif
4660
4661 void ewk_view_exceeded_local_file_system_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback, void* userData)
4662 {
4663 #if ENABLE(TIZEN_FILE_SYSTEM)
4664     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4665     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4666
4667     if (!impl->exceededLocalFileSystemQuotaContext)
4668         impl->exceededLocalFileSystemQuotaContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4669     impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback = callback;
4670     impl->exceededLocalFileSystemQuotaContext->userData = userData;
4671 #else
4672     UNUSED_PARAM(ewkView);
4673     UNUSED_PARAM(callback);
4674     UNUSED_PARAM(userData);
4675 #endif
4676 }
4677
4678 void ewk_view_exceeded_local_file_system_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
4679 {
4680 #if ENABLE(TIZEN_FILE_SYSTEM)
4681     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4682     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4683
4684     TIZEN_LOGI("allow %d", allow);
4685     WKPageReplyExceededLocalFileSystemQuota(toAPI(impl->page()), allow == EINA_TRUE);
4686     if (impl->exceededQuotaOrigin)
4687         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4688     impl->exceededQuotaOrigin = 0;
4689     impl->isWaitingForExceededQuotaPopupReply = false;
4690 #else
4691     UNUSED_PARAM(ewkView);
4692     UNUSED_PARAM(result);
4693 #endif
4694 }