Custom handler popups
authorPrzemyslaw Ciezkowski <p.ciezkowski@samsung.com>
Tue, 11 Dec 2012 14:10:10 +0000 (15:10 +0100)
committerGerrit Code Review <gerrit2@kim11>
Wed, 12 Dec 2012 13:54:46 +0000 (22:54 +0900)
[Issue#] N/A
[Feature] Custom handler register callbacks should show popup.
[Problem] N/A
[Cause] N/A
[Solution] Popups added.

[Verification] Run manual test custom_handlers.wgt
1. Click register provider, check if popup appears.
2. Click again, popup should not appear.
3. Run widget again check if popup doesn't appear.
Repeat steps for content handler.

Change-Id: I0117dcaf098e5d5f98b9ccb5570a66ff315d07a9

src/view/webkit/CMakeLists.txt
src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h

index 33b3325..7653370 100644 (file)
@@ -25,7 +25,9 @@ PKG_CHECK_MODULES(VIEW_MODULE_DEP
     dpl-popup-efl
     dpl-utils-efl
     dpl-wrt-dao-ro
+    wrt-commons-custom-handler-dao-rw
     wrt-plugin-js-overlay
+    wrt-popup-wrt-runner
     security-core
     security-client
     REQUIRED
index 78de022..bef1544 100644 (file)
@@ -34,6 +34,8 @@
 #include <vconf.h>
 #include <widget_model.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
+#include <wrt-commons/custom-handler-dao-rw/custom_handler_dao.h>
 
 #include <common/application_data.h>
 #include <common/application_launcher.h>
@@ -54,6 +56,7 @@
 #include <view_logic_geolocation_support_webkit2.h>
 #include <view_logic_web_storage_support.h>
 #include "bundles/plugin_module_support.h"
+#include <popup-runner/PopupInvoker.h>
 
 #include <EWebKit2.h>
 #include <js_overlay_types.h>
@@ -121,6 +124,11 @@ const char * const EWK_PROTOCOLHANDLER_UNREGISTRATION = "protocolhandler,unregis
 const char * const EWK_CONTENTHANDLER_REGISTRATION = "contenthandler,registration,requested";
 const char * const EWK_CONTENTHANDLER_ISREGISTERED = "contenthandler,isregistered";
 const char * const EWK_CONTENTHANDLER_UNREGISTRATION = "contenthandler,unregistration,requested";
+
+const char PROTOCOL_HANDLER_ASK_MSG[] = "Add protocol?";
+const char PROTOCOL_HANDLER_ASK_TITLE[] = "Add protocol";
+const char CONTENT_HANDLER_ASK_MSG[] = "Add content?";
+const char CONTENT_HANDLER_ASK_TITLE[] = "Add content";
 }
 
 ViewLogic::ViewLogic():
@@ -130,12 +138,14 @@ ViewLogic::ViewLogic():
     m_model(0),
     m_cbs(new WRT::UserDelegates),
     m_appsSupport(new ViewModule::AppsSupport()),
-    m_vibrationSupport(NULL)
+    m_vibrationSupport(NULL),
+    m_attachedToCustomHandlerDao(false)
 {
 }
 
 ViewLogic::~ViewLogic ()
 {
+    detachFromCustomHandlersDao();
 }
 
 void ViewLogic::createWebView(Ewk_Context* context,
@@ -1660,26 +1670,46 @@ void ViewLogic::imeCloseCallback(
 }
 
 // helper method
-void ViewLogic::debugCustomHandlerData(void* data)
+CustomHandlerDB::CustomHandlerPtr getCustomHandlerFromData(void* data)
 {
     Assert(data);
     Ewk_Custom_Handlers_Data* handler =
                 static_cast<Ewk_Custom_Handlers_Data*>(data);
+    CustomHandlerDB::CustomHandlerPtr customHandler(new CustomHandlerDB::CustomHandler());
     const char* base_url = ewk_custom_handlers_data_base_url_get(handler);
     if (base_url) {
         LogDebug("base url: " << base_url);
+        customHandler->base_url = DPL::FromASCIIString(string(base_url));
     }
     const char* url = ewk_custom_handlers_data_url_get(handler);
     if (url) {
         LogDebug("url: " << url);
+        customHandler->url = DPL::FromASCIIString(string(url));
     }
     const char* target = ewk_custom_handlers_data_target_get(handler);
     if (target) {
         LogDebug("target: " << target);
+        customHandler->target = DPL::FromASCIIString(string(target));
     }
     const char* title = ewk_custom_handlers_data_title_get(handler);
     if (title) {
         LogDebug("title: " << title);
+        customHandler->title = DPL::FromASCIIString(string(title));
+    }
+    return customHandler;
+}
+
+void ViewLogic::attachToCustomHandlersDao()
+{
+    if (!m_attachedToCustomHandlerDao) {
+        CustomHandlerDB::Interface::attachDatabaseRW();
+    }
+}
+
+void ViewLogic::detachFromCustomHandlersDao()
+{
+    if (m_attachedToCustomHandlerDao) {
+        CustomHandlerDB::Interface::detachDatabase();
     }
 }
 
@@ -1687,9 +1717,31 @@ void ViewLogic::protocolHandlerRegistrationCallback(void* data,
                                                     Evas_Object* obj,
                                                     void* eventInfo)
 {
+    Assert(data);
     LogDebug("enter");
-    debugCustomHandlerData(eventInfo);
-    // TODO to be continued...
+    CustomHandlerDB::CustomHandlerPtr customHandler =
+            getCustomHandlerFromData(eventInfo);
+    //TODO: whitelist/blacklist
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+    LogDebug("Creating handlers dao");
+    This->attachToCustomHandlersDao();
+    CustomHandlerDB::CustomHandlerDAO handlersDao(This->m_model->TizenId);
+    CustomHandlerDB::CustomHandlerPtr handler =
+            handlersDao.getProtocolHandler(customHandler->target, customHandler->url);
+    if (handler) {
+        LogDebug("Protocol already registered - nothing to do");
+    } else {
+        LogDebug("Protocol handler not found");
+        if (Wrt::Popup::PopupInvoker().askYesNo(PROTOCOL_HANDLER_ASK_TITLE, PROTOCOL_HANDLER_ASK_MSG)) {
+            LogDebug("User allowed");
+            customHandler->user_allowed = true;
+        } else {
+            LogDebug("User didn't allow");
+            customHandler->user_allowed = false;
+        }
+        handlersDao.registerProtocolHandler(*(customHandler.get()));
+        LogDebug("Protocal saved");
+    }
 }
 
 void ViewLogic::protocolHandlerIsRegisteredCallback(void* data,
@@ -1697,7 +1749,7 @@ void ViewLogic::protocolHandlerIsRegisteredCallback(void* data,
                                                     void* eventInfo)
 {
     LogDebug("enter");
-    debugCustomHandlerData(eventInfo);
+    getCustomHandlerFromData(eventInfo);
     // TODO to be continued...
 }
 
@@ -1706,7 +1758,7 @@ void ViewLogic::protocolHandlerUnregistrationCallback(void* data,
                                                       void* eventInfo)
 {
     LogDebug("enter");
-    debugCustomHandlerData(eventInfo);
+    getCustomHandlerFromData(eventInfo);
     // TODO to be continued...
 }
 
@@ -1714,9 +1766,31 @@ void ViewLogic::contentHandlerRegistrationCallback(void* data,
                                                    Evas_Object* obj,
                                                    void* eventInfo)
 {
+    Assert(data);
     LogDebug("enter");
-    debugCustomHandlerData(eventInfo);
-    // TODO to be continued...
+    CustomHandlerDB::CustomHandlerPtr customHandler =
+            getCustomHandlerFromData(eventInfo);
+    //TODO: whitelist/blacklist
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+    LogDebug("Creating handlers dao");
+    This->attachToCustomHandlersDao();
+    CustomHandlerDB::CustomHandlerDAO handlersDao(This->m_model->TizenId);
+    CustomHandlerDB::CustomHandlerPtr handler =
+            handlersDao.getContentHandler(customHandler->target, customHandler->url);
+    if (handler) {
+        LogDebug("Content already registered - nothing to do");
+    } else {
+        LogDebug("Content handler not found");
+        if (Wrt::Popup::PopupInvoker().askYesNo(CONTENT_HANDLER_ASK_TITLE, CONTENT_HANDLER_ASK_MSG)) {
+            LogDebug("User allowed");
+            customHandler->user_allowed = true;
+        } else {
+            LogDebug("User didn't allow");
+            customHandler->user_allowed = false;
+        }
+        handlersDao.registerContentHandler(*(customHandler.get()));
+        LogDebug("Content saved");
+    }
 }
 
 void ViewLogic::contentHandlerIsRegisteredCallback(void* data,
@@ -1724,7 +1798,7 @@ void ViewLogic::contentHandlerIsRegisteredCallback(void* data,
                                                    void* eventInfo)
 {
     LogDebug("enter");
-    debugCustomHandlerData(eventInfo);
+    getCustomHandlerFromData(eventInfo);
     // TODO to be continued...
 }
 
@@ -1733,7 +1807,7 @@ void ViewLogic::contentHandlerUnregistrationCallback(void* data,
                                                      void* eventInfo)
 {
     LogDebug("enter");
-    debugCustomHandlerData(eventInfo);
+    getCustomHandlerFromData(eventInfo);
     // TODO to be continued...
 }
 
index 84fce92..b48e524 100644 (file)
@@ -215,9 +215,9 @@ class ViewLogic : public ViewModule::IViewModule
             Evas_Object* obj,
             void* eventInfo);
 
-    static void debugCustomHandlerData(void* data);
-
     // custom content/scheme handlers
+    void attachToCustomHandlersDao();
+    void detachFromCustomHandlersDao();
     static void protocolHandlerRegistrationCallback(void* data,
             Evas_Object* obj,
             void* eventInfo);
@@ -292,6 +292,7 @@ class ViewLogic : public ViewModule::IViewModule
     std::unique_ptr<ViewModule::AppsSupport> m_appsSupport;
     std::unique_ptr<ViewModule::VibrationSupport> m_vibrationSupport;
     std::unique_ptr<ViewModule::SecurityOriginSupport> m_securityOriginSupport;
+    bool m_attachedToCustomHandlerDao;
 };
 
 #endif //VIEW_LOGIC_H_