Implement Certificate popup callback
authorSeungkeun Lee <sngn.lee@samsung.com>
Mon, 11 May 2015 09:20:45 +0000 (18:20 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Tue, 12 May 2015 02:22:59 +0000 (11:22 +0900)
Change-Id: I0e152bd72355477553cd4158fce41c79821b54aa

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 668f6f2..dbb07e7 100755 (executable)
@@ -92,7 +92,7 @@ const char* kBackgroundVibrationFeature = "background,vibration";
 const char* kGeolocationPermissionPrefix = "__WRT_GEOPERM_";
 const char* kNotificationPermissionPrefix = "__WRT_NOTIPERM_";
 const char* kQuotaPermissionPrefix = "__WRT_QUOTAPERM_";
-
+const char* kCertificateAllowPrefix = "__WRT_CERTIPERM_";
 
 
 bool FindPrivilege(wrt::ApplicationData* app_data,
@@ -667,6 +667,23 @@ void WebApplication::OnAuthenticationRequest(
   result_handler(false, "", "");
 }
 
+void WebApplication::OnCertificateAllowRequest(
+      WebView* view,
+      const std::string& url,
+      const std::string& pem,
+      std::function<void(bool allow)> result_handler) {
+  auto db = AppDB::GetInstance();
+  std::string reminder = db->Get(kCertificateAllowPrefix + pem);
+  if (reminder == "allowed") {
+    result_handler(true);
+  } else if (reminder == "denied") {
+    result_handler(false);
+  }
+
+  // TODO(sngn.lee): create poup and show
+  result_handler(false);
+}
+
 
 void WebApplication::HandleDBusMethod(GDBusConnection* /*connection*/,
                                       const std::string& method_name,
index 1bebb20..2f3c6b6 100755 (executable)
@@ -75,7 +75,11 @@ class WebApplication : public WebView::EventListener {
                          const std::string& id,
                          const std::string& password)
                    > result_handler);
-
+  virtual void OnCertificateAllowRequest(
+      WebView* view,
+      const std::string& url,
+      const std::string& pem,
+      std::function<void(bool allow)> result_handler);
 
  private:
   bool Initialize();
index 62fc1ad..e2d9a78 100755 (executable)
@@ -63,6 +63,13 @@ class WebView {
                            const std::string& /*id*/,
                            const std::string& /*password*/)
                      > /*result_handler*/) {}
+    virtual void OnCertificateAllowRequest(
+        WebView* /*view*/,
+        const std::string& /*url*/,
+        const std::string& /*pem*/,
+        std::function<void(bool allow)> result_handler) {
+      result_handler(false);
+    }
   };
 
   WebView(wrt::NativeWindow* window, Ewk_Context* context);
index 320b728..d4066db 100755 (executable)
@@ -101,8 +101,8 @@ void WebViewImpl::Initialize() {
   InitNotificationPermissionCallback();
   InitGeolocationPermissionCallback();
   InitAuthenticationCallback();
+  InitCertificateAllowCallback();
 
-  // TODO(sngn.lee): "request,certificate,confirm" certification popup
   // TODO(sngn.lee): "notification,show"
   // TODO(sngn.lee): "notification,cancel"
   // TODO(sngn.lee): "protocolhandler,registration,requested"
@@ -664,6 +664,41 @@ void WebViewImpl::InitAuthenticationCallback() {
   smart_callbacks_["authentication,challenge"] = auth_callback;
 }
 
+void WebViewImpl::InitCertificateAllowCallback() {
+  auto certi_callback = [](void* user_data,
+                           Evas_Object*,
+                           void* event_info) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    Ewk_Certificate_Policy_Decision* policy =
+      static_cast<Ewk_Certificate_Policy_Decision*>(event_info);
+
+    if (self == NULL || self->listener_ == NULL) {
+      ewk_certificate_policy_decision_allowed_set(policy, EINA_FALSE);
+      return;
+    }
+
+    ewk_certificate_policy_decision_suspend(policy);
+    auto result_handler = [policy](bool allow) {
+      ewk_certificate_policy_decision_allowed_set(policy, allow);
+    };
+
+    auto ptr = ewk_certificate_policy_decision_url_get(policy);
+    std::string url(ptr ? ptr : "");
+    ptr = ewk_certificate_policy_decision_certificate_pem_get(policy);
+    std::string pem(ptr ? ptr : "");
+    self->listener_->OnCertificateAllowRequest(self->view_,
+                                               url,
+                                               pem,
+                                               result_handler);
+  };
+  evas_object_smart_callback_add(ewk_view_,
+                                 "request,certificate,confirm",
+                                 certi_callback,
+                                 this);
+  smart_callbacks_["request,certificate,confirm"] = certi_callback;
+}
+
+
 std::string WebViewImpl::GetUrl() {
   return std::string(ewk_view_url_get(ewk_view_));
 }
index 37ce1b7..728d53c 100755 (executable)
@@ -56,6 +56,7 @@ class WebViewImpl {
   void InitNotificationPermissionCallback();
   void InitGeolocationPermissionCallback();
   void InitAuthenticationCallback();
+  void InitCertificateAllowCallback();
 
   NativeWindow* window_;
   Ewk_Context* context_;