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