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