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