tizen beta release
[platform/framework/web/wrt-plugins-common.git] / src / CommonsJavaScript / SecurityExceptions.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_SECURITYEXCEPTIONS_H_
18 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_SECURITYEXCEPTIONS_H_
19
20 #include <JavaScriptCore/JavaScript.h>
21 #include "JSDOMExceptionFactory.h"
22
23 namespace WrtDeviceApis {
24 namespace CommonsJavaScript {
25
26 /**
27  * synchronously checks access status and throws JS Security exception if
28  * necessary
29  */
30 #define SYNC_ACCESS_STATUS_HANDLER(status, context, exception)                 \
31     do {                                                                       \
32         switch (status)                                                        \
33         {                                                                      \
34         case AceSecurityStatus::InternalError:                                 \
35             return JSDOMExceptionFactory::UnknownException.make(                  \
36                        context, exception);                                    \
37             break;                                                             \
38                                                                                \
39         case AceSecurityStatus::AccessDenied:                                  \
40             return JSDOMExceptionFactory::SecurityException.make(                 \
41                        context, exception);                                    \
42             break;                                                             \
43                                                                                \
44         default:                                                               \
45             break;                                                             \
46         } \
47     } while (0)
48
49 /**
50  * checks access status and returns an error through JSCallbackManager if
51  * necessary
52  */
53 #define ASYNC_CBM_ACCESS_STATUS_HANDLER(status, context, cbm)                  \
54     do {                                                                       \
55         switch (status)                                                        \
56         {                                                                      \
57         case AceSecurityStatus::InternalError:                                 \
58             cbm->callOnError(JSDOMExceptionFactory::UnknownException.make(        \
59                                  context));                                    \
60             return JSValueMakeNull(context);                                   \
61                                                                                \
62         case AceSecurityStatus::AccessDenied:                                  \
63             cbm->callOnError(JSDOMExceptionFactory::SecurityException.make(       \
64                                  context));                                    \
65             return JSValueMakeNull(context);                                   \
66                                                                                \
67         default:                                                               \
68             break;                                                             \
69         }                                                                      \
70     } while (0)
71
72 }
73 }
74 #endif /*WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_SECURITYEXCEPTIONS_H_ */
75