[Badge] Privilege checks moved to JS.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 30 Apr 2015 11:49:35 +0000 (13:49 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 4 May 2015 07:57:33 +0000 (16:57 +0900)
Privileges need to be check before validation of arguments.

Change-Id: Ib3d7d5fa7ae6c4af3275b58cbaefd5c670cdc7c3
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/badge/badge_api.js
src/badge/badge_instance.cc

index c154ce6..a8b2b14 100644 (file)
@@ -46,6 +46,8 @@ function BadgeManager() {
  * Sets the badge count for the designated application.
  */
 BadgeManager.prototype.setBadgeCount = function() {
+  xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.NOTIFICATION);
+
   if (arguments.length < 2)
     throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
         'incorrect number of arguments');
@@ -75,6 +77,8 @@ BadgeManager.prototype.setBadgeCount = function() {
  * @return {number} long Count of the badge
  */
 BadgeManager.prototype.getBadgeCount = function() {
+  xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.NOTIFICATION);
+
   if (arguments.length < 1)
     throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR,
                                     'incorrect number of arguments');
@@ -98,6 +102,8 @@ BadgeManager.prototype.getBadgeCount = function() {
  * Gets the badge count for the designated application.
  */
 BadgeManager.prototype.addChangeListener = function() {
+  xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.NOTIFICATION);
+
   if (arguments.length < 2)
     throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
         'incorrect number of arguments');
@@ -140,6 +146,8 @@ BadgeManager.prototype.addChangeListener = function() {
  * Gets the badge count for the designated application.
  */
 BadgeManager.prototype.removeChangeListener = function() {
+  xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.NOTIFICATION);
+
   if (arguments.length < 1)
     throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
                                     'incorrect number of arguments');
index 25bab58..725fbba 100644 (file)
@@ -9,12 +9,6 @@
 namespace extension {
 namespace badge {
 
-namespace {
-// The privileges that required in Badge API
-const std::string kPrivilegeNotification = "http://tizen.org/privilege/notification";
-
-}  // namespace
-
 using namespace common;
 using namespace extension::badge;
 
@@ -37,7 +31,6 @@ BadgeInstance::~BadgeInstance() {}
 
 void BadgeInstance::BadgeManagerSetBadgeCount(const JsonValue& args,
                                               JsonObject& out) {
-  CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
   std::string app_id =
       common::FromJson<std::string>(args.get<JsonObject>(), "appId");
   const double count = args.get("count").get<double>();
@@ -52,7 +45,6 @@ void BadgeInstance::BadgeManagerSetBadgeCount(const JsonValue& args,
 
 void BadgeInstance::BadgeManagerGetBadgeCount(const JsonValue& args,
                                               JsonObject& out) {
-  CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
   std::string app_id =
       common::FromJson<std::string>(args.get<JsonObject>(), "appId");
 
@@ -67,7 +59,6 @@ void BadgeInstance::BadgeManagerGetBadgeCount(const JsonValue& args,
 
 void BadgeInstance::BadgeManagerAddChangeListener(const JsonValue& args,
                                                   JsonObject& out) {
-  CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
   PlatformResult status =
       manager_.AddChangeListener(args.get<JsonObject>());
 
@@ -79,7 +70,6 @@ void BadgeInstance::BadgeManagerAddChangeListener(const JsonValue& args,
 
 void BadgeInstance::BadgeManagerRemoveChangeListener(const JsonValue& args,
                                                      JsonObject& out) {
-  CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
   PlatformResult status =
       manager_.RemoveChangeListener(args.get<JsonObject>());