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