loading: it depends on jvm.dll, which was not on my path. I had to add %JDKHOME%\jre\bin\client to my path and now it loaded. Thanks to shaver and plasticmillion on #developers for the tip to use depends.exe, the Dependency Walker. What a nice tool. Of course, there is now a crash after it loads, which will be my next step after this checkin. A plugins/src/iPlugletEngine.idl A plugins/src/iPlugletManager.idl - make IDL files for our external interfaces. M plugins/src/Makefile.in - move PlugletEngine.cpp to the top of the list. M plugins/src/PlugletEngine.cpp M plugins/src/PlugletEngine.h - big changes here. Make this a proper generic XPCOM component. - use the iPlugletManager interface, and the nsICategoryManager to make sure we get called at startup. M plugins/src/Pluglet.cpp M plugins/src/Pluglet.h M plugins/src/PlugletFactory.cpp M plugins/src/PlugletFactory.h M plugins/src/PlugletInputStream.cpp M plugins/src/PlugletInputStream.h M plugins/src/PlugletLoader.cpp M plugins/src/PlugletManager.cpp M plugins/src/PlugletPeer.cpp M plugins/src/PlugletStreamInfo.cpp M plugins/src/PlugletStreamListener.cpp M plugins/src/PlugletViewWindows.cpp M plugins/src/PlugletsDir.cpp M plugins/src/Registry.cpp - remove static method PlugletEngine::GetJNIEnv, in favor of instance method and use of nsIServiceManager. git-svn-id: svn://10.0.0.236/trunk@200339 18797224-902f-48f8-a5cc-f745e15eee43
240 lines
6.6 KiB
C++
240 lines
6.6 KiB
C++
/*
|
|
* 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 Sun Microsystems,
|
|
* Inc. Portions created by Sun are
|
|
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
|
* Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
*/
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "PlugletFactory.h"
|
|
#include "iPlugletEngine.h"
|
|
#include "PlugletLoader.h"
|
|
#include "Pluglet.h"
|
|
#include "plstr.h"
|
|
#include "PlugletLog.h"
|
|
|
|
jmethodID PlugletFactory::createPlugletMID = NULL;
|
|
jmethodID PlugletFactory::initializeMID = NULL;
|
|
jmethodID PlugletFactory::shutdownMID = NULL;
|
|
|
|
|
|
nsresult PlugletFactory::CreatePluginInstance(const char* aPluginMIMEType, void **aResult) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("PlugletFactory::CreatePluginInstance\n"));
|
|
if(!aResult
|
|
|| Initialize() != NS_OK) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
JNIEnv *env = nsnull;
|
|
nsresult rv;
|
|
rv = plugletEngine->GetJNIEnv(&env);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("Pluglet::Initialize: plugletEngine->GetJNIEnv failed\n"));
|
|
return rv;
|
|
}
|
|
jstring jstr = env->NewStringUTF(aPluginMIMEType);
|
|
jobject obj = env->CallObjectMethod(jthis,createPlugletMID, jstr);
|
|
if (env->ExceptionOccurred()) {
|
|
env->ExceptionDescribe();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
if (!obj) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
nsISupports * instance = new Pluglet(obj);
|
|
NS_ADDREF(instance);
|
|
*aResult = instance;
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult PlugletFactory::Initialize(void) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("PlugletFactory::Initialize\n"));
|
|
JNIEnv *env = nsnull;
|
|
nsresult rv;
|
|
rv = plugletEngine->GetJNIEnv(&env);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("Pluglet::Initialize: plugletEngine->GetJNIEnv failed\n"));
|
|
return rv;
|
|
}
|
|
|
|
if (!initializeMID) {
|
|
jclass clazz = env->FindClass("org/mozilla/pluglet/PlugletFactory");
|
|
if(!clazz) {
|
|
env->ExceptionDescribe();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
createPlugletMID = env->GetMethodID(clazz,"createPluglet","(Ljava/lang/String;)Lorg/mozilla/pluglet/Pluglet;");
|
|
if (!createPlugletMID) {
|
|
env->ExceptionDescribe();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
shutdownMID = env->GetMethodID(clazz,"shutdown","()V");
|
|
if (!shutdownMID) {
|
|
env->ExceptionDescribe();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
initializeMID = env->GetMethodID(clazz,"initialize","(Lorg/mozilla/pluglet/mozilla/PlugletManager;)V");
|
|
if (!initializeMID) {
|
|
env->ExceptionDescribe();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
}
|
|
if (!jthis) {
|
|
jthis = PlugletLoader::GetPluglet(path);
|
|
if (!jthis) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
jobject plugletEngineObj = nsnull;
|
|
rv = plugletEngine->GetPlugletManager((void **) &plugletEngineObj);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
env->CallVoidMethod(jthis,initializeMID,plugletEngineObj);
|
|
if (env->ExceptionOccurred()) {
|
|
env->ExceptionDescribe();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult PlugletFactory::Shutdown(void) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("PlugletFactory::Shutdown\n"));
|
|
|
|
if(!jthis) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
JNIEnv *env = nsnull;
|
|
nsresult rv;
|
|
rv = plugletEngine->GetJNIEnv(&env);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("Pluglet::Initialize: plugletEngine->GetJNIEnv failed\n"));
|
|
return rv;
|
|
}
|
|
env->CallVoidMethod(jthis,shutdownMID);
|
|
if (env->ExceptionOccurred()) {
|
|
env->ExceptionDescribe();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult PlugletFactory::GetMIMEDescription(const char* *result) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("PlugletFactory::GetMimeDescription\n"));
|
|
if(!result) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
*result = mimeDescription;
|
|
return (*result) ? NS_OK : NS_ERROR_FAILURE;
|
|
}
|
|
|
|
PlugletFactory::PlugletFactory(const char *mimeDescription, const char *path) : plugletEngine(nsnull) {
|
|
jthis = NULL;
|
|
this->path = new char[strlen(path)+1];
|
|
strcpy(this->path,path);
|
|
this->mimeDescription = new char[strlen(mimeDescription)+1];
|
|
strcpy(this->mimeDescription,mimeDescription);
|
|
|
|
nsIServiceManager *servman = nsnull;
|
|
NS_GetServiceManager(&servman);
|
|
nsresult rv;
|
|
rv = servman->GetServiceByContractID(PLUGLETENGINE_ContractID,
|
|
NS_GET_IID(iPlugletEngine),
|
|
getter_AddRefs(plugletEngine));
|
|
if (NS_FAILED(rv)) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("Pluglet::PlugletFactory: Cannot access iPlugletEngine service\n"));
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
PlugletFactory::~PlugletFactory(void) {
|
|
if (path != NULL) {
|
|
delete[] path;
|
|
}
|
|
if (mimeDescription != NULL) {
|
|
delete[] mimeDescription;
|
|
}
|
|
JNIEnv *env = nsnull;
|
|
nsresult rv;
|
|
rv = plugletEngine->GetJNIEnv(&env);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("PlugletFactory::~PlugletFactory: plugletEngine->GetJNIEnv failed\n"));
|
|
return;
|
|
}
|
|
|
|
if (env != NULL) {
|
|
env->DeleteGlobalRef(jthis);
|
|
}
|
|
}
|
|
|
|
PlugletFactory * PlugletFactory::Load(const char * path) {
|
|
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
|
|
("PlugletFactory::Load\n"));
|
|
char * mime = PlugletLoader::GetMIMEDescription(path);
|
|
PlugletFactory * result = NULL;
|
|
if (mime) {
|
|
result = new PlugletFactory(mime,path);
|
|
//delete[] mime; //nb we have a strange exception here
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/*
|
|
1 if good
|
|
0 if not good
|
|
*/
|
|
int PlugletFactory::Compare(const char *mimeType) {
|
|
/* mimedDescription mimeTypes:extensions:description
|
|
mimeTypes mimeType;mimeType;...
|
|
extensions extension;extension;...
|
|
*/
|
|
if (!mimeType) {
|
|
return 0;
|
|
}
|
|
char * terminator = strchr(mimeDescription,':'); // terminator have to be not equal to NULL;
|
|
char *p1 = mimeDescription;
|
|
char *p2 = strchr(p1,';');
|
|
while ( p1 != NULL && p1 < terminator ) {
|
|
size_t n = sizeof(char) * ( ( (p2 == NULL || p2 > terminator) ? terminator : p2) - p1 );
|
|
if (PL_strncasecmp(p1,mimeType,n) == 0) {
|
|
return 1;
|
|
}
|
|
p1 = p2 ;
|
|
if (p2 != NULL) {
|
|
p2 = strchr(++p2,';');
|
|
p1++;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|