Source code formating unification
[platform/framework/web/wrt-plugins-common.git] / src / standards / W3C / Widget / JSWidget.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  *
18  * @file       JSWidget.h
19  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23
24 #ifndef _WRT_PLUGIN_JS_WIDGET_H_
25 #define _WRT_PLUGIN_JS_WIDGET_H_
26
27 #include <JavaScriptCore/JavaScript.h>
28 #include <CommonsJavaScript/PrivateObject.h>
29 #include <wrt_plugin_export.h>
30
31 namespace WrtPlugins {
32 namespace W3C {
33 class JSWidget
34 {
35   public:
36     /**
37      * This method initializes this in the JS Engine.
38      */
39     static const JSClassRef getClassRef();
40
41     /**
42      * Gets object's class description.
43      */
44     static const JSClassDefinition* getClassInfo();
45
46     static JSObjectRef callAsConstructor(JSContextRef context,
47                                          JSObjectRef constructor,
48                                          size_t argumentCount,
49                                          const JSValueRef arguments[],
50                                          JSValueRef* exception);
51
52     /**
53      * This function will acquire global context which is used later to
54      * keep JSValueProtect/Unprotect functionality working.
55      * This is workaround for JSCore semantic: when an object is created with
56      * JSObjectMakeConstructor a context passed to createCallback function
57      * is different (shorter lifecycle) than global context, so JSValueUnprotect
58      * called in finalize may fail because of invalid context.
59      */
60     static void acquireGlobalContext(java_script_context_t global_context,
61                                      js_object_instance_t iframe,
62                                      js_object_instance_t object);
63
64   private:
65     /**
66      * The callback invoked when an object is first created.
67      */
68     static void initialize(JSContextRef context,
69                            JSObjectRef object);
70
71     /**
72      * The callback invoked when an object is finalized.
73      */
74     static void finalize(JSObjectRef object);
75
76     /**
77      * This structure describes a statically declared value property.
78      */
79     static JSStaticValue m_property[];
80
81     /**
82      * This structure contains properties and callbacks that define a type of
83      * object.
84      */
85     static JSClassDefinition m_classInfo;
86
87     static JSClassRef m_jsClassRef;
88
89     /**
90      * Global context acquired by acquireGlobalContext() function.
91      */
92     static JSContextRef m_globalContext;
93
94     // getters for properties
95     static JSValueRef getAuthor(JSContextRef context,
96                                 JSObjectRef object,
97                                 JSStringRef propertyName,
98                                 JSValueRef* exception);
99     static JSValueRef getAuthorEmail(JSContextRef context,
100                                      JSObjectRef object,
101                                      JSStringRef propertyName,
102                                      JSValueRef* exception);
103     static JSValueRef getAuthorHref(JSContextRef context,
104                                     JSObjectRef object,
105                                     JSStringRef propertyName,
106                                     JSValueRef* exception);
107     static JSValueRef getDescription(JSContextRef context,
108                                      JSObjectRef object,
109                                      JSStringRef propertyName,
110                                      JSValueRef* exception);
111     static JSValueRef getId(JSContextRef context,
112                             JSObjectRef object,
113                             JSStringRef propertyName,
114                             JSValueRef* exception);
115     static JSValueRef getName(JSContextRef context,
116                               JSObjectRef object,
117                               JSStringRef propertyName,
118                               JSValueRef* exception);
119     static JSValueRef getShortName(JSContextRef context,
120                                    JSObjectRef object,
121                                    JSStringRef propertyName,
122                                    JSValueRef* exception);
123     static JSValueRef getVersion(JSContextRef context,
124                                  JSObjectRef object,
125                                  JSStringRef propertyName,
126                                  JSValueRef* exception);
127     static JSValueRef getHeight(JSContextRef context,
128                                 JSObjectRef object,
129                                 JSStringRef propertyName,
130                                 JSValueRef* exception);
131     static JSValueRef getWidth(JSContextRef context,
132                                JSObjectRef object,
133                                JSStringRef propertyName,
134                                JSValueRef* exception);
135
136     static bool hasProperty(JSContextRef context,
137                             JSObjectRef object,
138                             JSStringRef propertyName);
139
140     static JSValueRef getProperty(JSContextRef context,
141                                   JSObjectRef object,
142                                   JSStringRef propertyName,
143                                   JSValueRef* exception);
144
145     static bool setProperty(JSContextRef context,
146                             JSObjectRef object,
147                             JSStringRef propertyName,
148                             JSValueRef value,
149                             JSValueRef* exception);
150 };
151 }
152 }
153
154 #endif /* _WRT_PLUGIN_JS_WIDGET_INTERFACE_H_ */