#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 <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>
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():
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,
}
// 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();
}
}
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,
void* eventInfo)
{
LogDebug("enter");
- debugCustomHandlerData(eventInfo);
+ getCustomHandlerFromData(eventInfo);
// TODO to be continued...
}
void* eventInfo)
{
LogDebug("enter");
- debugCustomHandlerData(eventInfo);
+ getCustomHandlerFromData(eventInfo);
// TODO to be continued...
}
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,
void* eventInfo)
{
LogDebug("enter");
- debugCustomHandlerData(eventInfo);
+ getCustomHandlerFromData(eventInfo);
// TODO to be continued...
}
void* eventInfo)
{
LogDebug("enter");
- debugCustomHandlerData(eventInfo);
+ getCustomHandlerFromData(eventInfo);
// TODO to be continued...
}