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