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