From aa95b20b8922be18918d916f27a69118d7cc65ea Mon Sep 17 00:00:00 2001 From: Andrzej Surdej Date: Wed, 12 Dec 2012 18:45:36 +0100 Subject: [PATCH] Custom handlers callback connected. [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 | 190 +++++++++++++++++++++++++++++++++++------ 1 file changed, 165 insertions(+), 25 deletions(-) diff --git a/src/view/webkit/view_logic.cpp b/src/view/webkit/view_logic.cpp index c2a06ac..ddaecf4 100755 --- a/src/view/webkit/view_logic.cpp +++ b/src/view/webkit/view_logic.cpp @@ -34,8 +34,6 @@ #include #include #include -#include -#include #include #include @@ -62,6 +60,12 @@ #include #include #include +#include +#include +#include +#include + +#include 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 + (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(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(data), + EWK_CUSTOM_HANDLERS_REGISTERED); + else + ewk_custom_handlers_data_result_set( + static_cast(data), + EWK_CUSTOM_HANDLERS_DECLINED); + } else + ewk_custom_handlers_data_result_set( + static_cast(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(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 + (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(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(data), + EWK_CUSTOM_HANDLERS_REGISTERED); + else + ewk_custom_handlers_data_result_set( + static_cast(data), + EWK_CUSTOM_HANDLERS_DECLINED); + } else + ewk_custom_handlers_data_result_set( + static_cast(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(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( -- 2.7.4