[348] | 1 | /* IcedTeaScriptablePluginObject.h
|
---|
| 2 |
|
---|
| 3 | Copyright (C) 2009, 2010 Red Hat
|
---|
| 4 |
|
---|
| 5 | This file is part of IcedTea.
|
---|
| 6 |
|
---|
| 7 | IcedTea is free software; you can redistribute it and/or modify
|
---|
| 8 | it under the terms of the GNU General Public License as published by
|
---|
| 9 | the Free Software Foundation; either version 2, or (at your option)
|
---|
| 10 | any later version.
|
---|
| 11 |
|
---|
| 12 | IcedTea is distributed in the hope that it will be useful, but
|
---|
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 15 | General Public License for more details.
|
---|
| 16 |
|
---|
| 17 | You should have received a copy of the GNU General Public License
|
---|
| 18 | along with IcedTea; see the file COPYING. If not, write to the
|
---|
| 19 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
| 20 | 02110-1301 USA.
|
---|
| 21 |
|
---|
| 22 | Linking this library statically or dynamically with other modules is
|
---|
| 23 | making a combined work based on this library. Thus, the terms and
|
---|
| 24 | conditions of the GNU General Public License cover the whole
|
---|
| 25 | combination.
|
---|
| 26 |
|
---|
| 27 | As a special exception, the copyright holders of this library give you
|
---|
| 28 | permission to link this library with independent modules to produce an
|
---|
| 29 | executable, regardless of the license terms of these independent
|
---|
| 30 | modules, and to copy and distribute the resulting executable under
|
---|
| 31 | terms of your choice, provided that you also meet, for each linked
|
---|
| 32 | independent module, the terms and conditions of the license of that
|
---|
| 33 | module. An independent module is a module which is not derived from
|
---|
| 34 | or based on this library. If you modify this library, you may extend
|
---|
| 35 | this exception to your version of the library, but you are not
|
---|
| 36 | obligated to do so. If you do not wish to do so, delete this
|
---|
| 37 | exception 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 |
|
---|
| 53 | class 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 |
|
---|
[429] | 66 | static bool hasMethod(NPObject *npobj, NPIdentifier name_id);
|
---|
[348] | 67 |
|
---|
[429] | 68 | static bool invoke(NPObject *npobj, NPIdentifier name_id,
|
---|
[348] | 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 |
|
---|
[429] | 74 | static bool hasProperty(NPObject *npobj, NPIdentifier name_id);
|
---|
[348] | 75 |
|
---|
[429] | 76 | static bool getProperty(NPObject *npobj, NPIdentifier name_id,
|
---|
[348] | 77 | NPVariant *result);
|
---|
| 78 |
|
---|
[429] | 79 | static bool setProperty(NPObject *npobj, NPIdentifier name_id,
|
---|
[348] | 80 | const NPVariant *value);
|
---|
| 81 |
|
---|
[429] | 82 | static bool removeProperty(NPObject *npobj, NPIdentifier name_id);
|
---|
[348] | 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 |
|
---|
| 92 | NPObject* allocate_scriptable_jp_object(NPP npp, NPClass *aClass);
|
---|
| 93 |
|
---|
| 94 | class 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 |
|
---|
[429] | 114 | static bool hasMethod(NPObject *npobj, NPIdentifier name_id);
|
---|
[348] | 115 |
|
---|
[429] | 116 | static bool invoke(NPObject *npobj, NPIdentifier name_id,
|
---|
[348] | 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 |
|
---|
[429] | 122 | static bool hasProperty(NPObject *npobj, NPIdentifier name_id);
|
---|
[348] | 123 |
|
---|
[429] | 124 | static bool getProperty(NPObject *npobj, NPIdentifier name_id,
|
---|
[348] | 125 | NPVariant *result);
|
---|
| 126 |
|
---|
[429] | 127 | static bool setProperty(NPObject *npobj, NPIdentifier name_id,
|
---|
[348] | 128 | const NPVariant *value);
|
---|
| 129 |
|
---|
[429] | 130 | static bool removeProperty(NPObject *npobj, NPIdentifier name_id);
|
---|
[348] | 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 |
|
---|
[429] | 138 | static NPObject* get_scriptable_java_package_object(NPP instance, const NPUTF8* name);
|
---|
[348] | 139 |
|
---|
| 140 | static bool is_valid_java_object(NPObject* object_ptr);
|
---|
| 141 | };
|
---|
| 142 |
|
---|
| 143 | class IcedTeaScriptableJavaObject: public NPObject
|
---|
| 144 | {
|
---|
[429] | 145 | private:
|
---|
| 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;
|
---|
| 151 | public:
|
---|
| 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);
|
---|
[348] | 186 |
|
---|
[429] | 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);
|
---|
[348] | 203 | };
|
---|
| 204 |
|
---|
| 205 | /* Creates and retains a scriptable java object (intended to be called asynch.) */
|
---|
| 206 |
|
---|
| 207 | void _createAndRetainJavaObject(void* data);
|
---|
| 208 |
|
---|
| 209 | #endif /* __ICEDTEASCRIPTABLEPLUGINOBJECT_H_ */
|
---|