2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Created on: Apr 1, 2014
26 #if defined(USE_EWEBKIT)
27 #include <ewk_chromium.h>
30 #include <boost/format.hpp>
31 #include <boost/regex.hpp>
32 #include <boost/algorithm/string/regex.hpp>
33 #include <boost/algorithm/string/classification.hpp>
34 #include <boost/algorithm/string/split.hpp>
35 #include <Elementary.h>
38 #include "AbstractWebEngine/AbstractWebEngine.h"
39 #include "AbstractWebEngine/TabThumbCache.h"
40 #include "BrowserAssert.h"
41 #include "BrowserLogger.h"
43 #include "GeneralTools.h"
44 #include "Tools/WorkQueue.h"
45 #include "ServiceManager.h"
47 #define certificate_crt_path CERTS_DIR
48 #define APPLICATION_NAME_FOR_USER_AGENT "SamsungBrowser/1.0"
50 using namespace tizen_browser::tools;
52 namespace tizen_browser {
53 namespace basic_webengine {
54 namespace webkitengine_service {
56 WebView::WebView(Evas_Object * obj, TabId tabId)
63 config.load("whatever");
68 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
71 unregisterCallbacks();
75 void WebView::init(Evas_Object * opener)
77 #if defined(USE_EWEBKIT)
78 m_ewkView = ewk_view_add(evas_object_evas_get(m_parent));
80 evas_object_data_set(m_ewkView, "_container", this);
81 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, this);
83 evas_object_color_set(m_ewkView, 255, 255, 255, 255);
84 evas_object_size_hint_weight_set(m_ewkView, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
85 evas_object_size_hint_align_set(m_ewkView, EVAS_HINT_FILL, EVAS_HINT_FILL);
86 ewk_view_application_name_for_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT);
87 //\todo: when value is other than 1.0, scroller is located improperly
88 // ewk_view_device_pixel_ratio_set(m_ewkView, 1.0f);
91 ewk_view_resume(m_ewkView);
93 // set local storage, favion, cookies
94 std::string webkit_path = boost::any_cast <std::string> (config.get("webkit/dir"));
98 Ewk_Context *context = ewk_view_context_get(m_ewkView);
101 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
102 ewk_context_favicon_database_directory_set(context, (webkit_path + std::string("/favicon")).c_str());
106 ///\note Odroid modification - not exists in WebKit API
107 // ewk_cookie_manager_widget_cookie_directory_set(ewk_context_cookie_manager_get(context), webkit_path.c_str());
111 m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
115 void WebView::registerCallbacks()
117 #if defined(USE_EWEBKIT)
118 evas_object_smart_callback_add(m_ewkView, "load,started", __loadStarted, this);
119 evas_object_smart_callback_add(m_ewkView, "load,stop", __loadStop, this);
120 evas_object_smart_callback_add(m_ewkView, "load,finished", __loadFinished, this);
121 evas_object_smart_callback_add(m_ewkView, "load,progress", __loadProgress, this);
122 evas_object_smart_callback_add(m_ewkView, "load,error", __loadError, this);
124 evas_object_smart_callback_add(m_ewkView, "title,changed", __titleChanged, this);
125 evas_object_smart_callback_add(m_ewkView, "url,changed", __urlChanged, this);
127 evas_object_smart_callback_add(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
129 evas_object_smart_callback_add(m_ewkView, "create,window", __newWindowRequest, this);
130 evas_object_smart_callback_add(m_ewkView, "close,window", __closeWindowRequest, this);
132 evas_object_smart_callback_add(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
133 evas_object_smart_callback_add(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
134 evas_object_smart_callback_add(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
135 evas_object_smart_callback_add(m_ewkView, "authentication,request", __authenticationRequest, this);
136 evas_object_smart_callback_add(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
138 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView, this);
139 evas_object_smart_callback_add(m_ewkView, "icon,received", __faviconChanged, this);
141 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
142 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
146 void WebView::unregisterCallbacks()
148 #if defined(USE_EWEBKIT)
149 evas_object_smart_callback_del_full(m_ewkView, "load,started", __loadStarted, this);
150 evas_object_smart_callback_del_full(m_ewkView, "load,stop", __loadStop, this);
151 evas_object_smart_callback_del_full(m_ewkView, "load,finished", __loadFinished, this);
152 evas_object_smart_callback_del_full(m_ewkView, "load,progress", __loadProgress, this);
153 evas_object_smart_callback_del_full(m_ewkView, "load,error", __loadError, this);
155 evas_object_smart_callback_del_full(m_ewkView, "title,changed", __titleChanged, this);
156 evas_object_smart_callback_del_full(m_ewkView, "url,changed", __urlChanged, this);
158 evas_object_smart_callback_del_full(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
160 evas_object_smart_callback_del_full(m_ewkView, "create,window", __newWindowRequest, this);
161 evas_object_smart_callback_del_full(m_ewkView, "close,window", __closeWindowRequest, this);
163 evas_object_smart_callback_del_full(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
164 evas_object_smart_callback_del_full(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
165 evas_object_smart_callback_del_full(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
166 evas_object_smart_callback_del_full(m_ewkView, "authentication,request", __authenticationRequest, this);
167 evas_object_smart_callback_del_full(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
169 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView);
170 evas_object_smart_callback_del_full(m_ewkView, "icon,received", __faviconChanged, this);
172 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
173 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
177 void WebView::setupEwkSettings()
179 #if defined(USE_EWEBKIT)
181 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
182 ewk_settings_uses_keypad_without_user_action_set(settings, EINA_FALSE);
187 Evas_Object * WebView::getLayout()
192 void WebView::setURI(const std::string & uri)
194 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, uri.c_str());
195 #if defined(USE_EWEBKIT)
196 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
197 ewk_view_url_set(m_ewkView, uri.c_str());
202 std::string WebView::getURI(void)
204 #if defined(USE_EWEBKIT)
205 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, ewk_view_url_get(m_ewkView));
206 return tizen_browser::tools::fromChar(ewk_view_url_get(m_ewkView));
208 return std::string();
212 std::string WebView::getTitle(void)
217 void WebView::stopLoading(void)
219 #if defined(USE_EWEBKIT)
220 ewk_view_stop(m_ewkView);
225 void WebView::reload(void)
227 #if defined(USE_EWEBKIT)
231 ewk_view_url_set(m_ewkView, ewk_view_url_get(m_ewkView));
234 ewk_view_reload(m_ewkView);
238 void WebView::back(void)
240 #if defined(USE_EWEBKIT)
242 ewk_view_back(m_ewkView);
246 void WebView::forward(void)
248 #if defined(USE_EWEBKIT)
250 ewk_view_forward(m_ewkView);
254 bool WebView::isBackEnabled(void)
256 #if defined(USE_EWEBKIT)
257 return ewk_view_back_possible(m_ewkView);
263 bool WebView::isForwardEnabled(void)
265 #if defined(USE_EWEBKIT)
266 return ewk_view_forward_possible(m_ewkView);
272 bool WebView::isLoading()
277 bool WebView::isLoadError() const
282 void WebView::setPrivateMode(bool state)
284 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
287 #if defined(USE_EWEBKIT)
289 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
291 Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
293 ewk_settings_private_browsing_enabled_set(settings, state);
296 Ewk_Context *context = ewk_view_context_get(m_ewkView);
301 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_NEVER);
305 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
312 void WebView::confirmationResult(WebConfirmationPtr confirmation)
314 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
316 #if defined(USE_EWEBKIT)
318 switch(confirmation->getConfirmationType()) {
319 case WebConfirmation::ConfirmationType::Geolocation: {
320 Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
322 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
324 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
327 BROWSER_LOGE("Wrong ConfirmationResult");
330 // set geolocation permission
331 ewk_geolocation_permission_reply(request, result);
332 ewk_view_resume(m_ewkView);
335 m_confirmationGeolocationMap.erase(confirmation);
338 case WebConfirmation::ConfirmationType::UserMedia: {
339 Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
341 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
343 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
346 BROWSER_LOGE("Wrong ConfirmationResult");
350 // set usermedia permission
351 ewk_user_media_permission_reply(request, result);
352 ewk_view_resume(m_ewkView);
355 m_confirmationUserMediaMap.erase(confirmation);
358 case WebConfirmation::ConfirmationType::Notification: {
359 Ewk_Notification_Permission_Request *request = m_confirmationNotificationMap[confirmation];
361 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
363 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
366 BROWSER_LOGE("Wrong ConfirmationResult");
370 // set notification permission
371 ewk_notification_permission_reply(request, result);
372 ewk_view_resume(m_ewkView);
375 m_confirmationNotificationMap.erase(confirmation);
378 case WebConfirmation::ConfirmationType::CertificateConfirmation: {
379 CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
380 Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
382 if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
384 else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
387 BROWSER_LOGE("Wrong ConfirmationResult");
391 // set certificate confirmation
392 BROWSER_LOGE("NOT IMPLEMENTED: Certificate Confirmation handling!");
395 m_confirmationCertificatenMap.erase(cert);
398 case WebConfirmation::ConfirmationType::Authentication: {
399 AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
400 Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
401 if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
402 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Confirmation handling!");
403 } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
404 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Rejection handling!");
406 BROWSER_LOGE("Wrong ConfirmationResult");
411 m_confirmationAuthenticationMap.erase(auth);
423 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
425 BROWSER_LOGD("%s:%d %s NOT IMPLEMENTED, returning empty BrowserImage object", __FILE__, __LINE__, __func__);
427 M_ASSERT(targetWidth);
428 M_ASSERT(targetHeight);
430 std::shared_ptr<tizen_browser::tools::BrowserImage> noImage = std::make_shared<tizen_browser::tools::BrowserImage>();
431 evas_object_geometry_get(m_ewkView, NULL, NULL, &vw, &vh);
432 if (vw == 0 || vh == 0)
436 double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
437 double webkitProportions = (double)(vw) /(double)(vh);
438 if (webkitProportions >= snapshotProportions) {
439 // centring position of screenshot
440 area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
442 area.w = vh*getZoomFactor()*snapshotProportions;
443 area.h = vh*getZoomFactor();
448 area.w = vw*getZoomFactor();
449 area.h = vw*getZoomFactor()/snapshotProportions;
451 if (area.w == 0 || area.h == 0)
454 double scaleW = (double)targetWidth / (double)(area.w);
455 double scaleH = (double)targetHeight / (double)(area.h);
457 #if defined(USE_EWEBKIT)
459 Evas_Object *snapshot = nullptr;
460 // TODO use ewk_view_screenshot_contents_get_async API here
462 return tizen_browser::tools::EflTools::getBrowserImage(snapshot);
469 #if defined(USE_EWEBKIT)
470 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
472 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
474 WebView * self = reinterpret_cast<WebView *>(data);
476 if(!self->hasFocus())
477 self->ewkViewClicked();
480 void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
482 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
484 WebView * self = reinterpret_cast<WebView *>(data);
485 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
486 BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
487 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
488 m_webEngine = std::dynamic_pointer_cast
490 basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
492 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
493 M_ASSERT(m_webEngine);
495 /// \todo: Choose newly created tab.
496 TabId id = m_webEngine->addTab(std::string(), &self->getTabId());
497 BROWSER_LOGD("Created tab: %s", id.toString().c_str());
499 Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
500 *static_cast<Evas_Object**>(out) = tab_ewk_view;
503 void WebView::__closeWindowRequest(void *data, Evas_Object *, void *)
505 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
506 WebView * self = reinterpret_cast<WebView *>(data);
507 std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
508 std::dynamic_pointer_cast
509 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
510 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
511 m_webEngine->closeTab(self->getTabId());
514 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
516 WebView * self = reinterpret_cast<WebView *>(data);
518 BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
520 self->m_isLoading = true;
522 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
523 cache->clearThumb(self->m_tabId);
526 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
528 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
530 WebView * self = reinterpret_cast<WebView *>(data);
531 self->m_isLoading = false;
536 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
538 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
540 WebView * self = reinterpret_cast<WebView *>(data);
541 self->m_isLoading = false;
542 self->m_loadProgress = 1;
544 self->loadFinished();
545 self->loadProgress(self->m_loadProgress);
546 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
547 cache->updateThumb(self->m_tabId);
550 void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_info)
552 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
554 WebView * self = reinterpret_cast<WebView *>(data);
555 self->m_loadProgress = *(double *)event_info;
557 self->loadProgress(self->m_loadProgress);
560 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
562 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
564 WebView *self = reinterpret_cast<WebView*>(data);
565 Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
566 Ewk_Error_Type errorType = ewk_error_type_get(error);
568 BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
569 __PRETTY_FUNCTION__, __LINE__, errorType);
571 BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
572 int errorCode = ewk_error_code_get(error);
573 if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
575 BROWSER_LOGD("Stop signal emitted");
576 BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
577 evas_object_smart_callback_call(obj, "load,stop", NULL);
582 self->m_loadError=true;
586 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
588 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
590 WebView * self = reinterpret_cast<WebView *>(data);
591 self->m_title = tizen_browser::tools::fromChar(ewk_view_title_get(obj));
593 self->titleChanged(self->m_title);
596 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
598 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
600 WebView * self = reinterpret_cast<WebView *>(data);
601 BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
602 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
603 m_webEngine = std::dynamic_pointer_cast<basic_webengine::AbstractWebEngine<Evas_Object>, tizen_browser::core::AbstractService>(
604 tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
605 M_ASSERT(m_webEngine);
606 self->uriChanged(tizen_browser::tools::fromChar(reinterpret_cast<const char *>(event_info)));
607 self->tabIdChecker(self->m_tabId);
610 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
612 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
614 WebView * self = reinterpret_cast<WebView *>(data);
615 self->backwardEnableChanged(self->isBackEnabled());
616 self->forwardEnableChanged(self->isForwardEnabled());
619 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
623 WebView * self = static_cast<WebView *>(data);
624 Evas_Object * favicon = ewk_context_icon_database_icon_object_add(ewk_view_context_get(self->m_ewkView), ewk_view_url_get(self->m_ewkView),evas_object_evas_get(self->m_ewkView));
626 BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
627 self->faviconImage = tizen_browser::tools::EflTools::getBrowserImage(favicon);
628 evas_object_unref(favicon);
629 self->favIconChanged(self->faviconImage);
634 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
636 BROWSER_LOGD("%s", __func__);
637 WebView * self = reinterpret_cast<WebView *>(data);
638 self->IMEStateChanged(false);
641 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
643 BROWSER_LOGD("%s", __func__);
644 WebView * self = reinterpret_cast<WebView *>(data);
645 self->IMEStateChanged(true);
648 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
650 std::string protocol = tizen_browser::tools::fromChar(ewk_security_origin_protocol_get(origin));
651 std::string uri = tizen_browser::tools::fromChar(ewk_security_origin_host_get(origin));
652 std::string url = (boost::format("%1%://%2%") % protocol % uri).str();
656 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
658 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
660 WebView * self = reinterpret_cast<WebView *>(data);
662 Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
667 ewk_view_suspend(self->m_ewkView);
669 std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
671 ///\todo add translations
672 std::string message = (boost::format("%1% Requests your location") % url).str();
674 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
677 self->m_confirmationGeolocationMap[c] = request;
679 self->cofirmationRequest(c);
683 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
685 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
687 WebView * self = reinterpret_cast<WebView *>(data);
689 Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
694 ewk_view_suspend(self->m_ewkView);
696 ///\todo add translations
697 std::string message = "User media permission request";
699 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
702 self->m_confirmationUserMediaMap[c] = request;
704 self->cofirmationRequest(c);
708 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
710 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
712 WebView * self = reinterpret_cast<WebView *>(data);
714 Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
719 ewk_view_suspend(self->m_ewkView);
721 ///\todo add translations
722 std::string message = (boost::format("%1% wants to display notifications") % self->getURI()).str();
724 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, self->getURI(), message);
727 self->m_confirmationNotificationMap[c] = request;
729 self->cofirmationRequest(c);
733 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
735 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
737 WebView * self = reinterpret_cast<WebView *>(data);
739 Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
740 EINA_SAFETY_ON_NULL_RETURN(request);
742 std::string url = self->getURI();
743 std::string message = (boost::format("A username and password are being requested by %1%.") % url).str();
745 AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
747 self->m_confirmationAuthenticationMap[c] = request;
749 self->cofirmationRequest(c);
753 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
755 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
757 WebView * self = reinterpret_cast<WebView *>(data);
759 Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
764 ewk_view_suspend(self->m_ewkView);
766 std::string url = self->getURI();
768 ///\todo add translations
769 std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
771 CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
773 c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
776 self->m_confirmationCertificatenMap[c] = request;
778 self->cofirmationRequest(c);
783 void WebView::setFocus()
785 elm_object_focus_set(m_ewkView, EINA_TRUE);
788 void WebView::clearFocus()
790 elm_object_focus_set(m_ewkView, EINA_FALSE);
793 bool WebView::hasFocus() const
795 return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
798 double WebView::getZoomFactor() const
800 if(EINA_UNLIKELY(m_ewkView == NULL)){
804 #if defined(USE_EWEBKIT)
805 return ewk_view_page_zoom_get(m_ewkView);
811 void WebView::setZoomFactor(double zoomFactor)
813 #if defined(USE_EWEBKIT)
815 //using zoomFactor = 0 sets zoom "fit to screen"
817 ewk_view_page_zoom_set(m_ewkView, zoomFactor);
823 const TabId& WebView::getTabId(){
828 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::getFavicon() {
829 BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
832 #if defined(USE_EWEBKIT)
833 if (faviconImage.get() == NULL) {
837 Ewk_Context *context = ewk_view_context_get(m_ewkView);
840 Evas_Object * favicon = ewk_context_icon_database_icon_object_add(context, ewk_view_url_get(m_ewkView), evas_object_evas_get(m_ewkView));
844 evas_object_image_size_get(favicon, &w, &h);
845 BROWSER_LOGD("[%s]: Info about favicon: w:%d h:%d, type: %s", __func__, w, h, evas_object_type_get(favicon));
848 std::shared_ptr<tizen_browser::tools::BrowserImage>
849 image = tizen_browser::tools::EflTools::getBrowserImage(favicon);
851 evas_object_unref(favicon);
862 BROWSER_LOGE("[%s:%d]: Returned favicon is empty!", __PRETTY_FUNCTION__, __LINE__);
863 return std::make_shared<tizen_browser::tools::BrowserImage>();
866 void WebView::clearPrivateData()
868 BROWSER_LOGD("Clearing private data");
869 #if defined(USE_EWEBKIT)
872 Ewk_Context *context = ewk_view_context_get(m_ewkView);
875 ewk_context_web_storage_delete_all(context);
876 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
882 void WebView::searchOnWebsite(const std::string & searchString, int flags)
884 ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
885 Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
886 BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
889 } /* namespace webkitengine_service */
890 } /* end of basic_webengine */
891 } /* end of tizen_browser */