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 "app_common.h"
41 #include "BrowserAssert.h"
42 #include "BrowserLogger.h"
44 #include "GeneralTools.h"
45 #include "Tools/WorkQueue.h"
46 #include "ServiceManager.h"
48 #define certificate_crt_path CERTS_DIR
50 #define APPLICATION_NAME_FOR_USER_AGENT "SamsungBrowser/1.0"
52 #define APPLICATION_NAME_FOR_USER_AGENT "Mozilla/5.0 (X11; SMART-TV; Linux) AppleWebkit/538.1 (KHTML, like Gecko) Safari/538.1"
55 //TODO: temporary user agent for mobile display, change to proper one
56 #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"
58 using namespace tizen_browser::tools;
60 namespace tizen_browser {
61 namespace basic_webengine {
62 namespace webkitengine_service {
64 const std::string WebView::COOKIES_PATH = "cookies";
66 WebView::WebView(Evas_Object * obj, TabId tabId)
69 , m_ewkContext(ewk_context_new())
70 , m_title(std::string())
75 config.load("whatever");
80 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
83 unregisterCallbacks();
86 ewk_context_delete(m_ewkContext);
89 void WebView::init(bool desktopMode, Evas_Object * opener)
91 #if defined(USE_EWEBKIT)
92 M_ASSERT(m_ewkContext);
93 m_ewkView = ewk_view_add_with_context(evas_object_evas_get(m_parent), m_ewkContext);
95 evas_object_data_set(m_ewkView, "_container", this);
96 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, this);
98 evas_object_color_set(m_ewkView, 255, 255, 255, 255);
99 evas_object_size_hint_weight_set(m_ewkView, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100 evas_object_size_hint_align_set(m_ewkView, EVAS_HINT_FILL, EVAS_HINT_FILL);
102 switchToDesktopMode();
104 switchToMobileMode();
106 //\todo: when value is other than 1.0, scroller is located improperly
107 // ewk_view_device_pixel_ratio_set(m_ewkView, 1.0f);
110 ewk_view_resume(m_ewkView);
113 ewk_context_cache_model_set(m_ewkContext, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
114 std::string path = app_get_data_path() + COOKIES_PATH;
115 ewk_cookie_manager_persistent_storage_set(ewk_context_cookie_manager_get(m_ewkContext), path.c_str(), EWK_COOKIE_PERSISTENT_STORAGE_SQLITE);
120 m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
124 void WebView::registerCallbacks()
126 #if defined(USE_EWEBKIT)
127 evas_object_smart_callback_add(m_ewkView, "load,started", __loadStarted, this);
128 evas_object_smart_callback_add(m_ewkView, "load,stop", __loadStop, this);
129 evas_object_smart_callback_add(m_ewkView, "load,finished", __loadFinished, this);
130 evas_object_smart_callback_add(m_ewkView, "load,progress", __loadProgress, this);
131 evas_object_smart_callback_add(m_ewkView, "load,error", __loadError, this);
133 evas_object_smart_callback_add(m_ewkView, "title,changed", __titleChanged, this);
134 evas_object_smart_callback_add(m_ewkView, "url,changed", __urlChanged, this);
136 evas_object_smart_callback_add(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
138 evas_object_smart_callback_add(m_ewkView, "create,window", __newWindowRequest, this);
139 evas_object_smart_callback_add(m_ewkView, "close,window", __closeWindowRequest, this);
141 evas_object_smart_callback_add(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
142 evas_object_smart_callback_add(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
143 evas_object_smart_callback_add(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
144 evas_object_smart_callback_add(m_ewkView, "authentication,request", __authenticationRequest, this);
145 evas_object_smart_callback_add(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
147 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView, this);
148 evas_object_smart_callback_add(m_ewkView, "icon,received", __faviconChanged, this);
150 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
151 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
155 void WebView::unregisterCallbacks()
157 #if defined(USE_EWEBKIT)
158 evas_object_smart_callback_del_full(m_ewkView, "load,started", __loadStarted, this);
159 evas_object_smart_callback_del_full(m_ewkView, "load,stop", __loadStop, this);
160 evas_object_smart_callback_del_full(m_ewkView, "load,finished", __loadFinished, this);
161 evas_object_smart_callback_del_full(m_ewkView, "load,progress", __loadProgress, this);
162 evas_object_smart_callback_del_full(m_ewkView, "load,error", __loadError, this);
164 evas_object_smart_callback_del_full(m_ewkView, "title,changed", __titleChanged, this);
165 evas_object_smart_callback_del_full(m_ewkView, "url,changed", __urlChanged, this);
167 evas_object_smart_callback_del_full(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
169 evas_object_smart_callback_del_full(m_ewkView, "create,window", __newWindowRequest, this);
170 evas_object_smart_callback_del_full(m_ewkView, "close,window", __closeWindowRequest, this);
172 evas_object_smart_callback_del_full(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
173 evas_object_smart_callback_del_full(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
174 evas_object_smart_callback_del_full(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
175 evas_object_smart_callback_del_full(m_ewkView, "authentication,request", __authenticationRequest, this);
176 evas_object_smart_callback_del_full(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
178 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView);
179 evas_object_smart_callback_del_full(m_ewkView, "icon,received", __faviconChanged, this);
181 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
182 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
186 void WebView::setupEwkSettings()
188 #if defined(USE_EWEBKIT)
190 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
191 ewk_settings_uses_keypad_without_user_action_set(settings, EINA_FALSE);
196 Evas_Object * WebView::getLayout()
201 void WebView::setURI(const std::string & uri)
203 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, uri.c_str());
204 #if defined(USE_EWEBKIT)
205 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
206 ewk_view_url_set(m_ewkView, uri.c_str());
211 std::string WebView::getURI(void)
213 #if defined(USE_EWEBKIT)
214 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, ewk_view_url_get(m_ewkView));
215 return fromChar(ewk_view_url_get(m_ewkView));
217 return std::string();
221 std::string WebView::getTitle(void)
226 void WebView::stopLoading(void)
228 #if defined(USE_EWEBKIT)
229 ewk_view_stop(m_ewkView);
234 void WebView::reload(void)
236 #if defined(USE_EWEBKIT)
240 ewk_view_url_set(m_ewkView, ewk_view_url_get(m_ewkView));
243 ewk_view_reload(m_ewkView);
247 void WebView::back(void)
249 #if defined(USE_EWEBKIT)
251 ewk_view_back(m_ewkView);
255 void WebView::forward(void)
257 #if defined(USE_EWEBKIT)
259 ewk_view_forward(m_ewkView);
263 bool WebView::isBackEnabled(void)
265 #if defined(USE_EWEBKIT)
266 return ewk_view_back_possible(m_ewkView);
272 bool WebView::isForwardEnabled(void)
274 #if defined(USE_EWEBKIT)
275 return ewk_view_forward_possible(m_ewkView);
281 bool WebView::isLoading()
286 bool WebView::isLoadError() const
291 void WebView::setPrivateMode(bool state)
293 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
296 #if defined(USE_EWEBKIT)
298 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
300 Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
302 ewk_settings_private_browsing_enabled_set(settings, state);
305 Ewk_Context *context = ewk_view_context_get(m_ewkView);
310 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_NEVER);
314 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
321 void WebView::confirmationResult(WebConfirmationPtr confirmation)
323 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
325 #if defined(USE_EWEBKIT)
327 switch(confirmation->getConfirmationType()) {
328 case WebConfirmation::ConfirmationType::Geolocation: {
329 Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
331 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
333 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
336 BROWSER_LOGE("Wrong ConfirmationResult");
339 // set geolocation permission
340 ewk_geolocation_permission_reply(request, result);
341 ewk_view_resume(m_ewkView);
344 m_confirmationGeolocationMap.erase(confirmation);
347 case WebConfirmation::ConfirmationType::UserMedia: {
348 Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
350 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
352 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
355 BROWSER_LOGE("Wrong ConfirmationResult");
359 // set usermedia permission
360 ewk_user_media_permission_reply(request, result);
361 ewk_view_resume(m_ewkView);
364 m_confirmationUserMediaMap.erase(confirmation);
367 case WebConfirmation::ConfirmationType::Notification: {
368 Ewk_Notification_Permission_Request *request = m_confirmationNotificationMap[confirmation];
370 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
372 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
375 BROWSER_LOGE("Wrong ConfirmationResult");
379 // set notification permission
380 ewk_notification_permission_reply(request, result);
381 ewk_view_resume(m_ewkView);
384 m_confirmationNotificationMap.erase(confirmation);
387 case WebConfirmation::ConfirmationType::CertificateConfirmation: {
388 CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
389 Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
391 if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
393 else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
396 BROWSER_LOGE("Wrong ConfirmationResult");
400 // set certificate confirmation
401 BROWSER_LOGE("NOT IMPLEMENTED: Certificate Confirmation handling!");
404 m_confirmationCertificatenMap.erase(cert);
407 case WebConfirmation::ConfirmationType::Authentication: {
408 AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
409 Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
410 if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
411 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Confirmation handling!");
412 } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
413 BROWSER_LOGE("NOT IMPLEMENTED: Autenthication Request Rejection handling!");
415 BROWSER_LOGE("Wrong ConfirmationResult");
420 m_confirmationAuthenticationMap.erase(auth);
432 std::shared_ptr<BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
434 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
436 M_ASSERT(targetWidth);
437 M_ASSERT(targetHeight);
439 std::shared_ptr<BrowserImage> noImage = std::make_shared<BrowserImage>();
440 evas_object_geometry_get(m_ewkView, nullptr, nullptr, &vw, &vh);
441 if (vw == 0 || vh == 0)
445 double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
446 double webkitProportions = (double)(vw) /(double)(vh);
447 if (webkitProportions >= snapshotProportions) {
448 // centring position of screenshot
449 area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
451 area.w = vh*getZoomFactor()*snapshotProportions;
452 area.h = vh*getZoomFactor();
457 area.w = vw*getZoomFactor();
458 area.h = vw*getZoomFactor()/snapshotProportions;
460 if (area.w == 0 || area.h == 0)
464 BROWSER_LOGD("[%s:%d] Before snapshot (screenshot) - look at the time of taking snapshot below",__func__, __LINE__);
465 #if defined(USE_EWEBKIT)
467 Evas_Object *snapshot = ewk_view_screenshot_contents_get( m_ewkView, area, 1.0, evas_object_evas_get(m_ewkView));
468 BROWSER_LOGD("[%s:%d] Snapshot (screenshot) catched, evas pointer: %p",__func__, __LINE__, snapshot);
470 return EflTools::getBrowserImage(snapshot);
477 #if defined(USE_EWEBKIT)
478 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
480 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
482 WebView * self = reinterpret_cast<WebView *>(data);
484 if(!self->hasFocus())
485 self->ewkViewClicked();
488 void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
490 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
492 WebView * self = reinterpret_cast<WebView *>(data);
493 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
494 BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
495 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
496 m_webEngine = std::dynamic_pointer_cast
498 basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
500 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
501 M_ASSERT(m_webEngine);
503 /// \todo: Choose newly created tab.
505 if (m_webEngine->currentTabId() != (id = m_webEngine->addTab(std::string(), &self->getTabId()))) {
506 BROWSER_LOGD("Created tab: %s", id.toString().c_str());
507 Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
508 *static_cast<Evas_Object**>(out) = tab_ewk_view;
512 void WebView::__closeWindowRequest(void *data, Evas_Object *, void *)
514 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
515 WebView * self = reinterpret_cast<WebView *>(data);
516 std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
517 std::dynamic_pointer_cast
518 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
519 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
520 m_webEngine->closeTab(self->getTabId());
523 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
525 WebView * self = reinterpret_cast<WebView *>(data);
527 BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
529 self->m_isLoading = true;
531 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
532 cache->clearThumb(self->m_tabId);
535 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
537 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
539 WebView * self = reinterpret_cast<WebView *>(data);
540 self->m_isLoading = false;
545 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
547 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
549 WebView * self = reinterpret_cast<WebView *>(data);
551 self->m_isLoading = false;
552 self->m_loadProgress = 1;
554 self->loadFinished();
555 self->loadProgress(self->m_loadProgress);
556 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
557 cache->updateThumb(self->m_tabId);
560 void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_info)
562 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
564 WebView * self = reinterpret_cast<WebView *>(data);
565 self->m_loadProgress = *(double *)event_info;
566 self->loadProgress(self->m_loadProgress);
569 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
571 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
573 WebView *self = reinterpret_cast<WebView*>(data);
574 Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
575 Ewk_Error_Type errorType = ewk_error_type_get(error);
577 BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
578 __PRETTY_FUNCTION__, __LINE__, errorType);
580 BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
581 int errorCode = ewk_error_code_get(error);
582 if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
584 BROWSER_LOGD("Stop signal emitted");
585 BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
586 evas_object_smart_callback_call(obj, "load,stop", nullptr);
591 self->m_loadError=true;
595 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
597 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
599 WebView * self = reinterpret_cast<WebView *>(data);
600 self->m_title = fromChar(ewk_view_title_get(obj));
601 self->titleChanged(self->m_title);
604 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
606 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
608 WebView * self = reinterpret_cast<WebView *>(data);
609 BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
610 self->uriChanged(self->getURI());
611 self->tabIdChecker(self->m_tabId);
614 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
616 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
618 WebView * self = reinterpret_cast<WebView *>(data);
619 self->backwardEnableChanged(self->isBackEnabled());
620 self->forwardEnableChanged(self->isForwardEnabled());
623 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
627 WebView * self = static_cast<WebView *>(data);
628 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));
630 BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
631 self->faviconImage = EflTools::getBrowserImage(favicon);
632 evas_object_unref(favicon);
633 self->favIconChanged(self->faviconImage);
638 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
640 BROWSER_LOGD("%s", __func__);
641 WebView * self = reinterpret_cast<WebView *>(data);
642 self->IMEStateChanged(false);
645 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
647 BROWSER_LOGD("%s", __func__);
648 WebView * self = reinterpret_cast<WebView *>(data);
649 self->IMEStateChanged(true);
652 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
654 std::string protocol = fromChar(ewk_security_origin_protocol_get(origin));
655 std::string uri = fromChar(ewk_security_origin_host_get(origin));
656 std::string url = (boost::format("%1%://%2%") % protocol % uri).str();
660 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
662 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
664 WebView * self = reinterpret_cast<WebView *>(data);
666 Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
671 ewk_view_suspend(self->m_ewkView);
673 std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
675 ///\todo add translations
676 std::string message = (boost::format("%1% Requests your location") % url).str();
678 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
681 self->m_confirmationGeolocationMap[c] = request;
683 self->cofirmationRequest(c);
687 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
689 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
691 WebView * self = reinterpret_cast<WebView *>(data);
693 Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
698 ewk_view_suspend(self->m_ewkView);
700 ///\todo add translations
701 std::string message = "User media permission request";
703 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
706 self->m_confirmationUserMediaMap[c] = request;
708 self->cofirmationRequest(c);
712 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
714 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
716 WebView * self = reinterpret_cast<WebView *>(data);
718 Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
723 ewk_view_suspend(self->m_ewkView);
725 ///\todo add translations
726 std::string message = (boost::format("%1% wants to display notifications") % self->getURI()).str();
728 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, self->getURI(), message);
731 self->m_confirmationNotificationMap[c] = request;
733 self->cofirmationRequest(c);
737 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
739 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
741 WebView * self = reinterpret_cast<WebView *>(data);
743 Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
744 EINA_SAFETY_ON_NULL_RETURN(request);
746 std::string url = self->getURI();
747 std::string message = (boost::format("A username and password are being requested by %1%.") % url).str();
749 AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
751 self->m_confirmationAuthenticationMap[c] = request;
753 self->cofirmationRequest(c);
757 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
759 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
761 WebView * self = reinterpret_cast<WebView *>(data);
763 Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
768 ewk_view_suspend(self->m_ewkView);
770 std::string url = self->getURI();
772 ///\todo add translations
773 std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
775 CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
777 c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
780 self->m_confirmationCertificatenMap[c] = request;
782 self->cofirmationRequest(c);
787 void WebView::setFocus()
789 elm_object_focus_set(m_ewkView, EINA_TRUE);
792 void WebView::clearFocus()
794 elm_object_focus_set(m_ewkView, EINA_FALSE);
797 bool WebView::hasFocus() const
799 return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
802 double WebView::getZoomFactor() const
804 if(EINA_UNLIKELY(m_ewkView == nullptr)) {
808 #if defined(USE_EWEBKIT)
809 return ewk_view_page_zoom_get(m_ewkView);
815 void WebView::setZoomFactor(double zoomFactor)
817 #if defined(USE_EWEBKIT)
819 //using zoomFactor = 0 sets zoom "fit to screen"
821 if(zoomFactor != getZoomFactor())
822 ewk_view_page_zoom_set(m_ewkView, zoomFactor);
827 void WebView::scrollView(const int& dx, const int& dy)
829 ewk_view_scroll_by(m_ewkView, dx, dy);
832 const TabId& WebView::getTabId() {
837 std::shared_ptr<BrowserImage> WebView::getFavicon()
839 BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
841 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));
842 faviconImage = EflTools::getBrowserImage(favicon);
843 evas_object_unref(favicon);
845 if(faviconImage.get())
848 BROWSER_LOGD("[%s:%d] Returned favicon is empty!", __PRETTY_FUNCTION__, __LINE__);
849 return std::make_shared<BrowserImage>();
852 void WebView::clearPrivateData()
854 BROWSER_LOGD("Clearing private data");
855 #if defined(USE_EWEBKIT)
858 Ewk_Context *context = ewk_view_context_get(m_ewkView);
861 ewk_context_web_storage_delete_all(context);
862 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
868 void WebView::searchOnWebsite(const std::string & searchString, int flags)
870 ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
871 Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
872 BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
875 void WebView::switchToDesktopMode() {
876 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
877 int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT);
878 m_desktopMode = true;
881 void WebView::switchToMobileMode() {
882 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
883 int res = ewk_view_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT_MOBILE);
884 m_desktopMode = false;
887 bool WebView::isDesktopMode() const {
888 return m_desktopMode;
891 } /* namespace webkitengine_service */
892 } /* end of basic_webengine */
893 } /* end of tizen_browser */