Implemented DataList interface to UI
[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 "NativeWebKeyboardEvent.h"
25 #include "NativeWebMouseEvent.h"
26 #include "NativeWebWheelEvent.h"
27 #include "PageClientImpl.h"
28 #include "WKAPICast.h"
29 #include "WKRetainPtr.h"
30 #include "WKURL.h"
31 #include "ewk_context.h"
32 #include "ewk_context_private.h"
33 #include "ewk_view_private.h"
34 #include <wtf/text/CString.h>
35
36 #if OS(TIZEN)
37 #include "DrawingAreaProxyImpl.h"
38 #include "JavaScriptPopup.h"
39 #include "OpenPanel.h"
40 #include "WKArray.h"
41 #include "WKData.h"
42 #include "WKDownload.h"
43 #include "WKError.h"
44 #include "WKGeolocationPermissionRequest.h"
45 #include "WKImageCairo.h"
46 #include "WKOpenPanelParameters.h"
47 #include "WKOpenPanelResultListener.h"
48 #include "WKPage.h"
49 #include "WKPageGroup.h"
50 #include "WKPageTizen.h"
51 #include "WKPreferences.h"
52 #include "WKSerializedScriptValue.h"
53 #include "WKString.h"
54 #include "WKURLRequest.h"
55 #include "ewk_auth_challenge_private.h"
56 #include "ewk_context_menu_private.h"
57 #include "ewk_error.h"
58 #include "ewk_error_private.h"
59 #include "ewk_history_private.h"
60 #include "ewk_setting_private.h"
61 #include "ewk_view_context_menu_client.h"
62 #include "ewk_view_find_client.h"
63 #include "ewk_view_form_client.h"
64 #include "ewk_view_loader_client.h"
65 #include "ewk_view_policy_client.h"
66 #include "ewk_view_tizen_client.h"
67 #include "ewk_view_ui_client.h"
68 #include <Ecore.h>
69 #include <Ecore_Evas.h>
70 #include <Elementary.h>
71 #include <JavaScriptCore/JSRetainPtr.h>
72 #include <WebCore/NotImplemented.h>
73 #include <cairo.h>
74
75 #if ENABLE(TIZEN_ERROR_PAGE)
76 #include "WebErrorPageEfl.h"
77 #endif
78
79 #if ENABLE(TIZEN_GEOLOCATION)
80 #include "ewk_security_origin.h"
81 #include "ewk_view_geolocation_provider.h"
82 #endif
83
84 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
85 #include "InputPicker.h"
86 #endif
87
88 #if ENABLE(TIZEN_GESTURE)
89 #include "GestureRecognizer.h"
90 #include "GestureClient.h"
91 #endif
92
93 #if ENABLE(TOUCH_EVENTS)
94 #include "NativeWebTouchEvent.h"
95 #include "WebEvent.h"
96 #endif
97
98 #if ENABLE(TIZEN_ISF_PORT)
99 #include <Ecore_IMF.h>
100 #endif
101
102 #if ENABLE(TIZEN_NOTIFICATION)
103 #include "WKArray.h"
104 #include "WKNotificationManager.h"
105 #include "WKNumber.h"
106 #include "ewk_view_notification_provider.h"
107 #endif
108
109 #if ENABLE(TIZEN_READER)
110 #include "WKDictionary.h"
111 #endif
112
113 #if ENABLE(TIZEN_WEBKIT2_POPUP)
114 #include "WebPopupItem.h"
115 #include "WebPopupMenuProxyEfl.h"
116 #endif
117
118 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
119 #include "ewk_popup_picker.h"
120 #endif
121
122 #if ENABLE(TIZEN_MEDIA_STREAM)
123 #include "WKUserMediaPermissionRequest.h"
124 #endif
125
126 #if ENABLE(TIZEN_PREFERENCE)
127 #include "WebPageGroup.h"
128 #include "WebPreferences.h"
129 #endif
130
131 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
132 #include "ewk_util.h"
133 #endif
134
135 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
136 #include "ewk_hit_test_private.h"
137 #endif
138
139 #if ENABLE(TIZEN_WEBKIT2_CURSOR_PARTIAL_EARLY_MERGE)
140 #include <Ecore_Evas.h>
141 #include <WebCore/Cursor.h>
142 #include <WebCore/EflScreenUtilities.h>
143 #endif
144
145 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
146 #include "FocusRing.h"
147 #endif
148
149 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
150 #include "WebColorChooserProxyEfl.h"
151 #endif // ENABLE(TIZEN_INPUT_COLOR_PICKER)
152
153 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
154 #include "ewk_text_style.h"
155 #endif
156
157 #endif // #if OS(TIZEN)
158
159 using namespace WebKit;
160 using namespace WebCore;
161
162 static const char EWK_VIEW_TYPE_STR[] = "EWK2_View";
163
164 typedef struct _Ewk_View_Callback_Context Ewk_View_Callback_Context;
165
166 struct _Ewk_View_Private_Data {
167     OwnPtr<PageClientImpl> pageClient;
168     const char* uri;
169 #if ENABLE(TIZEN_WEBKIT2_CURSOR_PARTIAL_EARLY_MERGE)
170     const char* cursorGroup;
171
172 #ifdef HAVE_ECORE_X
173     bool isUsingEcoreX;
174 #endif
175 #endif
176 #if OS(TIZEN)
177     bool areMouseEventsEnabled;
178 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
179     int orientation;
180 #endif
181
182     struct {
183         int count;
184         int position;
185     } formNavigation;
186
187     JSGlobalContextRef javascriptGlobalContext;
188
189     const char* title;
190     const char* userAgent;
191     const char* theme;
192     const char* encoding;
193 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
194     const char* webAppIconURL;
195 #endif
196
197     OwnPtr<Ewk_View_Callback_Context> alertContext;
198     OwnPtr<Ewk_View_Callback_Context> confirmContext;
199     OwnPtr<Ewk_View_Callback_Context> promptContext;
200     OwnPtr<Ewk_View_Callback_Context> openpanelContext;
201     OwnPtr<JavaScriptPopup> javascriptPopup;
202     OwnPtr<OpenPanel> openPanel;
203 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
204     OwnPtr<InputPicker> inputPicker;
205     const char* inputValue;
206 #endif
207
208     Ewk_Auth_Challenge* authChallenge;
209     Ewk_Policy_Decision* policyDecision;
210     WKOpenPanelResultListenerRef openPanelListener;
211
212 #if ENABLE(TIZEN_MEDIA_STREAM)
213     Ewk_User_Media_Permission* userMediaPermission;
214 #endif
215
216     struct {
217         Ewk_View_String_Find_Callback callback;
218         void* userData;
219     } findClientInfo;
220
221     Ewk_Setting* setting;
222     Ewk_Context* context;
223
224 #if ENABLE(TIZEN_GEOLOCATION)
225     Ewk_Geolocation* geolocation;
226     Ewk_Geolocation_Permission_Data* geolocationPermission;
227 #endif
228
229 #if ENABLE(TIZEN_NOTIFICATION)
230     Eina_List* notifications;
231     Ewk_Notification_Permission_Request* notificationPermissionRequest;
232 #endif
233 #if ENABLE(TIZEN_SQL_DATABASE)
234     Ewk_Context_Exceeded_Quota* exceededDatabaseQuota;
235 #endif
236 #if ENABLE(TIZEN_WEBKIT2_POPUP)
237     WebPopupMenuProxyEfl* popupMenuProxy;
238     Eina_List* popupMenuItems;
239 #endif
240 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
241     Ewk_Popup_Picker* popupPicker;
242 #endif
243
244     bool isVerticalEdge;
245     bool isHorizontalEdge;
246 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
247     OwnPtr<FocusRing> focusRing;
248 #endif // #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
249
250 #if ENABLE(TIZEN_GESTURE)
251     OwnPtr<GestureRecognizer> gestureRecognizer;
252     OwnPtr<GestureClient> gestureClient;
253 #if ENABLE(TOUCH_EVENTS)
254     Ecore_Animator* touchAnimator;
255     Evas_Coord_Point touchDownPoint;
256     bool exceedTouchMoveThreshold;
257 #endif // #if ENABLE(TOUCH_EVENTS)
258     bool holdHorizontalPanning;
259     bool holdVerticalPanning;
260 #endif // #if ENABLE(TIZEN_GESTURE)
261
262 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
263     const char* selectedText;
264 #endif
265 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
266     WebColorChooserProxyEfl* colorChooser;
267 #endif // ENABLE(TIZEN_INPUT_COLOR_PICKER)
268 #if ENABLE(TIZEN_DATALIST_ELEMENT)
269     Eina_List* dataList;
270 #endif
271 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
272     struct {
273         Ewk_Orientation_Lock_Cb callback;
274         void* data;
275     } orientationLock;
276 #endif
277 #endif // #if OS(TIZEN)
278 };
279
280 #if OS(TIZEN)
281 #if ENABLE(TIZEN_MM_PLAYER)
282 struct _Ewk_View_Html5_Video_Data {
283     WKStringRef url;
284     WKStringRef cookie;
285 };
286 #endif // #if ENABLE(TIZEN_MM_PLAYER)
287
288 struct _Ewk_View_Callback_Context {
289     union {
290         Ewk_View_Rss_Items_Get_Callback rssItemsGetCallback;
291         Ewk_Web_App_Capable_Get_Callback webAppCapableCallback;
292         Ewk_Web_App_Icon_URL_Get_Callback webAppIconURLCallback;
293 #if ENABLE(TIZEN_READER)
294         Ewk_View_Reader_Callback readerCallback;
295 #endif // #if ENABLE(TIZEN_READER)
296 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
297         Ewk_Web_Storage_Quota_Get_Callback webStorageQuotaCallback;
298 #endif
299         Ewk_View_Script_Execute_Callback scriptExecuteCallback;
300         Ewk_View_Plain_Text_Get_Callback plainTextGetCallback;
301 #if OS(TIZEN)
302         Ewk_View_JavaScript_Alert_Callback javascriptAlertCallback;
303         Ewk_View_JavaScript_Confirm_Callback javascriptConfirmCallback;
304         Ewk_View_JavaScript_Prompt_Callback javascriptPromptCallback;
305         Ewk_View_Open_Panel_Callback openPanelCallback;
306 #endif // #if OS(TIZEN)
307     };
308
309     Evas_Object* ewkView;
310     void* userData;
311 };
312
313 #define READABLE_SCALE_FACTOR 1.0
314 #endif // #if OS(TIZEN)
315
316 #define EWK_VIEW_TYPE_CHECK(ewkView, result)                                   \
317     bool result = true;                                                        \
318     do {                                                                       \
319         const char* _tmp_otype = evas_object_type_get(ewkView);                \
320         const Evas_Smart* _tmp_s = evas_object_smart_smart_get(ewkView);       \
321         if (EINA_UNLIKELY(!_tmp_s)) {                                          \
322             EINA_LOG_CRIT                                                      \
323                 ("%p (%s) is not a smart object!",                             \
324                  ewkView, _tmp_otype ? _tmp_otype : "(null)");                 \
325             result = false;                                                    \
326         }                                                                      \
327         const Evas_Smart_Class* _tmp_sc = evas_smart_class_get(_tmp_s);        \
328         if (EINA_UNLIKELY(!_tmp_sc)) {                                         \
329             EINA_LOG_CRIT                                                      \
330                 ("%p (%s) is not a smart object!",                             \
331                  ewkView, _tmp_otype ? _tmp_otype : "(null)");                 \
332             result = false;                                                    \
333         }                                                                      \
334         else if (EINA_UNLIKELY(_tmp_sc->data != EWK_VIEW_TYPE_STR)) {               \
335             EINA_LOG_CRIT                                                      \
336                 ("%p (%s) is not of an ewk_view (need %p, got %p)!",           \
337                  ewkView, _tmp_otype ? _tmp_otype : "(null)",                  \
338                  EWK_VIEW_TYPE_STR, _tmp_sc->data);                            \
339             result = false;                                                    \
340         }                                                                      \
341     } while (0)
342
343 #define EWK_VIEW_SD_GET(ewkView, smartData)                                    \
344     EWK_VIEW_TYPE_CHECK(ewkView, _tmp_result);                                 \
345     Ewk_View_Smart_Data* smartData = 0;                                        \
346     if (_tmp_result)                                                           \
347         smartData = (Ewk_View_Smart_Data*)evas_object_smart_data_get(ewkView);
348
349 #define EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, ...)                     \
350     EWK_VIEW_SD_GET(ewkView, smartData);                                       \
351     if (!smartData) {                                                          \
352         EINA_LOG_CRIT("no smart data for object %p (%s)",                      \
353                  ewkView, evas_object_type_get(ewkView));                      \
354         return __VA_ARGS__;                                                    \
355     }
356
357 #define EWK_VIEW_PRIV_GET(smartData, priv)                                     \
358     Ewk_View_Private_Data* priv = smartData->priv
359
360 #define EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, ...)                      \
361     if (!smartData) {                                                          \
362         EINA_LOG_CRIT("smart data is null");                                   \
363         return __VA_ARGS__;                                                    \
364     }                                                                          \
365     EWK_VIEW_PRIV_GET(smartData, priv);                                        \
366     if (!priv) {                                                               \
367         EINA_LOG_CRIT("no private data for object %p (%s)",                    \
368                  smartData->self, evas_object_type_get(smartData->self));      \
369         return __VA_ARGS__;                                                    \
370     }
371
372 #if OS(TIZEN)
373 #define DECLARE_EVENT_FUNC(func) \
374     static void func(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
375
376 DECLARE_EVENT_FUNC(_ewk_view_on_touch_down);
377 DECLARE_EVENT_FUNC(_ewk_view_on_touch_move);
378 DECLARE_EVENT_FUNC(_ewk_view_on_touch_up);
379
380 #undef DECLARE_EVENT_FUNC
381
382 static Eina_Bool _ewk_view_default_javascript_alert(Evas_Object*, const char* alertText, void* userData);
383 static Eina_Bool _ewk_view_default_javascript_confirm(Evas_Object*, const char* message, void* userData);
384 static Eina_Bool _ewk_view_default_javascript_prompt(Evas_Object*, const char* message, const char* defaultValue, void* userData);
385 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);
386
387 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
388 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);
389 Eina_Bool _ewk_view_popup_menu_hide(Ewk_View_Smart_Data*);
390 #endif
391 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
392 Eina_Bool _ewk_orientation_lock(Ewk_View_Smart_Data *sd, int orientations);
393 void _ewk_orientation_unlock(Ewk_View_Smart_Data *sd);
394 #endif
395
396 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
397 static Eina_Bool _ewk_view_input_picker_show(Ewk_View_Smart_Data*, Ewk_Input_Type, const char* inputValue);
398 #endif
399
400 #if ENABLE(TIZEN_DATALIST_ELEMENT)
401 static Eina_Bool _ewk_view_data_list_show(Ewk_View_Smart_Data*, Ewk_Input_Type, Eina_List*);
402 static Eina_Bool _ewk_view_data_list_hide(Ewk_View_Smart_Data*, Ewk_Input_Type);
403 #endif
404
405 #endif // #if OS(TIZEN)
406
407 static void _ewk_view_smart_changed(Ewk_View_Smart_Data* smartData)
408 {
409     if (smartData->changed.any)
410         return;
411     smartData->changed.any = true;
412     evas_object_smart_changed(smartData->self);
413 }
414
415 // Default Event Handling.
416 static Eina_Bool _ewk_view_smart_focus_in(Ewk_View_Smart_Data* smartData)
417 {
418     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
419
420 #if OS(TIZEN)
421     priv->pageClient->setViewFocused(true);
422 #endif // #if OS(TIZEN)
423     priv->pageClient->page()->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
424 #if ENABLE(TIZEN_ISF_PORT)
425     priv->pageClient->handleInputMethodForFocusedNode();
426 #endif
427     return true;
428 }
429
430 static Eina_Bool _ewk_view_smart_focus_out(Ewk_View_Smart_Data* smartData)
431 {
432     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
433 #if ENABLE(TIZEN_ISF_PORT)
434     Ecore_IMF_Context* imContext = priv->pageClient->getIMFContext();
435     Ecore_IMF_Input_Panel_State state = ecore_imf_context_input_panel_state_get(imContext);
436     if (imContext && state == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
437         ecore_imf_context_input_panel_hide(imContext);
438         ecore_imf_context_focus_out(imContext);
439         priv->pageClient->setImeState(false);
440         LOG(ISF, "[STATUS] HIDE - focus_out\n");
441     }
442 #endif
443 #if OS(TIZEN)
444     priv->pageClient->setViewFocused(false);
445 #endif // #if OS(TIZEN)
446     priv->pageClient->page()->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
447     return true;
448 }
449
450 static Eina_Bool _ewk_view_smart_mouse_wheel(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Wheel* wheelEvent)
451 {
452     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
453
454     Evas_Point position = {smartData->view.x, smartData->view.y};
455     priv->pageClient->page()->handleWheelEvent(NativeWebWheelEvent(wheelEvent, &position));
456     return true;
457 }
458
459 #if OS(TIZEN) && ENABLE(TOUCH_EVENTS)
460 void ewkViewHandleTouchEvent(Evas_Object* ewkView, Ewk_Touch_Event_Type type)
461 {
462     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(ewkView));
463     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv)
464
465     Eina_List* points = 0;
466     int count = evas_touch_point_list_count(smartData->base.evas);
467     Ewk_Touch_Point* point;
468     for (int i = 0; i < count; ++i) {
469         point = static_cast<Ewk_Touch_Point*>(calloc(1, sizeof(Ewk_Touch_Point)));
470         point->id = evas_touch_point_list_nth_id_get(smartData->base.evas, i);
471         evas_touch_point_list_nth_xy_get(smartData->base.evas, i, &point->x, &point->y);
472         point->state = evas_touch_point_list_nth_state_get(smartData->base.evas, i);
473         points = eina_list_append(points, point);
474     }
475
476     ewk_view_feed_touch_event(ewkView, type, points, evas_key_modifier_get(smartData->base.evas));
477
478     void* data;
479     EINA_LIST_FREE(points, data)
480         free(data);
481 }
482
483 static Eina_Bool _ewk_view_touch_animator(void *data)
484 {
485     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
486     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
487
488     if (!priv->exceedTouchMoveThreshold && evas_touch_point_list_count(smartData->base.evas)) {
489         Evas_Coord x, y;
490         evas_touch_point_list_nth_xy_get(smartData->base.evas, 0, &x, &y);
491         unsigned int threshold = elm_config_scroll_thumbscroll_threshold_get();
492         int diffX = priv->touchDownPoint.x - x;
493         int diffY = priv->touchDownPoint.y - y;
494         if (static_cast<unsigned int>(diffX * diffX + diffY * diffY) > threshold * threshold)
495             priv->exceedTouchMoveThreshold = true;
496     }
497     if (priv->exceedTouchMoveThreshold)
498         ewkViewHandleTouchEvent(smartData->self, EWK_TOUCH_MOVE);
499
500     return ECORE_CALLBACK_RENEW;
501 }
502 #endif // #if OS(TIZEN) && ENABLE(TOUCH_EVENTS)
503
504 static Eina_Bool _ewk_view_smart_mouse_down(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Down* downEvent)
505 {
506     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
507
508 #if OS(TIZEN)
509     priv->pageClient->handleInputMethodMousePress();
510 #endif // #if OS(TIZEN)
511
512     Evas_Point position = {smartData->view.x, smartData->view.y};
513     priv->pageClient->page()->handleMouseEvent(NativeWebMouseEvent(downEvent, &position));
514     return true;
515 }
516
517 static Eina_Bool _ewk_view_smart_mouse_up(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Up* upEvent)
518 {
519     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
520
521     Evas_Point position = {smartData->view.x, smartData->view.y};
522     priv->pageClient->page()->handleMouseEvent(NativeWebMouseEvent(upEvent, &position));
523     return true;
524 }
525
526 static Eina_Bool _ewk_view_smart_mouse_move(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Move* moveEvent)
527 {
528     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
529
530     Evas_Point position = {smartData->view.x, smartData->view.y};
531     priv->pageClient->page()->handleMouseEvent(NativeWebMouseEvent(moveEvent, &position));
532     return true;
533 }
534
535 static Eina_Bool _ewk_view_smart_key_down(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Down* downEvent)
536 {
537     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
538
539 #if ENABLE(TIZEN_ISF_PORT)
540     Ecore_IMF_Event IMFEvent;
541     ecore_imf_evas_event_key_down_wrap(const_cast<Evas_Event_Key_Down*>(downEvent), &IMFEvent.key_down);
542     bool filtered = ecore_imf_context_filter_event(priv->pageClient->getIMFContext(), ECORE_IMF_EVENT_KEY_DOWN, &IMFEvent);
543
544     priv->pageClient->page()->handleKeyboardEvent(NativeWebKeyboardEvent(downEvent, filtered));
545 #else
546     priv->pageClient->page()->handleKeyboardEvent(NativeWebKeyboardEvent(downEvent));
547 #endif // #if ENABLE(TIZEN_ISF_PORT)
548
549     return true;
550 }
551
552 static Eina_Bool _ewk_view_smart_key_up(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Up* upEvent)
553 {
554     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
555
556     priv->pageClient->page()->handleKeyboardEvent(NativeWebKeyboardEvent(upEvent));
557     return true;
558 }
559
560 #if OS(TIZEN)
561 #if ENABLE(TOUCH_EVENTS)
562 static Eina_Bool _ewk_view_smart_multi_down(Ewk_View_Smart_Data* smartData, const Evas_Event_Multi_Down* downEvent)
563 {
564     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData, false);
565
566     _ewk_view_on_touch_down(0, smartData->base.evas, smartData->self, 0);
567
568     return true;
569 }
570
571 static Eina_Bool _ewk_view_smart_multi_up(Ewk_View_Smart_Data* smartData, const Evas_Event_Multi_Up* upEvent)
572 {
573     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData, false);
574
575     _ewk_view_on_touch_up(0, smartData->base.evas, smartData->self, 0);
576
577     return true;
578 }
579
580 static Eina_Bool _ewk_view_smart_multi_move(Ewk_View_Smart_Data* smartData, const Evas_Event_Multi_Move* moveEvent)
581 {
582     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData, false);
583
584     _ewk_view_on_touch_move(0, smartData->base.evas, smartData->self, 0);
585
586     return true;
587 }
588 #endif // #if ENABLE(TOUCH_EVENTS)
589
590 static Eina_Bool _ewk_view_smart_gesture_start(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
591 {
592     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
593
594     switch (event->type) {
595     case EWK_GESTURE_TAP:
596         priv->gestureClient->startTap(IntPoint(event->position.x, event->position.y));
597         break;
598     case EWK_GESTURE_LONG_PRESS:
599         priv->gestureClient->startLongPress(IntPoint(event->position.x, event->position.y));
600         break;
601     case EWK_GESTURE_PAN:
602         priv->gestureClient->startPan(IntPoint(event->position.x, event->position.y));
603         break;
604     case EWK_GESTURE_FLICK:
605         priv->gestureClient->startFlick(IntPoint(event->position.x, event->position.y), IntPoint(event->velocity.x, event->velocity.y));
606         break;
607     case EWK_GESTURE_PINCH: {
608         PageClientImpl* pageClient = ewkViewGetPageClient(smartData->self);
609         if (pageClient->viewportConstraints().userScalable)
610             priv->gestureClient->startPinch(IntPoint(event->position.x, event->position.y), event->scale);
611         break;
612     }
613     default:
614         ASSERT_NOT_REACHED();
615         break;
616     }
617
618     return true;
619 }
620
621 static Eina_Bool _ewk_view_smart_gesture_end(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
622 {
623     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
624
625     switch (event->type) {
626     case EWK_GESTURE_TAP:
627         if (event->count == 1)
628             priv->gestureClient->endTap(IntPoint(event->position.x, event->position.y));
629         break;
630     case EWK_GESTURE_LONG_PRESS:
631         priv->gestureClient->endLongPress(IntPoint(event->position.x, event->position.y));
632         break;
633     case EWK_GESTURE_PAN:
634         priv->gestureClient->endPan(IntPoint(event->position.x, event->position.y));
635         break;
636     case EWK_GESTURE_FLICK:
637         priv->gestureClient->endFlick(IntPoint(event->position.x, event->position.y), IntPoint(event->velocity.x, event->velocity.y));
638         break;
639     case EWK_GESTURE_PINCH:
640         priv->gestureClient->endPinch(IntPoint(event->position.x, event->position.y), event->scale);
641         break;
642     default:
643         ASSERT_NOT_REACHED();
644         break;
645     }
646
647     return true;
648 }
649
650 static Eina_Bool _ewk_view_smart_gesture_move(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
651 {
652     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
653
654     switch (event->type) {
655     case EWK_GESTURE_PAN:
656         priv->gestureClient->movePan(IntPoint(event->position.x, event->position.y));
657         break;
658     case EWK_GESTURE_TAP:
659     case EWK_GESTURE_LONG_PRESS:
660     case EWK_GESTURE_FLICK:
661         break;
662     case EWK_GESTURE_PINCH: {
663         PageClientImpl* pageClient = ewkViewGetPageClient(smartData->self);
664         if (pageClient->viewportConstraints().userScalable)
665             priv->gestureClient->movePinch(IntPoint(event->position.x, event->position.y), event->scale);
666         break;
667     }
668     default:
669         ASSERT_NOT_REACHED();
670         break;
671     }
672
673     return true;
674 }
675
676 static void _ewk_view_clients_attach(Ewk_View_Smart_Data* smartData)
677 {
678     EINA_SAFETY_ON_NULL_RETURN(smartData);
679
680     ewkViewContextMenuClientAttachClient(smartData->self);
681     ewkViewFindClientAttatchClient(smartData->self);
682     ewkViewFormClientAttachClient(smartData->self);
683     ewkViewLoaderClientAttachClient(smartData->self);
684     ewkViewPolicyClientAttatchClient(smartData->self);
685     ewkViewTizenClientAttachClient(smartData->self);
686     ewkViewUIClientAttatchClient(smartData->self);
687 }
688
689 static void _ewk_view_providers_attach(Ewk_View_Smart_Data* smartData, WKContextRef contextRef)
690 {
691     EINA_SAFETY_ON_NULL_RETURN(smartData);
692     EINA_SAFETY_ON_NULL_RETURN(contextRef);
693
694 #if ENABLE(TIZEN_GEOLOCATION)
695     ewkViewGeolocationProviderAttachProvider(smartData->self, contextRef);
696 #endif
697 #if ENABLE(TIZEN_NOTIFICATION)
698     ewkViewNotificationProviderAttachProvider(smartData->self, contextRef);
699 #endif
700 }
701
702 static void _ewk_view_default_callbacks_set(Ewk_View_Smart_Data* smartData)
703 {
704     EINA_SAFETY_ON_NULL_RETURN(smartData);
705
706     ewk_view_javascript_alert_callback_set(smartData->self, _ewk_view_default_javascript_alert, 0);
707     ewk_view_javascript_confirm_callback_set(smartData->self, _ewk_view_default_javascript_confirm, 0);
708     ewk_view_javascript_prompt_callback_set(smartData->self, _ewk_view_default_javascript_prompt, 0);
709     ewk_view_open_panel_callback_set(smartData->self, _ewk_view_default_open_panel, 0);
710 }
711
712 static void _ewk_view_page_initialize(Ewk_View_Smart_Data* smartData, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
713 {
714     EINA_SAFETY_ON_NULL_RETURN(smartData);
715     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
716
717     priv->pageClient = PageClientImpl::create(toImpl(contextRef), toImpl(pageGroupRef), smartData->self);
718     priv->setting = ewkSettingCreate(WKPageGroupGetPreferences(WKPageGetPageGroup(toAPI(priv->pageClient->page()))));
719 #if ENABLE(TIZEN_WEBKIT2_THEME_SET_INTERNAL)
720     ewk_view_theme_set(smartData->self, DEFAULT_THEME_PATH"/default.edj");
721 #endif
722
723     _ewk_view_clients_attach(smartData);
724     _ewk_view_providers_attach(smartData, contextRef);
725     _ewk_view_default_callbacks_set(smartData);
726 }
727
728 static Eina_Bool _ewk_view_initialize(Ewk_View_Smart_Data* smartData, Ewk_Context* context)
729 {
730     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData, false);
731     EINA_SAFETY_ON_NULL_RETURN_VAL(context, false);
732     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
733
734     priv->context = context;
735     _ewk_view_page_initialize(smartData, ewk_context_WKContext_get(context), 0);
736
737     return true;
738 }
739 #endif //#if OS(TIZEN)
740
741 // Event Handling.
742 static void _ewk_view_on_focus_in(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
743 {
744     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
745     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
746     EINA_SAFETY_ON_NULL_RETURN(smartData->api->focus_in);
747     smartData->api->focus_in(smartData);
748 }
749
750 static void _ewk_view_on_focus_out(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
751 {
752     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
753     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
754     EINA_SAFETY_ON_NULL_RETURN(smartData->api->focus_out);
755     smartData->api->focus_out(smartData);
756 }
757
758 static void _ewk_view_on_mouse_wheel(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
759 {
760     Evas_Event_Mouse_Wheel* wheelEvent = static_cast<Evas_Event_Mouse_Wheel*>(eventInfo);
761     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
762     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
763     EINA_SAFETY_ON_NULL_RETURN(smartData->api->mouse_wheel);
764     smartData->api->mouse_wheel(smartData, wheelEvent);
765 }
766
767 static void _ewk_view_on_mouse_down(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
768 {
769     Evas_Event_Mouse_Down* downEvent = static_cast<Evas_Event_Mouse_Down*>(eventInfo);
770     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
771     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
772     EINA_SAFETY_ON_NULL_RETURN(smartData->api->mouse_down);
773     smartData->api->mouse_down(smartData, downEvent);
774 }
775
776 static void _ewk_view_on_mouse_up(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
777 {
778     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
779     Evas_Event_Mouse_Up* upEvent = static_cast<Evas_Event_Mouse_Up*>(eventInfo);
780     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
781     EINA_SAFETY_ON_NULL_RETURN(smartData->api->mouse_up);
782     smartData->api->mouse_up(smartData, upEvent);
783 }
784
785 static void _ewk_view_on_mouse_move(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
786 {
787     Evas_Event_Mouse_Move* moveEvent = static_cast<Evas_Event_Mouse_Move*>(eventInfo);
788     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
789     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
790     EINA_SAFETY_ON_NULL_RETURN(smartData->api->mouse_move);
791     smartData->api->mouse_move(smartData, moveEvent);
792 }
793
794 static void _ewk_view_on_key_down(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
795 {
796     Evas_Event_Key_Down* downEvent = static_cast<Evas_Event_Key_Down*>(eventInfo);
797     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
798
799     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
800     EINA_SAFETY_ON_NULL_RETURN(smartData->api->key_down);
801     smartData->api->key_down(smartData, downEvent);
802 }
803
804 static void _ewk_view_on_key_up(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
805 {
806     Evas_Event_Key_Up* upEvent = static_cast<Evas_Event_Key_Up*>(eventInfo);
807     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
808     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
809     EINA_SAFETY_ON_NULL_RETURN(smartData->api->key_up);
810     smartData->api->key_up(smartData, upEvent);
811 }
812
813 #if OS(TIZEN)
814 static void _ewk_view_mouse_events_connect(Ewk_View_Smart_Data* smartData)
815 {
816     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv)
817     EINA_SAFETY_ON_FALSE_RETURN(priv->areMouseEventsEnabled);
818
819 #define CONNECT(s, c) evas_object_event_callback_add(smartData->self, s, c, smartData)
820     CONNECT(EVAS_CALLBACK_MOUSE_DOWN, _ewk_view_on_mouse_down);
821     CONNECT(EVAS_CALLBACK_MOUSE_UP, _ewk_view_on_mouse_up);
822     CONNECT(EVAS_CALLBACK_MOUSE_MOVE, _ewk_view_on_mouse_move);
823 #undef CONNECT
824 }
825
826 static void _ewk_view_mouse_events_disconnect(Ewk_View_Smart_Data* smartData)
827 {
828     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv)
829     EINA_SAFETY_ON_TRUE_RETURN(priv->areMouseEventsEnabled);
830
831 #define DISCONNECT(s, c) evas_object_event_callback_del(smartData->self, s, c)
832     DISCONNECT(EVAS_CALLBACK_MOUSE_DOWN, _ewk_view_on_mouse_down);
833     DISCONNECT(EVAS_CALLBACK_MOUSE_UP, _ewk_view_on_mouse_up);
834     DISCONNECT(EVAS_CALLBACK_MOUSE_MOVE, _ewk_view_on_mouse_move);
835 #undef DISCONNECT
836 }
837
838 #if ENABLE(TOUCH_EVENTS)
839 static void _ewk_view_on_touch_down(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
840 {
841     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
842     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
843
844     // Start touchAnimator if current number of touch is one.
845     if (evas_touch_point_list_count(smartData->base.evas) == 1) {
846         priv->gestureRecognizer->initializeGesture();
847         if (priv->touchAnimator)
848             ecore_animator_del(priv->touchAnimator);
849         priv->touchAnimator = ecore_animator_add(_ewk_view_touch_animator, smartData);
850 #if OS(TIZEN)
851         priv->pageClient->handleInputMethodMousePress();
852         evas_touch_point_list_nth_xy_get(canvas, 0, &priv->touchDownPoint.x, &priv->touchDownPoint.y);
853         priv->exceedTouchMoveThreshold = false;
854 #endif // #if OS(TIZEN)
855     }
856     ewkViewHandleTouchEvent(ewkView, EWK_TOUCH_START);
857 }
858
859 static void _ewk_view_on_touch_up(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
860 {
861     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
862     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
863
864     // Stop touchAnimator if current number of touch is one.
865     if (evas_touch_point_list_count(smartData->base.evas) == 1 && priv->touchAnimator) {
866         ecore_animator_del(priv->touchAnimator);
867         priv->touchAnimator = 0;
868     }
869     ewkViewHandleTouchEvent(ewkView, EWK_TOUCH_END);
870 }
871
872 static void _ewk_view_on_touch_move(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
873 {
874     notImplemented();
875 }
876 #endif
877
878 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
879 Eina_Bool _ewk_view_text_selection_down(Ewk_View_Smart_Data* smartData, int x, int y)
880 {
881     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
882
883     IntPoint point(x, y);
884     priv->pageClient->textSelectionDown(point, true);
885
886     return true;
887 }
888
889 Eina_Bool _ewk_view_text_selection_move(Ewk_View_Smart_Data* smartData, int x, int y)
890 {
891     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
892
893     IntPoint point(x, y);
894     priv->pageClient->textSelectionMove(point, true);
895
896     return true;
897 }
898
899 Eina_Bool _ewk_view_text_selection_up(Ewk_View_Smart_Data* smartData, int x, int y)
900 {
901     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
902
903     IntPoint point(x, y);
904     priv->pageClient->textSelectionUp(point);
905
906     return true;
907 }
908 #endif
909
910 #if ENABLE(TIZEN_DATALIST_ELEMENT)
911 static void _ewk_view_data_list_del(Eina_List* dataList)
912 {
913     EINA_SAFETY_ON_NULL_RETURN(dataList);
914
915     void* item;
916     EINA_LIST_FREE(dataList, item)
917         eina_stringshare_del(static_cast<char*>(item));
918 }
919 #endif
920
921 #endif // #if OS(TIZEN)
922
923 static Evas_Smart_Class g_parentSmartClass = EVAS_SMART_CLASS_INIT_NULL;
924
925 static Ewk_View_Private_Data* _ewk_view_priv_new(Ewk_View_Smart_Data* smartData)
926 {
927     Ewk_View_Private_Data* priv =
928         static_cast<Ewk_View_Private_Data*>(calloc(1, sizeof(Ewk_View_Private_Data)));
929     if (!priv) {
930         EINA_LOG_CRIT("could not allocate Ewk_View_Private_Data");
931         return 0;
932     }
933 #if ENABLE(TIZEN_WEBKIT2_CURSOR_PARTIAL_EARLY_MERGE)
934 #ifdef HAV_ECORE_X
935     priv->isUsingEcoreX = WebCore::isUsingEcoreX(smartData->base.evas);
936 #endif
937 #endif
938 #if OS(TIZEN)
939     priv->areMouseEventsEnabled = false;
940
941     priv->javascriptPopup = adoptPtr<JavaScriptPopup>(new JavaScriptPopup(smartData->self));
942     priv->openPanel = adoptPtr<OpenPanel>(new OpenPanel(smartData->self));
943
944 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
945     priv->inputPicker = adoptPtr<InputPicker>(new InputPicker(smartData->self));
946 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
947
948 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
949     priv->focusRing = FocusRing::create(smartData->self);
950 #endif // #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
951
952 #if ENABLE(TIZEN_GESTURE)
953     priv->gestureRecognizer = GestureRecognizer::create(smartData->self);
954     priv->gestureClient = GestureClient::create(smartData->self);
955 #endif // #if ENABLE(TIZEN_GESTURE)
956
957 #if ENABLE(TIZEN_DATALIST_ELEMENT)
958     priv->dataList = 0;
959 #endif
960
961 #endif // #if OS(TIZEN)
962
963     return priv;
964 }
965
966 static void _ewk_view_priv_del(Ewk_View_Private_Data* priv)
967 {
968     if (!priv)
969         return;
970
971     priv->pageClient = nullptr;
972 #if OS(TIZEN)
973     if (priv->javascriptGlobalContext)
974         JSGlobalContextRelease(priv->javascriptGlobalContext);
975
976     eina_stringshare_del(priv->uri);
977     eina_stringshare_del(priv->title);
978     eina_stringshare_del(priv->userAgent);
979     eina_stringshare_del(priv->encoding);
980 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
981     eina_stringshare_del(priv->webAppIconURL);
982 #endif
983
984     if (priv->authChallenge)
985         ewkAuthChallengeDelete(priv->authChallenge);
986     if (priv->policyDecision)
987         ewkPolicyDecisionDelete(priv->policyDecision);
988
989 #if ENABLE(TIZEN_MEDIA_STREAM)
990     if (priv->userMediaPermission)
991         ewkUserMediaPermissionDelete(priv->userMediaPermission);
992 #endif
993
994     ewkSettingDelete(priv->setting);
995     priv->openPanelListener = 0;
996     priv->openPanel = nullptr;
997     priv->javascriptPopup = nullptr;
998     priv->alertContext = nullptr;
999     priv->confirmContext = nullptr;
1000     priv->promptContext = nullptr;
1001     priv->openpanelContext = nullptr;
1002 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1003     priv->inputPicker = nullptr;
1004     eina_stringshare_del(priv->inputValue);
1005 #endif
1006 #endif
1007
1008 #if ENABLE(TIZEN_DATALIST_ELEMENT)
1009     _ewk_view_data_list_del(priv->dataList);
1010     priv->dataList = 0;
1011 #endif
1012
1013 #if ENABLE(TIZEN_GEOLOCATION)
1014     if (priv->geolocation)
1015         ewkGeolocationDeleteGeolocation(priv->geolocation);
1016     if (priv->geolocationPermission)
1017         ewkGeolocationDeletePermission(priv->geolocationPermission);
1018 #endif
1019
1020 #if ENABLE(TIZEN_NOTIFICATION)
1021     if (priv->notifications)
1022         ewkNotificationDeleteNotificationList(priv->notifications);
1023     if (priv->notificationPermissionRequest)
1024         ewkNotificationDeletePermissionRequest(priv->notificationPermissionRequest);
1025 #endif
1026 #if ENABLE(TIZEN_SQL_DATABASE)
1027     if (priv->exceededDatabaseQuota)
1028         ewkContextDeleteExceededQuota(priv->exceededDatabaseQuota);
1029 #endif
1030 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1031     priv->focusRing = nullptr;
1032 #endif // #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1033 #if ENABLE(TIZEN_GESTURE)
1034     priv->gestureRecognizer = nullptr;
1035     priv->gestureClient = nullptr;
1036 #if ENABLE(TOUCH_EVENTS)
1037     if (priv->touchAnimator)
1038         ecore_animator_del(priv->touchAnimator);
1039 #endif // #if ENABLE(TOUCH_EVENTS)
1040 #endif // #if ENABLE(TIZEN_GESTURE)
1041
1042 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1043     eina_stringshare_del(priv->selectedText);
1044 #endif
1045
1046     free(priv);
1047 }
1048
1049 static void _ewk_view_smart_add(Evas_Object* ewkView)
1050 {
1051     const Evas_Smart* smart = evas_object_smart_smart_get(ewkView);
1052     const Evas_Smart_Class* smartClass = evas_smart_class_get(smart);
1053     const Ewk_View_Smart_Class* api = reinterpret_cast<const Ewk_View_Smart_Class*>(smartClass);
1054     EWK_VIEW_SD_GET(ewkView, smartData);
1055
1056     if (!smartData) {
1057         smartData = static_cast<Ewk_View_Smart_Data*>(calloc(1, sizeof(Ewk_View_Smart_Data)));
1058         if (!smartData) {
1059             EINA_LOG_CRIT("could not allocate Ewk_View_Smart_Data");
1060             return;
1061         }
1062         evas_object_smart_data_set(ewkView, smartData);
1063     }
1064
1065     smartData->self = ewkView;
1066 #if !ENABLE(TIZEN_WEBKIT2_CURSOR_PARTIAL_EARLY_MERGE)
1067     smartData->priv = _ewk_view_priv_new(smartData);
1068 #endif
1069     smartData->api = api;
1070
1071 #if ENABLE(TIZEN_WEBKIT2_CURSOR_PARTIAL_EARLY_MERGE)
1072     g_parentSmartClass.add(ewkView);
1073
1074     smartData->priv = _ewk_view_priv_new(smartData);
1075 #endif
1076     if (!smartData->priv) {
1077         EINA_LOG_CRIT("could not allocate _Ewk_View_Private_Data");
1078         evas_object_smart_data_set(ewkView, 0);
1079         free(smartData);
1080         return;
1081     }
1082
1083 #if !ENABLE(TIZEN_WEBKIT2_CURSOR_PARTIAL_EARLY_MERGE)
1084     g_parentSmartClass.add(ewkView);
1085 #endif
1086
1087 #if OS(TIZEN)
1088     // create bg_rect
1089     smartData->bg_rect = evas_object_rectangle_add(smartData->base.evas);
1090     evas_object_color_set(smartData->bg_rect, 255, 255, 255, 255);
1091     evas_object_show(smartData->bg_rect);
1092     evas_object_smart_member_add(smartData->bg_rect, ewkView);
1093 #endif // #if OS(TIZEN)
1094
1095     // Create evas_object_image to draw web contents.
1096     smartData->image = evas_object_image_add(smartData->base.evas);
1097 #if OS(TIZEN)
1098 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
1099     Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
1100     const char *engine = ecore_evas_engine_name_get(ee);
1101     if (engine && !strcmp(engine, "opengl_x11"))
1102         evas_object_image_content_hint_set(smartData->image, EVAS_IMAGE_CONTENT_HINT_DYNAMIC);
1103 #endif
1104 #endif // #if OS(TIZEN)
1105     evas_object_image_alpha_set(smartData->image, false);
1106     evas_object_image_filled_set(smartData->image, true);
1107     evas_object_smart_member_add(smartData->image, ewkView);
1108     evas_object_show(smartData->image);
1109 #if OS(TIZEN)
1110     evas_object_pass_events_set(smartData->image, true);
1111
1112     // create events_rect
1113     smartData->events_rect = evas_object_rectangle_add(smartData->base.evas);
1114     evas_object_color_set(smartData->events_rect, 0, 0, 0, 0);
1115     evas_object_smart_member_add(smartData->events_rect, ewkView);
1116     evas_object_show(smartData->events_rect);
1117
1118     if (smartData->priv->areMouseEventsEnabled)
1119         _ewk_view_mouse_events_connect(smartData);
1120 #endif // #if OS(TIZEN)
1121
1122 #define CONNECT(s, c) evas_object_event_callback_add(ewkView, s, c, smartData)
1123     CONNECT(EVAS_CALLBACK_FOCUS_IN, _ewk_view_on_focus_in);
1124     CONNECT(EVAS_CALLBACK_FOCUS_OUT, _ewk_view_on_focus_out);
1125     CONNECT(EVAS_CALLBACK_MOUSE_WHEEL, _ewk_view_on_mouse_wheel);
1126 #if !OS(TIZEN)
1127     CONNECT(EVAS_CALLBACK_MOUSE_DOWN, _ewk_view_on_mouse_down);
1128     CONNECT(EVAS_CALLBACK_MOUSE_UP, _ewk_view_on_mouse_up);
1129     CONNECT(EVAS_CALLBACK_MOUSE_MOVE, _ewk_view_on_mouse_move);
1130 #endif
1131     CONNECT(EVAS_CALLBACK_KEY_DOWN, _ewk_view_on_key_down);
1132     CONNECT(EVAS_CALLBACK_KEY_UP, _ewk_view_on_key_up);
1133 #if OS(TIZEN) && ENABLE(TOUCH_EVENTS)
1134     // FIXME: We have to connect touch callbacks with Mouse and Multi event
1135     // because the Evas sends the Touch event using them.
1136     // It should be fixed when the Evas supports the Touch event.
1137     CONNECT(EVAS_CALLBACK_MOUSE_DOWN, _ewk_view_on_touch_down);
1138     CONNECT(EVAS_CALLBACK_MOUSE_UP, _ewk_view_on_touch_up);
1139     CONNECT(EVAS_CALLBACK_MOUSE_MOVE, _ewk_view_on_touch_move);
1140     CONNECT(EVAS_CALLBACK_MULTI_DOWN, _ewk_view_on_touch_down);
1141     CONNECT(EVAS_CALLBACK_MULTI_UP, _ewk_view_on_touch_up);
1142     CONNECT(EVAS_CALLBACK_MULTI_MOVE, _ewk_view_on_touch_move);
1143 #endif // #if OS(TIZEN) && ENABLE(TOUCH_EVENTS)
1144 #undef CONNECT
1145 }
1146
1147 static void _ewk_view_smart_del(Evas_Object* ewkView)
1148 {
1149     EWK_VIEW_SD_GET(ewkView, smartData);
1150     if (smartData && smartData->priv)
1151         _ewk_view_priv_del(smartData->priv);
1152
1153     g_parentSmartClass.del(ewkView);
1154 }
1155
1156 static void _ewk_view_smart_resize(Evas_Object* ewkView, Evas_Coord width, Evas_Coord height)
1157 {
1158     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1159
1160     evas_object_resize(smartData->image, width, height);
1161     evas_object_image_size_set(smartData->image, width, height);
1162     evas_object_image_fill_set(smartData->image, 0, 0, width, height);
1163 #if OS(TIZEN)
1164     evas_object_resize(smartData->events_rect, width, height);
1165
1166     EWK_VIEW_PRIV_GET(smartData, priv);
1167 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1168     evas_object_image_native_surface_set(smartData->image, 0);
1169     if (priv)
1170         priv->pageClient->displayViewport();
1171 #endif
1172
1173 #if ENABLE(TIZEN_PREFERENCE)
1174     if (priv && priv->pageClient->page()) {
1175         priv->pageClient->page()->pageGroup()->preferences()->setViewWidth(width);
1176         priv->pageClient->page()->pageGroup()->preferences()->setViewHeight(height);
1177     }
1178 #endif
1179 #endif // #if OS(TIZEN)
1180
1181     smartData->changed.size = true;
1182     _ewk_view_smart_changed(smartData);
1183 }
1184
1185 static void _ewk_view_smart_move(Evas_Object* ewkView, Evas_Coord x, Evas_Coord y)
1186 {
1187     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1188
1189     smartData->changed.position = true;
1190     _ewk_view_smart_changed(smartData);
1191 }
1192
1193 static void _ewk_view_smart_calculate(Evas_Object* ewkView)
1194 {
1195     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1196     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1197     Evas_Coord x, y, width, height;
1198
1199     smartData->changed.any = false;
1200
1201     evas_object_geometry_get(ewkView, &x, &y, &width, &height);
1202
1203     if (smartData->changed.size) {
1204         smartData->view.w = width;
1205         smartData->view.h = height;
1206         smartData->changed.size = false;
1207
1208 #if OS(TIZEN)
1209         if (priv->pageClient) {
1210             if (DrawingAreaProxy* drawingArea = priv->pageClient->page()->drawingArea()) {
1211 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1212                 if (priv->pageClient->page()->isViewVisible())
1213                     drawingArea->setSize(IntSize(width, height), IntSize());
1214 #else
1215                 drawingArea->setSize(IntSize(width, height), IntSize());
1216 #endif
1217 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE) && !ENABLE(TIZEN_WEBKIT2_EFL_WTR)
1218                 priv->pageClient->updateViewportSize(IntSize(width, height));
1219                 priv->pageClient->displayViewport();
1220 #endif
1221             }
1222 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
1223             priv->pageClient->frameRectChanged();
1224 #endif
1225         }
1226         evas_object_resize(smartData->bg_rect, width, height);
1227
1228 #endif // #if OS(TIZEN)
1229     }
1230
1231     if (smartData->changed.position) {
1232         evas_object_move(smartData->image, x, y);
1233 #if OS(TIZEN)
1234         evas_object_move(smartData->events_rect, x, y);
1235         evas_object_move(smartData->bg_rect, x, y);
1236 #endif // #if OS(TIZEN)
1237         smartData->view.x = x;
1238         smartData->view.y = y;
1239         smartData->changed.position = false;
1240
1241 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
1242         priv->pageClient->frameRectChanged();
1243 #endif
1244     }
1245
1246     if (priv->popupPicker)
1247         ewk_popup_picker_resize(priv->popupPicker);
1248 }
1249
1250 static void _ewk_view_smart_show(Evas_Object* ewkView)
1251 {
1252     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1253     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1254
1255     if (evas_object_clipees_get(smartData->base.clipper))
1256         evas_object_show(smartData->base.clipper);
1257     evas_object_show(smartData->image);
1258 }
1259
1260 static void _ewk_view_smart_hide(Evas_Object* ewkView)
1261 {
1262     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1263     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1264
1265     evas_object_hide(smartData->base.clipper);
1266     evas_object_hide(smartData->image);
1267 }
1268
1269 static void _ewk_view_smart_color_set(Evas_Object* ewkView, int red, int green, int blue, int alpha)
1270 {
1271     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1272     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1273
1274     if (alpha < 0)
1275         alpha = 0;
1276     else if (alpha > 255)
1277         alpha = 255;
1278
1279 #define CHECK_COLOR(color, alpha) \
1280     if (color < 0)                \
1281         color = 0;                \
1282     else if (color > alpha)       \
1283         color = alpha;
1284     CHECK_COLOR(red, alpha);
1285     CHECK_COLOR(green, alpha);
1286     CHECK_COLOR(blue, alpha);
1287 #undef CHECK_COLOR
1288
1289 #if OS(TIZEN)
1290     evas_object_color_set(smartData->bg_rect, red, green, blue, alpha);
1291 #endif
1292     evas_object_image_alpha_set(smartData->image, alpha < 255);
1293     priv->pageClient->page()->setDrawsBackground(red || green || blue);
1294     priv->pageClient->page()->setDrawsTransparentBackground(alpha < 255);
1295
1296     g_parentSmartClass.color_set(ewkView, red, green, blue, alpha);
1297 }
1298
1299 #if OS(TIZEN)
1300 Eina_Bool ewk_view_smart_class_set(Ewk_View_Smart_Class* api)
1301 #else
1302 Eina_Bool ewk_view_smart_class_init(Ewk_View_Smart_Class* api)
1303 #endif
1304 {
1305     EINA_SAFETY_ON_NULL_RETURN_VAL(api, false);
1306
1307     if (api->version != EWK_VIEW_SMART_CLASS_VERSION) {
1308         EINA_LOG_CRIT("Ewk_View_Smart_Class %p is version %lu while %lu was expected.",
1309              api, api->version, EWK_VIEW_SMART_CLASS_VERSION);
1310         return false;
1311     }
1312
1313     if (EINA_UNLIKELY(!g_parentSmartClass.add))
1314         evas_object_smart_clipped_smart_set(&g_parentSmartClass);
1315
1316     evas_object_smart_clipped_smart_set(&api->sc);
1317
1318     // Set Evas_Smart_Class functions.
1319     api->sc.add = _ewk_view_smart_add;
1320     api->sc.del = _ewk_view_smart_del;
1321     api->sc.move = _ewk_view_smart_move;
1322     api->sc.resize = _ewk_view_smart_resize;
1323     api->sc.show = _ewk_view_smart_show;
1324     api->sc.hide = _ewk_view_smart_hide;
1325     api->sc.color_set = _ewk_view_smart_color_set;
1326     api->sc.calculate = _ewk_view_smart_calculate;
1327     api->sc.data = EWK_VIEW_TYPE_STR; // It is used by type checking.
1328
1329     // Set Ewk_View_Smart_Class functions.
1330     api->focus_in = _ewk_view_smart_focus_in;
1331     api->focus_out = _ewk_view_smart_focus_out;
1332     api->mouse_wheel = _ewk_view_smart_mouse_wheel;
1333     api->mouse_down = _ewk_view_smart_mouse_down;
1334     api->mouse_up = _ewk_view_smart_mouse_up;
1335     api->mouse_move = _ewk_view_smart_mouse_move;
1336     api->key_down = _ewk_view_smart_key_down;
1337     api->key_up = _ewk_view_smart_key_up;
1338 #if OS(TIZEN)
1339     api->initialize = _ewk_view_initialize;
1340 #if ENABLE(TOUCH_EVENTS)
1341     api->multi_down = _ewk_view_smart_multi_down;
1342     api->multi_up = _ewk_view_smart_multi_up;
1343     api->multi_move = _ewk_view_smart_multi_move;
1344 #endif // #if ENABLE(TOUCH_EVENTS)
1345     api->gesture_start = _ewk_view_smart_gesture_start;
1346     api->gesture_end = _ewk_view_smart_gesture_end;
1347     api->gesture_move = _ewk_view_smart_gesture_move;
1348
1349 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1350     api->popup_menu_show = _ewk_view_popup_menu_show;
1351     api->popup_menu_hide = _ewk_view_popup_menu_hide;
1352 #endif
1353 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1354     api->text_selection_down = _ewk_view_text_selection_down;
1355     api->text_selection_move = _ewk_view_text_selection_move;
1356     api->text_selection_up = _ewk_view_text_selection_up;
1357 #endif
1358 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1359     api->input_picker_show = _ewk_view_input_picker_show;
1360 #endif
1361 #if ENABLE(TIZEN_DATALIST_ELEMENT)
1362     api->data_list_show = _ewk_view_data_list_show;
1363     api->data_list_hide = _ewk_view_data_list_hide;
1364 #endif
1365 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
1366     api->orientation_lock = _ewk_orientation_lock;
1367     api->orientation_unlock = _ewk_orientation_unlock;
1368 #endif
1369 #endif //#if OS(TIZEN)
1370
1371     return true;
1372 }
1373
1374 static inline Evas_Smart* _ewk_view_smart_class_new(void)
1375 {
1376     static Ewk_View_Smart_Class api = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION(ewkViewLegacyName);
1377     static Evas_Smart* smart = 0;
1378
1379     if (EINA_UNLIKELY(!smart)) {
1380 #if OS(TIZEN)
1381         ewk_view_smart_class_set(&api);
1382 #else
1383         ewk_view_smart_class_init(&api);
1384 #endif
1385         smart = evas_smart_class_new(&api.sc);
1386     }
1387
1388     return smart;
1389 }
1390
1391 #if OS(TIZEN)
1392 static Evas_Object* _ewk_view_base_add(Evas* canvas, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
1393 #else
1394 Evas_Object* ewk_view_base_add(Evas* canvas, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
1395 #endif
1396 {
1397     Evas_Object* ewkView = evas_object_smart_add(canvas, _ewk_view_smart_class_new());
1398     if (!ewkView)
1399         return 0;
1400
1401     EWK_VIEW_SD_GET(ewkView, smartData);
1402     if (!smartData) {
1403         evas_object_del(ewkView);
1404         return 0;
1405     }
1406
1407     EWK_VIEW_PRIV_GET(smartData, priv);
1408     if (!priv) {
1409         evas_object_del(ewkView);
1410         return 0;
1411     }
1412
1413 #if !OS(TIZEN)
1414     priv->pageClient = PageClientImpl::create(toImpl(contextRef), toImpl(pageGroupRef), ewkView);
1415 #endif
1416
1417     return ewkView;
1418 }
1419
1420 #if OS(TIZEN)
1421 /**
1422  * @internal
1423  * Constructs a ewk_view Evas_Object with WKType parameters.
1424  */
1425 Evas_Object* ewk_view_add_with_WKType(Evas* canvas, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
1426 {
1427     Evas_Object* ewkView = _ewk_view_base_add(canvas, contextRef, pageGroupRef);
1428
1429     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, ewkView);
1430     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, ewkView);
1431
1432     priv->context = ewk_context_new_with_WKContext(contextRef);
1433     _ewk_view_page_initialize(smartData, contextRef, pageGroupRef);
1434
1435     return ewkView;
1436 }
1437 #endif // #if OS(TIZEN)
1438
1439 Evas_Object* ewk_view_add_with_context(Evas* canvas, Ewk_Context* context)
1440 {
1441 #if OS(TIZEN)
1442     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1443     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1444
1445     Evas_Object* ewkView = _ewk_view_base_add(canvas, ewk_context_WKContext_get(context), 0);
1446
1447     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, ewkView);
1448     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api, ewkView);
1449     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api->initialize, ewkView);
1450     smartData->api->initialize(smartData, context);
1451
1452     return ewkView;
1453 #else
1454     return ewk_view_base_add(canvas, ewk_context_WKContext_get(context), 0);
1455 #endif
1456 }
1457
1458 Evas_Object* ewk_view_add(Evas* canvas)
1459 {
1460     return ewk_view_add_with_context(canvas, ewk_context_default_get());
1461 }
1462
1463 Ewk_Context* ewk_view_context_get(const Evas_Object* ewkView)
1464 {
1465     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1466     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1467     return priv->context;
1468 }
1469
1470 Eina_Bool ewk_view_uri_set(Evas_Object* ewkView, const char* uri)
1471 {
1472     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1473     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1474
1475     WKRetainPtr<WKURLRef> url(AdoptWK, WKURLCreateWithUTF8CString(uri));
1476     WKPageLoadURL(toAPI(priv->pageClient->page()), url.get());
1477
1478     eina_stringshare_replace(&priv->uri, uri);
1479
1480     return true;
1481 }
1482
1483 const char* ewk_view_uri_get(const Evas_Object* ewkView)
1484 {
1485     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1486     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1487
1488     return priv->uri;
1489 }
1490
1491 Eina_Bool ewk_view_reload(Evas_Object* ewkView)
1492 {
1493     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1494     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1495
1496     WKPageReload(toAPI(priv->pageClient->page()));
1497     return true;
1498 }
1499
1500 Eina_Bool ewk_view_reload_bypass_cache(Evas_Object* ewkView)
1501 {
1502     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1503     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1504
1505     WKPageReloadFromOrigin(toAPI(priv->pageClient->page()));
1506
1507     return true;
1508 }
1509
1510 Eina_Bool ewk_view_stop(Evas_Object* ewkView)
1511 {
1512     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1513     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1514
1515     WKPageStopLoading(toAPI(priv->pageClient->page()));
1516     return true;
1517 }
1518
1519 Eina_Bool ewk_view_device_pixel_ratio_set(Evas_Object* ewkView, float ratio)
1520 {
1521     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1522     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1523
1524     priv->pageClient->page()->setCustomDeviceScaleFactor(ratio);
1525     return true;
1526 }
1527
1528 float ewk_view_device_pixel_ratio_get(const Evas_Object* ewkView)
1529 {
1530     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 1);
1531     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 1);
1532
1533     return priv->pageClient->page()->deviceScaleFactor();
1534 }
1535
1536 void ewk_view_display(Evas_Object* ewkView, const IntRect& rect)
1537 {
1538     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1539     if (!smartData->image)
1540         return;
1541
1542     evas_object_image_data_update_add(smartData->image, rect.x(), rect.y(), rect.width(), rect.height());
1543 }
1544
1545 Eina_Bool ewk_view_back(Evas_Object* ewkView)
1546 {
1547     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1548     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1549
1550     WKPageRef pageRef = toAPI(priv->pageClient->page());
1551     if (WKPageCanGoBack(pageRef)) {
1552         WKPageGoBack(pageRef);
1553         return true;
1554     }
1555     return false;
1556 }
1557
1558 Eina_Bool ewk_view_forward(Evas_Object* ewkView)
1559 {
1560     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1561     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1562
1563     WKPageRef pageRef = toAPI(priv->pageClient->page());
1564     if (WKPageCanGoForward(pageRef)) {
1565         WKPageGoForward(pageRef);
1566         return true;
1567     }
1568     return false;
1569 }
1570
1571 Eina_Bool ewk_view_back_possible(Evas_Object* ewkView)
1572 {
1573     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1574     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1575
1576     return WKPageCanGoBack(toAPI(priv->pageClient->page()));
1577 }
1578
1579 Eina_Bool ewk_view_forward_possible(Evas_Object* ewkView)
1580 {
1581     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1582     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1583
1584     return WKPageCanGoForward(toAPI(priv->pageClient->page()));
1585 }
1586
1587 void ewk_view_image_data_set(Evas_Object* ewkView, void* imageData, const IntSize& size)
1588 {
1589     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1590     if (!imageData || !smartData->image)
1591         return;
1592
1593     evas_object_resize(smartData->image, size.width(), size.height());
1594     evas_object_image_size_set(smartData->image, size.width(), size.height());
1595     evas_object_image_data_copy_set(smartData->image, imageData);
1596 }
1597
1598 WebPageProxy* ewk_view_page_get(const Evas_Object* ewkView)
1599 {
1600     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1601     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1602
1603     return priv->pageClient->page();
1604 }
1605
1606 #if OS(TIZEN)
1607 // FIXME: It should be removed.
1608 WKPageRef ewk_view_WKPage_get(Evas_Object* ewkView)
1609 {
1610     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1611     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1612
1613     return toAPI(priv->pageClient->page());
1614 }
1615
1616 Eina_Bool ewk_view_mouse_events_enabled_set(Evas_Object* ewkView, Eina_Bool enabled)
1617 {
1618     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1619     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1620
1621     enabled = !!enabled;
1622     if (priv->areMouseEventsEnabled == enabled)
1623         return true;
1624
1625     priv->areMouseEventsEnabled = enabled;
1626     if (enabled)
1627         _ewk_view_mouse_events_connect(smartData);
1628     else
1629         _ewk_view_mouse_events_disconnect(smartData);
1630
1631     return true;
1632 }
1633
1634 Eina_Bool ewk_view_mouse_events_enabled_get(const Evas_Object* ewkView)
1635 {
1636     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1637     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1638
1639     return priv->areMouseEventsEnabled;
1640 }
1641
1642 Eina_Bool ewk_view_feed_touch_event(Evas_Object* ewkView, Ewk_Touch_Event_Type type, Eina_List* points, const Evas_Modifier* modifiers)
1643 {
1644 #if ENABLE(TOUCH_EVENTS)
1645     EINA_SAFETY_ON_NULL_RETURN_VAL(points, false);
1646     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1647     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1648
1649 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1650     // We don't want to process touch event when context menu is shown.
1651     if (priv->pageClient->isContextMenuVisible()) {
1652 #if ENABLE(TIZEN_GESTURE)
1653         priv->gestureRecognizer->setEnableGesture(true);
1654         priv->gestureRecognizer->setEnableMoving(true);
1655 #endif
1656         return true;
1657     }
1658 #endif
1659
1660 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
1661     const Eina_List* list;
1662     void* item;
1663     EINA_LIST_FOREACH(points, list, item) {
1664         Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(item);
1665         float revertScale = 1 / priv->pageClient->scaleFactor();
1666         IntPoint scrollPosition = priv->pageClient->scrollPosition();
1667         point->x = (scrollPosition.x() + (point->x - smartData->view.x)) * revertScale + smartData->view.x;
1668         point->y = (scrollPosition.y() + (point->y - smartData->view.y)) * revertScale + smartData->view.y;
1669     }
1670 #endif
1671
1672     Evas_Point position = {smartData->view.x, smartData->view.y};
1673     priv->pageClient->page()->handleTouchEvent(NativeWebTouchEvent(type, points, modifiers, position, smartData->base.evas, ecore_time_get()));
1674
1675     return true;
1676 #else
1677     return false;
1678 #endif
1679 }
1680
1681 static Eina_Bool _ewk_view_default_javascript_alert(Evas_Object* ewkView, const char* alertText, void* userData)
1682 {
1683     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1684     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1685
1686     return priv->javascriptPopup->alert(alertText);
1687 }
1688
1689 static Eina_Bool _ewk_view_default_javascript_confirm(Evas_Object* ewkView, const char* message, void* userData)
1690 {
1691     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1692     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1693
1694     return priv->javascriptPopup->confirm(message);
1695 }
1696
1697 static Eina_Bool _ewk_view_default_javascript_prompt(Evas_Object* ewkView, const char* message, const char* defaultValue, void* userData)
1698 {
1699     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1700     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1701
1702     return priv->javascriptPopup->prompt(message, defaultValue);
1703 }
1704
1705 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)
1706 {
1707     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1708     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1709
1710     return priv->openPanel->openPanel(ewkView, allow_multiple_files, accepted_mime_types, capture, priv);
1711 }
1712
1713 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1714 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)
1715 {
1716     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1717
1718     if (priv->popupPicker)
1719         ewk_popup_picker_del(priv->popupPicker);
1720
1721     priv->popupPicker = ewk_popup_picker_new(smartData->self, items, selectedIndex);
1722
1723     return true;
1724 }
1725
1726 Eina_Bool _ewk_view_popup_menu_hide(Ewk_View_Smart_Data* smartData)
1727 {
1728     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1729
1730     if (!priv->popupPicker)
1731         return false;
1732
1733     ewk_popup_picker_del(priv->popupPicker);
1734     priv->popupPicker = 0;
1735
1736     return true;
1737 }
1738 #endif
1739
1740 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1741 static Eina_Bool _ewk_view_input_picker_show(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType, const char* inputValue)
1742 {
1743     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1744
1745     priv->inputPicker->show(inputType, inputValue);
1746     return true;
1747 }
1748 #endif
1749
1750 #if ENABLE(TIZEN_DATALIST_ELEMENT)
1751 static Eina_Bool _ewk_view_data_list_show(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType, Eina_List* optionList)
1752 {
1753     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1754
1755     priv->inputPicker->showDataList(inputType, optionList);
1756     return true;
1757 }
1758
1759 static Eina_Bool _ewk_view_data_list_hide(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType)
1760 {
1761     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1762
1763     priv->inputPicker->hideDataList(inputType);
1764     return true;
1765 }
1766 #endif
1767
1768 PageClientImpl* ewkViewGetPageClient(const Evas_Object* ewkView)
1769 {
1770     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1771     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1772
1773     return priv->pageClient.get();
1774 }
1775
1776 double ewk_view_text_zoom_get(const Evas_Object* ewkView)
1777 {
1778     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 1);
1779     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 1);
1780
1781     return WKPageGetTextZoomFactor(toAPI(priv->pageClient->page()));
1782 }
1783
1784 Eina_Bool ewk_view_text_zoom_set(Evas_Object* ewkView, double textZoomFactor)
1785 {
1786     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1787     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
1788
1789     WKPageSetTextZoomFactor(toAPI(priv->pageClient->page()), textZoomFactor);
1790     return true;
1791 }
1792
1793 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1794 void ewkViewShowFocusRing(Evas_Object* ewkView, const IntPoint& position)
1795 {
1796     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1797     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1798     if (!priv->focusRing)
1799         return;
1800
1801     priv->focusRing->requestToShow(position);
1802 }
1803
1804 void ewkViewHideFocusRing(Evas_Object* ewkView)
1805 {
1806     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1807     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1808     if (!priv->focusRing)
1809         return;
1810
1811     priv->focusRing->hide();
1812 }
1813 #endif // #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1814
1815 Ewk_Frame_Ref ewk_view_main_frame_get(Evas_Object* ewkView)
1816 {
1817     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1818     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1819
1820     return static_cast<Ewk_Frame_Ref>(WKPageGetMainFrame(toAPI(priv->pageClient->page())));
1821 }
1822
1823 Ewk_Frame_Ref ewk_view_focused_frame_get(Evas_Object* ewkView)
1824 {
1825     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1826     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1827
1828     return static_cast<Ewk_Frame_Ref>(WKPageGetFocusedFrame(toAPI(priv->pageClient->page())));
1829 }
1830
1831 Ewk_Setting* ewk_view_setting_get(Evas_Object* ewkView)
1832 {
1833     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1834     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1835
1836     return priv->setting;
1837 }
1838
1839 #if ENABLE(TIZEN_WEBKIT2_CURSOR_PARTIAL_EARLY_MERGE)
1840 void ewk_view_cursor_set(Evas_Object* ewkView, const Cursor& cursor)
1841 {
1842 #ifdef HAVE_ECORE_X
1843     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1844     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1845
1846     if (!priv->isUsingEcoreX)
1847         return;
1848
1849     const char* group = cursor.platformCursor();
1850     if (!group || group == priv->cursorGroup)
1851         return;
1852     priv->cursorGroup = group;
1853
1854     Ecore_Evas* ecoreEvas = ecore_evas_ecore_evas_get(smartData->base.evas);
1855     WebCore::applyFallbackCursor(ecoreEvas, group);
1856 #endif
1857 }
1858 #endif
1859
1860 JSGlobalContextRef ewkViewGetJavascriptGlobalContext(Evas_Object* ewkView)
1861 {
1862     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1863     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
1864
1865     if (!priv->javascriptGlobalContext)
1866         priv->javascriptGlobalContext = JSGlobalContextCreate(0);
1867     return priv->javascriptGlobalContext;
1868 }
1869
1870 static void setURI(Evas_Object* ewkView)
1871 {
1872     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1873     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1874
1875     WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKPageCopyActiveURL(toAPI(priv->pageClient->page())));
1876     if (!wkURL)
1877         return;
1878
1879     CString activeURI = toImpl(wkURL.get())->string().utf8();
1880
1881     if (priv->uri && (activeURI == CString(priv->uri)))
1882         return;
1883
1884     eina_stringshare_replace(&priv->uri, activeURI.data());
1885
1886     evas_object_smart_callback_call(ewkView, "uri,changed", static_cast<void*>(const_cast<char*>(priv->uri)));
1887 }
1888
1889 void ewkViewLoadStarted(Evas_Object* ewkView)
1890 {
1891     setURI(ewkView);
1892     evas_object_smart_callback_call(ewkView, "load,started", 0);
1893 }
1894
1895 void ewkViewLoadCommitted(Evas_Object* ewkView)
1896 {
1897     setURI(ewkView);
1898     evas_object_smart_callback_call(ewkView, "load,committed", 0);
1899 }
1900
1901 void ewkViewLoadFinished(Evas_Object* ewkView)
1902 {
1903     setURI(ewkView);
1904     evas_object_smart_callback_call(ewkView, "load,finished", 0);
1905 }
1906
1907 void ewkViewLoadError(Evas_Object* ewkView, WKErrorRef error)
1908 {
1909     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1910     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1911
1912     Ewk_Error* ewkError = ewkErrorCreate(error);
1913     ewkErrorLoadErrorPage(ewkError, toAPI(priv->pageClient->page()));
1914     evas_object_smart_callback_call(ewkView, "load,error", ewkError);
1915     ewkErrorDelete(ewkError);
1916 }
1917
1918 void ewkViewSetTitleAndURL(Evas_Object* ewkView, const char* title, const char* url)
1919 {
1920     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1921     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1922
1923     if (title && eina_stringshare_replace(&priv->title, title))
1924         evas_object_smart_callback_call(ewkView, "title,changed", static_cast<void*>(const_cast<char*>(priv->title)));
1925     if (url && eina_stringshare_replace(&priv->uri, title))
1926         evas_object_smart_callback_call(ewkView, "uri,changed", static_cast<void*>(const_cast<char*>(priv->uri)));
1927 }
1928
1929 void ewkViewSetTitle(Evas_Object* ewkView, const char* title)
1930 {
1931     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1932     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1933
1934     if (!title || !eina_stringshare_replace(&priv->title, title))
1935         return;
1936     evas_object_smart_callback_call(ewkView, "title,changed", static_cast<void*>(const_cast<char*>(priv->title)));
1937 }
1938
1939 void ewkViewDidFirstVisuallyNonEmptyLayout(Evas_Object* ewkView)
1940 {
1941     evas_object_smart_callback_call(ewkView, "load,nonemptylayout,finished", 0);
1942 }
1943
1944 void ewkViewDidReceiveAuthenticationChallenge(Evas_Object* ewkView, Ewk_Auth_Challenge* authChallenge)
1945 {
1946     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1947     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1948
1949     if (priv->authChallenge)
1950         ewkAuthChallengeDelete(priv->authChallenge);
1951     priv->authChallenge = authChallenge;
1952
1953     evas_object_smart_callback_call(ewkView, "authentication,challenge", priv->authChallenge);
1954 }
1955
1956 void ewkViewLoadProgressChanged(Evas_Object* ewkView, double progress)
1957 {
1958     evas_object_smart_callback_call(ewkView, "load,progress", &progress);
1959 }
1960
1961 void ewkViewProcessCrashed(Evas_Object* ewkView)
1962 {
1963     evas_object_smart_callback_call(ewkView, "process,crashed", 0);
1964 }
1965
1966 #if ENABLE(TIZEN_SQL_DATABASE)
1967 unsigned long long ewkViewExceededDatabaseQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, WKStringRef databaseName, WKStringRef displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage)
1968 {
1969     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, currentQuota);
1970     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, currentQuota);
1971
1972     if (priv->exceededDatabaseQuota)
1973         ewkContextDeleteExceededQuota(priv->exceededDatabaseQuota);
1974     priv->exceededDatabaseQuota = ewkContextCreateExceededQuota(origin, databaseName, displayName, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage);
1975     evas_object_smart_callback_call(ewkView, "database,quota,exceeded", priv->exceededDatabaseQuota);
1976
1977     return ewkContextGetNewQuotaForExceededQuota(priv->context, priv->exceededDatabaseQuota);
1978 }
1979 #endif
1980
1981 #if ENABLE(TIZEN_NOTIFICATION)
1982 void ewkViewCancelNotification(Evas_Object* ewkView, uint64_t notificationID)
1983 {
1984     evas_object_smart_callback_call(ewkView, "notification,cancel", &notificationID);
1985 }
1986
1987 void ewkViewRequestNotificationPermission(Evas_Object* ewkView, Ewk_Notification_Permission_Request* notificationPermissionRequest)
1988 {
1989     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1990     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
1991
1992     if(priv->notificationPermissionRequest)
1993         ewkNotificationDeletePermissionRequest(priv->notificationPermissionRequest);
1994     priv->notificationPermissionRequest = notificationPermissionRequest;
1995
1996     evas_object_smart_callback_call(ewkView, "notification,permission,request", notificationPermissionRequest);
1997 }
1998
1999 void ewkViewShowNotification(Evas_Object* ewkView, Ewk_Notification* notification)
2000 {
2001     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2002     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2003
2004     Eina_List* listIterator=0;
2005     void* data=0;
2006     const char* replaceID = ewkNotificationGetReplaceID(notification);
2007     if(strlen(replaceID)) {
2008         EINA_LIST_FOREACH(priv->notifications, listIterator, data) {
2009             Ewk_Notification* notificationForReplace = static_cast<Ewk_Notification*>(data);
2010             if(!strcmp(ewkNotificationGetReplaceID(notificationForReplace), replaceID))
2011                 ewkViewCancelNotification(ewkView, ewk_notification_id_get(notificationForReplace));
2012         }
2013     }
2014
2015     priv->notifications = eina_list_append(priv->notifications, notification);
2016     evas_object_smart_callback_call(ewkView, "notification,show", notification);
2017 }
2018 #endif
2019
2020 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER)
2021 void ewkViewRegisterProtocolHandlers(Evas_Object* ewkView, const char* scheme, const char* baseUrl, const char* url, const char* title)
2022 {
2023     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2024     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(scheme, baseUrl, url, title);
2025     evas_object_smart_callback_call(ewkView, "protocolhandlers,register", static_cast<void*>(customHandlersData));
2026     ewkCustomHandlersDeleteData(customHandlersData);
2027 }
2028 #endif
2029
2030 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
2031 void ewkViewRegisterContentHandlers(Evas_Object* ewkView, const char* mimeType, const char* baseUrl, const char* url, const char* title)
2032 {
2033     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2034     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(mimeType, baseUrl, url, title);
2035     evas_object_smart_callback_call(ewkView, "contenthandlers,register", static_cast<void*>(customHandlersData));
2036     ewkCustomHandlersDeleteData(customHandlersData);
2037 }
2038 #endif
2039
2040 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
2041 bool ewkViewGetStandaloneStatus(Evas_Object* ewkView)
2042 {
2043     bool standalone = true;
2044     evas_object_smart_callback_call(ewkView, "webapp,metatag,standalone", (void*)&standalone);
2045     return standalone;
2046 }
2047 #endif
2048
2049 #if ENABLE(TIZEN_MM_PLAYER)
2050 void ewkViewProcessHTML5Video(Evas_Object* ewkView, WKStringRef url, WKStringRef cookie)
2051 {
2052     Ewk_View_Html5_Video_Data videoData;
2053     videoData.url = url;
2054     videoData.cookie = cookie;
2055     evas_object_smart_callback_call(ewkView, "request,html5video", &videoData);
2056 }
2057 #endif
2058
2059 #if ENABLE(TIZEN_MEDIA_STREAM)
2060 void ewkViewRequestUserMediaPermission(Evas_Object* ewkView, Ewk_User_Media_Permission* userMediaPermission)
2061 {
2062     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2063     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2064     if (priv->userMediaPermission)
2065         ewkUserMediaPermissionDelete(priv->userMediaPermission);
2066     priv->userMediaPermission = userMediaPermission;
2067
2068     evas_object_smart_callback_call(ewkView, "usermedia,permission,request", priv->userMediaPermission);
2069 }
2070 #endif
2071
2072 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
2073 void ewkViewProcessJSBridgePlugin(Evas_Object* ewkView, WKStringRef request, WKStringRef message)
2074 {
2075     int requestLength = WKStringGetMaximumUTF8CStringSize(request);
2076     OwnArrayPtr<char> requestBuffer = adoptArrayPtr(new char[requestLength]);
2077     int messageLength = WKStringGetMaximumUTF8CStringSize(message);
2078     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[messageLength]);
2079     WKStringGetUTF8CString(request, requestBuffer.get(), requestLength);
2080     WKStringGetUTF8CString(message, messageBuffer.get(), messageLength);
2081
2082     evas_object_smart_callback_call(ewkView, requestBuffer.get(), static_cast<void*>(messageBuffer.get()));
2083 }
2084 #endif
2085
2086 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
2087 void ewkViewRequestCertificateConfirm(Evas_Object* ewkView, Ewk_Certificate_Policy_Decision* certificatePolicyDecision)
2088 {
2089     evas_object_smart_callback_call(ewkView, "request,certificate,confirm", certificatePolicyDecision);
2090 }
2091 #endif
2092
2093 void ewkViewCustomizeContextMenu(Evas_Object* ewkView, Ewk_Context_Menu* menu)
2094 {
2095     evas_object_smart_callback_call(ewkView, "contextmenu,customize", static_cast<void*>(menu));
2096 }
2097
2098 void ewkViewCustomContextMenuItemSelected(Evas_Object* ewkView, Ewk_Context_Menu_Item* item)
2099 {
2100     evas_object_smart_callback_call(ewkView, "contextmenu,selected", static_cast<void*>(item));
2101 }
2102
2103 void ewkViewClosePage(Evas_Object* ewkView)
2104 {
2105     evas_object_smart_callback_call(ewkView, "close,window", 0);
2106 }
2107
2108 #if ENABLE(TIZEN_GEOLOCATION)
2109 void ewkViewRequestGeolocationPermission(Evas_Object* ewkView, Ewk_Geolocation_Permission_Data* permissionData)
2110 {
2111     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2112     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2113
2114     if (priv->geolocationPermission)
2115         ewkGeolocationDeletePermission(priv->geolocationPermission);
2116     priv->geolocationPermission = permissionData;
2117
2118     evas_object_smart_callback_call(ewkView, "request,geolocation,permission", priv->geolocationPermission);
2119 }
2120
2121 void ewkViewSetGeolocation(Evas_Object* ewkView, Ewk_Geolocation* geolocation)
2122 {
2123     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2124     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2125
2126     priv->geolocation = geolocation;
2127 }
2128
2129 Ewk_Geolocation* ewkViewGetGeolocation(Evas_Object* ewkView)
2130 {
2131     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2132     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
2133
2134     return priv->geolocation;
2135 }
2136
2137 bool ewkViewIsValidLocationService(Evas_Object* ewkView)
2138 {
2139     bool valid = false;
2140     evas_object_smart_callback_call(ewkView, "geolocation,valid", &valid);
2141     return valid;
2142 }
2143 #endif
2144
2145 WKPageRef ewkViewCreateNewPage(Evas_Object* ewkView)
2146 {
2147     Evas_Object* createdEwkView = 0;
2148
2149     evas_object_smart_callback_call(ewkView, "create,window", &createdEwkView);
2150
2151     if (!createdEwkView)
2152         return 0;
2153
2154     return static_cast<WKPageRef>(WKRetain(toAPI(ewk_view_page_get(createdEwkView))));
2155 }
2156
2157 void ewkViewFormSubmit(Evas_Object* ewkView, Ewk_Form_Data* formData)
2158 {
2159     evas_object_smart_callback_call(ewkView, "form,submit", formData);
2160 }
2161
2162 void ewkViewPolicyNavigationDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2163 {
2164     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2165     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
2166     if (priv->policyDecision)
2167         ewkPolicyDecisionDelete(priv->policyDecision);
2168     priv->policyDecision = policyDecision;
2169
2170     evas_object_smart_callback_call(ewkView, "policy,navigation,decide", priv->policyDecision);
2171 }
2172
2173 void ewkViewPolicyNewWindowDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2174 {
2175     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2176     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
2177     if (priv->policyDecision)
2178         ewkPolicyDecisionDelete(priv->policyDecision);
2179     priv->policyDecision = policyDecision;
2180
2181     evas_object_smart_callback_call(ewkView, "policy,newwindow,decide", priv->policyDecision);
2182 }
2183
2184 void ewkViewPolicyResponseDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2185 {
2186     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2187     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
2188     if (priv->policyDecision)
2189         ewkPolicyDecisionDelete(priv->policyDecision);
2190     priv->policyDecision = policyDecision;
2191
2192     evas_object_smart_callback_call(ewkView, "policy,response,decide", priv->policyDecision);
2193 }
2194
2195 void ewkViewSendScrollEvent(Evas_Object* ewkView, int deltaX, int deltaY)
2196 {
2197     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2198     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2199
2200     IntPoint scrollPosition = priv->pageClient->scrollPosition();
2201     IntSize contentsSize = priv->pageClient->page()->contentsSize();
2202 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2203     contentsSize.scale(priv->pageClient->scaleFactor());
2204 #endif
2205
2206     // some website's contents size is smaller than view size,
2207     // so we have to adjust contents size to view size for that case.
2208     if (contentsSize.width() < smartData->view.w)
2209         contentsSize.setWidth(smartData->view.w);
2210     if (contentsSize.height() < smartData->view.h)
2211         contentsSize.setHeight(smartData->view.h);
2212
2213     // Call "scroll,down" if webview can be scrolled down.
2214     if (deltaY > 0 && (scrollPosition.y() + smartData->view.h) < contentsSize.height())
2215         evas_object_smart_callback_call(ewkView, "scroll,down", 0);
2216     // Call "scroll,up" if webview can be scrolled up.
2217     else if (deltaY < 0 && scrollPosition.y() > 0)
2218         evas_object_smart_callback_call(ewkView, "scroll,up", 0);
2219
2220     // Call "scroll,right" if webview can be scrolled down.
2221     if (deltaX > 0 && (scrollPosition.x() + smartData->view.w) < contentsSize.width())
2222         evas_object_smart_callback_call(ewkView, "scroll,right", 0);
2223     // Call "scroll,left" if webview can be scrolled up.
2224     else if (deltaX < 0 && scrollPosition.x() > 0)
2225         evas_object_smart_callback_call(ewkView, "scroll,left", 0);
2226 }
2227
2228 void ewkViewSendEdgeEvent(Evas_Object* ewkView, const IntPoint& scrollPosition, int deltaX, int deltaY)
2229 {
2230     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2231     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2232
2233     IntSize contentsSize = priv->pageClient->page()->contentsSize();
2234 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2235     contentsSize.scale(priv->pageClient->scaleFactor());
2236 #endif
2237
2238     int maxScrollY = contentsSize.height() - smartData->view.h;
2239     if (!priv->isVerticalEdge) {
2240         if (deltaY < 0 && (scrollPosition.y() + deltaY) <= 0) {
2241             evas_object_smart_callback_call(ewkView, "edge,top", NULL);
2242             priv->isVerticalEdge = true;
2243         } else if (deltaY > 0 && (scrollPosition.y() + deltaY) >= maxScrollY) {
2244             evas_object_smart_callback_call(ewkView, "edge,bottom", NULL);
2245             priv->isVerticalEdge = true;
2246         }
2247     } else {
2248         if (maxScrollY && ((scrollPosition.y() == 0 && deltaY > 0)
2249                            || (scrollPosition.y() == maxScrollY && deltaY < 0)))
2250             priv->isVerticalEdge = false;
2251     }
2252
2253     int maxScrollX = contentsSize.width() - smartData->view.w;
2254     if (!priv->isHorizontalEdge) {
2255         if (deltaX < 0 && (scrollPosition.x() + deltaX) <= 0) {
2256             evas_object_smart_callback_call(ewkView, "edge,left", NULL);
2257             priv->isHorizontalEdge = true;
2258         } else if (deltaX > 0 && (scrollPosition.x() + deltaX) >= maxScrollX) {
2259             evas_object_smart_callback_call(ewkView, "edge,right", NULL);
2260             priv->isHorizontalEdge = true;
2261         }
2262     } else {
2263         if (maxScrollX && ((scrollPosition.x() == 0 && deltaX > 0)
2264                            || (scrollPosition.x() == maxScrollX && deltaX < 0)))
2265             priv->isHorizontalEdge = false;
2266     }
2267 }
2268
2269 void ewkViewClearEdges(Evas_Object* ewkView)
2270 {
2271     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2272     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2273
2274     priv->isVerticalEdge = false;
2275     priv->isHorizontalEdge = false;
2276 }
2277
2278 void ewk_view_top_of_contents_go(Evas_Object* ewkView)
2279 {
2280     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2281     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2282
2283 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2284     priv->pageClient->setVisibleContentRect(IntPoint(), priv->pageClient->scaleFactor(), FloatPoint());
2285     priv->pageClient->displayViewport();
2286 #else
2287     priv->pageClient->page()->scrollMainFrameTo(IntPoint());
2288 #endif
2289 }
2290
2291 Eina_Bool ewk_view_enable_specified_plugin_set(Evas_Object* ewkView, Eina_Bool enable, const char* mimeType)
2292 {
2293 #if ENABLE(TIZEN_ON_OFF_SPECIFIED_PLUGINS)
2294     if (!mimeType)
2295         return false;
2296
2297     PluginDatabase* pluginDatabase = PluginDatabase::installedPlugins(true);
2298     if (!pluginDatabase)
2299         return false;
2300
2301     // Find pluginPackage.
2302     String key = String(mimeType).lower();
2303     Vector<PluginPackage*, 2> pluginChoices;
2304     const Vector<WebCore::PluginPackage *> plugins = pluginDatabase->plugins();
2305     for (unsigned int i = 0; i < plugins.size(); i++) {
2306         PluginPackage* plugin = plugins[i];
2307         if (plugin->mimeToDescriptions().contains(key))
2308             pluginChoices.append(plugin);
2309     }
2310
2311     // Set enable/disable to choiced pluginPackage.
2312     if (!pluginChoices.isEmpty()) {
2313         qsort(pluginChoices.data(), pluginChoices.size(), sizeof(PluginPackage*), PluginDatabase::preferredPluginCompare);
2314         pluginChoices[0].setEnabled(enable);
2315         return true;
2316     }
2317
2318     return false;
2319 #else
2320     return false;
2321 #endif
2322 }
2323
2324 double ewk_view_scale_get(Evas_Object* ewkView)
2325 {
2326     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1);
2327     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, -1);
2328
2329     return priv->pageClient->page()->scaleFactor();
2330 }
2331
2332 Eina_Bool ewk_view_scale_set(Evas_Object* ewkView, double scaleFactor, Evas_Coord centerX, Evas_Coord centerY)
2333 {
2334     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2335     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2336
2337     scaleFactor = priv->pageClient->adjustScaleWithViewport(scaleFactor);
2338
2339     IntPoint scrollPosition = priv->pageClient->scrollPosition();
2340     double scaleDifference = scaleFactor / priv->pageClient->scaleFactor();
2341     int newScrollX = (scrollPosition.x() + centerX - smartData->view.x) * scaleDifference - (centerX - smartData->view.x);
2342     int newScrollY = (scrollPosition.y() + centerY - smartData->view.y) * scaleDifference - (centerY - smartData->view.y);
2343
2344     priv->pageClient->page()->scale(scaleFactor, IntPoint(newScrollX, newScrollY));
2345
2346     return true;
2347 }
2348
2349 void ewk_view_scale_range_get(Evas_Object* ewkView, double* minimumScale, double* maximumScale)
2350 {
2351     EWK_VIEW_SD_GET(ewkView, smartData);
2352     if (!smartData || !smartData->priv) {
2353         if (minimumScale)
2354             *minimumScale = -1;
2355         if (maximumScale)
2356             *maximumScale = -1;
2357         return;
2358     }
2359
2360     PageClientImpl::ViewportConstraints constraints = smartData->priv->pageClient->viewportConstraints();
2361     if (minimumScale)
2362         *minimumScale = constraints.minimumScale;
2363     if (maximumScale)
2364         *maximumScale = constraints.maximumScale;
2365 }
2366
2367 static void inputPickerClosed(void* data, Evas_Object*, void*)
2368 {
2369     Evas_Object* ewkView = static_cast<Evas_Object*>(data);
2370     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2371     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
2372
2373     ecore_imf_context_input_panel_hide(priv->pageClient->getIMFContext());
2374     ecore_imf_context_focus_out(priv->pageClient->getIMFContext());
2375 }
2376
2377 Evas_Object* ewk_view_image_get(Evas_Object* o)
2378 {
2379     EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
2380     return sd->image;
2381 }
2382
2383 void ewk_view_form_navigation_move(Evas_Object* ewkView, int newPosition)
2384 {
2385     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2386     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2387
2388     priv->pageClient->page()->moveFocus(newPosition);
2389     priv->formNavigation.position = newPosition;
2390 }
2391
2392 bool ewk_view_focused_node_adjust(Evas_Object* ewkView)
2393 {
2394     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2395     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2396
2397     double scaleFactor = priv->pageClient->scaleFactor();
2398     IntSize contentsSize = priv->pageClient->page()->contentsSize();
2399
2400     IntSize visibleSize(0, 0);
2401     IntPoint scrollPosition(0, 0);
2402     IntRect caretRect(0, 0, 0, 0);
2403
2404     double newScaleFactor = scaleFactor;
2405     // Readable zoom value is dependent on device DPI
2406     if (scaleFactor < priv->pageClient->page()->pageGroup()->preferences()->devicePixelRatio()
2407         && priv->pageClient->viewportConstraints().userScalable)
2408         newScaleFactor = ((float)priv->pageClient->page()->pageGroup()->preferences()->devicePixelRatio()) / 160;
2409
2410     // Readable zoom value should be inside of viewport scale range
2411     newScaleFactor = priv->pageClient->adjustScaleWithViewport(newScaleFactor);
2412
2413     // scale contents' size with new scale factor
2414 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2415     contentsSize.scale(newScaleFactor);
2416 #else
2417     contentsSize.scale(newScaleFactor / scaleFactor);
2418 #endif
2419
2420     Ecore_IMF_Context* imfContext = priv->pageClient->getIMFContext();
2421     // We should treat both of ECORE_IMF_INPUT_PANEL_STATE_SHOW and ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW
2422     // as IME is shown. ECORE_IMF_INPUT_PANEL_STATE_HIDE is ignored at here.
2423     if (!(static_cast<PageClient*>(priv->pageClient.get()))->isViewFocused()
2424         || !imfContext
2425         || ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_HIDE)
2426         return false;
2427
2428     visibleSize = IntSize(smartData->view.w, smartData->view.h);
2429     // caret position can be outside of visible rect.
2430     // we need to consider it.
2431     priv->pageClient->page()->getCaretPosition(caretRect);
2432 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2433     caretRect.scale(newScaleFactor);
2434 #else
2435     caretRect.scale(newScaleFactor / scaleFactor);
2436 #endif
2437     if (caretRect.isEmpty())
2438         return false;
2439
2440     // set paddings
2441     scrollPosition.setX(caretRect.x() - 20);
2442     scrollPosition.setY(caretRect.y() - visibleSize.height() / 2);
2443
2444     // Restrict visible content rect inside of contents boundary
2445     if (scrollPosition.x() < 0)
2446         scrollPosition.setX(0);
2447     if (scrollPosition.y() < 0)
2448         scrollPosition.setY(0);
2449     if (scrollPosition.x() + visibleSize.width() > contentsSize.width())
2450         scrollPosition.setX(contentsSize.width() - visibleSize.width());
2451     if (scrollPosition.y() + visibleSize.height() > contentsSize.height())
2452         scrollPosition.setY(contentsSize.height() - visibleSize.height());
2453
2454 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2455     priv->pageClient->setVisibleContentRect(scrollPosition, newScaleFactor, FloatPoint());
2456     if (newScaleFactor == scaleFactor)
2457         priv->pageClient->displayViewport();
2458 #else
2459     if (newScaleFactor != scaleFactor)
2460         priv->pageClient->page()->scalePage(newScaleFactor, scrollPosition);
2461     else
2462         priv->pageClient->page()->scrollMainFrameTo(scrollPosition);
2463 #endif
2464     evas_object_move(smartData->image, smartData->view.x, smartData->view.y);
2465     return true;
2466 }
2467
2468 #if ENABLE(TIZEN_READER)
2469 static void getReaderCallback(WKDictionaryRef reader, WKErrorRef error, void* functionContext)
2470 {
2471     EINA_SAFETY_ON_NULL_RETURN(functionContext);
2472     Ewk_View_Callback_Context* context = static_cast<Ewk_View_Callback_Context*>(functionContext);
2473
2474     if (!reader || error) {
2475         delete context;
2476         return;
2477     }
2478
2479     WKRetainPtr<WKStringRef> urlKey(AdoptWK, WKStringCreateWithUTF8CString("url"));
2480     WKRetainPtr<WKStringRef> htmlKey(AdoptWK, WKStringCreateWithUTF8CString("html"));
2481     WKStringRef urlString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(reader, urlKey.get()));
2482     WKStringRef htmlString = static_cast<WKStringRef>(WKDictionaryGetItemForKey(reader, htmlKey.get()));
2483     ASSERT(urlString);
2484     ASSERT(htmlString);
2485
2486     int htmlLength = WKStringGetMaximumUTF8CStringSize(htmlString);
2487     ASSERT(htmlLength);
2488     OwnArrayPtr<char> html = adoptArrayPtr(new char[htmlLength]);
2489     WKStringGetUTF8CString(htmlString, html.get(), htmlLength);
2490
2491     ASSERT(context->readerCallback);
2492
2493     int urlLength = WKStringGetMaximumUTF8CStringSize(urlString);
2494     if (urlLength) {
2495         OwnArrayPtr<char> url = adoptArrayPtr(new char[urlLength]);
2496         WKStringGetUTF8CString(urlString, url.get(), urlLength);
2497         context->readerCallback(context->ewkView, url.get(), html.get(), context->userData);
2498     } else {
2499         context->readerCallback(context->ewkView, "", html.get(), context->userData);
2500     }
2501
2502     delete context;
2503 }
2504 #endif
2505
2506 void ewk_view_reader_article_check(Evas_Object* ewkView, Ewk_View_Reader_Callback callback, void* userData)
2507 {
2508 #if ENABLE(TIZEN_READER)
2509     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2510     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2511     EINA_SAFETY_ON_NULL_RETURN(callback);
2512
2513     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
2514     context->readerCallback = callback;
2515     context->ewkView = ewkView;
2516     context->userData = userData;
2517     WKPageCheckReaderArticle(toAPI(priv->pageClient->page()), context, getReaderCallback);
2518 #endif
2519 }
2520
2521 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
2522 void ewk_view_mark_for_sync(Evas_Object* ewkView)
2523 {
2524     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2525     EINA_SAFETY_ON_NULL_RETURN(smartData->image);
2526     evas_object_image_pixels_dirty_set(smartData->image, true);
2527 }
2528
2529 static void on_pixels_for_accelerated_compositing(void* data, Evas_Object* obj)
2530 {
2531     Evas_Object* ewkView = static_cast<Evas_Object*>(data);
2532     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2533     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2534     priv->pageClient->drawContents();
2535 }
2536
2537 bool ewk_view_image_native_surface_set(Evas_Object* ewkView, Evas_Native_Surface* nativeSurface)
2538 {
2539     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2540     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2541
2542     if (!smartData->image)
2543         return false;
2544
2545     evas_object_image_native_surface_set(smartData->image, nativeSurface);
2546     evas_object_image_pixels_get_callback_set(smartData->image, on_pixels_for_accelerated_compositing, ewkView);
2547
2548     return true;
2549 }
2550 #endif
2551
2552 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
2553 void ewk_view_write_data_to_clipboard_with_type(Evas_Object* ewkView, const String& data, Pasteboard::PasteboardDataType type)
2554 {
2555     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2556
2557     switch (type) {
2558     case Pasteboard::PlainText:
2559         elm_cnp_selection_set(elm_object_parent_widget_get(ewkView), ELM_SEL_TYPE_CLIPBOARD,
2560                               ELM_SEL_FORMAT_TEXT, data.utf8().data(), data.length());
2561         break;
2562     case Pasteboard::Markup:
2563         elm_cnp_selection_set(elm_object_parent_widget_get(ewkView), ELM_SEL_TYPE_CLIPBOARD,
2564                               ELM_SEL_FORMAT_HTML, data.utf8().data(), data.length());
2565         break;
2566     case Pasteboard::ImageURI:
2567         // FIXME: We pass data.length() + 1 because of a bug in elementary which adds some random characters
2568         // to copied image path. '+1' should be removed when the bug will be fixed on elementary side.
2569         elm_cnp_selection_set(elm_object_parent_widget_get(ewkView), ELM_SEL_TYPE_CLIPBOARD,
2570                               ELM_SEL_FORMAT_IMAGE, data.utf8().data(), data.length() + 1);
2571         break;
2572     default:
2573         break;
2574     }
2575 }
2576
2577 static Eina_Bool pasteCallback(void* data, Evas_Object* object, Elm_Selection_Data* selectionData)
2578 {
2579     WebPageProxy* webPageProxy = static_cast<WebPageProxy*>(data);
2580
2581     if (!selectionData || selectionData->len <= 0) {
2582         webPageProxy->sendPasteMessageWithData(String(""), WebCore::Pasteboard::PlainText);
2583     } else {
2584         String data = String::fromUTF8(static_cast<const char*>(selectionData->data));
2585         if (selectionData->format == ELM_SEL_FORMAT_TEXT)
2586             webPageProxy->sendPasteMessageWithData(data, WebCore::Pasteboard::PlainText);
2587         else if (selectionData->format == ELM_SEL_FORMAT_HTML)
2588             webPageProxy->sendPasteMessageWithData(data, WebCore::Pasteboard::Markup);
2589         else if (selectionData->format == ELM_SEL_FORMAT_IMAGE)
2590             webPageProxy->sendPasteMessageWithData(data, WebCore::Pasteboard::ImageURI);
2591     }
2592
2593     return true;
2594 }
2595
2596 void ewk_view_paste_with_clipboard(Evas_Object* ewkView)
2597 {
2598     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2599     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2600
2601     if (!ewk_util_number_of_clipboard_items_get(ewkView)) {
2602         priv->pageClient->page()->sendPasteMessageWithData(String(""), WebCore::Pasteboard::PlainText);
2603         return;
2604     }
2605
2606     Eina_Bool result = elm_cnp_selection_get(elm_object_parent_widget_get(ewkView), ELM_SEL_TYPE_CLIPBOARD,
2607                                              static_cast<Elm_Sel_Format>(ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_HTML | ELM_SEL_FORMAT_IMAGE),
2608                                              pasteCallback, priv->pageClient->page());
2609     if (!result)
2610         priv->pageClient->page()->sendPasteMessageWithData(String(""), WebCore::Pasteboard::PlainText);
2611 }
2612 #endif // ENABLE(TIZEN_WEBKIT_PASTEBOARD)
2613
2614 void ewk_view_suspend(Evas_Object* ewkView)
2615 {
2616     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2617     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2618
2619     priv->pageClient->suspendIfNeeded();
2620 }
2621
2622 void ewk_view_resume(Evas_Object* ewkView)
2623 {
2624     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2625     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2626
2627     priv->pageClient->resumeIfNeeded();
2628 }
2629
2630 Eina_Bool ewk_view_url_request_set(Evas_Object* ewkView, const char* url, Ewk_Http_Method method, Eina_Hash* headers, const char* body)
2631 {
2632     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2633     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2634     EINA_SAFETY_ON_NULL_RETURN_VAL(url, false);
2635
2636     ResourceRequest request(url);
2637
2638     switch (method) {
2639     case EWK_HTTP_METHOD_GET:
2640         request.setHTTPMethod("GET");
2641         break;
2642     case EWK_HTTP_METHOD_HEAD:
2643         request.setHTTPMethod("HEAD");
2644         break;
2645     case EWK_HTTP_METHOD_POST:
2646         request.setHTTPMethod("POST");
2647         break;
2648     case EWK_HTTP_METHOD_PUT:
2649         request.setHTTPMethod("PUT");
2650         break;
2651     case EWK_HTTP_METHOD_DELETE:
2652         request.setHTTPMethod("DELETE");
2653         break;
2654     default:
2655         return false;
2656     }
2657
2658     if (headers) {
2659         Eina_Iterator* it = eina_hash_iterator_tuple_new(headers);
2660         void* data;
2661         while (eina_iterator_next(it, &data)) {
2662             Eina_Hash_Tuple* t = static_cast<Eina_Hash_Tuple*>(data);
2663             const char* name = static_cast<const char*>(t->key);
2664             const char* value = static_cast<const char*>(t->data);
2665             request.addHTTPHeaderField(name, value);
2666         }
2667         eina_iterator_free(it);
2668     }
2669
2670     if (body)
2671         request.setHTTPBody(FormData::create(body));
2672
2673     WKRetainPtr<WKURLRequestRef> urlRequest(AdoptWK,toAPI(WebURLRequest::create(request).leakRef()));
2674     WKPageLoadURLRequest(toAPI(priv->pageClient->page()), urlRequest.get());
2675
2676     return true;
2677 }
2678
2679 Eina_Bool ewk_view_plain_text_set(Evas_Object* ewkView, const char* plainText)
2680 {
2681     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2682     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2683
2684     WKRetainPtr<WKStringRef> plainTextRef(AdoptWK, WKStringCreateWithUTF8CString(plainText));
2685     WKPageLoadPlainTextString(toAPI(priv->pageClient->page()), plainTextRef.get());
2686
2687     return true;
2688 }
2689
2690 Eina_Bool ewk_view_contents_set(Evas_Object* ewkView, const char* contents, size_t contentsSize, char* mimeType, char* encoding, char* baseUri)
2691 {
2692     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2693     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2694     EINA_SAFETY_ON_NULL_RETURN_VAL(contents, false);
2695
2696     if (contentsSize == 0)
2697         return false;
2698
2699     String mimeTypeString;
2700     if (mimeType)
2701         mimeTypeString = String::fromUTF8(mimeType);
2702     else
2703         mimeTypeString = String::fromUTF8("text/html");
2704
2705     String encodingString;
2706     if (encoding)
2707         encodingString = String::fromUTF8(encoding);
2708     else
2709         encodingString = String::fromUTF8("UTF-8");
2710
2711     String baseUriString;
2712     if (baseUri)
2713         baseUriString = String::fromUTF8(baseUri);
2714     else
2715         baseUriString = String::fromUTF8("about:blank");
2716
2717     WKRetainPtr<WKDataRef> contentsRef(AdoptWK, WKDataCreate(reinterpret_cast<const unsigned char*>(contents), contentsSize));
2718     priv->pageClient->page()->loadContentsbyMimeType(toImpl(contentsRef.get()), mimeTypeString, encodingString, baseUriString);
2719
2720     return true;
2721 }
2722
2723 const char* ewk_view_title_get(const Evas_Object* ewkView)
2724 {
2725     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2726     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
2727
2728     return priv->title;
2729 }
2730
2731 double ewk_view_load_progress_get(const Evas_Object* ewkView)
2732 {
2733     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1);
2734     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, -1);
2735
2736     return WKPageGetEstimatedProgress(toAPI(priv->pageClient->page()));
2737 }
2738
2739 Eina_Bool ewk_view_html_contents_set(Evas_Object* ewkView, const char* html, const char* baseUri)
2740 {
2741     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2742     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2743
2744     WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(html));
2745     WKRetainPtr<WKURLRef> baseURL(AdoptWK, WKURLCreateWithUTF8CString(baseUri));
2746
2747     WKPageLoadHTMLString(toAPI(priv->pageClient->page()), htmlString.get(), baseURL.get());
2748
2749     return true;
2750 }
2751
2752 Eina_Bool ewk_view_page_visibility_state_set(Evas_Object* ewkView, Ewk_Page_Visibility_State pageVisibilityState, Eina_Bool initialState)
2753 {
2754     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2755     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2756
2757 #if ENABLE(TIZEN_PAGE_VISIBILITY_API)
2758     WKPageSetPageVisibility(toAPI(priv->pageClient->page()), static_cast<WKPageVisibilityState
2759     >(pageVisibilityState), initialState);
2760
2761     return true;
2762 #else
2763     return false;
2764 #endif
2765 }
2766
2767 Eina_Bool ewk_view_user_agent_set(Evas_Object* ewkView, const char* userAgent)
2768 {
2769     EINA_SAFETY_ON_NULL_RETURN_VAL(userAgent, false);
2770
2771     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2772     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2773
2774     eina_stringshare_replace(&priv->userAgent, userAgent);
2775
2776     WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKStringCreateWithUTF8CString(userAgent));
2777     WKPageSetCustomUserAgent(toAPI(priv->pageClient->page()), userAgentString.get());
2778
2779     return true;
2780 }
2781
2782 const char* ewk_view_user_agent_get(const Evas_Object* ewkView)
2783 {
2784     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2785     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
2786
2787     if (!priv->userAgent) {
2788         WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKPageCopyUserAgent(toAPI(priv->pageClient->page())));
2789
2790         int length = WKStringGetMaximumUTF8CStringSize(userAgentString.get());
2791         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
2792         WKStringGetUTF8CString(userAgentString.get(), buffer.get(), length);
2793         eina_stringshare_replace(&priv->userAgent, buffer.get());
2794     }
2795
2796     return priv->userAgent;
2797 }
2798 Eina_Bool ewk_view_custom_header_add(const Evas_Object* ewkView, const char* name, const char* value)
2799 {
2800 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2801     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2802     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2803
2804     WKRetainPtr<WKStringRef> customHeaderName(AdoptWK, WKStringCreateWithUTF8CString(name));
2805     WKRetainPtr<WKStringRef> customHeaderValue(AdoptWK, WKStringCreateWithUTF8CString(value));
2806
2807     WKPageAddCustomHeader(toAPI(priv->pageClient->page()), customHeaderName.get(), customHeaderValue.get());
2808     return true;
2809 #else
2810     ERR("TIZEN_CUSTOM_HEADERS not enabled!");
2811     return false;
2812 #endif
2813 }
2814
2815 const char* ewk_view_video_data_url_get(const Ewk_View_Html5_Video_Data* videoData)
2816 {
2817 #if ENABLE(TIZEN_MM_PLAYER)
2818     if (!videoData || !videoData->url)
2819         return "";
2820
2821     return toImpl(videoData->url)->string().utf8().data();
2822 #else
2823     return "";
2824 #endif
2825 }
2826
2827 const char* ewk_view_video_data_cookie_get(const Ewk_View_Html5_Video_Data* videoData)
2828 {
2829 #if ENABLE(TIZEN_MM_PLAYER)
2830     if (!videoData || videoData->cookie)
2831         return "";
2832
2833     return toImpl(videoData->cookie)->string().utf8().data();
2834 #else
2835     return "";
2836 #endif
2837 }
2838
2839 #if ENABLE(TIZEN_WEBKIT2_VIEW_VISIBILITY)
2840 Eina_Bool ewk_view_visibility_set(Evas_Object* ewkView, Eina_Bool enable)
2841 {
2842     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2843     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2844
2845     priv->pageClient->setIsVisible(enable);
2846     return true;
2847 }
2848 #endif
2849
2850 Evas_Object* ewk_view_screenshot_contents_get(const Evas_Object* ewkView, Eina_Rectangle viewArea, float scaleFactor, Evas* canvas)
2851 {
2852     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
2853
2854     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2855     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
2856
2857     WKRect rect;
2858     rect.origin.x = viewArea.x;
2859     rect.origin.y = viewArea.y;
2860     rect.size.width = viewArea.w;
2861     rect.size.height = viewArea.h;
2862
2863     WKRetainPtr<WKImageRef> snapshot(AdoptWK, WKPageCreateSnapshot(toAPI(priv->pageClient->page()), rect, scaleFactor));
2864     if (!snapshot.get())
2865         return 0;
2866
2867     RefPtr<cairo_surface_t> screenshotSurface = adoptRef(WKImageCreateCairoSurface(snapshot.get()));
2868
2869     Evas_Object* screenshotImage = evas_object_image_add(canvas);
2870     int surfaceWidth = cairo_image_surface_get_width(screenshotSurface.get());
2871     int surfaceHeight = cairo_image_surface_get_height(screenshotSurface.get());
2872     evas_object_image_size_set(screenshotImage, surfaceWidth, surfaceHeight);
2873     evas_object_image_colorspace_set(screenshotImage, EVAS_COLORSPACE_ARGB8888);
2874
2875     uint8_t* pixels = static_cast<uint8_t*>(evas_object_image_data_get(screenshotImage, true));
2876
2877     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)));
2878     RefPtr<cairo_t> cairo = adoptRef(cairo_create(imageSurface.get()));
2879
2880     cairo_set_source_surface(cairo.get(), screenshotSurface.get(), 0, 0);
2881     cairo_rectangle(cairo.get(), 0, 0, surfaceWidth, surfaceHeight);
2882     cairo_fill(cairo.get());
2883
2884     evas_object_image_smooth_scale_set(screenshotImage, true);
2885     evas_object_size_hint_min_set(screenshotImage, surfaceWidth, surfaceHeight);
2886     evas_object_resize(screenshotImage, surfaceWidth, surfaceHeight);
2887     evas_object_image_fill_set(screenshotImage, 0, 0, surfaceWidth, surfaceHeight);
2888     evas_object_image_data_set(screenshotImage, pixels);
2889
2890     return screenshotImage;
2891 }
2892
2893 unsigned int ewk_view_inspector_server_start(Evas_Object* ewkView, unsigned int port)
2894 {
2895 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
2896     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd, 0);
2897     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
2898
2899     return priv->pageClient->page()->startInspectorServer(port);
2900 #else
2901     LOG_ERROR("TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR is disabled.\n");
2902     return 0;
2903 #endif
2904 }
2905
2906 Eina_Bool ewk_view_inspector_server_stop(Evas_Object* ewkView)
2907 {
2908 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
2909     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd, false);
2910     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, false);
2911
2912     return priv->pageClient->page()->stopInspectorServer();
2913 #else
2914     LOG_ERROR("TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR is disabled.\n");
2915     return false;
2916 #endif
2917 }
2918
2919 void ewk_view_scroll_by(Evas_Object* ewkView, int deltaX, int deltaY)
2920 {
2921     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2922     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
2923
2924     WKPageScrollBy(toAPI(priv->pageClient->page()), toAPI(IntSize(deltaX, deltaY)));
2925 }
2926
2927 Eina_Bool ewk_view_scroll_pos_get(Evas_Object* ewkView, int* x, int* y)
2928 {
2929     if (x)
2930         *x = 0;
2931     if (y)
2932         *y = 0;
2933     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2934     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2935
2936     IntPoint scrollPosition = priv->pageClient->scrollPosition();
2937     if (x)
2938         *x = scrollPosition.x();
2939     if (y)
2940         *y = scrollPosition.y();
2941
2942     return true;
2943 }
2944
2945 Eina_Bool ewk_view_scroll_set(Evas_Object* ewkView, int x, int y)
2946 {
2947     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2948     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2949
2950     priv->pageClient->page()->scrollMainFrameTo(IntPoint(x, y));
2951     return true;
2952 }
2953
2954 Eina_Bool ewk_view_scroll_size_get(const Evas_Object* ewkView, int* width, int* height)
2955 {
2956     if (width)
2957         *width = 0;
2958     if (height)
2959         *height = 0;
2960     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2961     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2962
2963     IntSize contentsSize = priv->pageClient->page()->contentsSize();
2964 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2965     contentsSize.scale(priv->pageClient->scaleFactor());
2966 #endif
2967
2968     if (width && contentsSize.width() > smartData->view.w)
2969         *width = contentsSize.width() - smartData->view.w;
2970     if (height && contentsSize.height() > smartData->view.h)
2971         *height = contentsSize.height() - smartData->view.h;
2972     return true;
2973 }
2974
2975 bool ewkViewRunJavaScriptAlert(Evas_Object* ewkView, WKStringRef alertText)
2976 {
2977     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2978     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2979     if (!priv->alertContext || !priv->alertContext->javascriptAlertCallback)
2980         return false;
2981     EINA_SAFETY_ON_FALSE_RETURN_VAL(priv->alertContext->ewkView == ewkView, false);
2982
2983     int length = WKStringGetMaximumUTF8CStringSize(alertText);
2984     OwnArrayPtr<char> alertTextBuffer = adoptArrayPtr(new char[length]);
2985     WKStringGetUTF8CString(alertText, alertTextBuffer.get(), length);
2986     return priv->alertContext->javascriptAlertCallback(priv->alertContext->ewkView, alertTextBuffer.get(), priv->alertContext->userData) == EINA_TRUE;
2987 }
2988
2989 bool ewkViewRunJavaScriptConfirm(Evas_Object* ewkView, WKStringRef message)
2990 {
2991     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2992     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
2993     if (!priv->confirmContext || !priv->confirmContext->javascriptConfirmCallback)
2994         return false;
2995     EINA_SAFETY_ON_FALSE_RETURN_VAL(priv->confirmContext->ewkView == ewkView, false);
2996
2997     int length = WKStringGetMaximumUTF8CStringSize(message);
2998     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
2999     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3000     return priv->confirmContext->javascriptConfirmCallback(priv->confirmContext->ewkView, messageBuffer.get(), priv->confirmContext->userData) == EINA_TRUE;
3001 }
3002
3003 bool ewkViewRunJavaScriptPrompt(Evas_Object* ewkView, WKStringRef message, WKStringRef defaultValue)
3004 {
3005     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3006     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3007     if (!priv->promptContext || !priv->promptContext->javascriptPromptCallback)
3008         return false;
3009     EINA_SAFETY_ON_FALSE_RETURN_VAL(priv->promptContext->ewkView == ewkView, false);
3010
3011     int length = WKStringGetMaximumUTF8CStringSize(message);
3012     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
3013     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3014     length = WKStringGetMaximumUTF8CStringSize(defaultValue);
3015     OwnArrayPtr<char> defaultValueBuffer = adoptArrayPtr(new char[length]);
3016     WKStringGetUTF8CString(defaultValue, defaultValueBuffer.get(), length);
3017     return priv->promptContext->javascriptPromptCallback(priv->promptContext->ewkView, messageBuffer.get(), defaultValueBuffer.get(), priv->promptContext->userData) == EINA_TRUE;
3018 }
3019
3020 bool ewkViewRunOpenPanel(Evas_Object* ewkView, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener)
3021 {
3022     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3023     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3024     if (!priv->openpanelContext || !priv->openpanelContext->openPanelCallback)
3025         return false;
3026
3027     EINA_SAFETY_ON_FALSE_RETURN_VAL(priv->openpanelContext->ewkView == ewkView, false);
3028
3029     priv->openPanelListener = listener;
3030
3031     Eina_Bool allowMultipleFiles = WKOpenPanelParametersGetAllowsMultipleFiles(parameters) ? EINA_TRUE : EINA_FALSE;
3032     Eina_List* acceptedMimeTypes = 0;
3033     WKRetainPtr<WKArrayRef> array(AdoptWK, WKOpenPanelParametersCopyAcceptedMIMETypes(parameters));
3034     size_t len = WKArrayGetSize(array.get());
3035     for (size_t i = 0; i < len; i++) {
3036         WKTypeRef item = WKArrayGetItemAtIndex(array.get(), i);
3037         if (WKGetTypeID(item) != WKStringGetTypeID())
3038             continue;
3039         WKStringRef mime = static_cast<WKStringRef>(item);
3040         int length = WKStringGetMaximumUTF8CStringSize(mime);
3041         char* buffer = new char[length];
3042         WKStringGetUTF8CString(mime, buffer, length);
3043         acceptedMimeTypes = eina_list_append(acceptedMimeTypes, static_cast<const void*>(const_cast<const char*>(buffer)));
3044     }
3045     const char* capture = 0;
3046 #if ENABLE(MEDIA_CAPTURE)
3047     WKRetainPtr<WKStringRef> captureRef(AdoptWK, WKOpenPanelParametersCopyCapture(parameters));
3048     capture = eina_stringshare_add(toImpl(captureRef.get())->string().utf8().data());
3049 #endif
3050     bool result = priv->openpanelContext->openPanelCallback(priv->openpanelContext->ewkView, allowMultipleFiles, acceptedMimeTypes, capture, 0);
3051     if (!acceptedMimeTypes)
3052         return result;
3053
3054     Eina_List* list;
3055     void* data = 0;
3056     EINA_LIST_FOREACH(acceptedMimeTypes, list, data)
3057         delete[] (char*)data;
3058     eina_list_free(acceptedMimeTypes);
3059     return result;
3060 }
3061
3062 void ewk_view_javascript_alert_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Alert_Callback callback, void* userData)
3063 {
3064     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3065     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3066
3067     if (!priv->alertContext)
3068         priv->alertContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3069     priv->alertContext->javascriptAlertCallback = callback;
3070     priv->alertContext->ewkView = ewkView;
3071     priv->alertContext->userData = userData;
3072 }
3073
3074 void ewk_view_javascript_alert_reply(Evas_Object* ewkView)
3075 {
3076     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3077     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3078
3079     WKPageReplyJavaScriptAlert(toAPI(ewk_view_page_get(ewkView)));
3080 }
3081
3082 void ewk_view_javascript_confirm_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Confirm_Callback callback, void* userData)
3083 {
3084     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3085     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3086
3087     if (!priv->confirmContext)
3088         priv->confirmContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3089     priv->confirmContext->javascriptConfirmCallback = callback;
3090     priv->confirmContext->ewkView = ewkView;
3091     priv->confirmContext->userData = userData;
3092 }
3093
3094 void ewk_view_javascript_confirm_reply(Evas_Object* ewkView, Eina_Bool result)
3095 {
3096     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3097     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3098
3099     WKPageReplyJavaScriptConfirm(toAPI(ewk_view_page_get(ewkView)), result == EINA_TRUE);
3100 }
3101
3102 void ewk_view_javascript_prompt_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Prompt_Callback callback, void* userData)
3103 {
3104     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3105     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3106
3107     if (!priv->promptContext)
3108         priv->promptContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3109     priv->promptContext->javascriptPromptCallback = callback;
3110     priv->promptContext->ewkView = ewkView;
3111     priv->promptContext->userData = userData;
3112 }
3113
3114 void ewk_view_javascript_prompt_reply(Evas_Object* ewkView, const char* result)
3115 {
3116     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3117     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3118
3119     WKRetainPtr<WKStringRef> resultString(AdoptWK, WKStringCreateWithUTF8CString(result));
3120     WKPageReplyJavaScriptPrompt(toAPI(ewk_view_page_get(ewkView)), result ? resultString.get() : 0);
3121 }
3122
3123 void ewk_view_open_panel_callback_set(Evas_Object* ewkView, Ewk_View_Open_Panel_Callback callback, void* userData)
3124 {
3125     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3126     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3127
3128     if (!priv->openpanelContext)
3129         priv->openpanelContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3130
3131     priv->openpanelContext->openPanelCallback = callback;
3132     priv->openpanelContext->ewkView = ewkView;
3133     priv->openpanelContext->userData = userData;
3134 }
3135
3136 void ewk_view_open_panel_reply(Evas_Object* ewkView, Eina_List* fileUrls, Eina_Bool result)
3137 {
3138     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3139     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3140
3141     if (!priv->openPanelListener)
3142         return;
3143
3144     unsigned int size = eina_list_count(fileUrls);
3145     if ((result == EINA_FALSE) || (size == 0)) {
3146         WKOpenPanelResultListenerCancel(priv->openPanelListener);
3147         priv->openPanelListener = 0;
3148         return;
3149     }
3150
3151     WKTypeRef* items = new WKTypeRef[size];
3152     Eina_List* list;
3153     void* data;
3154     unsigned int i = 0;
3155     EINA_LIST_FOREACH(fileUrls, list, data)
3156         items[i++] = WKURLCreateWithUTF8CString((char*)data);
3157     WKRetainPtr<WKArrayRef> filesArray(AdoptWK, WKArrayCreate(items, size));
3158     WKOpenPanelResultListenerChooseFiles(priv->openPanelListener, filesArray.get());
3159     priv->openPanelListener = 0;
3160     delete [] items;
3161     eina_list_free(fileUrls);
3162 }
3163
3164 static void getRssItemsCallback(const Eina_List* rss_items, WKErrorRef, void* context)
3165 {
3166     EINA_SAFETY_ON_NULL_RETURN(context);
3167
3168     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3169
3170     ASSERT(callbackContext->rssItemsGetCallback);
3171     callbackContext->rssItemsGetCallback(callbackContext->ewkView, rss_items, callbackContext->userData);
3172
3173     delete callbackContext;
3174 }
3175
3176 Eina_Bool ewk_view_rss_items_get(Evas_Object* ewkView, Ewk_View_Rss_Items_Get_Callback callback, void* user_data)
3177 {
3178     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd, false);
3179     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, false);
3180     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3181
3182     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3183     context->rssItemsGetCallback = callback;
3184     context->ewkView = ewkView;
3185     context->userData = user_data;
3186
3187     WKPageGetRssItems(toAPI(priv->pageClient->page()), context, getRssItemsCallback);
3188
3189     return true;
3190 }
3191
3192 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3193 static void didGetWebAppCapable(WKBooleanRef capable, WKErrorRef, void* context)
3194 {
3195     EINA_SAFETY_ON_NULL_RETURN(capable);
3196     EINA_SAFETY_ON_NULL_RETURN(context);
3197
3198     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3199
3200     ASSERT(webAppContext->webAppCapableCallback);
3201
3202     if (capable)
3203         webAppContext->webAppCapableCallback(toImpl(capable)->value(), webAppContext->userData);
3204     else
3205         webAppContext->webAppCapableCallback(0, webAppContext->userData);
3206
3207     delete webAppContext;
3208 }
3209
3210 static void didGetWebAppIconURL(WKStringRef iconURL, WKErrorRef, void* context)
3211 {
3212     EINA_SAFETY_ON_NULL_RETURN(iconURL);
3213     EINA_SAFETY_ON_NULL_RETURN(context);
3214
3215     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3216
3217     EWK_VIEW_SD_GET_OR_RETURN(webAppContext->ewkView, smartData);
3218     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3219
3220     ASSERT(webAppContext->webAppIconURLCallback);
3221
3222     if (iconURL) {
3223         eina_stringshare_replace(&priv->webAppIconURL, toImpl(iconURL)->string().utf8().data());
3224         webAppContext->webAppIconURLCallback(priv->webAppIconURL, webAppContext->userData);
3225     } else
3226         webAppContext->webAppIconURLCallback(0, webAppContext->userData);
3227
3228     delete webAppContext;
3229 }
3230 #endif
3231
3232 Eina_Bool ewk_view_web_application_capable_get(Evas_Object* ewkView, Ewk_Web_App_Capable_Get_Callback callback, void* userData)
3233 {
3234 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3235     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3236     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3237     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
3238
3239     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3240     context->webAppCapableCallback = callback;
3241     context->ewkView = ewkView;
3242     context->userData = userData;
3243
3244     WKPageGetWebAppCapable(toAPI(priv->pageClient->page()), context, didGetWebAppCapable);
3245
3246     return true;
3247 #else
3248     return false;
3249 #endif
3250 }
3251
3252 Eina_Bool ewk_view_web_application_icon_url_get(Evas_Object* ewkView, Ewk_Web_App_Icon_URL_Get_Callback callback, void* userData)
3253 {
3254 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3255     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3256     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3257     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
3258
3259     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3260     context->webAppIconURLCallback = callback;
3261     context->ewkView = ewkView;
3262     context->userData = userData;
3263
3264     WKPageGetWebAppIconURL(toAPI(priv->pageClient->page()), context, didGetWebAppIconURL);
3265
3266     return true;
3267 #else
3268     return 0;
3269 #endif
3270 }
3271
3272 Eina_Bool ewk_view_command_execute(Evas_Object* ewkView, const char* command, const char* value)
3273 {
3274     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3275     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3276     EINA_SAFETY_ON_NULL_RETURN_VAL(command, false);
3277
3278     WKRetainPtr<WKStringRef> commandString(AdoptWK, WKStringCreateWithUTF8CString(command));
3279     WKRetainPtr<WKStringRef> valueString(AdoptWK, WKStringCreateWithUTF8CString(value));
3280     WKPageExecuteCommandWithArgument(toAPI(priv->pageClient->page()), commandString.get(), valueString.get());
3281
3282     return true;
3283 }
3284
3285 Eina_Bool ewk_view_string_find(Evas_Object* ewkView, const char* string, EwkFindOptions options, unsigned maxMatchCount, Ewk_View_String_Find_Callback callback, void* userData)
3286 {
3287     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3288     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3289
3290     EINA_SAFETY_ON_NULL_RETURN_VAL(string, false);
3291     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3292
3293     priv->findClientInfo.callback = callback;
3294     priv->findClientInfo.userData = userData;
3295
3296     WKRetainPtr<WKStringRef> findString(AdoptWK, WKStringCreateWithUTF8CString(string));
3297
3298     WKPageFindString(toAPI(priv->pageClient->page()), findString.get(), options, maxMatchCount);
3299
3300     return true;
3301 }
3302
3303 Eina_Bool ewk_view_contents_size_get(Evas_Object* ewkView, Evas_Coord* width, Evas_Coord* height)
3304 {
3305     if (width)
3306         *width = 0;
3307     if (height)
3308         *height = 0;
3309
3310     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3311     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3312
3313     IntSize contentsSize = priv->pageClient->page()->contentsSize();
3314
3315     if (width)
3316         *width = contentsSize.width();
3317     if (height)
3318         *height = contentsSize.height();
3319
3320     return true;
3321 }
3322
3323 Eina_Bool ewk_view_contents_pdf_get(Evas_Object* ewkView, const char* fileName)
3324 {
3325 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
3326     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3327     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3328     EINA_SAFETY_ON_NULL_RETURN_VAL(fileName, false);
3329
3330     IntSize contentsSize = priv->pageClient->page()->contentsSize();
3331     WKPageGetSnapshotPdfFile(toAPI(priv->pageClient->page()), toAPI(IntSize(contentsSize.width(), contentsSize.height())), WKStringCreateWithUTF8CString(fileName));
3332
3333     return true;
3334 #else
3335     return false;
3336 #endif
3337 }
3338
3339 static void runJavaScriptCallback(WKSerializedScriptValueRef scriptValue, WKErrorRef error, void* context)
3340 {
3341     EINA_SAFETY_ON_NULL_RETURN(context);
3342     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3343
3344     if (!callbackContext->scriptExecuteCallback) {
3345         delete callbackContext;
3346         return;
3347     }
3348
3349     JSGlobalContextRef jsGlobalContext = ewkViewGetJavascriptGlobalContext(callbackContext->ewkView);
3350
3351     if (scriptValue) {
3352         JSValueRef value = WKSerializedScriptValueDeserialize(scriptValue, jsGlobalContext, 0);
3353         JSRetainPtr<JSStringRef> jsStringValue(JSValueToStringCopy(jsGlobalContext, value, 0));
3354         size_t length = JSStringGetMaximumUTF8CStringSize(jsStringValue.get());
3355         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
3356         JSStringGetUTF8CString(jsStringValue.get(), buffer.get(), length);
3357         callbackContext->scriptExecuteCallback(callbackContext->ewkView, buffer.get(), callbackContext->userData);
3358     } else
3359         callbackContext->scriptExecuteCallback(callbackContext->ewkView, 0, callbackContext->userData);
3360
3361     delete callbackContext;
3362 }
3363
3364 Eina_Bool ewk_view_script_execute(Evas_Object* ewkView, const char* script, Ewk_View_Script_Execute_Callback callback, void* user_data)
3365 {
3366     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3367     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3368     EINA_SAFETY_ON_NULL_RETURN_VAL(script, false);
3369     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3370
3371     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3372     context->scriptExecuteCallback = callback;
3373     context->ewkView = ewkView;
3374     context->userData = user_data;
3375     WKRetainPtr<WKStringRef> scriptString(AdoptWK, WKStringCreateWithUTF8CString(script));
3376     WKPageRunJavaScriptInMainFrame(toAPI(priv->pageClient->page()), scriptString.get(), context, runJavaScriptCallback);
3377
3378     return true;
3379 }
3380
3381 void ewk_view_theme_set(Evas_Object* ewkView, const char* path)
3382 {
3383 #if ENABLE(TIZEN_WEBKIT2_THEME_SET)
3384     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3385     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3386     if (!eina_stringshare_replace(&priv->theme, path))
3387         return;
3388
3389     priv->pageClient->page()->setThemePath(path);
3390 #endif
3391 }
3392
3393 const char* ewk_view_theme_get(const Evas_Object* ewkView)
3394 {
3395 #if ENABLE(TIZEN_WEBKIT2_THEME_SET)
3396     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3397     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
3398     return priv->theme;
3399 #else
3400     return 0;
3401 #endif
3402 }
3403
3404 void ewkViewDidFindString(Evas_Object* ewkView, WKStringRef string, unsigned maxMatchCount)
3405 {
3406     EINA_SAFETY_ON_NULL_RETURN(string);
3407
3408     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3409     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3410
3411     int length = WKStringGetMaximumUTF8CStringSize(string);
3412     OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
3413     WKStringGetUTF8CString(string, buffer.get(), length);
3414
3415     if (priv->findClientInfo.callback)
3416         priv->findClientInfo.callback(ewkView, buffer.get(), maxMatchCount, priv->findClientInfo.userData);
3417 }
3418
3419 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
3420 static void didGetWebStorageQuota(WKUInt32Ref quota, WKErrorRef error, void* context)
3421 {
3422     Ewk_View_Callback_Context* storageContext = static_cast<Ewk_View_Callback_Context*>(context);
3423
3424     if (quota)
3425         storageContext->webStorageQuotaCallback(toImpl(quota)->value(), storageContext->userData);
3426     else
3427         storageContext->webStorageQuotaCallback(0, storageContext->userData);
3428
3429     delete storageContext;
3430 }
3431 #endif
3432
3433 Eina_Bool ewk_view_web_storage_quota_get(const Evas_Object* ewkView, Ewk_Web_Storage_Quota_Get_Callback resultCallback, void* userData)
3434 {
3435 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
3436     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, false);
3437     EINA_SAFETY_ON_NULL_RETURN_VAL(resultCallback, false);
3438
3439     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3440     context->webStorageQuotaCallback = resultCallback;
3441     context->userData = userData;
3442
3443     WKPageRef pageRef = toAPI(ewk_view_page_get(const_cast<Evas_Object*>(ewkView)));
3444     WKPageGetWebStorageQuota(pageRef, context, didGetWebStorageQuota);
3445
3446     return true;
3447 #else
3448     return false;
3449 #endif
3450 }
3451
3452 Eina_Bool ewk_view_web_storage_quota_set(Evas_Object* ewkView, uint32_t quota)
3453 {
3454 #if ENABLE(TIZEN_WEB_STORAGE)
3455     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, false);
3456
3457     WKPageRef pageRef = toAPI(ewk_view_page_get(const_cast<Evas_Object*>(ewkView)));
3458     WKPageSetWebStorageQuota(pageRef, quota);
3459
3460     return true;
3461 #else
3462     return false;
3463 #endif
3464 }
3465
3466 static void getContentsAsStringCallback(WKStringRef plain_text, WKErrorRef error, void* context)
3467 {
3468     EINA_SAFETY_ON_NULL_RETURN(context);
3469     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3470
3471     ASSERT(callbackContext->plainTextGetCallback);
3472
3473     if (plain_text) {
3474         size_t length = WKStringGetMaximumUTF8CStringSize(plain_text);
3475         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
3476         WKStringGetUTF8CString(plain_text, buffer.get(), length);
3477
3478         callbackContext->plainTextGetCallback(callbackContext->ewkView, buffer.get(), callbackContext->userData);
3479     } else
3480         callbackContext->plainTextGetCallback(callbackContext->ewkView, 0, callbackContext->userData);
3481
3482     delete callbackContext;
3483 }
3484
3485 Eina_Bool ewk_view_plain_text_get(Evas_Object* ewkView, Ewk_View_Plain_Text_Get_Callback callback, void* user_data)
3486 {
3487     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3488     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3489     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3490
3491     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3492     context->plainTextGetCallback = callback;
3493     context->ewkView = ewkView;
3494     context->userData = user_data;
3495     WKPageGetContentsAsString(toAPI(priv->pageClient->page()), context, getContentsAsStringCallback);
3496
3497     return true;
3498 }
3499
3500 Ewk_Hit_Test* ewk_view_hit_test_new(Evas_Object* ewkView, int x, int y, int hitTestMode)
3501 {
3502 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
3503     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3504     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
3505
3506     int viewPositionX;
3507     int viewPositionY;
3508
3509     evas_object_geometry_get(ewkView, &viewPositionX, &viewPositionY, 0, 0);
3510
3511     IntPoint pointForHitTest(x, y);
3512 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
3513     float revertScale = 1 / priv->pageClient->scaleFactor();
3514     IntPoint scrollPosition = priv->pageClient->scrollPosition();
3515
3516     pointForHitTest.setX((scrollPosition.x() + (x - viewPositionX)) * revertScale);
3517     pointForHitTest.setY((scrollPosition.y() + (y - viewPositionY)) * revertScale);
3518 #else
3519     pointForHitTest.setX(x - viewPositionX);
3520     pointForHitTest.setY(y - viewPositionY);
3521 #endif
3522
3523     WebHitTestResult::Data hitTestResultData = priv->pageClient->page()->hitTestResultAtPoint(pointForHitTest, hitTestMode);
3524     Ewk_Hit_Test* hitTest = ewkHitTestCreate(hitTestResultData);
3525
3526     return hitTest;
3527 #else
3528     return 0;
3529 #endif
3530 }
3531
3532 Ewk_History* ewk_view_history_get(Evas_Object* ewkView)
3533 {
3534     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, 0);
3535
3536     return ewkHistoryCreate(WKPageGetBackForwardList(toAPI(ewk_view_page_get(ewkView))));
3537 }
3538
3539 Eina_Bool ewk_view_recording_surface_enable_set(Evas_Object* ewkView, Eina_Bool enable)
3540 {
3541     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3542     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3543
3544     WKPageRecordingSurfaceSetEnable(toAPI(priv->pageClient->page()), enable);
3545
3546     return true;
3547 }
3548
3549 Eina_Bool ewk_view_notification_closed(Evas_Object* ewkView, Eina_List* ewkNotifications)
3550 {
3551 #if ENABLE(TIZEN_NOTIFICATION)
3552     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3553     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3554     EINA_SAFETY_ON_NULL_RETURN_VAL(priv->context, false);
3555
3556     if (!eina_list_count(ewkNotifications))
3557         return false;
3558
3559     Eina_List* listIterator = 0;
3560     void* data = 0;
3561     Vector<WKTypeRef> ids;
3562     EINA_LIST_FOREACH(ewkNotifications, listIterator, data) {
3563         Ewk_Notification* notification = static_cast<Ewk_Notification*>(data);
3564         WKUInt64Ref idRef = WKUInt64Create(ewk_notification_id_get(notification));
3565         ids.append(idRef);
3566         priv->notifications = eina_list_remove(priv->notifications, notification);
3567     }
3568
3569     WKRetainPtr<WKArrayRef> notificationIDsArray(AdoptWK, WKArrayCreate(ids.data(), ids.size()));
3570     WKNotificationManagerRef notificationManager = WKContextGetNotificationManager(ewk_context_WKContext_get(priv->context));
3571     WKNotificationManagerProviderDidCloseNotifications(notificationManager, notificationIDsArray.get());
3572     ewkNotificationDeleteNotificationList(ewkNotifications);
3573
3574     return true;
3575 #else
3576     return false;
3577 #endif
3578 }
3579
3580 #if ENABLE(TIZEN_WEBKIT2_POPUP)
3581 void ewk_view_popup_menu_request(Evas_Object* ewkView, WebPopupMenuProxyEfl* popupMenu, const IntRect& rect, TextDirection textDirection, double pageScaleFactor, const Vector<WebPopupItem>& items, int32_t selectedIndex)
3582 {
3583     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3584     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3585     EINA_SAFETY_ON_NULL_RETURN(smartData->api->popup_menu_show);
3586
3587     ASSERT(popupMenenu);
3588
3589     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3590     if (priv->popupMenuProxy)
3591         ewk_view_popup_menu_close(ewkView);
3592     priv->popupMenuProxy = popupMenu;
3593
3594     Eina_List* popupItems = 0;
3595     for (size_t i = 0; i < items.size(); ++i) {
3596         Ewk_Popup_Menu_Item* item = new Ewk_Popup_Menu_Item;
3597         if (items[i].m_type == WebPopupItem::Separator) {
3598             item->type = EWK_POPUP_MENU_SEPARATOR;
3599             item->text = 0;
3600         } else {
3601             item->type = EWK_POPUP_MENU_ITEM;
3602             item->text = eina_stringshare_add(items[i].m_text.utf8().data());
3603         }
3604
3605         popupItems = eina_list_append(popupItems, item);
3606     }
3607     priv->popupMenuItems = popupItems;
3608
3609     smartData->api->popup_menu_show(smartData, rect, static_cast<Ewk_Text_Direction>(textDirection), pageScaleFactor, popupItems, selectedIndex);
3610 }
3611
3612 Eina_Bool ewk_view_popup_menu_close(Evas_Object* ewkView)
3613 {
3614     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3615     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3616     EINA_SAFETY_ON_NULL_RETURN_VAL(priv->popupMenuProxy, false);
3617
3618     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api, false);
3619     if (smartData->api->popup_menu_hide)
3620         smartData->api->popup_menu_hide(smartData);
3621
3622     void* itemv;
3623     EINA_LIST_FREE(priv->popupMenuItems, itemv) {
3624         Ewk_Popup_Menu_Item* item = static_cast<Ewk_Popup_Menu_Item*>(itemv);
3625         eina_stringshare_del(item->text);
3626         delete item;
3627     }
3628
3629     priv->popupMenuProxy = 0;
3630 }
3631
3632 Eina_Bool ewk_view_popup_menu_select(Evas_Object* ewkView, unsigned int selectedIndex)
3633 {
3634     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3635     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3636     EINA_SAFETY_ON_NULL_RETURN_VAL(priv->popupMenuProxy, false);
3637
3638     if (selectedIndex > eina_list_count(priv->popupMenuItems))
3639         return false;
3640
3641     priv->popupMenuProxy->valueChanged(selectedIndex);
3642     return true;
3643 }
3644 #endif
3645
3646 void ewk_view_orientation_send(Evas_Object* ewkView, int orientation)
3647 {
3648 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
3649     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3650     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3651
3652     if (orientation != 0 && orientation != 90 && orientation != -90 && orientation != 180)
3653         return;
3654
3655     if (priv->orientation == orientation)
3656         return;
3657
3658     priv->orientation = orientation;
3659
3660     priv->pageClient->page()->sendOrientationChangeEvent(orientation);
3661 #endif
3662 }
3663
3664 void ewkViewFrameRendered(Evas_Object* ewkView)
3665 {
3666     evas_object_smart_callback_call(ewkView, "frame,rendered", 0);
3667 }
3668
3669 const char* ewk_view_encoding_custom_get(const Evas_Object* ewkView)
3670 {
3671     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3672     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
3673
3674     WKRetainPtr<WKStringRef> encodingString(AdoptWK, WKPageCopyCustomTextEncodingName(toAPI(priv->pageClient->page())));
3675     eina_stringshare_replace(&priv->encoding, toImpl(encodingString.get())->string().utf8().data());
3676
3677     return priv->encoding;
3678 }
3679
3680 void ewk_view_encoding_custom_set(Evas_Object* ewkView, const char* encoding)
3681 {
3682     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3683     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3684
3685     WKRetainPtr<WKStringRef> encodingString(AdoptWK, WKStringCreateWithUTF8CString(encoding));
3686     WKPageSetCustomTextEncodingName(toAPI(priv->pageClient->page()), encodingString.get());
3687 }
3688
3689 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3690 Eina_Bool ewk_view_text_selection_enable_set(Evas_Object* ewkView, Eina_Bool enable)
3691 {
3692     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3693     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3694
3695     priv->pageClient->setIsTextSelectionEnable(enable);
3696     return true;
3697 }
3698
3699 Eina_Bool ewk_view_text_selection_range_get(Evas_Object* ewkView, Eina_Rectangle* leftRect, Eina_Rectangle* rightRect)
3700 {
3701     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3702     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
3703
3704     EINA_SAFETY_ON_NULL_RETURN_VAL(priv->pageClient->page()->focusedFrame(), false);
3705
3706     IntRect leftSelectionRect;
3707     IntRect rightSelectionRect;
3708     if (!priv->pageClient->page()->focusedFrame()->getSelectionHandlers(leftSelectionRect, rightSelectionRect)) {
3709         leftRect->x = 0;
3710         leftRect->y = 0;
3711         leftRect->w = 0;
3712         leftRect->h = 0;
3713
3714         rightRect->x = 0;
3715         rightRect->y = 0;
3716         rightRect->w = 0;
3717         rightRect->h = 0;
3718         return false;
3719     }
3720
3721     int viewPositionX;
3722     int viewPositionY;
3723     evas_object_geometry_get(ewkView, &viewPositionX, &viewPositionY, 0, 0);
3724
3725 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
3726     float scaleFactor = priv->pageClient->scaleFactor();
3727     IntPoint scrollPosition = priv->pageClient->scrollPosition();
3728
3729     leftSelectionRect.scale(scaleFactor);
3730     leftSelectionRect.move(-scrollPosition.x(), -scrollPosition.y());
3731 #endif
3732     leftSelectionRect.move(viewPositionX, viewPositionY);
3733
3734 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
3735     rightSelectionRect.scale(scaleFactor);
3736     rightSelectionRect.move(-scrollPosition.x(), -scrollPosition.y());
3737 #endif
3738     rightSelectionRect.move(viewPositionX, viewPositionY);
3739
3740     leftRect->x = leftSelectionRect.x();
3741     leftRect->y = leftSelectionRect.y();
3742     leftRect->w = leftSelectionRect.width();
3743     leftRect->h = leftSelectionRect.height();
3744
3745     rightRect->x = rightSelectionRect.x();
3746     rightRect->y = rightSelectionRect.y();
3747     rightRect->w = rightSelectionRect.width();
3748     rightRect->h = rightSelectionRect.height();
3749
3750     return true;;
3751 }
3752
3753 const char* ewk_view_text_selection_text_get(Evas_Object* ewkView)
3754 {
3755     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3756     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
3757
3758     EINA_SAFETY_ON_NULL_RETURN_VAL(priv->pageClient->page()->focusedFrame(), 0);
3759
3760     const CString selectedString = priv->pageClient->page()->focusedFrame()->getSelectionText().utf8();
3761     eina_stringshare_replace(&priv->selectedText, selectedString.data());
3762
3763     return priv->selectedText;
3764 }
3765 #endif // #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3766
3767 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3768 void ewkViewInputPickerRequest(Evas_Object* ewkView, Ewk_Input_Type inputType, const String& inputValue)
3769 {
3770     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3771     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3772     EINA_SAFETY_ON_NULL_RETURN(smartData->api->input_picker_show);
3773
3774     smartData->api->input_picker_show(smartData, inputType, inputValue.utf8().data());
3775 }
3776
3777 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
3778 void ewkViewColorChooserRequest(Evas_Object* ewkView, WebColorChooserProxyEfl* colorChooser, const String& inputValue)
3779 {
3780     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3781     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3782
3783     priv->colorChooser = colorChooser;
3784
3785     ewkViewInputPickerRequest(ewkView, EWK_INPUT_TYPE_COLOR, inputValue);
3786 }
3787 #endif // ENABLE(TIZEN_INPUT_COLOR_PICKER)
3788 #endif
3789
3790 void ewk_view_focused_input_element_value_set(Evas_Object* ewkView, const char* value)
3791 {
3792 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3793     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3794     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3795
3796     priv->pageClient->page()->setFocusedInputElementValue(String(value));
3797 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3798 }
3799
3800 const char* ewk_view_focused_input_element_value_get(Evas_Object* ewkView)
3801 {
3802 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3803     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3804     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
3805
3806     eina_stringshare_replace(&priv->inputValue, priv->pageClient->page()->getFocusedInputElementValue().utf8().data());
3807     return priv->inputValue;
3808 #else
3809     return 0;
3810 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
3811 }
3812
3813 void ewk_view_color_chooser_color_set(Evas_Object* ewkView, const char* color)
3814 {
3815 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
3816     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3817     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3818
3819     if (priv->colorChooser)
3820         priv->colorChooser->setSelectedColor(Color(color));
3821 #endif // ENABLE(TIZEN_INPUT_COLOR_PICKER)
3822 }
3823
3824 void ewk_view_color_chooser_close(Evas_Object* ewkView)
3825 {
3826 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
3827     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3828     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3829
3830     if (priv->colorChooser)
3831         priv->colorChooser->endChooser();
3832
3833     priv->colorChooser = 0;
3834 #endif // ENABLE(TIZEN_INPUT_COLOR_PICKER)
3835 }
3836
3837 #if ENABLE(TIZEN_DATALIST_ELEMENT)
3838 void ewkViewDataListShowRequest(Evas_Object* ewkView, Ewk_Input_Type inputType, Vector<String> optionList)
3839 {
3840     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3841     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3842     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3843     EINA_SAFETY_ON_NULL_RETURN(smartData->api->data_list_show);
3844
3845     if (priv->dataList)
3846         ewkViewDataListHideRequest(ewkView, inputType);
3847
3848     for (Vector<String>::const_iterator it = optionList.begin(); it != optionList.end(); ++it) {
3849         String value = *it;
3850         priv->dataList = eina_list_append(priv->dataList, eina_stringshare_add(value.utf8().data()));
3851     }
3852
3853     smartData->api->data_list_show(smartData, inputType, priv->dataList);
3854 }
3855
3856 void ewkViewDataListHideRequest(Evas_Object* ewkView, Ewk_Input_Type inputType)
3857 {
3858     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3859     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3860     EINA_SAFETY_ON_NULL_RETURN(priv->dataList);
3861     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3862     EINA_SAFETY_ON_NULL_RETURN(smartData->api->data_list_hide);
3863
3864     _ewk_view_data_list_del(priv->dataList);
3865     priv->dataList = 0;
3866
3867     smartData->api->data_list_hide(smartData, inputType);
3868 }
3869 #endif
3870
3871 void ewk_view_data_list_close(Evas_Object* ewkView, const char* value)
3872 {
3873 #if ENABLE(TIZEN_DATALIST_ELEMENT)
3874     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3875     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
3876
3877     _ewk_view_data_list_del(priv->dataList);
3878     priv->dataList = 0;
3879
3880     ewk_view_focused_input_element_value_set(ewkView, value);
3881 #endif
3882 }
3883
3884 Eina_Bool ewk_view_horizontal_panning_hold_get(Evas_Object* ewkView)
3885 {
3886 #if ENABLE(TIZEN_GESTURE)
3887     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false)
3888     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
3889     return priv->holdHorizontalPanning;
3890 #else
3891     return false;
3892 #endif
3893 }
3894
3895 void ewk_view_horizontal_panning_hold_set(Evas_Object* ewkView, Eina_Bool hold)
3896 {
3897 #if ENABLE(TIZEN_GESTURE)
3898     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData)
3899     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv)
3900     priv->holdHorizontalPanning = hold;
3901 #endif
3902 }
3903
3904 Eina_Bool ewk_view_vertical_panning_hold_get(Evas_Object* ewkView)
3905 {
3906 #if ENABLE(TIZEN_GESTURE)
3907     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false)
3908     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false)
3909     return priv->holdVerticalPanning;
3910 #else
3911     return false;
3912 #endif
3913 }
3914
3915 void ewk_view_vertical_panning_hold_set(Evas_Object* ewkView, Eina_Bool hold)
3916 {
3917 #if ENABLE(TIZEN_GESTURE)
3918     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData)
3919     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv)
3920     priv->holdVerticalPanning = hold;
3921 #endif
3922 }
3923
3924 void ewk_view_touch_event_handler_result_set(Evas_Object* ewkView, WebKit::WebEvent::Type type, bool wasHandled)
3925 {
3926 #if ENABLE(TIZEN_GESTURE)
3927     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData)
3928     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv)
3929
3930 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
3931     if (wasHandled)
3932         ewkViewHideFocusRing(ewkView);
3933 #endif // #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
3934
3935     if (priv->areMouseEventsEnabled)
3936         return;
3937
3938     // We have to check TouchStart, TouchMove and TouchEnd with handled.
3939     // The Pan and Flick will be enabled if Touch Start was not handled,
3940     // and Touch Move was not handled or did not occur.
3941     // Tap will be enabled if Touch Start and End was not handled
3942     // and Touch Move did not occur.
3943     // The gestures are disabled as a default.
3944     // o: handled, x: not handled
3945     // ------------------------------------------------------------
3946     // Touch Start | Touch Move | Touch End ||   Tap   | Pan, Flick
3947     // ------------------------------------------------------------
3948     //      o      |   o or x   |   o or x  || disable |  disable
3949     //      x      |      o     |   o or x  || disable |  disable
3950     //      x      |      x     |   o or x  || disable |  enable
3951     //      x      |not occured |     x     || enable  |  enable
3952     // ------------------------------------------------------------
3953     if (type == WebEvent::TouchStart)
3954         priv->gestureRecognizer->setEnableGesture(!wasHandled);
3955     else if (type == WebEvent::TouchMove)
3956         priv->gestureRecognizer->setEnableMoving(!wasHandled);
3957     else if (type == WebEvent::TouchEnd && !priv->exceedTouchMoveThreshold && !wasHandled) {
3958         priv->gestureRecognizer->setEnableMoving(!wasHandled);
3959         priv->gestureRecognizer->setEnableTap(!wasHandled);
3960     }
3961 #endif
3962 }
3963
3964 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
3965 void  ewkViewDidGetTextStyleStateForSelection(Evas_Object* ewkView, int underlineState, int italicState, int boldState)
3966 {
3967     Ewk_Text_Style* textStyle = ewkTextStyleCreate(underlineState, italicState, boldState);
3968     evas_object_smart_callback_call(ewkView, "text,style,state", static_cast<void*>(textStyle));
3969     ewkTextStyleDelete(textStyle);
3970 }
3971 #endif
3972
3973 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
3974 bool ewk_view_orientation_lock(Evas_Object* ewkView, int willLockOrientation)
3975 {
3976     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3977     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api, false);
3978
3979     if (!smartData->api->orientation_lock)
3980         return false;
3981
3982     return smartData->api->orientation_lock(smartData, willLockOrientation);
3983 }
3984
3985 void ewk_view_orientation_unlock(Evas_Object* ewkView)
3986 {
3987     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3988     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3989
3990     if (!smartData->api->orientation_unlock)
3991         return;
3992
3993     smartData->api->orientation_unlock(smartData);
3994 }
3995 #endif
3996
3997 void ewk_view_orientation_lock_callback_set(Evas_Object* ewkView, Ewk_Orientation_Lock_Cb func, void* data)
3998 {
3999 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
4000     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4001     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
4002
4003     priv->orientationLock.callback = func;
4004     priv->orientationLock.data = data;
4005 #endif
4006 }
4007
4008 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
4009 Eina_Bool _ewk_orientation_lock(Ewk_View_Smart_Data *sd, int orientations)
4010 {
4011     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, false);
4012     if (priv->orientationLock.callback) {
4013         return priv->orientationLock.callback(sd->self, true, orientations, priv->orientationLock.data);
4014     }
4015     return false;
4016 }
4017
4018 void _ewk_orientation_unlock(Ewk_View_Smart_Data *sd)
4019 {
4020     EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
4021
4022     priv->orientationLock.callback(sd->self, false, 0, priv->orientationLock.data);
4023 }
4024 #endif
4025
4026 #endif // #if OS(TIZEN)