From 8d683a720db6db5bf2647d345e5b7e08049b4f85 Mon Sep 17 00:00:00 2001 From: Tomasz Marciniak Date: Wed, 4 Nov 2015 12:31:11 +0100 Subject: [PATCH] Revert "[Notification] Moved checking privileges to JS layer." This reverts commit 7bd561f1d2119cb7fcc19f89fa536d846dc40e80. This also applies changes from commit bcba48b118a6724da5c96aa155db22fe2fc87df0 [Verification] Code compiles. TCT pass rate 100% Change-Id: Icf6c2d4e348f8bc0f4d0874ae639ccbfce8254c5 Signed-off-by: Tomasz Marciniak --- src/notification/notification_api.js | 30 +++++------------------ src/notification/notification_instance.cc | 13 ++++++++++ src/notification/notification_manager.cc | 8 +++++- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/notification/notification_api.js b/src/notification/notification_api.js index aefbeffa..21bcadf5 100644 --- a/src/notification/notification_api.js +++ b/src/notification/notification_api.js @@ -21,7 +21,6 @@ var type_ = utils_.type; var converter_ = utils_.converter; var validator_ = utils_.validator; var types_ = validator_.Types; -var privilege_ = xwalk.utils.privilege; var native_ = new xwalk.utils.NativeManager(extension); function convertColorToInt(rgbaColor) { @@ -84,8 +83,6 @@ function NotificationManager() {} NotificationManager.prototype.post = function(notification) { - xwalk.utils.checkPrivilegeAccess(privilege_.NOTIFICATION); - var args = validator_.validateArgs(arguments, [ {name: 'notification', type: types_.PLATFORM_OBJECT, values: StatusNotification} ]); @@ -97,7 +94,7 @@ NotificationManager.prototype.post = function(notification) { var result = native_.callSync('NotificationManager_post', data); if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); + throw native_.getErrorObject(result); } _edit.allow(); @@ -109,8 +106,6 @@ NotificationManager.prototype.post = function(notification) { }; NotificationManager.prototype.update = function(notification) { - xwalk.utils.checkPrivilegeAccess(privilege_.NOTIFICATION); - var args = validator_.validateArgs(arguments, [ {name: 'notification', type: types_.PLATFORM_OBJECT, values: StatusNotification} ]); @@ -129,14 +124,11 @@ NotificationManager.prototype.update = function(notification) { var result = native_.callSync('NotificationManager_update', data); if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR, - native_.getErrorObject(result)); + throw native_.getErrorObject(result); } }; NotificationManager.prototype.remove = function(id) { - xwalk.utils.checkPrivilegeAccess(privilege_.NOTIFICATION); - var args = validator_.validateArgs(arguments, [ {name: 'id', type: types_.STRING} ]); @@ -152,19 +144,15 @@ NotificationManager.prototype.remove = function(id) { var result = native_.callSync('NotificationManager_remove', data); if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR, - native_.getErrorObject(result)); + throw native_.getErrorObject(result); } }; NotificationManager.prototype.removeAll = function() { - xwalk.utils.checkPrivilegeAccess(privilege_.NOTIFICATION); - var result = native_.callSync('NotificationManager_removeAll', {}); if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.UNKNOWN_ERR, - native_.getErrorObject(result)); + throw native_.getErrorObject(result); } }; @@ -184,8 +172,7 @@ NotificationManager.prototype.get = function(id) { var result = native_.callSync('NotificationManager_get', data); if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR, - native_.getErrorObject(result)); + throw native_.getErrorObject(result); } var n = native_.getResultObject(result); @@ -201,8 +188,7 @@ NotificationManager.prototype.getAll = function() { var result = native_.callSync('NotificationManager_getAll', {}); if (native_.isFailure(result)) { - throw new WebAPIException(WebAPIException.NOT_FOUND_ERR, - native_.getErrorObject(result)); + throw native_.getErrorObject(result); } var n = native_.getResultObject(result); @@ -226,8 +212,6 @@ NotificationManager.prototype.getAll = function() { * @param flags Array */ NotificationManager.prototype.playLEDCustomEffect = function(timeOn, timeOff, color, flags) { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.LED); - var args = validator_.validateArgs(arguments, [ {name: 'timeOn', type: types_.LONG}, {name: 'timeOff', type: types_.LONG}, @@ -252,8 +236,6 @@ NotificationManager.prototype.playLEDCustomEffect = function(timeOn, timeOff, co * Stops the custom effect of the service LED that is located to the front of a device. */ NotificationManager.prototype.stopLEDCustomEffect = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.LED); - var result = native_.callSync('NotificationManager_stopLEDCustomEffect'); if (native_.isFailure(result)) { throw native_.getErrorObject(result); diff --git a/src/notification/notification_instance.cc b/src/notification/notification_instance.cc index 9505df74..ec92eb59 100644 --- a/src/notification/notification_instance.cc +++ b/src/notification/notification_instance.cc @@ -21,12 +21,19 @@ #include "common/logger.h" #include "common/picojson.h" #include "common/platform_result.h" +#include "common/tools.h" #include "notification/notification_manager.h" namespace extension { namespace notification { +namespace { +// The privileges that required in Notification API +const std::string kPrivilegeNotification = "http://tizen.org/privilege/notification"; +const std::string kPrivilegeLED = "http://tizen.org/privilege/led"; +} // namespace + using namespace common; NotificationInstance::NotificationInstance() { @@ -62,6 +69,7 @@ NotificationInstance::~NotificationInstance() { void NotificationInstance::NotificationManagerPost(const picojson::value& args, picojson::object& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out); LoggerD("Enter"); picojson::value val{picojson::object{}}; @@ -78,6 +86,7 @@ void NotificationInstance::NotificationManagerPost(const picojson::value& args, void NotificationInstance::NotificationManagerUpdate( const picojson::value& args, picojson::object& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out); LoggerD("Enter"); PlatformResult status = manager_->Update(args.get()); @@ -92,6 +101,7 @@ void NotificationInstance::NotificationManagerUpdate( void NotificationInstance::NotificationManagerRemove( const picojson::value& args, picojson::object& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out); LoggerD("Enter"); PlatformResult status = manager_->Remove(args.get()); @@ -106,6 +116,7 @@ void NotificationInstance::NotificationManagerRemove( void NotificationInstance::NotificationManagerRemoveAll( const picojson::value& args, picojson::object& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out); LoggerD("Enter"); PlatformResult status = manager_->RemoveAll(); @@ -151,6 +162,7 @@ void NotificationInstance::NotificationManagerPlayLEDCustomEffect( const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeLED, &out); PlatformResult status = manager_->PlayLEDCustomEffect(args.get()); @@ -165,6 +177,7 @@ void NotificationInstance::NotificationManagerStopLEDCustomEffect( const picojson::value& /*args*/, picojson::object& out) { LoggerD("Enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeLED, &out); PlatformResult status = manager_->StopLEDCustomEffect(); diff --git a/src/notification/notification_manager.cc b/src/notification/notification_manager.cc index 5b59c5a7..d7b56662 100644 --- a/src/notification/notification_manager.cc +++ b/src/notification/notification_manager.cc @@ -95,7 +95,13 @@ PlatformResult NotificationManager::RemoveAll() { PlatformResult NotificationManager::Get(const picojson::object& args, picojson::object& out) { LoggerD("Enter"); - int id = std::stoi(FromJson(args, "id")); + int id; + try { + id = std::stoi(FromJson(args, "id")); + } catch (...) { + LoggerE("Failed to convert string to int"); + return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Failed to convert string to int."); + } app_control_h app_control = nullptr; notification_h noti_handle = nullptr; -- 2.34.1