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