From 7c3ced2422291a51adce898f2b6aa851c8bd0c9a Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Wed, 29 Apr 2015 16:40:43 +0900 Subject: [PATCH] Implement geolocation permission callback Change-Id: Ia5af9042c3c6e8c8bdb64ef74cdd2d2eaa282af2 --- src/runtime/web_application.cc | 26 +++++++++++++++++++++++++ src/runtime/web_application.h | 4 ++++ src/runtime/web_view.h | 4 ++++ src/runtime/web_view_impl.cc | 43 +++++++++++++++++++++++++++++++++++++++++- src/runtime/web_view_impl.h | 1 + 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/runtime/web_application.cc b/src/runtime/web_application.cc index 4b3e252..72bd68d 100755 --- a/src/runtime/web_application.cc +++ b/src/runtime/web_application.cc @@ -60,6 +60,8 @@ namespace { const char* kFullscreenFeature = "fullscreen"; const char* kNotificationPrivilege = "http://tizen.org/privilege/notification"; + const char* kLocationPrivilege = + "http://tizen.org/privilege/location"; bool FindPrivilege(wrt::ApplicationData* app_data, const std::string& privilege) { @@ -457,6 +459,30 @@ void WebApplication::OnNotificationPermissionRequest( // TODO(sngn.lee): create popup and show } +void WebApplication::OnGeolocationPermissionRequest( + WebView* view, + const std::string& url, + std::function result_handler) { + // TODO(sngn.lee): check from DB url was already allowed + // if(check already allow or denied) { + // result_handler(true); + // 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(), kLocationPrivilege)) { + result_handler(false); + return; + } + + if (utils::StartsWith(url, "file://")) { + result_handler(true); + return; + } + + // TODO(sngn.lee): create popup and show +} + } // namespace wrt diff --git a/src/runtime/web_application.h b/src/runtime/web_application.h index 89a458e..c194823 100755 --- a/src/runtime/web_application.h +++ b/src/runtime/web_application.h @@ -59,6 +59,10 @@ class WebApplication : public WebView::EventListener { WebView* view, const std::string& url, std::function result_handler); + virtual void OnGeolocationPermissionRequest( + WebView* view, + const std::string& url, + std::function result_handler); std::string uuid() const { return uuid_; } diff --git a/src/runtime/web_view.h b/src/runtime/web_view.h index 2bad6c5..c79e379 100755 --- a/src/runtime/web_view.h +++ b/src/runtime/web_view.h @@ -47,6 +47,10 @@ class WebView { WebView* /*view*/, const std::string& /*url*/, std::function /*result_handler*/) {} + virtual void OnGeolocationPermissionRequest( + WebView* /*view*/, + const std::string& /*url*/, + std::function /*result_handler*/) {} }; WebView(wrt::NativeWindow* window, Ewk_Context* context); diff --git a/src/runtime/web_view_impl.cc b/src/runtime/web_view_impl.cc index d51e0b7..f976080 100755 --- a/src/runtime/web_view_impl.cc +++ b/src/runtime/web_view_impl.cc @@ -99,13 +99,13 @@ void WebViewImpl::Initialize() { InitWindowCreateCallback(); InitFullscreenCallback(); InitNotificationPermissionCallback(); + InitGeolocationPermissionCallback(); // TODO(sngn.lee): "request,certificate,confirm" certification popup // TODO(sngn.lee): "notification,show" // TODO(sngn.lee): "notification,cancel" // TODO(sngn.lee): "protocolhandler,registration,requested" // custom protocol handler - // TODO(sngn.lee): ewk_view_geolocation_permission_callback_set // TODO(sngn.lee): ewk_view_user_media_permission_callback_set // Show webview @@ -143,6 +143,10 @@ void WebViewImpl::Deinitialize() { ewk_view_, NULL, NULL); + ewk_view_geolocation_permission_callback_set( + ewk_view_, + NULL, + NULL); window_->RemoveRotationHandler(rotation_handler_id_); } @@ -549,6 +553,43 @@ void WebViewImpl::InitNotificationPermissionCallback() { this); } +void WebViewImpl::InitGeolocationPermissionCallback() { + auto permission_callback = []( + Evas_Object*, + Ewk_Geolocation_Permission_Request* request, + void* user_data) { + LoggerD("Geolocation Permission Request"); + WebViewImpl* self = static_cast(user_data); + if (self == NULL || self->listener_ == NULL) { + ewk_geolocation_permission_reply(request, EINA_FALSE); + return EINA_TRUE; + } + ewk_geolocation_permission_request_suspend(request); + + const Ewk_Security_Origin* ewk_origin = + ewk_geolocation_permission_request_origin_get(request); + auto result_handler = [request](bool result) { + LoggerD("Geolocation Permission Result : %d", result); + ewk_geolocation_permission_reply(request, result); + }; + + std::stringstream url; + url << ewk_security_origin_protocol_get(ewk_origin) + << "://" + << ewk_security_origin_host_get(ewk_origin) + << ":" + << ewk_security_origin_port_get(ewk_origin); + + self->listener_->OnGeolocationPermissionRequest( + self->view_, + url.str(), + result_handler); + return EINA_TRUE; + }; + ewk_view_geolocation_permission_callback_set(ewk_view_, + permission_callback, + this); +} std::string WebViewImpl::GetUrl() { return std::string(ewk_view_url_get(ewk_view_)); diff --git a/src/runtime/web_view_impl.h b/src/runtime/web_view_impl.h index 43893ca..3debadd 100755 --- a/src/runtime/web_view_impl.h +++ b/src/runtime/web_view_impl.h @@ -54,6 +54,7 @@ class WebViewImpl { void InitWindowCreateCallback(); void InitFullscreenCallback(); void InitNotificationPermissionCallback(); + void InitGeolocationPermissionCallback(); NativeWindow* window_; Ewk_Context* context_; -- 2.7.4