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