From: Seungkeun Lee Date: Mon, 7 Sep 2015 02:10:39 +0000 (+0900) Subject: Implement GetUsermedia Popup X-Git-Tag: accepted/tizen/mobile/20151006.042140~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edbf412bca7eea2af30b0470904bb80570d6cda0;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Implement GetUsermedia Popup Change-Id: I57bd1a45a70b2173cb75308c830293a2edb92504 --- diff --git a/runtime/browser/web_application.cc b/runtime/browser/web_application.cc index 3733a91..03aa954 100755 --- a/runtime/browser/web_application.cc +++ b/runtime/browser/web_application.cc @@ -96,6 +96,8 @@ const char* kLocationPrivilege = "http://tizen.org/privilege/location"; const char* kStoragePrivilege = "http://tizen.org/privilege/unlimitedstorage"; +const char* kUsermediaPrivilege = + "http://tizen.org/privilege/mediacapture"; const char* kNotiIconFile = "noti_icon.png"; const char* kVisibilitySuspendFeature = "visibility,suspend"; @@ -111,6 +113,7 @@ const char* kGeolocationPermissionPrefix = "__WRT_GEOPERM_"; const char* kNotificationPermissionPrefix = "__WRT_NOTIPERM_"; const char* kQuotaPermissionPrefix = "__WRT_QUOTAPERM_"; const char* kCertificateAllowPrefix = "__WRT_CERTIPERM_"; +const char* kUsermediaPermissionPrefix = "__WRT_USERMEDIAPERM_"; const char* kDBPrivateSection = "private"; const char* kDefaultCSPRule = @@ -860,4 +863,49 @@ void WebApplication::OnCertificateAllowRequest( popup->Show(); } +void WebApplication::OnUsermediaPermissionRequest( + WebView*, + const std::string& url, + std::function result_handler) { + auto db = common::AppDB::GetInstance(); + std::string reminder = db->Get(kDBPrivateSection, + kUsermediaPermissionPrefix + url); + if (reminder == "allowed") { + result_handler(true); + return; + } else if (reminder == "denied") { + result_handler(false); + return; + } + + // Local Domain: Grant permission if defined, otherwise block execution. + // Remote Domain: Popup user prompt if defined, otherwise block execution. + if (!FindPrivilege(app_data_.get(), kUsermediaPrivilege)) { + result_handler(false); + return; + } + + if (common::utils::StartsWith(url, "file://")) { + result_handler(true); + return; + } + + Popup* popup = Popup::CreatePopup(window_); + popup->SetButtonType(Popup::ButtonType::AllowDenyButton); + popup->SetTitle(popup_string::kPopupTitleUserMedia); + popup->SetBody(popup_string::kPopupBodyUserMedia); + popup->SetCheckBox(popup_string::kPopupCheckRememberPreference); + popup->SetResultHandler( + [db, result_handler, url](Popup* popup, void* /*user_data*/) { + bool result = popup->GetButtonResult(); + bool remember = popup->GetCheckBoxResult(); + if (remember) { + db->Set(kDBPrivateSection, kUsermediaPermissionPrefix + url, + result ? "allowed" : "denied"); + } + result_handler(result); + }, this); + popup->Show(); +} + } // namespace runtime diff --git a/runtime/browser/web_application.h b/runtime/browser/web_application.h index 88ac4d1..a5404d5 100755 --- a/runtime/browser/web_application.h +++ b/runtime/browser/web_application.h @@ -95,6 +95,10 @@ class WebApplication : public WebView::EventListener { const std::string& url, const std::string& pem, std::function result_handler); + virtual void OnUsermediaPermissionRequest( + WebView* view, + const std::string& url, + std::function result_handler); private: bool Initialize(); diff --git a/runtime/browser/web_view.h b/runtime/browser/web_view.h index 2ed9e62..718b899 100755 --- a/runtime/browser/web_view.h +++ b/runtime/browser/web_view.h @@ -83,6 +83,10 @@ class WebView { std::function result_handler) { result_handler(false); } + virtual void OnUsermediaPermissionRequest( + WebView* /*view*/, + const std::string& /*url*/, + std::function /*result_handler*/) {} }; WebView(NativeWindow* window, Ewk_Context* context); diff --git a/runtime/browser/web_view_impl.cc b/runtime/browser/web_view_impl.cc index 5a73aa9..063eac9 100755 --- a/runtime/browser/web_view_impl.cc +++ b/runtime/browser/web_view_impl.cc @@ -193,6 +193,7 @@ void WebViewImpl::Initialize() { InitAuthenticationCallback(); InitCertificateAllowCallback(); InitPopupWaitCallback(); + InitUsermediaCallback(); Ewk_Settings* settings = ewk_view_settings_get(ewk_view_); ewk_settings_scripts_can_open_windows_set(settings, EINA_TRUE); @@ -200,7 +201,6 @@ void WebViewImpl::Initialize() { // TODO(sngn.lee): "protocolhandler,registration,requested" // custom protocol handler - // TODO(sngn.lee): ewk_view_user_media_permission_callback_set // Show webview evas_object_show(ewk_view_); @@ -237,6 +237,10 @@ void WebViewImpl::Deinitialize() { ewk_view_, NULL, NULL); + ewk_view_user_media_permission_callback_set( + ewk_view_, + NULL, + NULL); window_->RemoveRotationHandler(rotation_handler_id_); } @@ -784,6 +788,39 @@ void WebViewImpl::InitPopupWaitCallback() { }, this); } +void WebViewImpl::InitUsermediaCallback() { + auto callback = [](Evas_Object*, + Ewk_User_Media_Permission_Request* request, + void* user_data) { + WebViewImpl* self = static_cast(user_data); + if (self == NULL || self->listener_ == NULL) { + ewk_user_media_permission_reply(request, EINA_FALSE); + return EINA_TRUE; + } + + ewk_user_media_permission_request_suspend(request); + const Ewk_Security_Origin* origin = + ewk_user_media_permission_request_origin_get(request); + std::stringstream url; + url << ewk_security_origin_protocol_get(origin) + << "://" + << ewk_security_origin_host_get(origin) + << ":" + << ewk_security_origin_port_get(origin); + + auto result_handler = [request](bool result) { + LOGGER(DEBUG) << "Getusermedia Permission Result : " << result; + ewk_user_media_permission_reply(request, result); + }; + std::string test = url.str(); + self->listener_->OnUsermediaPermissionRequest(self->view_, + url.str(), + result_handler); + return EINA_TRUE; + }; + ewk_view_user_media_permission_callback_set(ewk_view_, callback, this); +} + std::string WebViewImpl::GetUrl() { return std::string(ewk_view_url_get(ewk_view_)); } diff --git a/runtime/browser/web_view_impl.h b/runtime/browser/web_view_impl.h index 6eb2b8c..2a81112 100755 --- a/runtime/browser/web_view_impl.h +++ b/runtime/browser/web_view_impl.h @@ -72,6 +72,7 @@ class WebViewImpl { void InitAuthenticationCallback(); void InitCertificateAllowCallback(); void InitPopupWaitCallback(); + void InitUsermediaCallback(); NativeWindow* window_; Ewk_Context* context_;