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