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);
111 Ewk_Context *context = ewk_view_context_get(m_ewkView);
114 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
118 ///\note Odroid modification - not exists in WebKit API
119 // ewk_cookie_manager_widget_cookie_directory_set(ewk_context_cookie_manager_get(context), webkit_path.c_str());
123 m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
127 void WebView::registerCallbacks()
129 #if defined(USE_EWEBKIT)
130 evas_object_smart_callback_add(m_ewkView, "load,started", __loadStarted, this);
131 evas_object_smart_callback_add(m_ewkView, "load,stop", __loadStop, this);
132 evas_object_smart_callback_add(m_ewkView, "load,finished", __loadFinished, this);
133 evas_object_smart_callback_add(m_ewkView, "load,progress", __loadProgress, this);
134 evas_object_smart_callback_add(m_ewkView, "load,error", __loadError, this);
136 evas_object_smart_callback_add(m_ewkView, "title,changed", __titleChanged, this);
137 evas_object_smart_callback_add(m_ewkView, "url,changed", __urlChanged, this);
139 evas_object_smart_callback_add(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
141 evas_object_smart_callback_add(m_ewkView, "create,window", __newWindowRequest, this);
142 evas_object_smart_callback_add(m_ewkView, "close,window", __closeWindowRequest, this);
144 evas_object_smart_callback_add(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
145 evas_object_smart_callback_add(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
146 evas_object_smart_callback_add(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
147 evas_object_smart_callback_add(m_ewkView, "authentication,request", __authenticationRequest, this);
148 evas_object_smart_callback_add(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
150 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView, this);
151 evas_object_smart_callback_add(m_ewkView, "icon,received", __faviconChanged, this);
153 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
154 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
158 void WebView::unregisterCallbacks()
160 #if defined(USE_EWEBKIT)
161 evas_object_smart_callback_del_full(m_ewkView, "load,started", __loadStarted, this);
162 evas_object_smart_callback_del_full(m_ewkView, "load,stop", __loadStop, this);
163 evas_object_smart_callback_del_full(m_ewkView, "load,finished", __loadFinished, this);
164 evas_object_smart_callback_del_full(m_ewkView, "load,progress", __loadProgress, this);
165 evas_object_smart_callback_del_full(m_ewkView, "load,error", __loadError, this);
167 evas_object_smart_callback_del_full(m_ewkView, "title,changed", __titleChanged, this);
168 evas_object_smart_callback_del_full(m_ewkView, "url,changed", __urlChanged, this);
170 evas_object_smart_callback_del_full(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
172 evas_object_smart_callback_del_full(m_ewkView, "create,window", __newWindowRequest, this);
173 evas_object_smart_callback_del_full(m_ewkView, "close,window", __closeWindowRequest, this);
175 evas_object_smart_callback_del_full(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
176 evas_object_smart_callback_del_full(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
177 evas_object_smart_callback_del_full(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
178 evas_object_smart_callback_del_full(m_ewkView, "authentication,request", __authenticationRequest, this);
179 evas_object_smart_callback_del_full(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
181 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView);
182 evas_object_smart_callback_del_full(m_ewkView, "icon,received", __faviconChanged, this);
184 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
185 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
189 void WebView::setupEwkSettings()
191 #if defined(USE_EWEBKIT)
193 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
194 ewk_settings_uses_keypad_without_user_action_set(settings, EINA_FALSE);
199 Evas_Object * WebView::getLayout()
204 void WebView::setURI(const std::string & uri)
206 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, uri.c_str());
207 #if defined(USE_EWEBKIT)
208 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
209 ewk_view_url_set(m_ewkView, uri.c_str());
214 std::string WebView::getURI(void)
216 #if defined(USE_EWEBKIT)
217 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, ewk_view_url_get(m_ewkView));
218 return fromChar(ewk_view_url_get(m_ewkView));
220 return std::string();
224 std::string WebView::getTitle(void)
229 void WebView::stopLoading(void)
231 #if defined(USE_EWEBKIT)
232 ewk_view_stop(m_ewkView);
237 void WebView::reload(void)
239 #if defined(USE_EWEBKIT)
243 ewk_view_url_set(m_ewkView, ewk_view_url_get(m_ewkView));
246 ewk_view_reload(m_ewkView);
250 void WebView::back(void)
252 #if defined(USE_EWEBKIT)
254 ewk_view_back(m_ewkView);
258 void WebView::forward(void)
260 #if defined(USE_EWEBKIT)
262 ewk_view_forward(m_ewkView);
266 bool WebView::isBackEnabled(void)
268 #if defined(USE_EWEBKIT)
269 return ewk_view_back_possible(m_ewkView);
275 bool WebView::isForwardEnabled(void)
277 #if defined(USE_EWEBKIT)
278 return ewk_view_forward_possible(m_ewkView);
284 bool WebView::isLoading()
289 bool WebView::isLoadError() const
294 void WebView::setPrivateMode(bool state)
296 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
299 #if defined(USE_EWEBKIT)
301 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
303 Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
305 ewk_settings_private_browsing_enabled_set(settings, state);
308 Ewk_Context *context = ewk_view_context_get(m_ewkView);
313 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_NEVER);
317 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
324 void WebView::confirmationResult(WebConfirmationPtr confirmation)
326 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
328 #if defined(USE_EWEBKIT)
330 switch(confirmation->getConfirmationType()) {
331 case WebConfirmation::ConfirmationType::Geolocation: {
332 Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
334 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
336 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
339 BROWSER_LOGE("Wrong ConfirmationResult");
342 // set geolocation permission
343 ewk_geolocation_permission_reply(request, result);
344 ewk_view_resume(m_ewkView);
347 m_confirmationGeolocationMap.erase(confirmation);
350 case WebConfirmation::ConfirmationType::UserMedia: {
351 Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
353 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
355 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
358 BROWSER_LOGE("Wrong ConfirmationResult");
362 // set usermedia permission
363 ewk_user_media_permission_reply(request, result);
364 ewk_view_resume(m_ewkView);
367 m_confirmationUserMediaMap.erase(confirmation);
370 case WebConfirmation::ConfirmationType::Notification: {
371 Ewk_Notification_Permission_Request *request = m_confirmationNotificationMap[confirmation];
373 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
375 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
378 BROWSER_LOGE("Wrong ConfirmationResult");
382 // set notification permission
383 ewk_notification_permission_reply(request, result);
384 ewk_view_resume(m_ewkView);
387 m_confirmationNotificationMap.erase(confirmation);
390 case WebConfirmation::ConfirmationType::CertificateConfirmation: {
391 CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
392 Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
394 if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
396 else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
399 BROWSER_LOGE("Wrong ConfirmationResult");
403 // set certificate confirmation
404 BROWSER_LOGE("NOT IMPLEMENTED: Certificate Confirmation handling!");
407 m_confirmationCertificatenMap.erase(cert);
410 case WebConfirmation::ConfirmationType::Authentication: {
411 AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
412 Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
413 if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
414 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Confirmation handling!");
415 } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
416 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Rejection handling!");
418 BROWSER_LOGE("Wrong ConfirmationResult");
423 m_confirmationAuthenticationMap.erase(auth);
435 std::shared_ptr<BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
437 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
439 M_ASSERT(targetWidth);
440 M_ASSERT(targetHeight);
442 std::shared_ptr<BrowserImage> noImage = std::make_shared<BrowserImage>();
443 evas_object_geometry_get(m_ewkView, nullptr, nullptr, &vw, &vh);
444 if (vw == 0 || vh == 0)
448 double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
449 double webkitProportions = (double)(vw) /(double)(vh);
450 if (webkitProportions >= snapshotProportions) {
451 // centring position of screenshot
452 area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
454 area.w = vh*getZoomFactor()*snapshotProportions;
455 area.h = vh*getZoomFactor();
460 area.w = vw*getZoomFactor();
461 area.h = vw*getZoomFactor()/snapshotProportions;
463 if (area.w == 0 || area.h == 0)
467 BROWSER_LOGD("[%s:%d] Before snapshot (screenshot) - look at the time of taking snapshot below",__func__, __LINE__);
468 #if defined(USE_EWEBKIT)
470 Evas_Object *snapshot = ewk_view_screenshot_contents_get( m_ewkView, area, 1.0, evas_object_evas_get(m_ewkView));
471 BROWSER_LOGD("[%s:%d] Snapshot (screenshot) catched, evas pointer: %p",__func__, __LINE__, snapshot);
473 return EflTools::getBrowserImage(snapshot);
480 #if defined(USE_EWEBKIT)
481 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
483 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
485 WebView * self = reinterpret_cast<WebView *>(data);
487 if(!self->hasFocus())
488 self->ewkViewClicked();
491 void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
493 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
495 WebView * self = reinterpret_cast<WebView *>(data);
496 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
497 BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
498 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
499 m_webEngine = std::dynamic_pointer_cast
501 basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
503 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
504 M_ASSERT(m_webEngine);
506 /// \todo: Choose newly created tab.
507 TabId id = m_webEngine->addTab(std::string(), &self->getTabId());
508 BROWSER_LOGD("Created tab: %s", id.toString().c_str());
510 Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
511 *static_cast<Evas_Object**>(out) = tab_ewk_view;
514 void WebView::__closeWindowRequest(void *data, Evas_Object *, void *)
516 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
517 WebView * self = reinterpret_cast<WebView *>(data);
518 std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
519 std::dynamic_pointer_cast
520 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
521 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
522 m_webEngine->closeTab(self->getTabId());
525 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
527 WebView * self = reinterpret_cast<WebView *>(data);
529 BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
531 self->m_isLoading = true;
533 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
534 cache->clearThumb(self->m_tabId);
537 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
539 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
541 WebView * self = reinterpret_cast<WebView *>(data);
542 self->m_isLoading = false;
547 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
549 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
551 WebView * self = reinterpret_cast<WebView *>(data);
552 self->m_isLoading = false;
553 self->m_loadProgress = 1;
555 self->loadFinished();
556 self->loadProgress(self->m_loadProgress);
557 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
558 cache->updateThumb(self->m_tabId);
561 void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_info)
563 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
565 WebView * self = reinterpret_cast<WebView *>(data);
566 self->m_loadProgress = *(double *)event_info;
568 self->loadProgress(self->m_loadProgress);
571 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
573 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
575 WebView *self = reinterpret_cast<WebView*>(data);
576 Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
577 Ewk_Error_Type errorType = ewk_error_type_get(error);
579 BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
580 __PRETTY_FUNCTION__, __LINE__, errorType);
582 BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
583 int errorCode = ewk_error_code_get(error);
584 if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
586 BROWSER_LOGD("Stop signal emitted");
587 BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
588 evas_object_smart_callback_call(obj, "load,stop", nullptr);
593 self->m_loadError=true;
597 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
599 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
601 WebView * self = reinterpret_cast<WebView *>(data);
602 self->m_title = fromChar(ewk_view_title_get(obj));
604 self->titleChanged(self->m_title);
607 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
609 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
611 WebView * self = reinterpret_cast<WebView *>(data);
612 BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
613 self->uriChanged(self->getURI());
614 self->tabIdChecker(self->m_tabId);
617 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
619 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
621 WebView * self = reinterpret_cast<WebView *>(data);
622 self->backwardEnableChanged(self->isBackEnabled());
623 self->forwardEnableChanged(self->isForwardEnabled());
626 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
630 WebView * self = static_cast<WebView *>(data);
631 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));
633 BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
634 self->faviconImage = EflTools::getBrowserImage(favicon);
635 evas_object_unref(favicon);
636 self->favIconChanged(self->faviconImage);
641 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
643 BROWSER_LOGD("%s", __func__);
644 WebView * self = reinterpret_cast<WebView *>(data);
645 self->IMEStateChanged(false);
648 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
650 BROWSER_LOGD("%s", __func__);
651 WebView * self = reinterpret_cast<WebView *>(data);
652 self->IMEStateChanged(true);
655 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
657 std::string protocol = fromChar(ewk_security_origin_protocol_get(origin));
658 std::string uri = fromChar(ewk_security_origin_host_get(origin));
659 std::string url = (boost::format("%1%://%2%") % protocol % uri).str();
663 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
665 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
667 WebView * self = reinterpret_cast<WebView *>(data);
669 Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
674 ewk_view_suspend(self->m_ewkView);
676 std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
678 ///\todo add translations
679 std::string message = (boost::format("%1% Requests your location") % url).str();
681 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
684 self->m_confirmationGeolocationMap[c] = request;
686 self->cofirmationRequest(c);
690 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
692 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
694 WebView * self = reinterpret_cast<WebView *>(data);
696 Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
701 ewk_view_suspend(self->m_ewkView);
703 ///\todo add translations
704 std::string message = "User media permission request";
706 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
709 self->m_confirmationUserMediaMap[c] = request;
711 self->cofirmationRequest(c);
715 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
717 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
719 WebView * self = reinterpret_cast<WebView *>(data);
721 Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
726 ewk_view_suspend(self->m_ewkView);
728 ///\todo add translations
729 std::string message = (boost::format("%1% wants to display notifications") % self->getURI()).str();
731 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, self->getURI(), message);
734 self->m_confirmationNotificationMap[c] = request;
736 self->cofirmationRequest(c);
740 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
742 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
744 WebView * self = reinterpret_cast<WebView *>(data);
746 Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
747 EINA_SAFETY_ON_NULL_RETURN(request);
749 std::string url = self->getURI();
750 std::string message = (boost::format("A username and password are being requested by %1%.") % url).str();
752 AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
754 self->m_confirmationAuthenticationMap[c] = request;
756 self->cofirmationRequest(c);
760 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
762 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
764 WebView * self = reinterpret_cast<WebView *>(data);
766 Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
771 ewk_view_suspend(self->m_ewkView);
773 std::string url = self->getURI();
775 ///\todo add translations
776 std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
778 CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
780 c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
783 self->m_confirmationCertificatenMap[c] = request;
785 self->cofirmationRequest(c);
790 void WebView::setFocus()
792 elm_object_focus_set(m_ewkView, EINA_TRUE);
795 void WebView::clearFocus()
797 elm_object_focus_set(m_ewkView, EINA_FALSE);
800 bool WebView::hasFocus() const
802 return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
805 double WebView::getZoomFactor() const
807 if(EINA_UNLIKELY(m_ewkView == nullptr)){
811 #if defined(USE_EWEBKIT)
812 return ewk_view_page_zoom_get(m_ewkView);
818 void WebView::setZoomFactor(double zoomFactor)
820 #if defined(USE_EWEBKIT)
822 //using zoomFactor = 0 sets zoom "fit to screen"
824 if(zoomFactor != getZoomFactor())
825 ewk_view_page_zoom_set(m_ewkView, zoomFactor);
830 void WebView::scrollView(const int& dx, const int& dy)
832 ewk_view_scroll_by(m_ewkView, dx, dy);
835 const TabId& WebView::getTabId(){
840 std::shared_ptr<BrowserImage> WebView::getFavicon()
842 BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
844 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));
845 faviconImage = EflTools::getBrowserImage(favicon);
846 evas_object_unref(favicon);
848 if(faviconImage.get())
851 BROWSER_LOGD("[%s:%d] Returned favicon is empty!", __PRETTY_FUNCTION__, __LINE__);
852 return std::make_shared<BrowserImage>();
855 void WebView::clearPrivateData()
857 BROWSER_LOGD("Clearing private data");
858 #if defined(USE_EWEBKIT)
861 Ewk_Context *context = ewk_view_context_get(m_ewkView);
864 ewk_context_web_storage_delete_all(context);
865 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
871 void WebView::searchOnWebsite(const std::string & searchString, int flags)
873 ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
874 Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
875 BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
878 void WebView::switchToDesktopMode() {
879 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
880 int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT);
881 m_desktopMode = true;
884 void WebView::switchToMobileMode() {
885 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
886 int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT_MOBILE);
887 m_desktopMode = false;
890 bool WebView::isDesktopMode() const {
891 return m_desktopMode;
894 } /* namespace webkitengine_service */
895 } /* end of basic_webengine */
896 } /* end of tizen_browser */