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