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