source: trunk/icedtea-web/plugin/icedteanp/IcedTeaScriptablePluginObject.h@ 429

Last change on this file since 429 was 429, checked in by dmik, 11 years ago

icedtea-web: Merge version 1.5.1 from vendor to trunk.

File size: 7.5 KB
Line 
1/* IcedTeaScriptablePluginObject.h
2
3 Copyright (C) 2009, 2010 Red Hat
4
5This file is part of IcedTea.
6
7IcedTea is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12IcedTea is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with IcedTea; see the file COPYING. If not, write to the
19Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2002110-1301 USA.
21
22Linking this library statically or dynamically with other modules is
23making a combined work based on this library. Thus, the terms and
24conditions of the GNU General Public License cover the whole
25combination.
26
27As a special exception, the copyright holders of this library give you
28permission to link this library with independent modules to produce an
29executable, regardless of the license terms of these independent
30modules, and to copy and distribute the resulting executable under
31terms of your choice, provided that you also meet, for each linked
32independent module, the terms and conditions of the license of that
33module. An independent module is a module which is not derived from
34or based on this library. If you modify this library, you may extend
35this exception to your version of the library, but you are not
36obligated to do so. If you do not wish to do so, delete this
37exception statement from your version. */
38
39#ifndef __ICEDTEASCRIPTABLEPLUGINOBJECT_H_
40#define __ICEDTEASCRIPTABLEPLUGINOBJECT_H_
41
42#include <npapi.h>
43#include <npruntime.h>
44
45#include "IcedTeaJavaRequestProcessor.h"
46#include "IcedTeaNPPlugin.h"
47
48/**
49 * IcedTeaScriptablePluginObject, an extended NPObject that implements
50 * static functions whose pointers are supplied to NPClass.
51 */
52
53class IcedTeaScriptablePluginObject: public NPObject
54{
55
56 private:
57 NPP instance;
58
59 public:
60 IcedTeaScriptablePluginObject(NPP instance);
61
62 static void deAllocate(NPObject *npobj);
63
64 static void invalidate(NPObject *npobj);
65
66 static bool hasMethod(NPObject *npobj, NPIdentifier name_id);
67
68 static bool invoke(NPObject *npobj, NPIdentifier name_id,
69 const NPVariant *args, uint32_t argCount, NPVariant *result);
70
71 static bool invokeDefault(NPObject *npobj, const NPVariant *args,
72 uint32_t argCount, NPVariant *result);
73
74 static bool hasProperty(NPObject *npobj, NPIdentifier name_id);
75
76 static bool getProperty(NPObject *npobj, NPIdentifier name_id,
77 NPVariant *result);
78
79 static bool setProperty(NPObject *npobj, NPIdentifier name_id,
80 const NPVariant *value);
81
82 static bool removeProperty(NPObject *npobj, NPIdentifier name_id);
83
84 static bool enumerate(NPObject *npobj, NPIdentifier **value,
85 uint32_t *count);
86
87 static bool construct(NPObject *npobj, const NPVariant *args,
88 uint32_t argCount, NPVariant *result);
89
90};
91
92NPObject* allocate_scriptable_jp_object(NPP npp, NPClass *aClass);
93
94class IcedTeaScriptableJavaPackageObject: public NPObject
95{
96
97 private:
98 NPP instance;
99 std::string* package_name;
100
101 public:
102 IcedTeaScriptableJavaPackageObject(NPP instance);
103
104 ~IcedTeaScriptableJavaPackageObject();
105
106 void setPackageName(const NPUTF8* name);
107
108 std::string getPackageName();
109
110 static void deAllocate(NPObject *npobj);
111
112 static void invalidate(NPObject *npobj);
113
114 static bool hasMethod(NPObject *npobj, NPIdentifier name_id);
115
116 static bool invoke(NPObject *npobj, NPIdentifier name_id,
117 const NPVariant *args, uint32_t argCount, NPVariant *result);
118
119 static bool invokeDefault(NPObject *npobj, const NPVariant *args,
120 uint32_t argCount, NPVariant *result);
121
122 static bool hasProperty(NPObject *npobj, NPIdentifier name_id);
123
124 static bool getProperty(NPObject *npobj, NPIdentifier name_id,
125 NPVariant *result);
126
127 static bool setProperty(NPObject *npobj, NPIdentifier name_id,
128 const NPVariant *value);
129
130 static bool removeProperty(NPObject *npobj, NPIdentifier name_id);
131
132 static bool enumerate(NPObject *npobj, NPIdentifier **value,
133 uint32_t *count);
134
135 static bool construct(NPObject *npobj, const NPVariant *args,
136 uint32_t argCount, NPVariant *result);
137
138 static NPObject* get_scriptable_java_package_object(NPP instance, const NPUTF8* name);
139
140 static bool is_valid_java_object(NPObject* object_ptr);
141};
142
143class IcedTeaScriptableJavaObject: public NPObject
144{
145private:
146 NPP instance;
147 bool is_object_array;
148 /* These may be empty if 'is_applet_instance' is true
149 * and the object has not yet been used */
150 std::string class_id, instance_id;
151public:
152 IcedTeaScriptableJavaObject(NPP instance) {
153 this->instance = instance;
154 is_object_array = false;
155 }
156 static void deAllocate(NPObject *npobj) {
157 delete (IcedTeaScriptableJavaObject*)npobj;
158 }
159 std::string getInstanceID() {
160 return instance_id;
161 }
162 std::string getClassID() {
163 return class_id;
164 }
165 std::string objectKey() {
166 return getClassID() + ":" + getInstanceID();
167 }
168 static void invalidate(NPObject *npobj) {
169 IcedTeaPluginUtilities::removeInstanceID(npobj);
170 IcedTeaScriptableJavaObject* scriptable_object = (IcedTeaScriptableJavaObject*) npobj;
171 IcedTeaPluginUtilities::removeObjectMapping(scriptable_object->objectKey());
172 }
173 static bool hasMethod(NPObject *npobj, NPIdentifier name_id);
174 static bool invoke(NPObject *npobj, NPIdentifier name_id,
175 const NPVariant *args, uint32_t argCount, NPVariant *result);
176 static bool invokeDefault(NPObject *npobj, const NPVariant *args,
177 uint32_t argCount, NPVariant *result) {
178 PLUGIN_ERROR ("** Unimplemented: IcedTeaScriptableJavaObject::invokeDefault %p\n", npobj);
179 return false;
180 }
181 static bool hasProperty(NPObject *npobj, NPIdentifier name_id);
182 static bool getProperty(NPObject *npobj, NPIdentifier name_id,
183 NPVariant *result);
184 static bool setProperty(NPObject *npobj, NPIdentifier name_id,
185 const NPVariant *value);
186
187 static bool removeProperty(NPObject *npobj, NPIdentifier name_id) {
188 PLUGIN_ERROR ("** Unimplemented: IcedTeaScriptableJavaObject::removeProperty %p\n", npobj);
189 return false;
190 }
191 static bool enumerate(NPObject *npobj, NPIdentifier **value,
192 uint32_t *count) {
193 PLUGIN_ERROR ("** Unimplemented: IcedTeaScriptableJavaObject::enumerate %p\n", npobj);
194 return false;
195 }
196 static bool construct(NPObject *npobj, const NPVariant *args,
197 uint32_t argCount, NPVariant *result);
198 /* Creates and retains a scriptable java object (intended to be called asynch.) */
199 static NPObject* get_scriptable_java_object(NPP instance,
200 std::string class_id,
201 std::string instance_id,
202 bool isArray);
203};
204
205/* Creates and retains a scriptable java object (intended to be called asynch.) */
206
207void _createAndRetainJavaObject(void* data);
208
209#endif /* __ICEDTEASCRIPTABLEPLUGINOBJECT_H_ */
Note: See TracBrowser for help on using the repository browser.