From d7cf5961f9fe8a90b5eb2504d2deb27d4c5ff6ee Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Sat, 20 Feb 1999 02:24:15 +0000 Subject: [PATCH] OJI interface changes git-svn-id: svn://10.0.0.236/trunk@21382 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/oji/public/MANIFEST | 3 +- mozilla/modules/oji/public/Makefile.in | 6 +- mozilla/modules/oji/public/ProxyJNI.h | 6 +- mozilla/modules/oji/public/makefile.win | 6 +- mozilla/modules/oji/public/nsIJVMManager.h | 4 +- mozilla/modules/oji/public/nsIJVMPlugin.h | 75 +++++------ .../modules/oji/public/nsIJVMPluginInstance.h | 4 +- mozilla/modules/oji/src/ProxyJNI.cpp | 18 +-- mozilla/modules/oji/src/lcglue.cpp | 30 ++--- mozilla/modules/oji/src/nsJVMManager.cpp | 23 +++- mozilla/modules/oji/src/nsJVMManager.h | 2 +- .../plugin/base/public/nsIPluginInstance.h | 23 +++- .../modules/plugin/base/public/nsplugindefs.h | 9 +- .../plugin/base/src/ns4xPluginInstance.cpp | 8 -- .../modules/plugin/base/src/nsIPluginHost.h | 4 + .../plugin/base/src/nsPluginHostImpl.cpp | 122 ++++++++++++++++++ .../plugin/base/src/nsPluginHostImpl.h | 6 + .../plugin/nglsrc/ns4xPluginInstance.cpp | 8 -- mozilla/modules/plugin/nglsrc/nsIPluginHost.h | 4 + .../plugin/nglsrc/nsPluginHostImpl.cpp | 122 ++++++++++++++++++ .../modules/plugin/nglsrc/nsPluginHostImpl.h | 6 + .../modules/plugin/public/nsIPluginInstance.h | 23 +++- mozilla/modules/plugin/public/nsplugindefs.h | 9 +- 23 files changed, 400 insertions(+), 121 deletions(-) diff --git a/mozilla/modules/oji/public/MANIFEST b/mozilla/modules/oji/public/MANIFEST index e128cd8c6d6..84eb1f67bf6 100644 --- a/mozilla/modules/oji/public/MANIFEST +++ b/mozilla/modules/oji/public/MANIFEST @@ -28,6 +28,7 @@ nsIJVMPluginTagInfo.h nsISymantecDebugger.h nsISymantecDebugManager.h nsjvm.h -nsISecureJNI2.h +nsISecureEnv.h ProxyJNI.h nsIThreadManager.h +nsIJVMWindow.h diff --git a/mozilla/modules/oji/public/Makefile.in b/mozilla/modules/oji/public/Makefile.in index 7b9381f89bf..e350938b52f 100644 --- a/mozilla/modules/oji/public/Makefile.in +++ b/mozilla/modules/oji/public/Makefile.in @@ -36,9 +36,9 @@ EXPORTS = \ nsIJVMWindow.h \ nsISymantecDebugManager.h \ nsISymantecDebugger.h \ - nsISecureJNI2.h \ - ProxyJNI.h \ - nsIThreadManager.h + nsISecureEnv.h \ + ProxyJNI.h \ + nsIThreadManager.h EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/modules/oji/public/ProxyJNI.h b/mozilla/modules/oji/public/ProxyJNI.h index 4e49e076528..dd7a8d3a6cf 100644 --- a/mozilla/modules/oji/public/ProxyJNI.h +++ b/mozilla/modules/oji/public/ProxyJNI.h @@ -28,12 +28,12 @@ #endif class nsIJVMPlugin; -class nsISecureJNI2; +class nsISecureEnv; /** * Creates a proxy JNIEnv using the given JVM plugin, and optional native JNIEnv*. */ -JNIEnv* CreateProxyJNI(nsIJVMPlugin* jvmPlugin, nsISecureJNI2* secureEnv = NULL); +JNIEnv* CreateProxyJNI(nsIJVMPlugin* jvmPlugin, nsISecureEnv* secureEnv = NULL); /** * Deletes the proxy JNIEnv. Releases the connection @@ -45,6 +45,6 @@ void DeleteProxyJNI(JNIEnv* proxyEnv); /** * Returns the secure env associated with the given proxy env. */ -nsISecureJNI2* GetSecureEnv(JNIEnv* proxyEnv); +nsISecureEnv* GetSecureEnv(JNIEnv* proxyEnv); #endif /* PROXY_JNI_H */ diff --git a/mozilla/modules/oji/public/makefile.win b/mozilla/modules/oji/public/makefile.win index 034280a6e43..b194b5d05d4 100644 --- a/mozilla/modules/oji/public/makefile.win +++ b/mozilla/modules/oji/public/makefile.win @@ -33,9 +33,9 @@ EXPORTS = \ nsIJVMWindow.h \ nsISymantecDebugManager.h \ nsISymantecDebugger.h \ - nsISecureJNI2.h \ - ProxyJNI.h \ - nsIThreadManager.h + nsISecureEnv.h \ + ProxyJNI.h \ + nsIThreadManager.h include <$(DEPTH)/config/rules.mak> diff --git a/mozilla/modules/oji/public/nsIJVMManager.h b/mozilla/modules/oji/public/nsIJVMManager.h index 5bb1871c1a2..eca97b4a398 100644 --- a/mozilla/modules/oji/public/nsIJVMManager.h +++ b/mozilla/modules/oji/public/nsIJVMManager.h @@ -37,7 +37,7 @@ // to JVM plugins for browsers that support JVM plugins. class nsIJVMPlugin; -class nsISecureJNI2; +class nsISecureEnv; class nsIJVMManager : public nsISupports { public: @@ -48,7 +48,7 @@ public: * the same proxy JNI. */ NS_IMETHOD - CreateProxyJNI(nsISecureJNI2* inSecureEnv, JNIEnv** outProxyEnv) = 0; + CreateProxyJNI(nsISecureEnv* inSecureEnv, JNIEnv** outProxyEnv) = 0; /** * Returns the proxy JNI associated with the current thread, or NULL if no diff --git a/mozilla/modules/oji/public/nsIJVMPlugin.h b/mozilla/modules/oji/public/nsIJVMPlugin.h index af61f6a80ff..9d3c8cb6f45 100644 --- a/mozilla/modules/oji/public/nsIJVMPlugin.h +++ b/mozilla/modules/oji/public/nsIJVMPlugin.h @@ -29,11 +29,11 @@ #ifndef nsIJVMPlugin_h___ #define nsIJVMPlugin_h___ -#include "nsIPlugin.h" +#include "nsISupports.h" #include "nsIPrincipal.h" #include "jni.h" -class nsISecureJNI2; +class nsISecureEnv; /** * This MIME type is what should be used to signify a Java VM plugin. @@ -45,54 +45,41 @@ class nsISecureJNI2; // This interface defines additional entry points that a plugin developer needs // to implement in order to implement a Java virtual machine plugin. -class nsIJVMPlugin : public nsIPlugin { +class nsIJVMPlugin : public nsISupports { public: + // Causes the JVM to append a new directory to its classpath. + // If the JVM doesn't support this operation, an error is returned. + NS_IMETHOD + AddToClassPath(const char* dirPath) = 0; - // Causes the JVM to append a new directory to its classpath. - // If the JVM doesn't support this operation, an error is returned. - NS_IMETHOD - AddToClassPath(const char* dirPath) = 0; + // Causes the JVM to remove a directory from its classpath. + // If the JVM doesn't support this operation, an error is returned. + NS_IMETHOD + RemoveFromClassPath(const char* dirPath) = 0; - // Causes the JVM to remove a directory from its classpath. - // If the JVM doesn't support this operation, an error is returned. - NS_IMETHOD - RemoveFromClassPath(const char* dirPath) = 0; + // Returns the current classpath in use by the JVM. + NS_IMETHOD + GetClassPath(const char* *result) = 0; - // Returns the current classpath in use by the JVM. - NS_IMETHOD - GetClassPath(const char* *result) = 0; + NS_IMETHOD + GetJavaWrapper(JNIEnv* jenv, jint obj, jobject *jobj) = 0; - NS_IMETHOD - GetJavaWrapper(JNIEnv* jenv, jint obj, jobject *jobj) = 0; + /** + * This creates a new secure communication channel with Java. The second parameter, + * nativeEnv, if non-NULL, will be the actual thread for Java communication. + * Otherwise, a new thread should be created. + * @param proxyEnv the env to be used by all clients on the browser side + * @return outSecureEnv the secure environment used by the proxyEnv + */ + NS_IMETHOD + CreateSecureEnv(JNIEnv* proxyEnv, nsISecureEnv* *outSecureEnv) = 0; - // Find or create a JNIEnv for the current thread. - // Returns NULL if an error occurs. - NS_IMETHOD_(nsrefcnt) - GetJNIEnv(JNIEnv* *result) = 0; - - // This method must be called when the caller is done using the JNIEnv. - // This decrements a refcount associated with it may free it. - NS_IMETHOD_(nsrefcnt) - ReleaseJNIEnv(JNIEnv* env) = 0; - - /** - * This creates a new secure communication channel with Java. The second parameter, - * nativeEnv, if non-NULL, will be the actual thread for Java communication. - * Otherwise, a new thread should be created. - * @param proxyEnv the env to be used by all clients on the browser side - * @return outSecureEnv the secure environment used by the proxyEnv - */ - NS_IMETHOD - CreateSecureEnv(JNIEnv* proxyEnv, nsISecureJNI2* *outSecureEnv) = 0; - - /** - * Gives time to the JVM from the main event loop of the browser. This is - * necessary when there aren't any plugin instances around, but Java threads exist. - */ -#ifdef XP_MAC - NS_IMETHOD - SpendTime(PRUint32 timeMillis) = 0; -#endif + /** + * Gives time to the JVM from the main event loop of the browser. This is + * necessary when there aren't any plugin instances around, but Java threads exist. + */ + NS_IMETHOD + SpendTime(PRUint32 timeMillis) = 0; }; #define NS_IJVMPLUGIN_IID \ diff --git a/mozilla/modules/oji/public/nsIJVMPluginInstance.h b/mozilla/modules/oji/public/nsIJVMPluginInstance.h index 3849834342d..b5b4e85cd1f 100644 --- a/mozilla/modules/oji/public/nsIJVMPluginInstance.h +++ b/mozilla/modules/oji/public/nsIJVMPluginInstance.h @@ -29,12 +29,12 @@ #ifndef nsIJVMPluginInstance_h___ #define nsIJVMPluginInstance_h___ -#include "nsIPluginInstance.h" +#include "nsISupports.h" //////////////////////////////////////////////////////////////////////////////// // Java VM Plugin Instance Interface -class nsIJVMPluginInstance : public nsIPluginInstance { +class nsIJVMPluginInstance : public nsISupports { public: // This method is called when LiveConnect wants to find the Java object diff --git a/mozilla/modules/oji/src/ProxyJNI.cpp b/mozilla/modules/oji/src/ProxyJNI.cpp index 04b1743b2b0..6f8c2223e70 100644 --- a/mozilla/modules/oji/src/ProxyJNI.cpp +++ b/mozilla/modules/oji/src/ProxyJNI.cpp @@ -21,7 +21,7 @@ */ #include "jvmmgr.h" -#include "nsISecureJNI2.h" +#include "nsISecureEnv.h" #include "nsIJVMPlugin.h" #include "nsHashtable.h" #include "nsVector.h" @@ -228,13 +228,13 @@ class ProxyJNIEnv : public JNIEnv { private: static JNINativeInterface_ theFuncs; static nsHashtable* theIDTable; - nsISecureJNI2* mSecureEnv; + nsISecureEnv* mSecureEnv; nsISecurityContext* mContext; jobject mJavaThread; static ProxyJNIEnv& nsJNIEnvRef(JNIEnv* env) { return *(ProxyJNIEnv*)env; } - nsISecureJNI2* operator->() { return mSecureEnv; } + nsISecureEnv* operator->() { return mSecureEnv; } nsISecurityContext* getContext() { return JVM_GetJSSecurityContext(); } static jint JNICALL GetVersion(JNIEnv* env) @@ -1092,10 +1092,10 @@ private: } public: - ProxyJNIEnv(nsIJVMPlugin* jvmPlugin, nsISecureJNI2* secureEnv); + ProxyJNIEnv(nsIJVMPlugin* jvmPlugin, nsISecureEnv* secureEnv); ~ProxyJNIEnv(); - nsISecureJNI2* getSecureEnv() { return mSecureEnv; } + nsISecureEnv* getSecureEnv() { return mSecureEnv; } }; JNINativeInterface_ ProxyJNIEnv::theFuncs = { @@ -1477,7 +1477,7 @@ JNINativeInterface_ ProxyJNIEnv::theFuncs = { nsHashtable* ProxyJNIEnv::theIDTable = NULL; -ProxyJNIEnv::ProxyJNIEnv(nsIJVMPlugin* jvmPlugin, nsISecureJNI2* secureEnv) +ProxyJNIEnv::ProxyJNIEnv(nsIJVMPlugin* jvmPlugin, nsISecureEnv* secureEnv) : mSecureEnv(secureEnv), mContext(NULL), mJavaThread(NULL) { nsresult result; @@ -1485,7 +1485,7 @@ ProxyJNIEnv::ProxyJNIEnv(nsIJVMPlugin* jvmPlugin, nsISecureJNI2* secureEnv) if (theIDTable == NULL) theIDTable = new nsHashtable(); - // Ask the JVM for a new nsISecureJNI2, if none provided. + // Ask the JVM for a new nsISecureEnv, if none provided. if (secureEnv == NULL) result = jvmPlugin->CreateSecureEnv(this, &mSecureEnv); } @@ -1498,7 +1498,7 @@ ProxyJNIEnv::~ProxyJNIEnv() mSecureEnv->Release(); } -JNIEnv* CreateProxyJNI(nsIJVMPlugin* jvmPlugin, nsISecureJNI2* inSecureEnv) +JNIEnv* CreateProxyJNI(nsIJVMPlugin* jvmPlugin, nsISecureEnv* inSecureEnv) { return new ProxyJNIEnv(jvmPlugin, inSecureEnv); } @@ -1510,7 +1510,7 @@ void DeleteProxyJNI(JNIEnv* env) delete proxyEnv; } -nsISecureJNI2* GetSecureEnv(JNIEnv* env) +nsISecureEnv* GetSecureEnv(JNIEnv* env) { ProxyJNIEnv* proxyEnv = (ProxyJNIEnv*)env; return proxyEnv->getSecureEnv(); diff --git a/mozilla/modules/oji/src/lcglue.cpp b/mozilla/modules/oji/src/lcglue.cpp index d2748c790b6..2db0cf0fc84 100644 --- a/mozilla/modules/oji/src/lcglue.cpp +++ b/mozilla/modules/oji/src/lcglue.cpp @@ -221,25 +221,19 @@ map_java_object_to_js_object_impl(JNIEnv *env, void *pNSIPluginInstanceIn, char /* ** Check for the mayscript tag. */ - nsIPluginInstance* pPIT; - pPIT = (nsIPluginInstance*)pNSIPluginInstanceIn; - if ( (err == NS_OK) && (pPIT != NULL) ) { - nsIJVMPluginInstance* pJVMPIT; - if (pPIT->QueryInterface(kIJVMPluginInstanceIID, - (void**)&pJVMPIT) == NS_OK) { - nsIPluginInstancePeer* pPITP; - err = pJVMPIT->GetPeer((nsIPluginInstancePeer**)&pPITP); - if ( (err == NS_OK) &&(pPITP != NULL) ) { - nsIJVMPluginTagInfo* pJVMTagInfo; - if (pPITP->QueryInterface(kIJVMPluginTagInfoIID, - (void**)&pJVMTagInfo) == NS_OK) { - err = pJVMTagInfo->GetMayScript(&mayscript); - PR_ASSERT(err != NS_OK ? mayscript == PR_FALSE : PR_TRUE); - pJVMTagInfo->Release(); - } - pPITP->Release(); + nsIPluginInstance* pluginInstance = (nsIPluginInstance*)pNSIPluginInstanceIn; + if ( (err == NS_OK) && (pluginInstance != NULL) ) { + nsIPluginInstancePeer* pluginPeer; + err = pluginInstance->GetPeer((nsIPluginInstancePeer**)&pluginPeer); + if ( (err == NS_OK) &&(pluginPeer != NULL) ) { + nsIJVMPluginTagInfo* pJVMTagInfo; + if (pluginPeer->QueryInterface(kIJVMPluginTagInfoIID, + (void**)&pJVMTagInfo) == NS_OK) { + err = pJVMTagInfo->GetMayScript(&mayscript); + PR_ASSERT(err != NS_OK ? mayscript == PR_FALSE : PR_TRUE); + pJVMTagInfo->Release(); } - pJVMPIT->Release(); + pluginPeer->Release(); } } diff --git a/mozilla/modules/oji/src/nsJVMManager.cpp b/mozilla/modules/oji/src/nsJVMManager.cpp index 8eb3bfaded1..42c5e8a62ae 100644 --- a/mozilla/modules/oji/src/nsJVMManager.cpp +++ b/mozilla/modules/oji/src/nsJVMManager.cpp @@ -73,6 +73,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIJVMManagerIID, NS_IJVMMANAGER_IID); static NS_DEFINE_IID(kIThreadManagerIID, NS_ITHREADMANAGER_IID); static NS_DEFINE_IID(kIJVMPluginIID, NS_IJVMPLUGIN_IID); +static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID); static NS_DEFINE_IID(kISymantecDebugManagerIID, NS_ISYMANTECDEBUGMANAGER_IID); static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); @@ -101,7 +102,7 @@ GetRunningJVM() } NS_METHOD -nsJVMManager::CreateProxyJNI(nsISecureJNI2* inSecureEnv, JNIEnv** outProxyEnv) +nsJVMManager::CreateProxyJNI(nsISecureEnv* inSecureEnv, JNIEnv** outProxyEnv) { JVMContext* context = GetJVMContext(); if (context->proxyEnv != NULL) { @@ -437,27 +438,34 @@ nsJVMManager::StartupJVM(void) ** nsIPlugin* plugin = NPL_LoadPluginByType(NS_JVM_MIME_TYPE); */ - /*nsIPluginHost* pNSIPluginHost = NULL; - nsresult err = g_pNSIServiceManager->GetService(kPluginManagerCID, kPluginHostIID, (nsISupports**)&pNSIPluginHost);*/ - - nsresult err = g_pNSIServiceManager->GetService(kPluginManagerCID, kPluginManagerIID, (nsISupports**)&plugin); + nsIPluginHost* pluginHost = NULL; + nsresult err = g_pNSIServiceManager->GetService(kPluginManagerCID, kPluginHostIID, (nsISupports**)&pluginHost); if (err != NS_OK) { fStatus = nsJVMStatus_Failed; return fStatus; } - if (plugin == NULL) { + if (pluginHost == NULL) { fStatus = nsJVMStatus_Failed; return fStatus; } - nsresult rslt = plugin->QueryInterface(kIJVMPluginIID, (void**)&fJVM); + nsIPlugin* pluginFactory = NULL; + err = pluginHost->GetPluginFactory(NS_JVM_MIME_TYPE, &pluginFactory); + if (pluginFactory == NULL) { + fStatus = nsJVMStatus_Failed; + return fStatus; + } + + nsresult rslt = pluginFactory->QueryInterface(kIJVMPluginIID, (void**)&fJVM); if (rslt != NS_OK) { PR_ASSERT(fJVM == NULL); fStatus = nsJVMStatus_Failed; return fStatus; } + // beard: do we really need an explicit startup mechanim for the JVM? +#if 0 // Get an execution environment -- that will cause the VM to start up JNIEnv* env = NULL; rslt = fJVM->GetJNIEnv(&env); @@ -468,6 +476,7 @@ nsJVMManager::StartupJVM(void) /* else the JVM is running. */ fStatus = nsJVMStatus_Running; } +#endif #if 0 JSContext* crippledContext = LM_GetCrippledContext(); diff --git a/mozilla/modules/oji/src/nsJVMManager.h b/mozilla/modules/oji/src/nsJVMManager.h index b839436ade9..c382110d91b 100644 --- a/mozilla/modules/oji/src/nsJVMManager.h +++ b/mozilla/modules/oji/src/nsJVMManager.h @@ -56,7 +56,7 @@ public: * the same proxy JNI. */ NS_IMETHOD - CreateProxyJNI(nsISecureJNI2* inSecureEnv, JNIEnv** outProxyEnv); + CreateProxyJNI(nsISecureEnv* inSecureEnv, JNIEnv** outProxyEnv); /** * Returns the proxy JNI associated with the current thread, or NULL if no diff --git a/mozilla/modules/plugin/base/public/nsIPluginInstance.h b/mozilla/modules/plugin/base/public/nsIPluginInstance.h index 314c64a0e62..03418c95a35 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginInstance.h +++ b/mozilla/modules/plugin/base/public/nsIPluginInstance.h @@ -35,7 +35,7 @@ #define nsIPluginInstance_h___ #include "nsplugindefs.h" -#include "nsIEventHandler.h" +#include "nsISupports.h" #ifdef NEW_PLUGIN_STREAM_API #include "nsIPluginStreamListener.h" @@ -61,7 +61,7 @@ * Destroy -- called once, before the plugin instance peer is to be * destroyed. This method is used to destroy the plugin instance. */ -class nsIPluginInstance : public nsIEventHandler { +class nsIPluginInstance : public nsISupports { public: /** @@ -198,6 +198,25 @@ public: NS_IMETHOD GetValue(nsPluginInstanceVariable variable, void *value) = 0; + /** + * Handles an event. An nsIEventHandler can also get registered with with + * nsIPluginManager2::RegisterWindow and will be called whenever an event + * comes in for that window. + * + * Note that for Unix and Mac the nsPluginEvent structure is different + * from the old NPEvent structure -- it's no longer the native event + * record, but is instead a struct. This was done for future extensibility, + * and so that the Mac could receive the window argument too. For Windows + * and OS2, it's always been a struct, so there's no change for them. + * + * (Corresponds to NPP_HandleEvent.) + * + * @param event - the event to be handled + * @param handled - set to PR_TRUE if event was handled + * @result - NS_OK if this operation was successful + */ + NS_IMETHOD + HandleEvent(nsPluginEvent* event, PRBool* handled) = 0; }; #define NS_IPLUGININSTANCE_IID \ diff --git a/mozilla/modules/plugin/base/public/nsplugindefs.h b/mozilla/modules/plugin/base/public/nsplugindefs.h index 5a0a76d76f5..e2b1e401ed4 100644 --- a/mozilla/modules/plugin/base/public/nsplugindefs.h +++ b/mozilla/modules/plugin/base/public/nsplugindefs.h @@ -317,10 +317,11 @@ struct nsPluginEvent { */ enum nsPluginEventType { #ifdef XP_MAC - nsPluginEventType_GetFocusEvent = (osEvt + 16), - nsPluginEventType_LoseFocusEvent = (osEvt + 17), - nsPluginEventType_AdjustCursorEvent = (osEvt + 18), - nsPluginEventType_MenuCommandEvent = (osEvt + 19), + nsPluginEventType_GetFocusEvent = (osEvt + 16), + nsPluginEventType_LoseFocusEvent, + nsPluginEventType_AdjustCursorEvent, + nsPluginEventType_MenuCommandEvent, + nsPluginEventType_ClippingChangedEvent, #endif /* XP_MAC */ nsPluginEventType_Idle = 0 }; diff --git a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp index 0e40312b4f3..cf5e550853d 100644 --- a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp @@ -299,7 +299,6 @@ NS_IMPL_ADDREF(ns4xPluginInstance); NS_IMPL_RELEASE(ns4xPluginInstance); static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); -static NS_DEFINE_IID(kIEventHandlerIID, NS_IEVENTHANDLER_IID); static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -315,13 +314,6 @@ NS_IMETHODIMP ns4xPluginInstance :: QueryInterface(const nsIID& iid, void** inst return NS_OK; } - if (iid.Equals(kIEventHandlerIID)) - { - *instance = (void *)(nsIEventHandler *)this; - AddRef(); - return NS_OK; - } - if (iid.Equals(kISupportsIID)) { *instance = (void *)(nsISupports *)this; diff --git a/mozilla/modules/plugin/base/src/nsIPluginHost.h b/mozilla/modules/plugin/base/src/nsIPluginHost.h index 25502d70c92..a96e10654e5 100644 --- a/mozilla/modules/plugin/base/src/nsIPluginHost.h +++ b/mozilla/modules/plugin/base/src/nsIPluginHost.h @@ -26,6 +26,7 @@ #include "nsIPluginInstanceOwner.h" #include "nsIStreamListener.h" +class nsIPlugin; class nsIURL; #define NS_IPLUGINHOST_IID \ @@ -44,6 +45,9 @@ public: NS_IMETHOD LoadPlugins(void) = 0; + + NS_IMETHOD + GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) = 0; NS_IMETHOD InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner) = 0; diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index b6a65ca9338..2805f3c55e5 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -48,6 +48,11 @@ #include "winbase.h" #endif +#ifdef XP_MAC +#include "nsFileSpec.h" +#include "nsPluginsDir.h" +#endif + //uncomment this to use netlib to determine what the //user agent string is. we really *want* to do this, //can't today since netlib returns 4.05, but this @@ -1511,6 +1516,9 @@ NS_IMETHODIMP nsPluginHostImpl :: Init(void) NS_RELEASE(object); } + // eagerly load them as a test. + LoadPlugins(); + return rv; } @@ -1811,6 +1819,98 @@ NS_IMETHODIMP nsPluginHostImpl :: SetUpPluginInstance(const char *aMimeType, } } +NS_IMETHODIMP nsPluginHostImpl :: GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) +{ + *aPlugin = NULL; + return NS_ERROR_NOT_IMPLEMENTED; +} + +#ifdef XP_MAC + +#include +#include + +static nsresult getApplicationDir(nsNativeFileSpec& outAppDir) +{ + // Use the process manager to get the application's FSSpec, + // then construct an nsNativeFileSpec that encapsulates it. + FSSpec spec; + ProcessInfoRec info; + info.processInfoLength = sizeof(info); + info.processName = NULL; + info.processAppSpec = &spec; + ProcessSerialNumber psn = { 0, kCurrentProcess }; + OSErr result = GetProcessInformation(&psn, &info); + nsNativeFileSpec appSpec(spec); + appSpec.GetParent(outAppDir); + return NS_OK; +} + +nsPluginsDir::nsPluginsDir() +{ + // Use the folder manager to get location of Extensions folder, and + // build an FSSpec for "Netscape Plugins" within it. + FSSpec& pluginsDir = *this; + OSErr result = FindFolder(kOnSystemDisk, + kExtensionFolderType, + kDontCreateFolder, + &pluginsDir.vRefNum, + &pluginsDir.parID); + if (result == noErr) { + SetLeafName("Netscape Plugins"); + } +} + +nsPluginsDir::~nsPluginsDir() {} + +bool nsPluginsDir::IsPluginFile(const nsNativeFileSpec& fileSpec) +{ + return true; +} + +// excuse me while I try to rewrite this using XP code... + +NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() +{ + do { + // 1. scan the plugins directory (where is it?) for eligible plugin libraries. +#if 0 + nsNativeFileSpec applicationDir; + if (getApplicationDir(applicationDir) != NS_OK) + break; + + nsPluginsDir pluginsDir = applicationDir + "plugins"; + if (! pluginsDir.Valid()) + break; +#else + nsPluginsDir pluginsDir; + if (! pluginsDir.Valid()) + break; +#endif + + for (nsDirectoryIterator iter(pluginsDir); iter; iter++) { + const nsNativeFileSpec& pluginFile = iter; + // see if the file is in fact a library. + PRLibrary* pluginLibrary = LoadPluginLibrary(pluginFile); + if (pluginLibrary != NULL) { + // create a tag describing this plugin. + nsPluginTag* pluginTag = new nsPluginTag(); + pluginTag->mNext = mPlugins; + mPlugins = pluginTag; + // GetLeafName() returns a copy allocated with new. + pluginTag->mName = pluginFile.GetLeafName(); + } + } + + mPluginsLoaded = PR_TRUE; + return NS_OK; + } while (0); + + return NS_ERROR_FAILURE; +} + +#else + NS_IMETHODIMP nsPluginHostImpl :: LoadPlugins(void) { #ifdef XP_PC @@ -2169,9 +2269,30 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS return NS_OK; } +#endif /* !XP_MAC */ // private methods +PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const nsNativeFileSpec &pluginSpec) +{ + PRLibrary* plugin = NULL; + +#ifdef XP_PC + plugin = PR_LoadLibrary((const char*)pluginSpec); +#endif + +#ifdef XP_MAC + char* pluginName = pluginSpec.GetLeafName(); + if (pluginName != NULL) { + plugin = PR_LoadLibrary(pluginName); + delete[] pluginName; + } +#endif + + return plugin; +} + + PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path) { #ifdef XP_PC @@ -2200,6 +2321,7 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha #endif } + /* Called by GetURL and PostURL */ #ifdef NEW_PLUGIN_STREAM_API diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index 8566ed09ed3..2cc9619224d 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -29,6 +29,7 @@ #include "nsIFileUtilities.h" class ns4xPlugin; +class nsNativeFileSpec; class nsPluginTag { @@ -131,6 +132,9 @@ public: NS_IMETHOD LoadPlugins(void); + + NS_IMETHOD + GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin); NS_IMETHOD InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner); @@ -211,6 +215,8 @@ private: nsresult NewFullPagePluginStream(nsIStreamListener *&aStreamListener, nsIPluginInstance *aInstance); + PRLibrary* LoadPluginLibrary(const nsNativeFileSpec &pluginSpec); + PRLibrary* LoadPluginLibrary(const char* pluginPath, const char* path); char *mPluginPath; diff --git a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp index 0e40312b4f3..cf5e550853d 100644 --- a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp +++ b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp @@ -299,7 +299,6 @@ NS_IMPL_ADDREF(ns4xPluginInstance); NS_IMPL_RELEASE(ns4xPluginInstance); static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); -static NS_DEFINE_IID(kIEventHandlerIID, NS_IEVENTHANDLER_IID); static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -315,13 +314,6 @@ NS_IMETHODIMP ns4xPluginInstance :: QueryInterface(const nsIID& iid, void** inst return NS_OK; } - if (iid.Equals(kIEventHandlerIID)) - { - *instance = (void *)(nsIEventHandler *)this; - AddRef(); - return NS_OK; - } - if (iid.Equals(kISupportsIID)) { *instance = (void *)(nsISupports *)this; diff --git a/mozilla/modules/plugin/nglsrc/nsIPluginHost.h b/mozilla/modules/plugin/nglsrc/nsIPluginHost.h index 25502d70c92..a96e10654e5 100644 --- a/mozilla/modules/plugin/nglsrc/nsIPluginHost.h +++ b/mozilla/modules/plugin/nglsrc/nsIPluginHost.h @@ -26,6 +26,7 @@ #include "nsIPluginInstanceOwner.h" #include "nsIStreamListener.h" +class nsIPlugin; class nsIURL; #define NS_IPLUGINHOST_IID \ @@ -44,6 +45,9 @@ public: NS_IMETHOD LoadPlugins(void) = 0; + + NS_IMETHOD + GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) = 0; NS_IMETHOD InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner) = 0; diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index b6a65ca9338..2805f3c55e5 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -48,6 +48,11 @@ #include "winbase.h" #endif +#ifdef XP_MAC +#include "nsFileSpec.h" +#include "nsPluginsDir.h" +#endif + //uncomment this to use netlib to determine what the //user agent string is. we really *want* to do this, //can't today since netlib returns 4.05, but this @@ -1511,6 +1516,9 @@ NS_IMETHODIMP nsPluginHostImpl :: Init(void) NS_RELEASE(object); } + // eagerly load them as a test. + LoadPlugins(); + return rv; } @@ -1811,6 +1819,98 @@ NS_IMETHODIMP nsPluginHostImpl :: SetUpPluginInstance(const char *aMimeType, } } +NS_IMETHODIMP nsPluginHostImpl :: GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) +{ + *aPlugin = NULL; + return NS_ERROR_NOT_IMPLEMENTED; +} + +#ifdef XP_MAC + +#include +#include + +static nsresult getApplicationDir(nsNativeFileSpec& outAppDir) +{ + // Use the process manager to get the application's FSSpec, + // then construct an nsNativeFileSpec that encapsulates it. + FSSpec spec; + ProcessInfoRec info; + info.processInfoLength = sizeof(info); + info.processName = NULL; + info.processAppSpec = &spec; + ProcessSerialNumber psn = { 0, kCurrentProcess }; + OSErr result = GetProcessInformation(&psn, &info); + nsNativeFileSpec appSpec(spec); + appSpec.GetParent(outAppDir); + return NS_OK; +} + +nsPluginsDir::nsPluginsDir() +{ + // Use the folder manager to get location of Extensions folder, and + // build an FSSpec for "Netscape Plugins" within it. + FSSpec& pluginsDir = *this; + OSErr result = FindFolder(kOnSystemDisk, + kExtensionFolderType, + kDontCreateFolder, + &pluginsDir.vRefNum, + &pluginsDir.parID); + if (result == noErr) { + SetLeafName("Netscape Plugins"); + } +} + +nsPluginsDir::~nsPluginsDir() {} + +bool nsPluginsDir::IsPluginFile(const nsNativeFileSpec& fileSpec) +{ + return true; +} + +// excuse me while I try to rewrite this using XP code... + +NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() +{ + do { + // 1. scan the plugins directory (where is it?) for eligible plugin libraries. +#if 0 + nsNativeFileSpec applicationDir; + if (getApplicationDir(applicationDir) != NS_OK) + break; + + nsPluginsDir pluginsDir = applicationDir + "plugins"; + if (! pluginsDir.Valid()) + break; +#else + nsPluginsDir pluginsDir; + if (! pluginsDir.Valid()) + break; +#endif + + for (nsDirectoryIterator iter(pluginsDir); iter; iter++) { + const nsNativeFileSpec& pluginFile = iter; + // see if the file is in fact a library. + PRLibrary* pluginLibrary = LoadPluginLibrary(pluginFile); + if (pluginLibrary != NULL) { + // create a tag describing this plugin. + nsPluginTag* pluginTag = new nsPluginTag(); + pluginTag->mNext = mPlugins; + mPlugins = pluginTag; + // GetLeafName() returns a copy allocated with new. + pluginTag->mName = pluginFile.GetLeafName(); + } + } + + mPluginsLoaded = PR_TRUE; + return NS_OK; + } while (0); + + return NS_ERROR_FAILURE; +} + +#else + NS_IMETHODIMP nsPluginHostImpl :: LoadPlugins(void) { #ifdef XP_PC @@ -2169,9 +2269,30 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS return NS_OK; } +#endif /* !XP_MAC */ // private methods +PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const nsNativeFileSpec &pluginSpec) +{ + PRLibrary* plugin = NULL; + +#ifdef XP_PC + plugin = PR_LoadLibrary((const char*)pluginSpec); +#endif + +#ifdef XP_MAC + char* pluginName = pluginSpec.GetLeafName(); + if (pluginName != NULL) { + plugin = PR_LoadLibrary(pluginName); + delete[] pluginName; + } +#endif + + return plugin; +} + + PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path) { #ifdef XP_PC @@ -2200,6 +2321,7 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha #endif } + /* Called by GetURL and PostURL */ #ifdef NEW_PLUGIN_STREAM_API diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h index 8566ed09ed3..2cc9619224d 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h @@ -29,6 +29,7 @@ #include "nsIFileUtilities.h" class ns4xPlugin; +class nsNativeFileSpec; class nsPluginTag { @@ -131,6 +132,9 @@ public: NS_IMETHOD LoadPlugins(void); + + NS_IMETHOD + GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin); NS_IMETHOD InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner); @@ -211,6 +215,8 @@ private: nsresult NewFullPagePluginStream(nsIStreamListener *&aStreamListener, nsIPluginInstance *aInstance); + PRLibrary* LoadPluginLibrary(const nsNativeFileSpec &pluginSpec); + PRLibrary* LoadPluginLibrary(const char* pluginPath, const char* path); char *mPluginPath; diff --git a/mozilla/modules/plugin/public/nsIPluginInstance.h b/mozilla/modules/plugin/public/nsIPluginInstance.h index 314c64a0e62..03418c95a35 100644 --- a/mozilla/modules/plugin/public/nsIPluginInstance.h +++ b/mozilla/modules/plugin/public/nsIPluginInstance.h @@ -35,7 +35,7 @@ #define nsIPluginInstance_h___ #include "nsplugindefs.h" -#include "nsIEventHandler.h" +#include "nsISupports.h" #ifdef NEW_PLUGIN_STREAM_API #include "nsIPluginStreamListener.h" @@ -61,7 +61,7 @@ * Destroy -- called once, before the plugin instance peer is to be * destroyed. This method is used to destroy the plugin instance. */ -class nsIPluginInstance : public nsIEventHandler { +class nsIPluginInstance : public nsISupports { public: /** @@ -198,6 +198,25 @@ public: NS_IMETHOD GetValue(nsPluginInstanceVariable variable, void *value) = 0; + /** + * Handles an event. An nsIEventHandler can also get registered with with + * nsIPluginManager2::RegisterWindow and will be called whenever an event + * comes in for that window. + * + * Note that for Unix and Mac the nsPluginEvent structure is different + * from the old NPEvent structure -- it's no longer the native event + * record, but is instead a struct. This was done for future extensibility, + * and so that the Mac could receive the window argument too. For Windows + * and OS2, it's always been a struct, so there's no change for them. + * + * (Corresponds to NPP_HandleEvent.) + * + * @param event - the event to be handled + * @param handled - set to PR_TRUE if event was handled + * @result - NS_OK if this operation was successful + */ + NS_IMETHOD + HandleEvent(nsPluginEvent* event, PRBool* handled) = 0; }; #define NS_IPLUGININSTANCE_IID \ diff --git a/mozilla/modules/plugin/public/nsplugindefs.h b/mozilla/modules/plugin/public/nsplugindefs.h index 5a0a76d76f5..e2b1e401ed4 100644 --- a/mozilla/modules/plugin/public/nsplugindefs.h +++ b/mozilla/modules/plugin/public/nsplugindefs.h @@ -317,10 +317,11 @@ struct nsPluginEvent { */ enum nsPluginEventType { #ifdef XP_MAC - nsPluginEventType_GetFocusEvent = (osEvt + 16), - nsPluginEventType_LoseFocusEvent = (osEvt + 17), - nsPluginEventType_AdjustCursorEvent = (osEvt + 18), - nsPluginEventType_MenuCommandEvent = (osEvt + 19), + nsPluginEventType_GetFocusEvent = (osEvt + 16), + nsPluginEventType_LoseFocusEvent, + nsPluginEventType_AdjustCursorEvent, + nsPluginEventType_MenuCommandEvent, + nsPluginEventType_ClippingChangedEvent, #endif /* XP_MAC */ nsPluginEventType_Idle = 0 };