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