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