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