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