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