Implement "create,window", "close,window"
authorSeungkeun Lee <sngn.lee@samsung.com>
Tue, 28 Apr 2015 07:07:15 +0000 (16:07 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Tue, 28 Apr 2015 07:10:12 +0000 (16:10 +0900)
Change-Id: I6ebf340c3d35ff3c75eadb3ebdba99cb35338f25

packaging/wrt.spec
src/runtime/CMakeLists.txt
src/runtime/web_application.cc
src/runtime/web_view_impl.cc
src/runtime/web_view_impl.h

index 7efc609..d3ba278 100755 (executable)
@@ -27,6 +27,7 @@ BuildRequires: pkgconfig(cert-svc)
 BuildRequires: pkgconfig(uuid)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(ecore)
 BuildRequires: boost-devel
 %if %{with x}
 BuildRequires: pkgconfig(ecore-x)
index d6cd9ed..c69904c 100755 (executable)
@@ -28,6 +28,7 @@ PKG_CHECK_MODULES(TARGET_RUNTIME_DEPS
   deviced
   capi-system-runtime-info
   aul
+  ecore
   REQUIRED
 )
 
index 229b861..989e73a 100755 (executable)
@@ -5,6 +5,7 @@
 #include "runtime/web_application.h"
 
 #include <app.h>
+#include <Ecore.h>
 #include <ewk_chromium.h>
 #include <algorithm>
 #include <memory>
@@ -295,7 +296,12 @@ void WebApplication::OnClosedWebView(WebView * view) {
     window_->SetContent(view_stack_.front()->evas_object());
   }
 
-  delete view;
+  // Delete after the callback context(for ewk view) was not used
+  ecore_idler_add([](void* view) {
+      WebView* obj = static_cast<WebView*>(view);
+      delete view;
+      return EINA_FALSE;
+    }, view);
 }
 
 void WebApplication::OnReceivedWrtMessage(
@@ -404,7 +410,7 @@ void WebApplication::SetupWebView(WebView* view) {
   // TODO(sngn.lee): set CSP
 }
 
-bool OnDidNavigation(WebView* view, const std::string& url) {
+bool WebApplication::OnDidNavigation(WebView* view, const std::string& url) {
   // TODO(sngn.lee): scheme handling
   // except(file , http, https, app) pass to appcontrol and return false
   return true;
index bce6e47..15a9b94 100755 (executable)
@@ -94,6 +94,7 @@ void WebViewImpl::Initialize() {
   InitConsoleMessageCallback();
   InitCustomContextMenuCallback();
   InitRotationCallback();
+  InitWindowCreateCallback();
 
   // TODO(sngn.lee): "request,certificate,confirm" certification popup
   // TODO(sngn.lee): ewk_view_notification_permission_callback_set
@@ -448,6 +449,40 @@ void WebViewImpl::InitRotationCallback() {
                                   std::placeholders::_1));
 }
 
+void WebViewImpl::InitWindowCreateCallback() {
+  auto create_callback = [](void* user_data,
+                            Evas_Object*,
+                            void* event_info) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    if (!self->listener_) {
+      return;
+    }
+    WebView* new_view = new WebView(self->window_, self->context_);
+    self->listener_->OnCreatedNewWebView(self->view_, new_view);
+  };
+
+  auto close_callback = [](void* user_data,
+                            Evas_Object*,
+                            void*) {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    if (!self->listener_) {
+      return;
+    }
+    self->listener_->OnClosedWebView(self->view_);
+  };
+  evas_object_smart_callback_add(ewk_view_,
+                                 "create,window",
+                                 create_callback,
+                                 this);
+  evas_object_smart_callback_add(ewk_view_,
+                                 "close,window",
+                                 close_callback,
+                                 this);
+
+  smart_callbacks_["create,window"] = create_callback;
+  smart_callbacks_["close,window"] = close_callback;
+}
+
 std::string WebViewImpl::GetUrl() {
   return std::string(ewk_view_url_get(ewk_view_));
 }
index 3a89b96..a83c6d2 100755 (executable)
@@ -51,6 +51,7 @@ class WebViewImpl {
   void InitConsoleMessageCallback();
   void InitCustomContextMenuCallback();
   void InitRotationCallback();
+  void InitWindowCreateCallback();
 
   NativeWindow* window_;
   Ewk_Context* context_;