#include <common/view_logic_uri_support.h>
#include <common/view_logic_user_agent_support.h>
#include <common/view_logic_vibration_support.h>
-#include <common/view_logic_web_notification_support.h>
#include <view_logic_scheme_support.h>
#include <view_logic_filesystem_support.h>
#include <view_logic_geolocation_support_webkit2.h>
#include <view_logic_usermedia_support.h>
+#include <view_logic_web_notification_support.h>
#include <view_logic_web_storage_support.h>
#include "bundles/plugin_module_support.h"
#include <popup-runner/PopupInvoker.h>
LogDebug("notificationPermissionRequestCallback called");
Assert(data);
ViewLogic* This = static_cast<ViewLogic*>(data);
+ if (This->m_securityOriginSupport->isNeedPermissionCheck(
+ SecurityOriginDB::FEATURE_WEB_NOTIFICATION)
+ == WrtDB::SETTINGS_TYPE_OFF)
+ {
+ Ewk_Notification_Permission_Request* request =
+ static_cast<Ewk_Notification_Permission_Request*>(eventInfo);
+ ewk_notification_permission_request_response(
+ This->m_ewkContext,
+ request,
+ EINA_FALSE);
+ return;
+ }
Assert(eventInfo);
- Ewk_Notification_Permission_Request* request =
- static_cast<Ewk_Notification_Permission_Request*>(eventInfo);
- ewk_notification_permission_request_response(
+ ViewModule::WebNotification::webNotificationPermissionRequest(
+ This->m_window,
+ This->m_securityOriginSupport->getSecurityOriginDAO(),
This->m_ewkContext,
- request,
- EINA_TRUE);
+ eventInfo);
return;
}
#include <string>
#include <dpl/log/log.h>
#include <dpl/string.h>
+#include <wrt-commons/security-origin-dao/security_origin_dao_types.h>
+#include <wrt-commons/security-origin-dao/security_origin_dao.h>
+#include <common/view_logic_security_origin_support.h>
#include <notification.h>
#include <pcrecpp.h>
#include <sstream>
#include <curl/curl.h>
#include <widget_model.h>
+#include <EWebKit2.h>
namespace {
const char* PATTERN_CHECK_EXTERNAL = "^http(s)?://\\w+.*$";
+const char* const WEB_NOTIFICATION_ASK_BODY_PREFIX = "Do you want to allow ";
+const char* const WEB_NOTIFICATION_ASK_BODY_POSTFIX =
+ " to use web notificaion?";
+const char* const WEB_NOTIFICATION_ASK_CHECK = "Don't ask again";
+
}
namespace ViewModule {
namespace WebNotification {
+using namespace SecurityOriginDB;
+using namespace ViewModule::SecurityOriginSupportUtil;
+
+class WebNotificationPermissionData
+ : public ViewModule::SecurityOriginSupportUtil::PermissionData
+{
+ public:
+ Ewk_Context* m_ewkContext;
+
+ WebNotificationPermissionData(
+ SecurityOriginDB::SecurityOriginDAO* originDao,
+ SecurityOriginDB::SecurityOriginData originData,
+ Ewk_Context* ewkContext,
+ void* data) :
+ ViewModule::SecurityOriginSupportUtil::PermissionData(
+ originDao,
+ originData,
+ data),
+ m_ewkContext(ewkContext)
+ {
+ };
+};
+
bool notificationShow(WebNotificationDataPtr notiData);
bool notificationHide(WebNotificationDataPtr notiData);
bool isExternalUri(const std::string &pattern, const std::string &uri);
bool downloadImage(WebNotificationDataPtr notiData);
size_t curlWriteData(void *ptr, size_t size, size_t nmemb, FILE *stream);
+void askUserForWebNotificationPermission(
+ Evas_Object* window,
+ WebNotificationPermissionData* data);
+static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
WebNotificationData::WebNotificationData(WidgetModel* widgetModel,
uint64_t id) :
{
}
+void webNotificationPermissionRequest(
+ Evas_Object* window,
+ SecurityOriginDAO* securityOriginDAO,
+ Ewk_Context* ewkContext,
+ void* data)
+{
+ LogDebug("permissionRequest called");
+ Assert(securityOriginDAO);
+ Assert(data);
+ Ewk_Notification_Permission_Request* request =
+ static_cast<Ewk_Notification_Permission_Request*>(data);
+ const Ewk_Security_Origin* ewkOrigin =
+ ewk_notification_permission_request_origin_get(request);
+ Assert(ewkOrigin);
+
+ SecurityOriginData securityOriginData(
+ FEATURE_WEB_NOTIFICATION,
+ Origin(
+ DPL::FromUTF8String(ewk_security_origin_protocol_get(ewkOrigin)),
+ DPL::FromUTF8String(ewk_security_origin_host_get(ewkOrigin)),
+ ewk_security_origin_port_get(ewkOrigin)));
+
+ // check cache database
+ Result result = securityOriginDAO->getResult(securityOriginData);
+ if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) {
+ LogDebug("allow");
+ ewk_notification_permission_request_response(ewkContext,
+ request,
+ EINA_TRUE);
+ return;
+ } else if (RESULT_DENY_ONCE == result || RESULT_DENY_ALWAYS == result) {
+ LogDebug("deny");
+ ewk_notification_permission_request_response(ewkContext,
+ request,
+ EINA_FALSE);
+ return;
+ }
+
+ // ask to user
+ WebNotificationPermissionData* permissionData =
+ new WebNotificationPermissionData(securityOriginDAO,
+ securityOriginData,
+ ewkContext,
+ data);
+
+ // suspend notification
+ ewk_notification_permission_request_suspend(request);
+ askUserForWebNotificationPermission(window, permissionData);
+ return;
+}
+
bool showWebNotification(WebNotificationDataPtr notiData)
{
LogInfo("showWebNotification called");
return written;
}
+void askUserForWebNotificationPermission(
+ Evas_Object* window,
+ WebNotificationPermissionData* data)
+{
+ LogDebug("askUserForWebNotificationPermission called");
+ std::string body =
+ WEB_NOTIFICATION_ASK_BODY_PREFIX +
+ DPL::ToUTF8String(data->m_originData.origin.host) +
+ WEB_NOTIFICATION_ASK_BODY_POSTFIX;
+ Evas_Object* popup = createPopup(window,
+ body.c_str(),
+ WEB_NOTIFICATION_ASK_CHECK,
+ popupCallback,
+ data);
+ if (popup == NULL) {
+ LogError("Fail to create popup object");
+ delete data;
+ return;
+ } else {
+ evas_object_show(popup);
+ }
+}
+
+void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
+{
+ LogDebug("popupCallback");
+ Assert(data);
+ WebNotificationPermissionData* permData =
+ static_cast<WebNotificationPermissionData*>(data);
+ Ewk_Notification_Permission_Request* request =
+ static_cast<Ewk_Notification_Permission_Request*>(permData->m_data);
+
+ Evas_Object* popup = getPopup(obj);
+ Result result = getResult(obj);
+
+ if (result != RESULT_UNKNOWN) {
+ permData->m_originDao->setSecurityOriginData(permData->m_originData, result);
+ }
+ Eina_Bool ret =
+ (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ?
+ EINA_TRUE : EINA_FALSE;
+ ewk_notification_permission_request_response(permData->m_ewkContext,
+ request,
+ ret);
+ delete permData;
+ evas_object_hide(popup);
+ evas_object_del(popup);
+}
+
+
} // namespace WebNotification
} //namespace ViewModule