Implement Authentication request callback
authorSeungkeun Lee <sngn.lee@samsung.com>
Wed, 6 May 2015 09:51:55 +0000 (18:51 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Thu, 7 May 2015 04:42:05 +0000 (13:42 +0900)
Change-Id: If36c716b1db015d9bf247e47dc888dad71262322

src/runtime/web_application.cc
src/runtime/web_application.h
src/runtime/web_view.h
src/runtime/web_view_impl.cc
src/runtime/web_view_impl.h

index 42b893c..7485d08 100755 (executable)
@@ -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<void(bool submit,
+                         const std::string& id,
+                         const std::string& password)
+                   > result_handler) {
+  // TODO(sngn.lee): create popup and show
+  result_handler(false, "", "");
+}
+
+
 void WebApplication::HandleDBusMethod(GDBusConnection* /*connection*/,
                                       const std::string& method_name,
                                       GVariant* parameters,
index 6b6f069..1bebb20 100755 (executable)
@@ -67,6 +67,15 @@ class WebApplication : public WebView::EventListener {
       WebView* view,
       const std::string& url,
       std::function<void(bool)> result_handler);
+  virtual void OnAuthenticationRequest(
+      WebView* view,
+      const std::string& url,
+      const std::string& message,
+      std::function<void(bool submit,
+                         const std::string& id,
+                         const std::string& password)
+                   > result_handler);
+
 
  private:
   bool Initialize();
index 4d71744..62fc1ad 100755 (executable)
@@ -55,6 +55,14 @@ class WebView {
         WebView* /*view*/,
         const std::string& /*url*/,
         std::function<void(bool)> /*result_handler*/) {}
+    virtual void OnAuthenticationRequest(
+        WebView* /*view*/,
+        const std::string& /*url*/,
+        const std::string& /*message*/,
+        std::function<void(bool /*submit*/,
+                           const std::string& /*id*/,
+                           const std::string& /*password*/)
+                     > /*result_handler*/) {}
   };
 
   WebView(wrt::NativeWindow* window, Ewk_Context* context);
index db78800..d996451 100755 (executable)
@@ -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<WebViewImpl*>(user_data);
+    Ewk_Auth_Challenge* auth_challenge =
+        static_cast<Ewk_Auth_Challenge*>(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_));
 }
index 3debadd..37ce1b7 100755 (executable)
@@ -55,6 +55,7 @@ class WebViewImpl {
   void InitFullscreenCallback();
   void InitNotificationPermissionCallback();
   void InitGeolocationPermissionCallback();
+  void InitAuthenticationCallback();
 
   NativeWindow* window_;
   Ewk_Context* context_;