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