From 5028835bd07bda2991613f55eb6637697417ddcd Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Wed, 6 May 2015 18:51:55 +0900 Subject: [PATCH] Implement Authentication request callback Change-Id: If36c716b1db015d9bf247e47dc888dad71262322 --- src/runtime/web_application.cc | 13 +++++++++++++ src/runtime/web_application.h | 9 +++++++++ src/runtime/web_view.h | 8 ++++++++ src/runtime/web_view_impl.cc | 43 ++++++++++++++++++++++++++++++++++++++++++ src/runtime/web_view_impl.h | 1 + 5 files changed, 74 insertions(+) diff --git a/src/runtime/web_application.cc b/src/runtime/web_application.cc index 42b893c..7485d08 100755 --- a/src/runtime/web_application.cc +++ b/src/runtime/web_application.cc @@ -600,6 +600,19 @@ void WebApplication::OnQuotaExceed( // TODO(sngn.lee): create popup and show } +void WebApplication::OnAuthenticationRequest( + WebView* view, + const std::string& url, + const std::string& message, + std::function result_handler) { + // TODO(sngn.lee): create popup and show + result_handler(false, "", ""); +} + + void WebApplication::HandleDBusMethod(GDBusConnection* /*connection*/, const std::string& method_name, GVariant* parameters, diff --git a/src/runtime/web_application.h b/src/runtime/web_application.h index 6b6f069..1bebb20 100755 --- a/src/runtime/web_application.h +++ b/src/runtime/web_application.h @@ -67,6 +67,15 @@ class WebApplication : public WebView::EventListener { WebView* view, const std::string& url, std::function result_handler); + virtual void OnAuthenticationRequest( + WebView* view, + const std::string& url, + const std::string& message, + std::function result_handler); + private: bool Initialize(); diff --git a/src/runtime/web_view.h b/src/runtime/web_view.h index 4d71744..62fc1ad 100755 --- a/src/runtime/web_view.h +++ b/src/runtime/web_view.h @@ -55,6 +55,14 @@ class WebView { WebView* /*view*/, const std::string& /*url*/, std::function /*result_handler*/) {} + virtual void OnAuthenticationRequest( + WebView* /*view*/, + const std::string& /*url*/, + const std::string& /*message*/, + 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 db78800..d996451 100755 --- a/src/runtime/web_view_impl.cc +++ b/src/runtime/web_view_impl.cc @@ -100,6 +100,7 @@ void WebViewImpl::Initialize() { InitFullscreenCallback(); InitNotificationPermissionCallback(); InitGeolocationPermissionCallback(); + InitAuthenticationCallback(); // TODO(sngn.lee): "request,certificate,confirm" certification popup // TODO(sngn.lee): "notification,show" @@ -621,6 +622,48 @@ void WebViewImpl::InitGeolocationPermissionCallback() { this); } +void WebViewImpl::InitAuthenticationCallback() { + auto auth_callback = [](void* user_data, + Evas_Object*, + void* event_info) { + LoggerD("Authentication Request"); + WebViewImpl* self = static_cast(user_data); + Ewk_Auth_Challenge* auth_challenge = + static_cast(event_info); + + if (self == NULL || self->listener_ == NULL) { + ewk_auth_challenge_credential_cancel(auth_challenge); + return; + } + auto result_handler = [auth_challenge](bool submit, + const std::string& id, + const std::string& password) { + LoggerD("Authentication Result : submit %d", submit); + if (!submit) { + ewk_auth_challenge_credential_cancel(auth_challenge); + return; + } + ewk_auth_challenge_credential_use(auth_challenge, + id.c_str(), + password.c_str()); + }; + ewk_auth_challenge_suspend(auth_challenge); + const char* message = + ewk_auth_challenge_realm_get(auth_challenge); + std::string url = self->GetUrl(); + self->listener_->OnAuthenticationRequest(self->view_, + url, + message, + result_handler); + }; + // "authentication,challenge" + evas_object_smart_callback_add(ewk_view_, + "authentication,challenge", + auth_callback, + this); + smart_callbacks_["authentication,challenge"] = auth_callback; +} + 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 3debadd..37ce1b7 100755 --- a/src/runtime/web_view_impl.h +++ b/src/runtime/web_view_impl.h @@ -55,6 +55,7 @@ class WebViewImpl { void InitFullscreenCallback(); void InitNotificationPermissionCallback(); void InitGeolocationPermissionCallback(); + void InitAuthenticationCallback(); NativeWindow* window_; Ewk_Context* context_; -- 2.7.4