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 <EWebKit2.h>
28 #include <ewk_chromium.h>
31 #include <boost/format.hpp>
32 #include <boost/regex.hpp>
33 #include <boost/algorithm/string/regex.hpp>
34 #include <boost/algorithm/string/classification.hpp>
35 #include <boost/algorithm/string/split.hpp>
36 #include <Elementary.h>
39 #include "AbstractWebEngine/AbstractWebEngine.h"
40 #include "AbstractWebEngine/TabThumbCache.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
49 #define APPLICATION_NAME_FOR_USER_AGENT "SamsungBrowser/1.0"
51 using namespace tizen_browser::tools;
53 namespace tizen_browser {
54 namespace basic_webengine {
55 namespace webkitengine_service {
57 WebView::WebView(Evas_Object * obj, TabId tabId)
64 config.load("whatever");
69 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
72 unregisterCallbacks();
76 void WebView::init(Evas_Object * opener)
78 #if defined(USE_EWEBKIT)
80 #if 0 //not using smart class
81 static Ewk_View_Smart_Class *clasz = NULL;
82 Ewk_Context *context = ewk_context_default_get();
85 ewk_view_smart_class_set(clasz);
87 // clasz->run_javascript_alert = onJavascriptAlert;
88 // clasz->run_javascript_confirm = onJavascriptConfirm;
89 // clasz->run_javascript_prompt = onJavascriptPrompt;
90 clasz->window_create = onWindowCreate;
91 clasz->window_close = onWindowClose;
93 ewk_context_cache_model_set(context, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
94 ewk_context_certificate_file_set(context, certificate_crt_path);
97 Evas_Smart *smart = evas_smart_class_new(&clasz->sc);
99 /// \todo: Consider process model. Now, One UIProcess / One WebProcess.
101 // m_ewkView = ewk_view_smart_add(evas_object_evas_get(m_parent), smart, context, ewk_view_page_group_get(opener));
103 m_ewkView = ewk_view_smart_add(evas_object_evas_get(m_parent), smart, context, ewk_page_group_create(NULL));
105 m_ewkView = ewk_view_add(evas_object_evas_get(m_parent));
106 // Ewk_Context *context = ewk_view_context_get(m_ewkView);
109 evas_object_data_set(m_ewkView, "_container", this);
110 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, this);
112 evas_object_color_set(m_ewkView, 255, 255, 255, 255);
113 evas_object_size_hint_weight_set(m_ewkView, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114 evas_object_size_hint_align_set(m_ewkView, EVAS_HINT_FILL, EVAS_HINT_FILL);
115 ewk_view_application_name_for_user_agent_set(m_ewkView, APPLICATION_NAME_FOR_USER_AGENT);
116 //\todo: when value is other than 1.0, scroller is located improperly
117 // ewk_view_device_pixel_ratio_set(m_ewkView, 1.0f);
120 ewk_view_resume(m_ewkView);
123 // set local storage, favion, cookies
124 std::string webkit_path = boost::any_cast <std::string> (config.get("webkit/dir"));
125 // ewk_context_web_storage_path_set(context, (webkit_path + std::string("/storage")).c_str());
126 ewk_context_favicon_database_directory_set(context, (webkit_path + std::string("/favicon")).c_str());
127 ewk_cookie_manager_persistent_storage_set(ewk_context_cookie_manager_get(context)
128 , (webkit_path + std::string("/cookies.db")).c_str()
129 , EWK_COOKIE_PERSISTENT_STORAGE_SQLITE);
131 ///\note Odroid modification - not exists in WebKit API
132 // ewk_cookie_manager_widget_cookie_directory_set(ewk_context_cookie_manager_get(context), webkit_path.c_str());
137 m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
141 void WebView::registerCallbacks()
143 #if defined(USE_EWEBKIT)
144 evas_object_smart_callback_add(m_ewkView, "load,started", __loadStarted, this);
145 evas_object_smart_callback_add(m_ewkView, "load,stop", __loadStop, this);
146 evas_object_smart_callback_add(m_ewkView, "load,finished", __loadFinished, this);
147 evas_object_smart_callback_add(m_ewkView, "load,progress", __loadProgress, this);
148 evas_object_smart_callback_add(m_ewkView, "load,error", __loadError, this);
150 evas_object_smart_callback_add(m_ewkView, "title,changed", __titleChanged, this);
151 evas_object_smart_callback_add(m_ewkView, "url,changed", __urlChanged, this);
153 evas_object_smart_callback_add(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
155 evas_object_smart_callback_add(m_ewkView, "create,window", __OnNewWindowRequest, this);
157 evas_object_smart_callback_add(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
158 evas_object_smart_callback_add(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
159 evas_object_smart_callback_add(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
160 evas_object_smart_callback_add(m_ewkView, "authentication,request", __authenticationRequest, this);
161 evas_object_smart_callback_add(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
163 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView, this);
164 evas_object_smart_callback_add(m_ewkView, "icon,received", __faviconChanged, this);
166 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
167 evas_object_smart_callback_add(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
171 void WebView::unregisterCallbacks()
173 #if defined(USE_EWEBKIT)
174 evas_object_smart_callback_del_full(m_ewkView, "load,started", __loadStarted, this);
175 evas_object_smart_callback_del_full(m_ewkView, "load,stop", __loadStop, this);
176 evas_object_smart_callback_del_full(m_ewkView, "load,finished", __loadFinished, this);
177 evas_object_smart_callback_del_full(m_ewkView, "load,progress", __loadProgress, this);
178 evas_object_smart_callback_del_full(m_ewkView, "load,error", __loadError, this);
180 evas_object_smart_callback_del_full(m_ewkView, "title,changed", __titleChanged, this);
181 evas_object_smart_callback_del_full(m_ewkView, "url,changed", __urlChanged, this);
183 evas_object_smart_callback_del_full(m_ewkView, "back,forward,list,changed", __backForwardListChanged, this);
185 evas_object_smart_callback_del_full(m_ewkView, "create,window", __OnNewWindowRequest, this);
187 evas_object_smart_callback_del_full(m_ewkView, "geolocation,permission,request", __geolocationPermissionRequest, this);
188 evas_object_smart_callback_del_full(m_ewkView, "usermedia,permission,request", __usermediaPermissionRequest, this);
189 evas_object_smart_callback_del_full(m_ewkView, "notification,permission,request", __notificationPermissionRequest, this);
190 evas_object_smart_callback_del_full(m_ewkView, "authentication,request", __authenticationRequest, this);
191 evas_object_smart_callback_del_full(m_ewkView, "request,certificate,confirm", __requestCertificationConfirm, this);
193 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, __setFocusToEwkView);
194 evas_object_smart_callback_del_full(m_ewkView, "icon,received", __faviconChanged, this);
196 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,closed", __IMEClosed, this);
197 evas_object_smart_callback_del_full(m_ewkView, "editorclient,ime,opened", __IMEOpened, this);
201 void WebView::setupEwkSettings()
203 #if defined(USE_EWEBKIT)
205 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
206 ewk_settings_uses_keypad_without_user_action_set(settings, EINA_FALSE);
211 Evas_Object * WebView::getLayout()
216 void WebView::setURI(const std::string & uri)
218 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, uri.c_str());
219 #if defined(USE_EWEBKIT)
220 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
221 ewk_view_url_set(m_ewkView, uri.c_str());
226 std::string WebView::getURI(void)
228 #if defined(USE_EWEBKIT)
229 BROWSER_LOGD("%s:%d %s uri=%s", __FILE__, __LINE__, __func__, ewk_view_url_get(m_ewkView));
230 return tizen_browser::tools::fromChar(ewk_view_url_get(m_ewkView));
232 return std::string();
236 std::string WebView::getTitle(void)
241 void WebView::stopLoading(void)
243 #if defined(USE_EWEBKIT)
244 ewk_view_stop(m_ewkView);
249 void WebView::reload(void)
251 #if defined(USE_EWEBKIT)
255 ewk_view_url_set(m_ewkView, ewk_view_url_get(m_ewkView));
258 ewk_view_reload(m_ewkView);
262 void WebView::back(void)
264 #if defined(USE_EWEBKIT)
266 ewk_view_back(m_ewkView);
270 void WebView::forward(void)
272 #if defined(USE_EWEBKIT)
274 ewk_view_forward(m_ewkView);
278 bool WebView::isBackEnabled(void)
280 #if defined(USE_EWEBKIT)
281 return ewk_view_back_possible(m_ewkView);
287 bool WebView::isForwardEnabled(void)
289 #if defined(USE_EWEBKIT)
290 return ewk_view_forward_possible(m_ewkView);
296 bool WebView::isLoading()
301 bool WebView::isLoadError() const
307 void WebView::setPrivateMode(bool state)
309 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
312 #if defined(USE_EWEBKIT)
314 Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
316 Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
318 ewk_settings_private_browsing_enabled_set(settings, state);
320 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(ewk_context_default_get()), EWK_COOKIE_ACCEPT_POLICY_NEVER);
323 ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(ewk_context_default_get()), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
328 void WebView::confirmationResult(WebConfirmationPtr confirmation)
330 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
332 #if defined(USE_EWEBKIT)
334 switch(confirmation->getConfirmationType()) {
335 case WebConfirmation::ConfirmationType::Geolocation: {
336 Ewk_Geolocation_Permission_Request *request = m_confirmationGeolocationMap[confirmation];
338 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
340 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
343 BROWSER_LOGE("Wrong ConfirmationResult");
346 // set geolocation permission
347 ewk_geolocation_permission_request_set(request, result );
350 m_confirmationGeolocationMap.erase(confirmation);
353 case WebConfirmation::ConfirmationType::UserMedia: {
354 Ewk_User_Media_Permission_Request *request = m_confirmationUserMediaMap[confirmation];
356 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
358 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
361 BROWSER_LOGE("Wrong ConfirmationResult");
365 // set usermedia permission
366 ewk_user_media_permission_request_set(request, result);
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_request_set(request, result);
388 m_confirmationNotificationMap.erase(confirmation);
391 case WebConfirmation::ConfirmationType::CertificateConfirmation: {
392 CertificateConfirmationPtr cert = std::dynamic_pointer_cast<CertificateConfirmation, WebConfirmation>(confirmation);
393 Ewk_Certificate_Policy_Decision *request = m_confirmationCertificatenMap[cert];
395 if (cert->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
397 else if (cert->getResult() == WebConfirmation::ConfirmationResult::Rejected)
400 BROWSER_LOGE("Wrong ConfirmationResult");
404 // set certificate confirmation
405 ewk_certificate_policy_decision_allowed_set(request, result);
408 m_confirmationCertificatenMap.erase(cert);
411 case WebConfirmation::ConfirmationType::Authentication: {
412 AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<AuthenticationConfirmation, WebConfirmation>(confirmation);
413 Ewk_Auth_Request *request = m_confirmationAuthenticationMap[auth];
414 if (auth->getResult() == WebConfirmation::ConfirmationResult::Confirmed) {
415 // set auth challange credential
416 ewk_auth_request_authenticate(request, const_cast<char*>(auth->getLogin().c_str()), const_cast<char*>(auth->getPassword().c_str()));
417 // ewk_object_unref(request);
418 } else if (auth->getResult() == WebConfirmation::ConfirmationResult::Rejected) {
419 ewk_auth_request_cancel(request);
420 // ewk_object_unref(request);
422 BROWSER_LOGE("Wrong ConfirmationResult");
427 m_confirmationAuthenticationMap.erase(auth);
430 case WebConfirmation::ConfirmationType::ScriptAlert:
432 ewk_view_javascript_alert_reply(m_ewkView);
434 case WebConfirmation::ConfirmationType::ScriptConfirmation: {
436 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
438 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
441 BROWSER_LOGE("Wrong ConfirmationResult");
446 ewk_view_javascript_confirm_reply(m_ewkView, result);
449 case WebConfirmation::ConfirmationType::ScriptPrompt: {
450 ScriptPromptPtr prompt = std::dynamic_pointer_cast<ScriptPrompt, WebConfirmation>(confirmation);
452 if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Confirmed)
454 else if (confirmation->getResult() == WebConfirmation::ConfirmationResult::Rejected)
457 BROWSER_LOGE("Wrong ConfirmationResult");
462 ewk_view_javascript_prompt_reply(m_ewkView, prompt->getUserData().c_str());
474 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::captureSnapshot(int targetWidth, int targetHeight)
476 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
478 M_ASSERT(targetWidth);
479 M_ASSERT(targetHeight);
481 std::shared_ptr<tizen_browser::tools::BrowserImage> noImage = std::make_shared<tizen_browser::tools::BrowserImage>();
482 evas_object_geometry_get(m_ewkView, NULL, NULL, &vw, &vh);
483 if (vw == 0 || vh == 0)
487 double snapshotProportions = (double)(targetWidth) /(double)(targetHeight);
488 double webkitProportions = (double)(vw) /(double)(vh);
489 if (webkitProportions >= snapshotProportions) {
490 // centring position of screenshot
491 area.x = (vw*getZoomFactor()/2) - (vh*getZoomFactor()*snapshotProportions/2);
493 area.w = vh*getZoomFactor()*snapshotProportions;
494 area.h = vh*getZoomFactor();
499 area.w = vw*getZoomFactor();
500 area.h = vw*getZoomFactor()/snapshotProportions;
502 if (area.w == 0 || area.h == 0)
505 double scaleW = (double)targetWidth / (double)(area.w);
506 double scaleH = (double)targetHeight / (double)(area.h);
508 BROWSER_LOGD("[%s:%d] Before snapshot (screenshot) - look at the time of taking snapshot below",__func__, __LINE__);
509 #if defined(USE_EWEBKIT)
511 Evas_Object *snapshot = ewk_view_screenshot_contents_get( m_ewkView, area, scaleW > scaleH ? scaleW : scaleH, evas_object_evas_get(m_ewkView));
512 BROWSER_LOGD("[%s:%d] Snapshot (screenshot) catched, evas pointer: %p",__func__, __LINE__, snapshot);
514 return tizen_browser::tools::EflTools::getBrowserImage(snapshot);
518 return std::shared_ptr<tizen_browser::tools::BrowserImage> ();
521 #if defined(USE_EWEBKIT)
522 void WebView::__setFocusToEwkView(void * data, Evas * /* e */, Evas_Object * /* obj */, void * /* event_info */)
524 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
526 WebView * self = reinterpret_cast<WebView *>(data);
528 if(!self->hasFocus())
529 self->ewkViewClicked();
532 Ewk_View_Smart_Class * WebView::smartClass()
534 static Ewk_View_Smart_Class clasz = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("BrowserView");
539 void WebView::onJavascriptAlert(Ewk_View_Smart_Data */*smartData*/, const char * /*message*/)
541 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
542 /*\todo FIX, because is not working propetly
543 WebView * self = reinterpret_cast<WebView *>(evas_object_data_get(smartData->self, "_container"));
544 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
545 std::string msg = tizen_browser::tools::fromChar(message);
547 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ScriptAlert, self->m_tabId, std::string(), msg);
548 self->cofirmationRequest(c);
552 Eina_Bool WebView::onJavascriptConfirm(Ewk_View_Smart_Data */*smartData*/, const char * /*message*/)
554 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
555 /*\todo FIX, because is not working propetly
556 WebView * self = reinterpret_cast<WebView *>(evas_object_data_get(smartData->self, "_container"));
557 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
558 std::string msg = tizen_browser::tools::fromChar(message);
560 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ScriptConfirmation, self->m_tabId, std::string(), msg);
561 self->cofirmationRequest(c);
566 const char * WebView::onJavascriptPrompt(Ewk_View_Smart_Data */*smartData*/, const char * /* message */, const char */*defaultValue*/)
568 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
569 /*/*\todo FIX, because is not working propetly
570 WebView * self = reinterpret_cast<WebView *>(evas_object_data_get(smartData->self, "_container"));
571 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
573 std::string msg = tizen_browser::tools::fromChar(message);
574 std::string userdata = tizen_browser::tools::fromChar(defaultValue);
575 ScriptPromptPtr c = std::make_shared<ScriptPrompt>(self->m_tabId, std::string(), msg);
576 c->setUserData(userdata);
578 self->cofirmationRequest(c);
583 Evas_Object * WebView::onWindowCreate(Ewk_View_Smart_Data *smartData, const Ewk_Window_Features *)
585 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
587 WebView * self = reinterpret_cast<WebView *>(evas_object_data_get(smartData->self, "_container"));
588 BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, self);
589 BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
590 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
591 m_webEngine = std::dynamic_pointer_cast
593 basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
595 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
596 M_ASSERT(m_webEngine);
598 /// \todo: Choose newly created tab.
599 TabId id = m_webEngine->addTab(std::string(), &self->getTabId());
600 BROWSER_LOGD("Created tab: %s", id.toString().c_str());
602 Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
606 void WebView::onWindowClose(Ewk_View_Smart_Data *smartData)
608 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
609 WebView * self = reinterpret_cast<WebView *>(evas_object_data_get(smartData->self, "_container"));
610 std::shared_ptr<AbstractWebEngine<Evas_Object>> m_webEngine =
611 std::dynamic_pointer_cast
612 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
613 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
614 m_webEngine->closeTab(self->getTabId());
617 void WebView::__loadStarted(void * data, Evas_Object * /* obj */, void * /* event_info */)
619 WebView * self = reinterpret_cast<WebView *>(data);
621 BROWSER_LOGD("%s:%d\n\t %s", __func__, __LINE__, ewk_view_url_get(self->m_ewkView));
623 self->m_isLoading = true;
625 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
626 cache->clearThumb(self->m_tabId);
629 void WebView::__loadStop(void * data, Evas_Object * /* obj */, void * /* event_info */)
631 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
633 WebView * self = reinterpret_cast<WebView *>(data);
634 self->m_isLoading = false;
639 void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* event_info */)
641 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
643 WebView * self = reinterpret_cast<WebView *>(data);
644 self->m_isLoading = false;
645 self->m_loadProgress = 1;
647 self->loadFinished();
648 self->loadProgress(self->m_loadProgress);
649 tizen_browser::services::TabThumbCache* cache = tizen_browser::services::TabThumbCache::getInstance();
650 cache->updateThumb(self->m_tabId);
653 void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_info)
655 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
657 WebView * self = reinterpret_cast<WebView *>(data);
658 self->m_loadProgress = *(double *)event_info;
660 self->loadProgress(self->m_loadProgress);
663 void WebView::__loadError(void* data, Evas_Object * obj, void* ewkError)
665 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
667 WebView *self = reinterpret_cast<WebView*>(data);
668 Ewk_Error *error = reinterpret_cast<Ewk_Error*>(ewkError);
669 Ewk_Error_Type errorType = ewk_error_type_get(error);
671 BROWSER_LOGD("[%s:%d] ewk_error_type: %d ",
672 __PRETTY_FUNCTION__, __LINE__, errorType);
674 BROWSER_LOGD("[%s:%d] emiting signal ", __PRETTY_FUNCTION__, __LINE__);
675 int errorCode = ewk_error_code_get(error);
676 if(errorCode == EWK_ERROR_NETWORK_STATUS_CANCELLED)
678 BROWSER_LOGD("Stop signal emitted");
679 BROWSER_LOGD("Error description: %s", ewk_error_description_get(error));
680 evas_object_smart_callback_call(obj, "load,stop", NULL);
685 self->m_loadError=true;
689 void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_info */)
691 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
693 WebView * self = reinterpret_cast<WebView *>(data);
694 self->m_title = tizen_browser::tools::fromChar(ewk_view_title_get(obj));
696 self->titleChanged(self->m_title);
699 void WebView::__urlChanged(void * data, Evas_Object * /* obj */, void * event_info)
701 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
703 WebView * self = reinterpret_cast<WebView *>(data);
704 BROWSER_LOGD("URL changed for tab: %s", self->getTabId().toString().c_str());
705 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
706 m_webEngine = std::dynamic_pointer_cast<basic_webengine::AbstractWebEngine<Evas_Object>, tizen_browser::core::AbstractService>(
707 tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
708 M_ASSERT(m_webEngine);
709 self->uriChanged(tizen_browser::tools::fromChar(reinterpret_cast<const char *>(event_info)));
710 self->tabIdChecker(self->m_tabId);
713 void WebView::__backForwardListChanged(void * data, Evas_Object * /* obj */, void * /* event_info */)
715 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
717 WebView * self = reinterpret_cast<WebView *>(data);
718 self->backwardEnableChanged(self->isBackEnabled());
719 self->forwardEnableChanged(self->isForwardEnabled());
722 void WebView::__OnNewWindowRequest(void *data, Evas_Object*, void* out)
724 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
726 WebView * self = reinterpret_cast<WebView *>(data);
727 BROWSER_LOGD("Window creating in tab: %s", self->getTabId().toString().c_str());
729 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
730 m_webEngine = std::dynamic_pointer_cast
732 basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService
734 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
735 M_ASSERT(m_webEngine);
737 /// \todo: Choose newly created tab.
738 TabId id = m_webEngine->addTab(std::string(), &self->getTabId());
739 BROWSER_LOGD("Created tab: %s", id.toString().c_str());
741 Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
742 *static_cast<Evas_Object**>(out) = tab_ewk_view;
745 void WebView::__faviconChanged(void* data, Evas_Object*, void*)
749 WebView * self = static_cast<WebView *>(data);
750 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));
752 BROWSER_LOGD("[%s:%d] Favicon received", __PRETTY_FUNCTION__, __LINE__);
753 self->faviconImage = tizen_browser::tools::EflTools::getBrowserImage(favicon);
754 evas_object_unref(favicon);
755 self->favIconChanged(self->faviconImage);
760 void WebView::__IMEClosed(void* data, Evas_Object*, void*)
762 BROWSER_LOGD("%s", __func__);
763 WebView * self = reinterpret_cast<WebView *>(data);
764 self->IMEStateChanged(false);
767 void WebView::__IMEOpened(void* data, Evas_Object*, void*)
769 BROWSER_LOGD("%s", __func__);
770 WebView * self = reinterpret_cast<WebView *>(data);
771 self->IMEStateChanged(true);
774 std::string WebView::securityOriginToUri(const Ewk_Security_Origin *origin)
776 std::string protocol = tizen_browser::tools::fromChar(ewk_security_origin_protocol_get(origin));
777 std::string uri = tizen_browser::tools::fromChar(ewk_security_origin_host_get(origin));
778 int port = ewk_security_origin_port_get(origin);
781 url = (boost::format("%1%:%2%//%3%") % protocol % port % uri).str();
783 url = (boost::format("%1%://%2%") % protocol % uri).str();
787 void WebView::__geolocationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
789 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
791 WebView * self = reinterpret_cast<WebView *>(data);
793 Ewk_Geolocation_Permission_Request *request = reinterpret_cast<Ewk_Geolocation_Permission_Request *>(event_info);
798 ewk_geolocation_permission_request_suspend(request);
800 std::string url = WebView::securityOriginToUri(ewk_geolocation_permission_request_origin_get(request));
802 ///\todo add translations
803 std::string message = (boost::format("%1% Requests your location") % url).str();
805 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Geolocation, self->m_tabId, url, message);
808 self->m_confirmationGeolocationMap[c] = request;
810 self->cofirmationRequest(c);
814 void WebView::__usermediaPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
816 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
818 WebView * self = reinterpret_cast<WebView *>(data);
820 Ewk_User_Media_Permission_Request *request = reinterpret_cast<Ewk_User_Media_Permission_Request *>(event_info);
825 ewk_user_media_permission_request_suspend(request);
827 ///\todo add translations
828 std::string message = "User media permission request";
830 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::UserMedia, self->m_tabId, std::string(), message);
833 self->m_confirmationUserMediaMap[c] = request;
835 self->cofirmationRequest(c);
839 void WebView::__notificationPermissionRequest(void * data, Evas_Object * /* obj */, void * event_info)
841 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
843 WebView * self = reinterpret_cast<WebView *>(data);
845 Ewk_Notification_Permission_Request *request = reinterpret_cast<Ewk_Notification_Permission_Request *>(event_info);
850 ewk_notification_permission_request_suspend(request);
852 std::string url = WebView::securityOriginToUri(ewk_notification_permission_request_origin_get(request));
854 ///\todo add translations
855 std::string message = (boost::format("%1% wants to display notifications") % url).str();
857 WebConfirmationPtr c = std::make_shared<WebConfirmation>(WebConfirmation::ConfirmationType::Notification, self->m_tabId, url, message);
860 self->m_confirmationNotificationMap[c] = request;
862 self->cofirmationRequest(c);
866 void WebView::__authenticationRequest(void * data, Evas_Object * /* obj */, void * event_info)
868 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
870 WebView * self = reinterpret_cast<WebView *>(data);
872 Ewk_Auth_Request *request = reinterpret_cast<Ewk_Auth_Request *>(event_info);
873 EINA_SAFETY_ON_NULL_RETURN(request);
875 std::string realm = tizen_browser::tools::fromChar(ewk_auth_request_realm_get(request));
876 // std::string url = tizen_browser::tools::fromChar(ewk_auth_request_host_get(request));
878 // ewk_object_ref(request);
880 ///\todo add translations
881 // std::string message = (boost::format("A username and password are being requested by %1%. The site says: \"%2%\"") % url % realm).str();
883 // AuthenticationConfirmationPtr c = std::make_shared<AuthenticationConfirmation>(self->m_tabId, url, message);
886 // self->m_confirmationAuthenticationMap[c] = request;
888 // self->cofirmationRequest(c);
892 void WebView::__requestCertificationConfirm(void * data , Evas_Object * /* obj */, void * event_info)
894 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
896 WebView * self = reinterpret_cast<WebView *>(data);
898 Ewk_Certificate_Policy_Decision *request = reinterpret_cast<Ewk_Certificate_Policy_Decision *>(event_info);
903 ewk_certificate_policy_decision_suspend(request);
905 std::string url = tizen_browser::tools::fromChar(ewk_certificate_policy_decision_url_get(request));
907 ///\todo add translations
908 std::string message = (boost::format("There are problems with the security certificate for this site.<br>%1%") % url).str();
910 CertificateConfirmationPtr c = std::make_shared<CertificateConfirmation>(self->m_tabId, url, message);
912 c->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
915 self->m_confirmationCertificatenMap[c] = request;
917 self->cofirmationRequest(c);
922 void WebView::setFocus()
924 elm_object_focus_set(m_ewkView, EINA_TRUE);
927 void WebView::clearFocus()
929 elm_object_focus_set(m_ewkView, EINA_FALSE);
932 bool WebView::hasFocus() const
934 return elm_object_focus_get(m_ewkView) == EINA_TRUE ? true : false;
937 double WebView::getZoomFactor() const
939 if(EINA_UNLIKELY(m_ewkView == NULL)){
943 #if defined(USE_EWEBKIT)
944 return ewk_view_text_zoom_get(m_ewkView);
950 void WebView::setZoomFactor(double zoomFactor)
952 #if defined(USE_EWEBKIT)
954 //using zoomFactor = 0 sets zoom "fit to screen"
956 ewk_view_text_zoom_set(m_ewkView, zoomFactor);
962 const TabId& WebView::getTabId(){
967 std::shared_ptr<tizen_browser::tools::BrowserImage> WebView::getFavicon() {
968 BROWSER_LOGD("%s:%d, TabId: %s", __PRETTY_FUNCTION__, __LINE__, m_tabId.toString().c_str());
971 #if defined(USE_EWEBKIT)
972 if (faviconImage.get() == NULL) {
975 // Evas_Object * favicon = ewk_view_favicon_get(m_ewkView);
976 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));
978 Ewk_Favicon_Database * database = ewk_context_favicon_database_get(ewk_view_context_get(m_ewkView));
979 Evas_Object * favicon = ewk_favicon_database_icon_get(database, ewk_view_url_get(m_ewkView), evas_object_evas_get(m_ewkView));
984 evas_object_image_size_get(favicon, &w, &h);
985 BROWSER_LOGD("[%s]: Info about favicon: w:%d h:%d, type: %s", __func__, w, h, evas_object_type_get(favicon));
988 std::shared_ptr<tizen_browser::tools::BrowserImage>
989 image = tizen_browser::tools::EflTools::getBrowserImage(favicon);
991 evas_object_unref(favicon);
1000 BROWSER_LOGE("[%s:%d]: Returned favicon is empty!", __PRETTY_FUNCTION__, __LINE__);
1001 return std::make_shared<tizen_browser::tools::BrowserImage>();
1004 void WebView::clearPrivateData()
1006 BROWSER_LOGD("Clearing private data");
1007 #if defined(USE_EWEBKIT)
1008 Ewk_Context * context = ewk_context_default_get();
1009 ewk_context_web_storage_delete_all(context);
1010 ewk_cookie_manager_cookies_clear(ewk_context_cookie_manager_get(context));
1014 void WebView::searchOnWebsite(const std::string & searchString, int flags)
1016 ///\todo: it should be "0" instead of "1024" for unlimited match count but it doesn't work properly in WebKit
1017 Eina_Bool result = ewk_view_text_find(m_ewkView, searchString.c_str(), static_cast<Ewk_Find_Options>(flags), 1024);
1018 BROWSER_LOGD("Ewk search; word: %s, result: %d", searchString.c_str(), result);
1021 } /* namespace webkitengine_service */
1022 } /* end of basic_webengine */
1023 } /* end of tizen_browser */