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