Fix for screen shift upward after showing ime
[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 "FindClientEfl.h"
26 #include "FormClientEfl.h"
27 #include "LayerTreeCoordinatorProxy.h"
28 #include "InputMethodContextEfl.h"
29 #include "NativeWebKeyboardEvent.h"
30 #include "NativeWebMouseEvent.h"
31 #include "NativeWebWheelEvent.h"
32 #include "PageClientImpl.h"
33 #include "PageLoadClientEfl.h"
34 #include "PagePolicyClientEfl.h"
35 #include "PageUIClientEfl.h"
36 #include "ResourceLoadClientEfl.h"
37 #include "WKAPICast.h"
38 #include "WKEinaSharedString.h"
39 #include "WKFindOptions.h"
40 #include "WKRetainPtr.h"
41 #include "WKString.h"
42 #include "WebContext.h"
43 #include "WebData.h"
44 #include "WebPageGroup.h"
45 #include "WebPopupItem.h"
46 #include "WebPopupMenuProxyEfl.h"
47 #include "WebPreferences.h"
48 #include "ewk_back_forward_list_private.h"
49 #include "ewk_context.h"
50 #include "ewk_context_private.h"
51 #include "ewk_favicon_database_private.h"
52 #include "ewk_intent_private.h"
53 #include "ewk_popup_menu_item_private.h"
54 #include "ewk_private.h"
55 #include "ewk_settings_private.h"
56 #include "ewk_view_private.h"
57 #include <Ecore_Evas.h>
58 #include <Ecore_X.h>
59 #include <WebKit2/WKPageGroup.h>
60 #include <wtf/text/CString.h>
61
62 #if ENABLE(FULLSCREEN_API)
63 #include "WebFullScreenManagerProxy.h"
64 #endif
65
66 #if ENABLE(TIZEN_WEBKIT2_DDK_CHECK)
67 namespace EGL {
68 #include <EGL/egl.h>
69 }
70 #endif
71
72 #if OS(TIZEN)
73 #include "DrawingAreaProxyImpl.h"
74 #include "WKArray.h"
75 #include "WKData.h"
76 #include "WKDownload.h"
77 #include "WKError.h"
78 #include "WKGeolocationPermissionRequest.h"
79 #include "WKImageCairo.h"
80 #include "WKOpenPanelParameters.h"
81 #include "WKOpenPanelResultListener.h"
82 #include "WKPage.h"
83 #include "WKPageGroup.h"
84 #include "WKView.h"
85 #include "WKPageTizen.h"
86 #include "WKPreferences.h"
87 #include "WKSerializedScriptValue.h"
88 #include "WKString.h"
89 #include "WKURLRequest.h"
90 #include "ewk_context_menu_private.h"
91 #include "ewk_error.h"
92 #include "ewk_error_private.h"
93 #include "ewk_history_private.h"
94 #include "ewk_popup_menu_item.h"
95 #include "ewk_popup_menu_item_private.h"
96 #include "ewk_view_context_menu_client.h"
97 #include "ewk_view_icondatabase_client.h"
98 #include "ewk_view_tizen_client.h"
99 #include <Ecore.h>
100 #include <Elementary.h>
101 #include <WebCore/EflScreenUtilities.h>
102 #include <WebCore/NotImplemented.h>
103 #include <cairo.h>
104
105 #if ENABLE(TIZEN_ICON_DATABASE)
106 #include "WKContextPrivate.h"
107 #endif
108
109 #if ENABLE(TIZEN_GEOLOCATION)
110 #include "ewk_geolocation_private.h"
111 #include "ewk_security_origin.h"
112 #include "ewk_view_geolocation_provider.h"
113 #endif
114
115 #if ENABLE(TOUCH_EVENTS)
116 #include "NativeWebTouchEvent.h"
117 #include "WebEvent.h"
118 #endif
119
120 #if ENABLE(TIZEN_ISF_PORT)
121 #include <Ecore_IMF.h>
122 #endif
123
124 #if ENABLE(TIZEN_NOTIFICATIONS)
125 #include "WKArray.h"
126 #include "WKNotificationManager.h"
127 #include "WKNumber.h"
128 #include "ewk_notification_private.h"
129 #include "ewk_view_notification_provider.h"
130 #endif
131
132 #if ENABLE(TIZEN_MEDIA_STREAM)
133 #include "WKUserMediaPermissionRequest.h"
134 #include "ewk_user_media_private.h"
135 #endif
136
137 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
138 #include "WebPageGroup.h"
139 #include "WebPreferences.h"
140 #endif
141
142 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
143 #include "ewk_hit_test_private.h"
144 #endif
145
146 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
147 #include "ewk_text_style.h"
148 #endif
149
150 #if ENABLE(TIZEN_SCREEN_READER)
151 #include "ScreenReaderProxy.h"
152 #endif
153
154 #if ENABLE(TIZEN_CSP)
155 #include <WebCore/ContentSecurityPolicy.h>
156 #endif
157
158 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
159 #include "WKDictionary.h"
160 #include "ewk_web_application_icon_data_private.h"
161 #endif
162
163 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
164 #include "AutoFillPopup.h"
165 #endif
166 #endif // #if OS(TIZEN)
167
168 using namespace WebKit;
169 using namespace WebCore;
170
171 static const char EWK_VIEW_TYPE_STR[] = "EWK2_View";
172
173 #define EWK_VIEW_TYPE_CHECK(ewkView, result)                                   \
174     bool result = true;                                                        \
175     do {                                                                       \
176         if (!ewkView) {                                                        \
177             EINA_LOG_CRIT("null is not a ewk_view");                           \
178             result = false;                                                    \
179             break;                                                             \
180         }                                                                      \
181         const char* _tmp_otype = evas_object_type_get(ewkView);                \
182         const Evas_Smart* _tmp_s = evas_object_smart_smart_get(ewkView);       \
183         if (EINA_UNLIKELY(!_tmp_s)) {                                          \
184             EINA_LOG_CRIT                                                      \
185                 ("%p (%s) is not a smart object!",                             \
186                  ewkView, _tmp_otype ? _tmp_otype : "(null)");                 \
187             result = false;                                                    \
188             break;                                                             \
189         }                                                                      \
190         const Evas_Smart_Class* _tmp_sc = evas_smart_class_get(_tmp_s);        \
191         if (EINA_UNLIKELY(!_tmp_sc)) {                                         \
192             EINA_LOG_CRIT                                                      \
193                 ("%p (%s) is not a smart object!",                             \
194                  ewkView, _tmp_otype ? _tmp_otype : "(null)");                 \
195             result = false;                                                    \
196             break;                                                             \
197         }                                                                      \
198         else if (EINA_UNLIKELY(_tmp_sc->data != EWK_VIEW_TYPE_STR)) {               \
199             EINA_LOG_CRIT                                                      \
200                 ("%p (%s) is not of an ewk_view (need %p, got %p)!",           \
201                  ewkView, _tmp_otype ? _tmp_otype : "(null)",                  \
202                  EWK_VIEW_TYPE_STR, _tmp_sc->data);                            \
203             result = false;                                                    \
204         }                                                                      \
205     } while (0)
206
207 #define EWK_VIEW_SD_GET(ewkView, smartData)                                    \
208     EWK_VIEW_TYPE_CHECK(ewkView, _tmp_result);                                 \
209     Ewk_View_Smart_Data* smartData = 0;                                        \
210     if (_tmp_result)                                                           \
211         smartData = (Ewk_View_Smart_Data*)evas_object_smart_data_get(ewkView)
212
213 #define EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, ...)                     \
214     EWK_VIEW_SD_GET(ewkView, smartData);                                       \
215     do {                                                                       \
216         if (!smartData) {                                                      \
217             EINA_LOG_CRIT("no smart data for object %p (%s)",                  \
218                      ewkView, evas_object_type_get(ewkView));                  \
219             return __VA_ARGS__;                                                \
220         }                                                                      \
221     } while (0)
222
223 #if OS(TIZEN)
224 static Eina_Bool _ewk_view_default_javascript_alert(Evas_Object*, const char* alertText, void* userData);
225 static Eina_Bool _ewk_view_default_javascript_confirm(Evas_Object*, const char* message, void* userData);
226 static Eina_Bool _ewk_view_default_javascript_prompt(Evas_Object*, const char* message, const char* defaultValue, void* userData);
227 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
228 static Eina_Bool _ewk_view_default_before_unload_confirm_panel(Evas_Object*, const char* message, void* userData);
229 #endif
230 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);
231
232 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
233 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);
234 #if ENABLE(TIZEN_MULTIPLE_SELECT)
235 Eina_Bool _ewk_view_multiple_popup_menu_show(Ewk_View_Smart_Data*, Eina_Rectangle, Ewk_Text_Direction, double page_scale_factor, Eina_List* items);
236 #endif
237 Eina_Bool _ewk_view_popup_menu_hide(Ewk_View_Smart_Data*);
238 Eina_Bool _ewk_view_popup_menu_update(Ewk_View_Smart_Data*, Eina_Rectangle, Ewk_Text_Direction, Eina_List*, int);
239 #endif
240 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
241 Eina_Bool _ewk_orientation_lock(Ewk_View_Smart_Data *sd, int orientations);
242 void _ewk_orientation_unlock(Ewk_View_Smart_Data *sd);
243 #endif
244
245 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
246 static Eina_Bool _ewk_view_input_picker_show(Ewk_View_Smart_Data*, Ewk_Input_Type, const char* inputValue);
247 #endif
248
249 #if ENABLE(TIZEN_DATALIST_ELEMENT)
250 static Eina_Bool _ewk_view_data_list_show(Ewk_View_Smart_Data*, Ewk_Input_Type, Eina_List*);
251 static Eina_Bool _ewk_view_data_list_hide(Ewk_View_Smart_Data*, Ewk_Input_Type);
252 #endif
253
254 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
255 static Eina_Bool _ewk_input_picker_color_request(Ewk_View_Smart_Data*, int, int, int, int);
256 static Eina_Bool _ewk_input_picker_color_dismiss(Ewk_View_Smart_Data*);
257 #endif
258 #endif // #if OS(TIZEN)
259
260 static void _ewk_view_smart_changed(Ewk_View_Smart_Data* smartData)
261 {
262     if (smartData->changed.any)
263         return;
264     smartData->changed.any = true;
265     evas_object_smart_changed(smartData->self);
266 }
267
268 #if !ENABLE(TIZEN_ICON_DATABASE)
269 static void _ewk_view_on_favicon_changed(const char* pageURL, void* eventInfo)
270 {
271     Evas_Object* ewkView = static_cast<Evas_Object*>(eventInfo);
272     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
273     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
274
275     const char* viewURL = ewk_view_url_get(ewkView);
276     if (!viewURL || strcasecmp(viewURL, pageURL))
277         return;
278
279     impl->informIconChange();
280 }
281 #endif
282
283 // Default Event Handling.
284 static Eina_Bool _ewk_view_smart_focus_in(Ewk_View_Smart_Data* smartData)
285 {
286     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
287     TIZEN_LOGI("");
288
289 #if OS(TIZEN)
290     impl->pageClient->setViewFocused(true);
291 #endif // #if OS(TIZEN)
292     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
293 #if ENABLE(TIZEN_ISF_PORT)
294     if (impl->inputMethodContext())
295         impl->inputMethodContext()->onFocusIn();
296 #endif
297     return true;
298 }
299
300 static Eina_Bool _ewk_view_smart_focus_out(Ewk_View_Smart_Data* smartData)
301 {
302     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
303     TIZEN_LOGI("");
304
305 #if OS(TIZEN)
306 #if ENABLE(TIZEN_ISF_PORT)
307     // Keypad should be hidden rapidly when moving focus on elementary
308     // because Ecore-ime doesn't support it.
309     if (impl->inputMethodContext())
310         impl->inputMethodContext()->onFocusOut();
311 #endif
312
313 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
314     if (impl->pageClient->isTextSelectionMode() && ewk_settings_clear_text_selection_automatically_get(impl->settings()))
315         impl->pageClient->setIsTextSelectionMode(false);
316 #endif
317
318 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
319     if (impl->pageClient->isContextMenuVisible())
320         impl->pageProxy->hideContextMenu();
321 #endif
322
323 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
324     if (impl->pageClient->isClipboardWindowOpened())
325         impl->pageClient->closeClipboardWindow();
326 #endif
327
328 #if ENABLE(TIZEN_DRAG_SUPPORT)
329     if (impl->pageClient->isDragMode())
330         impl->pageClient->setDragMode(false);
331 #endif
332
333 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
334     if (smartData->api->formdata_candidate_is_showing(smartData))
335         smartData->api->formdata_candidate_hide(smartData);
336 #endif
337
338     impl->pageClient->setViewFocused(false);
339 #endif // #if OS(TIZEN)
340     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
341     return true;
342 }
343
344 static Eina_Bool _ewk_view_smart_mouse_wheel(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Wheel* wheelEvent)
345 {
346     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
347
348     impl->page()->handleWheelEvent(NativeWebWheelEvent(wheelEvent, impl->transformFromScene(), impl->transformToScreen()));
349     return true;
350 }
351
352 static Eina_Bool _ewk_view_smart_mouse_down(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Down* downEvent)
353 {
354     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
355
356     impl->page()->handleMouseEvent(NativeWebMouseEvent(downEvent, impl->transformFromScene(), impl->transformToScreen()));
357     return true;
358 }
359
360 static Eina_Bool _ewk_view_smart_mouse_up(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Up* upEvent)
361 {
362     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
363
364     impl->page()->handleMouseEvent(NativeWebMouseEvent(upEvent, impl->transformFromScene(), impl->transformToScreen()));
365
366     InputMethodContextEfl* inputMethodContext = impl->inputMethodContext();
367     if (inputMethodContext)
368         inputMethodContext->handleMouseUpEvent(upEvent);
369
370     return true;
371 }
372
373 static Eina_Bool _ewk_view_smart_mouse_move(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Move* moveEvent)
374 {
375     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
376
377     // FIXME: impl->page() is used in the webkit opensource, but tizen webkit does not use it yet.
378     impl->page()->handleMouseEvent(NativeWebMouseEvent(moveEvent, impl->transformFromScene(), impl->transformToScreen()));
379     return true;
380 }
381
382 static Eina_Bool _ewk_view_smart_key_down(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Down* downEvent)
383 {
384     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
385
386     bool isFiltered = false;
387     InputMethodContextEfl* inputMethodContext = impl->inputMethodContext();
388     if (inputMethodContext)
389         inputMethodContext->handleKeyDownEvent(downEvent, &isFiltered);
390
391     impl->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(downEvent, isFiltered));
392     return true;
393 }
394
395 static Eina_Bool _ewk_view_smart_key_up(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Up* upEvent)
396 {
397     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
398
399     impl->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(upEvent));
400     return true;
401 }
402
403 #if OS(TIZEN)
404 static Eina_Bool _ewk_view_smart_gesture_start(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
405 {
406 #if ENABLE(TIZEN_GESTURE)
407     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
408
409 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
410     if (impl->pageClient->isTextSelectionMode() && impl->pageClient->isTextSelectionHandleDowned())
411         return true;
412 #endif
413
414 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
415     FocusRing* focusRing = impl->focusRing();
416     if (focusRing) {
417         if (event->type == EWK_GESTURE_TAP && event->count == 1) {
418             focusRing->requestToShow(IntPoint(event->position.x, event->position.y));
419         } else if (event->type == EWK_GESTURE_PAN) {
420             if (impl->exceedTouchMoveThreshold)
421                 focusRing->requestToHide();
422         } else {
423             if (event->type != EWK_GESTURE_LONG_PRESS) {
424 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
425                 if (!impl->pageClient->isContextMenuVisible())
426 #endif
427                     focusRing->requestToHide();
428             }
429         }
430     }
431 #endif
432
433 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
434     if (smartData->api->formdata_candidate_is_showing(smartData))
435         smartData->api->formdata_candidate_hide(smartData);
436 #endif
437
438     switch (event->type) {
439     case EWK_GESTURE_TAP:
440         impl->gestureClient->startTap(IntPoint(event->position.x, event->position.y));
441         break;
442     case EWK_GESTURE_LONG_PRESS: {
443 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
444 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
445         if (ewk_settings_text_selection_enabled_get(impl->settings()))
446             impl->pageClient->setIsTextSelectionMode(false);
447 #endif
448
449         IntPoint scenePoint(event->position.x, event->position.y);
450         IntPoint contentsPoint = impl->transformFromScene().mapPoint(scenePoint);
451         WebHitTestResult::Data hitTestResultData = impl->pageProxy->hitTestResultAtPoint(contentsPoint, WebHitTestResult::HitTestModeDefault | WebHitTestResult::HitTestModeSetFocus);
452         if (!hitTestResultData.absoluteMediaURL.isEmpty())
453             break;
454
455 #if ENABLE(TIZEN_DRAG_SUPPORT)
456         // 1. Check to start dragging.
457         if (hitTestResultData.isDragSupport && !hitTestResultData.isContentEditable) {
458             impl->pageClient->setDragPoint(scenePoint);
459             if (impl->pageClient->isDragMode())
460                 impl->pageClient->setDragMode(false);
461
462 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
463             if (focusRing)
464                 focusRing->showWithContextMenu(scenePoint, hitTestResultData.focusedColor, hitTestResultData.focusedRects);
465 #endif
466             break;
467         }
468 #endif
469
470         // 2. Check to show context menu.
471         if ((!hitTestResultData.absoluteImageURL.isEmpty() || !hitTestResultData.absoluteLinkURL.isEmpty())
472             && !hitTestResultData.isContentEditable) {
473 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
474             if (focusRing)
475                 focusRing->showWithContextMenu(scenePoint, hitTestResultData.focusedColor, hitTestResultData.focusedRects);
476 #endif
477             break;
478         }
479
480 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
481         // 3. Check for text selection.
482         if (ewk_settings_text_selection_enabled_get(impl->settings())) {
483             // Process gesture_end(EWK_GESTURE_TAP) to activate the editing if node under point is editable.
484             if (hitTestResultData.context & WebHitTestResult::HitTestResultContextEditable) {
485                 if (smartData->api && smartData->api->gesture_end) {
486                     Ewk_Event_Gesture tapEvent = {EWK_GESTURE_TAP, event->position, {0, 0}, 0, 1, ecore_time_get() * 1000};
487                     smartData->api->gesture_end(smartData, &tapEvent);
488                 }
489             }
490
491             if (impl->pageClient->textSelectionDown(scenePoint)) {
492                 impl->gestureClient->setGestureEnabled(false);
493                 impl->feedTouchEventsByType(EWK_TOUCH_CANCEL);
494             }
495         }
496 #endif
497         break;
498 #endif // #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
499     }
500     case EWK_GESTURE_PAN:
501         impl->gestureClient->startPan(IntPoint(event->position.x, event->position.y));
502         break;
503     case EWK_GESTURE_FLICK:
504         impl->gestureClient->startFlick(IntPoint(event->position.x, event->position.y), IntPoint(event->velocity.x, event->velocity.y));
505         break;
506     case EWK_GESTURE_PINCH:
507         if (impl->pageClient->viewportConstraints().userScalable)
508             impl->gestureClient->startPinch(IntPoint(event->position.x, event->position.y), event->scale);
509         break;
510     default:
511         ASSERT_NOT_REACHED();
512         break;
513     }
514
515     return true;
516 #else
517     return false;
518 #endif // #if ENABLE(TIZEN_GESTURE)
519 }
520
521 static Eina_Bool _ewk_view_smart_gesture_end(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
522 {
523 #if ENABLE(TIZEN_GESTURE)
524     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
525
526 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
527     if (impl->pageClient->isTextSelectionMode() && impl->pageClient->isTextSelectionHandleDowned()) {
528         impl->pageClient->initTextSelectionHandlesMouseDownedStatus();
529         return true;
530     }
531 #endif
532
533 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
534     FocusRing* focusRing = impl->focusRing();
535     if (focusRing) {
536 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
537         if (!impl->pageClient->isContextMenuVisible() || impl->pageClient->isTextSelectionMode())
538 #endif
539             focusRing->requestToHide();
540     }
541 #endif
542
543     switch (event->type) {
544     case EWK_GESTURE_TAP:
545         if (event->count == 1) {
546 #if ENABLE(TIZEN_DRAG_SUPPORT)
547         if (impl->pageClient->isDragMode())
548             impl->pageClient->setDragMode(false);
549 #endif
550 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
551             if (impl->pageClient->isTextSelectionMode())
552                 impl->pageClient->setIsTextSelectionMode(false);
553 #endif
554
555 #if ENABLE(TIZEN_ISF_PORT)
556             if (impl->inputMethodContext()->isIMEPostion(event->position.x, event->position.y))
557                 return false;
558 #endif
559
560             impl->gestureClient->endTap(IntPoint(event->position.x, event->position.y));
561         } else if (event->count == 2) {
562 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
563             if (focusRing)
564                 focusRing->requestToHide(true);
565 #endif
566             impl->gestureClient->endDoubleTap(IntPoint(event->position.x, event->position.y));
567         }
568         break;
569     case EWK_GESTURE_LONG_PRESS:
570         // Prcess endTap for LONG_PRESS gesture if text-selection and context menu did not work
571         impl->gestureClient->endTap(IntPoint(event->position.x, event->position.y));
572         break;
573     case EWK_GESTURE_PAN:
574         impl->gestureClient->endPan(IntPoint(event->position.x, event->position.y));
575         break;
576     case EWK_GESTURE_FLICK:
577         impl->gestureClient->endFlick(IntPoint(event->position.x, event->position.y), IntPoint(event->velocity.x, event->velocity.y));
578         break;
579     case EWK_GESTURE_PINCH:
580         impl->gestureClient->endPinch(IntPoint(event->position.x, event->position.y), event->scale);
581         break;
582     default:
583         ASSERT_NOT_REACHED();
584         break;
585     }
586
587     return true;
588 #else
589     return false;
590 #endif // #if ENABLE(TIZEN_GESTURE)
591 }
592
593 static Eina_Bool _ewk_view_smart_gesture_move(Ewk_View_Smart_Data* smartData, const Ewk_Event_Gesture* event)
594 {
595 #if ENABLE(TIZEN_GESTURE)
596     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
597
598 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
599     if (impl->pageClient->isTextSelectionMode() && impl->pageClient->isTextSelectionHandleDowned())
600         return true;
601 #endif
602
603 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
604     FocusRing* focusRing = impl->focusRing();
605     if (focusRing && !(event->type == EWK_GESTURE_PAN && !impl->exceedTouchMoveThreshold)) {
606 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
607         if (!impl->pageClient->isContextMenuVisible())
608 #endif
609             focusRing->requestToHide(true);
610     }
611 #endif
612
613     switch (event->type) {
614     case EWK_GESTURE_PAN:
615         impl->gestureClient->movePan(IntPoint(event->position.x, event->position.y));
616         break;
617     case EWK_GESTURE_TAP:
618     case EWK_GESTURE_LONG_PRESS:
619     case EWK_GESTURE_FLICK:
620         break;
621     case EWK_GESTURE_PINCH:
622         if (impl->pageClient->viewportConstraints().userScalable)
623             impl->gestureClient->movePinch(IntPoint(event->position.x, event->position.y), event->scale);
624         break;
625     default:
626         ASSERT_NOT_REACHED();
627         break;
628     }
629
630     return true;
631 #else
632     return false;
633 #endif // #if ENABLE(TIZEN_GESTURE)
634 }
635 #endif //#if OS(TIZEN)
636
637 // Event Handling.
638 static void _ewk_view_on_focus_in(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
639 {
640     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
641     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
642     EINA_SAFETY_ON_NULL_RETURN(smartData->api->focus_in);
643     smartData->api->focus_in(smartData);
644 }
645
646 static void _ewk_view_on_focus_out(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
647 {
648     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
649     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
650     EINA_SAFETY_ON_NULL_RETURN(smartData->api->focus_out);
651     smartData->api->focus_out(smartData);
652 }
653
654 static void _ewk_view_on_mouse_wheel(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
655 {
656     Evas_Event_Mouse_Wheel* wheelEvent = static_cast<Evas_Event_Mouse_Wheel*>(eventInfo);
657     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
658     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
659     EINA_SAFETY_ON_NULL_RETURN(smartData->api->mouse_wheel);
660     smartData->api->mouse_wheel(smartData, wheelEvent);
661 }
662
663 static void _ewk_view_on_key_down(void* data, Evas*, Evas_Object*, void* eventInfo)
664 {
665     Evas_Event_Key_Down* downEvent = static_cast<Evas_Event_Key_Down*>(eventInfo);
666     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
667     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
668     EINA_SAFETY_ON_NULL_RETURN(smartData->api->key_down);
669     smartData->api->key_down(smartData, downEvent);
670 }
671
672 static void _ewk_view_on_key_up(void* data, Evas* canvas, Evas_Object* ewkView, void* eventInfo)
673 {
674     Evas_Event_Key_Up* upEvent = static_cast<Evas_Event_Key_Up*>(eventInfo);
675     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
676     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
677     EINA_SAFETY_ON_NULL_RETURN(smartData->api->key_up);
678     smartData->api->key_up(smartData, upEvent);
679 }
680
681 static void _ewk_view_on_show(void* data, Evas*, Evas_Object*, void* /*eventInfo*/)
682 {
683     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
684     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
685     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible);
686 }
687
688 static void _ewk_view_on_hide(void* data, Evas*, Evas_Object*, void* /*eventInfo*/)
689 {
690     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
691     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
692
693     // This call may look wrong, but we really need to pass ViewIsVisible here.
694     // viewStateDidChange() itself is responsible for actually setting the visibility to Visible or Hidden
695     // depending on what WebPageProxy::isViewVisible() returns, this simply triggers the process.
696     impl->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible);
697 }
698
699 #if OS(TIZEN)
700
701 #if ENABLE(TIZEN_FULLSCREEN_API)
702 Eina_Bool _ewk_view_smart_fullscreen_enter(Ewk_View_Smart_Data* smartData)
703 {
704     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
705
706     ewk_view_main_frame_scrollbar_visible_set(impl->view(), false);
707     evas_object_smart_callback_call(impl->view(), "fullscreen,enterfullscreen", 0);
708     return true;
709 }
710
711 Eina_Bool _ewk_view_smart_fullscreen_exit(Ewk_View_Smart_Data* smartData)
712 {
713     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
714
715     ewk_view_main_frame_scrollbar_visible_set(impl->view(), true);
716     evas_object_smart_callback_call(impl->view(), "fullscreen,exitfullscreen", 0);
717     return true;
718 }
719 #endif
720
721 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
722 Eina_Bool _ewk_view_text_selection_down(Ewk_View_Smart_Data* smartData, int x, int y)
723 {
724     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
725
726     return impl->pageClient->textSelectionDown(IntPoint(x, y));
727 }
728
729 Eina_Bool _ewk_view_text_selection_move(Ewk_View_Smart_Data* smartData, int x, int y)
730 {
731     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
732
733     IntPoint point(x, y);
734     impl->pageClient->textSelectionMove(point);
735
736     return true;
737 }
738
739 Eina_Bool _ewk_view_text_selection_up(Ewk_View_Smart_Data* smartData, int x, int y)
740 {
741     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
742
743     IntPoint point(x, y);
744     impl->pageClient->textSelectionUp(point, true);
745
746     return true;
747 }
748 #endif
749
750 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
751 Eina_Bool _ewk_view_smart_formdata_candidate_show(Ewk_View_Smart_Data* smartData, int x, int y, int w, int h)
752 {
753     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
754
755     impl->pageClient->showAutoFillPopup(IntRect(x, y, w, h));
756
757     return true;
758 }
759
760 Eina_Bool _ewk_view_smart_formdata_candidate_hide(Ewk_View_Smart_Data* smartData)
761 {
762     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
763
764     impl->pageClient->hideAutoFillPopup();
765
766     return true;
767 }
768
769 Eina_Bool _ewk_view_smart_formdata_candidate_update_data(Ewk_View_Smart_Data* smartData, Eina_List* dataList)
770 {
771     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
772
773     Vector<AutoFillPopupItem> formData;
774     Eina_List* list;
775     void* data;
776     EINA_LIST_FOREACH(dataList, list, data)
777         formData.append(AutoFillPopupItem(String::fromUTF8(static_cast<char*>(data)), candidateAutoFill));
778
779     impl->pageClient->updateAutoFillPopup(formData);
780
781     return true;
782 }
783
784 Eina_Bool _ewk_view_smart_formdata_candidate_is_showing(Ewk_View_Smart_Data* smartData)
785 {
786     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
787
788     return impl->pageClient->isShowingAutoFillPopup();
789 }
790 #endif
791
792 #if ENABLE(TIZEN_SCREEN_READER)
793 Eina_Bool _ewk_view_screen_reader_action_execute(Ewk_View_Smart_Data* smartData, void* actionInfo)
794 {
795     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
796
797     return ScreenReaderProxy::executeAction(impl, 0, static_cast<Elm_Access_Action_Info*>(actionInfo));
798 }
799 #endif
800 #endif // #if OS(TIZEN)
801
802 static Evas_Smart_Class g_parentSmartClass = EVAS_SMART_CLASS_INIT_NULL;
803
804 static void _ewk_view_impl_del(EwkViewImpl* impl)
805 {
806 #if !ENABLE(TIZEN_ICON_DATABASE)
807     /* Unregister icon change callback */
808     Ewk_Favicon_Database* iconDatabase = impl->context->faviconDatabase();
809     iconDatabase->unwatchChanges(_ewk_view_on_favicon_changed);
810 #endif
811
812     delete impl;
813 }
814
815 static void _ewk_view_smart_add(Evas_Object* ewkView)
816 {
817     const Evas_Smart* smart = evas_object_smart_smart_get(ewkView);
818     const Evas_Smart_Class* smartClass = evas_smart_class_get(smart);
819     const Ewk_View_Smart_Class* api = reinterpret_cast<const Ewk_View_Smart_Class*>(smartClass);
820     EWK_VIEW_SD_GET(ewkView, smartData);
821
822     if (!smartData) {
823         smartData = static_cast<Ewk_View_Smart_Data*>(calloc(1, sizeof(Ewk_View_Smart_Data)));
824         if (!smartData) {
825             EINA_LOG_CRIT("could not allocate Ewk_View_Smart_Data");
826             return;
827         }
828         evas_object_smart_data_set(ewkView, smartData);
829     }
830
831     smartData->self = ewkView;
832     smartData->api = api;
833
834     g_parentSmartClass.add(ewkView);
835
836     smartData->priv = new EwkViewImpl(ewkView);
837     if (!smartData->priv) {
838         EINA_LOG_CRIT("could not allocate EwkViewImpl");
839         evas_object_smart_data_set(ewkView, 0);
840         free(smartData);
841         return;
842     }
843
844     // Create evas_object_image to draw web contents.
845     smartData->image = evas_object_image_add(smartData->base.evas);
846     evas_object_image_alpha_set(smartData->image, false);
847     evas_object_image_filled_set(smartData->image, true);
848     evas_object_smart_member_add(smartData->image, ewkView);
849
850 #if OS(TIZEN)
851 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
852     Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
853     const char *engine = ecore_evas_engine_name_get(ee);
854     if (engine && !strcmp(engine, "opengl_x11"))
855         evas_object_image_content_hint_set(smartData->image, EVAS_IMAGE_CONTENT_HINT_DYNAMIC);
856 #endif
857     ewk_view_mouse_events_enabled_set(ewkView, false);
858     ewk_view_touch_events_enabled_set(ewkView, true);
859
860     // FIXME: This code should be removed if side effect occur.
861     // WebView does not have focus after url loading.
862     // If focus is set as true to webview,
863     // elementary steal webview's focus during mouse up event
864     // So, added code that events are not propagated to smart parent according to guide from EFL
865     evas_object_propagate_events_set(ewkView, false);
866 #endif // #if OS(TIZEN)
867
868 #define CONNECT(s, c) evas_object_event_callback_add(ewkView, s, c, smartData)
869     CONNECT(EVAS_CALLBACK_FOCUS_IN, _ewk_view_on_focus_in);
870     CONNECT(EVAS_CALLBACK_FOCUS_OUT, _ewk_view_on_focus_out);
871     CONNECT(EVAS_CALLBACK_MOUSE_WHEEL, _ewk_view_on_mouse_wheel);
872     CONNECT(EVAS_CALLBACK_KEY_DOWN, _ewk_view_on_key_down);
873     CONNECT(EVAS_CALLBACK_KEY_UP, _ewk_view_on_key_up);
874     CONNECT(EVAS_CALLBACK_SHOW, _ewk_view_on_show);
875     CONNECT(EVAS_CALLBACK_HIDE, _ewk_view_on_hide);
876 #undef CONNECT
877 }
878
879 static void _ewk_view_smart_del(Evas_Object* ewkView)
880 {
881     EwkViewImpl::removeFromPageViewMap(ewkView);
882     EWK_VIEW_SD_GET(ewkView, smartData);
883 #if ENABLE(TIZEN_SCREEN_READER)
884     ScreenReaderProxy::screenReader().finalize(smartData->priv);
885 #endif
886 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
887     // Close color picker if it's opened.
888     if (smartData && smartData->priv && smartData->priv->inputPicker->isColorPickerShown())
889         ewk_view_color_picker_color_set(ewkView, 0, 0, 0, 0);
890 #endif
891     if (smartData && smartData->priv)
892         _ewk_view_impl_del(smartData->priv);
893
894     g_parentSmartClass.del(ewkView);
895 }
896
897 static Eina_Bool _ewk_view_composite(void* data);
898
899 static void _ewk_view_smart_resize(Evas_Object* ewkView, Evas_Coord width, Evas_Coord height)
900 {
901     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
902
903     evas_object_resize(smartData->image, width, height);
904     evas_object_image_size_set(smartData->image, width, height);
905     evas_object_image_fill_set(smartData->image, 0, 0, width, height);
906 #if OS(TIZEN)
907     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
908 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
909     evas_object_image_native_surface_set(smartData->image, 0);
910
911 #if ENABLE(TIZEN_WEBKIT2_VIEW_VISIBILITY)
912     if (impl->pageClient->isVisible()) {
913         Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
914         impl->pageClient->updateViewportSize(IntSize(width, height), ecore_evas_rotation_get(ee));
915     } else
916         impl->pageClient->setDeferUpdateViewportSize(true);
917 #else
918     Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
919     impl->pageClient->updateViewportSize(IntSize(width, height), ecore_evas_rotation_get(ee));
920 #endif
921
922 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
923     if (!ewk_view_is_opengl_backend(ewkView))
924         _ewk_view_composite(smartData);
925     else // OpenGL backend
926 #endif
927     impl->pageClient->displayViewport();
928 #endif
929 #endif // #if OS(TIZEN)
930
931     smartData->changed.size = true;
932     _ewk_view_smart_changed(smartData);
933 }
934
935 static void _ewk_view_smart_move(Evas_Object* ewkView, Evas_Coord x, Evas_Coord y)
936 {
937     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
938
939     smartData->changed.position = true;
940     _ewk_view_smart_changed(smartData);
941 }
942
943 static void _ewk_view_smart_calculate(Evas_Object* ewkView)
944 {
945     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
946     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
947
948     Evas_Coord x, y, width, height;
949
950     smartData->changed.any = false;
951
952     evas_object_geometry_get(ewkView, &x, &y, &width, &height);
953
954     if (smartData->changed.size) {
955 #if !OS(TIZEN)
956 #if USE(COORDINATED_GRAPHICS)
957         impl->pageViewportControllerClient->updateViewportSize(IntSize(width, height));
958 #endif
959 #if USE(ACCELERATED_COMPOSITING)
960         needsNewSurface = impl->evasGlSurface;
961 #endif
962
963         if (impl->pageProxy->drawingArea())
964             impl->pageProxy->drawingArea()->setSize(IntSize(width, height), IntSize());
965
966 #if USE(ACCELERATED_COMPOSITING)
967         if (!impl->evasGlSurface)
968             return;
969         evas_gl_surface_destroy(impl->evasGl, impl->evasGlSurface);
970         impl->evasGlSurface = 0;
971         ewk_view_create_gl_surface(ewkView, IntSize(width, height));
972         ewk_view_display(ewkView, IntRect(IntPoint(), IntSize(width, height)));
973 #endif
974 #endif // #if !OS(TIZEN)
975
976         smartData->view.w = width;
977         smartData->view.h = height;
978         smartData->changed.size = false;
979
980 #if OS(TIZEN)
981         if (impl->pageClient) {
982             if (DrawingAreaProxy* drawingArea = impl->pageProxy->drawingArea()) {
983 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
984                 if (impl->pageProxy->isViewVisible())
985                     drawingArea->setSize(IntSize(width, height), IntSize());
986 #else
987                 drawingArea->setSize(IntSize(width, height), IntSize());
988 #endif
989 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE) && !ENABLE(TIZEN_WEBKIT2_EFL_WTR)
990                 Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
991                 int newAngle = ecore_evas_rotation_get(ee);
992 #if ENABLE(TIZEN_WEBKIT2_VIEW_VISIBILITY)
993                 if (impl->pageClient->deferUpdateViewportSize()) {
994                     impl->pageClient->updateViewportSize(IntSize(width, height), newAngle);
995                 }
996 #endif
997                 impl->pageClient->updateVisibleContentRectSize(IntSize(width, height));
998                 if (ewk_view_is_opengl_backend(ewkView))
999                     impl->pageClient->displayViewport();
1000 #endif
1001             }
1002 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
1003             impl->pageClient->frameRectChanged();
1004 #endif
1005         }
1006 #endif // #if OS(TIZEN)
1007     }
1008
1009     if (smartData->changed.position) {
1010 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1011         IntSize diff(x - smartData->view.x, y - smartData->view.y);
1012 #endif
1013
1014         evas_object_move(smartData->image, x, y);
1015         smartData->view.x = x;
1016         smartData->view.y = y;
1017         smartData->changed.position = false;
1018 #if OS(TIZEN)
1019 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
1020         impl->pageClient->frameRectChanged();
1021 #endif
1022 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1023         impl->pageClient->updateTextSelectionHandlesAndContextMenu(true);
1024 #endif
1025 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1026         if (impl->focusRing())
1027             impl->focusRing()->moveBy(diff);
1028 #endif
1029 #endif // #if OS(TIZEN)
1030     }
1031 #if OS(TIZEN)
1032     if (impl->popupPicker)
1033         ewk_popup_picker_resize(impl->popupPicker);
1034 #endif // #if OS(TIZEN)
1035 }
1036
1037 static void _ewk_view_smart_show(Evas_Object* ewkView)
1038 {
1039     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1040     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1041
1042     if (evas_object_clipees_get(smartData->base.clipper))
1043         evas_object_show(smartData->base.clipper);
1044     evas_object_show(smartData->image);
1045
1046 #if ENABLE(TIZEN_SCREEN_READER)
1047     ScreenReaderProxy::screenReader().initialize(impl);
1048 #endif
1049 }
1050
1051 static void _ewk_view_smart_hide(Evas_Object* ewkView)
1052 {
1053     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1054
1055     evas_object_hide(smartData->base.clipper);
1056     evas_object_hide(smartData->image);
1057 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1058     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1059     if (impl->pageClient->isTextSelectionMode())
1060         impl->pageClient->setIsTextSelectionMode(false);
1061 #endif
1062 }
1063
1064 static void _ewk_view_smart_color_set(Evas_Object* ewkView, int red, int green, int blue, int alpha)
1065 {
1066     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1067     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1068
1069     if (alpha < 0)
1070         alpha = 0;
1071     else if (alpha > 255)
1072         alpha = 255;
1073
1074 #define CHECK_COLOR(color, alpha) \
1075     if (color < 0)                \
1076         color = 0;                \
1077     else if (color > alpha)       \
1078         color = alpha;
1079     CHECK_COLOR(red, alpha);
1080     CHECK_COLOR(green, alpha);
1081     CHECK_COLOR(blue, alpha);
1082 #undef CHECK_COLOR
1083
1084     evas_object_image_alpha_set(smartData->image, alpha < 255);
1085     impl->pageProxy->setDrawsBackground(red || green || blue);
1086     impl->pageProxy->setDrawsTransparentBackground(alpha < 255);
1087     impl->pageClient->setBackgroundColor(red/255.0, green/255.0, blue/255.0, alpha/255.0);
1088
1089 #if !OS(TIZEN)
1090     g_parentSmartClass.color_set(ewkView, red, green, blue, alpha);
1091 #endif
1092 }
1093
1094 Eina_Bool ewk_view_smart_class_set(Ewk_View_Smart_Class* api)
1095 {
1096     EINA_SAFETY_ON_NULL_RETURN_VAL(api, false);
1097
1098     if (api->version != EWK_VIEW_SMART_CLASS_VERSION) {
1099         EINA_LOG_CRIT("Ewk_View_Smart_Class %p is version %lu while %lu was expected.",
1100              api, api->version, EWK_VIEW_SMART_CLASS_VERSION);
1101         return false;
1102     }
1103
1104     if (EINA_UNLIKELY(!g_parentSmartClass.add))
1105         evas_object_smart_clipped_smart_set(&g_parentSmartClass);
1106
1107     evas_object_smart_clipped_smart_set(&api->sc);
1108
1109     // Set Evas_Smart_Class functions.
1110     api->sc.add = _ewk_view_smart_add;
1111     api->sc.del = _ewk_view_smart_del;
1112     api->sc.move = _ewk_view_smart_move;
1113     api->sc.resize = _ewk_view_smart_resize;
1114     api->sc.show = _ewk_view_smart_show;
1115     api->sc.hide = _ewk_view_smart_hide;
1116     api->sc.color_set = _ewk_view_smart_color_set;
1117     api->sc.calculate = _ewk_view_smart_calculate;
1118     api->sc.data = EWK_VIEW_TYPE_STR; // It is used by type checking.
1119
1120     // Set Ewk_View_Smart_Class functions.
1121     api->focus_in = _ewk_view_smart_focus_in;
1122     api->focus_out = _ewk_view_smart_focus_out;
1123     api->mouse_wheel = _ewk_view_smart_mouse_wheel;
1124     api->mouse_down = _ewk_view_smart_mouse_down;
1125     api->mouse_up = _ewk_view_smart_mouse_up;
1126     api->mouse_move = _ewk_view_smart_mouse_move;
1127     api->key_down = _ewk_view_smart_key_down;
1128     api->key_up = _ewk_view_smart_key_up;
1129 #if OS(TIZEN)
1130     api->gesture_start = _ewk_view_smart_gesture_start;
1131     api->gesture_end = _ewk_view_smart_gesture_end;
1132     api->gesture_move = _ewk_view_smart_gesture_move;
1133
1134 #if ENABLE(TIZEN_FULLSCREEN_API)
1135     api->fullscreen_enter = _ewk_view_smart_fullscreen_enter;
1136     api->fullscreen_exit = _ewk_view_smart_fullscreen_exit;
1137 #endif
1138
1139 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1140     api->popup_menu_show = _ewk_view_popup_menu_show;
1141 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1142     api->multiple_popup_menu_show = _ewk_view_multiple_popup_menu_show;
1143 #endif
1144     api->popup_menu_hide = _ewk_view_popup_menu_hide;
1145     api->popup_menu_update = _ewk_view_popup_menu_update;
1146 #endif
1147 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1148     api->text_selection_down = _ewk_view_text_selection_down;
1149     api->text_selection_move = _ewk_view_text_selection_move;
1150     api->text_selection_up = _ewk_view_text_selection_up;
1151 #endif
1152 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1153     api->input_picker_show = _ewk_view_input_picker_show;
1154 #endif
1155 #if ENABLE(TIZEN_DATALIST_ELEMENT)
1156     api->data_list_show = _ewk_view_data_list_show;
1157     api->data_list_hide = _ewk_view_data_list_hide;
1158 #endif
1159 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
1160     api->orientation_lock = _ewk_orientation_lock;
1161     api->orientation_unlock = _ewk_orientation_unlock;
1162 #endif
1163 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
1164     api->input_picker_color_request = _ewk_input_picker_color_request;
1165     api->input_picker_color_dismiss = _ewk_input_picker_color_dismiss;
1166 #endif
1167 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1168     api->formdata_candidate_show = _ewk_view_smart_formdata_candidate_show;
1169     api->formdata_candidate_hide = _ewk_view_smart_formdata_candidate_hide;
1170     api->formdata_candidate_update_data = _ewk_view_smart_formdata_candidate_update_data;
1171     api->formdata_candidate_is_showing = _ewk_view_smart_formdata_candidate_is_showing;
1172 #endif
1173 #if ENABLE(TIZEN_SCREEN_READER)
1174     api->screen_reader_action_execute = _ewk_view_screen_reader_action_execute;
1175 #endif
1176 #endif //#if OS(TIZEN)
1177
1178     return true;
1179 }
1180
1181 static inline Evas_Smart* _ewk_view_smart_class_new(void)
1182 {
1183     static Ewk_View_Smart_Class api = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("Ewk_View");
1184     static Evas_Smart* smart = 0;
1185
1186     if (EINA_UNLIKELY(!smart)) {
1187         ewk_view_smart_class_set(&api);
1188         smart = evas_smart_class_new(&api.sc);
1189     }
1190
1191     return smart;
1192 }
1193
1194 static void _ewk_view_initialize(Evas_Object* ewkView, PassRefPtr<Ewk_Context> context, WKPageGroupRef pageGroupRef)
1195 {
1196     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1197     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1198     EINA_SAFETY_ON_NULL_RETURN(context);
1199
1200     if (impl->pageClient)
1201         return;
1202
1203 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
1204     bool isOpenGL = ewk_view_is_opengl_backend(ewkView);
1205     if (isOpenGL)
1206         impl->pageClient = PageClientEvasGL::create(impl);
1207     else
1208         impl->pageClient = PageClientImpl::create(impl);
1209 #else
1210     impl->pageClient = PageClientImpl::create(impl);
1211 #endif
1212
1213     if (pageGroupRef)
1214         impl->pageProxy = toImpl(context->wkContext())->createWebPage(impl->pageClient.get(), toImpl(pageGroupRef));
1215     else
1216         impl->pageProxy = toImpl(context->wkContext())->createWebPage(impl->pageClient.get(), WebPageGroup::create().get());
1217
1218     EwkViewImpl::addToPageViewMap(ewkView);
1219
1220 #if OS(TIZEN)
1221     impl->pageProxy->pageGroup()->preferences()->setAcceleratedCompositingEnabled(true);
1222     impl->pageProxy->pageGroup()->preferences()->setForceCompositingMode(true);
1223     impl->pageProxy->pageGroup()->preferences()->setFrameFlatteningEnabled(true);
1224     impl->pageProxy->pageGroup()->preferences()->setAllowUniversalAccessFromFileURLs(true);
1225 #endif
1226
1227     impl->pageProxy->initializeWebPage();
1228
1229 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
1230     impl->pageProxy->setCustomDeviceScaleFactor((float)getMobileDPI() / 160);
1231 #else
1232     impl->pageProxy->setCustomDeviceScaleFactor((float)getDPI() / 160);
1233 #endif
1234
1235 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE) && !ENABLE(TIZEN_WEBKIT2_EFL_WTR)
1236     impl->pageProxy->setUseFixedLayout(true);
1237 #endif
1238 #if ENABLE(FULLSCREEN_API)
1239     impl->pageProxy->fullScreenManager()->setWebView(ewkView);
1240 #endif
1241
1242 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
1243     if (isOpenGL)
1244         impl->pageProxy->drawingArea()->layerTreeCoordinatorProxy()->initializeAcceleratedCompositingMode(true);
1245     else {
1246         impl->pageProxy->pageGroup()->preferences()->setAcceleratedCompositingEnabled(false);
1247         impl->pageProxy->pageGroup()->preferences()->setWebGLEnabled(false);
1248         impl->pageProxy->drawingArea()->layerTreeCoordinatorProxy()->initializeAcceleratedCompositingMode(false);
1249     }
1250 #endif
1251
1252     impl->backForwardList = Ewk_Back_Forward_List::create(toAPI(impl->pageProxy->backForwardList()));
1253
1254     impl->context = context;
1255
1256 #if OS(TIZEN)
1257     ewkViewContextMenuClientAttachClient(ewkView);
1258     ewkViewTizenClientAttachClient(ewkView);
1259
1260 #if ENABLE(TIZEN_GEOLOCATION)
1261     ewkViewGeolocationProviderAttachProvider(ewkView, impl->context->wkContext());
1262 #endif
1263
1264 #if ENABLE(TIZEN_NOTIFICATIONS)
1265     ewkViewNotificationProviderAttachProvider(ewkView, impl->context->wkContext());
1266 #endif
1267
1268 #if ENABLE(TIZEN_ICON_DATABASE)
1269     ewk_view_icondatabase_client_attach(ewkView, impl->context->wkContext());
1270 #endif
1271
1272     ewk_view_javascript_alert_callback_set(ewkView, _ewk_view_default_javascript_alert, 0);
1273     ewk_view_javascript_confirm_callback_set(ewkView, _ewk_view_default_javascript_confirm, 0);
1274     ewk_view_javascript_prompt_callback_set(ewkView, _ewk_view_default_javascript_prompt, 0);
1275 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
1276     ewk_view_before_unload_confirm_panel_callback_set(ewkView, _ewk_view_default_before_unload_confirm_panel, 0);
1277 #endif
1278     ewk_view_open_panel_callback_set(ewkView, _ewk_view_default_open_panel, 0);
1279 #else // #if OS(TIZEN)
1280 #if USE(COORDINATED_GRAPHICS)
1281     impl->viewportHandler = EflViewportHandler::create(impl->pageClient.get());
1282 #endif
1283 #endif // #if OS(TIZEN)
1284
1285 #if ENABLE(FULLSCREEN_API)
1286     impl->pageProxy->fullScreenManager()->setWebView(ewkView);
1287     impl->pageProxy->pageGroup()->preferences()->setFullScreenEnabled(true);
1288 #endif
1289
1290     // Initialize page clients.
1291     impl->pageLoadClient = PageLoadClientEfl::create(impl);
1292     impl->pagePolicyClient = PagePolicyClientEfl::create(impl);
1293     impl->pageUIClient = PageUIClientEfl::create(impl);
1294     impl->resourceLoadClient = ResourceLoadClientEfl::create(impl);
1295     impl->findClient = FindClientEfl::create(impl);
1296     impl->formClient = FormClientEfl::create(impl);
1297 #if !ENABLE(TIZEN_ICON_DATABASE)
1298     /* Listen for favicon changes */
1299     Ewk_Favicon_Database* iconDatabase = impl->context->faviconDatabase();
1300     iconDatabase->watchChanges(IconChangeCallbackData(_ewk_view_on_favicon_changed, ewkView));
1301 #endif
1302 #if ENABLE(TIZEN_WEBKIT2_THEME_SET_INTERNAL)
1303     ewk_view_theme_set(ewkView, "/usr/share/edje/webkit.edj");
1304 #endif
1305
1306 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
1307     if (!impl->context->xWindow())
1308         impl->context->setXWindow(elm_win_xwindow_get(ewkView));
1309 #endif
1310 }
1311
1312 static Evas_Object* _ewk_view_add_with_smart(Evas* canvas, Evas_Smart* smart)
1313 {
1314     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1315     EINA_SAFETY_ON_NULL_RETURN_VAL(smart, 0);
1316
1317 #if ENABLE(TIZEN_WEBKIT2_DDK_CHECK)
1318     {
1319         using namespace EGL;
1320         if(!eglGetDisplay(EGL_DEFAULT_DISPLAY)) {
1321             EINA_LOG_CRIT("Fail in initiziling view because No DDK is installed.");
1322             return 0;
1323         }
1324     }
1325 #endif
1326
1327     Evas_Object* ewkView = evas_object_smart_add(canvas, smart);
1328     if (!ewkView)
1329         return 0;
1330
1331     EWK_VIEW_SD_GET(ewkView, smartData);
1332     if (!smartData) {
1333         evas_object_del(ewkView);
1334         return 0;
1335     }
1336
1337     EWK_VIEW_IMPL_GET(smartData, impl);
1338     if (!impl) {
1339         evas_object_del(ewkView);
1340         return 0;
1341     }
1342
1343     return ewkView;
1344 }
1345
1346 /**
1347  * @internal
1348  * Constructs a ewk_view Evas_Object with WKType parameters.
1349  */
1350 Evas_Object* ewk_view_base_add(Evas* canvas, WKContextRef contextRef, WKPageGroupRef pageGroupRef)
1351 {
1352     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1353     EINA_SAFETY_ON_NULL_RETURN_VAL(contextRef, 0);
1354
1355     Evas_Object* ewkView = _ewk_view_add_with_smart(canvas, _ewk_view_smart_class_new());
1356     if (!ewkView)
1357         return 0;
1358
1359     _ewk_view_initialize(ewkView, Ewk_Context::create(contextRef), pageGroupRef);
1360
1361     return ewkView;
1362 }
1363
1364 Evas_Object* ewk_view_smart_add(Evas* canvas, Evas_Smart* smart, Ewk_Context* context)
1365 {
1366     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1367     EINA_SAFETY_ON_NULL_RETURN_VAL(smart, 0);
1368     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1369
1370     Evas_Object* ewkView = _ewk_view_add_with_smart(canvas, smart);
1371     if (!ewkView)
1372         return 0;
1373
1374 #if ENABLE(TIZEN_WEBKIT2_CREATE_VIEW_WITH_CREATED_PAGE_GROUP_WITH_IDENTIFIER)
1375     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1376     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1377     _ewk_view_initialize(ewkView, context, toAPI(impl->pageGroup.get()));
1378 #else
1379     _ewk_view_initialize(ewkView, context, 0);
1380 #endif
1381
1382     return ewkView;
1383 }
1384
1385 Evas_Object* ewk_view_add_with_context(Evas* canvas, Ewk_Context* context)
1386 {
1387     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1388     return ewk_view_smart_add(canvas, _ewk_view_smart_class_new(), context);
1389 }
1390
1391 Evas_Object* ewk_view_add(Evas* canvas)
1392 {
1393     return ewk_view_add_with_context(canvas, ewk_context_default_get());
1394 }
1395
1396 Ewk_Context* ewk_view_context_get(const Evas_Object* ewkView)
1397 {
1398     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1399     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1400
1401     return impl->ewkContext();
1402 }
1403
1404 Eina_Bool ewk_view_url_set(Evas_Object* ewkView, const char* url)
1405 {
1406     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1407     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1408     EINA_SAFETY_ON_NULL_RETURN_VAL(url, false);
1409
1410     impl->pageProxy->loadURL(String::fromUTF8(url));
1411     impl->informURLChange();
1412
1413     return true;
1414 }
1415
1416 const char* ewk_view_url_get(const Evas_Object* ewkView)
1417 {
1418     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1419     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1420
1421     return impl->url();
1422 }
1423
1424 const char *ewk_view_icon_url_get(const Evas_Object *ewkView)
1425 {
1426     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1427     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1428
1429     return impl->faviconURL();
1430 }
1431
1432 Eina_Bool ewk_view_reload(Evas_Object* ewkView)
1433 {
1434     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1435     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1436
1437     impl->pageClient->prepareRestoredVisibleContectRect();
1438     impl->pageProxy->reload(/*reloadFromOrigin*/ false);
1439     impl->informURLChange();
1440
1441     return true;
1442 }
1443
1444 Eina_Bool ewk_view_reload_bypass_cache(Evas_Object* ewkView)
1445 {
1446     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1447     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1448
1449     impl->pageProxy->reload(/*reloadFromOrigin*/ true);
1450     impl->informURLChange();
1451
1452     return true;
1453 }
1454
1455 Eina_Bool ewk_view_stop(Evas_Object* ewkView)
1456 {
1457     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1458     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1459
1460     impl->pageProxy->stopLoading();
1461
1462     return true;
1463 }
1464
1465 Ewk_Settings* ewk_view_settings_get(const Evas_Object* ewkView)
1466 {
1467     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1468     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1469
1470     return impl->settings();
1471 }
1472
1473 const char* ewk_view_title_get(const Evas_Object* ewkView)
1474 {
1475     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1476     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1477
1478     return impl->title();
1479 }
1480
1481 /**
1482  * @internal
1483  * Reports that the requested text was found.
1484  *
1485  * Emits signal: "text,found" with the number of matches.
1486  */
1487 void ewk_view_text_found(Evas_Object* ewkView, unsigned int matchCount)
1488 {
1489     evas_object_smart_callback_call(ewkView, "text,found", &matchCount);
1490 }
1491
1492 double ewk_view_load_progress_get(const Evas_Object* ewkView)
1493 {
1494     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1.0);
1495     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, -1.0);
1496
1497     return impl->pageProxy->estimatedProgress();
1498 }
1499
1500 Eina_Bool ewk_view_scale_set(Evas_Object* ewkView, double scaleFactor, int x, int y)
1501 {
1502     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1503     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1504
1505 #if OS(TIZEN)
1506     // FIXME
1507     int centerX = x;
1508     int centerY = y;
1509     scaleFactor = impl->pageClient->adjustScaleWithViewport(scaleFactor);
1510
1511     IntPoint scrollPosition = impl->pageClient->scrollPosition();
1512     double scaleDifference = scaleFactor / impl->pageClient->scaleFactor();
1513     int newScrollX = (scrollPosition.x() + centerX - smartData->view.x) * scaleDifference - (centerX - smartData->view.x);
1514     int newScrollY = (scrollPosition.y() + centerY - smartData->view.y) * scaleDifference - (centerY - smartData->view.y);
1515
1516     impl->pageProxy->scale(scaleFactor, IntPoint(newScrollX, newScrollY));
1517 #else
1518     impl->pageProxy->scalePage(scaleFactor, IntPoint(x, y));
1519 #endif
1520     return true;
1521 }
1522
1523 double ewk_view_scale_get(const Evas_Object* ewkView)
1524 {
1525     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1);
1526     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, -1);
1527
1528 #if OS(TIZEN)
1529     return impl->pageProxy->scaleFactor();
1530 #else
1531     return impl->pageProxy->pageScaleFactor();
1532 #endif
1533 }
1534
1535 Eina_Bool ewk_view_device_pixel_ratio_set(Evas_Object* ewkView, float ratio)
1536 {
1537     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1538     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1539
1540     impl->pageProxy->setCustomDeviceScaleFactor(ratio);
1541
1542     return true;
1543 }
1544
1545 float ewk_view_device_pixel_ratio_get(const Evas_Object* ewkView)
1546 {
1547     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, -1.0);
1548     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, -1.0);
1549
1550     return impl->pageProxy->deviceScaleFactor();
1551 }
1552
1553 void ewk_view_theme_set(Evas_Object* ewkView, const char* path)
1554 {
1555     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1556     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1557
1558     impl->setThemePath(path);
1559 }
1560
1561 const char* ewk_view_theme_get(const Evas_Object* ewkView)
1562 {
1563     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1564     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1565
1566     return impl->themePath();
1567 }
1568
1569 Eina_Bool ewk_view_back(Evas_Object* ewkView)
1570 {
1571     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1572     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1573
1574     WebPageProxy* page = impl->pageProxy.get();
1575     if (page->canGoBack()) {
1576         page->goBack();
1577         return true;
1578     }
1579
1580     return false;
1581 }
1582
1583 Eina_Bool ewk_view_forward(Evas_Object* ewkView)
1584 {
1585     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1586     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1587
1588     WebPageProxy* page = impl->pageProxy.get();
1589     if (page->canGoForward()) {
1590         page->goForward();
1591         return true;
1592     }
1593
1594     return false;
1595 }
1596
1597 Eina_Bool ewk_view_intent_deliver(Evas_Object* ewkView, Ewk_Intent* intent)
1598 {
1599 #if ENABLE(WEB_INTENTS)
1600     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1601     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1602     EINA_SAFETY_ON_NULL_RETURN_VAL(intent, false);
1603
1604     WebPageProxy* page = impl->pageProxy.get();
1605     page->deliverIntentToFrame(page->mainFrame(), intent->webIntentData());
1606
1607     return true;
1608 #else
1609     return false;
1610 #endif
1611 }
1612
1613 Eina_Bool ewk_view_back_possible(Evas_Object* ewkView)
1614 {
1615     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1616     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1617
1618     return impl->pageProxy->canGoBack();
1619 }
1620
1621 Eina_Bool ewk_view_forward_possible(Evas_Object* ewkView)
1622 {
1623     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1624     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1625
1626     return impl->pageProxy->canGoForward();
1627 }
1628
1629 Ewk_Back_Forward_List* ewk_view_back_forward_list_get(const Evas_Object* ewkView)
1630 {
1631     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1632     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1633
1634     return impl->backForwardList.get();
1635 }
1636
1637 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1638 #if ENABLE(TIZEN_WEBKIT2_AUTOFILL_PROFILE_FORM)
1639 void ewk_view_text_change_in_textfield(Evas_Object* ewkView, const String& name, const String& value, bool isInputInForm)
1640 #else
1641 void ewk_view_text_change_in_textfield(Evas_Object* ewkView, const String& name, const String& value)
1642 #endif // TIZEN_WEBKIT2_AUTOFILL_PROFILE_FORM
1643 {
1644     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1645     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1646
1647     if (value.isEmpty()) {
1648         if(smartData->api->formdata_candidate_is_showing(smartData))
1649             smartData->api->formdata_candidate_hide(smartData);
1650         return;
1651     }
1652
1653     Eina_List* optionList = 0;
1654     Vector<String> popupOptionLists = impl->pageProxy->getFocusedInputElementDataList();
1655     std::sort(popupOptionLists.begin(), popupOptionLists.end(), WTF::codePointCompareLessThan);
1656     for (size_t i = 0; i < popupOptionLists.size(); ++i) {
1657         if (popupOptionLists[i].startsWith(value, false))
1658             optionList = eina_list_append(optionList, eina_stringshare_add(popupOptionLists[i].utf8().data()));
1659     }
1660
1661     Eina_List* candidateList = 0;
1662     if (ewk_settings_form_candidate_data_enabled_get(ewk_view_settings_get(ewkView))) {
1663         Vector<String> popupCandidates;
1664         ewk_view_form_candidate_data_get(ewkView, name, popupCandidates);
1665         std::sort(popupCandidates.begin(), popupCandidates.end(), WTF::codePointCompareLessThan);
1666
1667         for (size_t i = 0; i < popupCandidates.size(); ++i) {
1668             if (popupCandidates[i].startsWith(value, false))
1669                 candidateList = eina_list_append(candidateList, eina_stringshare_add(popupCandidates[i].utf8().data()));
1670         }
1671     }
1672
1673     Vector<AutoFillPopupItem> formData;
1674
1675 #if ENABLE(TIZEN_WEBKIT2_AUTOFILL_PROFILE_FORM)
1676     if (ewk_settings_form_profile_data_enabled_get(ewk_view_settings_get(ewkView)) && isInputInForm) {
1677         Vector<std::pair<int, std::pair<String, String> > > profileFormCandidates;
1678         ewk_view_profile_form_candidate_data_get(ewkView, name, value, profileFormCandidates);
1679         for (size_t ittr = 0; ittr < profileFormCandidates.size(); ++ittr) {
1680             std::pair<int, std::pair<String, String> > fullData(profileFormCandidates[ittr]);
1681             std::pair<String, String> dispStrings(fullData.second);
1682             formData.append(AutoFillPopupItem(dispStrings.first, dispStrings.second, fullData.first, profileAutoFill));
1683         }
1684     }
1685 #endif
1686
1687     Eina_List* list;
1688     void* data;
1689     if (eina_list_count(optionList)) {
1690         EINA_LIST_FOREACH(optionList, list, data)
1691             formData.append(AutoFillPopupItem(String::fromUTF8(static_cast<char*>(data)), dataListAutoFill));
1692     }
1693
1694     if (eina_list_count(candidateList) && ewk_settings_form_candidate_data_enabled_get(ewk_view_settings_get(ewkView))) {
1695         EINA_LIST_FOREACH(candidateList, list, data)
1696             formData.append(AutoFillPopupItem(String::fromUTF8(static_cast<char*>(data)), candidateAutoFill));
1697     }
1698
1699     if (!formData.size()) {
1700         if(smartData->api->formdata_candidate_is_showing(smartData))
1701             smartData->api->formdata_candidate_hide(smartData);
1702         return;
1703     }
1704
1705     if (formData[0].itemtype == profileAutoFill)
1706         impl->pageClient->updateAutoFillPopup(formData);
1707     else {
1708         Eina_List* autoFillList = 0;
1709
1710         if (eina_list_count(optionList)) {
1711             EINA_LIST_FOREACH(optionList, list, data)
1712                 autoFillList = eina_list_append(autoFillList, eina_stringshare_add(static_cast<char*>(data)));
1713         }
1714         if (eina_list_count(candidateList)) {
1715             EINA_LIST_FOREACH(candidateList, list, data)
1716                 autoFillList = eina_list_append(autoFillList, eina_stringshare_add(static_cast<char*>(data)));
1717         }
1718         smartData->api->formdata_candidate_update_data(smartData, autoFillList);
1719     }
1720
1721     IntRect inputFieldRect = impl->transformToScene().mapRect(impl->pageClient->focusedNodeRect());
1722     smartData->api->formdata_candidate_show(smartData, inputFieldRect.x(), inputFieldRect.y(), inputFieldRect.width(), inputFieldRect.height());
1723 }
1724
1725 void ewk_view_form_data_add(Evas_Object* ewkView, WKDictionaryRef& formData, bool isPasswordForm)
1726 {
1727     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1728     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1729     if (!ewk_settings_autofill_password_form_enabled_get(ewk_view_settings_get(ewkView))
1730         && !ewk_settings_form_candidate_data_enabled_get(ewk_view_settings_get(ewkView)))
1731         return;
1732     ewk_view_context_get(ewkView)->addFormData(impl->url(), formData, isPasswordForm);
1733 }
1734
1735 void ewk_view_form_password_data_fill(Evas_Object* ewkView)
1736 {
1737     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1738     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1739
1740     if (!ewk_settings_autofill_password_form_enabled_get(ewk_view_settings_get(ewkView)))
1741         return;
1742
1743     Vector<std::pair<String, String> > passwordFormData;
1744     ewk_view_context_get(ewkView)->passwordFormData(impl->url(), passwordFormData);
1745
1746     if (!passwordFormData.size())
1747         return;
1748
1749     String passwordFormAutofill = String::fromUTF8("try { function passwordFormAutofill() { var inputFields;");
1750     for (size_t i = 0; i < passwordFormData.size(); i++) {
1751         passwordFormAutofill += String::fromUTF8(" inputFields = document.getElementsByName(\"");
1752         passwordFormAutofill += passwordFormData[i].first;
1753         passwordFormAutofill += String::fromUTF8("\");");
1754         passwordFormAutofill += String::fromUTF8(" for (var i = 0; i < inputFields.length; i++)");
1755         passwordFormAutofill += String::fromUTF8(" if (inputFields[i].tagName.toLowerCase() == \"input\" && (inputFields[i].type.toLowerCase() == \"text\" || inputFields[i].type.toLowerCase() == \"password\" || inputFields[i].type.toLowerCase() == \"email\"))");
1756         passwordFormAutofill += String::fromUTF8(" inputFields[i].value = \"");
1757         passwordFormAutofill += passwordFormData[i].second;
1758         passwordFormAutofill += String::fromUTF8("\";");
1759     }
1760     passwordFormAutofill += String::fromUTF8("} passwordFormAutofill(); } catch(e) { }");
1761     ewk_view_script_execute(ewkView, passwordFormAutofill.utf8().data(), 0, 0);
1762 }
1763
1764 void ewk_view_form_candidate_data_get(Evas_Object* ewkView, const String& name, Vector<String>& candidates)
1765 {
1766     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
1767     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
1768     ewk_view_context_get(ewkView)->candidateFormData(name, candidates);
1769 }
1770 #endif
1771
1772 Eina_Bool ewk_view_html_string_load(Evas_Object* ewkView, const char* html, const char* baseUrl, const char* unreachableUrl)
1773 {
1774     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1775     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1776     EINA_SAFETY_ON_NULL_RETURN_VAL(html, false);
1777
1778     if (unreachableUrl && *unreachableUrl)
1779         impl->pageProxy->loadAlternateHTMLString(String::fromUTF8(html), baseUrl ? String::fromUTF8(baseUrl) : "", String::fromUTF8(unreachableUrl));
1780     else
1781         impl->pageProxy->loadHTMLString(String::fromUTF8(html), baseUrl ? String::fromUTF8(baseUrl) : "");
1782
1783     impl->informURLChange();
1784
1785     return true;
1786 }
1787
1788 const char* ewk_view_custom_encoding_get(const Evas_Object* ewkView)
1789 {
1790     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1791     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1792
1793     return impl->customTextEncodingName();
1794 }
1795
1796 Eina_Bool ewk_view_custom_encoding_set(Evas_Object* ewkView, const char* encoding)
1797 {
1798     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1799     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1800
1801     impl->setCustomTextEncodingName(encoding);
1802
1803     return true;
1804 }
1805
1806 #if OS(TIZEN)
1807 // FIXME: It should be removed.
1808 WKPageRef ewk_view_WKPage_get(Evas_Object* ewkView)
1809 {
1810     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1811     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1812
1813     return toAPI(impl->pageProxy.get());
1814 }
1815
1816 Eina_Bool ewk_view_mouse_events_enabled_set(Evas_Object* ewkView, Eina_Bool enabled)
1817 {
1818     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1819     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1820
1821     impl->setMouseEventsEnabled(!!enabled);
1822
1823     return true;
1824 }
1825
1826 Eina_Bool ewk_view_mouse_events_enabled_get(const Evas_Object* ewkView)
1827 {
1828     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1829     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1830
1831     return impl->mouseEventsEnabled();
1832 }
1833
1834 Eina_Bool ewk_view_color_picker_color_set(Evas_Object* ewkView, int r, int g, int b, int a)
1835 {
1836 #if ENABLE(INPUT_TYPE_COLOR)
1837     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1838     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1839
1840     return impl->setColorPickerColor(WebCore::Color(r, g, b, a));
1841 #else
1842     return false;
1843 #endif
1844 }
1845
1846 static Eina_Bool _ewk_view_default_javascript_alert(Evas_Object* ewkView, const char* alertText, void* userData)
1847 {
1848     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1849     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1850
1851     return impl->javascriptPopup->alert(alertText);
1852 }
1853
1854 static Eina_Bool _ewk_view_default_javascript_confirm(Evas_Object* ewkView, const char* message, void* userData)
1855 {
1856     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1857     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1858
1859     return impl->javascriptPopup->confirm(message);
1860 }
1861
1862 static Eina_Bool _ewk_view_default_javascript_prompt(Evas_Object* ewkView, const char* message, const char* defaultValue, void* userData)
1863 {
1864     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1865     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1866
1867     return impl->javascriptPopup->prompt(message, defaultValue);
1868 }
1869
1870 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
1871 static Eina_Bool _ewk_view_default_before_unload_confirm_panel(Evas_Object* ewkView, const char* message, void* userData)
1872 {
1873     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1874     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1875
1876     return impl->javascriptPopup->beforeUnloadConfirmPanel(message);
1877 }
1878 #endif
1879
1880 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)
1881 {
1882     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
1883     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1884
1885     return impl->openPanel->openPanel(ewkView, allow_multiple_files, accepted_mime_types, capture, impl);
1886 }
1887
1888 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1889 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)
1890 {
1891     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1892
1893     if (impl->popupPicker)
1894         ewk_popup_picker_del(impl->popupPicker);
1895
1896 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1897     impl->popupPicker = ewk_popup_picker_new(smartData->self, items, selectedIndex, false);
1898 #else
1899     impl->popupPicker = ewk_popup_picker_new(smartData->self, items, selectedIndex);
1900 #endif
1901
1902     return true;
1903 }
1904
1905 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1906 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)
1907 {
1908     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1909
1910     if (impl->popupPicker)
1911         ewk_popup_picker_del(impl->popupPicker);
1912
1913     impl->popupPicker = ewk_popup_picker_new(smartData->self, items, 0, true);
1914
1915     return true;
1916 }
1917 #endif
1918
1919 Eina_Bool _ewk_view_popup_menu_hide(Ewk_View_Smart_Data* smartData)
1920 {
1921     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1922
1923     if (!impl->popupPicker)
1924         return false;
1925
1926     ewk_popup_picker_del(impl->popupPicker);
1927     impl->popupPicker = 0;
1928
1929     return true;
1930 }
1931
1932 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)
1933 {
1934     // FIXME: The rect should be updated if it was changed
1935
1936     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1937
1938     if (!impl->popupPicker)
1939         return false;
1940
1941     ewk_popup_picker_update(smartData->self, impl->popupPicker, items, selectedIndex);
1942
1943     return true;
1944 }
1945 #endif
1946
1947 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1948 static Eina_Bool _ewk_view_input_picker_show(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType, const char* inputValue)
1949 {
1950     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1951
1952     impl->inputPicker->show(inputType, inputValue);
1953     return true;
1954 }
1955 #endif
1956
1957 #if ENABLE(TIZEN_DATALIST_ELEMENT)
1958 static Eina_Bool _ewk_view_data_list_show(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType, Eina_List* optionList)
1959 {
1960     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1961
1962     impl->inputPicker->showDataList(inputType, optionList);
1963     return true;
1964 }
1965
1966 static Eina_Bool _ewk_view_data_list_hide(Ewk_View_Smart_Data* smartData, Ewk_Input_Type inputType)
1967 {
1968     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1969
1970     impl->inputPicker->hideDataList(inputType);
1971     return true;
1972 }
1973 #endif
1974
1975 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
1976 static Eina_Bool _ewk_input_picker_color_request(Ewk_View_Smart_Data* smartData, int r, int g, int b, int a)
1977 {
1978     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1979
1980     impl->inputPicker->showColorPicker(r, g, b, a);
1981     return true;
1982 }
1983
1984 static Eina_Bool _ewk_input_picker_color_dismiss(Ewk_View_Smart_Data* smartData)
1985 {
1986     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
1987
1988     impl->inputPicker->hideColorPicker();
1989     return true;
1990 }
1991 #endif
1992
1993 PageClientImpl* ewkViewGetPageClient(const Evas_Object* ewkView)
1994 {
1995     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
1996     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
1997
1998     return impl->pageClient.get();
1999 }
2000
2001 double ewk_view_text_zoom_get(const Evas_Object* ewkView)
2002 {
2003     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 1);
2004     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 1);
2005
2006     return WKPageGetTextZoomFactor(toAPI(impl->pageProxy.get()));
2007 }
2008
2009 Eina_Bool ewk_view_text_zoom_set(Evas_Object* ewkView, double textZoomFactor)
2010 {
2011     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2012     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2013
2014     WKPageSetTextZoomFactor(toAPI(impl->pageProxy.get()), textZoomFactor);
2015     return true;
2016 }
2017
2018 Ewk_Frame_Ref ewk_view_main_frame_get(Evas_Object* ewkView)
2019 {
2020     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2021     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2022
2023     return static_cast<Ewk_Frame_Ref>(WKPageGetMainFrame(toAPI(impl->pageProxy.get())));
2024 }
2025
2026 Ewk_Frame_Ref ewk_view_focused_frame_get(Evas_Object* ewkView)
2027 {
2028     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2029     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2030
2031     return static_cast<Ewk_Frame_Ref>(WKPageGetFocusedFrame(toAPI(impl->pageProxy.get())));
2032 }
2033
2034 JSGlobalContextRef ewkViewGetJavascriptGlobalContext(Evas_Object* ewkView)
2035 {
2036     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2037     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2038
2039     if (!impl->javascriptGlobalContext)
2040         impl->javascriptGlobalContext = JSGlobalContextCreate(0);
2041     return impl->javascriptGlobalContext;
2042 }
2043
2044 void ewkViewLoadCommitted(Evas_Object* ewkView)
2045 {
2046 #if ENABLE(TIZEN_GESTURE)
2047     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2048     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2049     impl->gestureClient->reset();
2050 #endif
2051 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
2052     if (impl->focusRing())
2053         impl->focusRing()->hide(false);
2054 #endif
2055 #if ENABLE(TIZEN_ISF_PORT)
2056     impl->inputMethodContext()->hideIMFContext();
2057 #endif
2058 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
2059     if (smartData->api->formdata_candidate_is_showing(smartData))
2060         smartData->api->formdata_candidate_hide(smartData);
2061 #endif
2062     impl->informURLChange();
2063     evas_object_smart_callback_call(ewkView, "load,committed", 0);
2064 }
2065
2066 void ewkViewLoadError(Evas_Object* ewkView, WKErrorRef error)
2067 {
2068     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2069     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2070
2071     OwnPtr<Ewk_Error> ewkError = Ewk_Error::create(error);
2072     ewk_error_load_error_page(ewkError.get(), toAPI(impl->pageProxy.get()));
2073     evas_object_smart_callback_call(ewkView, "load,error", ewkError.get());
2074 }
2075
2076 void ewkViewDidFirstVisuallyNonEmptyLayout(Evas_Object* ewkView)
2077 {
2078 #if ENABLE(TIZEN_GESTURE)
2079     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2080     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2081     impl->gestureClient->reset();
2082 #endif
2083     evas_object_smart_callback_call(ewkView, "load,nonemptylayout,finished", 0);
2084 }
2085
2086 void ewkViewDidReceiveAuthenticationChallenge(Evas_Object* ewkView, Ewk_Auth_Challenge* authChallenge)
2087 {
2088     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2089     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2090
2091     if (impl->authChallenge)
2092         ewkAuthChallengeDelete(impl->authChallenge);
2093     impl->authChallenge = authChallenge;
2094
2095     evas_object_smart_callback_call(ewkView, "authentication,challenge", impl->authChallenge);
2096 }
2097
2098 void ewk_view_process_crashed(Evas_Object* ewkView)
2099 {
2100     bool handled = false;
2101     evas_object_smart_callback_call(ewkView, "process,crashed", &handled);
2102
2103     if (!handled)
2104         exit(0);
2105 }
2106
2107 #if ENABLE(TIZEN_SQL_DATABASE)
2108 bool ewkViewExceededDatabaseQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, WKStringRef databaseName, unsigned long long expectedUsage)
2109 {
2110     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2111     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2112
2113     if (!impl->exceededDatabaseQuotaContext || !impl->exceededDatabaseQuotaContext->exceededDatabaseQuotaCallback)
2114         return false;
2115
2116     TIZEN_LOGI("No error in prameter. Request to display user confirm popup. expectedUsage(%llu)", expectedUsage);
2117     impl->isWaitingForExceededQuotaPopupReply = true;
2118     if (impl->exceededQuotaOrigin)
2119         deleteSecurityOrigin(impl->exceededQuotaOrigin);
2120     impl->exceededQuotaOrigin = createSecurityOrigin(origin);
2121
2122     int length = WKStringGetMaximumUTF8CStringSize(databaseName);
2123     OwnArrayPtr<char> databaseNameBuffer = adoptArrayPtr(new char[length]);
2124     WKStringGetUTF8CString(databaseName, databaseNameBuffer.get(), length);
2125
2126     return impl->exceededDatabaseQuotaContext->exceededDatabaseQuotaCallback(ewkView, impl->exceededQuotaOrigin, databaseNameBuffer.get(), expectedUsage, impl->exceededDatabaseQuotaContext->userData) == EINA_TRUE;
2127 }
2128 #endif
2129
2130 #if ENABLE(TIZEN_NOTIFICATIONS)
2131 void ewkViewCancelNotification(Evas_Object* ewkView, uint64_t notificationID)
2132 {
2133     TIZEN_LOGI("notification,cancel");
2134     evas_object_smart_callback_call(ewkView, "notification,cancel", &notificationID);
2135 }
2136
2137 void ewkViewRequestNotificationPermission(Evas_Object* ewkView, Ewk_Notification_Permission_Request* notificationPermissionRequest)
2138 {
2139     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2140     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2141
2142     TIZEN_LOGI("notification,permission,request");
2143     impl->notificationPermissionRequests = eina_list_append(impl->notificationPermissionRequests, notificationPermissionRequest);
2144     evas_object_smart_callback_call(ewkView, "notification,permission,request", notificationPermissionRequest);
2145 }
2146
2147 void ewkViewShowNotification(Evas_Object* ewkView, Ewk_Notification* notification)
2148 {
2149     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2150     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2151
2152     TIZEN_LOGI("notification,show");
2153     Eina_List* listIterator=0;
2154     void* data=0;
2155     const char* replaceID = ewkNotificationGetReplaceID(notification);
2156     if(strlen(replaceID)) {
2157         EINA_LIST_FOREACH(impl->notifications, listIterator, data) {
2158             Ewk_Notification* notificationForReplace = static_cast<Ewk_Notification*>(data);
2159             if(!strcmp(ewkNotificationGetReplaceID(notificationForReplace), replaceID))
2160                 ewkViewCancelNotification(ewkView, ewk_notification_id_get(notificationForReplace));
2161         }
2162     }
2163
2164     impl->notifications = eina_list_append(impl->notifications, notification);
2165     evas_object_smart_callback_call(ewkView, "notification,show", notification);
2166 }
2167
2168 void ewkViewDeleteNotificationPermissionRequest(Evas_Object* ewkView, Ewk_Notification_Permission_Request* ewkNotificationPermissionRequest)
2169 {
2170     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2171     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2172
2173     impl->notificationPermissionRequests = eina_list_remove(impl->notificationPermissionRequests, ewkNotificationPermissionRequest);
2174 }
2175 #endif
2176
2177 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER)
2178 void ewkViewRegisterProtocolHandlers(Evas_Object* ewkView, const char* scheme, const char* baseUrl, const char* url, const char* title)
2179 {
2180     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2181
2182     TIZEN_LOGI("protocolhandler,registration,requested");
2183     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(scheme, baseUrl, url, title);
2184     evas_object_smart_callback_call(ewkView, "protocolhandler,registration,requested", static_cast<void*>(customHandlersData));
2185     ewkCustomHandlersDeleteData(customHandlersData);
2186 }
2187 #endif
2188
2189 #if ENABLE(TIZEN_CUSTOM_SCHEME_HANDLER)
2190 Ewk_Custom_Handlers_State ewkViewIsProtocolHandlerRegistered(Evas_Object* ewkView, const char* scheme, const char* baseURL, const char* url)
2191 {
2192     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, EWK_CUSTOM_HANDLERS_DECLINED);
2193
2194     TIZEN_LOGI("protocolhandler,isregistered");
2195     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(scheme, baseURL, url);
2196     evas_object_smart_callback_call(ewkView, "protocolhandler,isregistered", static_cast<void*>(customHandlersData));
2197
2198     Ewk_Custom_Handlers_State result;
2199     result = ewkGetCustomHandlersDataResult(customHandlersData);
2200     ewkCustomHandlersDeleteData(customHandlersData);
2201
2202     return result;
2203 }
2204
2205 void ewkViewUnregisterProtocolHandlers(Evas_Object* ewkView, const char* scheme, const char* baseURL, const char* url)
2206 {
2207     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2208
2209     TIZEN_LOGI("protocolhandler,unregistration,requested");
2210     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(scheme, baseURL, url);
2211     evas_object_smart_callback_call(ewkView, "protocolhandler,unregistration,requested", static_cast<void*>(customHandlersData));
2212     ewkCustomHandlersDeleteData(customHandlersData);
2213 }
2214 #endif
2215
2216 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
2217 void ewkViewRegisterContentHandlers(Evas_Object* ewkView, const char* mimeType, const char* baseUrl, const char* url, const char* title)
2218 {
2219     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2220
2221     TIZEN_LOGI("contenthandler,registration,requested");
2222     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(mimeType, baseUrl, url, title);
2223     evas_object_smart_callback_call(ewkView, "contenthandler,registration,requested", static_cast<void*>(customHandlersData));
2224     ewkCustomHandlersDeleteData(customHandlersData);
2225 }
2226
2227 Ewk_Custom_Handlers_State ewkViewIsContentHandlerRegistered(Evas_Object* ewkView, const char* mimeType, const char* baseURL, const char* url)
2228 {
2229     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, EWK_CUSTOM_HANDLERS_DECLINED);
2230
2231     TIZEN_LOGI("contenthandler,isregistered");
2232     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(mimeType, baseURL, url);
2233     evas_object_smart_callback_call(ewkView, "contenthandler,isregistered", static_cast<void*>(customHandlersData));
2234
2235     Ewk_Custom_Handlers_State result;
2236     result = ewkGetCustomHandlersDataResult(customHandlersData);
2237     ewkCustomHandlersDeleteData(customHandlersData);
2238
2239     return result;
2240 }
2241
2242 void ewkViewUnregisterContentHandlers(Evas_Object* ewkView, const char* mimeType, const char* baseURL, const char* url)
2243 {
2244     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2245
2246     TIZEN_LOGI("contenthandler,unregistration,requested");
2247     Ewk_Custom_Handlers_Data* customHandlersData = ewkCustomHandlersCreateData(mimeType, baseURL, url);
2248     evas_object_smart_callback_call(ewkView, "contenthandler,unregistration,requested", static_cast<void*>(customHandlersData));
2249     ewkCustomHandlersDeleteData(customHandlersData);
2250 }
2251 #endif
2252
2253 #if ENABLE(TIZEN_SEARCH_PROVIDER)
2254 void ewkViewAddSearchProvider(Evas_Object* ewkView, const char* baseURL, const char* engineURL)
2255 {
2256     EINA_SAFETY_ON_NULL_RETURN(ewkView);
2257
2258     TIZEN_LOGI("searchProvider,add");
2259     Ewk_Search_Provider_Data* searchProviderData = ewkSearchProviderCreateData(baseURL, engineURL);
2260     evas_object_smart_callback_call(ewkView, "searchProvider,add", static_cast<void*>(searchProviderData));
2261     ewkSearchProviderDeleteData(searchProviderData);
2262 }
2263
2264 unsigned long ewkViewIsSearchProviderInstalled(Evas_Object* ewkView, const char* baseURL, const char* engineURL)
2265 {
2266     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, 0);
2267
2268     TIZEN_LOGI("searchProvider,installed");
2269     Ewk_Search_Provider_Data* searchProviderData = ewkSearchProviderCreateData(baseURL, engineURL);
2270     evas_object_smart_callback_call(ewkView, "searchProvider,installed", static_cast<void*>(searchProviderData));
2271     unsigned long result;
2272     result = ewkGetSearchProviderResult(searchProviderData);
2273     ewkSearchProviderDeleteData(searchProviderData);
2274     return result;
2275 }
2276 #endif
2277
2278 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
2279 bool ewkViewGetStandaloneStatus(Evas_Object* ewkView)
2280 {
2281     TIZEN_LOGI("webapp,metatag,standalone");
2282     bool standalone = true;
2283     evas_object_smart_callback_call(ewkView, "webapp,metatag,standalone", (void*)&standalone);
2284     return standalone;
2285 }
2286 #endif
2287
2288 #if ENABLE(TIZEN_MEDIA_STREAM)
2289 void ewkViewRequestUserMediaPermission(Evas_Object* ewkView, Ewk_User_Media_Permission_Request* userMediaPermission)
2290 {
2291     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2292     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2293
2294     impl->userMediaPermissionRequests = eina_list_append(impl->userMediaPermissionRequests, userMediaPermission);
2295     evas_object_smart_callback_call(ewkView, "usermedia,permission,request", userMediaPermission);
2296 }
2297
2298 void ewkViewDeleteUserMediaPermissionRequest(Evas_Object* ewkView, Ewk_User_Media_Permission_Request* permission)
2299 {
2300     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2301     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2302
2303     impl->userMediaPermissionRequests = eina_list_remove(impl->userMediaPermissionRequests, permission);
2304 }
2305
2306 #endif
2307
2308 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
2309 void ewkViewProcessJSBridgePlugin(Evas_Object* ewkView, WKStringRef request, WKStringRef message)
2310 {
2311     int requestLength = WKStringGetMaximumUTF8CStringSize(request);
2312     OwnArrayPtr<char> requestBuffer = adoptArrayPtr(new char[requestLength]);
2313     int messageLength = WKStringGetMaximumUTF8CStringSize(message);
2314     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[messageLength]);
2315     WKStringGetUTF8CString(request, requestBuffer.get(), requestLength);
2316     WKStringGetUTF8CString(message, messageBuffer.get(), messageLength);
2317
2318     evas_object_smart_callback_call(ewkView, requestBuffer.get(), static_cast<void*>(messageBuffer.get()));
2319 }
2320 #endif
2321
2322 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
2323 void ewkViewRequestCertificateConfirm(Evas_Object* ewkView, Ewk_Certificate_Policy_Decision* certificatePolicyDecision)
2324 {
2325     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2326     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2327     if (impl->certificatePolicyDecision)
2328         ewkCertificatePolicyDecisionDelete(impl->certificatePolicyDecision);
2329     impl->certificatePolicyDecision = certificatePolicyDecision;
2330
2331     evas_object_smart_callback_call(ewkView, "request,certificate,confirm", certificatePolicyDecision);
2332 }
2333 #endif
2334
2335 void ewkViewCustomizeContextMenu(Evas_Object* ewkView, Ewk_Context_Menu* menu)
2336 {
2337     evas_object_smart_callback_call(ewkView, "contextmenu,customize", static_cast<void*>(menu));
2338 }
2339
2340 void ewkViewCustomContextMenuItemSelected(Evas_Object* ewkView, Ewk_Context_Menu_Item* item)
2341 {
2342     evas_object_smart_callback_call(ewkView, "contextmenu,selected", static_cast<void*>(item));
2343 }
2344
2345 #if ENABLE(TIZEN_GEOLOCATION)
2346 void ewkViewRequestGeolocationPermission(Evas_Object* ewkView, Ewk_Geolocation_Permission_Request* geolocationPermissionRequest)
2347 {
2348     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2349     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2350
2351     TIZEN_LOGI("geolocation,permission,request");
2352     impl->geolocationPermissionRequests = eina_list_append(impl->geolocationPermissionRequests, geolocationPermissionRequest);
2353     evas_object_smart_callback_call(ewkView, "geolocation,permission,request", geolocationPermissionRequest);
2354 }
2355
2356 void ewkViewDeleteGeolocationPermission(Evas_Object* ewkView, Ewk_Geolocation_Permission_Request* geolocationPermissionRequest)
2357 {
2358     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2359     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2360
2361     impl->geolocationPermissionRequests = eina_list_remove(impl->geolocationPermissionRequests, geolocationPermissionRequest);
2362 }
2363
2364 void ewkViewSetGeolocation(Evas_Object* ewkView, Ewk_Geolocation* geolocation)
2365 {
2366     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2367     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2368
2369     impl->geolocation = geolocation;
2370 }
2371
2372 Ewk_Geolocation* ewkViewGetGeolocation(Evas_Object* ewkView)
2373 {
2374     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2375     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2376
2377     return impl->geolocation;
2378 }
2379
2380 bool ewkViewIsValidLocationService(Evas_Object* ewkView)
2381 {
2382     TIZEN_LOGI("geolocation,valid");
2383
2384     bool valid = true;
2385     evas_object_smart_callback_call(ewkView, "geolocation,valid", &valid);
2386     return valid;
2387 }
2388 #endif
2389
2390 void ewkViewFormSubmit(Evas_Object* ewkView, Ewk_Form_Data* formData)
2391 {
2392     evas_object_smart_callback_call(ewkView, "form,submit", formData);
2393 }
2394
2395 void ewkViewPolicyNavigationDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2396 {
2397     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2398     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2399     if (impl->policyDecision)
2400         ewkPolicyDecisionDelete(impl->policyDecision);
2401     impl->policyDecision = policyDecision;
2402
2403     evas_object_smart_callback_call(ewkView, "policy,navigation,decide", impl->policyDecision);
2404 }
2405
2406 void ewkViewPolicyNewWindowDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2407 {
2408     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2409     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2410     if (impl->policyDecision)
2411         ewkPolicyDecisionDelete(impl->policyDecision);
2412     impl->policyDecision = policyDecision;
2413
2414     evas_object_smart_callback_call(ewkView, "policy,newwindow,decide", impl->policyDecision);
2415 }
2416
2417 void ewkViewPolicyResponseDecide(Evas_Object* ewkView, Ewk_Policy_Decision* policyDecision)
2418 {
2419     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
2420     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
2421     if (impl->policyDecision)
2422         ewkPolicyDecisionDelete(impl->policyDecision);
2423     impl->policyDecision = policyDecision;
2424
2425     evas_object_smart_callback_call(ewkView, "policy,response,decide", impl->policyDecision);
2426 }
2427
2428 void ewkViewSendScrollEvent(Evas_Object* ewkView, int deltaX, int deltaY)
2429 {
2430     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2431     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2432
2433     IntPoint scrollPosition = impl->pageClient->scrollPosition();
2434     IntSize contentsSize = impl->pageProxy->contentsSize();
2435 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2436     contentsSize.scale(impl->pageClient->scaleFactor());
2437 #endif
2438
2439     // some website's contents size is smaller than view size,
2440     // so we have to adjust contents size to view size for that case.
2441     if (contentsSize.width() < smartData->view.w)
2442         contentsSize.setWidth(smartData->view.w);
2443     if (contentsSize.height() < smartData->view.h)
2444         contentsSize.setHeight(smartData->view.h);
2445
2446     // Call "scroll,down" if webview can be scrolled down.
2447     if (deltaY > 0 && (scrollPosition.y() + smartData->view.h) < contentsSize.height())
2448         evas_object_smart_callback_call(ewkView, "scroll,down", 0);
2449     // Call "scroll,up" if webview can be scrolled up.
2450     else if (deltaY < 0 && scrollPosition.y() > 0)
2451         evas_object_smart_callback_call(ewkView, "scroll,up", 0);
2452
2453     // Call "scroll,right" if webview can be scrolled down.
2454     if (deltaX > 0 && (scrollPosition.x() + smartData->view.w) < contentsSize.width())
2455         evas_object_smart_callback_call(ewkView, "scroll,right", 0);
2456     // Call "scroll,left" if webview can be scrolled up.
2457     else if (deltaX < 0 && scrollPosition.x() > 0)
2458         evas_object_smart_callback_call(ewkView, "scroll,left", 0);
2459 }
2460
2461 void ewkViewSendEdgeEvent(Evas_Object* ewkView, const IntPoint& scrollPosition, int deltaX, int deltaY)
2462 {
2463     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2464     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2465
2466     IntSize contentsSize = impl->pageProxy->contentsSize();
2467 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2468     contentsSize.scale(impl->pageClient->scaleFactor());
2469 #endif
2470
2471     int maxScrollY = contentsSize.height() - smartData->view.h;
2472     if (!impl->isVerticalEdge) {
2473         if (deltaY < 0 && (scrollPosition.y() + deltaY) <= 0) {
2474             evas_object_smart_callback_call(ewkView, "edge,top", NULL);
2475             impl->isVerticalEdge = true;
2476         } else if (deltaY > 0 && (scrollPosition.y() + deltaY) >= maxScrollY) {
2477             evas_object_smart_callback_call(ewkView, "edge,bottom", NULL);
2478             impl->isVerticalEdge = true;
2479         }
2480     } else {
2481         if (maxScrollY && ((scrollPosition.y() == 0 && deltaY > 0)
2482                            || (scrollPosition.y() == maxScrollY && deltaY < 0)))
2483             impl->isVerticalEdge = false;
2484     }
2485
2486     int maxScrollX = contentsSize.width() - smartData->view.w;
2487     if (!impl->isHorizontalEdge) {
2488         if (deltaX < 0 && (scrollPosition.x() + deltaX) <= 0) {
2489             evas_object_smart_callback_call(ewkView, "edge,left", NULL);
2490             impl->isHorizontalEdge = true;
2491         } else if (deltaX > 0 && (scrollPosition.x() + deltaX) >= maxScrollX) {
2492             evas_object_smart_callback_call(ewkView, "edge,right", NULL);
2493             impl->isHorizontalEdge = true;
2494         }
2495     } else {
2496         if (maxScrollX && ((scrollPosition.x() == 0 && deltaX > 0)
2497                            || (scrollPosition.x() == maxScrollX && deltaX < 0)))
2498             impl->isHorizontalEdge = false;
2499     }
2500 }
2501
2502 void ewkViewClearEdges(Evas_Object* ewkView)
2503 {
2504     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2505     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2506
2507     impl->isVerticalEdge = false;
2508     impl->isHorizontalEdge = false;
2509 }
2510
2511 void ewk_view_scale_range_get(Evas_Object* ewkView, double* minimumScale, double* maximumScale)
2512 {
2513     EWK_VIEW_SD_GET(ewkView, smartData);
2514     if (!smartData || !smartData->priv) {
2515         if (minimumScale)
2516             *minimumScale = -1;
2517         if (maximumScale)
2518             *maximumScale = -1;
2519         return;
2520     }
2521
2522     PageClientImpl::ViewportConstraints constraints = smartData->priv->pageClient->viewportConstraints();
2523     if (minimumScale)
2524         *minimumScale = constraints.minimumScale;
2525     if (maximumScale)
2526         *maximumScale = constraints.maximumScale;
2527 }
2528
2529 bool ewk_view_focused_node_adjust(Evas_Object* ewkView, Eina_Bool adjustForExternalKeyboard)
2530 {
2531     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2532     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2533
2534 #if ENABLE(TIZEN_ISF_PORT)
2535     // We should treat both of ECORE_IMF_INPUT_PANEL_STATE_SHOW and ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW
2536     // as IME is shown. ECORE_IMF_INPUT_PANEL_STATE_HIDE is ignored at here.
2537     // input field zoom should not work with below conditions
2538     // 1. view is not focused
2539     // 2. external keyboard is not connected(if adjustForExternalKeyboard is true)
2540     // 3. imfContext is null(if adjustForExternalKeyboard is false)
2541     // 4. input panel state is hidden(if adjustForExternalKeyboard is false)
2542
2543     if ((!(static_cast<PageClient*>(impl->pageClient.get()))->isViewFocused()
2544         || (!adjustForExternalKeyboard && !impl->inputMethodContext())
2545         || (!adjustForExternalKeyboard && !impl->inputMethodContext()->isShow()))
2546 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
2547         && !(impl->pageClient->isClipboardWindowOpened())
2548 #endif
2549         )
2550         return false;
2551 #endif
2552
2553     double scaleFactor = impl->pageClient->scaleFactor();
2554     IntSize contentsSize = impl->pageProxy->contentsSize();
2555
2556     double newScaleFactor = scaleFactor;
2557     // Readable zoom value is dependent on device DPI
2558     if (scaleFactor < impl->pageProxy->deviceScaleFactor()
2559         && impl->pageClient->viewportConstraints().userScalable)
2560         newScaleFactor = impl->pageProxy->deviceScaleFactor();
2561
2562     // Readable zoom value should be inside of viewport scale range
2563     newScaleFactor = impl->pageClient->adjustScaleWithViewport(newScaleFactor);
2564
2565     // caret position can be outside of visible rect.
2566     // we need to consider it.
2567     IntRect selectionRect = impl->pageProxy->editorState().selectionRect;
2568     IntRect focusedNodeRect = impl->pageClient->focusedNodeRect();
2569     IntRect focusedNodeRectScaled = focusedNodeRect;
2570
2571     if (selectionRect.isEmpty())
2572         return false;
2573
2574 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
2575     focusedNodeRectScaled.scale(newScaleFactor);
2576 #else
2577     focusedNodeRectScaled.scale(newScaleFactor / scaleFactor);
2578 #endif
2579
2580     IntRect visibleRect = impl->pageClient->visibleContentRect();
2581     if (visibleRect.contains(focusedNodeRectScaled))
2582         return false;
2583
2584 #if ENABLE(TIZEN_WEBKIT2_INPUT_FIELD_ZOOM)
2585     impl->inputFieldZoom->startInputFieldZoom(impl->transformFromScene().mapPoint(IntPoint(focusedNodeRect.x(), focusedNodeRect.y())) ,focusedNodeRect);
2586 #endif
2587
2588     return true;
2589 }
2590
2591 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
2592 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
2593 static Eina_Bool _ewk_view_composite(void* data)
2594 {
2595     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
2596     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2597
2598     if (!evas_object_visible_get(smartData->image))
2599         return ECORE_CALLBACK_CANCEL;
2600
2601     Evas_Coord ow, oh;
2602     evas_object_image_size_get(smartData->image, &ow, &oh);
2603     uint8_t* pixels = static_cast<uint8_t*>(evas_object_image_data_get(smartData->image, true));
2604
2605     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)));
2606     RefPtr<cairo_t> context = adoptRef(cairo_create(surface.get()));
2607
2608     cairo_save(context.get());
2609     cairo_set_operator(context.get(), CAIRO_OPERATOR_CLEAR);
2610     cairo_rectangle(context.get(), 0, 0, ow, oh);
2611     cairo_fill(context.get());
2612     cairo_restore(context.get());
2613
2614     impl->pageClient->drawContents(context.get());
2615
2616     evas_object_image_data_set(smartData->image, pixels);
2617     evas_object_image_data_update_add(smartData->image, 0, 0, ow, oh);
2618
2619     if (impl->pageClient->notifiedNonemptyLayout() && impl->pageClient->canUpdateVisibleContentRect())
2620         ewkViewFrameRendered(smartData->self);
2621
2622     impl->compositionAnimator = 0;
2623
2624     return ECORE_CALLBACK_CANCEL;
2625 }
2626 #endif
2627
2628 void ewk_view_mark_for_sync(Evas_Object* ewkView)
2629 {
2630     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2631     EINA_SAFETY_ON_NULL_RETURN(smartData->image);
2632
2633 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
2634     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2635
2636     if (!ewk_view_is_opengl_backend(ewkView)) {
2637         if (!impl->compositionAnimator)
2638             impl->compositionAnimator = ecore_animator_add(_ewk_view_composite, smartData);
2639         return;
2640     }
2641 #endif
2642
2643     evas_object_image_pixels_dirty_set(smartData->image, true);
2644 }
2645
2646 static void on_pixels_for_accelerated_compositing(void* data, Evas_Object* obj)
2647 {
2648     Evas_Object* ewkView = static_cast<Evas_Object*>(data);
2649     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2650     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2651     impl->pageClient->drawContents();
2652 }
2653
2654 bool ewk_view_image_native_surface_set(Evas_Object* ewkView, Evas_Native_Surface* nativeSurface)
2655 {
2656     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2657     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2658
2659     if (!smartData->image)
2660         return false;
2661
2662     evas_object_image_native_surface_set(smartData->image, nativeSurface);
2663     evas_object_image_pixels_get_callback_set(smartData->image, on_pixels_for_accelerated_compositing, ewkView);
2664
2665     return true;
2666 }
2667 #endif
2668
2669 void _ewk_view_suspend_painting(Evas_Object* ewkView)
2670 {
2671     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2672     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2673
2674     if (!impl->suspendedPainting) {
2675         impl->pageProxy->suspendPainting();
2676         impl->suspendedPainting = true;
2677     }
2678 }
2679
2680 void _ewk_view_resume_painting(Evas_Object* ewkView)
2681 {
2682     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2683     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2684
2685     if (impl->suspendedPainting) {
2686         impl->pageProxy->resumePainting();
2687         impl->suspendedPainting = false;
2688     }
2689 }
2690
2691 void ewk_view_suspend(Evas_Object* ewkView)
2692 {
2693     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2694     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2695
2696     if (impl->pageProxy->estimatedProgress() < 1.0) {
2697         impl->suspendRequested = true;
2698         return;
2699     }
2700     impl->suspendRequested = false;
2701
2702     _ewk_view_suspend_painting(ewkView);
2703
2704     // FIXME Workaround for suspend/resume while javascript popup is displayed.
2705     // condition ' && !private->isWaitingForJavaScriptPopupReply' is added to
2706     // skip suspendJavaScriptAndResource to prevent multiple ActiveDOMObject
2707     // suspend.
2708     // During the javascript popup is displayed, PageGroupLoadDeferrer is activated,
2709     // which suspends resource loading and scheduled tasks, including ActiveDOMObject.
2710     // When ewk_view_suspend() is called during the javascript popup, scheduled tasks
2711     // will be suspended again.
2712     // Multiple suspend of ActiveDOMObject makes unintended suspend/resume status of
2713     // the ActiveDOMObject.
2714     if (!impl->suspendedResources && (!impl->isWaitingForJavaScriptPopupReply || !impl->isWaitingForApplicationCachePermission || !impl->isWaitingForExceededQuotaPopupReply)) {
2715         impl->pageProxy->suspendAnimations();
2716         impl->pageProxy->suspendJavaScriptAndResource();
2717         impl->suspendedResources = true;
2718     }
2719
2720 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
2721     impl->pageProxy->suspendPlugin();
2722 #endif
2723 }
2724
2725 void ewk_view_resume(Evas_Object* ewkView)
2726 {
2727     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
2728     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
2729
2730     if (impl->suspendRequested) {
2731         impl->suspendRequested = false;
2732         return;
2733     }
2734
2735     _ewk_view_resume_painting(ewkView);
2736
2737     // FIXME Workaround for suspend/resume while javascript popup is displayed.
2738     // condition ' && !private->isWaitingForJavaScriptPopupReply' is added to
2739     // skip suspendJavaScriptAndResource to prevent multiple ActiveDOMObject
2740     // suspend.
2741     // During the javascript popup is displayed, PageGroupLoadDeferrer is activated,
2742     // which suspends resource loading and scheduled tasks, including ActiveDOMObject.
2743     // When ewk_view_suspend() is called during the javascript popup, scheduled tasks
2744     // will be suspended again.
2745     // Multiple suspend of ActiveDOMObject makes unintended suspend/resume status of
2746     // the ActiveDOMObject.
2747     if (impl->suspendedResources && (!impl->isWaitingForJavaScriptPopupReply || !impl->isWaitingForApplicationCachePermission || !impl->isWaitingForExceededQuotaPopupReply)) {
2748         impl->pageProxy->resumeAnimations();
2749         impl->pageProxy->resumeJavaScriptAndResource();
2750         impl->suspendedResources = false;
2751     }
2752
2753 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
2754     impl->pageProxy->resumePlugin();
2755 #endif
2756 }
2757
2758 Eina_Bool ewk_view_url_request_set(Evas_Object* ewkView, const char* url, Ewk_Http_Method method, Eina_Hash* headers, const char* body)
2759 {
2760     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2761     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2762     EINA_SAFETY_ON_NULL_RETURN_VAL(url, false);
2763
2764     ResourceRequest request(String::fromUTF8(url));
2765
2766     switch (method) {
2767     case EWK_HTTP_METHOD_GET:
2768         request.setHTTPMethod("GET");
2769         break;
2770     case EWK_HTTP_METHOD_HEAD:
2771         request.setHTTPMethod("HEAD");
2772         break;
2773     case EWK_HTTP_METHOD_POST:
2774         request.setHTTPMethod("POST");
2775         break;
2776     case EWK_HTTP_METHOD_PUT:
2777         request.setHTTPMethod("PUT");
2778         break;
2779     case EWK_HTTP_METHOD_DELETE:
2780         request.setHTTPMethod("DELETE");
2781         break;
2782     default:
2783         return false;
2784     }
2785
2786     if (headers) {
2787         Eina_Iterator* it = eina_hash_iterator_tuple_new(headers);
2788         void* data;
2789         while (eina_iterator_next(it, &data)) {
2790             Eina_Hash_Tuple* t = static_cast<Eina_Hash_Tuple*>(data);
2791             const char* name = static_cast<const char*>(t->key);
2792             const char* value = static_cast<const char*>(t->data);
2793             request.addHTTPHeaderField(name, value);
2794         }
2795         eina_iterator_free(it);
2796     }
2797
2798     if (body)
2799         request.setHTTPBody(FormData::create(body));
2800
2801     WKRetainPtr<WKURLRequestRef> urlRequest(AdoptWK,toAPI(WebURLRequest::create(request).leakRef()));
2802     WKPageLoadURLRequest(toAPI(impl->pageProxy.get()), urlRequest.get());
2803
2804     return true;
2805 }
2806
2807 Eina_Bool ewk_view_plain_text_set(Evas_Object* ewkView, const char* plainText)
2808 {
2809     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2810     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2811
2812     WKRetainPtr<WKStringRef> plainTextRef(AdoptWK, WKStringCreateWithUTF8CString(plainText));
2813     WKPageLoadPlainTextString(toAPI(impl->pageProxy.get()), plainTextRef.get());
2814
2815     return true;
2816 }
2817
2818 Eina_Bool ewk_view_contents_set(Evas_Object* ewkView, const char* contents, size_t contentsSize, char* mimeType, char* encoding, char* baseUri)
2819 {
2820     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2821     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2822     EINA_SAFETY_ON_NULL_RETURN_VAL(contents, false);
2823
2824     if (contentsSize == 0)
2825         return false;
2826
2827     String mimeTypeString;
2828     if (mimeType)
2829         mimeTypeString = String::fromUTF8(mimeType);
2830     else
2831         mimeTypeString = String::fromUTF8("text/html");
2832
2833     String encodingString;
2834     if (encoding)
2835         encodingString = String::fromUTF8(encoding);
2836     else
2837         encodingString = String::fromUTF8("UTF-8");
2838
2839     String baseUriString;
2840     if (baseUri)
2841         baseUriString = String::fromUTF8(baseUri);
2842     else
2843         baseUriString = String::fromUTF8("about:blank");
2844
2845     WKRetainPtr<WKDataRef> contentsRef(AdoptWK, WKDataCreate(reinterpret_cast<const unsigned char*>(contents), contentsSize));
2846     impl->pageProxy->loadContentsbyMimeType(toImpl(contentsRef.get()), mimeTypeString, encodingString, baseUriString);
2847
2848     return true;
2849 }
2850
2851 Eina_Bool ewk_view_html_contents_set(Evas_Object* ewkView, const char* html, const char* baseUri)
2852 {
2853     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2854     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2855
2856     WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(html));
2857     WKRetainPtr<WKURLRef> baseURL(AdoptWK, WKURLCreateWithUTF8CString(baseUri));
2858
2859     WKPageLoadHTMLString(toAPI(impl->pageProxy.get()), htmlString.get(), baseURL.get());
2860
2861     return true;
2862 }
2863
2864 Eina_Bool ewk_view_page_visibility_state_set(Evas_Object* ewkView, Ewk_Page_Visibility_State pageVisibilityState, Eina_Bool initialState)
2865 {
2866     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2867     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2868
2869     TIZEN_LOGI("initialState (%d)", initialState);
2870 #if ENABLE(TIZEN_PAGE_VISIBILITY_API)
2871     WKPageSetPageVisibility(toAPI(impl->pageProxy.get()), static_cast<WKPageVisibilityState>(pageVisibilityState), initialState);
2872     return true;
2873 #else
2874     return false;
2875 #endif
2876 }
2877
2878 Eina_Bool ewk_view_user_agent_set(Evas_Object* ewkView, const char* userAgent)
2879 {
2880     EINA_SAFETY_ON_NULL_RETURN_VAL(userAgent, false);
2881
2882     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2883     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2884
2885     impl->userAgent = userAgent;
2886
2887     WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKStringCreateWithUTF8CString(userAgent));
2888     WKPageSetCustomUserAgent(toAPI(impl->pageProxy.get()), userAgentString.get());
2889
2890     return true;
2891 }
2892
2893 const char* ewk_view_user_agent_get(const Evas_Object* ewkView)
2894 {
2895     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2896     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2897
2898 #if OS(TIZEN)
2899     WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKPageCopyUserAgent(toAPI(impl->pageProxy.get())));
2900
2901     int length = WKStringGetMaximumUTF8CStringSize(userAgentString.get());
2902     OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
2903     WKStringGetUTF8CString(userAgentString.get(), buffer.get(), length);
2904     impl->userAgent = buffer.get();
2905 #else
2906     if (!impl->userAgent) {
2907         WKRetainPtr<WKStringRef> userAgentString(AdoptWK, WKPageCopyUserAgent(toAPI(impl->pageProxy.get())));
2908
2909         int length = WKStringGetMaximumUTF8CStringSize(userAgentString.get());
2910         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
2911         WKStringGetUTF8CString(userAgentString.get(), buffer.get(), length);
2912         impl->userAgent = buffer.get();
2913     }
2914 #endif
2915
2916     return impl->userAgent;
2917 }
2918
2919 #if OS(TIZEN)
2920 Eina_Bool ewk_view_application_name_for_user_agent_set(Evas_Object* ewkView, const char* applicationName)
2921 {
2922     EINA_SAFETY_ON_NULL_RETURN_VAL(applicationName, false);
2923
2924     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2925     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2926
2927     WKRetainPtr<WKStringRef> applicationNameString(AdoptWK, WKStringCreateWithUTF8CString(applicationName));
2928     WKPageSetApplicationNameForUserAgent(toAPI(impl->pageProxy.get()), applicationNameString.get());
2929
2930     return true;
2931 }
2932
2933 const char* ewk_view_application_name_for_user_agent_get(const Evas_Object* ewkView)
2934 {
2935     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
2936     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
2937
2938     WKRetainPtr<WKStringRef> applicationNameString(AdoptWK, WKPageCopyApplicationNameForUserAgent(toAPI(impl->pageProxy.get())));
2939
2940     int length = WKStringGetMaximumUTF8CStringSize(applicationNameString.get());
2941     OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
2942     WKStringGetUTF8CString(applicationNameString.get(), buffer.get(), length);
2943     impl->applicationName = buffer.get();
2944
2945     return impl->applicationName;
2946 }
2947 #endif
2948
2949 Eina_Bool ewk_view_custom_header_add(const Evas_Object* ewkView, const char* name, const char* value)
2950 {
2951 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2952     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2953     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2954
2955     WKRetainPtr<WKStringRef> customHeaderName(AdoptWK, WKStringCreateWithUTF8CString(name));
2956     WKRetainPtr<WKStringRef> customHeaderValue(AdoptWK, WKStringCreateWithUTF8CString(value));
2957
2958     WKPageAddCustomHeader(toAPI(impl->pageProxy.get()), customHeaderName.get(), customHeaderValue.get());
2959     return true;
2960 #else
2961     ERR("TIZEN_CUSTOM_HEADERS not enabled!");
2962     return false;
2963 #endif
2964 }
2965
2966 Eina_Bool ewk_view_custom_header_remove(const Evas_Object* ewkView, const char* name)
2967 {
2968 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2969     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2970     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2971
2972     WKRetainPtr<WKStringRef> customHeaderName(AdoptWK, WKStringCreateWithUTF8CString(name));
2973
2974     WKPageRemoveCustomHeader(toAPI(impl->pageProxy.get()), customHeaderName.get());
2975     return true;
2976 #else
2977     ERR("TIZEN_CUSTOM_HEADERS not enabled!");
2978     return false;
2979 #endif
2980 }
2981
2982 Eina_Bool ewk_view_custom_header_clear(const Evas_Object* ewkView)
2983 {
2984 #if ENABLE(TIZEN_CUSTOM_HEADERS)
2985     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
2986     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
2987
2988     WKPageClearCustomHeaders(toAPI(impl->pageProxy.get()));
2989     return true;
2990 #else
2991     ERR("TIZEN_CUSTOM_HEADERS not enabled!");
2992     return false;
2993 #endif
2994 }
2995
2996 #if ENABLE(TIZEN_WEBKIT2_VIEW_VISIBILITY)
2997 Eina_Bool ewk_view_visibility_set(Evas_Object* ewkView, Eina_Bool enable)
2998 {
2999     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3000     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3001
3002 #if ENABLE(TIZEN_DRAG_SUPPORT)
3003     if (impl->pageClient->isDragMode())
3004         impl->pageClient->setDragMode(false);
3005 #endif
3006
3007     impl->pageClient->setIsVisible(enable);
3008     return true;
3009 }
3010 #endif
3011
3012 #if ENABLE(TIZEN_BACKGROUND_DISK_CACHE)
3013 Eina_Bool ewk_view_foreground_set(Evas_Object* ewkView, Eina_Bool enable)
3014 {
3015     return true;
3016 }
3017 #endif
3018
3019 Evas_Object* ewk_view_screenshot_contents_get(const Evas_Object* ewkView, Eina_Rectangle viewArea, float scaleFactor, Evas* canvas)
3020 {
3021     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
3022
3023     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3024     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3025
3026     WKRect rect;
3027     rect.origin.x = viewArea.x;
3028     rect.origin.y = viewArea.y;
3029     rect.size.width = viewArea.w;
3030     rect.size.height = viewArea.h;
3031
3032     WKRetainPtr<WKImageRef> snapshot(AdoptWK, WKPageCreateSnapshot(toAPI(impl->pageProxy.get()), rect, scaleFactor));
3033     if (!snapshot.get())
3034         return 0;
3035
3036     RefPtr<cairo_surface_t> screenshotSurface = adoptRef(WKImageCreateCairoSurface(snapshot.get()));
3037
3038     Evas_Object* screenshotImage = evas_object_image_add(canvas);
3039     int surfaceWidth = cairo_image_surface_get_width(screenshotSurface.get());
3040     int surfaceHeight = cairo_image_surface_get_height(screenshotSurface.get());
3041     evas_object_image_size_set(screenshotImage, surfaceWidth, surfaceHeight);
3042     evas_object_image_colorspace_set(screenshotImage, EVAS_COLORSPACE_ARGB8888);
3043
3044     uint8_t* pixels = static_cast<uint8_t*>(evas_object_image_data_get(screenshotImage, true));
3045
3046     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)));
3047     RefPtr<cairo_t> cairo = adoptRef(cairo_create(imageSurface.get()));
3048
3049     cairo_set_source_surface(cairo.get(), screenshotSurface.get(), 0, 0);
3050     cairo_rectangle(cairo.get(), 0, 0, surfaceWidth, surfaceHeight);
3051     cairo_fill(cairo.get());
3052
3053     evas_object_image_smooth_scale_set(screenshotImage, true);
3054     evas_object_size_hint_min_set(screenshotImage, surfaceWidth, surfaceHeight);
3055     evas_object_resize(screenshotImage, surfaceWidth, surfaceHeight);
3056     evas_object_image_fill_set(screenshotImage, 0, 0, surfaceWidth, surfaceHeight);
3057     evas_object_image_data_set(screenshotImage, pixels);
3058
3059     return screenshotImage;
3060 }
3061
3062 unsigned int ewk_view_inspector_server_start(Evas_Object* ewkView, unsigned int port)
3063 {
3064 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
3065     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd, 0);
3066     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl, 0);
3067
3068     return impl->pageProxy->startInspectorServer(port);
3069 #else
3070     LOG_ERROR("TIZEN_REMOTE_WEB_INSPECTOR is disabled.\n");
3071     return 0;
3072 #endif
3073 }
3074
3075 Eina_Bool ewk_view_inspector_server_stop(Evas_Object* ewkView)
3076 {
3077 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
3078     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd, false);
3079     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl, false);
3080
3081     return impl->pageProxy->stopInspectorServer();
3082 #else
3083     LOG_ERROR("TIZEN_REMOTE_WEB_INSPECTOR is disabled.\n");
3084     return false;
3085 #endif
3086 }
3087
3088 void ewk_view_scroll_by(Evas_Object* ewkView, int deltaX, int deltaY)
3089 {
3090     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3091     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3092
3093     WKPageScrollBy(toAPI(impl->pageProxy.get()), toAPI(IntSize(deltaX, deltaY)));
3094 }
3095
3096 Eina_Bool ewk_view_scroll_pos_get(Evas_Object* ewkView, int* x, int* y)
3097 {
3098     if (x)
3099         *x = 0;
3100     if (y)
3101         *y = 0;
3102     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3103     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3104
3105     IntPoint scrollPosition = impl->pageClient->scrollPosition();
3106     if (x)
3107         *x = scrollPosition.x();
3108     if (y)
3109         *y = scrollPosition.y();
3110
3111     return true;
3112 }
3113
3114 Eina_Bool ewk_view_scroll_set(Evas_Object* ewkView, int x, int y)
3115 {
3116     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3117     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3118
3119     impl->pageProxy->scrollMainFrameTo(IntPoint(x, y));
3120     return true;
3121 }
3122
3123 Eina_Bool ewk_view_scroll_size_get(const Evas_Object* ewkView, int* width, int* height)
3124 {
3125     if (width)
3126         *width = 0;
3127     if (height)
3128         *height = 0;
3129     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3130     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3131
3132     IntSize contentsSize = impl->pageProxy->contentsSize();
3133 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
3134     contentsSize.scale(impl->pageClient->scaleFactor());
3135 #endif
3136
3137     if (width && contentsSize.width() > smartData->view.w)
3138         *width = contentsSize.width() - smartData->view.w;
3139     if (height && contentsSize.height() > smartData->view.h)
3140         *height = contentsSize.height() - smartData->view.h;
3141     return true;
3142 }
3143
3144 #if ENABLE(TIZEN_WEBKIT2_NOTIFY_POPUP_REPLY_STATUS)
3145 void ewkViewNotifyPopupReplyWaitingState(Evas_Object* ewkView, bool isWaiting)
3146 {
3147     if (isWaiting)
3148         evas_object_smart_callback_call(ewkView, "popup,reply,wait,start", 0);
3149     else
3150         evas_object_smart_callback_call(ewkView, "popup,reply,wait,finish", 0);
3151 }
3152 #endif
3153
3154 bool ewkViewRunJavaScriptAlert(Evas_Object* ewkView, WKStringRef alertText)
3155 {
3156     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3157     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3158     if (!impl->alertContext || !impl->alertContext->javascriptAlertCallback)
3159         return false;
3160     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->alertContext->ewkView == ewkView, false);
3161
3162     impl->isWaitingForJavaScriptPopupReply = true;
3163     int length = WKStringGetMaximumUTF8CStringSize(alertText);
3164     OwnArrayPtr<char> alertTextBuffer = adoptArrayPtr(new char[length]);
3165     WKStringGetUTF8CString(alertText, alertTextBuffer.get(), length);
3166     return impl->alertContext->javascriptAlertCallback(impl->alertContext->ewkView, alertTextBuffer.get(), impl->alertContext->userData) == EINA_TRUE;
3167 }
3168
3169 bool ewkViewRunJavaScriptConfirm(Evas_Object* ewkView, WKStringRef message)
3170 {
3171     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3172     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3173     if (!impl->confirmContext || !impl->confirmContext->javascriptConfirmCallback)
3174         return false;
3175     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->confirmContext->ewkView == ewkView, false);
3176
3177     impl->isWaitingForJavaScriptPopupReply = true;
3178     int length = WKStringGetMaximumUTF8CStringSize(message);
3179     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
3180     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3181     return impl->confirmContext->javascriptConfirmCallback(impl->confirmContext->ewkView, messageBuffer.get(), impl->confirmContext->userData) == EINA_TRUE;
3182 }
3183
3184 bool ewkViewRunJavaScriptPrompt(Evas_Object* ewkView, WKStringRef message, WKStringRef defaultValue)
3185 {
3186     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3187     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3188     if (!impl->promptContext || !impl->promptContext->javascriptPromptCallback)
3189         return false;
3190     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->promptContext->ewkView == ewkView, false);
3191
3192     impl->isWaitingForJavaScriptPopupReply = true;
3193     int length = WKStringGetMaximumUTF8CStringSize(message);
3194     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
3195     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3196     length = WKStringGetMaximumUTF8CStringSize(defaultValue);
3197     OwnArrayPtr<char> defaultValueBuffer = adoptArrayPtr(new char[length]);
3198     WKStringGetUTF8CString(defaultValue, defaultValueBuffer.get(), length);
3199     return impl->promptContext->javascriptPromptCallback(impl->promptContext->ewkView, messageBuffer.get(), defaultValueBuffer.get(), impl->promptContext->userData) == EINA_TRUE;
3200 }
3201
3202 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
3203 bool ewk_view_run_before_unload_confirm_panel(Evas_Object* ewkView, WKStringRef message)
3204 {
3205     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3206     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3207     if (!impl->beforeUnloadConfirmPanelContext || !impl->beforeUnloadConfirmPanelContext->beforeUnloadConfirmPanelCallback)
3208         return false;
3209     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->beforeUnloadConfirmPanelContext->ewkView == ewkView, false);
3210
3211     impl->isWaitingForJavaScriptPopupReply = true;
3212     int length = WKStringGetMaximumUTF8CStringSize(message);
3213     OwnArrayPtr<char> messageBuffer = adoptArrayPtr(new char[length]);
3214     WKStringGetUTF8CString(message, messageBuffer.get(), length);
3215     bool result = impl->beforeUnloadConfirmPanelContext->beforeUnloadConfirmPanelCallback(impl->beforeUnloadConfirmPanelContext->ewkView, messageBuffer.get(), impl->beforeUnloadConfirmPanelContext->userData) == EINA_TRUE;
3216     return result;
3217 }
3218 #endif
3219
3220 bool ewkViewRunOpenPanel(Evas_Object* ewkView, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener)
3221 {
3222     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3223     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3224     if (!impl->openpanelContext || !impl->openpanelContext->openPanelCallback)
3225         return false;
3226
3227     EINA_SAFETY_ON_FALSE_RETURN_VAL(impl->openpanelContext->ewkView == ewkView, false);
3228
3229     impl->openPanelListener = listener;
3230
3231     Eina_Bool allowMultipleFiles = WKOpenPanelParametersGetAllowsMultipleFiles(parameters) ? EINA_TRUE : EINA_FALSE;
3232     Eina_List* acceptedMimeTypes = 0;
3233     WKRetainPtr<WKArrayRef> array(AdoptWK, WKOpenPanelParametersCopyAcceptedMIMETypes(parameters));
3234     size_t len = WKArrayGetSize(array.get());
3235     for (size_t i = 0; i < len; i++) {
3236         WKTypeRef item = WKArrayGetItemAtIndex(array.get(), i);
3237         if (WKGetTypeID(item) != WKStringGetTypeID())
3238             continue;
3239         WKStringRef mime = static_cast<WKStringRef>(item);
3240         int length = WKStringGetMaximumUTF8CStringSize(mime);
3241         char* buffer = new char[length];
3242         WKStringGetUTF8CString(mime, buffer, length);
3243         acceptedMimeTypes = eina_list_append(acceptedMimeTypes, static_cast<const void*>(const_cast<const char*>(buffer)));
3244     }
3245     const char* capture = 0;
3246 #if ENABLE(MEDIA_CAPTURE)
3247     WKRetainPtr<WKStringRef> captureRef(AdoptWK, WKOpenPanelParametersCopyCapture(parameters));
3248     capture = eina_stringshare_add(toImpl(captureRef.get())->string().utf8().data());
3249 #endif
3250     bool result = impl->openpanelContext->openPanelCallback(impl->openpanelContext->ewkView, allowMultipleFiles, acceptedMimeTypes, capture, 0);
3251     if (!acceptedMimeTypes)
3252         return result;
3253
3254     Eina_List* list;
3255     void* data = 0;
3256     EINA_LIST_FOREACH(acceptedMimeTypes, list, data)
3257         delete[] (char*)data;
3258     eina_list_free(acceptedMimeTypes);
3259     return result;
3260 }
3261
3262 void ewk_view_javascript_alert_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Alert_Callback callback, void* userData)
3263 {
3264     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3265     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3266
3267     if (!impl->alertContext)
3268         impl->alertContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3269     impl->alertContext->javascriptAlertCallback = callback;
3270     impl->alertContext->ewkView = ewkView;
3271     impl->alertContext->userData = userData;
3272 }
3273
3274 void ewk_view_javascript_alert_reply(Evas_Object* ewkView)
3275 {
3276     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3277     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3278
3279     WKPageReplyJavaScriptAlert(toAPI(impl->page()));
3280     impl->isWaitingForJavaScriptPopupReply = false;
3281 }
3282
3283 void ewk_view_javascript_confirm_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Confirm_Callback callback, void* userData)
3284 {
3285     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3286     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3287
3288     if (!impl->confirmContext)
3289         impl->confirmContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3290     impl->confirmContext->javascriptConfirmCallback = callback;
3291     impl->confirmContext->ewkView = ewkView;
3292     impl->confirmContext->userData = userData;
3293 }
3294
3295 void ewk_view_javascript_confirm_reply(Evas_Object* ewkView, Eina_Bool result)
3296 {
3297     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3298     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3299
3300     WKPageReplyJavaScriptConfirm(toAPI(impl->page()), result == EINA_TRUE);
3301     impl->isWaitingForJavaScriptPopupReply = false;
3302 }
3303
3304 void ewk_view_javascript_prompt_callback_set(Evas_Object* ewkView, Ewk_View_JavaScript_Prompt_Callback callback, void* userData)
3305 {
3306     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3307     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3308
3309     if (!impl->promptContext)
3310         impl->promptContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3311     impl->promptContext->javascriptPromptCallback = callback;
3312     impl->promptContext->ewkView = ewkView;
3313     impl->promptContext->userData = userData;
3314 }
3315
3316 void ewk_view_javascript_prompt_reply(Evas_Object* ewkView, const char* result)
3317 {
3318     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3319     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3320
3321     WKRetainPtr<WKStringRef> resultString(AdoptWK, WKStringCreateWithUTF8CString(result));
3322     WKPageReplyJavaScriptPrompt(toAPI(impl->page()), result ? resultString.get() : 0);
3323     impl->isWaitingForJavaScriptPopupReply = false;
3324 }
3325
3326 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
3327 void ewk_view_before_unload_confirm_panel_callback_set(Evas_Object* ewkView, Ewk_View_Before_Unload_Confirm_Panel_Callback callback, void* userData)
3328 {
3329     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3330     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3331
3332     if (!impl->beforeUnloadConfirmPanelContext)
3333         impl->beforeUnloadConfirmPanelContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3334     impl->beforeUnloadConfirmPanelContext->beforeUnloadConfirmPanelCallback = callback;
3335     impl->beforeUnloadConfirmPanelContext->ewkView = ewkView;
3336     impl->beforeUnloadConfirmPanelContext->userData = userData;
3337 }
3338
3339 void ewk_view_before_unload_confirm_panel_reply(Evas_Object* ewkView, Eina_Bool result)
3340 {
3341     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3342     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3343
3344     WKPageReplyBeforeUnloadConfirmPanel(toAPI(impl->page()), result == EINA_TRUE);
3345     impl->isWaitingForJavaScriptPopupReply = false;
3346 }
3347 #endif
3348
3349 void ewk_view_open_panel_callback_set(Evas_Object* ewkView, Ewk_View_Open_Panel_Callback callback, void* userData)
3350 {
3351     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3352     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3353
3354     if (!impl->openpanelContext)
3355         impl->openpanelContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
3356
3357     impl->openpanelContext->openPanelCallback = callback;
3358     impl->openpanelContext->ewkView = ewkView;
3359     impl->openpanelContext->userData = userData;
3360 }
3361
3362 void ewk_view_open_panel_reply(Evas_Object* ewkView, Eina_List* fileUrls, Eina_Bool result)
3363 {
3364     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3365     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3366
3367     if (!impl->openPanelListener)
3368         return;
3369
3370     unsigned int size = eina_list_count(fileUrls);
3371     if ((result == EINA_FALSE) || (size == 0)) {
3372         WKOpenPanelResultListenerCancel(impl->openPanelListener);
3373         impl->openPanelListener = 0;
3374         return;
3375     }
3376
3377     WKTypeRef* items = new WKTypeRef[size];
3378     Eina_List* list;
3379     void* data;
3380     unsigned int i = 0;
3381     KURL base(KURL(), "file://");
3382     EINA_LIST_FOREACH(fileUrls, list, data) {
3383         KURL url(base, String::fromUTF8(static_cast<char*>(data)));
3384         items[i++] = WKURLCreateWithUTF8CString(url.string().utf8().data());
3385     }
3386     WKRetainPtr<WKArrayRef> filesArray(AdoptWK, WKArrayCreate(items, size));
3387     WKOpenPanelResultListenerChooseFiles(impl->openPanelListener, filesArray.get());
3388     impl->openPanelListener = 0;
3389     delete [] items;
3390     eina_list_free(fileUrls);
3391 }
3392
3393 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3394 static void didGetWebAppCapable(WKBooleanRef capable, WKErrorRef, void* context)
3395 {
3396     EINA_SAFETY_ON_NULL_RETURN(capable);
3397     EINA_SAFETY_ON_NULL_RETURN(context);
3398
3399     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3400
3401     ASSERT(webAppContext->webAppCapableCallback);
3402
3403     TIZEN_LOGI("webAppCapableCallback exist. capable(%b)", capable);
3404     if (capable)
3405         webAppContext->webAppCapableCallback(toImpl(capable)->value(), webAppContext->userData);
3406     else
3407         webAppContext->webAppCapableCallback(0, webAppContext->userData);
3408
3409     delete webAppContext;
3410 }
3411
3412 static void didGetWebAppIconURL(WKStringRef iconURL, WKErrorRef, void* context)
3413 {
3414     EINA_SAFETY_ON_NULL_RETURN(iconURL);
3415     EINA_SAFETY_ON_NULL_RETURN(context);
3416
3417     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3418
3419     EWK_VIEW_SD_GET_OR_RETURN(webAppContext->ewkView, smartData);
3420     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3421
3422     ASSERT(webAppContext->webAppIconURLCallback);
3423
3424     if (iconURL) {
3425         impl->webAppIconURL = toImpl(iconURL)->string().utf8().data();
3426         webAppContext->webAppIconURLCallback(impl->webAppIconURL, webAppContext->userData);
3427     } else
3428         webAppContext->webAppIconURLCallback(0, webAppContext->userData);
3429
3430     delete webAppContext;
3431 }
3432
3433 static void didGetWebAppIconURLs(WKDictionaryRef iconURLs, WKErrorRef, void* context)
3434 {
3435     EINA_SAFETY_ON_NULL_RETURN(iconURLs);
3436     EINA_SAFETY_ON_NULL_RETURN(context);
3437
3438     Ewk_View_Callback_Context* webAppContext = static_cast<Ewk_View_Callback_Context*>(context);
3439
3440     EWK_VIEW_SD_GET_OR_RETURN(webAppContext->ewkView, smartData);
3441     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3442
3443     ASSERT(webAppContext->webAppIconURLsCallback);
3444
3445     if (impl->webAppIconURLs) {
3446         void* data = 0;
3447         EINA_LIST_FREE(impl->webAppIconURLs, data)
3448             ewkWebAppIconDataDelete(static_cast<Ewk_Web_App_Icon_Data*>(data));
3449     }
3450
3451     WKRetainPtr<WKArrayRef> wkKeys(AdoptWK, WKDictionaryCopyKeys(iconURLs));
3452     size_t iconURLCount = WKArrayGetSize(wkKeys.get());
3453     for (size_t i = 0; i < iconURLCount; i++) {
3454         WKStringRef urlRef = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkKeys.get(), i));
3455         WKStringRef sizeRef = static_cast<WKStringRef>(WKDictionaryGetItemForKey(iconURLs, urlRef));
3456         impl->webAppIconURLs = eina_list_append(impl->webAppIconURLs, ewkWebAppIconDataCreate(sizeRef, urlRef));
3457     }
3458     TIZEN_LOGI("webAppIconURLsCallback exist. found %d icon urls", iconURLCount);
3459
3460     webAppContext->webAppIconURLsCallback(impl->webAppIconURLs, webAppContext->userData);
3461     delete webAppContext;
3462 }
3463 #endif
3464
3465 Eina_Bool ewk_view_web_application_capable_get(Evas_Object* ewkView, Ewk_Web_App_Capable_Get_Callback callback, void* userData)
3466 {
3467 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3468     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3469     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3470     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3471
3472     TIZEN_LOGI("callback(%d), userData(%d)", callback, userData);
3473     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3474     context->webAppCapableCallback = callback;
3475     context->ewkView = ewkView;
3476     context->userData = userData;
3477
3478     WKPageGetWebAppCapable(toAPI(impl->pageProxy.get()), context, didGetWebAppCapable);
3479
3480     return true;
3481 #else
3482     return false;
3483 #endif
3484 }
3485
3486 Eina_Bool ewk_view_web_application_icon_url_get(Evas_Object* ewkView, Ewk_Web_App_Icon_URL_Get_Callback callback, void* userData)
3487 {
3488 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3489     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3490     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3491     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3492
3493     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3494     context->webAppIconURLCallback = callback;
3495     context->ewkView = ewkView;
3496     context->userData = userData;
3497
3498     WKPageGetWebAppIconURL(toAPI(impl->page()), context, didGetWebAppIconURL);
3499
3500     return true;
3501 #else
3502     return 0;
3503 #endif
3504 }
3505
3506 Eina_Bool ewk_view_web_application_icon_urls_get(Evas_Object* ewkView, Ewk_Web_App_Icon_URLs_Get_Callback callback, void* userData)
3507 {
3508 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
3509     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3510     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3511     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3512
3513     TIZEN_LOGI("callback(%d), userData(%d)", callback, userData);
3514     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3515     context->webAppIconURLsCallback = callback;
3516     context->ewkView = ewkView;
3517     context->userData = userData;
3518
3519     WKPageGetWebAppIconURLs(toAPI(impl->page()), context, didGetWebAppIconURLs);
3520
3521     return true;
3522 #else
3523     UNUSED_PARAM(ewkView);
3524     UNUSED_PARAM(callback);
3525     UNUSED_PARAM(userData);
3526     return 0;
3527 #endif
3528 }
3529
3530 Eina_Bool ewk_view_command_execute(Evas_Object* ewkView, const char* command, const char* value)
3531 {
3532     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3533     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3534     EINA_SAFETY_ON_NULL_RETURN_VAL(command, false);
3535
3536     WKRetainPtr<WKStringRef> commandString(AdoptWK, WKStringCreateWithUTF8CString(command));
3537     WKRetainPtr<WKStringRef> valueString(AdoptWK, WKStringCreateWithUTF8CString(value));
3538     WKPageExecuteCommandWithArgument(toAPI(impl->pageProxy.get()), commandString.get(), valueString.get());
3539
3540     return true;
3541 }
3542
3543 Eina_Bool ewk_view_contents_size_get(Evas_Object* ewkView, Evas_Coord* width, Evas_Coord* height)
3544 {
3545     if (width)
3546         *width = 0;
3547     if (height)
3548         *height = 0;
3549
3550     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3551     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3552
3553     IntSize contentsSize = impl->pageProxy->contentsSize();
3554
3555     if (width)
3556         *width = contentsSize.width();
3557     if (height)
3558         *height = contentsSize.height();
3559
3560     return true;
3561 }
3562
3563 Eina_Bool ewk_view_contents_pdf_get_temp(Evas_Object* ewkView, int width, int height, const char* fileName)
3564 {
3565 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
3566     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3567     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3568     EINA_SAFETY_ON_NULL_RETURN_VAL(fileName, false);
3569
3570     IntSize contentsSize = impl->pageProxy->contentsSize();
3571     WKPageGetSnapshotPdfFile(toAPI(impl->pageProxy.get()), toAPI(IntSize(width, height)), toAPI(IntSize(contentsSize.width(), contentsSize.height())), WKStringCreateWithUTF8CString(fileName));
3572
3573     return true;
3574 #else
3575     return false;
3576 #endif
3577 }
3578
3579 Eina_Bool ewk_view_contents_pdf_get(Evas_Object* ewkView, int width, int height, const char* fileName)
3580 {
3581 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
3582     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3583     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3584     EINA_SAFETY_ON_NULL_RETURN_VAL(fileName, false);
3585
3586     IntSize contentsSize = impl->pageProxy->contentsSize();
3587     WKPageGetSnapshotPdfFile(toAPI(impl->pageProxy.get()), toAPI(IntSize(width, height)), toAPI(IntSize(contentsSize.width(), contentsSize.height())), WKStringCreateWithUTF8CString(fileName));
3588
3589     return true;
3590 #else
3591     return false;
3592 #endif
3593 }
3594
3595 static void runJavaScriptCallback(WKSerializedScriptValueRef scriptValue, WKErrorRef error, void* context)
3596 {
3597     EINA_SAFETY_ON_NULL_RETURN(context);
3598     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3599
3600     if (!callbackContext->scriptExecuteCallback) {
3601         delete callbackContext;
3602         return;
3603     }
3604
3605     JSGlobalContextRef jsGlobalContext = ewkViewGetJavascriptGlobalContext(callbackContext->ewkView);
3606
3607     if (scriptValue) {
3608         JSValueRef value = WKSerializedScriptValueDeserialize(scriptValue, jsGlobalContext, 0);
3609         JSRetainPtr<JSStringRef> jsStringValue(JSValueToStringCopy(jsGlobalContext, value, 0));
3610         size_t length = JSStringGetMaximumUTF8CStringSize(jsStringValue.get());
3611         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
3612         JSStringGetUTF8CString(jsStringValue.get(), buffer.get(), length);
3613         callbackContext->scriptExecuteCallback(callbackContext->ewkView, buffer.get(), callbackContext->userData);
3614     } else
3615         callbackContext->scriptExecuteCallback(callbackContext->ewkView, 0, callbackContext->userData);
3616
3617     delete callbackContext;
3618 }
3619
3620 Eina_Bool ewk_view_script_execute(Evas_Object* ewkView, const char* script, Ewk_View_Script_Execute_Callback callback, void* user_data)
3621 {
3622     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3623     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3624     EINA_SAFETY_ON_NULL_RETURN_VAL(script, false);
3625     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->pageClient, false);
3626
3627     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3628     context->scriptExecuteCallback = callback;
3629     context->ewkView = ewkView;
3630     context->userData = user_data;
3631     WKRetainPtr<WKStringRef> scriptString(AdoptWK, WKStringCreateWithUTF8CString(script));
3632     WKPageRunJavaScriptInMainFrame(toAPI(impl->pageProxy.get()), scriptString.get(), context, runJavaScriptCallback);
3633
3634     return true;
3635 }
3636
3637 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
3638 static void didGetWebStorageQuota(WKUInt32Ref quota, WKErrorRef error, void* context)
3639 {
3640     Ewk_View_Callback_Context* storageContext = static_cast<Ewk_View_Callback_Context*>(context);
3641
3642     if (quota)
3643         storageContext->webStorageQuotaCallback(toImpl(quota)->value(), storageContext->userData);
3644     else
3645         storageContext->webStorageQuotaCallback(0, storageContext->userData);
3646
3647     delete storageContext;
3648 }
3649 #endif
3650
3651 Eina_Bool ewk_view_web_storage_quota_get(const Evas_Object* ewkView, Ewk_Web_Storage_Quota_Get_Callback resultCallback, void* userData)
3652 {
3653 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
3654     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, false);
3655     EINA_SAFETY_ON_NULL_RETURN_VAL(resultCallback, false);
3656     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3657     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3658     TIZEN_LOGI("resultCallback (%p)", resultCallback);
3659
3660     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3661     context->webStorageQuotaCallback = resultCallback;
3662     context->userData = userData;
3663
3664     WKPageRef pageRef = toAPI(impl->page());
3665     WKPageGetWebStorageQuota(pageRef, context, didGetWebStorageQuota);
3666
3667     return true;
3668 #else
3669     return false;
3670 #endif
3671 }
3672
3673 Eina_Bool ewk_view_web_storage_quota_set(Evas_Object* ewkView, uint32_t quota)
3674 {
3675 #if ENABLE(TIZEN_WEB_STORAGE)
3676     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, false);
3677     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3678     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3679
3680     TIZEN_LOGI("quota (%d)", quota);
3681     WKPageRef pageRef = toAPI(impl->page());
3682     WKPageSetWebStorageQuota(pageRef, quota);
3683
3684     return true;
3685 #else
3686     return false;
3687 #endif
3688 }
3689
3690 static void getContentsAsStringCallback(WKStringRef plain_text, WKErrorRef error, void* context)
3691 {
3692     EINA_SAFETY_ON_NULL_RETURN(context);
3693     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3694
3695     ASSERT(callbackContext->plainTextGetCallback);
3696
3697     if (plain_text) {
3698         size_t length = WKStringGetMaximumUTF8CStringSize(plain_text);
3699         OwnArrayPtr<char> buffer = adoptArrayPtr(new char[length]);
3700         WKStringGetUTF8CString(plain_text, buffer.get(), length);
3701
3702         callbackContext->plainTextGetCallback(callbackContext->ewkView, buffer.get(), callbackContext->userData);
3703     } else
3704         callbackContext->plainTextGetCallback(callbackContext->ewkView, 0, callbackContext->userData);
3705
3706     delete callbackContext;
3707 }
3708
3709 Eina_Bool ewk_view_plain_text_get(Evas_Object* ewkView, Ewk_View_Plain_Text_Get_Callback callback, void* user_data)
3710 {
3711     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3712     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3713     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3714     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->pageClient, false);
3715
3716     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3717     context->plainTextGetCallback = callback;
3718     context->ewkView = ewkView;
3719     context->userData = user_data;
3720     WKPageGetContentsAsString(toAPI(impl->pageProxy.get()), context, getContentsAsStringCallback);
3721
3722     return true;
3723 }
3724
3725 #if ENABLE(TIZEN_SUPPORT_MHTML)
3726 /**
3727  * @internal
3728  * Callback function used for ewk_view_mhtml_data_get().
3729  */
3730 static void getContentsAsMHTMLCallback(WKDataRef wkData, WKErrorRef, void* context)
3731 {
3732     EINA_SAFETY_ON_NULL_RETURN(context);
3733     Ewk_View_Callback_Context* callbackContext = static_cast<Ewk_View_Callback_Context*>(context);
3734
3735     ASSERT(callbackContext->mhtmlDataGetCallback);
3736
3737     callbackContext->mhtmlDataGetCallback(callbackContext->ewkView, reinterpret_cast<const char*>(WKDataGetBytes(wkData)), callbackContext->userData);
3738
3739     delete callbackContext;
3740 }
3741
3742 Eina_Bool ewk_view_mhtml_data_get(Evas_Object* ewkView, Ewk_View_MHTML_Data_Get_Callback callback, void* user_data)
3743 {
3744     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
3745     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3746     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3747
3748     Ewk_View_Callback_Context* context = new Ewk_View_Callback_Context;
3749     context->mhtmlDataGetCallback = callback;
3750     context->ewkView = ewkView;
3751     context->userData = user_data;
3752
3753     WKPageGetContentsAsMHTMLData(toAPI(impl->page()), false, context, getContentsAsMHTMLCallback);
3754
3755     return true;
3756 }
3757 #endif // ENABLE(TIZEN_SUPPORT_MHTML)
3758
3759 Ewk_Hit_Test* ewk_view_hit_test_new(Evas_Object* ewkView, int x, int y, int hitTestMode)
3760 {
3761 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
3762     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
3763     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
3764
3765     IntPoint pointForHitTest = impl->transformFromScene().mapPoint(IntPoint(x, y));
3766     WebHitTestResult::Data hitTestResultData = impl->pageProxy->hitTestResultAtPoint(pointForHitTest, hitTestMode);
3767     Ewk_Hit_Test* hitTest = ewkHitTestCreate(hitTestResultData);
3768
3769     return hitTest;
3770 #else
3771     return 0;
3772 #endif
3773 }
3774
3775 Ewk_History* ewk_view_history_get(Evas_Object* ewkView)
3776 {
3777     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkView, 0);
3778     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3779     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3780     WebPageProxy* page = impl->page();
3781     EINA_SAFETY_ON_NULL_RETURN_VAL(page, 0);
3782
3783     return ewkHistoryCreate(WKPageGetBackForwardList(toAPI(page)));
3784 }
3785
3786 Eina_Bool ewk_view_recording_surface_enable_set(Evas_Object* ewkView, Eina_Bool enable)
3787 {
3788     return false;
3789 }
3790
3791 Eina_Bool ewk_view_notification_closed(Evas_Object* ewkView, Eina_List* ewkNotifications)
3792 {
3793 #if ENABLE(TIZEN_NOTIFICATIONS)
3794     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3795     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3796     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->context, false);
3797
3798     TIZEN_LOGI("ewkNotifications (%p)", ewkNotifications);
3799     if (!eina_list_count(ewkNotifications))
3800         return false;
3801
3802     Eina_List* listIterator = 0;
3803     void* data = 0;
3804     Vector<WKTypeRef> ids;
3805     EINA_LIST_FOREACH(ewkNotifications, listIterator, data) {
3806         Ewk_Notification* notification = static_cast<Ewk_Notification*>(data);
3807         WKUInt64Ref idRef = WKUInt64Create(ewk_notification_id_get(notification));
3808         ids.append(idRef);
3809         impl->notifications = eina_list_remove(impl->notifications, notification);
3810     }
3811
3812     WKRetainPtr<WKArrayRef> notificationIDsArray(AdoptWK, WKArrayCreate(ids.data(), ids.size()));
3813     WKNotificationManagerRef notificationManager = WKContextGetNotificationManager(impl->context->wkContext());
3814     WKNotificationManagerProviderDidCloseNotifications(notificationManager, notificationIDsArray.get());
3815     ewkNotificationDeleteNotificationList(ewkNotifications);
3816
3817     return true;
3818 #else
3819     return false;
3820 #endif
3821 }
3822
3823 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
3824 static Eina_List* createPopupMenuList(const Vector<WebPopupItem>& items)
3825 {
3826     Eina_List* popupItems = 0;
3827     size_t size = items.size();
3828     for (size_t i = 0; i < size; ++i)
3829         popupItems = eina_list_append(popupItems, Ewk_Popup_Menu_Item::create(items[i]).leakPtr());
3830     TIZEN_LOGI("size : %d", size);
3831     return popupItems;
3832 }
3833
3834 static void releasePopupMenuList(Eina_List* popupMenuItems)
3835 {
3836     if (!popupMenuItems)
3837         return;
3838
3839     void* item;
3840     EINA_LIST_FREE(popupMenuItems, item)
3841         delete static_cast<Ewk_Popup_Menu_Item*>(item);
3842 }
3843 #endif
3844
3845 Eina_Bool ewk_view_popup_menu_close(Evas_Object* ewkView)
3846 {
3847     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3848     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3849     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api, false);
3850 #if OS(TIZEN)
3851     TIZEN_LOGI("proxy : %p", impl->popupMenuProxy);
3852 #endif
3853
3854     if (!impl->popupMenuProxy)
3855         return false;
3856
3857     impl->popupMenuProxy = 0;
3858
3859     if (smartData->api->popup_menu_hide)
3860         smartData->api->popup_menu_hide(smartData);
3861 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
3862     ewk_view_touch_events_enabled_set(ewkView, true);
3863
3864     releasePopupMenuList(impl->popupMenuItems);
3865     impl->popupMenuItems = 0;
3866 #else
3867     void* item;
3868     EINA_LIST_FREE(impl->popupMenuItems, item)
3869         delete static_cast<Ewk_Popup_Menu_Item*>(item);
3870 #endif
3871
3872     return true;
3873 }
3874
3875 Eina_Bool ewk_view_popup_menu_select(Evas_Object* ewkView, unsigned int selectedIndex)
3876 {
3877     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3878     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3879     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->popupMenuProxy, false);
3880 #if OS(TIZEN)
3881     TIZEN_LOGI("proxy : %p / index : %d", impl->popupMenuProxy, selectedIndex);
3882
3883     if (!impl->popupMenuItems)
3884         return false;
3885 #endif
3886
3887     if (selectedIndex >= eina_list_count(impl->popupMenuItems))
3888         return false;
3889
3890     impl->popupMenuProxy->valueChanged(selectedIndex);
3891
3892     return true;
3893 }
3894
3895 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
3896 void ewk_view_popup_menu_update(Evas_Object* ewkView, TextDirection textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex)
3897 {
3898     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3899     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3900     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
3901     TIZEN_LOGI("proxy : %p", impl->popupMenuProxy);
3902
3903     if (!impl->popupMenuProxy)
3904         return;
3905
3906     if (!smartData->api->popup_menu_update)
3907         return;
3908
3909     releasePopupMenuList(impl->popupMenuItems);
3910     impl->popupMenuItems = createPopupMenuList(items);
3911
3912     // TODO: Instead of passing a dummy rect, updated rect should be coming from WebProcess
3913     smartData->api->popup_menu_update(smartData, IntRect(), static_cast<Ewk_Text_Direction>(textDirection), impl->popupMenuItems, selectedIndex);
3914 }
3915 #endif
3916
3917 #if ENABLE(TIZEN_MULTIPLE_SELECT)
3918 Eina_Bool ewk_view_popup_menu_multiple_select(Evas_Object* ewkView, Eina_Inarray* changeList)
3919 {
3920     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3921     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3922     EINA_SAFETY_ON_NULL_RETURN_VAL(impl->popupMenuProxy, false);
3923
3924     Vector<int> selectedIndex;
3925
3926     if (!impl->popupMenuItems)
3927         return false;
3928
3929     Eina_Iterator* itr;
3930     void* data;
3931     itr = eina_inarray_iterator_new(changeList);
3932     EINA_ITERATOR_FOREACH(itr, data)
3933     {
3934         int* pData = static_cast<int*>(data);
3935         selectedIndex.append(*pData);
3936     }
3937     eina_iterator_free(itr);
3938
3939     impl->popupMenuProxy->multipleValueChanged(selectedIndex);
3940     return true;
3941 }
3942 #endif
3943
3944 void ewk_view_orientation_send(Evas_Object* ewkView, int orientation)
3945 {
3946 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
3947     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
3948     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
3949     TIZEN_LOGI("orientation : %d", orientation);
3950
3951     if (orientation != 0 && orientation != 90 && orientation != -90 && orientation != 180)
3952         return;
3953
3954     if (impl->orientation == orientation)
3955         return;
3956
3957     impl->orientation = orientation;
3958
3959     impl->pageProxy->sendOrientationChangeEvent(orientation);
3960 #endif
3961 }
3962
3963 void ewkViewFrameRendered(Evas_Object* ewkView)
3964 {
3965     evas_object_smart_callback_call(ewkView, "frame,rendered", 0);
3966 }
3967
3968 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
3969 Eina_Bool ewk_view_text_selection_enable_set(Evas_Object* ewkView, Eina_Bool enable)
3970 {
3971     return ewk_settings_text_selection_enabled_set(ewk_view_settings_get(ewkView), enable);
3972 }
3973
3974 Eina_Bool ewk_view_text_selection_range_get(Evas_Object* ewkView, Eina_Rectangle* leftRect, Eina_Rectangle* rightRect)
3975 {
3976     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
3977     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
3978
3979     IntRect leftSelectionRect;
3980     IntRect rightSelectionRect;
3981     if (!impl->pageProxy->getSelectionHandlers(leftSelectionRect, rightSelectionRect)) {
3982         leftRect->x = 0;
3983         leftRect->y = 0;
3984         leftRect->w = 0;
3985         leftRect->h = 0;
3986
3987         rightRect->x = 0;
3988         rightRect->y = 0;
3989         rightRect->w = 0;
3990         rightRect->h = 0;
3991         return false;
3992     }
3993
3994     AffineTransform contentToScreen = impl->transformToScene();
3995     leftSelectionRect = contentToScreen.mapRect(leftSelectionRect);
3996     rightSelectionRect = contentToScreen.mapRect(rightSelectionRect);
3997
3998     leftRect->x = leftSelectionRect.x();
3999     leftRect->y = leftSelectionRect.y();
4000     leftRect->w = leftSelectionRect.width();
4001     leftRect->h = leftSelectionRect.height();
4002
4003     rightRect->x = rightSelectionRect.x();
4004     rightRect->y = rightSelectionRect.y();
4005     rightRect->w = rightSelectionRect.width();
4006     rightRect->h = rightSelectionRect.height();
4007
4008     return true;;
4009 }
4010
4011 const char* ewk_view_text_selection_text_get(Evas_Object* ewkView)
4012 {
4013     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
4014     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
4015
4016     const CString selectedString = impl->pageProxy->getSelectionText().utf8();
4017     impl->selectedText = selectedString.data();
4018
4019     return impl->selectedText;
4020 }
4021
4022 Eina_Bool ewk_view_auto_clear_text_selection_mode_set(Evas_Object* ewkView, Eina_Bool enable)
4023 {
4024     return ewk_settings_clear_text_selection_automatically_set(ewk_view_settings_get(ewkView), enable);
4025 }
4026
4027 Eina_Bool ewk_view_auto_clear_text_selection_mode_get(Evas_Object* ewkView)
4028 {
4029     return ewk_settings_clear_text_selection_automatically_get(ewk_view_settings_get(ewkView));
4030 }
4031
4032 Eina_Bool ewk_view_text_selection_range_clear(Evas_Object* ewkView)
4033 {
4034     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4035     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4036
4037     bool isTextSelectionMode = impl->pageClient->isTextSelectionMode();
4038     impl->pageClient->setIsTextSelectionMode(false);
4039     return isTextSelectionMode;
4040 }
4041 #endif // #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
4042
4043 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
4044 void ewkViewInputPickerRequest(Evas_Object* ewkView, Ewk_Input_Type inputType, const String& inputValue)
4045 {
4046     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4047     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
4048     EINA_SAFETY_ON_NULL_RETURN(smartData->api->input_picker_show);
4049
4050     smartData->api->input_picker_show(smartData, inputType, inputValue.utf8().data());
4051 }
4052 #endif
4053
4054 #if ENABLE(TIZEN_VIEWPORT_META_TAG)
4055 void ewkViewGetWindowFrame(Evas_Object* ewkView, int *x, int *y, int *w, int *h)
4056 {
4057     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4058     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4059     IntPoint drawingPosition = (IntPoint)(impl->pageClient->visibleContentRect().location() - impl->pageClient->scrollPosition());
4060     if (x)
4061         *x = drawingPosition.x();
4062     if (y)
4063         *y = drawingPosition.y();
4064     if (w)
4065         *w = impl->pageClient->visibleContentRect().width();
4066     if (h)
4067         *h = impl->pageClient->visibleContentRect().height();
4068 }
4069 #endif
4070
4071 void ewk_view_focused_input_element_value_set(Evas_Object* ewkView, const char* value)
4072 {
4073 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
4074     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4075     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4076
4077     impl->pageProxy->setFocusedInputElementValue(String::fromUTF8(value));
4078 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
4079 }
4080
4081 const char* ewk_view_focused_input_element_value_get(Evas_Object* ewkView)
4082 {
4083 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
4084     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
4085     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, 0);
4086
4087     impl->inputValue = impl->pageProxy->getFocusedInputElementValue().utf8().data();
4088     return impl->inputValue;
4089 #else
4090     return 0;
4091 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
4092 }
4093
4094 #if ENABLE(TIZEN_DATALIST_ELEMENT)
4095 void ewkViewDataListShowRequest(Evas_Object* ewkView, Ewk_Input_Type inputType, Vector<String> optionList)
4096 {
4097     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4098     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4099     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
4100     EINA_SAFETY_ON_NULL_RETURN(smartData->api->data_list_show);
4101
4102     if (impl->dataList)
4103         ewkViewDataListHideRequest(ewkView, inputType);
4104
4105     for (Vector<String>::const_iterator it = optionList.begin(); it != optionList.end(); ++it) {
4106         String value = *it;
4107         impl->dataList = eina_list_append(impl->dataList, eina_stringshare_add(value.utf8().data()));
4108     }
4109
4110     smartData->api->data_list_show(smartData, inputType, impl->dataList);
4111 }
4112
4113 void ewkViewDataListHideRequest(Evas_Object* ewkView, Ewk_Input_Type inputType)
4114 {
4115     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4116     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4117     EINA_SAFETY_ON_NULL_RETURN(impl->dataList);
4118     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
4119     EINA_SAFETY_ON_NULL_RETURN(smartData->api->data_list_hide);
4120
4121     impl->deleteDataList();
4122
4123     smartData->api->data_list_hide(smartData, inputType);
4124 }
4125 #endif
4126
4127 void ewk_view_data_list_close(Evas_Object* ewkView, const char* value)
4128 {
4129 #if ENABLE(TIZEN_DATALIST_ELEMENT)
4130     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4131     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4132
4133     impl->deleteDataList();
4134
4135     ewk_view_focused_input_element_value_set(ewkView, value);
4136 #endif
4137 }
4138
4139 Eina_Bool ewk_view_horizontal_panning_hold_get(Evas_Object* ewkView)
4140 {
4141 #if ENABLE(TIZEN_GESTURE)
4142     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4143     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4144     return impl->holdHorizontalPanning;
4145 #else
4146     return false;
4147 #endif
4148 }
4149
4150 void ewk_view_horizontal_panning_hold_set(Evas_Object* ewkView, Eina_Bool hold)
4151 {
4152 #if ENABLE(TIZEN_GESTURE)
4153     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4154     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4155     impl->holdHorizontalPanning = hold;
4156 #endif
4157 }
4158
4159 Eina_Bool ewk_view_vertical_panning_hold_get(Evas_Object* ewkView)
4160 {
4161 #if ENABLE(TIZEN_GESTURE)
4162     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4163     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4164     return impl->holdVerticalPanning;
4165 #else
4166     return false;
4167 #endif
4168 }
4169
4170 void ewk_view_vertical_panning_hold_set(Evas_Object* ewkView, Eina_Bool hold)
4171 {
4172 #if ENABLE(TIZEN_GESTURE)
4173     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4174     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4175     impl->holdVerticalPanning = hold;
4176 #endif
4177 }
4178
4179 void ewk_view_touch_event_handler_result_set(Evas_Object* ewkView, WebKit::WebEvent::Type type, bool wasHandled)
4180 {
4181 #if ENABLE(TIZEN_GESTURE)
4182     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4183     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4184
4185 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
4186     if (impl->focusRing() && wasHandled)
4187         impl->focusRing()->hide();
4188 #endif // #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
4189
4190     if (impl->mouseEventsEnabled())
4191         return;
4192
4193 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
4194     if (wasHandled && impl->pageClient->isTextSelectionMode()) {
4195         if (type == WebEvent::TouchStart)
4196             impl->pageClient->updateTextSelectionHandlesAndContextMenu(false);
4197         else if (type == WebEvent::TouchMove)
4198             impl->pageClient->updateTextSelectionHandlesAndContextMenu(false);
4199         else if (type == WebEvent::TouchEnd)
4200             impl->pageClient->requestToShowTextSelectionHandlesAndContextMenu();
4201     }
4202 #endif
4203
4204     // We have to check TouchStart, TouchMove and TouchEnd with handled.
4205     // The Pan and Flick will be enabled if Touch Start was not handled,
4206     // and Touch Move was not handled or did not occur.
4207     // Tap will be enabled if Touch Start and End was not handled
4208     // and Touch Move did not occur.
4209     // The gestures are disabled as a default.
4210     // o: handled, x: not handled
4211     // ------------------------------------------------------------
4212     // Touch Start | Touch Move | Touch End ||   Tap   | Pan, Flick
4213     // ------------------------------------------------------------
4214     //      o      |   o or x   |   o or x  || disable |  disable
4215     //      x      |      o     |   o or x  || disable |  disable
4216     //      x      |      x     |   o or x  || disable |  enable
4217     //      x      |not occured |     x     || enable  |  enable
4218     // ------------------------------------------------------------
4219     if (type == WebEvent::TouchStart) {
4220         impl->gestureClient->setGestureEnabled(!wasHandled);
4221         impl->wasHandledTouchStart = wasHandled;
4222
4223         // Initialize wasHandledTouchMove to true and notify that to the application
4224         // to prevent applications scrolling at the beginning of touch.
4225         impl->wasHandledTouchMove = true;
4226         evas_object_smart_callback_call(ewkView, "touchmove,handled", static_cast<void*>(&impl->wasHandledTouchMove));
4227     } else if (type == WebEvent::TouchMove) {
4228         impl->gestureClient->setMovingEnabled(!wasHandled);
4229
4230         // We have to set wasHandled to true if touchstart was handled even though current touchmove was not handled.
4231         if (impl->wasHandledTouchStart)
4232             wasHandled = true;
4233
4234         // Notify the result of touchmove to applications when handled value is changed
4235         // in order to make applications to choose whether scrolling its scrollable objects or not.
4236         if (impl->wasHandledTouchMove != wasHandled)
4237             evas_object_smart_callback_call(ewkView, "touchmove,handled", static_cast<void*>(&wasHandled));
4238         impl->wasHandledTouchMove = wasHandled;
4239     } else if (type == WebEvent::TouchEnd && !impl->exceedTouchMoveThreshold) {
4240         if (!wasHandled) {
4241             impl->gestureClient->setMovingEnabled(!wasHandled);
4242             impl->gestureClient->setTapEnabled(!wasHandled);
4243         }
4244 #if ENABLE(TIZEN_ISF_PORT)
4245         else if (impl->pageProxy->isViewVisible()) {
4246             IntPoint pointForHitTest = impl->transformFromScene().mapPoint(IntPoint(impl->touchDownPoint.x, impl->touchDownPoint.y));
4247             WebHitTestResult::Data hitTestResultData = impl->pageProxy->hitTestResultAtPoint(pointForHitTest);
4248             if (hitTestResultData.isContentEditable && impl->inputMethodContext()) {
4249                 evas_object_focus_set(ewkView, true);
4250                 impl->inputMethodContext()->updateTextInputState();
4251             }
4252         }
4253 #endif
4254     }
4255 #endif
4256 }
4257
4258 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
4259 void  ewkViewTextStyleState(Evas_Object* ewkView, const IntPoint& startPoint, const IntPoint& endPoint)
4260 {
4261     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4262     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4263
4264     EditorState editorState = impl->page()->editorState();
4265     Ewk_Text_Style* textStyle = ewkTextStyleCreate(editorState, startPoint, endPoint);
4266     evas_object_smart_callback_call(ewkView, "text,style,state", static_cast<void*>(textStyle));
4267     ewkTextStyleDelete(textStyle);
4268 }
4269 #endif
4270
4271 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
4272 bool ewk_view_orientation_lock(Evas_Object* ewkView, int willLockOrientation)
4273 {
4274     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4275     EINA_SAFETY_ON_NULL_RETURN_VAL(smartData->api, false);
4276
4277     TIZEN_LOGI("willLockOrientation (%d)", willLockOrientation);
4278     if (!smartData->api->orientation_lock) {
4279         TIZEN_LOGE("fail");
4280         return false;
4281     }
4282
4283     return smartData->api->orientation_lock(smartData, willLockOrientation);
4284 }
4285
4286 void ewk_view_orientation_unlock(Evas_Object* ewkView)
4287 {
4288     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4289     EINA_SAFETY_ON_NULL_RETURN(smartData->api);
4290
4291     TIZEN_LOGI("ewkView (%p)", ewkView);
4292     if (!smartData->api->orientation_unlock) {
4293         TIZEN_LOGE("fail");
4294         return;
4295     }
4296
4297     smartData->api->orientation_unlock(smartData);
4298 }
4299 #endif
4300
4301 void ewk_view_orientation_lock_callback_set(Evas_Object* ewkView, Ewk_Orientation_Lock_Cb func, void* data)
4302 {
4303 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
4304     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4305     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4306     TIZEN_LOGI("callbacks: %p / data: %p", func, data);
4307
4308     impl->orientationLock.callback = func;
4309     impl->orientationLock.data = data;
4310 #endif
4311 }
4312
4313 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
4314 Eina_Bool _ewk_orientation_lock(Ewk_View_Smart_Data *sd, int orientations)
4315 {
4316     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl, false);
4317     TIZEN_LOGI("locked orientations : %d", orientations);
4318
4319     if (impl->orientationLock.callback)
4320         return impl->orientationLock.callback(sd->self, true, orientations, impl->orientationLock.data);
4321
4322     return false;
4323 }
4324
4325 void _ewk_orientation_unlock(Ewk_View_Smart_Data *sd)
4326 {
4327     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
4328     TIZEN_LOGI("unlock is requested");
4329
4330     if (impl->orientationLock.callback)
4331         impl->orientationLock.callback(sd->self, false, 0, impl->orientationLock.data);
4332 }
4333 #endif
4334
4335 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
4336 bool ewk_view_is_opengl_backend(Evas_Object* ewkView)
4337 {
4338     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4339
4340     Ecore_Evas* ee = ecore_evas_ecore_evas_get(smartData->base.evas);
4341     const char *engine = ecore_evas_engine_name_get(ee);
4342     if (engine && !strcmp(engine, "opengl_x11"))
4343         return true;
4344     return false;
4345 }
4346 #endif
4347
4348 void ewk_view_zoomable_area_set(Evas_Object* ewkView, const IntPoint& target, const IntRect& area)
4349 {
4350 #if ENABLE(TIZEN_GESTURE)
4351     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4352     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4353
4354     impl->gestureClient->setZoomableArea(target, area);
4355 #endif
4356 }
4357
4358 #if ENABLE(TIZEN_BACKFORWARD_LIST_CLEAR)
4359 void ewk_view_back_forward_list_clear(const Evas_Object* ewkView)
4360 {
4361     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4362     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4363
4364     WKBackForwardListClearBackForwardList(WKPageGetBackForwardList(toAPI(impl->pageProxy.get())));
4365 }
4366 #endif
4367
4368 #if ENABLE(TIZEN_SIGNAL_APP_BACK_FORWARD_LIST_CHANGED)
4369 void ewkViewBackForwardListChanged(Evas_Object* ewkView)
4370 {
4371     evas_object_smart_callback_call(ewkView, "back,forward,list,changed", 0);
4372 }
4373 #endif
4374
4375 #if ENABLE(TIZEN_ICON_DATABASE)
4376 void ewkViewIconReceived(Evas_Object* ewkView)
4377 {
4378     if (!ewkView)
4379         return;
4380     evas_object_smart_callback_call(ewkView, "icon,received", 0);
4381 }
4382 #endif
4383
4384 #endif // #if OS(TIZEN)
4385
4386 Eina_Bool ewk_view_feed_touch_event(Evas_Object* ewkView, Ewk_Touch_Event_Type type, const Eina_List* points, const Evas_Modifier* modifiers)
4387 {
4388 #if ENABLE(TOUCH_EVENTS)
4389     EINA_SAFETY_ON_NULL_RETURN_VAL(points, false);
4390     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4391     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4392
4393 #if ENABLE(TIZEN_FOCUS_UI)
4394     if (type == EWK_TOUCH_START)
4395         impl->page()->setSpatialNavigationEnabled(false);
4396 #endif
4397
4398 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION) && ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
4399     if (impl->pageClient->isTextSelectionMode() && eina_list_count(points) == 1) {
4400         Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(eina_list_data_get(points));
4401         IntPoint handlePoint(point->x, point->y);
4402
4403         if (type == EWK_TOUCH_START)
4404             impl->pageClient->textSelectonHandleDown(handlePoint);
4405         else if (type == EWK_TOUCH_MOVE)
4406             impl->pageClient->textSelectonHandleMove(handlePoint);
4407         else
4408             impl->pageClient->textSelectonHandleUp();
4409
4410         if (impl->pageClient->isTextSelectionHandleDowned())
4411             return true;
4412     }
4413 #endif
4414
4415 #if ENABLE(TIZEN_GESTURE)
4416 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
4417     // We don't want to process touch event when context menu is shown.
4418     if ((impl->pageClient->isContextMenuVisible() && type != EWK_TOUCH_CANCEL)
4419 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
4420         && !impl->pageClient->isTextSelectionMode()
4421 #endif
4422         )
4423         return true;
4424 #endif
4425 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
4426     if (impl->pageClient->isTextSelectionDowned() && type != EWK_TOUCH_CANCEL)
4427         return true;
4428 #endif
4429
4430     if (type == EWK_TOUCH_START) {
4431         if (eina_list_count(points) == 1) {
4432             impl->gestureClient->reset();
4433             Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(eina_list_data_get(points));
4434             impl->touchDownPoint.x = point->x;
4435             impl->touchDownPoint.y = point->y;
4436             impl->exceedTouchMoveThreshold = false;
4437         }
4438     } else if (type == EWK_TOUCH_MOVE && !impl->exceedTouchMoveThreshold) {
4439         if (eina_list_count(points) == 1) {
4440             unsigned int threshold = elm_config_scroll_thumbscroll_threshold_get();
4441             Ewk_Touch_Point* point = static_cast<Ewk_Touch_Point*>(eina_list_data_get(points));
4442             int diffX = impl->touchDownPoint.x - point->x;
4443             int diffY = impl->touchDownPoint.y - point->y;
4444             if (static_cast<unsigned int>(diffX * diffX + diffY * diffY) > threshold * threshold)
4445                 impl->exceedTouchMoveThreshold = true;
4446             else
4447                 return true;
4448         } else {
4449             impl->exceedTouchMoveThreshold = true;
4450         }
4451     }
4452 #endif // #if ENABLE(TIZEN_GESTURE)
4453
4454     // FIXME: impl is used in the webkit opensource, but tizen webkit does not use it yet.
4455     //impl->page()->handleTouchEvent(NativeWebTouchEvent(type, points, modifiers, impl->transformFromScene(), impl->transformToScreen(), ecore_time_get()));
4456     impl->pageProxy->handleTouchEvent(NativeWebTouchEvent(type, points, modifiers, impl->transformFromScene(), impl->transformToScreen(), ecore_time_get()));
4457
4458     return true;
4459 #else
4460     return false;
4461 #endif
4462 }
4463
4464 Eina_Bool ewk_view_touch_events_enabled_set(Evas_Object* ewkView, Eina_Bool enabled)
4465 {
4466 #if ENABLE(TOUCH_EVENTS)
4467     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4468     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4469
4470     impl->setTouchEventsEnabled(!!enabled);
4471
4472     return true;
4473 #else
4474     return false;
4475 #endif
4476 }
4477
4478 Eina_Bool ewk_view_touch_events_enabled_get(const Evas_Object* ewkView)
4479 {
4480 #if ENABLE(TOUCH_EVENTS)
4481     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4482     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4483
4484     return impl->touchEventsEnabled();
4485 #else
4486     return false;
4487 #endif
4488 }
4489
4490 Eina_Bool ewk_view_main_frame_scrollbar_visible_set(Evas_Object* ewkView, Eina_Bool visible)
4491 {
4492 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
4493     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4494     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4495
4496     impl->mainFrameScrollbarVisibility = visible;
4497     impl->pageClient->updateVisibility();
4498
4499     return true;
4500 #else
4501     return false;
4502 #endif
4503 }
4504
4505 Eina_Bool ewk_view_main_frame_scrollbar_visible_get(const Evas_Object* ewkView)
4506 {
4507 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
4508     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4509     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4510
4511     return impl->mainFrameScrollbarVisibility;
4512 #else
4513     return false;
4514 #endif
4515 }
4516
4517 Eina_Bool ewk_view_page_save(Evas_Object* ewkView, const char* path)
4518 {
4519 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
4520     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4521     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4522     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
4523
4524     String title = ewk_view_title_get(ewkView);
4525     String url = ewk_view_url_get(ewkView);
4526     String directoryPath(path);
4527     impl->pageClient->startOfflinePageSave(directoryPath, url, title);
4528
4529     return true;
4530 #else
4531     UNUSED_PARAM(ewkView);
4532     UNUSED_PARAM(path);
4533     return false;
4534 #endif
4535 }
4536
4537 /**
4538  * @internal
4539  * Callback function used for ewk_view_page_contents_get().
4540  */
4541 static void ewkViewPageContentsAsMHTMLCallback(WKDataRef wkData, WKErrorRef, void* context)
4542 {
4543     EINA_SAFETY_ON_NULL_RETURN(context);
4544
4545     RefPtr<WebData> webData = toImpl(wkData);
4546     Ewk_Page_Contents_Context* contentsContext= static_cast<Ewk_Page_Contents_Context*>(context);
4547     contentsContext->callback(contentsContext->type, reinterpret_cast<const char*>(webData->bytes()));
4548 }
4549
4550 /**
4551  * @internal
4552  * Callback function used for ewk_view_page_contents_get().
4553  */
4554 static void ewkViewPageContentsAsStringCallback(WKStringRef wkString, WKErrorRef, void* context)
4555 {
4556     EINA_SAFETY_ON_NULL_RETURN(context);
4557
4558     RefPtr<WebString> webString = toImpl(wkString);
4559     Ewk_Page_Contents_Context* contentsContext= static_cast<Ewk_Page_Contents_Context*>(context);
4560     contentsContext->callback(contentsContext->type, webString->string().utf8().data());
4561 }
4562
4563 Eina_Bool ewk_view_page_contents_get(const Evas_Object* ewkView, Ewk_Page_Contents_Context* context)
4564 {
4565     EINA_SAFETY_ON_NULL_RETURN_VAL(context, false);
4566     EINA_SAFETY_ON_NULL_RETURN_VAL(context->callback, false);
4567     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4568     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4569
4570     switch (context->type) {
4571     case EWK_PAGE_CONTENTS_TYPE_MHTML:
4572         impl->pageProxy->getContentsAsMHTMLData(DataCallback::create(context, ewkViewPageContentsAsMHTMLCallback), false);
4573         break;
4574
4575     case EWK_PAGE_CONTENTS_TYPE_STRING:
4576         impl->pageProxy->getContentsAsString(StringCallback::create(context, ewkViewPageContentsAsStringCallback));
4577         break;
4578
4579     default:
4580         ASSERT_NOT_REACHED();
4581         return false;
4582     }
4583
4584     return true;
4585 }
4586
4587 Eina_Bool ewk_view_animated_scroll_set(Evas_Object* ewkView, int x, int y)
4588 {
4589 #if ENABLE(TIZEN_GESTURE)
4590     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4591     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4592
4593     return impl->gestureClient->scrollToWithAnimation(x, y);
4594 #else
4595     UNUSED_PARAM(ewkView);
4596     UNUSED_PARAM(x);
4597     UNUSED_PARAM(y);
4598     return false;
4599 #endif
4600 }
4601
4602 void ewk_view_content_security_policy_set(Evas_Object* ewkView, const char* policy, Ewk_CSP_Header_Type type)
4603 {
4604 #if ENABLE(TIZEN_CSP)
4605     EWK_VIEW_SD_GET_OR_RETURN(ewkView, sd);
4606     EWK_VIEW_IMPL_GET_OR_RETURN(sd, impl);
4607
4608     TIZEN_LOGI("policy(%s), type(%d)\n", policy, type);
4609     impl->pageProxy->setContentSecurityPolicy(String::fromUTF8(policy), static_cast<WebCore::ContentSecurityPolicy::HeaderType>(type));
4610 #endif
4611 }
4612
4613 #if ENABLE(TIZEN_APPLICATION_CACHE)
4614 Eina_Bool ewkViewRequestApplicationCachePermission(Evas_Object* ewkView, WKSecurityOriginRef origin)
4615 {
4616     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4617     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4618
4619     if (!impl->applicationCachePermissionContext || !impl->applicationCachePermissionContext->applicationCachePermissionCallback)
4620         return false;
4621
4622     impl->isWaitingForApplicationCachePermission = true;
4623     if (impl->applicationCachePermissionOrigin)
4624         deleteSecurityOrigin(impl->applicationCachePermissionOrigin);
4625     impl->applicationCachePermissionOrigin = createSecurityOrigin(origin);
4626
4627     return impl->applicationCachePermissionContext->applicationCachePermissionCallback(ewkView, impl->applicationCachePermissionOrigin, impl->applicationCachePermissionContext->userData) == EINA_TRUE;
4628 }
4629 #endif
4630
4631 void ewk_view_application_cache_permission_callback_set(Evas_Object* ewkView, Ewk_View_Applicacion_Cache_Permission_Callback callback, void* userData)
4632 {
4633 #if ENABLE(TIZEN_APPLICATION_CACHE)
4634     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4635     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4636
4637     if (!impl->applicationCachePermissionContext)
4638         impl->applicationCachePermissionContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4639     impl->applicationCachePermissionContext->applicationCachePermissionCallback = callback;
4640     impl->applicationCachePermissionContext->userData = userData;
4641 #else
4642     UNUSED_PARAM(ewkView);
4643     UNUSED_PARAM(callback);
4644     UNUSED_PARAM(userData);
4645 #endif
4646 }
4647
4648 void ewk_view_application_cache_permission_reply(Evas_Object* ewkView, Eina_Bool allow)
4649 {
4650 #if ENABLE(TIZEN_APPLICATION_CACHE)
4651     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4652     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4653
4654     TIZEN_LOGI("allow %d", allow);
4655     WKPageReplyApplicationCachePermission(toAPI(impl->page()), allow);
4656     if (impl->applicationCachePermissionOrigin)
4657         deleteSecurityOrigin(impl->applicationCachePermissionOrigin);
4658     impl->applicationCachePermissionOrigin = 0;
4659     impl->isWaitingForApplicationCachePermission = false;
4660 #else
4661     UNUSED_PARAM(ewkView);
4662     UNUSED_PARAM(allow);
4663 #endif
4664 }
4665
4666 #if ENABLE(TIZEN_INDEXED_DATABASE)
4667 bool ewkViewExceededIndexedDatabaseQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, long long currentUsage)
4668 {
4669     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4670     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4671
4672     if (!impl->exceededIndexedDatabaseQuotaContext || !impl->exceededIndexedDatabaseQuotaContext->exceededIndexedDatabaseQuotaCallback)
4673         return false;
4674
4675     impl->isWaitingForExceededQuotaPopupReply = true;
4676     if (impl->exceededQuotaOrigin)
4677         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4678     impl->exceededQuotaOrigin = createSecurityOrigin(origin);
4679
4680     TIZEN_LOGI("currentUsage(%lld)", currentUsage);
4681
4682     return impl->exceededIndexedDatabaseQuotaContext->exceededIndexedDatabaseQuotaCallback(ewkView, impl->exceededQuotaOrigin, currentUsage, impl->exceededIndexedDatabaseQuotaContext->userData) == EINA_TRUE;
4683 }
4684 #endif
4685
4686 void ewk_view_exceeded_indexed_database_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback, void* userData)
4687 {
4688 #if ENABLE(TIZEN_INDEXED_DATABASE)
4689     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4690     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4691
4692     if (!impl->exceededIndexedDatabaseQuotaContext)
4693         impl->exceededIndexedDatabaseQuotaContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4694     impl->exceededIndexedDatabaseQuotaContext->exceededIndexedDatabaseQuotaCallback = callback;
4695     impl->exceededIndexedDatabaseQuotaContext->userData = userData;
4696 #else
4697     UNUSED_PARAM(ewkView);
4698     UNUSED_PARAM(callback);
4699     UNUSED_PARAM(userData);
4700 #endif
4701 }
4702
4703 void ewk_view_exceeded_indexed_database_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
4704 {
4705 #if ENABLE(TIZEN_INDEXED_DATABASE)
4706     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4707     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4708
4709     TIZEN_LOGI("allow %d", allow);
4710     WKPageReplyExceededIndexedDatabaseQuota(toAPI(impl->page()), allow == EINA_TRUE);
4711     if (impl->exceededQuotaOrigin)
4712         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4713     impl->exceededQuotaOrigin = 0;
4714     impl->isWaitingForExceededQuotaPopupReply = false;
4715 #else
4716     UNUSED_PARAM(ewkView);
4717     UNUSED_PARAM(allow);
4718 #endif
4719 }
4720
4721 // EwkFindOptions should be matched up orders with WkFindOptions.
4722 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_CASE_INSENSITIVE, kWKFindOptionsCaseInsensitive);
4723 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_AT_WORD_STARTS, kWKFindOptionsAtWordStarts);
4724 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, kWKFindOptionsTreatMedialCapitalAsWordStart);
4725 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_BACKWARDS, kWKFindOptionsBackwards);
4726 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_WRAP_AROUND, kWKFindOptionsWrapAround);
4727 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_OVERLAY, kWKFindOptionsShowOverlay);
4728 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_FIND_INDICATOR, kWKFindOptionsShowFindIndicator);
4729 COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_HIGHLIGHT, kWKFindOptionsShowHighlight);
4730
4731 Eina_Bool ewk_view_text_find(Evas_Object* ewkView, const char* text, Ewk_Find_Options options, unsigned maxMatchCount)
4732 {
4733     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4734     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4735     EINA_SAFETY_ON_NULL_RETURN_VAL(text, false);
4736
4737     impl->pageProxy->findString(String::fromUTF8(text), static_cast<WebKit::FindOptions>(options), maxMatchCount);
4738
4739     return true;
4740 }
4741
4742 Eina_Bool ewk_view_text_find_highlight_clear(Evas_Object* ewkView)
4743 {
4744     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4745     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4746
4747     impl->pageProxy->hideFindUI();
4748
4749     return true;
4750 }
4751
4752 Eina_Bool ewk_view_text_matches_count(Evas_Object* ewkView, const char* text, Ewk_Find_Options options, unsigned maxMatchCount)
4753 {
4754     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4755     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4756     EINA_SAFETY_ON_NULL_RETURN_VAL(text, false);
4757
4758     impl->pageProxy->countStringMatches(String::fromUTF8(text), static_cast<WebKit::FindOptions>(options), maxMatchCount);
4759
4760     return true;
4761 }
4762
4763 void ewk_view_exceeded_database_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Database_Quota_Callback callback, void* userData)
4764 {
4765 #if ENABLE(TIZEN_SQL_DATABASE)
4766     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4767     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4768
4769     if (!impl->exceededDatabaseQuotaContext)
4770         impl->exceededDatabaseQuotaContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4771     impl->exceededDatabaseQuotaContext->exceededDatabaseQuotaCallback = callback;
4772     impl->exceededDatabaseQuotaContext->userData = userData;
4773 #else
4774     UNUSED_PARAM(ewkView);
4775     UNUSED_PARAM(callback);
4776     UNUSED_PARAM(userData);
4777 #endif
4778 }
4779
4780 void ewk_view_exceeded_database_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
4781 {
4782 #if ENABLE(TIZEN_SQL_DATABASE)
4783     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4784     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4785
4786     TIZEN_LOGI("allow %d", allow);
4787     WKPageReplyExceededDatabaseQuota(toAPI(impl->page()), allow == EINA_TRUE);
4788     if (impl->exceededQuotaOrigin)
4789         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4790     impl->exceededQuotaOrigin = 0;
4791     impl->isWaitingForExceededQuotaPopupReply = false;
4792 #else
4793     UNUSED_PARAM(ewkView);
4794     UNUSED_PARAM(allow);
4795 #endif
4796 }
4797
4798 #if ENABLE(TIZEN_FILE_SYSTEM)
4799 bool ewkViewExceededLocalFileSystemQuota(Evas_Object* ewkView, WKSecurityOriginRef origin, long long currentUsage)
4800 {
4801     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4802     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4803
4804     if (!impl->exceededLocalFileSystemQuotaContext || !impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback)
4805         return false;
4806
4807     impl->isWaitingForExceededQuotaPopupReply = true;
4808     if (impl->exceededQuotaOrigin)
4809         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4810     impl->exceededQuotaOrigin = createSecurityOrigin(origin);
4811
4812     TIZEN_LOGI("currentUsage(%lld)", currentUsage);
4813
4814     return impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback(ewkView, impl->exceededQuotaOrigin , currentUsage, impl->exceededLocalFileSystemQuotaContext->userData) == EINA_TRUE;
4815 }
4816 #endif
4817
4818 void ewk_view_exceeded_local_file_system_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback, void* userData)
4819 {
4820 #if ENABLE(TIZEN_FILE_SYSTEM)
4821     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4822     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4823
4824     if (!impl->exceededLocalFileSystemQuotaContext)
4825         impl->exceededLocalFileSystemQuotaContext = adoptPtr<Ewk_View_Callback_Context>(new Ewk_View_Callback_Context);
4826     impl->exceededLocalFileSystemQuotaContext->exceededLocalFileSystemQuotaCallback = callback;
4827     impl->exceededLocalFileSystemQuotaContext->userData = userData;
4828 #else
4829     UNUSED_PARAM(ewkView);
4830     UNUSED_PARAM(callback);
4831     UNUSED_PARAM(userData);
4832 #endif
4833 }
4834
4835 void ewk_view_exceeded_local_file_system_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
4836 {
4837 #if ENABLE(TIZEN_FILE_SYSTEM)
4838     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4839     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4840
4841     TIZEN_LOGI("allow %d", allow);
4842     WKPageReplyExceededLocalFileSystemQuota(toAPI(impl->page()), allow == EINA_TRUE);
4843     if (impl->exceededQuotaOrigin)
4844         deleteSecurityOrigin(impl->exceededQuotaOrigin);
4845     impl->exceededQuotaOrigin = 0;
4846     impl->isWaitingForExceededQuotaPopupReply = false;
4847 #else
4848     UNUSED_PARAM(ewkView);
4849     UNUSED_PARAM(result);
4850 #endif
4851 }
4852
4853 void ewk_view_rotation_prepare(Evas_Object* ewkView, int angle)
4854 {
4855 #if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
4856     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4857     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4858
4859     int width, height;
4860     if (angle == 0 || angle == 180) {
4861         width = WebCore::getDefaultScreenResolution().width();
4862         height = WebCore::getDefaultScreenResolution().height() + 100;
4863     }
4864     if (angle == 90 || angle == 270) {
4865         width = WebCore::getDefaultScreenResolution().height();
4866         height = WebCore::getDefaultScreenResolution().width() + 100;
4867     }
4868
4869     impl->pageProxy->drawingArea()->setSize(IntSize(width, height), IntSize());
4870     impl->pageClient->setWaitFrameOfNewViewortSize(true);
4871     ewk_view_suspend(ewkView);
4872     impl->pageClient->updateViewportSize(IntSize(width, height), angle);
4873 #endif
4874 }
4875
4876 #if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
4877 void ewkViewRotatePrepared(Evas_Object* ewkView)
4878 {
4879     evas_object_smart_callback_call(ewkView, "rotate,prepared", 0);
4880 }
4881 #endif
4882
4883 void ewk_view_use_settings_font(Evas_Object* ewkView)
4884 {
4885 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
4886     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4887     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4888
4889     impl->pageProxy->useSettingsFont();
4890 #endif
4891 }
4892
4893 void ewk_view_fullscreen_exit(Evas_Object* ewkView)
4894 {
4895 #if ENABLE(TIZEN_FULLSCREEN_API)
4896     TIZEN_LOGI("");
4897
4898     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
4899     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl);
4900
4901     if (!impl->pageProxy->fullScreenManager()->isFullScreen())
4902         return;
4903
4904     impl->pageProxy->fullScreenManager()->requestExitFullScreen();
4905 #else
4906     UNUSED_PARAM(ewkView);
4907 #endif
4908 }
4909
4910 Eina_Bool ewk_view_draws_transparent_background_set(Evas_Object* ewkView, Eina_Bool enabled)
4911 {
4912     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4913     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4914
4915     impl->pageProxy->setDrawsTransparentBackground(enabled);
4916     evas_object_image_alpha_set(smartData->image, enabled);
4917
4918     return true;
4919 }
4920
4921 Eina_Bool ewk_view_draws_transparent_background_get(Evas_Object* ewkView)
4922 {
4923     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
4924     EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, false);
4925
4926     return impl->pageProxy->drawsTransparentBackground();
4927 }