2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 #include "runtime/browser/web_view_impl.h"
20 #include <ewk_chromium.h>
24 #include "common/file_utils.h"
25 #include "common/logger.h"
26 #include "common/profiler.h"
27 #include "runtime/browser/native_window.h"
33 const char* kKeyNameBack = "back";
34 const char* kKeyNameMenu = "menu";
35 const char* kDefaultEncoding = "UTF-8";
36 const char* kSmartClassUserDataKey = "__SC_USERDATA__";
38 static int ToWebRotation(int r) {
48 static NativeWindow::ScreenOrientation ToNativeRotation(int r) {
50 (EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY
51 | EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY
52 | EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY
53 | EWK_SCREEN_ORIENTATION_LANDSCAPE_SECONDARY)) {
54 return NativeWindow::ScreenOrientation::ANY;
56 (EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY
57 | EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY)) {
58 return NativeWindow::ScreenOrientation::NATURAL;
59 } else if (r & EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY) {
60 return NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY;
61 } else if (r & EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY) {
62 return NativeWindow::ScreenOrientation::PORTRAIT_SECONDARY;
63 } else if (r & EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY) {
64 return NativeWindow::ScreenOrientation::LANDSCAPE_PRIMARY;
66 return NativeWindow::ScreenOrientation::LANDSCAPE_SECONDARY;
72 WebViewImpl::WebViewImpl(WebView* view,
79 rotation_handler_id_(0),
82 evas_smart_class_(NULL),
83 internal_popup_opened_(false),
89 WebViewImpl::~WebViewImpl() {
90 if (internal_popup_opened_) {
91 ewk_view_javascript_alert_reply(ewk_view_);
94 evas_object_del(ewk_view_);
95 if (evas_smart_class_ != NULL)
96 evas_smart_free(evas_smart_class_);
99 void WebViewImpl::LoadUrl(const std::string& url, const std::string& mime) {
102 mime_set_cb_ = [url, mime]
103 (const char* request_url, const char* request_mime,
104 char** new_mime, void* data) {
105 WebViewImpl* view = static_cast<WebViewImpl*>(data);
106 if (view != nullptr &&
107 common::utils::BaseName(url) ==
108 common::utils::BaseName(request_url)) {
109 *new_mime = strdup(mime.c_str());
110 LOGGER(DEBUG) << "ewk's new_mime: " << *new_mime;
115 auto mime_override_cb = [](const char* url, const char* mime,
116 char** new_mime, void* data) -> Eina_Bool {
117 WebViewImpl* view = static_cast<WebViewImpl*>(data);
118 return view->mime_set_cb_(url, mime, new_mime, data);
120 ewk_context_mime_override_callback_set(context_, mime_override_cb, this);
122 ewk_view_url_set(ewk_view_, url.c_str());
125 void WebViewImpl::Suspend() {
127 ewk_view_suspend(ewk_view_);
130 void WebViewImpl::Resume() {
132 ewk_view_resume(ewk_view_);
135 void WebViewImpl::Reload() {
136 ewk_view_reload(ewk_view_);
139 bool WebViewImpl::Backward() {
140 if (ewk_view_back_possible(ewk_view_)) {
141 ewk_view_back(ewk_view_);
147 void WebViewImpl::SetVisibility(bool show) {
148 ewk_view_page_visibility_state_set(ewk_view_,
149 show ? EWK_PAGE_VISIBILITY_STATE_VISIBLE :
150 EWK_PAGE_VISIBILITY_STATE_HIDDEN,
155 bool WebViewImpl::EvalJavascript(const std::string& script) {
156 return ewk_view_script_execute(ewk_view_, script.c_str(), NULL, NULL);
159 void WebViewImpl::Initialize() {
160 ewk_smart_class_ = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("WebView");
161 ewk_view_smart_class_set(&ewk_smart_class_);
162 ewk_smart_class_.orientation_lock = [](Ewk_View_Smart_Data *sd,
164 WebViewImpl* self = static_cast<WebViewImpl*>(
165 evas_object_data_get(sd->self, kSmartClassUserDataKey));
166 if (self == NULL || self->listener_ == NULL)
168 self->listener_->OnOrientationLock(self->view_,
170 ToNativeRotation(orientation));
174 ewk_smart_class_.orientation_unlock = [](Ewk_View_Smart_Data *sd) {
175 WebViewImpl* self = static_cast<WebViewImpl*>(
176 evas_object_data_get(sd->self, kSmartClassUserDataKey));
177 if (self == NULL || self->listener_ == NULL)
179 self->listener_->OnOrientationLock(
182 NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY);
185 if (evas_smart_class_ != NULL)
186 evas_smart_free(evas_smart_class_);
187 evas_smart_class_ = evas_smart_class_new(&ewk_smart_class_.sc);
188 if (evas_smart_class_ == NULL) {
189 LOGGER(ERROR) << "Can't create evas smart class";
193 Ewk_Page_Group* page_group = ewk_page_group_create("");
194 ewk_view_ = ewk_view_smart_add(evas_object_evas_get(window_->evas_object()),
198 evas_object_data_set(ewk_view_, kSmartClassUserDataKey, this);
201 InitLoaderCallback();
202 InitPolicyDecideCallback();
203 InitQuotaExceededCallback();
204 InitIPCMessageCallback();
205 InitConsoleMessageCallback();
206 InitCustomContextMenuCallback();
207 InitRotationCallback();
208 InitWindowCreateCallback();
209 InitFullscreenCallback();
210 InitNotificationPermissionCallback();
211 InitGeolocationPermissionCallback();
212 InitAuthenticationCallback();
213 InitCertificateAllowCallback();
214 InitPopupWaitCallback();
215 InitUsermediaCallback();
216 InitEditorClientImeCallback();
217 #ifdef ROTARY_EVENT_FEATURE_SUPPORT
218 InitRotaryEventCallback();
219 #endif // ROTARY_EVENT_FEATURE_SUPPORT
221 Ewk_Settings* settings = ewk_view_settings_get(ewk_view_);
222 ewk_settings_scripts_can_open_windows_set(settings, EINA_TRUE);
223 ewk_settings_default_text_encoding_name_set(settings, kDefaultEncoding);
225 // TODO(sngn.lee): "protocolhandler,registration,requested"
226 // custom protocol handler
229 evas_object_show(ewk_view_);
232 void WebViewImpl::Deinitialize() {
233 auto it = smart_callbacks_.begin();
234 for ( ; it != smart_callbacks_.end(); ++it) {
235 evas_object_smart_callback_del(
240 eext_object_event_callback_del(ewk_view_,
242 smart_callbacks_["key_callback"]);
243 ewk_view_exceeded_database_quota_callback_set(
247 ewk_view_exceeded_indexed_database_quota_callback_set(
251 ewk_view_exceeded_local_file_system_quota_callback_set(
255 ewk_view_notification_permission_callback_set(
259 ewk_view_geolocation_permission_callback_set(
263 ewk_view_user_media_permission_callback_set(
267 window_->RemoveRotationHandler(rotation_handler_id_);
270 void WebViewImpl::InitKeyCallback() {
271 auto key_callback = [](void* user_data,
272 Evas_Object* /*obj*/,
273 void* event_info) -> void {
274 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
275 Eext_Callback_Type key = static_cast<Eext_Callback_Type>(
276 reinterpret_cast<long long>(event_info)); // NOLINT
277 self->OnKeyEvent(key);
279 eext_object_event_callback_add(ewk_view_,
283 eext_object_event_callback_add(ewk_view_,
287 smart_callbacks_["key_callback"] = key_callback;
290 void WebViewImpl::InitLoaderCallback() {
291 // load statred callback
292 auto loadstart_callback = [](void* user_data,
293 Evas_Object* /*obj*/,
295 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
297 self->listener_->OnLoadStart(self->view_);
299 evas_object_smart_callback_add(ewk_view_,
303 // load finished callback
304 auto loadfinished_callback = [](void* user_data,
307 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
309 self->listener_->OnLoadFinished(self->view_);
311 evas_object_smart_callback_add(ewk_view_,
313 loadfinished_callback,
316 // load progress callback
317 auto loadprogress_callback = [](void* user_data,
320 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
321 double* progress = static_cast<double*>(event_info);
323 self->listener_->OnLoadProgress(self->view_, *progress);
325 evas_object_smart_callback_add(ewk_view_,
327 loadprogress_callback,
330 auto rendered_callback = [](void* user_data,
333 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
335 self->listener_->OnRendered(self->view_);
337 evas_object_smart_callback_add(ewk_view_,
341 smart_callbacks_["load,started"] = loadstart_callback;
342 smart_callbacks_["load,finished"] = loadfinished_callback;
343 smart_callbacks_["load,progress"] = loadprogress_callback;
344 smart_callbacks_["frame,rendered"] = rendered_callback;
347 void WebViewImpl::InitPolicyDecideCallback() {
348 // "policy,navigation,decide"
349 auto navigation_decide_callback = [](void* user_data,
352 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
353 Ewk_Policy_Decision* policy =
354 static_cast<Ewk_Policy_Decision*>(event_info);
355 const char* url = ewk_policy_decision_url_get(policy);
357 if (self->listener_) {
358 if (self->listener_->OnDidNavigation(self->view_, url))
359 ewk_policy_decision_use(policy);
361 ewk_policy_decision_ignore(policy);
363 ewk_policy_decision_use(policy);
366 evas_object_smart_callback_add(ewk_view_,
367 "policy,navigation,decide",
368 navigation_decide_callback,
371 // policy,newwindow,decide
372 auto newwindow_decide_callback = [](void* user_data,
375 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
376 Ewk_Policy_Decision* policy =
377 static_cast<Ewk_Policy_Decision*>(event_info);
379 const char* url = ewk_policy_decision_url_get(policy);
381 if (self->listener_) {
382 if (self->listener_->OnDidNavigation(self->view_, url) &&
383 self->listener_->OnDidOpenWindow(self->view_, url)) {
384 ewk_policy_decision_use(policy);
386 ewk_policy_decision_ignore(policy);
389 ewk_policy_decision_use(policy);
392 evas_object_smart_callback_add(ewk_view_,
393 "policy,newwindow,decide",
394 newwindow_decide_callback,
396 smart_callbacks_["policy,navigation,decide"] = navigation_decide_callback;
397 smart_callbacks_["policy,newwindow,decide"] = newwindow_decide_callback;
400 void WebViewImpl::InitQuotaExceededCallback() {
401 // TODO(sngn.lee): Need callback interface - OnQutaExceed
402 // check http://tizen.org/privilege/unlimitedstorage
404 // callback for database quota exceeded
405 auto database_exceeded_callback = [](Evas_Object* view,
406 Ewk_Security_Origin* origin,
408 unsigned long long, // NOLINT
409 void* user_data) -> Eina_Bool {
410 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
411 if (self == NULL || self->listener_ == NULL)
414 auto result_handler = [view](bool result) {
415 LOGGER(DEBUG) << "database quota Permission Result : " << result;
416 ewk_view_exceeded_database_quota_reply(view, result);
418 std::stringstream url;
419 url << ewk_security_origin_protocol_get(origin)
421 << ewk_security_origin_host_get(origin)
423 << ewk_security_origin_port_get(origin);
424 self->listener_->OnQuotaExceed(
430 ewk_view_exceeded_database_quota_callback_set(
432 database_exceeded_callback,
435 // callback for indexed database quota exceeded
436 auto indexed_db_exceeded_callback = [](Evas_Object* view,
437 Ewk_Security_Origin* origin,
439 void* user_data) -> Eina_Bool {
440 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
441 if (self == NULL || self->listener_ == NULL)
444 auto result_handler = [view](bool result) {
445 LOGGER(DEBUG) << "indexed db quota Permission Result : " << result;
446 ewk_view_exceeded_indexed_database_quota_reply(view, result);
448 std::stringstream url;
449 url << ewk_security_origin_protocol_get(origin)
451 << ewk_security_origin_host_get(origin)
453 << ewk_security_origin_port_get(origin);
454 self->listener_->OnQuotaExceed(
460 ewk_view_exceeded_indexed_database_quota_callback_set(
462 indexed_db_exceeded_callback,
465 // callback for localfile quota exceeded
466 auto localfile_exceeded_callback = [](Evas_Object* view,
467 Ewk_Security_Origin* origin,
469 void* user_data) -> Eina_Bool {
470 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
471 if (self == NULL || self->listener_ == NULL)
474 auto result_handler = [view](bool result) {
475 LOGGER(DEBUG) << "local file quota Permission Result : " << result;
476 ewk_view_exceeded_local_file_system_quota_reply(view, result);
478 std::stringstream url;
479 url << ewk_security_origin_protocol_get(origin)
481 << ewk_security_origin_host_get(origin)
483 << ewk_security_origin_port_get(origin);
484 self->listener_->OnQuotaExceed(
490 ewk_view_exceeded_local_file_system_quota_callback_set(
492 localfile_exceeded_callback,
496 void WebViewImpl::InitIPCMessageCallback() {
498 auto wrt_message_callback = [](void* user_data,
501 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
502 Ewk_IPC_Wrt_Message_Data* msg =
503 static_cast<Ewk_IPC_Wrt_Message_Data*>(event_info);
505 self->listener_->OnReceivedWrtMessage(self->view_, msg);
507 evas_object_smart_callback_add(ewk_view_,
509 wrt_message_callback,
511 smart_callbacks_["wrt,message"] = wrt_message_callback;
514 void WebViewImpl::InitConsoleMessageCallback() {
516 auto console_message_callback = [](void* user_data,
519 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
520 if (!self->listener_) {
523 Ewk_Console_Message* msg = static_cast<Ewk_Console_Message*>(event_info);
524 unsigned int line_number = ewk_console_message_line_get(msg);
526 std::stringstream buf;
528 buf << common::utils::BaseName(ewk_console_message_source_get(msg))
529 << ":" << line_number << ": ";
531 buf << ewk_console_message_text_get(msg);
532 int level = ewk_console_message_level_get(msg);
533 self->listener_->OnConsoleMessage(buf.str(), level);
535 evas_object_smart_callback_add(ewk_view_,
537 console_message_callback,
539 smart_callbacks_["console,message"] = console_message_callback;
542 void WebViewImpl::InitCustomContextMenuCallback() {
543 auto custom_context_menu_callback = [](void* user_data,
546 Ewk_Context_Menu* contextmenu = static_cast<Ewk_Context_Menu*>(event_info);
547 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
548 bool disabled = false;
549 if (self->listener_ &&
550 self->listener_->OnContextMenuDisabled(self->view_)) {
553 int cnt = ewk_context_menu_item_count(contextmenu);
554 for (int idx = cnt-1; idx >= 0; --idx) {
555 auto* item = ewk_context_menu_nth_item_get(contextmenu, idx);
556 Ewk_Context_Menu_Item_Tag tag = ewk_context_menu_item_tag_get(item);
558 case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW:
559 case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW:
560 case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_FRAME_IN_NEW_WINDOW:
561 case EWK_CONTEXT_MENU_ITEM_TAG_SEARCH_WEB:
562 case EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK:
563 ewk_context_menu_item_remove(contextmenu, item);
567 ewk_context_menu_item_remove(contextmenu, item);
571 evas_object_smart_callback_add(ewk_view_,
572 "contextmenu,customize",
573 custom_context_menu_callback,
575 smart_callbacks_["contextmenu,customize"] = custom_context_menu_callback;
578 void WebViewImpl::InitRotationCallback() {
580 ewk_view_orientation_send(ewk_view_, ToWebRotation(window_->rotation()));
581 rotation_handler_id_ = window_->AddRotationHandler(
582 std::bind(&WebViewImpl::OnRotation,
584 std::placeholders::_1));
587 void WebViewImpl::InitWindowCreateCallback() {
588 auto create_callback = [](void* user_data,
591 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
592 if (!self->listener_) {
595 WebView* new_view = new WebView(self->window_, self->context_);
596 self->listener_->OnCreatedNewWebView(self->view_, new_view);
597 *(static_cast<Evas_Object **>(event_info)) = new_view->evas_object();
600 auto close_callback = [](void* user_data,
603 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
604 if (!self->listener_) {
607 self->listener_->OnClosedWebView(self->view_);
609 evas_object_smart_callback_add(ewk_view_,
613 evas_object_smart_callback_add(ewk_view_,
618 smart_callbacks_["create,window"] = create_callback;
619 smart_callbacks_["close,window"] = close_callback;
622 void WebViewImpl::InitFullscreenCallback() {
623 auto enter_callback = [](void* user_data,
625 void* /*event_info*/) {
626 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
627 self->fullscreen_ = true;
628 self->window_->FullScreen(true);
630 auto exit_callback = [](void* user_data,
632 void* /*event_info*/) {
633 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
634 self->fullscreen_ = false;
635 self->window_->FullScreen(false);
637 evas_object_smart_callback_add(ewk_view_,
638 "fullscreen,enterfullscreen",
641 evas_object_smart_callback_add(ewk_view_,
642 "fullscreen,exitfullscreen",
645 smart_callbacks_["fullscreen,enterfullscreen"] = enter_callback;
646 smart_callbacks_["fullscreen,exitfullscreen"] = exit_callback;
649 void WebViewImpl::InitNotificationPermissionCallback() {
650 auto request_callback = [](Evas_Object*,
651 Ewk_Notification_Permission_Request* request,
653 LOGGER(DEBUG) << "Notification Permission Request";
654 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
655 if (!self->listener_) {
656 ewk_notification_permission_reply(request, EINA_FALSE);
660 ewk_notification_permission_request_suspend(request);
661 auto result_handler = [request](bool result) {
662 LOGGER(DEBUG) << "Notification Permission Result : %d" << result;
663 ewk_notification_permission_reply(request, result);
665 const Ewk_Security_Origin* ewk_origin =
666 ewk_notification_permission_request_origin_get(request);
668 std::stringstream url;
669 url << ewk_security_origin_protocol_get(ewk_origin)
671 << ewk_security_origin_host_get(ewk_origin)
673 << ewk_security_origin_port_get(ewk_origin);
674 self->listener_->OnNotificationPermissionRequest(
680 ewk_view_notification_permission_callback_set(ewk_view_,
685 void WebViewImpl::InitGeolocationPermissionCallback() {
686 auto permission_callback = [](
688 Ewk_Geolocation_Permission_Request* request,
690 LOGGER(DEBUG) << "Geolocation Permission Request";
691 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
692 if (self == NULL || self->listener_ == NULL) {
693 ewk_geolocation_permission_reply(request, EINA_FALSE);
696 ewk_geolocation_permission_request_suspend(request);
698 const Ewk_Security_Origin* ewk_origin =
699 ewk_geolocation_permission_request_origin_get(request);
700 auto result_handler = [request](bool result) {
701 LOGGER(DEBUG) << "Geolocation Permission Result : " << result;
702 ewk_geolocation_permission_reply(request, result);
705 std::stringstream url;
706 url << ewk_security_origin_protocol_get(ewk_origin)
708 << ewk_security_origin_host_get(ewk_origin)
710 << ewk_security_origin_port_get(ewk_origin);
712 self->listener_->OnGeolocationPermissionRequest(
718 ewk_view_geolocation_permission_callback_set(ewk_view_,
723 void WebViewImpl::InitAuthenticationCallback() {
724 auto auth_callback = [](void* user_data,
727 LOGGER(DEBUG) << "Authentication Request";
728 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
729 Ewk_Auth_Challenge* auth_challenge =
730 static_cast<Ewk_Auth_Challenge*>(event_info);
732 if (self == NULL || self->listener_ == NULL) {
733 ewk_auth_challenge_credential_cancel(auth_challenge);
736 auto result_handler = [auth_challenge](bool submit,
737 const std::string& id,
738 const std::string& password) {
739 LOGGER(DEBUG) << "Authentication Result : submit = " << submit;
741 ewk_auth_challenge_credential_cancel(auth_challenge);
744 ewk_auth_challenge_credential_use(auth_challenge,
748 ewk_auth_challenge_suspend(auth_challenge);
749 const char* message =
750 ewk_auth_challenge_realm_get(auth_challenge);
751 std::string url = self->GetUrl();
752 self->listener_->OnAuthenticationRequest(self->view_,
757 // "authentication,challenge"
758 evas_object_smart_callback_add(ewk_view_,
759 "authentication,challenge",
762 smart_callbacks_["authentication,challenge"] = auth_callback;
765 void WebViewImpl::InitCertificateAllowCallback() {
766 auto certi_callback = [](void* user_data,
769 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
770 Ewk_Certificate_Policy_Decision* policy =
771 static_cast<Ewk_Certificate_Policy_Decision*>(event_info);
773 if (self == NULL || self->listener_ == NULL) {
774 ewk_certificate_policy_decision_allowed_set(policy, EINA_FALSE);
778 ewk_certificate_policy_decision_suspend(policy);
779 auto result_handler = [policy](bool allow) {
780 ewk_certificate_policy_decision_allowed_set(policy, allow);
783 auto ptr = ewk_certificate_policy_decision_url_get(policy);
784 std::string url(ptr ? ptr : "");
785 ptr = ewk_certificate_policy_decision_certificate_pem_get(policy);
786 std::string pem(ptr ? ptr : "");
787 self->listener_->OnCertificateAllowRequest(self->view_,
792 evas_object_smart_callback_add(ewk_view_,
793 "request,certificate,confirm",
796 smart_callbacks_["request,certificate,confirm"] = certi_callback;
799 void WebViewImpl::InitPopupWaitCallback() {
800 evas_object_smart_callback_add(ewk_view_,
801 "popup,reply,wait,start",
802 [](void* user_data, Evas_Object* /*obj*/, void*) {
803 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
804 self->internal_popup_opened_ = true;
806 evas_object_smart_callback_add(ewk_view_,
807 "popup,reply,wait,finish",
808 [](void* user_data, Evas_Object* /*obj*/, void*) {
809 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
810 self->internal_popup_opened_ = false;
814 void WebViewImpl::InitUsermediaCallback() {
815 auto callback = [](Evas_Object*,
816 Ewk_User_Media_Permission_Request* request,
818 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
819 if (self == NULL || self->listener_ == NULL) {
820 ewk_user_media_permission_reply(request, EINA_FALSE);
824 ewk_user_media_permission_request_suspend(request);
825 const Ewk_Security_Origin* origin =
826 ewk_user_media_permission_request_origin_get(request);
827 std::stringstream url;
828 url << ewk_security_origin_protocol_get(origin)
830 << ewk_security_origin_host_get(origin)
832 << ewk_security_origin_port_get(origin);
834 auto result_handler = [request](bool result) {
835 LOGGER(DEBUG) << "Getusermedia Permission Result : " << result;
836 ewk_user_media_permission_reply(request, result);
838 self->listener_->OnUsermediaPermissionRequest(self->view_,
843 ewk_view_user_media_permission_callback_set(ewk_view_, callback, this);
846 void WebViewImpl::InitEditorClientImeCallback() {
847 auto ime_changed_callback = [](void* user_data,
850 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
852 Eina_Rectangle *rect = static_cast<Eina_Rectangle *>(event_info);
853 self->ime_width_ = rect->w;
854 self->ime_height_ = rect->h;
857 auto ime_opened_callback = [](void* user_data,
860 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
862 SoftKeyboardChangeEventValue softkeyboard_value;
863 softkeyboard_value.state = "on";
864 softkeyboard_value.width = self->ime_width_;
865 softkeyboard_value.height = self->ime_height_;
867 self->listener_->OnSoftKeyboardChangeEvent(self->view_, softkeyboard_value);
870 auto ime_closed_callback = [](void* user_data,
873 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
875 SoftKeyboardChangeEventValue softkeyboard_value;
876 softkeyboard_value.state = "off";
878 self->listener_->OnSoftKeyboardChangeEvent(self->view_, softkeyboard_value);
880 evas_object_smart_callback_add(ewk_view_,
881 "inputmethod,changed",
882 ime_changed_callback,
884 evas_object_smart_callback_add(ewk_view_,
885 "editorclient,ime,opened",
888 evas_object_smart_callback_add(ewk_view_,
889 "editorclient,ime,closed",
892 smart_callbacks_["inputmethod,changed"] = ime_changed_callback;
893 smart_callbacks_["editorclient,ime,opened"] = ime_opened_callback;
894 smart_callbacks_["editorclient,ime,closed"] = ime_closed_callback;
897 #ifdef ROTARY_EVENT_FEATURE_SUPPORT
898 void WebViewImpl::InitRotaryEventCallback() {
899 auto rotary_callback = [](void* user_data,
901 Eext_Rotary_Event_Info* event_info) -> Eina_Bool {
902 WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
903 Eext_Rotary_Event_Info* rotary = event_info;
905 RotaryEventType type;
906 if (rotary->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE)
907 type = RotaryEventType::CLOCKWISE;
909 type = RotaryEventType::COUNTER_CLOCKWISE;
911 self->listener_->OnRotaryEvent(self->view_, type);
915 // add callback to handle rotary event
916 eext_rotary_object_event_callback_add(ewk_view_, rotary_callback, this);
917 eext_rotary_object_event_activated_set(ewk_view_, EINA_TRUE);
919 #endif // ROTARY_EVENT_FEATURE_SUPPORT
921 std::string WebViewImpl::GetUrl() {
922 return std::string(ewk_view_url_get(ewk_view_));
925 Evas_Object* WebViewImpl::evas_object() const {
929 void WebViewImpl::OnRotation(int degree) {
930 ewk_view_orientation_send(ewk_view_, ToWebRotation(degree));
933 void WebViewImpl::OnKeyEvent(Eext_Callback_Type key_type) {
935 if (key_type == EEXT_CALLBACK_BACK) {
937 ewk_view_fullscreen_exit(ewk_view_);
940 if (EINA_TRUE == ewk_view_text_selection_clear(ewk_view_)) {
943 keyname = kKeyNameBack;
944 } else if (key_type == EEXT_CALLBACK_MORE) {
945 keyname = kKeyNameMenu;
951 listener_->OnHardwareKey(view_, keyname);
955 void WebViewImpl::SetEventListener(WebView::EventListener* listener) {
956 listener_ = listener;
959 void WebViewImpl::SetAppInfo(const std::string& app_name,
960 const std::string& version) {
961 std::string ua = app_name + "/" + version;
962 ewk_view_application_name_for_user_agent_set(ewk_view_, ua.c_str());
964 bool WebViewImpl::SetUserAgent(const std::string& user_agent) {
965 return ewk_view_user_agent_set(ewk_view_, user_agent.c_str());
968 void WebViewImpl::SetCSPRule(const std::string& rule, bool report_only) {
969 ewk_view_content_security_policy_set(
972 report_only ? EWK_REPORT_ONLY : EWK_ENFORCE_POLICY);
975 void WebViewImpl::SetDefaultEncoding(const std::string& encoding) {
976 if (ewk_settings_is_encoding_valid(encoding.c_str())) {
977 Ewk_Settings* settings = ewk_view_settings_get(ewk_view_);
978 ewk_settings_default_text_encoding_name_set(settings, encoding.c_str());
982 } // namespace runtime