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