Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / 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  * synchronously checks access status and throws JS Security exception if
27  * necessary
28  */
29 #define SYNC_ACCESS_STATUS_HANDLER(status, context, exception)                 \
30     do {                                                                       \
31         switch (status)                                                        \
32         {                                                                      \
33         case AceSecurityStatus::InternalError:                                 \
34             return JSDOMExceptionFactory::UnknownException.make(                  \
35                        context, exception);                                    \
36             break;                                                             \
37                                                                                \
38         case AceSecurityStatus::AccessDenied:                                  \
39             return JSDOMExceptionFactory::SecurityException.make(                 \
40                        context, exception);                                    \
41             break;                                                             \
42                                                                                \
43         default:                                                               \
44             break;                                                             \
45         } \
46     } while (0)
47
48 /**
49  * checks access status and returns an error through JSCallbackManager if
50  * necessary
51  */
52 #define ASYNC_CBM_ACCESS_STATUS_HANDLER(status, context, cbm)                  \
53     do {                                                                       \
54         switch (status)                                                        \
55         {                                                                      \
56         case AceSecurityStatus::InternalError:                                 \
57             cbm->callOnError(JSDOMExceptionFactory::UnknownException.make(        \
58                                  context));                                    \
59             return JSValueMakeNull(context);                                   \
60                                                                                \
61         case AceSecurityStatus::AccessDenied:                                  \
62             cbm->callOnError(JSDOMExceptionFactory::SecurityException.make(       \
63                                  context));                                    \
64             return JSValueMakeNull(context);                                   \
65                                                                                \
66         default:                                                               \
67             break;                                                             \
68         }                                                                      \
69     } while (0)
70 }
71 }
72 #endif /*WRTDEVICEAPIS_COMMONSJAVASCRIPT_JS_SECURITYEXCEPTIONS_H_ */
73