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