Remove tw_callbacks.h
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / public / ewk_view.cc
1 /*
2  * Copyright (C) 2009-2010 ProFUSION embedded systems
3  * Copyright (C) 2009-2014 Samsung Electronics. All rights reserved.
4  * Copyright (C) 2012 Intel Corporation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA  02110-1301, USA.
20  *
21  */
22
23 #include "ewk_view.h"
24
25 #include <Evas.h>
26 #include <tizen_webview/public/tw_webview.h>
27
28 #include "content/public/browser/navigation_controller.h"
29 #include "ui/events/gesture_detection/gesture_configuration.h"
30 #if !defined(EWK_BRINGUP)
31 #include "webkit/common/webpreferences.h"
32 #else
33 #include "content/public/common/web_preferences.h"
34 #endif
35 #include "eweb_view.h"
36 #include "cookie_manager.h"
37 #include "public/ewk_back_forward_list.h"
38 #include "public/ewk_context.h"
39 #include "public/ewk_enums.h"
40 #include "public/ewk_settings.h"
41 #include "private/ewk_context_private.h"
42 #include "private/ewk_frame_private.h"
43 #include "private/ewk_hit_test_private.h"
44 #include "private/ewk_notification_private.h"
45 #include "private/ewk_private.h"
46 #if !defined(EWK_BRINGUP)
47 #include "private/ewk_quota_permission_request_private.h"
48 #endif
49 #include "private/ewk_back_forward_list_private.h"
50 #include "private/ewk_history_private.h"
51 #include "private/ewk_view_private.h"
52 #include "third_party/WebKit/public/web/WebViewModeEnums.h"
53 #include "web_contents_delegate_efl.h"
54
55 using tizen_webview::WebView;
56 using tizen_webview::WebContext;
57
58 Eina_Bool ewk_view_smart_class_set(Ewk_View_Smart_Class* api)
59 {
60   EINA_SAFETY_ON_NULL_RETURN_VAL(api, false);
61   return InitSmartClassInterface(*api);
62 }
63
64 // TODO: Evas_Object *ewk_view_smart_add(Evas *e, Evas_Smart *smart, Ewk_Context *context, Ewk_Page_Group *pageGroup)
65
66 Evas_Object* ewk_view_add_with_session_data(Evas* canvas, const char* data, unsigned length)
67 {
68   EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, NULL);
69
70   Evas_Object* ret = ewk_view_add(canvas);
71
72   WebView *webView = GetWebViewFromEvasObject(ret);
73
74   if (!webView || !data || !length)
75     return ret;
76
77   if (webView->RestoreFromSessionData(data, length))
78     return ret;
79
80   evas_object_del(ret);
81
82   return NULL;
83 }
84
85 Evas_Object* ewk_view_add_with_context(Evas* e, Ewk_Context* context)
86 {
87   EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
88   return CreateWebViewAsEvasObject(context, e);
89 }
90
91 Evas_Object* ewk_view_add(Evas* e)
92 {
93   EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL);
94   // TODO: shouldn't this function create new EWebContext for each new EWebView?
95   // when using default context like that it makes unclear who should release
96   // default web context. It won't be released by destroyed eweb_view because
97   // ewk_context_default_get does AddRef
98   Ewk_Context* context = ewk_context_default_get();
99   return ewk_view_add_with_context(e, context);
100 }
101
102 Evas_Object* ewk_view_add_in_incognito_mode(Evas* e)
103 {
104   Ewk_Context* context = static_cast<Ewk_Context*>(WebContext::Create(true));
105   EINA_SAFETY_ON_NULL_RETURN_VAL(context, NULL);
106   return ewk_view_add_with_context(e, context);
107 }
108
109 Ewk_Context *ewk_view_context_get(const Evas_Object *view)
110 {
111   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, 0);
112   return static_cast<Ewk_Context*>(impl->GetWebContext());
113 }
114
115 Eina_Bool ewk_view_url_set(Evas_Object* view, const char* url)
116 {
117   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
118   EINA_SAFETY_ON_NULL_RETURN_VAL(url, false);
119   impl->SetURL(url);
120   return true;
121 }
122
123 const char* ewk_view_url_get(const Evas_Object* view)
124 {
125   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, 0);
126   return impl->GetURL();
127 }
128
129
130 Eina_Bool ewk_view_reload(Evas_Object *view)
131 {
132   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
133   impl->Reload();
134   return true;
135 }
136
137
138 Eina_Bool ewk_view_reload_bypass_cache(Evas_Object *view)
139 {
140   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
141   impl->ReloadIgnoringCache();
142   return true;
143 }
144
145 Eina_Bool ewk_view_stop(Evas_Object* view)
146 {
147   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
148   impl->Stop();
149   return true;
150 }
151
152
153 Ewk_Settings *ewk_view_settings_get(const Evas_Object *ewkView)
154 {
155   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl,0);
156   return impl->GetSettings();
157 }
158
159 const char* ewk_view_title_get(const Evas_Object* view)
160 {
161   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, 0);
162   return impl->GetTitle();
163 }
164
165 double ewk_view_load_progress_get(const Evas_Object* view)
166 {
167   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, -1);
168   return impl->GetProgressValue();
169 }
170
171 Eina_Bool ewk_view_scale_set(const Evas_Object* view, double scale_factor, int x, int y)
172 {
173   // TODO: We should implement AC in order to work this API normally.
174   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
175   impl->SetScale(scale_factor, x, y);
176   return EINA_TRUE;
177 }
178
179 double ewk_view_scale_get(const Evas_Object *view)
180 {
181   // TODO: We should implement AC in order to work this API normally.
182   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, -1);
183   return impl->GetScale();
184 }
185
186 Eina_Bool ewk_view_back(Evas_Object *view)
187 {
188   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
189   return impl->GoBack();
190 }
191
192 Eina_Bool ewk_view_forward(Evas_Object *view)
193 {
194   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
195   return impl->GoForward();
196 }
197
198 Eina_Bool ewk_view_back_possible(Evas_Object *view)
199 {
200   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
201   return impl->CanGoBack();
202 }
203
204 Eina_Bool ewk_view_forward_possible(Evas_Object *view)
205 {
206   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
207   return impl->CanGoForward();
208 }
209
210 Eina_Bool ewk_view_web_login_request(Evas_Object* ewkView)
211 {
212   LOG_EWK_API_MOCKUP();
213   return false;
214 }
215
216 Eina_Bool ewk_view_html_string_load(Evas_Object* view, const char* html, const char* base_uri, const char* unreachable_uri)
217 {
218   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
219   EINA_SAFETY_ON_NULL_RETURN_VAL(html, EINA_FALSE);
220   impl->LoadHTMLString(html, base_uri, unreachable_uri);
221   return EINA_TRUE;
222 }
223
224 Eina_Bool ewk_view_mouse_events_enabled_set(Evas_Object *view, Eina_Bool enabled)
225 {
226   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
227
228   impl->SetMouseEventsEnabled(!!enabled);
229
230   return true;
231 }
232
233 Eina_Bool ewk_view_mouse_events_enabled_get(const Evas_Object *view)
234 {
235   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
236
237   return impl->MouseEventsEnabled();
238 }
239
240 Eina_Bool ewk_view_color_picker_color_set(Evas_Object* ewkView, int r, int g, int b, int a)
241 {
242   LOG_EWK_API_MOCKUP();
243   return false;
244 }
245
246 double ewk_view_text_zoom_get(const Evas_Object* view)
247 {
248   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, -1.0);
249   return impl->GetTextZoomFactor();
250 }
251
252 Eina_Bool ewk_view_text_zoom_set(Evas_Object* view, double text_zoom_level)
253 {
254   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
255   if (ewk_settings_text_zoom_enabled_get(ewk_view_settings_get(view))) {
256    impl->SetTextZoomFactor(text_zoom_level);
257    return true;
258   }
259   return false;
260 }
261
262 void ewk_view_not_found_error_page_load(Evas_Object* ewkView, const char* errorUrl)
263 {
264   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
265   impl->LoadNotFoundErrorPage(std::string(errorUrl));
266 }
267
268 void ewk_view_scale_range_get(Evas_Object* view, double* min_scale, double* max_scale)
269 {
270   if (!min_scale && !max_scale)
271     return;
272
273   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
274   impl->GetPageScaleRange(min_scale, max_scale);
275 }
276
277 void ewk_view_suspend(Evas_Object* ewkView)
278 {
279   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
280   impl->Suspend();
281 }
282
283 void ewk_view_resume(Evas_Object* ewkView)
284 {
285   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
286   impl->Resume();
287 }
288
289 Eina_Bool ewk_view_url_request_set(Evas_Object* ewkView, const char* url, Ewk_Http_Method method, Eina_Hash* headers, const char* body)
290 {
291   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
292   EINA_SAFETY_ON_NULL_RETURN_VAL(url, EINA_FALSE);
293   content::NavigationController::LoadURLType loadtype;
294   switch (method) {
295   case EWK_HTTP_METHOD_GET:
296     loadtype = content::NavigationController::LOAD_TYPE_DEFAULT;
297     break;
298   case EWK_HTTP_METHOD_POST:
299     loadtype = content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
300     break;
301   default:
302     LOG(ERROR) << "Not supported HTTP Method.";
303     return EINA_FALSE;
304   }
305
306   impl->UrlRequestSet(url, loadtype, headers, body);
307   return EINA_TRUE;
308 }
309
310 Eina_Bool ewk_view_plain_text_set(Evas_Object* view, const char* plain_text)
311 {
312   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
313   EINA_SAFETY_ON_NULL_RETURN_VAL(plain_text, EINA_FALSE);
314   impl->LoadPlainTextString(plain_text);
315   return EINA_TRUE;
316 }
317
318 Eina_Bool ewk_view_contents_set(Evas_Object* view, const char* contents, size_t contents_size, char* mime_type, char* encoding, char* base_uri)
319 {
320   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
321   EINA_SAFETY_ON_NULL_RETURN_VAL(contents, EINA_FALSE);
322   impl->LoadData(contents, contents_size, mime_type, encoding, base_uri);
323   return EINA_TRUE;
324 }
325
326 Eina_Bool ewk_view_html_contents_set(Evas_Object* view, const char* html, const char* base_uri)
327 {
328   return ewk_view_html_string_load(view, html, base_uri, NULL);
329 }
330
331 Eina_Bool ewk_view_page_visibility_state_set(Evas_Object* ewkView, Ewk_Page_Visibility_State page_visibility_state, Eina_Bool initial_state)
332 {
333   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl,false);
334   switch (page_visibility_state) {
335     case EWK_PAGE_VISIBILITY_STATE_VISIBLE :
336       impl->Show();
337       break;
338     case EWK_PAGE_VISIBILITY_STATE_HIDDEN :
339       impl->Hide();
340       break;
341     default:
342       break;
343   }
344   return true;
345 }
346
347 Eina_Bool ewk_view_user_agent_set(Evas_Object* ewkView, const char* user_agent)
348 {
349   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
350
351   return impl->SetUserAgent(user_agent);
352 }
353
354 const char* ewk_view_user_agent_get(const Evas_Object* ewkView)
355 {
356   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, 0);
357   return impl->GetUserAgent();
358 }
359
360 Eina_Bool ewk_view_application_name_for_user_agent_set(Evas_Object* ewkView, const char* application_name)
361 {
362   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
363   return impl->SetUserAgentAppName(application_name);
364 }
365
366 const char* ewk_view_application_name_for_user_agent_get(const Evas_Object* ewkView)
367 {
368   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, 0);
369   return eina_stringshare_add(impl->GetUserAgentAppName());
370 }
371
372 Eina_Bool ewk_view_custom_header_add(const Evas_Object* ewkView, const char* name, const char* value)
373 {
374   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
375   EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
376   EINA_SAFETY_ON_NULL_RETURN_VAL(value, EINA_FALSE);
377   EINA_SAFETY_ON_NULL_RETURN_VAL(impl->GetWebContext(),EINA_FALSE);
378   return impl->GetWebContext()->HTTPCustomHeaderAdd(name, value);
379 }
380
381 Eina_Bool ewk_view_custom_header_remove(const Evas_Object* ewkView, const char* name)
382 {
383   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
384   EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
385   EINA_SAFETY_ON_NULL_RETURN_VAL(impl->GetWebContext(),EINA_FALSE);
386   return impl->GetWebContext()->HTTPCustomHeaderRemove(name);
387
388 }
389
390 Eina_Bool ewk_view_custom_header_clear(const Evas_Object* ewkView)
391 {
392   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
393   EINA_SAFETY_ON_NULL_RETURN_VAL(impl->GetWebContext(),EINA_FALSE);
394   impl->GetWebContext()->HTTPCustomHeaderClear();
395   return EINA_TRUE;
396 }
397
398
399 Eina_Bool ewk_view_visibility_set(const Evas_Object* view, Eina_Bool enable)
400 {
401   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
402
403   if (enable)
404     impl->Show();
405   else
406     impl->Hide();
407
408   return EINA_TRUE;
409 }
410
411 Evas_Object* ewk_view_screenshot_contents_get(const Evas_Object* view, Eina_Rectangle view_area, float scale_factor, Evas* canvas)
412 {
413   EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, NULL);
414   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, NULL);
415   // Zoom level equality (<=0.001) is sufficient compared to high precision std::numeric_value::epsilon.
416   if (!content::ZoomValuesEqual(scale_factor, 1.0)) {
417     LOG(ERROR) << "We only support scale factor of 1.0."
418                << "Scaling option will be supported after hardware acceleration is enabled.";
419     return NULL;
420   }
421   return impl->GetSnapshot(view_area);
422 }
423
424 Eina_Bool ewk_view_screenshot_contents_get_async(const Evas_Object* view, Eina_Rectangle view_area,
425         float scale_factor, Evas* canvas, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data)
426 {
427   EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
428   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
429   // Zoom level equality (<=0.001) is sufficient compared to high precision std::numeric_value::epsilon.
430   if (!content::ZoomValuesEqual(scale_factor, 1.0)) {
431     LOG(ERROR) << "We only support scale factor of 1.0."
432                << "Scaling option will be supported after hardware acceleration is enabled.";
433     return EINA_FALSE;
434   }
435   return impl->GetSnapshotAsync(view_area, canvas, callback, user_data) ? EINA_TRUE : EINA_FALSE;
436 }
437
438 unsigned int ewk_view_inspector_server_start(Evas_Object* ewkView, unsigned int port)
439 {
440   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
441   return impl->StartInspectorServer(port);
442 }
443
444 Eina_Bool ewk_view_inspector_server_stop(Evas_Object* ewkView)
445 {
446   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
447   return impl->StopInspectorServer();
448 }
449
450 Evas_Object* ewk_view_cache_image_get(const Evas_Object* ewkView, const char* imageUrl, Evas* canvas)
451 {
452   LOG_EWK_API_MOCKUP();
453         return NULL;
454 }
455
456 void ewk_view_scroll_by(Evas_Object* ewkView, int deltaX, int deltaY)
457 {
458   int x, y;
459
460   if (EINA_TRUE == ewk_view_scroll_pos_get(ewkView, &x, &y)) {
461     ewk_view_scroll_set(ewkView, x + deltaX, y + deltaY);
462   }
463 }
464
465 Eina_Bool ewk_view_scroll_pos_get(Evas_Object* ewkView, int* x, int* y)
466 {
467   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
468   EINA_SAFETY_ON_NULL_RETURN_VAL(x, EINA_FALSE);
469   EINA_SAFETY_ON_NULL_RETURN_VAL(y, EINA_FALSE);
470   return impl->GetScrollPosition(x, y);
471 }
472
473 Eina_Bool ewk_view_scroll_set(Evas_Object* view, int x, int y)
474 {
475   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
476   impl->SetScroll(x, y);
477
478   return EINA_TRUE;
479 }
480
481 Eina_Bool ewk_view_scroll_size_get(const Evas_Object* view, int* width, int* height)
482 {
483   if (width)
484     *width = 0;
485   if (height)
486     *height = 0;
487   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
488   impl->GetScrollSize(width,height);
489   return EINA_TRUE;
490 }
491
492 void ewk_view_password_confirm_popup_callback_set(Evas_Object* view, Ewk_View_Password_Confirm_Popup_Callback callback, void* user_data)
493 {
494   LOG_EWK_API_MOCKUP();
495 }
496
497 void ewk_view_password_confirm_popup_reply(Evas_Object* ewkView, Ewk_Password_Popup_Option result)
498 {
499   LOG_EWK_API_MOCKUP();
500 }
501
502 void ewk_view_javascript_alert_callback_set(Evas_Object* view, Ewk_View_JavaScript_Alert_Callback callback, void* user_data)
503 {
504   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
505   if (callback)
506     impl->SetJavaScriptAlertCallback(callback, user_data);
507 }
508
509 void ewk_view_javascript_alert_reply(Evas_Object* view)
510 {
511   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
512   impl->JavaScriptAlertReply();
513 }
514
515 void ewk_view_javascript_confirm_callback_set(Evas_Object* view, Ewk_View_JavaScript_Confirm_Callback callback, void* user_data)
516 {
517   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
518   if (callback)
519     impl->SetJavaScriptConfirmCallback(callback, user_data);
520 }
521
522 void ewk_view_javascript_confirm_reply(Evas_Object* view, Eina_Bool result)
523 {
524   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
525   impl->JavaScriptConfirmReply(result);
526 }
527
528 void ewk_view_javascript_prompt_callback_set(Evas_Object* view, Ewk_View_JavaScript_Prompt_Callback callback, void* user_data)
529 {
530   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
531   if (callback)
532     impl->SetJavaScriptPromptCallback(callback, user_data);
533 }
534
535 void ewk_view_javascript_prompt_reply(Evas_Object* view, const char* result)
536 {
537   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
538   impl->JavaScriptPromptReply(result);
539 }
540
541 void ewk_view_before_unload_confirm_panel_callback_set(Evas_Object* ewkView, Ewk_View_Before_Unload_Confirm_Panel_Callback callback, void* userData)
542 {
543   LOG_EWK_API_MOCKUP();
544 }
545
546 void ewk_view_before_unload_confirm_panel_reply(Evas_Object* ewkView, Eina_Bool result)
547 {
548   LOG_EWK_API_MOCKUP();
549 }
550
551 Eina_Bool ewk_view_web_application_capable_get(Evas_Object* ewkView, Ewk_Web_App_Capable_Get_Callback callback, void* userData)
552 {
553   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
554   EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
555   return impl->WebAppCapableGet(callback, userData) ? EINA_TRUE : EINA_FALSE;
556 }
557
558 Eina_Bool ewk_view_web_application_icon_url_get(Evas_Object* ewkView, Ewk_Web_App_Icon_URL_Get_Callback callback, void* userData)
559 {
560   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
561   EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
562   return impl->WebAppIconUrlGet(callback, userData) ? EINA_TRUE : EINA_FALSE;
563 }
564
565 Eina_Bool ewk_view_web_application_icon_urls_get(Evas_Object* ewkView, Ewk_Web_App_Icon_URLs_Get_Callback callback, void* userData)
566 {
567   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
568   EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
569   return impl->WebAppIconUrlsGet(callback, userData) ? EINA_TRUE : EINA_FALSE;
570 }
571
572 Eina_Bool ewk_view_command_execute(Evas_Object* view, const char* command, const char* value)
573 {
574   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
575   EINA_SAFETY_ON_NULL_RETURN_VAL(command, false);
576   impl->ExecuteEditCommand(command, value);
577   return true;
578 }
579
580 Eina_Bool ewk_view_contents_size_get(Evas_Object* view, Evas_Coord* width, Evas_Coord* height)
581 {
582   if (width)
583     *width = 0;
584   if (height)
585     *height = 0;
586
587   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
588   Eina_Rectangle contents_size = impl->GetContentsSize();
589
590   if (width)
591     *width = contents_size.w;
592   if (height)
593     *height = contents_size.h;
594
595   return EINA_TRUE;
596 }
597
598 Eina_Bool ewk_view_contents_pdf_get(Evas_Object* view, int width, int height, const char* fileName)
599 {
600   EINA_SAFETY_ON_NULL_RETURN_VAL(fileName, EINA_FALSE);
601   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
602   return impl->SaveAsPdf(width, height, fileName);
603 }
604
605 Eina_Bool ewk_view_script_execute(Evas_Object* ewkView, const char* script, Ewk_View_Script_Execute_Callback callback, void* user_data)
606 {
607   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
608   EINA_SAFETY_ON_NULL_RETURN_VAL(script, false);
609   // callback can be null, so do not test it for null
610   if (0 != strcmp(script, "")) //check for empty string
611     return impl->ExecuteJavaScript(script, callback, user_data);
612   return false;
613 }
614
615
616 Eina_Bool ewk_view_plain_text_get(Evas_Object* view, Ewk_View_Plain_Text_Get_Callback callback, void* user_data)
617 {
618   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
619   EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
620   return (impl->PlainTextGet(callback, user_data));
621 }
622
623 Eina_Bool ewk_view_mhtml_data_get(Evas_Object *view, Ewk_View_MHTML_Data_Get_Callback callback, void *user_data)
624 {
625   EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
626   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
627   return impl->GetMHTMLData(callback, user_data);
628 }
629
630 Ewk_Hit_Test* ewk_view_hit_test_new(Evas_Object* ewkView, int x, int y, int hit_test_mode)
631 {
632   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, 0);
633   return impl->RequestHitTestDataAt(x, y,
634       static_cast<Ewk_Hit_Test_Mode>(hit_test_mode));
635 }
636
637 Eina_Bool ewk_view_hit_test_request(Evas_Object* o, int x, int y, int hit_test_mode, Ewk_View_Hit_Test_Request_Callback callback, void* user_data)
638 {
639   EWK_VIEW_IMPL_GET_OR_RETURN(o, impl, EINA_FALSE);
640   return impl->AsyncRequestHitTestDataAt(x, y, static_cast<Ewk_Hit_Test_Mode>(hit_test_mode), callback, user_data);
641 }
642
643 Ewk_History* ewk_view_history_get(Evas_Object* ewkView)
644 {
645   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, NULL);
646   return impl->GetBackForwardHistory();
647 }
648
649 Eina_Bool ewk_view_notification_closed(Evas_Object* ewkView, Eina_List* notification_list)
650 {
651   return EINA_FALSE;
652 }
653
654 Eina_Bool ewk_view_popup_menu_select(Evas_Object* ewkView, unsigned int selectedIndex)
655 {
656   LOG_EWK_API_MOCKUP();
657   return false;
658 }
659
660 Eina_Bool ewk_view_popup_menu_multiple_select(Evas_Object* ewkView, Eina_Inarray* changeList)
661 {
662   LOG_EWK_API_MOCKUP();
663   return false;
664 }
665
666 /*
667  * Sends the new orientation of the device.
668  *
669  * If orientation value is changed, orientationchanged event will occur.
670  *
671  * @param view object to receive orientation event.
672  * @param orientation the new orientation of the device. (degree)
673  *
674  * orientation will be 0 degrees when the device is oriented to natural position,
675  *                     90 degrees when it's left side is at the top,
676  *                    -90 degrees when it's right side is at the top,
677  *                     180 degrees when it is upside down.
678  */
679 void ewk_view_orientation_send(Evas_Object* ewkView, int orientation)
680 {
681   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
682   impl->SetOrientation(orientation);
683 }
684
685 void ewk_view_encoding_custom_set(Evas_Object* ewkView, const char* encoding)
686 {
687   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
688   impl->SetOverrideEncoding(std::string(encoding));
689 }
690
691 Eina_Bool ewk_view_text_selection_range_get(const Evas_Object* view, Eina_Rectangle* left_rect, Eina_Rectangle* right_rect)
692 {
693   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
694   if (left_rect && right_rect && impl->GetSelectionRange(left_rect, right_rect)) {
695     Evas_Coord x, y;
696     evas_object_geometry_get(view, &x, &y, 0, 0);
697     left_rect->x += x;
698     left_rect->y += y;
699     right_rect->x += x;
700     right_rect->y += y;
701     return true;
702   }
703   return false;
704 }
705
706 Eina_Bool ewk_view_text_selection_clear(Evas_Object *view)
707 {
708   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
709   return impl->ClearSelection() ? EINA_TRUE : EINA_FALSE;
710 }
711
712 const char* ewk_view_text_selection_text_get(Evas_Object* view)
713 {
714   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, NULL);
715   return impl->GetSelectedText();
716 }
717
718 void ewk_view_focused_input_element_value_set(Evas_Object* ewkView, const char* value)
719 {
720   LOG_EWK_API_MOCKUP();
721 }
722
723 const char* ewk_view_focused_input_element_value_get(Evas_Object* ewkView)
724 {
725   LOG_EWK_API_MOCKUP();
726   return NULL;
727 }
728
729 Eina_Bool ewk_view_vertical_panning_hold_get(Evas_Object* ewkView)
730 {
731   LOG_EWK_API_MOCKUP();
732   return false;
733 }
734
735 void ewk_view_vertical_panning_hold_set(Evas_Object* view, Eina_Bool hold)
736 {
737   LOG_EWK_API_MOCKUP();
738   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
739   // FIX ME: Currently the pan support is not present.
740   // In WK2 panning was implemented with evas directly, here its with chorme gesture reconignation
741   // So paning is not present yet
742 }
743
744 void ewk_view_orientation_lock_callback_set(Evas_Object* ewkView, Ewk_Orientation_Lock_Cb func, void* data)
745 {
746   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
747   EINA_SAFETY_ON_NULL_RETURN(func);
748   impl->SetOrientationLockCallback(func, data);
749 }
750
751
752 void ewk_view_back_forward_list_clear(const Evas_Object *view)
753 {
754   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl);
755   impl->BackForwardListClear();
756 }
757
758 Eina_Bool ewk_view_feed_touch_event(Evas_Object *view, Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers)
759 {
760   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
761
762   impl->HandleTouchEvents(type, points, modifiers);
763
764   return true;
765 }
766
767 Eina_Bool ewk_view_touch_events_enabled_set(Evas_Object *view, Eina_Bool enabled)
768 {
769   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
770
771   impl->SetTouchEventsEnabled(!!enabled);
772
773   return true;
774 }
775
776 Eina_Bool ewk_view_touch_events_enabled_get(const Evas_Object *view)
777 {
778   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
779
780   return impl->TouchEventsEnabled();
781 }
782
783 Ewk_Frame_Ref ewk_view_main_frame_get(Evas_Object* o)
784 {
785   EWK_VIEW_IMPL_GET_OR_RETURN(o, impl, NULL);
786   return static_cast<Ewk_Frame_Ref>(impl->GetMainFrame());
787 }
788
789 Eina_Bool ewk_view_main_frame_scrollbar_visible_set(Evas_Object* ewkView, Eina_Bool visible)
790 {
791   LOG_EWK_API_MOCKUP();
792   return false;
793 }
794
795 void ewk_view_content_security_policy_set(Evas_Object* ewkView, const char* policy, Ewk_CSP_Header_Type type)
796 {
797   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
798   EINA_SAFETY_ON_NULL_RETURN(policy);
799   impl->SetContentSecurityPolicy(policy, type);
800 }
801
802 void ewk_view_application_cache_permission_callback_set(Evas_Object* ewkView, Ewk_View_Applicacion_Cache_Permission_Callback callback, void* userData)
803 {
804   // Chromium does not support this feature hence the comment
805   LOG_EWK_API_MOCKUP("Not Supported by chromium");
806 }
807
808 void ewk_view_application_cache_permission_reply(Evas_Object* ewkView, Eina_Bool allow)
809 {
810   // Chromium does not support this feature hence the comment
811   LOG_EWK_API_MOCKUP("Not Supported by chromium");
812 }
813
814 void ewk_view_exceeded_indexed_database_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback, void* userData)
815 {
816   // Chromium does not support quota for Indexed DB only.
817   // IndexedDB uses temporary storage that is shared
818   // between other features.
819   LOG_EWK_API_MOCKUP("Not Supported by chromium");
820 }
821
822 void ewk_view_exceeded_indexed_database_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
823 {
824   // Chromium does not support quota for Indexed DB only.
825   // IndexedDB uses temporary storage that is shared
826   // between other features.
827   LOG_EWK_API_MOCKUP("Not Supported by chromium");
828 }
829
830 Eina_Bool ewk_view_text_find(Evas_Object *view, const char *text, Ewk_Find_Options options, unsigned int max_match_count)
831 {
832   // FIXME: We need to implement next options in Ewk_Find_Options struct. (refer to ewk_view.h)
833   //         - EWK_FIND_OPTIONS_AT_WORD_STARTS
834   //         - EWK_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START
835   //         - EWK_FIND_OPTIONS_WRAP_AROUND
836   //         - EWK_FIND_OPTIONS_SHOW_OVERLAY
837   //         - EWK_FIND_OPTIONS_SHOW_FIND_INDICATOR
838   //         - EWK_FIND_OPTIONS_SHOW_HIGHLIGHT (Currently there is no way to control this option. so it is always set)
839
840   // FIXME: Updating of max_match_count is not implemented.
841
842   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
843   EINA_SAFETY_ON_NULL_RETURN_VAL(text, EINA_FALSE);
844   impl->Find(text, options);
845   return EINA_TRUE;
846 }
847
848 Eina_Bool ewk_view_text_find_highlight_clear(Evas_Object *view)
849 {
850   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
851   impl->StopFinding();
852   return EINA_TRUE;
853 }
854
855 void ewk_view_exceeded_database_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Database_Quota_Callback callback, void* userData)
856 {
857   // According to chromium source code:
858   // src/third_party/WebKit/Source/modules/webdatabase/SQLTransactionClient.cpp line 67
859   // Chromium does not allow users to manually change the quota for an origin (for now, at least).
860   // This API is impossible to implement right now
861   LOG_EWK_API_MOCKUP("Not Supported by chromium");
862 }
863
864 void ewk_view_exceeded_database_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
865 {
866   // According to chromium source code:
867   // src/third_party/WebKit/Source/modules/webdatabase/SQLTransactionClient.cpp line 67
868   // Chromium does not allow users to manually change the quota for an origin (for now, at least).
869   // This API is impossible to implement right now
870   LOG_EWK_API_MOCKUP("Not Supported by chromium");
871 }
872
873 void ewk_view_exceeded_local_file_system_quota_callback_set(Evas_Object* ewkView, Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback, void* userData)
874 {
875   LOG_EWK_API_MOCKUP();
876 }
877
878 void ewk_view_exceeded_local_file_system_quota_reply(Evas_Object* ewkView, Eina_Bool allow)
879 {
880   LOG_EWK_API_MOCKUP();
881 }
882
883 void ewk_view_intercept_request_callback_set (Evas_Object* ewkView, Ewk_View_Intercept_Request_Callback callback, void* user_data)
884 {
885   LOG_EWK_API_MOCKUP();
886 }
887
888 void ewk_view_unfocus_allow_callback_set(Evas_Object* ewkView, Ewk_View_Unfocus_Allow_Callback callback, void* user_data)
889 {
890   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
891   impl->SetViewUnfocusAllowCallback(callback, user_data);
892 }
893
894 void ewk_view_geolocation_permission_callback_set(Evas_Object* ewk_view, Ewk_View_Geolocation_Permission_Callback callback, void* user_data)
895 {
896   EWK_VIEW_IMPL_GET_OR_RETURN(ewk_view, impl);
897   impl->SetViewGeolocationPermissionCallback(callback, user_data);
898 }
899
900 void ewk_view_use_settings_font(Evas_Object* ewkView)
901 {
902   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
903   impl->UseSettingsFont();
904 }
905
906 char* ewk_view_get_cookies_for_url(Evas_Object* view, const char* url)
907 {
908   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, 0);
909   EINA_SAFETY_ON_NULL_RETURN_VAL(url, 0);
910   std::string cookiesForURL;
911   cookiesForURL = impl->GetWebContext()->cookieManager()->GetCookiesForURL(std::string(url));
912   if (cookiesForURL.empty())
913     return NULL;
914   return strndup(cookiesForURL.c_str(), cookiesForURL.length());
915 }
916
917 Eina_Bool ewk_view_fullscreen_exit(Evas_Object* view)
918 {
919   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
920   impl->ExitFullscreen();
921   return EINA_TRUE;
922 }
923
924 Eina_Bool ewk_view_draws_transparent_background_set(Evas_Object *view, Eina_Bool enabled)
925 {
926   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
927   impl->SetDrawsTransparentBackground(enabled);
928   return EINA_TRUE;
929 }
930
931 void ewk_view_browser_font_set(Evas_Object* ewkView)
932 {
933   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
934   impl->SetBrowserFont();
935 }
936
937 void ewk_view_session_data_get(Evas_Object* ewkView, const char** data, unsigned* length)
938 {
939   EINA_SAFETY_ON_NULL_RETURN(data);
940   EINA_SAFETY_ON_NULL_RETURN(length);
941
942   WebView* impl = GetWebViewFromEvasObject(ewkView);
943   if (!impl) {
944     *data = NULL;
945     *length = 0;
946     return;
947   }
948
949   impl->GetSessionData(data, length);
950 }
951
952 Eina_Bool ewk_view_mode_set(Evas_Object* ewkView, Ewk_View_Mode view_mode)
953 {
954   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, EINA_FALSE);
955
956   if (view_mode == EWK_VIEW_MODE_WINDOWED) {
957     impl->SetViewMode(blink::WebViewModeWindowed);
958     return EINA_TRUE;
959   } else if (view_mode == EWK_VIEW_MODE_FULLSCREEN) {
960     impl->SetViewMode(blink::WebViewModeFullscreen);
961     return EINA_TRUE;
962   } else {
963     return EINA_FALSE;
964   }
965 }
966
967 Eina_Bool ewk_view_split_scroll_overflow_enabled_set(Evas_Object* ewkView, const Eina_Bool enabled)
968 {
969   LOG_EWK_API_MOCKUP("for browser");
970   return false;
971 }
972
973 Ewk_Back_Forward_List* ewk_view_back_forward_list_get(const Evas_Object* ewkView)
974 {
975   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, NULL);
976   return impl->GetBackForwardList();
977 }
978
979 void ewk_view_notification_permission_callback_set(Evas_Object *o, Ewk_View_Notification_Permission_Callback callback, void *user_data)
980 {
981   EWK_VIEW_IMPL_GET_OR_RETURN(o, impl);
982   impl->SetNotificationPermissionCallback(callback, user_data);
983 }
984
985 void ewk_view_draw_focus_ring_enable_set(Evas_Object* ewkView, Eina_Bool enable)
986 {
987 #if defined(OS_TIZEN_TV) && !defined(EWK_BRINGUP)
988   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
989   impl->setDrawFocusRing(enable);
990 #else
991    LOG_EWK_API_MOCKUP("Only for Tizen TV Browser");
992 #endif
993 }
994
995 #if defined(OS_TIZEN_TV)
996 double ewk_view_page_zoom_get(const Evas_Object* ewkView)
997 {
998   LOG_EWK_API_MOCKUP("for Tizen TV Browser");
999   return 0;
1000 }
1001
1002 Eina_Bool ewk_view_page_zoom_set(Evas_Object* ewkView, double zoomFactor)
1003 {
1004   LOG_EWK_API_MOCKUP("for Tizen TV Browser");
1005   return false;
1006 }
1007
1008 Evas_Object* ewk_view_smart_add(Evas* canvas, Evas_Smart* smart, Ewk_Context* context, Ewk_Page_Group* pageGroup)
1009 {
1010   EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1011   return CreateWebViewAsEvasObject(context, canvas, smart);
1012 }
1013 #endif // OS_TIZEN_TV
1014
1015 #if !defined(EWK_BRINGUP)
1016 void ewk_view_quota_permission_request_callback_set(Evas_Object* ewkView, Ewk_Quota_Permission_Request_Callback callback, void* user_data)
1017 {
1018   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
1019   impl->SetQuotaPermissionRequestCallback((tizen_webview::QuotaPermissionRequest_Cb)callback, user_data);
1020 }
1021
1022 void ewk_view_quota_permission_request_reply(const Ewk_Quota_Permission_Request* request, const Eina_Bool allow)
1023 {
1024   EINA_SAFETY_ON_NULL_RETURN(request);
1025   Evas_Object* ewkView = request->getView();
1026   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
1027   impl->QuotaRequestReply(request, allow == EINA_TRUE);
1028 }
1029
1030 void ewk_view_quota_permission_request_cancel(const Ewk_Quota_Permission_Request* request)
1031 {
1032   EINA_SAFETY_ON_NULL_RETURN(request);
1033   Evas_Object* ewkView = request->getView();
1034   EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
1035   impl->QuotaRequestCancel(request);
1036 }
1037 #endif