2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
24 #ifndef _WRT_PLUGIN_JS_WIDGET_H_
25 #define _WRT_PLUGIN_JS_WIDGET_H_
27 #include <JavaScriptCore/JavaScript.h>
28 #include <CommonsJavaScript/PrivateObject.h>
29 #include <wrt_plugin_export.h>
31 namespace WrtPlugins {
39 * This method initializes this in the JS Engine.
41 static const JSClassRef getClassRef();
44 * Gets object's class description.
46 static const JSClassDefinition* getClassInfo();
48 static JSObjectRef callAsConstructor(JSContextRef context,
49 JSObjectRef constructor,
51 const JSValueRef arguments[],
52 JSValueRef* exception);
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.
62 static void acquireGlobalContext(java_script_context_t global_context,
63 js_object_instance_t iframe,
64 js_object_instance_t object);
68 * The callback invoked when an object is first created.
70 static void initialize(JSContextRef context,
74 * The callback invoked when an object is finalized.
76 static void finalize(JSObjectRef object);
79 * This structure describes a statically declared value property.
81 static JSStaticValue m_property[];
84 * This structure contains properties and callbacks that define a type of object.
86 static JSClassDefinition m_classInfo;
88 static JSClassRef m_jsClassRef;
91 * Global context acquired by acquireGlobalContext() function.
93 static JSContextRef m_globalContext;
95 // getters for properties
96 static JSValueRef getAuthor(JSContextRef context,
98 JSStringRef propertyName,
99 JSValueRef* exception);
100 static JSValueRef getAuthorEmail(JSContextRef context,
102 JSStringRef propertyName,
103 JSValueRef* exception);
104 static JSValueRef getAuthorHref(JSContextRef context,
106 JSStringRef propertyName,
107 JSValueRef* exception);
108 static JSValueRef getDescription(JSContextRef context,
110 JSStringRef propertyName,
111 JSValueRef* exception);
112 static JSValueRef getId(JSContextRef context,
114 JSStringRef propertyName,
115 JSValueRef* exception);
116 static JSValueRef getName(JSContextRef context,
118 JSStringRef propertyName,
119 JSValueRef* exception);
120 static JSValueRef getShortName(JSContextRef context,
122 JSStringRef propertyName,
123 JSValueRef* exception);
124 static JSValueRef getVersion(JSContextRef context,
126 JSStringRef propertyName,
127 JSValueRef* exception);
128 static JSValueRef getHeight(JSContextRef context,
130 JSStringRef propertyName,
131 JSValueRef* exception);
132 static JSValueRef getWidth(JSContextRef context,
134 JSStringRef propertyName,
135 JSValueRef* exception);
137 static bool hasProperty(JSContextRef context,
139 JSStringRef propertyName);
141 static JSValueRef getProperty(JSContextRef context,
143 JSStringRef propertyName,
144 JSValueRef* exception);
146 static bool setProperty(JSContextRef context,
148 JSStringRef propertyName,
150 JSValueRef* exception);
156 #endif /* _WRT_PLUGIN_JS_WIDGET_INTERFACE_H_ */