Custom handlers callback connected.
authorAndrzej Surdej <a.surdej@samsung.com>
Wed, 12 Dec 2012 17:45:36 +0000 (18:45 +0100)
committerGerrit Code Review <gerrit2@kim11>
Mon, 17 Dec 2012 10:46:11 +0000 (19:46 +0900)
[Issue#] N/A
[Problem] Support for custom handlers
[Cause] N/A
[Solution] Connected webkit callback with database to stor data.
[ScmRequest] wrt-commons
This commit depends on https://tizendev.org/gerrit/#/c/20791/
[Verification] To verify run custom_handlers.wgt and run
different buttons combination. Uninstall, install and try
this again

Change-Id: Iffc08a7f1093c249945df502c6f4bffe479f004a

src/view/webkit/view_logic.cpp

index c2a06ac..ddaecf4 100755 (executable)
@@ -34,8 +34,6 @@
 #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>
 #include <js_overlay_types.h>
 #include <i_runnable_widget_object.h>
 #include <profiling_util.h>
+#include <wrt-commons/custom-handler-dao-ro/common_dao_types.h>
+#include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
+#include <wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h>
+#include <wrt-commons/custom-handler-dao-rw/custom_handler_dao.h>
+
+#include <appsvc/appsvc.h>
 
 namespace {
 const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
@@ -1773,6 +1777,10 @@ char const * const contentBlackList[contentBlackListLenth] = {
     "text/xml"
 };
 
+//TODO registration, checking if registered and unregistration can be done in
+//common functions for both types of handlers. Only white and black lists
+//have to be separated
+//TODO attach database only one at the start (not in every callback?)
 void ViewLogic::protocolHandlerRegistrationCallback(void* data,
                                                     Evas_Object* obj,
                                                     void* eventInfo)
@@ -1823,23 +1831,49 @@ void ViewLogic::protocolHandlerRegistrationCallback(void* data,
     This->attachToCustomHandlersDao();
     CustomHandlerDB::CustomHandlerDAO handlersDao(This->m_model->TizenId);
     CustomHandlerDB::CustomHandlerPtr handler =
-            handlersDao.getProtocolHandler(customHandler->target, customHandler->url);
-    if (handler) {
+            handlersDao.getProtocolHandler(customHandler->target,
+                                           customHandler->url,
+                                           customHandler->base_url);
+    if (handler && (handler->user_decision & CustomHandlerDB::DecisionSaved)) {
         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;
+            customHandler->user_decision = CustomHandlerDB::Agreed;
+        } else {
+            LogDebug("User didn't allow");
+            customHandler->user_decision = CustomHandlerDB::Declined;
+        }
+        //TODO merge to one popup
+        LogDebug("Protocol handler not found");
+        if (Wrt::Popup::PopupInvoker().askYesNo("REMEMBER", "Want to remember? ")) {
+            LogDebug("User allowed");
+            customHandler->user_decision =
+                static_cast<CustomHandlerDB::HandlerState>
+                (customHandler->user_decision | CustomHandlerDB::DecisionSaved);
         } else {
             LogDebug("User didn't allow");
-            customHandler->user_allowed = false;
         }
+        if (customHandler->user_decision == CustomHandlerDB::Declined)
+            return;
         handlersDao.registerProtocolHandler(*(customHandler.get()));
+        if (customHandler->user_decision & CustomHandlerDB::Agreed) {
+            //TODO remove old default handler somehow from appsvc
+            LogDebug("Registering appservice entry");
+            int ret = appsvc_set_defapp(APPSVC_OPERATION_VIEW,
+                    NULL,
+                    DPL::ToUTF8String(customHandler->target).c_str(),
+                    DPL::ToUTF8String(This->m_model->TizenId).c_str());
+            if (APPSVC_RET_OK != ret)
+            {
+                LogWarning("Appsvc entry failed: " << ret);
+            }
+        }
         LogDebug("Protocal saved");
     }
 
-    // TODO to be continued...
+    This->detachFromCustomHandlersDao();
 }
 
 void ViewLogic::protocolHandlerIsRegisteredCallback(void* data,
@@ -1847,8 +1881,29 @@ void ViewLogic::protocolHandlerIsRegisteredCallback(void* data,
                                                     void* eventInfo)
 {
     LogDebug("enter");
-    getCustomHandlerFromData(eventInfo);
-    // TODO to be continued...
+    CustomHandlerDB::CustomHandlerPtr customHandler = getCustomHandlerFromData(eventInfo);
+    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,
+                                           customHandler->base_url);
+    if (handler) {
+        if (handler->user_decision & CustomHandlerDB::Agreed)
+            ewk_custom_handlers_data_result_set(
+                static_cast<Ewk_Custom_Handlers_Data*>(data),
+                EWK_CUSTOM_HANDLERS_REGISTERED);
+        else
+            ewk_custom_handlers_data_result_set(
+                static_cast<Ewk_Custom_Handlers_Data*>(data),
+                EWK_CUSTOM_HANDLERS_DECLINED);
+    } else
+            ewk_custom_handlers_data_result_set(
+                static_cast<Ewk_Custom_Handlers_Data*>(data),
+                EWK_CUSTOM_HANDLERS_NEW);
+    This->detachFromCustomHandlersDao();
 }
 
 void ViewLogic::protocolHandlerUnregistrationCallback(void* data,
@@ -1856,8 +1911,27 @@ void ViewLogic::protocolHandlerUnregistrationCallback(void* data,
                                                       void* eventInfo)
 {
     LogDebug("enter");
-    getCustomHandlerFromData(eventInfo);
-    // TODO to be continued...
+    CustomHandlerDB::CustomHandlerPtr customHandler =
+            getCustomHandlerFromData(eventInfo);
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+    LogDebug("Creating handlers dao");
+    This->attachToCustomHandlersDao();
+    CustomHandlerDB::CustomHandlerDAO handlersDao(This->m_model->TizenId);
+    CustomHandlerDB::CustomHandlerPtr handlerCheck =
+        handlersDao.getProtocolHandler(customHandler->target,
+                                       customHandler->url,
+                                       customHandler->base_url);
+    if (handlerCheck) {
+        if (handlerCheck->user_decision & CustomHandlerDB::Agreed)
+            appsvc_unset_defapp(DPL::ToUTF8String(This->m_model->TizenId).c_str());
+
+        handlersDao.unregisterProtocolHandler(customHandler->target,
+                                              customHandler->url,
+                                              customHandler->base_url);
+    } else
+        LogDebug("Nothing to unregister");
+
+    This->detachFromCustomHandlersDao();
 }
 
 void ViewLogic::contentHandlerRegistrationCallback(void* data,
@@ -1888,24 +1962,49 @@ void ViewLogic::contentHandlerRegistrationCallback(void* 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");
+        CustomHandlerDB::CustomHandlerPtr handler =
+            handlersDao.getContentHandler(customHandler->target,
+                                          customHandler->url,
+                                          customHandler->base_url);
+    if (handler && (handler->user_decision & CustomHandlerDB::DecisionSaved)) {
+        LogDebug("Protocol 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("Protocol handler not found");
+        if (Wrt::Popup::PopupInvoker().askYesNo(PROTOCOL_HANDLER_ASK_TITLE, PROTOCOL_HANDLER_ASK_MSG)) {
+            LogDebug("User allowed");
+            customHandler->user_decision = CustomHandlerDB::Agreed;
+        } else {
+            LogDebug("User didn't allow");
+            customHandler->user_decision = CustomHandlerDB::Declined;
+        }
+        //TODO merge to one popup
+        LogDebug("Protocol handler not found");
+        if (Wrt::Popup::PopupInvoker().askYesNo("REMEMBER", "Want to remember? ")) {
             LogDebug("User allowed");
-            customHandler->user_allowed = true;
+            customHandler->user_decision =
+                static_cast<CustomHandlerDB::HandlerState>
+                (customHandler->user_decision | CustomHandlerDB::DecisionSaved);
         } else {
             LogDebug("User didn't allow");
-            customHandler->user_allowed = false;
         }
+        if (customHandler->user_decision == CustomHandlerDB::Declined)
+            return;
         handlersDao.registerContentHandler(*(customHandler.get()));
+        if (customHandler->user_decision & CustomHandlerDB::Agreed) {
+            //TODO remove old default handler somehow from appsvc
+            LogDebug("Registering appservice entry");
+            int ret = appsvc_set_defapp(APPSVC_OPERATION_VIEW,
+                    DPL::ToUTF8String(customHandler->target).c_str(),
+                    NULL,
+                    DPL::ToUTF8String(This->m_model->TizenId).c_str());
+            if (APPSVC_RET_OK != ret)
+            {
+                LogWarning("Appsvc entry failed: " << ret);
+            }
+        }
         LogDebug("Content saved");
     }
-
-    // TODO to be continued...
+    This->detachFromCustomHandlersDao();
 }
 
 void ViewLogic::contentHandlerIsRegisteredCallback(void* data,
@@ -1913,8 +2012,31 @@ void ViewLogic::contentHandlerIsRegisteredCallback(void* data,
                                                    void* eventInfo)
 {
     LogDebug("enter");
-    getCustomHandlerFromData(eventInfo);
-    // TODO to be continued...
+    CustomHandlerDB::CustomHandlerPtr customHandler =
+        getCustomHandlerFromData(eventInfo);
+    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,
+                                          customHandler->base_url);
+    if (handler) {
+        if (handler->user_decision & CustomHandlerDB::Agreed)
+            ewk_custom_handlers_data_result_set(
+                static_cast<Ewk_Custom_Handlers_Data*>(data),
+                EWK_CUSTOM_HANDLERS_REGISTERED);
+        else
+            ewk_custom_handlers_data_result_set(
+                static_cast<Ewk_Custom_Handlers_Data*>(data),
+                EWK_CUSTOM_HANDLERS_DECLINED);
+    } else
+            ewk_custom_handlers_data_result_set(
+                static_cast<Ewk_Custom_Handlers_Data*>(data),
+                EWK_CUSTOM_HANDLERS_NEW);
+    This->detachFromCustomHandlersDao();
 }
 
 void ViewLogic::contentHandlerUnregistrationCallback(void* data,
@@ -1922,8 +2044,26 @@ void ViewLogic::contentHandlerUnregistrationCallback(void* data,
                                                      void* eventInfo)
 {
     LogDebug("enter");
-    getCustomHandlerFromData(eventInfo);
-    // TODO to be continued...
+    CustomHandlerDB::CustomHandlerPtr customHandler =
+            getCustomHandlerFromData(eventInfo);
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+    LogDebug("Creating handlers dao");
+    This->attachToCustomHandlersDao();
+    CustomHandlerDB::CustomHandlerDAO handlersDao(This->m_model->TizenId);
+        CustomHandlerDB::CustomHandlerPtr handlerCheck =
+            handlersDao.getContentHandler(customHandler->target,
+                                           customHandler->url,
+                                           customHandler->base_url);
+        if (handlerCheck) {
+            if (handlerCheck->user_decision & CustomHandlerDB::Agreed)
+                appsvc_unset_defapp(DPL::ToUTF8String(This->m_model->TizenId).c_str());
+
+            handlersDao.unregisterContentHandler(customHandler->target,
+                                                     customHandler->url,
+                                                     customHandler->base_url);
+        } else
+            LogDebug("Nothing to unregister");
+    This->detachFromCustomHandlersDao();
 }
 
 void ViewLogic::didRunJavaScriptCallback(