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