[Common] Added mechanism to check privileges from JS code.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 19 Mar 2015 10:20:50 +0000 (11:20 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 19 Mar 2015 10:20:50 +0000 (11:20 +0100)
Change-Id: I520da2250db9606f62c851cd6d8067bfba2d354e

src/utils/utils.gyp
src/utils/utils_api.js
src/utils/utils_extension.cc
src/utils/utils_extension.h
src/utils/utils_instance.cc [new file with mode: 0644]
src/utils/utils_instance.h [new file with mode: 0644]

index cb3480f2b3aee8dad23099e1dff55e892d0b9970..0a79b49bb56b1a29d27424cef179daee8f1d4f9c 100644 (file)
@@ -10,6 +10,8 @@
         'utils_api.js',
         'utils_extension.cc',
         'utils_extension.h',
+        'utils_instance.cc',
+        'utils_instance.h',
       ],
     },
   ],
index 6f3efe81eeee3886ebe1284759b7fe8749a348d3..b3b811d61fd7569ba2bcd70d18198430a84fb7e1 100644 (file)
@@ -136,7 +136,15 @@ Utils.prototype.validateObject = function(object, signature, attributes) {
   return true;
 };
 
+Utils.prototype.checkPrivilegeAccess = function(privilege) {
+  var result = native_.callSync('Utils_checkPrivilegeAccess', {
+    privilege : _toString(privilege),
+  });
 
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
 
 /////////////////////////////////////////////////////////////////////////////
 /** @constructor */
@@ -1350,4 +1358,6 @@ Utils.prototype.validator = _validator;
 Utils.prototype.NativeManager = NativeManager;
 Utils.prototype.NativeBridge = NativeBridge;
 
+var native_ = new NativeManager(extension);
+
 exports = new Utils();
index d62345e3ac4d8c533de23fafe6e9f46df67a5370..5f9f5ff99ed611116c74f8cf83bdb3bc96cf82c7 100644 (file)
@@ -3,6 +3,7 @@
 // found in the LICENSE file.
 
 #include "utils/utils_extension.h"
+#include "utils/utils_instance.h"
 
 // This will be generated from tizen_api.js.
 extern const char kSource_utils_api[];
@@ -17,3 +18,7 @@ UtilsExtension::UtilsExtension() {
 }
 
 UtilsExtension::~UtilsExtension() {}
+
+common::Instance* UtilsExtension::CreateInstance() {
+  return new extension::utils::UtilsInstance();
+}
index 484e4bf26ee60b6cc40bec038518d44d6feef75b..8504e5866553f45031a545bee57fb6b59636d932 100644 (file)
@@ -11,6 +11,9 @@ class UtilsExtension : public common::Extension {
  public:
   UtilsExtension();
   virtual ~UtilsExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
 };
 
 #endif  // UTILS_UTILS_EXTENSION_H_
diff --git a/src/utils/utils_instance.cc b/src/utils/utils_instance.cc
new file mode 100644 (file)
index 0000000..858bf3f
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "utils/utils_instance.h"
+
+namespace extension {
+namespace utils {
+
+UtilsInstance::UtilsInstance() {
+  using std::placeholders::_1;
+  using std::placeholders::_2;
+
+#define REGISTER_SYNC(c, x) \
+  RegisterSyncHandler(c, std::bind(&UtilsInstance::x, this, _1, _2));
+#define REGISTER_ASYNC(c, x) \
+  RegisterSyncHandler(c, std::bind(&UtilsInstance::x, this, _1, _2));
+
+  REGISTER_SYNC("Utils_checkPrivilegeAccess", CheckPrivilegeAccess);
+
+#undef REGISTER_SYNC
+#undef REGISTER_ASYNC
+}
+
+void UtilsInstance::CheckPrivilegeAccess(const picojson::value& args, picojson::object& out) {
+  const auto& privilege = args.get("privilege").to_str();
+  CHECK_PRIVILEGE_ACCESS(privilege, &out);
+  ReportSuccess(out);
+}
+
+}  // namespace utils
+}  // namespace extension
diff --git a/src/utils/utils_instance.h b/src/utils/utils_instance.h
new file mode 100644 (file)
index 0000000..c08332c
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UTILS_UTILS_INSTANCE_H_
+#define UTILS_UTILS_INSTANCE_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace utils {
+
+class UtilsInstance : public common::ParsedInstance {
+ public:
+  UtilsInstance();
+  virtual ~UtilsInstance() {}
+
+ private:
+  void CheckPrivilegeAccess(const picojson::value& args, picojson::object& out);
+};
+}  // namespace utils
+}  // namespace extension
+
+#endif  // UTILS_UTILS_INSTANCE_H_