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