A src/nsIPluglet.idl
M classes/org/mozilla/pluglet/Registry.java M dist/build.xml M examples/simple/src/main/java/simple/SimplePluglet.java M examples/simple/src/main/web/index.html M mozilla/Makefile.in M mozilla/nppluglet.cpp M mozilla/nppluglet.h M mozilla/nsScriptablePeer.cpp M netbeans/nbproject/build-impl.xml M netbeans/nbproject/genfiles.properties M netbeans/nbproject/project.properties M netbeans/nbproject/project.xml M src/Makefile.in M src/Pluglet.cpp M src/Pluglet.h M src/PlugletEngine.cpp M src/PlugletFactory.cpp M src/Registry.cpp M src/Registry.h R mozilla/nsIPluglet.idl - At this point, I can call from JavaScript and locate an arbitratily named method on the Pluglet instance that conforms to the signature of returning String, and taking 0 or more Strings as arguments. git-svn-id: svn://10.0.0.236/trunk@242001 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -34,17 +34,17 @@ IS_COMPONENT = 1
|
||||
|
||||
ifeq ($(OS_ARCH),Linux)
|
||||
INCLUDES := -I$(MOZ_JDKHOME)/include -I$(MOZ_JDKHOME)/include/linux $(INCLUDES) \
|
||||
-I$(DEPTH)/widget/src/gtk -I../src_share
|
||||
-I$(DEPTH)/widget/src/gtk
|
||||
else
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
INCLUDES := -I$(MOZ_JDKHOME)/include -I$(MOZ_JDKHOME)/include/win32 $(INCLUDES) \
|
||||
-I../src_share -I.
|
||||
-I -I.
|
||||
else
|
||||
ifeq ($(OS_ARCH),Darwin)
|
||||
INCLUDES := -I$(MOZ_JDKHOME)/include $(INCLUDES) -I../src_share -I.
|
||||
INCLUDES := -I$(MOZ_JDKHOME)/include $(INCLUDES) -I.
|
||||
else
|
||||
INCLUDES := -I$(MOZ_JDKHOME)/include -I$(MOZ_JDKHOME)/include/solaris $(INCLUDES) \
|
||||
-I$(DEPTH)/widget/src/gtk -I../src_share
|
||||
-I$(DEPTH)/widget/src/gtk
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@@ -81,6 +81,7 @@ endif
|
||||
endif
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIPluglet.idl \
|
||||
iPlugletEngine.idl \
|
||||
iPlugletManager.idl \
|
||||
$(NULL)
|
||||
|
||||
@@ -40,7 +40,10 @@ jmethodID Pluglet::printMID = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
|
||||
|
||||
NS_IMPL_ISUPPORTS1(Pluglet,nsIPluginInstance);
|
||||
NS_IMPL_ISUPPORTS2(Pluglet,
|
||||
nsIPluginInstance,
|
||||
nsIPluglet)
|
||||
|
||||
|
||||
Pluglet::Pluglet(jobject object) : peer(nsnull) {
|
||||
nsresult rv;
|
||||
@@ -299,6 +302,34 @@ NS_METHOD Pluglet::Print(nsPluginPrint* platformPrint) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP Pluglet::CallPlugletMethod(const char *methodName, PRUint32 *inArgc,
|
||||
char ***inArgv)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (NULL != methodName && 0 < strlen(methodName) && NULL != inArgc && NULL != inArgv) {
|
||||
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
||||
("Pluglet::CallPlugletMethod: methodName: %s\n", methodName));
|
||||
|
||||
jmethodID plugletMethodMID = Registry::GetMethodIDForPlugletMethod(jthis, methodName,
|
||||
(jint) *inArgc);
|
||||
if (NULL != plugletMethodMID) {
|
||||
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
||||
("Pluglet::CallPlugletMethod: found match for methodName: %s\n", methodName));
|
||||
}
|
||||
else {
|
||||
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
||||
("Pluglet::CallPlugletMethod: no match for methodName: %s\n", methodName));
|
||||
}
|
||||
}
|
||||
else {
|
||||
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
||||
("Pluglet::CallPlugletMethod: invalid arguments\n"));
|
||||
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
#include "nsplugin.h"
|
||||
#include "jni.h"
|
||||
#include "PlugletView.h"
|
||||
#include "nsIPluglet.h"
|
||||
|
||||
class iPlugletEngine;
|
||||
|
||||
class Pluglet : public nsIPluginInstance {
|
||||
class Pluglet : public nsIPluginInstance, public nsIPluglet {
|
||||
public:
|
||||
NS_IMETHOD HandleEvent(nsPluginEvent* event, PRBool* handled);
|
||||
NS_IMETHOD Initialize(nsIPluginInstancePeer* peer);
|
||||
@@ -38,6 +39,7 @@ class Pluglet : public nsIPluginInstance {
|
||||
NS_IMETHOD SetWindow(nsPluginWindow* window);
|
||||
NS_IMETHOD Print(nsPluginPrint* platformPrint);
|
||||
NS_IMETHOD GetValue(nsPluginInstanceVariable variable, void *value);
|
||||
NS_DECL_NSIPLUGLET
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
Pluglet(jobject object);
|
||||
|
||||
@@ -202,7 +202,7 @@ void PlugletEngine::StartJVM() {
|
||||
options[3].optionString=""; //-Djava.compiler=NONE";
|
||||
vm_args.version = JNI_VERSION_1_4;
|
||||
vm_args.options = options;
|
||||
vm_args.nOptions = 1; // EDBURNS: Change to 3 for debugging
|
||||
vm_args.nOptions = 1; // EDBURNS: Change to 3 for debugging, 1 for non-debuging
|
||||
vm_args.ignoreUnrecognized = JNI_FALSE;
|
||||
/* Create the Java VM */
|
||||
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
||||
|
||||
@@ -62,7 +62,7 @@ nsresult PlugletFactory::CreatePluginInstance(const char* aPluginMIMEType, void
|
||||
if (!obj) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsISupports * instance = new Pluglet(obj);
|
||||
Pluglet * instance = new Pluglet(obj);
|
||||
NS_ADDREF(instance);
|
||||
*aResult = instance;
|
||||
return NS_OK;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
jclass Registry::clazz = NULL;
|
||||
jmethodID Registry::setPeerMID = NULL;
|
||||
jmethodID Registry::removeMID = NULL;
|
||||
jmethodID Registry::findMatchingPlugletMethodMID = NULL;
|
||||
|
||||
void Registry::SetPeer(jobject key, jlong peer) {
|
||||
if (!clazz) {
|
||||
@@ -81,6 +82,71 @@ void Registry::Remove(jobject key) {
|
||||
}
|
||||
}
|
||||
|
||||
jmethodID Registry::GetMethodIDForPlugletMethod(jobject plugletInstance, const char *methodName,
|
||||
jint numStringArgs)
|
||||
{
|
||||
jmethodID result = NULL;
|
||||
|
||||
if (!clazz) { // it is impossible
|
||||
Initialize();
|
||||
if(!clazz) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == methodName || 0 == strlen(methodName)) {
|
||||
return result;
|
||||
}
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsCOMPtr<iPlugletEngine> plugletEngine =
|
||||
do_GetService(PLUGLETENGINE_ContractID, &rv);;
|
||||
if (NS_FAILED(rv)) {
|
||||
return result;
|
||||
}
|
||||
JNIEnv *env = nsnull;
|
||||
rv = plugletEngine->GetJNIEnv(&env);
|
||||
if (NS_FAILED(rv)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
env->ExceptionClear();
|
||||
|
||||
jstring methodNameJstr = env->NewStringUTF(methodName);
|
||||
jstring methodSignatureJstr;
|
||||
methodSignatureJstr = (jstring)
|
||||
env->CallStaticObjectMethod(clazz, findMatchingPlugletMethodMID,
|
||||
plugletInstance, methodNameJstr, numStringArgs);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
return result;
|
||||
}
|
||||
|
||||
if (NULL != methodSignatureJstr) {
|
||||
jboolean isCopy;
|
||||
const char *signature = env->GetStringUTFChars(methodSignatureJstr, &isCopy);
|
||||
|
||||
if (NULL != signature) {
|
||||
jclass plugletClass = env->GetObjectClass(plugletInstance);
|
||||
result = env->GetMethodID(plugletClass, methodName, signature);
|
||||
if (isCopy == JNI_TRUE) {
|
||||
env->ReleaseStringUTFChars(methodSignatureJstr, signature);
|
||||
}
|
||||
}
|
||||
env->DeleteLocalRef(methodSignatureJstr);
|
||||
}
|
||||
|
||||
env->DeleteLocalRef(methodNameJstr);
|
||||
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Registry::Initialize() {
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsCOMPtr<iPlugletEngine> plugletEngine =
|
||||
@@ -114,6 +180,14 @@ void Registry::Initialize() {
|
||||
clazz = NULL;
|
||||
return;
|
||||
}
|
||||
findMatchingPlugletMethodMID = env->GetStaticMethodID(clazz,"findMatchingPlugletMethod","(Lorg/mozilla/pluglet/Pluglet;Ljava/lang/String;I)Ljava/lang/String;");
|
||||
if (!findMatchingPlugletMethodMID) {
|
||||
env->ExceptionDescribe();
|
||||
clazz = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,11 +25,14 @@ class Registry {
|
||||
public:
|
||||
static void SetPeer(jobject key, jlong peer);
|
||||
static void Remove(jobject key);
|
||||
static jmethodID GetMethodIDForPlugletMethod(jobject plugletInstance, const char *methodName,
|
||||
jint numStringArgs);
|
||||
private:
|
||||
static void Initialize();
|
||||
static jclass clazz;
|
||||
static jmethodID setPeerMID;
|
||||
static jmethodID removeMID;
|
||||
static jmethodID findMatchingPlugletMethodMID;
|
||||
};
|
||||
#endif /* __Registry_h__ */
|
||||
|
||||
|
||||
46
mozilla/java/plugins/src/nsIPluglet.idl
Executable file
46
mozilla/java/plugins/src/nsIPluglet.idl
Executable file
@@ -0,0 +1,46 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(482e1890-1fe5-11d5-9cf8-0060b0fbd8ac)]
|
||||
interface nsIPluglet : nsISupports {
|
||||
void callPlugletMethod(in string methodName,
|
||||
inout PRUint32 inArgc,
|
||||
[array, size_is(inArgc)] inout string inArgv);
|
||||
};
|
||||
Reference in New Issue
Block a user