#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";
"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)
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,
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,
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,
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,
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,
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(