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
49 #define APPLICATION_NAME_FOR_USER_AGENT "SamsungBrowser/1.0"
51 #define APPLICATION_NAME_FOR_USER_AGENT "Mozilla/5.0 (X11; SMART-TV; Linux) AppleWebkit/538.1 (KHTML, like Gecko) Safari/538.1"
54 //TODO: temporary user agent for mobile display, change to proper one
55 #define APPLICATION_NAME_FOR_USER_AGENT_MOBILE "Mozilla/5.0 (Linux; Tizen 3.0; SAMSUNG SM-Z130H) AppleWebKit/538.1 (KHTML, like Gecko) SamsungBrowser/1.0 Mobile Safari/538.1"
57 using namespace tizen_browser::tools;
59 namespace tizen_browser {
60 namespace basic_webengine {
61 namespace webkitengine_service {
63 WebView::WebView(Evas_Object * obj, TabId tabId)
66 , m_ewkContext(ewk_context_new())
67 , m_title(std::string())
72 config.load("whatever");
77 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
80 unregisterCallbacks();
83 ewk_context_delete(m_ewkContext);
86 void WebView::init(bool desktopMode, Evas_Object * opener)
88 #if defined(USE_EWEBKIT)
89 m_ewkView = ewk_view_add_with_context(evas_object_evas_get(m_parent), m_ewkContext);
91 evas_object_data_set(m_ewkView, "_container", this);
92 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, this);
94 evas_object_color_set(m_ewkView, 255, 255, 255, 255);
95 evas_object_size_hint_weight_set(m_ewkView, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
96 evas_object_size_hint_align_set(m_ewkView, EVAS_HINT_FILL, EVAS_HINT_FILL);
98 switchToDesktopMode();
100 switchToMobileMode();
102 //\todo: when value is other than 1.0, scroller is located improperly
103 // ewk_view_device_pixel_ratio_set(m_ewkView, 1.0f);
106 ewk_view_resume(m_ewkView);
108 // set local storage, favion, cookies
109 std::string webkit_path = boost::any_cast <std::string> (config.get("webkit/dir"));
113 Ewk_Context *context = ewk_view_context_get(m_ewkView);
116 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
120 ///\note Odroid modification - not exists in WebKit API
121 // ewk_cookie_manager_widget_cookie_directory_set(ewk_context_cookie_manager_get(context), webkit_path.c_str());
125 m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
129 void WebView::registerCallbacks()
131 #if defined(USE_EWEBKIT)
132 evas_object_smart_callback_add(m_ewkView, "load,started", __loadStarted, this);
133 evas_object_smart_callback_add(m_ewkView, "load,stop", __loadStop, this);
134 evas_object_smart_callback_add(m_ewkView, "load,finished", __loadFinished, this);
135 evas_object_smart_callback_add(m_ewkView, "load,progress", __loadProgress, this);
136 evas_object_smart_callback_add(m_ewkView, "load,error", __loadError, this);
138 evas_object_smart_callback_add(m_ewkView, "title,changed", __titleChanged, this);
139 evas_object_smart_callback_add(m_ewkView, "url,changed", __urlChanged, this);
141 evas_object_smart_callback_add(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
143 evas_object_smart_callback_add(m_ewkView, "create,window", __newWindowRequest, this);
144 evas_object_smart_callback_add(m_ewkView, "close,window", __closeWindowRequest, this);
146 evas_object_smart_callback_add(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
147 evas_object_smart_callback_add(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
148 evas_object_smart_callback_add(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
149 evas_object_smart_callback_add(m_ewkView, "authentication,request", __authenticationRequest, this);
150 evas_object_smart_callback_add(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
152 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView, this);
153 evas_object_smart_callback_add(m_ewkView, "icon,received", __faviconChanged, this);
155 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
156 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
160 void WebView::unregisterCallbacks()
162 #if defined(USE_EWEBKIT)
163 evas_object_smart_callback_del_full(m_ewkView, "load,started", __loadStarted, this);
164 evas_object_smart_callback_del_full(m_ewkView, "load,stop", __loadStop, this);
165 evas_object_smart_callback_del_full(m_ewkView, "load,finished", __loadFinished, this);
166 evas_object_smart_callback_del_full(m_ewkView, "load,progress", __loadProgress, this);
167 evas_object_smart_callback_del_full(m_ewkView, "load,error", __loadError, this);
169 evas_object_smart_callback_del_full(m_ewkView, "title,changed", __titleChanged, this);
170 evas_object_smart_callback_del_full(m_ewkView, "url,changed", __urlChanged, this);
172 evas_object_smart_callback_del_full(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
174 evas_object_smart_callback_del_full(m_ewkView, "create,window", __newWindowRequest, this);
175 evas_object_smart_callback_del_full(m_ewkView, "close,window", __closeWindowRequest, this);
177 evas_object_smart_callback_del_full(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
178 evas_object_smart_callback_del_full(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
179 evas_object_smart_callback_del_full(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
180 evas_object_smart_callback_del_full(m_ewkView, "authentication,request", __authenticationRequest, this);
181 evas_object_smart_callback_del_full(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
183 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView);
184 evas_object_smart_callback_del_full(m_ewkView, "icon,received", __faviconChanged, this);
186 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
187 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
191 void WebView::setupEwkSettings()
193 #if defined(USE_EWEBKIT)
195 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
196 ewk_settings_uses_keypad_without_user_action_set(settings, EINA_FALSE);
201 Evas_Object * WebView::getLayout()
206 void WebView::setURI(const std::string & uri)
208 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, uri.c_str());
209 #if defined(USE_EWEBKIT)
210 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
211 ewk_view_url_set(m_ewkView, uri.c_str());
216 std::string WebView::getURI(void)
218 #if defined(USE_EWEBKIT)
219 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, ewk_view_url_get(m_ewkView));
220 return fromChar(ewk_view_url_get(m_ewkView));
222 return std::string();
226 std::string WebView::getTitle(void)
231 void WebView::stopLoading(void)
233 #if defined(USE_EWEBKIT)
234 ewk_view_stop(m_ewkView);
239 void WebView::reload(void)
241 #if defined(USE_EWEBKIT)
245 ewk_view_url_set(m_ewkView, ewk_view_url_get(m_ewkView));
248 ewk_view_reload(m_ewkView);
252 void WebView::back(void)
254 #if defined(USE_EWEBKIT)
256 ewk_view_back(m_ewkView);
260 void WebView::forward(void)
262 #if defined(USE_EWEBKIT)
264 ewk_view_forward(m_ewkView);
268 bool WebView::isBackEnabled(void)
270 #if defined(USE_EWEBKIT)
271 return ewk_view_back_possible(m_ewkView);
277 bool WebView::isForwardEnabled(void)
279 #if defined(USE_EWEBKIT)
280 return ewk_view_forward_possible(m_ewkView);
286 bool WebView::isLoading()
291 bool WebView::isLoadError() const
296 void WebView::setPrivateMode(bool state)
298 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
301 #if defined(USE_EWEBKIT)
303 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
305 Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
307 ewk_settings_private_browsing_enabled_set(settings, state);
310 Ewk_Context *context = ewk_view_context_get(m_ewkView);
315 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_NEVER);
319 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
326 void WebView::confirmationResult(WebConfirmationPtr confirmation)
328 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
330 #if defined(USE_EWEBKIT)
332 switch(confirmation->getConfirmationType()) {
333 case WebConfirmation::ConfirmationType::Geolocation: {
334 Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
336 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
338 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
341 BROWSER_LOGE("Wrong ConfirmationResult");
344 // set geolocation permission
345 ewk_geolocation_permission_reply(request, result);
346 ewk_view_resume(m_ewkView);
349 m_confirmationGeolocationMap.erase(confirmation);
352 case WebConfirmation::ConfirmationType::UserMedia: {
353 Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
355 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
357 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
360 BROWSER_LOGE("Wrong ConfirmationResult");
364 // set usermedia permission
365 ewk_user_media_permission_reply(request, result);
366 ewk_view_resume(m_ewkView);
369 m_confirmationUserMediaMap.erase(confirmation);
372 case WebConfirmation::ConfirmationType::Notification: {
373 Ewk_Notification_Permission_Request *request = m_confirmationNotificationMap[confirmation];
375 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
377 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
380 BROWSER_LOGE("Wrong ConfirmationResult");
384 // set notification permission
385 ewk_notification_permission_reply(request, result);
386 ewk_view_resume(m_ewkView);
389 m_confirmationNotificationMap.erase(confirmation);
392 case WebConfirmation::ConfirmationType::CertificateConfirmation: {
393 CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
394 Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
396 if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
398 else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
401 BROWSER_LOGE("Wrong ConfirmationResult");
405 // set certificate confirmation
406 BROWSER_LOGE("NOT IMPLEMENTED: Certificate Confirmation handling!");
409 m_confirmationCertificatenMap.erase(cert);
412 case WebConfirmation::ConfirmationType::Authentication: {
413 AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
414 Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
415 if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
416 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Confirmation handling!");
417 } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
418 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Rejection handling!");
420 BROWSER_LOGE("Wrong ConfirmationResult");
425 m_confirmationAuthenticationMap.erase(auth);
437 std::shared_ptr<BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
439 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
441 M_ASSERT(targetWidth);
442 M_ASSERT(targetHeight);
444 std::shared_ptr<BrowserImage> noImage = std::make_shared<BrowserImage>();
445 evas_object_geometry_get(m_ewkView, nullptr, nullptr, &vw, &vh);
446 if (vw == 0 || vh == 0)
450 double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
451 double webkitProportions = (double)(vw) /(double)(vh);
452 if (webkitProportions >= snapshotProportions) {
453 // centring position of screenshot
454 area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
456 area.w = vh*getZoomFactor()*snapshotProportions;
457 area.h = vh*getZoomFactor();
462 area.w = vw*getZoomFactor();
463 area.h = vw*getZoomFactor()/snapshotProportions;
465 if (area.w == 0 || area.h == 0)
469 BROWSER_LOGD("[%s:%d] Before snapshot (screenshot) - look at the time of taking snapshot below",__func__, __LINE__);
470 #if defined(USE_EWEBKIT)
472 Evas_Object *snapshot = ewk_view_screenshot_contents_get( m_ewkView, area, 1.0, evas_object_evas_get(m_ewkView));
473 BROWSER_LOGD("[%s:%d] Snapshot (screenshot) catched, evas pointer: %p",__func__, __LINE__, snapshot);
475 return EflTools::getBrowserImage(snapshot);
482 #if defined(USE_EWEBKIT)
483 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
485 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
487 WebView * self = reinterpret_cast<WebView *>(data);
489 if(!self->hasFocus())
490 self->ewkViewClicked();
493 void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
495 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
497 WebView * self = reinterpret_cast<WebView *>(data);
498 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
499 BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
500 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
501 m_webEngine = std::dynamic_pointer_cast
503 basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
505 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
506 M_ASSERT(m_webEngine);
508 /// \todo: Choose newly created tab.
509 TabId id = m_webEngine->addTab(std::string(), &self->getTabId());
510 BROWSER_LOGD("Created tab: %s", id.toString().c_str());
512 Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
513 *static_cast<Evas_Object**>(out) = tab_ewk_view;
516 void WebView::__closeWindowRequest(void *data, Evas_Object *, void *)
518 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
519 WebView * self = reinterpret_cast<WebView *>(data);
520 std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
521 std::dynamic_pointer_cast
522 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
523 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
524 m_webEngine->closeTab(self->getTabId());
527 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
529 WebView * self = reinterpret_cast<WebView *>(data);
531 BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
533 self->m_isLoading = true;
535 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
536 cache->clearThumb(self->m_tabId);
539 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
541 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
543 WebView * self = reinterpret_cast<WebView *>(data);
544 self->m_isLoading = false;
549 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
551 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
553 WebView * self = reinterpret_cast<WebView *>(data);
554 self->m_isLoading = false;
555 self->m_loadProgress = 1;
557 self->loadFinished();
558 self->loadProgress(self->m_loadProgress);
559 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
560 cache->updateThumb(self->m_tabId);
563 void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_info)
565 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
567 WebView * self = reinterpret_cast<WebView *>(data);
568 self->m_loadProgress = *(double *)event_info;
570 self->loadProgress(self->m_loadProgress);
573 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
575 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
577 WebView *self = reinterpret_cast<WebView*>(data);
578 Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
579 Ewk_Error_Type errorType = ewk_error_type_get(error);
581 BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
582 __PRETTY_FUNCTION__, __LINE__, errorType);
584 BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
585 int errorCode = ewk_error_code_get(error);
586 if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
588 BROWSER_LOGD("Stop signal emitted");
589 BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
590 evas_object_smart_callback_call(obj, "load,stop", nullptr);
595 self->m_loadError=true;
599 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
601 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
603 WebView * self = reinterpret_cast<WebView *>(data);
604 self->m_title = fromChar(ewk_view_title_get(obj));
606 self->titleChanged(self->m_title);
609 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
611 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
613 WebView * self = reinterpret_cast<WebView *>(data);
614 BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
615 self->uriChanged(self->getURI());
616 self->tabIdChecker(self->m_tabId);
619 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
621 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
623 WebView * self = reinterpret_cast<WebView *>(data);
624 self->backwardEnableChanged(self->isBackEnabled());
625 self->forwardEnableChanged(self->isForwardEnabled());
628 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
632 WebView * self = static_cast<WebView *>(data);
633 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));
635 BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
636 self->faviconImage = EflTools::getBrowserImage(favicon);
637 evas_object_unref(favicon);
638 self->favIconChanged(self->faviconImage);
643 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
645 BROWSER_LOGD("%s", __func__);
646 WebView * self = reinterpret_cast<WebView *>(data);
647 self->IMEStateChanged(false);
650 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
652 BROWSER_LOGD("%s", __func__);
653 WebView * self = reinterpret_cast<WebView *>(data);
654 self->IMEStateChanged(true);
657 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
659 std::string protocol = fromChar(ewk_security_origin_protocol_get(origin));
660 std::string uri = fromChar(ewk_security_origin_host_get(origin));
661 std::string url = (boost::format("%1%://%2%") % protocol % uri).str();
665 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
667 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
669 WebView * self = reinterpret_cast<WebView *>(data);
671 Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
676 ewk_view_suspend(self->m_ewkView);
678 std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
680 ///\todo add translations
681 std::string message = (boost::format("%1% Requests your location") % url).str();
683 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
686 self->m_confirmationGeolocationMap[c] = request;
688 self->cofirmationRequest(c);
692 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
694 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
696 WebView * self = reinterpret_cast<WebView *>(data);
698 Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
703 ewk_view_suspend(self->m_ewkView);
705 ///\todo add translations
706 std::string message = "User media permission request";
708 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
711 self->m_confirmationUserMediaMap[c] = request;
713 self->cofirmationRequest(c);
717 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
719 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
721 WebView * self = reinterpret_cast<WebView *>(data);
723 Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
728 ewk_view_suspend(self->m_ewkView);
730 ///\todo add translations
731 std::string message = (boost::format("%1% wants to display notifications") % self->getURI()).str();
733 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, self->getURI(), message);
736 self->m_confirmationNotificationMap[c] = request;
738 self->cofirmationRequest(c);
742 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
744 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
746 WebView * self = reinterpret_cast<WebView *>(data);
748 Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
749 EINA_SAFETY_ON_NULL_RETURN(request);
751 std::string url = self->getURI();
752 std::string message = (boost::format("A username and password are being requested by %1%.") % url).str();
754 AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
756 self->m_confirmationAuthenticationMap[c] = request;
758 self->cofirmationRequest(c);
762 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
764 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
766 WebView * self = reinterpret_cast<WebView *>(data);
768 Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
773 ewk_view_suspend(self->m_ewkView);
775 std::string url = self->getURI();
777 ///\todo add translations
778 std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
780 CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
782 c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
785 self->m_confirmationCertificatenMap[c] = request;
787 self->cofirmationRequest(c);
792 void WebView::setFocus()
794 elm_object_focus_set(m_ewkView, EINA_TRUE);
797 void WebView::clearFocus()
799 elm_object_focus_set(m_ewkView, EINA_FALSE);
802 bool WebView::hasFocus() const
804 return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
807 double WebView::getZoomFactor() const
809 if(EINA_UNLIKELY(m_ewkView == nullptr)){
813 #if defined(USE_EWEBKIT)
814 return ewk_view_page_zoom_get(m_ewkView);
820 void WebView::setZoomFactor(double zoomFactor)
822 #if defined(USE_EWEBKIT)
824 //using zoomFactor = 0 sets zoom "fit to screen"
826 if(zoomFactor != getZoomFactor())
827 ewk_view_page_zoom_set(m_ewkView, zoomFactor);
832 void WebView::scrollView(const int& dx, const int& dy)
834 ewk_view_scroll_by(m_ewkView, dx, dy);
837 const TabId& WebView::getTabId(){
842 std::shared_ptr<BrowserImage> WebView::getFavicon()
844 BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
846 Evas_Object * favicon = ewk_context_icon_database_icon_object_add(ewk_view_context_get(m_ewkView), ewk_view_url_get(m_ewkView),evas_object_evas_get(m_ewkView));
847 faviconImage = EflTools::getBrowserImage(favicon);
848 evas_object_unref(favicon);
850 if(faviconImage.get())
853 BROWSER_LOGD("[%s:%d] Returned favicon is empty!", __PRETTY_FUNCTION__, __LINE__);
854 return std::make_shared<BrowserImage>();
857 void WebView::clearPrivateData()
859 BROWSER_LOGD("Clearing private data");
860 #if defined(USE_EWEBKIT)
863 Ewk_Context *context = ewk_view_context_get(m_ewkView);
866 ewk_context_web_storage_delete_all(context);
867 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
873 void WebView::searchOnWebsite(const std::string & searchString, int flags)
875 ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
876 Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
877 BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
880 void WebView::switchToDesktopMode() {
881 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
882 int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT);
883 m_desktopMode = true;
886 void WebView::switchToMobileMode() {
887 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
888 int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT_MOBILE);
889 m_desktopMode = false;
892 bool WebView::isDesktopMode() const {
893 return m_desktopMode;
896 } /* namespace webkitengine_service */
897 } /* end of basic_webengine */
898 } /* end of tizen_browser */