From 79f9cd1dbe17c7cf66c77c8969dd2cf0f02e8c02 Mon Sep 17 00:00:00 2001 From: Tomasz Marciniak Date: Wed, 4 Nov 2015 12:53:51 +0100 Subject: [PATCH] Revert "[Push] Privilege checks moved to JS layer" This reverts commit ad01927f6992eb1f5866ce0b015de19e74ab4c1a. [Verification] Code compiles. TCT pass rate 100% Change-Id: Ia6145e6a5e257e0a0061995b630c061563aa5656 Signed-off-by: Tomasz Marciniak --- src/push/push_api.js | 14 ++++++-------- src/push/push_instance.cc | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/push/push_api.js b/src/push/push_api.js index 09de6fc7..93fc048a 100644 --- a/src/push/push_api.js +++ b/src/push/push_api.js @@ -17,7 +17,7 @@ var native = new xwalk.utils.NativeManager(extension); var validator = xwalk.utils.validator; var validatorType = xwalk.utils.type; -var Privilege = xwalk.utils.privilege; + /** * @const @@ -49,7 +49,6 @@ function PushManager() { } PushManager.prototype.registerService = function(appControl, successCallback, errorCallback) { - xwalk.utils.checkPrivilegeAccess(Privilege.PUSH); var data = validator.validateArgs(arguments, [ { name: 'appControl', @@ -88,7 +87,6 @@ PushManager.prototype.registerService = function(appControl, successCallback, er }; PushManager.prototype.unregisterService = function(successCallback, errorCallback) { - xwalk.utils.checkPrivilegeAccess(Privilege.PUSH); var data = validator.validateArgs(arguments, [ { name: 'successCallback', @@ -103,7 +101,7 @@ PushManager.prototype.unregisterService = function(successCallback, errorCallbac nullable: true } ]); - native.call('Push_unregisterService', {}, function(msg) { + var result = native.call('Push_unregisterService', {}, function(msg) { if (msg.error) { if (validatorType.isFunction(data.errorCallback)) { data.errorCallback(native.getErrorObject(msg)); @@ -112,10 +110,13 @@ PushManager.prototype.unregisterService = function(successCallback, errorCallbac data.successCallback(); } }); + + if (native.isFailure(result)) { + throw native.getErrorObject(result); + } }; PushManager.prototype.connectService = function(notificationCallback) { - xwalk.utils.checkPrivilegeAccess(Privilege.PUSH); var data = validator.validateArgs(arguments, [ { name: 'notificationCallback', @@ -132,7 +133,6 @@ PushManager.prototype.connectService = function(notificationCallback) { }; PushManager.prototype.disconnectService = function() { - xwalk.utils.checkPrivilegeAccess(Privilege.PUSH); var ret = native.callSync('Push_disconnectService', {}); if (native.isFailure(ret)) { throw native.getErrorObject(ret); @@ -141,7 +141,6 @@ PushManager.prototype.disconnectService = function() { }; PushManager.prototype.getRegistrationId = function() { - xwalk.utils.checkPrivilegeAccess(Privilege.PUSH); var ret = native.callSync('Push_getRegistrationId', {}); if (native.isFailure(ret)) { throw native.getErrorObject(ret); @@ -150,7 +149,6 @@ PushManager.prototype.getRegistrationId = function() { }; PushManager.prototype.getUnreadNotifications = function() { - xwalk.utils.checkPrivilegeAccess(Privilege.PUSH); var ret = native.callSync('Push_getUnreadNotifications', {}); if (native.isFailure(ret)) { throw native.getErrorObject(ret); diff --git a/src/push/push_instance.cc b/src/push/push_instance.cc index ab7c0938..6836b8cd 100644 --- a/src/push/push_instance.cc +++ b/src/push/push_instance.cc @@ -18,11 +18,18 @@ #include #include #include "common/logger.h" +#include "common/tools.h" #include "push/push_manager.h" namespace extension { namespace push { +namespace { + +const std::string kPrivilegePush = "http://tizen.org/privilege/push"; + +} // namespace + PushInstance::PushInstance(): m_ignoreNotificationEvents(true) { LoggerD("Enter"); using std::placeholders::_1; @@ -55,6 +62,8 @@ void PushInstance::registerService(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); + PushManager::ApplicationControl appControl; appControl.operation = args.get("operation").get(); if (args.get("uri").is()) { @@ -93,6 +102,8 @@ void PushInstance::unregisterService(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); + common::PlatformResult result = PushManager::getInstance() .unregisterService(args.get("callbackId").get()); if (result.IsError()) { @@ -107,6 +118,8 @@ void PushInstance::connectService(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); + m_ignoreNotificationEvents = false; picojson::value result; ReportSuccess(result, out); @@ -116,6 +129,8 @@ void PushInstance::disconnectService(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); + m_ignoreNotificationEvents = true; picojson::value result; ReportSuccess(result, out); @@ -125,6 +140,8 @@ void PushInstance::getRegistrationId(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); + std::string id; common::PlatformResult result = PushManager::getInstance() .getRegistrationId(id); @@ -142,6 +159,8 @@ void PushInstance::getUnreadNotifications(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out); + common::PlatformResult result = PushManager::getInstance() .getUnreadNotifications(); if (result.IsError()) { -- 2.34.1