From: Pawel Andruszkiewicz Date: Thu, 19 Mar 2015 10:20:50 +0000 (+0100) Subject: [Common] Added mechanism to check privileges from JS code. X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~275 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b740db8fc58249d869c8b936694e015563e83d4;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Added mechanism to check privileges from JS code. Change-Id: I520da2250db9606f62c851cd6d8067bfba2d354e --- diff --git a/src/utils/utils.gyp b/src/utils/utils.gyp index cb3480f2..0a79b49b 100644 --- a/src/utils/utils.gyp +++ b/src/utils/utils.gyp @@ -10,6 +10,8 @@ 'utils_api.js', 'utils_extension.cc', 'utils_extension.h', + 'utils_instance.cc', + 'utils_instance.h', ], }, ], diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js index 6f3efe81..b3b811d6 100644 --- a/src/utils/utils_api.js +++ b/src/utils/utils_api.js @@ -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(); diff --git a/src/utils/utils_extension.cc b/src/utils/utils_extension.cc index d62345e3..5f9f5ff9 100644 --- a/src/utils/utils_extension.cc +++ b/src/utils/utils_extension.cc @@ -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(); +} diff --git a/src/utils/utils_extension.h b/src/utils/utils_extension.h index 484e4bf2..8504e586 100644 --- a/src/utils/utils_extension.h +++ b/src/utils/utils_extension.h @@ -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 index 00000000..858bf3fe --- /dev/null +++ b/src/utils/utils_instance.cc @@ -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 index 00000000..c08332cc --- /dev/null +++ b/src/utils/utils_instance.h @@ -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_