summaryrefslogtreecommitdiff
path: root/mobile_src/Common/Security.h
diff options
context:
space:
mode:
Diffstat (limited to 'mobile_src/Common/Security.h')
-rw-r--r--mobile_src/Common/Security.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/mobile_src/Common/Security.h b/mobile_src/Common/Security.h
new file mode 100644
index 0000000..23aca61
--- /dev/null
+++ b/mobile_src/Common/Security.h
@@ -0,0 +1,121 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef __TIZEN_COMMON_SECURITY_H__
+#define __TIZEN_COMMON_SECURITY_H__
+
+#include <Commons/FunctionDeclaration.h>
+#include "SecurityAccessor.h"
+#include "JSTizenSecurityObject.h"
+#include "JSWebAPIErrorFactory.h"
+
+#define DEFINE_GLOBAL_SECURITY_ACCESSOR(Variable_Name) \
+ DeviceAPI::Common::SecurityAccessor* Variable_Name = NULL
+
+#define INITAILIZE_GLOBAL_SECURITY_ACCESSOR(Variable_Name, AceCheckAccessFunction_Name) \
+ do { \
+ Variable_Name = new DeviceAPI::Common::SecurityAccessor(&AceCheckAccessFunction_Name); \
+ } while(0)
+
+#define FINALIZE_GLOBAL_SECURITY_ACCESSOR(Variable_Name) \
+ do { \
+ if(Variable_Name) { \
+ delete Variable_Name; \
+ Variable_Name = NULL; \
+ } \
+ } while(0)
+
+#define DEFINE_JSOBJECT_SECURITY_ACCESSOR_SETTER(Function_Name, SecurityAccessor_Object) \
+ void Function_Name(java_script_context_t ctx, \
+ js_object_instance_t, \
+ js_object_instance_t obj) \
+ { \
+ DeviceAPI::Common::JSObjectSetSecurityAccessor(static_cast<JSContextRef>(ctx), \
+ static_cast<JSObjectRef>(obj), SecurityAccessor_Object); \
+ }
+
+#define DEFINE_SECURITY_ACCESSOR_SETTER(Function_Name, PrivObjectType, SecurityAccessor_Object) \
+ void Function_Name(java_script_context_t, \
+ js_object_instance_t, \
+ js_object_instance_t object) \
+ { \
+ PrivObjectType* priv = \
+ static_cast<PrivObjectType*>(JSObjectGetPrivate(static_cast<JSObjectRef>(object))); \
+ DeviceAPI::Common::SecurityAccessor* accessor = \
+ static_cast<DeviceAPI::Common::SecurityAccessor*>(priv); \
+ accessor->copyAceCheckAccessFunction(SecurityAccessor_Object); \
+ }
+
+
+#define TIZEN_CHECK_ACCESS(context, exception, privateObject, functionName) \
+ do { \
+ using namespace WrtDeviceApis::Commons; \
+ DeviceAPI::Common::SecurityAccessor* accessor = \
+ static_cast<DeviceAPI::Common::SecurityAccessor*>(privateObject); \
+ if(accessor->isInitialized() == false) { \
+ return JSWebAPIErrorFactory::postException(context, exception, \
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal security error"); \
+ } \
+ AceSecurityStatus status = accessor->invokeAceCheckAccessFunction(functionName); \
+ switch (status) { \
+ case AceSecurityStatus::InternalError: \
+ return JSWebAPIErrorFactory::postException(context, exception, \
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error"); \
+ break; \
+ case AceSecurityStatus::PrivacyDenied: \
+ return JSWebAPIErrorFactory::postException(context, exception, \
+ JSWebAPIErrorFactory::SECURITY_ERROR, "The user blocks an application from calling this method."); \
+ break; \
+ case AceSecurityStatus::AccessDenied: \
+ return JSWebAPIErrorFactory::postException(context, exception, \
+ JSWebAPIErrorFactory::SECURITY_ERROR, "The application does not have the privilege to call this method."); \
+ break; \
+ default: \
+ break; \
+ } \
+ } while(0)
+
+#define TIZEN_ASYNC_CBM_ACCESS(context, privateObject, cbm, functionName) \
+ do { \
+ using namespace WrtDeviceApis::Commons; \
+ DeviceAPI::Common::SecurityAccessor* accessor = \
+ static_cast<DeviceAPI::Common::SecurityAccessor*>(privateObject); \
+ if(accessor->isInitialized() == false) { \
+ cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, \
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal security error")); \
+ return JSValueMakeNull(context); \
+ } \
+ AceSecurityStatus status = accessor->invokeAceCheckAccessFunction(functionName); \
+ switch (status) { \
+ case AceSecurityStatus::InternalError: \
+ cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, \
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error")); \
+ return JSValueMakeNull(context); \
+ case AceSecurityStatus::PrivacyDenied: \
+ cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, \
+ JSWebAPIErrorFactory::SECURITY_ERROR, "The user blocks an application from calling this method.")); \
+ return JSValueMakeNull(context); \
+ case AceSecurityStatus::AccessDenied: \
+ cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, \
+ JSWebAPIErrorFactory::SECURITY_ERROR, "The application does not have the privilege to call this method.")); \
+ return JSValueMakeNull(context); \
+ default: \
+ break; \
+ } \
+ } while (0)
+
+#endif // __TIZEN_COMMON_SECURITY_H__