Revert "[Push] Privilege checks moved to JS layer"
authorTomasz Marciniak <t.marciniak@samsung.com>
Wed, 4 Nov 2015 11:53:51 +0000 (12:53 +0100)
committerHyunJin Park <hj.na.park@samsung.com>
Wed, 9 Dec 2015 06:16:53 +0000 (15:16 +0900)
This reverts commit ad01927f6992eb1f5866ce0b015de19e74ab4c1a.

[Verification] Code compiles. TCT pass rate 100%

Change-Id: Ia6145e6a5e257e0a0061995b630c061563aa5656
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/push/push_api.js
src/push/push_instance.cc

index 09de6fc..93fc048 100644 (file)
@@ -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);
index ab7c093..6836b8c 100644 (file)
 #include <string>
 #include <vector>
 #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<std::string>();
     if (args.get("uri").is<std::string>()) {
@@ -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<double>());
     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()) {