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