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