diff options
author | andrew <devnull@localhost> | 2010-10-19 17:55:59 +0100 |
---|---|---|
committer | andrew <devnull@localhost> | 2010-10-19 17:55:59 +0100 |
commit | 7603e948d7a0a7eb2e72358cb4a40ae6779f95da (patch) | |
tree | c6441f7d14eafe8119d890cddd09b05b8f88c52a /plugin/icedteanp/IcedTeaScriptablePluginObject.cc |
Initial import from IcedTea6.
2010-10-19 Andrew John Hughes <[email protected]>
* .hgignore,
* Makefile.am,
* acinclude.m4,
* autogen.sh,
* configure.ac,
* extra/net/sourceforge/jnlp/about/HTMLPanel.java,
* extra/net/sourceforge/jnlp/about/Main.java,
* extra/net/sourceforge/jnlp/about/resources/about.html,
* extra/net/sourceforge/jnlp/about/resources/applications.html,
* extra/net/sourceforge/jnlp/about/resources/notes.html,
* javac.in,
* javaws.desktop: Imported from IcedTea6.
* launcher/java.c,
* launcher/java.h,
* launcher/java_md.c,
* launcher/java_md.h,
* launcher/jli_util.h,
* launcher/jni.h,
* launcher/jvm.h,
* launcher/jvm_md.h,
* launcher/manifest_info.h,
* launcher/splashscreen.h,
* launcher/splashscreen_stubs.c,
* launcher/version_comp.h,
* launcher/wildcard.h: Imported from OpenJDK.
* netx/javaws.1,
* netx/javax/jnlp/BasicService.java,
* netx/javax/jnlp/ClipboardService.java,
* netx/javax/jnlp/DownloadService.java,
* netx/javax/jnlp/DownloadServiceListener.java,
* netx/javax/jnlp/ExtendedService.java,
* netx/javax/jnlp/ExtensionInstallerService.java,
* netx/javax/jnlp/FileContents.java,
* netx/javax/jnlp/FileOpenService.java,
* netx/javax/jnlp/FileSaveService.java,
* netx/javax/jnlp/JNLPRandomAccessFile.java,
* netx/javax/jnlp/PersistenceService.java,
* netx/javax/jnlp/PrintService.java,
* netx/javax/jnlp/ServiceManager.java,
* netx/javax/jnlp/ServiceManagerStub.java,
* netx/javax/jnlp/SingleInstanceListener.java,
* netx/javax/jnlp/SingleInstanceService.java,
* netx/javax/jnlp/UnavailableServiceException.java,
* netx/net/sourceforge/jnlp/AppletDesc.java,
* netx/net/sourceforge/jnlp/ApplicationDesc.java,
* netx/net/sourceforge/jnlp/AssociationDesc.java,
* netx/net/sourceforge/jnlp/ComponentDesc.java,
* netx/net/sourceforge/jnlp/DefaultLaunchHandler.java,
* netx/net/sourceforge/jnlp/ExtensionDesc.java,
* netx/net/sourceforge/jnlp/IconDesc.java,
* netx/net/sourceforge/jnlp/InformationDesc.java,
* netx/net/sourceforge/jnlp/InstallerDesc.java,
* netx/net/sourceforge/jnlp/JARDesc.java,
* netx/net/sourceforge/jnlp/JNLPFile.java,
* netx/net/sourceforge/jnlp/JNLPSplashScreen.java,
* netx/net/sourceforge/jnlp/JREDesc.java,
* netx/net/sourceforge/jnlp/LaunchException.java,
* netx/net/sourceforge/jnlp/LaunchHandler.java,
* netx/net/sourceforge/jnlp/Launcher.java,
* netx/net/sourceforge/jnlp/MenuDesc.java,
* netx/net/sourceforge/jnlp/NetxPanel.java,
* netx/net/sourceforge/jnlp/Node.java,
* netx/net/sourceforge/jnlp/PackageDesc.java,
* netx/net/sourceforge/jnlp/ParseException.java,
* netx/net/sourceforge/jnlp/Parser.java,
* netx/net/sourceforge/jnlp/PluginBridge.java,
* netx/net/sourceforge/jnlp/PropertyDesc.java,
* netx/net/sourceforge/jnlp/RelatedContentDesc.java,
* netx/net/sourceforge/jnlp/ResourcesDesc.java,
* netx/net/sourceforge/jnlp/SecurityDesc.java,
* netx/net/sourceforge/jnlp/ShortcutDesc.java,
* netx/net/sourceforge/jnlp/StreamEater.java,
* netx/net/sourceforge/jnlp/UpdateDesc.java,
* netx/net/sourceforge/jnlp/Version.java,
* netx/net/sourceforge/jnlp/cache/CacheEntry.java,
* netx/net/sourceforge/jnlp/cache/CacheUtil.java,
* netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java,
* netx/net/sourceforge/jnlp/cache/DownloadIndicator.java,
* netx/net/sourceforge/jnlp/cache/Resource.java,
* netx/net/sourceforge/jnlp/cache/ResourceTracker.java,
* netx/net/sourceforge/jnlp/cache/UpdatePolicy.java,
* netx/net/sourceforge/jnlp/cache/package.html,
* netx/net/sourceforge/jnlp/event/ApplicationEvent.java,
* netx/net/sourceforge/jnlp/event/ApplicationListener.java,
* netx/net/sourceforge/jnlp/event/DownloadEvent.java,
* netx/net/sourceforge/jnlp/event/DownloadListener.java,
* netx/net/sourceforge/jnlp/event/package.html,
* netx/net/sourceforge/jnlp/package.html,
* netx/net/sourceforge/jnlp/resources/Manifest.mf,
* netx/net/sourceforge/jnlp/resources/Messages.properties,
* netx/net/sourceforge/jnlp/resources/about.jnlp,
* netx/net/sourceforge/jnlp/resources/default.jnlp,
* netx/net/sourceforge/jnlp/runtime/AppThreadGroup.java,
* netx/net/sourceforge/jnlp/runtime/AppletAudioClip.java,
* netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java,
* netx/net/sourceforge/jnlp/runtime/AppletInstance.java,
* netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java,
* netx/net/sourceforge/jnlp/runtime/Boot.java,
* netx/net/sourceforge/jnlp/runtime/Boot13.java,
* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java,
* netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java,
* netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java,
* netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java,
* netx/net/sourceforge/jnlp/runtime/package.html,
* netx/net/sourceforge/jnlp/security/AccessWarningPane.java,
* netx/net/sourceforge/jnlp/security/AppletWarningPane.java,
* netx/net/sourceforge/jnlp/security/CertVerifier.java,
* netx/net/sourceforge/jnlp/security/CertWarningPane.java,
* netx/net/sourceforge/jnlp/security/CertsInfoPane.java,
* netx/net/sourceforge/jnlp/security/HttpsCertVerifier.java,
* netx/net/sourceforge/jnlp/security/MoreInfoPane.java,
* netx/net/sourceforge/jnlp/security/NotAllSignedWarningPane.java,
* netx/net/sourceforge/jnlp/security/SecurityDialogPanel.java,
* netx/net/sourceforge/jnlp/security/SecurityUtil.java,
* netx/net/sourceforge/jnlp/security/SecurityWarningDialog.java,
* netx/net/sourceforge/jnlp/security/SingleCertInfoPane.java,
* netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java,
* netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java,
* netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java,
* netx/net/sourceforge/jnlp/services/ExtendedSingleInstanceService.java,
* netx/net/sourceforge/jnlp/services/InstanceExistsException.java,
* netx/net/sourceforge/jnlp/services/ServiceUtil.java,
* netx/net/sourceforge/jnlp/services/SingleInstanceLock.java,
* netx/net/sourceforge/jnlp/services/XBasicService.java,
* netx/net/sourceforge/jnlp/services/XClipboardService.java,
* netx/net/sourceforge/jnlp/services/XDownloadService.java,
* netx/net/sourceforge/jnlp/services/XExtendedService.java,
* netx/net/sourceforge/jnlp/services/XExtensionInstallerService.java,
* netx/net/sourceforge/jnlp/services/XFileContents.java,
* netx/net/sourceforge/jnlp/services/XFileOpenService.java,
* netx/net/sourceforge/jnlp/services/XFileSaveService.java,
* netx/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java,
* netx/net/sourceforge/jnlp/services/XPersistenceService.java,
* netx/net/sourceforge/jnlp/services/XPrintService.java,
* netx/net/sourceforge/jnlp/services/XServiceManagerStub.java,
* netx/net/sourceforge/jnlp/services/XSingleInstanceService.java,
* netx/net/sourceforge/jnlp/services/package.html,
* netx/net/sourceforge/jnlp/tools/CharacterEncoder.java,
* netx/net/sourceforge/jnlp/tools/HexDumpEncoder.java,
* netx/net/sourceforge/jnlp/tools/JarRunner.java,
* netx/net/sourceforge/jnlp/tools/JarSigner.java,
* netx/net/sourceforge/jnlp/tools/JarSignerResources.java,
* netx/net/sourceforge/jnlp/tools/KeyStoreUtil.java,
* netx/net/sourceforge/jnlp/tools/KeyTool.java,
* netx/net/sourceforge/jnlp/util/FileUtils.java,
* netx/net/sourceforge/jnlp/util/PropertiesFile.java,
* netx/net/sourceforge/jnlp/util/Reflect.java,
* netx/net/sourceforge/jnlp/util/WeakList.java,
* netx/net/sourceforge/jnlp/util/XDesktopEntry.java,
* netx/net/sourceforge/nanoxml/XMLElement.java,
* netx/net/sourceforge/nanoxml/XMLParseException.java,
* plugin/icedteanp/IcedTeaJavaRequestProcessor.cc,
* plugin/icedteanp/IcedTeaJavaRequestProcessor.h,
* plugin/icedteanp/IcedTeaNPPlugin.cc,
* plugin/icedteanp/IcedTeaNPPlugin.h,
* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc,
* plugin/icedteanp/IcedTeaPluginRequestProcessor.h,
* plugin/icedteanp/IcedTeaPluginUtils.cc,
* plugin/icedteanp/IcedTeaPluginUtils.h,
* plugin/icedteanp/IcedTeaRunnable.cc,
* plugin/icedteanp/IcedTeaRunnable.h,
* plugin/icedteanp/IcedTeaScriptablePluginObject.cc,
* plugin/icedteanp/IcedTeaScriptablePluginObject.h,
* plugin/icedteanp/java/netscape/javascript/JSException.java,
* plugin/icedteanp/java/netscape/javascript/JSObject.java,
* plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java,
* plugin/icedteanp/java/netscape/javascript/JSProxy.java,
* plugin/icedteanp/java/netscape/javascript/JSRunnable.java,
* plugin/icedteanp/java/netscape/javascript/JSUtil.java,
* plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java,
* plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java,
* plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java,
* plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java,
* plugin/icedteanp/java/sun/applet/JavaConsole.java,
* plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java,
* plugin/icedteanp/java/sun/applet/PasswordAuthenticationDialog.java,
* plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java,
* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java,
* plugin/icedteanp/java/sun/applet/PluginCallRequest.java,
* plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java,
* plugin/icedteanp/java/sun/applet/PluginClassLoader.java,
* plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java,
* plugin/icedteanp/java/sun/applet/PluginCookieManager.java,
* plugin/icedteanp/java/sun/applet/PluginDebug.java,
* plugin/icedteanp/java/sun/applet/PluginException.java,
* plugin/icedteanp/java/sun/applet/PluginMain.java,
* plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java,
* plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java,
* plugin/icedteanp/java/sun/applet/PluginObjectStore.java,
* plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java,
* plugin/icedteanp/java/sun/applet/PluginProxySelector.java,
* plugin/icedteanp/java/sun/applet/PluginStreamHandler.java,
* plugin/icedteanp/java/sun/applet/RequestQueue.java,
* plugin/icedteanp/java/sun/applet/TestEnv.java,
* plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java,
* plugin/tests/LiveConnect/DummyObject.java,
* plugin/tests/LiveConnect/OverloadTestHelper1.java,
* plugin/tests/LiveConnect/OverloadTestHelper2.java,
* plugin/tests/LiveConnect/OverloadTestHelper3.java,
* plugin/tests/LiveConnect/PluginTest.java,
* plugin/tests/LiveConnect/build,
* plugin/tests/LiveConnect/common.js,
* plugin/tests/LiveConnect/index.html,
* plugin/tests/LiveConnect/jjs_eval_test.js,
* plugin/tests/LiveConnect/jjs_func_parameters_tests.js,
* plugin/tests/LiveConnect/jjs_func_rettype_tests.js,
* plugin/tests/LiveConnect/jjs_get_tests.js,
* plugin/tests/LiveConnect/jjs_set_tests.js,
* plugin/tests/LiveConnect/jsj_func_overload_tests.js,
* plugin/tests/LiveConnect/jsj_func_parameters_tests.js,
* plugin/tests/LiveConnect/jsj_func_rettype_tests.js,
* plugin/tests/LiveConnect/jsj_get_tests.js,
* plugin/tests/LiveConnect/jsj_set_tests.js,
* plugin/tests/LiveConnect/jsj_type_casting_tests.js,
* plugin/tests/LiveConnect/jsj_type_conversion_tests.js:
Initial import from IcedTea6.
* AUTHORS,
* COPYING
* INSTALL,
* NEWS,
* README: New documentation.
Diffstat (limited to 'plugin/icedteanp/IcedTeaScriptablePluginObject.cc')
-rw-r--r-- | plugin/icedteanp/IcedTeaScriptablePluginObject.cc | 897 |
1 files changed, 897 insertions, 0 deletions
diff --git a/plugin/icedteanp/IcedTeaScriptablePluginObject.cc b/plugin/icedteanp/IcedTeaScriptablePluginObject.cc new file mode 100644 index 0000000..e482941 --- /dev/null +++ b/plugin/icedteanp/IcedTeaScriptablePluginObject.cc @@ -0,0 +1,897 @@ +/* IcedTeaScriptablePluginObject.cc + + Copyright (C) 2009, 2010 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include <typeinfo> + +#include "IcedTeaScriptablePluginObject.h" + +IcedTeaScriptablePluginObject::IcedTeaScriptablePluginObject(NPP instance) +{ + this->instance = instance; + IcedTeaPluginUtilities::storeInstanceID(this, instance); +} + +void +IcedTeaScriptablePluginObject::deAllocate(NPObject *npobj) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::deAllocate %p\n", npobj); +} + +void +IcedTeaScriptablePluginObject::invalidate(NPObject *npobj) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::invalidate %p\n", npobj); +} + +bool +IcedTeaScriptablePluginObject::hasMethod(NPObject *npobj, NPIdentifier name) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::hasMethod %p\n", npobj); + return false; +} + +bool +IcedTeaScriptablePluginObject::invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, + uint32_t argCount,NPVariant *result) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::invoke %p\n", npobj); + return false; +} + +bool +IcedTeaScriptablePluginObject::invokeDefault(NPObject *npobj, const NPVariant *args, + uint32_t argCount, NPVariant *result) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::invokeDefault %p\n", npobj); + return false; +} + +bool +IcedTeaScriptablePluginObject::hasProperty(NPObject *npobj, NPIdentifier name) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::hasProperty %p\n", npobj); + return false; +} + +bool +IcedTeaScriptablePluginObject::getProperty(NPObject *npobj, NPIdentifier name, NPVariant *result) +{ + // Package request? + if (!strcmp(browser_functions.utf8fromidentifier(name), "java")) + { + //NPObject* obj = IcedTeaScriptablePluginObject::get_scriptable_java_package_object(getInstanceFromMemberPtr(npobj), name); + //OBJECT_TO_NPVARIANT(obj, *result); + + //printf ("Filling variant %p with object %p\n", result); + } + + return false; +} + +bool +IcedTeaScriptablePluginObject::setProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::setProperty %p\n", npobj); + return false; +} + +bool +IcedTeaScriptablePluginObject::removeProperty(NPObject *npobj, NPIdentifier name) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::removeProperty %p\n", npobj); + return false; +} + +bool +IcedTeaScriptablePluginObject::enumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::enumerate %p\n", npobj); + return false; +} + +bool +IcedTeaScriptablePluginObject::construct(NPObject *npobj, const NPVariant *args, uint32_t argCount, + NPVariant *result) +{ + printf ("** Unimplemented: IcedTeaScriptablePluginObject::construct %p\n", npobj); + return false; +} + +NPObject* +allocate_scriptable_jp_object(NPP npp, NPClass *aClass) +{ + PLUGIN_DEBUG("Allocating new scriptable Java Package object\n"); + return new IcedTeaScriptableJavaPackageObject(npp); +} + +NPObject* +IcedTeaScriptablePluginObject::get_scriptable_java_package_object(NPP instance, const NPUTF8* name) +{ + + NPObject* scriptable_object; + + NPClass* np_class = new NPClass(); + np_class->structVersion = NP_CLASS_STRUCT_VERSION; + np_class->allocate = allocate_scriptable_jp_object; + np_class->deallocate = IcedTeaScriptableJavaPackageObject::deAllocate; + np_class->invalidate = IcedTeaScriptableJavaPackageObject::invalidate; + np_class->hasMethod = IcedTeaScriptableJavaPackageObject::hasMethod; + np_class->invoke = IcedTeaScriptableJavaPackageObject::invoke; + np_class->invokeDefault = IcedTeaScriptableJavaPackageObject::invokeDefault; + np_class->hasProperty = IcedTeaScriptableJavaPackageObject::hasProperty; + np_class->getProperty = IcedTeaScriptableJavaPackageObject::getProperty; + np_class->setProperty = IcedTeaScriptableJavaPackageObject::setProperty; + np_class->removeProperty = IcedTeaScriptableJavaPackageObject::removeProperty; + np_class->enumerate = IcedTeaScriptableJavaPackageObject::enumerate; + np_class->construct = IcedTeaScriptableJavaPackageObject::construct; + + scriptable_object = browser_functions.createobject(instance, np_class); + PLUGIN_DEBUG("Returning new scriptable package class: %p from instance %p with name %s\n", scriptable_object, instance, name); + + ((IcedTeaScriptableJavaPackageObject*) scriptable_object)->setPackageName(name); + + IcedTeaPluginUtilities::storeInstanceID(scriptable_object, instance); + + return scriptable_object; +} + +IcedTeaScriptableJavaPackageObject::IcedTeaScriptableJavaPackageObject(NPP instance) +{ + PLUGIN_DEBUG("Constructing new scriptable java package object\n"); + this->instance = instance; + this->package_name = new std::string(); +} + +IcedTeaScriptableJavaPackageObject::~IcedTeaScriptableJavaPackageObject() +{ + delete this->package_name; +} + +void +IcedTeaScriptableJavaPackageObject::setPackageName(const NPUTF8* name) +{ + this->package_name->append(name); +} + +std::string +IcedTeaScriptableJavaPackageObject::getPackageName() +{ + return this->package_name->c_str(); +} + +void +IcedTeaScriptableJavaPackageObject::deAllocate(NPObject *npobj) +{ + browser_functions.releaseobject(npobj); +} + +void +IcedTeaScriptableJavaPackageObject::invalidate(NPObject *npobj) +{ + // nothing to do for these +} + +bool +IcedTeaScriptableJavaPackageObject::hasMethod(NPObject *npobj, NPIdentifier name) +{ + // Silly caller. Methods are for objects! + return false; +} + +bool +IcedTeaScriptableJavaPackageObject::invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, + uint32_t argCount,NPVariant *result) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaPackageObject::invoke %p\n", npobj); + return false; +} + +bool +IcedTeaScriptableJavaPackageObject::invokeDefault(NPObject *npobj, const NPVariant *args, + uint32_t argCount, NPVariant *result) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaPackageObject::invokeDefault %p\n", npobj); + return false; +} + +bool +IcedTeaScriptableJavaPackageObject::hasProperty(NPObject *npobj, NPIdentifier name) +{ + PLUGIN_DEBUG("IcedTeaScriptableJavaPackageObject::hasProperty %s\n", browser_functions.utf8fromidentifier(name)); + + bool hasProperty = false; + JavaResultData* java_result; + JavaRequestProcessor* java_request = new JavaRequestProcessor(); + NPP instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj); + int plugin_instance_id = get_id_from_instance(instance); + + PLUGIN_DEBUG("Object package name: \"%s\"\n", ((IcedTeaScriptableJavaPackageObject*) npobj)->getPackageName().c_str()); + + // "^java" is always a package + if (((IcedTeaScriptableJavaPackageObject*) npobj)->getPackageName().length() == 0 && + ( !strcmp(browser_functions.utf8fromidentifier(name), "java") || + !strcmp(browser_functions.utf8fromidentifier(name), "javax"))) + { + return true; + } + + std::string property_name = ((IcedTeaScriptableJavaPackageObject*) npobj)->getPackageName(); + if (property_name.length() > 0) + property_name += "."; + property_name += browser_functions.utf8fromidentifier(name); + + PLUGIN_DEBUG("Looking for name \"%s\"\n", property_name.c_str()); + + java_result = java_request->hasPackage(plugin_instance_id, property_name); + + if (!java_result->error_occurred && java_result->return_identifier != 0) hasProperty = true; + + // No such package. Do we have a class with that name? + if (!hasProperty) + { + java_result = java_request->findClass(plugin_instance_id, property_name); + } + + if (java_result->return_identifier != 0) hasProperty = true; + + delete java_request; + + return hasProperty; +} + +bool +IcedTeaScriptableJavaPackageObject::getProperty(NPObject *npobj, NPIdentifier name, NPVariant *result) +{ + + PLUGIN_DEBUG("IcedTeaScriptableJavaPackageObject::getProperty %s\n", browser_functions.utf8fromidentifier(name)); + + if (!browser_functions.utf8fromidentifier(name)) + return false; + + bool isPropertyClass = false; + JavaResultData* java_result; + JavaRequestProcessor java_request = JavaRequestProcessor(); + NPP instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj); + int plugin_instance_id = get_id_from_instance(instance); + + std::string property_name = ((IcedTeaScriptableJavaPackageObject*) npobj)->getPackageName(); + if (property_name.length() > 0) + property_name += "."; + property_name += browser_functions.utf8fromidentifier(name); + + java_result = java_request.findClass(plugin_instance_id, property_name); + isPropertyClass = (java_result->return_identifier == 0); + + //NPIdentifier property = browser_functions.getstringidentifier(property_name.c_str()); + + NPObject* obj; + + if (isPropertyClass) + { + PLUGIN_DEBUG("Returning package object\n"); + obj = IcedTeaScriptablePluginObject::get_scriptable_java_package_object( + IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj), + property_name.c_str()); + } + else + { + PLUGIN_DEBUG("Returning Java object\n"); + obj = IcedTeaScriptableJavaPackageObject::get_scriptable_java_object( + IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj), + *(java_result->return_string), "0", false); + } + + OBJECT_TO_NPVARIANT(obj, *result); + + return true; +} + +bool +IcedTeaScriptableJavaPackageObject::setProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value) +{ + // Can't be going around setting properties on namespaces.. that's madness! + return false; +} + +bool +IcedTeaScriptableJavaPackageObject::removeProperty(NPObject *npobj, NPIdentifier name) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaPackageObject::removeProperty %p\n", npobj); + return false; +} + +bool +IcedTeaScriptableJavaPackageObject::enumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaPackageObject::enumerate %p\n", npobj); + return false; +} + +bool +IcedTeaScriptableJavaPackageObject::construct(NPObject *npobj, const NPVariant *args, uint32_t argCount, + NPVariant *result) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaPackageObject::construct %p\n", npobj); + return false; +} + +NPObject* +allocate_scriptable_java_object(NPP npp, NPClass *aClass) +{ + PLUGIN_DEBUG("Allocating new scriptable Java object\n"); + return new IcedTeaScriptableJavaObject(npp); +} + +NPObject* +IcedTeaScriptableJavaPackageObject::get_scriptable_java_object(NPP instance, + std::string class_id, + std::string instance_id, + bool isArray) +{ + NPObject* scriptable_object; + + std::string obj_key = std::string(); + obj_key += class_id; + obj_key += ":"; + obj_key += instance_id; + + PLUGIN_DEBUG("get_scriptable_java_object searching for %s...\n", obj_key.c_str()); + scriptable_object = IcedTeaPluginUtilities::getNPObjectFromJavaKey(obj_key); + + if (scriptable_object != NULL) + { + PLUGIN_DEBUG("Returning existing object %p\n", scriptable_object); + browser_functions.retainobject(scriptable_object); + return scriptable_object; + } + + + NPClass* np_class = new NPClass(); + np_class->structVersion = NP_CLASS_STRUCT_VERSION; + np_class->allocate = allocate_scriptable_java_object; + np_class->deallocate = IcedTeaScriptableJavaObject::deAllocate; + np_class->invalidate = IcedTeaScriptableJavaObject::invalidate; + np_class->hasMethod = IcedTeaScriptableJavaObject::hasMethod; + np_class->invoke = IcedTeaScriptableJavaObject::invoke; + np_class->invokeDefault = IcedTeaScriptableJavaObject::invokeDefault; + np_class->hasProperty = IcedTeaScriptableJavaObject::hasProperty; + np_class->getProperty = IcedTeaScriptableJavaObject::getProperty; + np_class->setProperty = IcedTeaScriptableJavaObject::setProperty; + np_class->removeProperty = IcedTeaScriptableJavaObject::removeProperty; + np_class->enumerate = IcedTeaScriptableJavaObject::enumerate; + np_class->construct = IcedTeaScriptableJavaObject::construct; + + // try to create normally + scriptable_object = browser_functions.createobject(instance, np_class); + + // didn't work? try creating asynch + if (!scriptable_object) + { + AsyncCallThreadData thread_data = AsyncCallThreadData(); + thread_data.result_ready = false; + thread_data.parameters = std::vector<void*>(); + thread_data.result = std::string(); + + thread_data.parameters.push_back(instance); + thread_data.parameters.push_back(np_class); + thread_data.parameters.push_back(&scriptable_object); + + browser_functions.pluginthreadasynccall(instance, &_createAndRetainJavaObject, &thread_data); + + while (!thread_data.result_ready) usleep(2000); // wait till ready + } else + { + // Else retain object and continue + browser_functions.retainobject(scriptable_object); + } + + PLUGIN_DEBUG("Constructed new Java Object with classid=%s, instanceid=%s, isArray=%d and scriptable_object=%p\n", class_id.c_str(), instance_id.c_str(), isArray, scriptable_object); + + ((IcedTeaScriptableJavaObject*) scriptable_object)->setClassIdentifier(class_id); + ((IcedTeaScriptableJavaObject*) scriptable_object)->setIsArray(isArray); + + if (instance_id != "0") + ((IcedTeaScriptableJavaObject*) scriptable_object)->setInstanceIdentifier(instance_id); + + IcedTeaPluginUtilities::storeInstanceID(scriptable_object, instance); + IcedTeaPluginUtilities::storeObjectMapping(obj_key, scriptable_object); + + PLUGIN_DEBUG("Inserting into object_map key %s->%p\n", obj_key.c_str(), scriptable_object); + return scriptable_object; +} + +/* Creates and retains a scriptable java object (intended to be called asynch.) */ +void +_createAndRetainJavaObject(void* data) +{ + PLUGIN_DEBUG("Asynchronously creating/retaining object ...\n"); + + std::vector<void*> parameters = ((AsyncCallThreadData*) data)->parameters; + NPP instance = (NPP) parameters.at(0); + NPClass* np_class = (NPClass*) parameters.at(1); + NPObject** scriptable_object = (NPObject**) parameters.at(2); + + *scriptable_object = browser_functions.createobject(instance, np_class); + browser_functions.retainobject(*scriptable_object); + + ((AsyncCallThreadData*) data)->result_ready = true; +} + +bool +IcedTeaScriptableJavaPackageObject::is_valid_java_object(NPObject* object_ptr) { + return IcedTeaPluginUtilities::getInstanceFromMemberPtr(object_ptr) != NULL; +} + +IcedTeaScriptableJavaObject::IcedTeaScriptableJavaObject(NPP instance) +{ + this->instance = instance; + this->class_id = new std::string(); + this->instance_id = new std::string(); +} + +IcedTeaScriptableJavaObject::~IcedTeaScriptableJavaObject() +{ + delete this->class_id; + delete this->instance_id; +} + +void +IcedTeaScriptableJavaObject::setClassIdentifier(std::string class_id) +{ + this->class_id->append(class_id); +} + +void +IcedTeaScriptableJavaObject::setInstanceIdentifier(std::string instance_id) +{ + this->instance_id->append(instance_id); +} + +void +IcedTeaScriptableJavaObject::setIsArray(bool isArray) +{ + this->isObjectArray = isArray; +} + +void +IcedTeaScriptableJavaObject::deAllocate(NPObject *npobj) +{ + browser_functions.releaseobject(npobj); +} + +void +IcedTeaScriptableJavaObject::invalidate(NPObject *npobj) +{ + IcedTeaPluginUtilities::removeInstanceID(npobj); + + std::string obj_key = std::string(); + obj_key += ((IcedTeaScriptableJavaObject*) npobj)->getClassID(); + obj_key += ":"; + obj_key += ((IcedTeaScriptableJavaObject*) npobj)->getInstanceID(); + + IcedTeaPluginUtilities::removeObjectMapping(obj_key); +} + +bool +IcedTeaScriptableJavaObject::hasMethod(NPObject *npobj, NPIdentifier name) +{ + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::hasMethod %s (ival=%d)\n", browser_functions.utf8fromidentifier(name), browser_functions.intfromidentifier(name)); + bool hasMethod = false; + + // If object is an array and requested "method" may be a number, check for it first + if ( !((IcedTeaScriptableJavaObject*) npobj)->isArray() || + (browser_functions.intfromidentifier(name) < 0)) + { + + if (!browser_functions.utf8fromidentifier(name)) + return false; + + JavaResultData* java_result; + JavaRequestProcessor java_request = JavaRequestProcessor(); + + std::string classId = std::string(((IcedTeaScriptableJavaObject*) npobj)->getClassID()); + std::string methodName = browser_functions.utf8fromidentifier(name); + + java_result = java_request.hasMethod(classId, methodName); + hasMethod = java_result->return_identifier != 0; + } + + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::hasMethod returning %d\n", hasMethod); + return hasMethod; +} + +bool +IcedTeaScriptableJavaObject::invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, + uint32_t argCount, NPVariant *result) +{ + NPUTF8* method_name = browser_functions.utf8fromidentifier(name); + + // Extract arg type array + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::invoke %s. Args follow.\n", method_name); + for (int i=0; i < argCount; i++) + { + IcedTeaPluginUtilities::printNPVariant(args[i]); + } + + JavaResultData* java_result; + JavaRequestProcessor java_request = JavaRequestProcessor(); + + NPObject* obj; + std::string instance_id = ((IcedTeaScriptableJavaObject*) npobj)->getInstanceID(); + std::string class_id = ((IcedTeaScriptableJavaObject*) npobj)->getClassID(); + std::string callee; + std::string source; + + NPP instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj); + + // First, load the arguments into the java-side table + std::string id = std::string(); + std::vector<std::string> arg_ids = std::vector<std::string>(); + for (int i=0; i < argCount; i++) { + id.clear(); + createJavaObjectFromVariant(instance, args[i], &id); + + if (id == "-1") + { + printf("Unable to create arguments on Java side\n"); + return false; + } + + arg_ids.push_back(id); + } + + if (instance_id.length() == 0) // Static + { + PLUGIN_DEBUG("Calling static method\n"); + callee = ((IcedTeaScriptableJavaObject*) npobj)->getClassID(); + java_result = java_request.callStaticMethod( + IcedTeaPluginUtilities::getSourceFromInstance(instance), + callee, browser_functions.utf8fromidentifier(name), arg_ids); + } else + { + PLUGIN_DEBUG("Calling method normally\n"); + callee = ((IcedTeaScriptableJavaObject*) npobj)->getInstanceID(); + java_result = java_request.callMethod( + IcedTeaPluginUtilities::getSourceFromInstance(instance), + callee, browser_functions.utf8fromidentifier(name), arg_ids); + } + + if (java_result->error_occurred) + { + // error message must be allocated on heap + char* error_msg = (char*) malloc(java_result->error_msg->length()*sizeof(char)); + strcpy(error_msg, java_result->error_msg->c_str()); + browser_functions.setexception(npobj, error_msg); + return false; + } + + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::invoke converting and returning.\n"); + return IcedTeaPluginUtilities::javaResultToNPVariant(instance, java_result->return_string, result); +} + +bool +IcedTeaScriptableJavaObject::invokeDefault(NPObject *npobj, const NPVariant *args, + uint32_t argCount, NPVariant *result) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaObject::invokeDefault %p\n", npobj); + return false; +} + +bool +IcedTeaScriptableJavaObject::hasProperty(NPObject *npobj, NPIdentifier name) +{ + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::hasProperty %s (ival=%d)\n", browser_functions.utf8fromidentifier(name), browser_functions.intfromidentifier(name)); + bool hasProperty = false; + + // If it is an array, only length and indexes are valid + if (((IcedTeaScriptableJavaObject*) npobj)->isArray()) + { + if (browser_functions.intfromidentifier(name) >= 0 || + !strcmp(browser_functions.utf8fromidentifier(name), "length")) + hasProperty = true; + + } else + { + + if (!browser_functions.utf8fromidentifier(name)) + return false; + + if (!strcmp(browser_functions.utf8fromidentifier(name), "Packages")) + { + hasProperty = true; + } else { + + JavaResultData* java_result; + JavaRequestProcessor java_request = JavaRequestProcessor(); + + std::string class_id = std::string(((IcedTeaScriptableJavaObject*) npobj)->getClassID()); + std::string fieldName = browser_functions.utf8fromidentifier(name); + + java_result = java_request.hasField(class_id, fieldName); + + hasProperty = java_result->return_identifier != 0; + } + } + + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::hasProperty returning %d\n", hasProperty); + return hasProperty; +} + +bool +IcedTeaScriptableJavaObject::getProperty(NPObject *npobj, NPIdentifier name, NPVariant *result) +{ + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::getProperty %s (ival=%d)\n", browser_functions.utf8fromidentifier(name), browser_functions.intfromidentifier(name)); + + bool isPropertyClass = false; + JavaResultData* java_result; + JavaRequestProcessor java_request = JavaRequestProcessor(); + + NPObject* obj; + std::string instance_id = ((IcedTeaScriptableJavaObject*) npobj)->getInstanceID(); + std::string class_id = ((IcedTeaScriptableJavaObject*) npobj)->getClassID(); + NPP instance = ((IcedTeaScriptableJavaObject*) npobj)->getInstance(); + + if (instance_id.length() > 0) // Could be an array or a simple object + { + // If array and requesting length + if ( ((IcedTeaScriptableJavaObject*) npobj)->isArray() && + browser_functions.utf8fromidentifier(name) && + !strcmp(browser_functions.utf8fromidentifier(name), "length")) + { + java_result = java_request.getArrayLength(instance_id); + } else if ( ((IcedTeaScriptableJavaObject*) npobj)->isArray() && + browser_functions.intfromidentifier(name) >= 0) // else if array and requesting index + { + + java_result = java_request.getArrayLength(instance_id); + if (java_result->error_occurred) + { + printf("ERROR: Couldn't fetch array length\n"); + return false; + } + + int length = atoi(java_result->return_string->c_str()); + + // Access beyond size? + if (browser_functions.intfromidentifier(name) >= length) + { + VOID_TO_NPVARIANT(*result); + return true; + } + + std::string index = std::string(); + IcedTeaPluginUtilities::itoa(browser_functions.intfromidentifier(name), &index); + java_result = java_request.getSlot(instance_id, index); + + } else // Everything else + { + if (!browser_functions.utf8fromidentifier(name)) + return false; + + if (!strcmp(browser_functions.utf8fromidentifier(name), "Packages")) + { + NPObject* pkgObject = IcedTeaScriptablePluginObject::get_scriptable_java_package_object(instance, ""); + OBJECT_TO_NPVARIANT(pkgObject, *result); + return true; + } + + java_result = java_request.getField( + IcedTeaPluginUtilities::getSourceFromInstance(instance), + class_id, instance_id, browser_functions.utf8fromidentifier(name)); + } + } + else + { + if (!browser_functions.utf8fromidentifier(name)) + return true; + + java_result = java_request.getStaticField( + IcedTeaPluginUtilities::getSourceFromInstance(instance), + class_id, browser_functions.utf8fromidentifier(name)); + } + + if (java_result->error_occurred) + { + return false; + } + + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::getProperty converting and returning.\n"); + return IcedTeaPluginUtilities::javaResultToNPVariant(instance, java_result->return_string, result); +} + +bool +IcedTeaScriptableJavaObject::setProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value) +{ + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::setProperty %s (ival=%d) to:\n", browser_functions.utf8fromidentifier(name), browser_functions.intfromidentifier(name)); + IcedTeaPluginUtilities::printNPVariant(*value); + + bool isPropertyClass = false; + JavaResultData* java_result; + JavaRequestProcessor java_request = JavaRequestProcessor(); + + NPObject* obj; + std::string instance_id = ((IcedTeaScriptableJavaObject*) npobj)->getInstanceID(); + std::string class_id = ((IcedTeaScriptableJavaObject*) npobj)->getClassID(); + + NPP instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj); + + if (instance_id.length() > 0) // Could be an array or a simple object + { + // If array + if ( ((IcedTeaScriptableJavaObject*) npobj)->isArray() && + browser_functions.utf8fromidentifier(name) && + !strcmp(browser_functions.utf8fromidentifier(name), "length")) + { + printf("ERROR: Array length is not a modifiable property\n"); + return false; + } else if ( ((IcedTeaScriptableJavaObject*) npobj)->isArray() && + browser_functions.intfromidentifier(name) >= 0) // else if array and requesting index + { + + java_result = java_request.getArrayLength(instance_id); + if (java_result->error_occurred) + { + printf("ERROR: Couldn't fetch array length\n"); + return false; + } + + int length = atoi(java_result->return_string->c_str()); + + // Access beyond size? + if (browser_functions.intfromidentifier(name) >= length) + { + return true; + } + + std::string index = std::string(); + IcedTeaPluginUtilities::itoa(browser_functions.intfromidentifier(name), &index); + + std::string value_id = std::string(); + createJavaObjectFromVariant(instance, *value, &value_id); + + java_result = java_request.setSlot(instance_id, index, value_id); + + } else // Everything else + { + std::string value_id = std::string(); + createJavaObjectFromVariant(instance, *value, &value_id); + + java_result = java_request.setField( + IcedTeaPluginUtilities::getSourceFromInstance(instance), + class_id, instance_id, browser_functions.utf8fromidentifier(name), value_id); + } + } + else + { + std::string value_id = std::string(); + createJavaObjectFromVariant(instance, *value, &value_id); + + java_result = java_request.setStaticField( + IcedTeaPluginUtilities::getSourceFromInstance(instance), + class_id, browser_functions.utf8fromidentifier(name), value_id); + } + + if (java_result->error_occurred) + { + return false; + } + + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::setProperty returning.\n"); + return true; +} + +bool +IcedTeaScriptableJavaObject::removeProperty(NPObject *npobj, NPIdentifier name) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaObject::removeProperty %p\n", npobj); + return false; +} + +bool +IcedTeaScriptableJavaObject::enumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) +{ + printf ("** Unimplemented: IcedTeaScriptableJavaObject::enumerate %p\n", npobj); + return false; +} + +bool +IcedTeaScriptableJavaObject::construct(NPObject *npobj, const NPVariant *args, uint32_t argCount, + NPVariant *result) +{ + // Extract arg type array + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::construct %s. Args follow.\n", ((IcedTeaScriptableJavaObject*) npobj)->getClassID().c_str()); + for (int i=0; i < argCount; i++) + { + IcedTeaPluginUtilities::printNPVariant(args[i]); + } + + JavaResultData* java_result; + JavaRequestProcessor java_request = JavaRequestProcessor(); + + NPObject* obj; + std::string class_id = ((IcedTeaScriptableJavaObject*) npobj)->getClassID(); + NPP instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj); + + // First, load the arguments into the java-side table + std::string id = std::string(); + std::vector<std::string> arg_ids = std::vector<std::string>(); + for (int i=0; i < argCount; i++) { + id.clear(); + createJavaObjectFromVariant(instance, args[i], &id); + if (id == "0") + { + // error message must be allocated on heap + char* error_msg = (char*) malloc(1024*sizeof(char)); + strcpy(error_msg, "Unable to create argument on Java side"); + + browser_functions.setexception(npobj, error_msg); + return false; + } + + arg_ids.push_back(id); + } + + java_result = java_request.newObject( + IcedTeaPluginUtilities::getSourceFromInstance(instance), + class_id, + arg_ids); + + if (java_result->error_occurred) + { + // error message must be allocated on heap + int length = java_result->error_msg->length(); + char* error_msg = (char*) malloc((length+1)*sizeof(char)); + strcpy(error_msg, java_result->error_msg->c_str()); + + browser_functions.setexception(npobj, error_msg); + return false; + } + + std::string return_obj_instance_id = std::string(); + std::string return_obj_class_id = class_id; + return_obj_instance_id.append(*(java_result->return_string)); + + obj = IcedTeaScriptableJavaPackageObject::get_scriptable_java_object( + IcedTeaPluginUtilities::getInstanceFromMemberPtr(npobj), + return_obj_class_id, return_obj_instance_id, false); + + OBJECT_TO_NPVARIANT(obj, *result); + + PLUGIN_DEBUG("IcedTeaScriptableJavaObject::construct returning.\n"); + return true; +} |