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 Ewk_Context *context = ewk_context_default_get();
81 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
82 ewk_context_certificate_file_set(context, certificate_crt_path);
85 m_ewkView = ewk_view_add(evas_object_evas_get(m_parent));
87 evas_object_data_set(m_ewkView, "_container", this);
88 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, this);
90 evas_object_color_set(m_ewkView, 255, 255, 255, 255);
91 evas_object_size_hint_weight_set(m_ewkView, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
92 evas_object_size_hint_align_set(m_ewkView, EVAS_HINT_FILL, EVAS_HINT_FILL);
93 ewk_view_application_name_for_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT);
94 //\todo: when value is other than 1.0, scroller is located improperly
95 // ewk_view_device_pixel_ratio_set(m_ewkView, 1.0f);
98 ewk_view_resume(m_ewkView);
101 // set local storage, favion, cookies
102 std::string webkit_path = boost::any_cast <std::string> (config.get("webkit/dir"));
103 // ewk_context_web_storage_path_set(context, (webkit_path + std::string("/storage")).c_str());
104 ewk_context_favicon_database_directory_set(context, (webkit_path + std::string("/favicon")).c_str());
105 ewk_cookie_manager_persistent_storage_set(ewk_context_cookie_manager_get(context)
106 , (webkit_path + std::string("/cookies.db")).c_str()
107 , EWK_COOKIE_PERSISTENT_STORAGE_SQLITE);
109 ///\note Odroid modification - not exists in WebKit API
110 // ewk_cookie_manager_widget_cookie_directory_set(ewk_context_cookie_manager_get(context), webkit_path.c_str());
115 m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
119 void WebView::registerCallbacks()
121 #if defined(USE_EWEBKIT)
122 evas_object_smart_callback_add(m_ewkView, "load,started", __loadStarted, this);
123 evas_object_smart_callback_add(m_ewkView, "load,stop", __loadStop, this);
124 evas_object_smart_callback_add(m_ewkView, "load,finished", __loadFinished, this);
125 evas_object_smart_callback_add(m_ewkView, "load,progress", __loadProgress, this);
126 evas_object_smart_callback_add(m_ewkView, "load,error", __loadError, this);
128 evas_object_smart_callback_add(m_ewkView, "title,changed", __titleChanged, this);
129 evas_object_smart_callback_add(m_ewkView, "url,changed", __urlChanged, this);
131 evas_object_smart_callback_add(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
133 evas_object_smart_callback_add(m_ewkView, "create,window", __newWindowRequest, this);
134 evas_object_smart_callback_add(m_ewkView, "close,window", __closeWindowRequest, this);
136 evas_object_smart_callback_add(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
137 evas_object_smart_callback_add(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
138 evas_object_smart_callback_add(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
139 evas_object_smart_callback_add(m_ewkView, "authentication,request", __authenticationRequest, this);
140 evas_object_smart_callback_add(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
142 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView, this);
143 evas_object_smart_callback_add(m_ewkView, "icon,received", __faviconChanged, this);
145 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
146 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
150 void WebView::unregisterCallbacks()
152 #if defined(USE_EWEBKIT)
153 evas_object_smart_callback_del_full(m_ewkView, "load,started", __loadStarted, this);
154 evas_object_smart_callback_del_full(m_ewkView, "load,stop", __loadStop, this);
155 evas_object_smart_callback_del_full(m_ewkView, "load,finished", __loadFinished, this);
156 evas_object_smart_callback_del_full(m_ewkView, "load,progress", __loadProgress, this);
157 evas_object_smart_callback_del_full(m_ewkView, "load,error", __loadError, this);
159 evas_object_smart_callback_del_full(m_ewkView, "title,changed", __titleChanged, this);
160 evas_object_smart_callback_del_full(m_ewkView, "url,changed", __urlChanged, this);
162 evas_object_smart_callback_del_full(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
164 evas_object_smart_callback_del_full(m_ewkView, "create,window", __newWindowRequest, this);
165 evas_object_smart_callback_del_full(m_ewkView, "close,window", __closeWindowRequest, this);
167 evas_object_smart_callback_del_full(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
168 evas_object_smart_callback_del_full(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
169 evas_object_smart_callback_del_full(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
170 evas_object_smart_callback_del_full(m_ewkView, "authentication,request", __authenticationRequest, this);
171 evas_object_smart_callback_del_full(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
173 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView);
174 evas_object_smart_callback_del_full(m_ewkView, "icon,received", __faviconChanged, this);
176 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
177 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
181 void WebView::setupEwkSettings()
183 #if defined(USE_EWEBKIT)
185 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
186 ewk_settings_uses_keypad_without_user_action_set(settings, EINA_FALSE);
191 Evas_Object * WebView::getLayout()
196 void WebView::setURI(const std::string & uri)
198 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, uri.c_str());
199 #if defined(USE_EWEBKIT)
200 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
201 ewk_view_url_set(m_ewkView, uri.c_str());
206 std::string WebView::getURI(void)
208 #if defined(USE_EWEBKIT)
209 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, ewk_view_url_get(m_ewkView));
210 return tizen_browser::tools::fromChar(ewk_view_url_get(m_ewkView));
212 return std::string();
216 std::string WebView::getTitle(void)
221 void WebView::stopLoading(void)
223 #if defined(USE_EWEBKIT)
224 ewk_view_stop(m_ewkView);
229 void WebView::reload(void)
231 #if defined(USE_EWEBKIT)
235 ewk_view_url_set(m_ewkView, ewk_view_url_get(m_ewkView));
238 ewk_view_reload(m_ewkView);
242 void WebView::back(void)
244 #if defined(USE_EWEBKIT)
246 ewk_view_back(m_ewkView);
250 void WebView::forward(void)
252 #if defined(USE_EWEBKIT)
254 ewk_view_forward(m_ewkView);
258 bool WebView::isBackEnabled(void)
260 #if defined(USE_EWEBKIT)
261 return ewk_view_back_possible(m_ewkView);
267 bool WebView::isForwardEnabled(void)
269 #if defined(USE_EWEBKIT)
270 return ewk_view_forward_possible(m_ewkView);
276 bool WebView::isLoading()
281 bool WebView::isLoadError() const
287 void WebView::setPrivateMode(bool state)
289 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
292 #if defined(USE_EWEBKIT)
294 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
296 Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
298 ewk_settings_private_browsing_enabled_set(settings, state);
300 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(ewk_context_default_get()), EWK_COOKIE_ACCEPT_POLICY_NEVER);
303 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(ewk_context_default_get()), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
308 void WebView::confirmationResult(WebConfirmationPtr confirmation)
310 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
312 #if defined(USE_EWEBKIT)
314 switch(confirmation->getConfirmationType()) {
315 case WebConfirmation::ConfirmationType::Geolocation: {
316 Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
318 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
320 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
323 BROWSER_LOGE("Wrong ConfirmationResult");
326 // set geolocation permission
327 ewk_geolocation_permission_request_set(request, result );
330 m_confirmationGeolocationMap.erase(confirmation);
333 case WebConfirmation::ConfirmationType::UserMedia: {
334 Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
336 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
338 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
341 BROWSER_LOGE("Wrong ConfirmationResult");
345 // set usermedia permission
346 ewk_user_media_permission_request_set(request, result);
349 m_confirmationUserMediaMap.erase(confirmation);
352 case WebConfirmation::ConfirmationType::Notification: {
353 Ewk_Notification_Permission_Request *request = m_confirmationNotificationMap[confirmation];
355 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
357 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
360 BROWSER_LOGE("Wrong ConfirmationResult");
364 // set notification permission
365 ewk_notification_permission_request_set(request, result);
368 m_confirmationNotificationMap.erase(confirmation);
371 case WebConfirmation::ConfirmationType::CertificateConfirmation: {
372 CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
373 Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
375 if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
377 else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
380 BROWSER_LOGE("Wrong ConfirmationResult");
384 // set certificate confirmation
385 ewk_certificate_policy_decision_allowed_set(request, result);
388 m_confirmationCertificatenMap.erase(cert);
391 case WebConfirmation::ConfirmationType::Authentication: {
392 AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
393 Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
394 if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
395 // set auth challange credential
396 ewk_auth_request_authenticate(request, const_cast<char*>(auth->getLogin().c_str()), const_cast<char*>(auth->getPassword().c_str()));
397 // ewk_object_unref(request);
398 } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
399 ewk_auth_request_cancel(request);
400 // ewk_object_unref(request);
402 BROWSER_LOGE("Wrong ConfirmationResult");
407 m_confirmationAuthenticationMap.erase(auth);
410 case WebConfirmation::ConfirmationType::ScriptAlert:
412 ewk_view_javascript_alert_reply(m_ewkView);
414 case WebConfirmation::ConfirmationType::ScriptConfirmation: {
416 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
418 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
421 BROWSER_LOGE("Wrong ConfirmationResult");
426 ewk_view_javascript_confirm_reply(m_ewkView, result);
429 case WebConfirmation::ConfirmationType::ScriptPrompt: {
430 ScriptPromptPtr prompt = std::dynamic_pointer_cast<ScriptPrompt, WebConfirmation>(confirmation);
432 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
434 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
437 BROWSER_LOGE("Wrong ConfirmationResult");
442 ewk_view_javascript_prompt_reply(m_ewkView, prompt->getUserData().c_str());
454 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
456 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
458 M_ASSERT(targetWidth);
459 M_ASSERT(targetHeight);
461 std::shared_ptr<tizen_browser::tools::BrowserImage> noImage = std::make_shared<tizen_browser::tools::BrowserImage>();
462 evas_object_geometry_get(m_ewkView, NULL, NULL, &vw, &vh);
463 if (vw == 0 || vh == 0)
467 double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
468 double webkitProportions = (double)(vw) /(double)(vh);
469 if (webkitProportions >= snapshotProportions) {
470 // centring position of screenshot
471 area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
473 area.w = vh*getZoomFactor()*snapshotProportions;
474 area.h = vh*getZoomFactor();
479 area.w = vw*getZoomFactor();
480 area.h = vw*getZoomFactor()/snapshotProportions;
482 if (area.w == 0 || area.h == 0)
485 double scaleW = (double)targetWidth / (double)(area.w);
486 double scaleH = (double)targetHeight / (double)(area.h);
488 BROWSER_LOGD("[%s:%d] Before snapshot (screenshot) - look at the time of taking snapshot below",__func__, __LINE__);
489 #if defined(USE_EWEBKIT)
491 Evas_Object *snapshot = ewk_view_screenshot_contents_get( m_ewkView, area, scaleW > scaleH ? scaleW : scaleH, evas_object_evas_get(m_ewkView));
492 BROWSER_LOGD("[%s:%d] Snapshot (screenshot) catched, evas pointer: %p",__func__, __LINE__, snapshot);
494 return tizen_browser::tools::EflTools::getBrowserImage(snapshot);
498 return std::shared_ptr<tizen_browser::tools::BrowserImage> ();
501 #if defined(USE_EWEBKIT)
502 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
504 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
506 WebView * self = reinterpret_cast<WebView *>(data);
508 if(!self->hasFocus())
509 self->ewkViewClicked();
512 void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
514 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
516 WebView * self = reinterpret_cast<WebView *>(data);
517 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
518 BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
519 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
520 m_webEngine = std::dynamic_pointer_cast
522 basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
524 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
525 M_ASSERT(m_webEngine);
527 /// \todo: Choose newly created tab.
528 TabId id = m_webEngine->addTab(std::string(), &self->getTabId());
529 BROWSER_LOGD("Created tab: %s", id.toString().c_str());
531 Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
532 *static_cast<Evas_Object**>(out) = tab_ewk_view;
535 void WebView::__closeWindowRequest(void *data, Evas_Object *, void *)
537 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
538 WebView * self = reinterpret_cast<WebView *>(data);
539 std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
540 std::dynamic_pointer_cast
541 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
542 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
543 m_webEngine->closeTab(self->getTabId());
546 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
548 WebView * self = reinterpret_cast<WebView *>(data);
550 BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
552 self->m_isLoading = true;
554 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
555 cache->clearThumb(self->m_tabId);
558 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
560 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
562 WebView * self = reinterpret_cast<WebView *>(data);
563 self->m_isLoading = false;
568 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
570 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
572 WebView * self = reinterpret_cast<WebView *>(data);
573 self->m_isLoading = false;
574 self->m_loadProgress = 1;
576 self->loadFinished();
577 self->loadProgress(self->m_loadProgress);
578 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
579 cache->updateThumb(self->m_tabId);
582 void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_info)
584 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
586 WebView * self = reinterpret_cast<WebView *>(data);
587 self->m_loadProgress = *(double *)event_info;
589 self->loadProgress(self->m_loadProgress);
592 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
594 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
596 WebView *self = reinterpret_cast<WebView*>(data);
597 Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
598 Ewk_Error_Type errorType = ewk_error_type_get(error);
600 BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
601 __PRETTY_FUNCTION__, __LINE__, errorType);
603 BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
604 int errorCode = ewk_error_code_get(error);
605 if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
607 BROWSER_LOGD("Stop signal emitted");
608 BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
609 evas_object_smart_callback_call(obj, "load,stop", NULL);
614 self->m_loadError=true;
618 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
620 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
622 WebView * self = reinterpret_cast<WebView *>(data);
623 self->m_title = tizen_browser::tools::fromChar(ewk_view_title_get(obj));
625 self->titleChanged(self->m_title);
628 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
630 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
632 WebView * self = reinterpret_cast<WebView *>(data);
633 BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
634 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
635 m_webEngine = std::dynamic_pointer_cast<basic_webengine::AbstractWebEngine<Evas_Object>, tizen_browser::core::AbstractService>(
636 tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
637 M_ASSERT(m_webEngine);
638 self->uriChanged(tizen_browser::tools::fromChar(reinterpret_cast<const char *>(event_info)));
639 self->tabIdChecker(self->m_tabId);
642 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
644 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
646 WebView * self = reinterpret_cast<WebView *>(data);
647 self->backwardEnableChanged(self->isBackEnabled());
648 self->forwardEnableChanged(self->isForwardEnabled());
651 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
655 WebView * self = static_cast<WebView *>(data);
656 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));
658 BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
659 self->faviconImage = tizen_browser::tools::EflTools::getBrowserImage(favicon);
660 evas_object_unref(favicon);
661 self->favIconChanged(self->faviconImage);
666 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
668 BROWSER_LOGD("%s", __func__);
669 WebView * self = reinterpret_cast<WebView *>(data);
670 self->IMEStateChanged(false);
673 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
675 BROWSER_LOGD("%s", __func__);
676 WebView * self = reinterpret_cast<WebView *>(data);
677 self->IMEStateChanged(true);
680 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
682 std::string protocol = tizen_browser::tools::fromChar(ewk_security_origin_protocol_get(origin));
683 std::string uri = tizen_browser::tools::fromChar(ewk_security_origin_host_get(origin));
684 int port = ewk_security_origin_port_get(origin);
687 url = (boost::format("%1%:%2%//%3%") % protocol % port % uri).str();
689 url = (boost::format("%1%://%2%") % protocol % uri).str();
693 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
695 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
697 WebView * self = reinterpret_cast<WebView *>(data);
699 Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
704 ewk_geolocation_permission_request_suspend(request);
706 std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
708 ///\todo add translations
709 std::string message = (boost::format("%1% Requests your location") % url).str();
711 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
714 self->m_confirmationGeolocationMap[c] = request;
716 self->cofirmationRequest(c);
720 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
722 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
724 WebView * self = reinterpret_cast<WebView *>(data);
726 Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
731 ewk_user_media_permission_request_suspend(request);
733 ///\todo add translations
734 std::string message = "User media permission request";
736 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
739 self->m_confirmationUserMediaMap[c] = request;
741 self->cofirmationRequest(c);
745 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
747 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
749 WebView * self = reinterpret_cast<WebView *>(data);
751 Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
756 ewk_notification_permission_request_suspend(request);
758 std::string url = WebView::securityOriginToUri(ewk_notification_permission_request_origin_get(request));
760 ///\todo add translations
761 std::string message = (boost::format("%1% wants to display notifications") % url).str();
763 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, url, message);
766 self->m_confirmationNotificationMap[c] = request;
768 self->cofirmationRequest(c);
772 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
774 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
776 WebView * self = reinterpret_cast<WebView *>(data);
778 Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
779 EINA_SAFETY_ON_NULL_RETURN(request);
781 std::string realm = tizen_browser::tools::fromChar(ewk_auth_request_realm_get(request));
782 // std::string url = tizen_browser::tools::fromChar(ewk_auth_request_host_get(request));
784 // ewk_object_ref(request);
786 ///\todo add translations
787 // std::string message = (boost::format("A username and password are being requested by %1%. The site says: \"%2%\"") % url % realm).str();
789 // AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
792 // self->m_confirmationAuthenticationMap[c] = request;
794 // self->cofirmationRequest(c);
798 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
800 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
802 WebView * self = reinterpret_cast<WebView *>(data);
804 Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
809 ewk_certificate_policy_decision_suspend(request);
811 std::string url = tizen_browser::tools::fromChar(ewk_certificate_policy_decision_url_get(request));
813 ///\todo add translations
814 std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
816 CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
818 c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
821 self->m_confirmationCertificatenMap[c] = request;
823 self->cofirmationRequest(c);
828 void WebView::setFocus()
830 elm_object_focus_set(m_ewkView, EINA_TRUE);
833 void WebView::clearFocus()
835 elm_object_focus_set(m_ewkView, EINA_FALSE);
838 bool WebView::hasFocus() const
840 return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
843 double WebView::getZoomFactor() const
845 if(EINA_UNLIKELY(m_ewkView == NULL)){
849 #if defined(USE_EWEBKIT)
850 return ewk_view_text_zoom_get(m_ewkView);
856 void WebView::setZoomFactor(double zoomFactor)
858 #if defined(USE_EWEBKIT)
860 //using zoomFactor = 0 sets zoom "fit to screen"
862 ewk_view_text_zoom_set(m_ewkView, zoomFactor);
868 const TabId& WebView::getTabId(){
873 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::getFavicon() {
874 BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
877 #if defined(USE_EWEBKIT)
878 if (faviconImage.get() == NULL) {
881 // Evas_Object * favicon = ewk_view_favicon_get(m_ewkView);
882 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));
884 Ewk_Favicon_Database * database = ewk_context_favicon_database_get(ewk_view_context_get(m_ewkView));
885 Evas_Object * favicon = ewk_favicon_database_icon_get(database, ewk_view_url_get(m_ewkView), evas_object_evas_get(m_ewkView));
890 evas_object_image_size_get(favicon, &w, &h);
891 BROWSER_LOGD("[%s]: Info about favicon: w:%d h:%d, type: %s", __func__, w, h, evas_object_type_get(favicon));
894 std::shared_ptr<tizen_browser::tools::BrowserImage>
895 image = tizen_browser::tools::EflTools::getBrowserImage(favicon);
897 evas_object_unref(favicon);
906 BROWSER_LOGE("[%s:%d]: Returned favicon is empty!", __PRETTY_FUNCTION__, __LINE__);
907 return std::make_shared<tizen_browser::tools::BrowserImage>();
910 void WebView::clearPrivateData()
912 BROWSER_LOGD("Clearing private data");
913 #if defined(USE_EWEBKIT)
914 Ewk_Context * context = ewk_context_default_get();
915 ewk_context_web_storage_delete_all(context);
916 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
920 void WebView::searchOnWebsite(const std::string & searchString, int flags)
922 ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
923 Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
924 BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
927 } /* namespace webkitengine_service */
928 } /* end of basic_webengine */
929 } /* end of tizen_browser */