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