Revert "[Notification] Moved checking privileges to JS layer."
authorTomasz Marciniak <t.marciniak@samsung.com>
Wed, 4 Nov 2015 11:31:11 +0000 (12:31 +0100)
committerTomasz Marciniak <t.marciniak@samsung.com>
Fri, 4 Dec 2015 12:21:17 +0000 (21:21 +0900)
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 <t.marciniak@samsung.com>
src/notification/notification_api.js
src/notification/notification_instance.cc
src/notification/notification_manager.cc

index aefbeffaf1e5b849abeafb5c56c1ef6e64f9b611..21bcadf5dc8c79e1c67f567f0ffe784a02d6f9e3 100644 (file)
@@ -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);
index 9505df74b2a437582d99933f266afbeb248cf174..ec92eb59627c6bf39608371398ffd5ef8143faeb 100644 (file)
 #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<picojson::object>());
@@ -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<picojson::object>());
@@ -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<picojson::object>());
 
@@ -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();
 
index 5b59c5a70351d3b016bd0b65e79e2234c3f4b666..d7b56662ead10bc4a099ad846eb465af996f3164 100644 (file)
@@ -95,7 +95,13 @@ PlatformResult NotificationManager::RemoveAll() {
 PlatformResult NotificationManager::Get(const picojson::object& args,
                                         picojson::object& out) {
   LoggerD("Enter");
-  int id = std::stoi(FromJson<std::string>(args, "id"));
+  int id;
+  try {
+    id = std::stoi(FromJson<std::string>(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;