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 {
37 * This method initializes this in the JS Engine.
39 static const JSClassRef getClassRef();
42 * Gets object's class description.
44 static const JSClassDefinition* getClassInfo();
46 static JSObjectRef callAsConstructor(JSContextRef context,
47 JSObjectRef constructor,
49 const JSValueRef arguments[],
50 JSValueRef* exception);
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.
60 static void acquireGlobalContext(java_script_context_t global_context,
61 js_object_instance_t iframe,
62 js_object_instance_t object);
66 * The callback invoked when an object is first created.
68 static void initialize(JSContextRef context,
72 * The callback invoked when an object is finalized.
74 static void finalize(JSObjectRef object);
77 * This structure describes a statically declared value property.
79 static JSStaticValue m_property[];
82 * This structure contains properties and callbacks that define a type of
85 static JSClassDefinition m_classInfo;
87 static JSClassRef m_jsClassRef;
90 * Global context acquired by acquireGlobalContext() function.
92 static JSContextRef m_globalContext;
94 // getters for properties
95 static JSValueRef getAuthor(JSContextRef context,
97 JSStringRef propertyName,
98 JSValueRef* exception);
99 static JSValueRef getAuthorEmail(JSContextRef context,
101 JSStringRef propertyName,
102 JSValueRef* exception);
103 static JSValueRef getAuthorHref(JSContextRef context,
105 JSStringRef propertyName,
106 JSValueRef* exception);
107 static JSValueRef getDescription(JSContextRef context,
109 JSStringRef propertyName,
110 JSValueRef* exception);
111 static JSValueRef getId(JSContextRef context,
113 JSStringRef propertyName,
114 JSValueRef* exception);
115 static JSValueRef getName(JSContextRef context,
117 JSStringRef propertyName,
118 JSValueRef* exception);
119 static JSValueRef getShortName(JSContextRef context,
121 JSStringRef propertyName,
122 JSValueRef* exception);
123 static JSValueRef getVersion(JSContextRef context,
125 JSStringRef propertyName,
126 JSValueRef* exception);
127 static JSValueRef getHeight(JSContextRef context,
129 JSStringRef propertyName,
130 JSValueRef* exception);
131 static JSValueRef getWidth(JSContextRef context,
133 JSStringRef propertyName,
134 JSValueRef* exception);
136 static bool hasProperty(JSContextRef context,
138 JSStringRef propertyName);
140 static JSValueRef getProperty(JSContextRef context,
142 JSStringRef propertyName,
143 JSValueRef* exception);
145 static bool setProperty(JSContextRef context,
147 JSStringRef propertyName,
149 JSValueRef* exception);
154 #endif /* _WRT_PLUGIN_JS_WIDGET_INTERFACE_H_ */