Enhance createPopup() API to support key callback
authorJihoon Chung <jihoon.chung@samsaung.com>
Fri, 27 Sep 2013 10:37:36 +0000 (19:37 +0900)
committerHoseon LEE <hoseon46.lee@samsung.com>
Mon, 14 Oct 2013 11:18:27 +0000 (20:18 +0900)
[Issue#]   P130927-03479
[Problem]  A web page underneath pop-up moves to the previous page when user expects the pop-up closed.
           This happens when a user select back-key when the permission request pop-up is on the screen.
[Cause]    Permission request pop-up does not handle the key callback.
           Moreover, the key event (which is not consumed) is passed onto the webview evas_object.
           As a result, the default behavior (i.e. dispatch tizenhwkey event) happens.
[Solution] Add key callback handler to popup evas_object.
           Destory popup and pass "deny" to webkit that waits permission request result,
           when Back-key event callback is called.

[SCMRequest] Needed by https://tizendev.org/gerrit/#/c/91230/

[Remarks] Implementation details
    * SecurityOriginSupportUtil::createPopup extend an argument to receive key callback.
      (Evas_Smart_Cb keyCallback)
    * Add "EVAS_CALLBACK_DEL" callback to remove before popup is removed.
      This behavior will prevent crash.
      Sometimes ecore dispatch event which is in the queue even callback data is already released.

Change-Id: I4aeaf6ee4e2a9219ec3fd27c886673a2ba88a452

src/view/common/CMakeLists.txt
src/view/common/view_logic_security_origin_support.cpp
src/view/common/view_logic_security_origin_support.h
src/view/webkit/view_logic_geolocation_support.cpp
src/view/webkit/view_logic_web_notification_permission_support.cpp
src/view/webkit/view_logic_web_storage_support.cpp

index 0588a06..3338fb0 100644 (file)
@@ -23,6 +23,7 @@ PKG_CHECK_MODULES(SYS_VIEW_COMMON_DEP
     cert-svc-vcore
     capi-appfw-app-manager
     capi-web-url-download
+    efl-assist
     eina
     elementary
     evas
index 900b9d8..0bab2f3 100644 (file)
 #include <memory>
 #include <Evas.h>
 #include <Elementary.h>
-#include <dpl/log/log.h>
+#include <efl_assist.h>
 #include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <dpl/log/secure_log.h>
+#include <dpl/unused.h>
 #include <dpl/wrt-dao-ro/common_dao_types.h>
 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
 #include <widget_model.h>
 #include <common/view_logic_get_parent_window_util.h>
 
 namespace ViewModule {
+namespace {
+struct CallbackData {
+    Evas_Smart_Cb eaKeyCallback;
+};
+
+static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
+static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
+{
+    DPL_UNUSED_PARAM(e);
+    DPL_UNUSED_PARAM(eventInfo);
+
+    Assert(data);
+    CallbackData* callbackData = static_cast<CallbackData*>(data);
+    Assert(obj);
+    ea_object_event_callback_del(obj, EA_CALLBACK_BACK, callbackData->eaKeyCallback);
+    delete callbackData;
+}
+}
 
 class SecurityOriginSupportImplementation
 {
@@ -88,13 +109,22 @@ Evas_Object* SecurityOriginSupportUtil::createPopup(
     Evas_Object* window,
     const char* bodyText,
     const char* checkText,
-    Evas_Smart_Cb
-    buttonCallback,
+    Evas_Smart_Cb buttonCallback,
+    Evas_Smart_Cb keyCallback,
     void* data)
 {
     LogDebug("createPopup");
     Evas_Object* parentWindow = PopupUtil::getParentWindow(window);
     Evas_Object* popup = elm_popup_add(parentWindow);
+
+    if (keyCallback) {
+        CallbackData* callbackData = new CallbackData;
+        callbackData->eaKeyCallback = keyCallback;
+
+        ea_object_event_callback_add(popup, EA_CALLBACK_BACK, keyCallback, data);
+        evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, deleteCallback, static_cast<void*>(callbackData));
+    }
+
     elm_object_style_set(popup, "popup/default");
     evas_object_size_hint_weight_set(popup,
                                      EVAS_HINT_EXPAND,
index b8867bc..d10900e 100644 (file)
@@ -70,6 +70,7 @@ Evas_Object* createPopup(Evas_Object* window,
                          const char* bodyText,
                          const char* checkText,
                          Evas_Smart_Cb buttonCallback,
+                         Evas_Smart_Cb keyCallback,
                          void* data);
 Evas_Object* getPopup(Evas_Object* button);
 Evas_Object* getCheck(Evas_Object* popup);
index 6ed0497..547a193 100644 (file)
@@ -68,6 +68,7 @@ void askUserForGeolocationPermission(
                                      body.c_str(),
                                      WRT_BODY_REMEMBER_PREFERENCE,
                                      popupCallback,
+                                     NULL,
                                      data);
 
     if (popup == NULL) {
index aade0fa..670358a 100644 (file)
@@ -65,6 +65,7 @@ bool askUserPermission(Evas_Object* parent, PermissionData* data)
                                      body.c_str(),
                                      WRT_BODY_REMEMBER_PREFERENCE,
                                      popupCallback,
+                                     NULL,
                                      data);
     if (popup == NULL) {
         delete data;
index 1786e52..e0f812d 100644 (file)
@@ -76,6 +76,7 @@ void askUserForWebStorageCreatePermission(
                                      body.c_str(),
                                      WRT_BODY_REMEMBER_PREFERENCE,
                                      popupCallback,
+                                     NULL,
                                      data);
 
     if (popup == NULL) {