Adding new files, breaking things out of jvmmgr.cpp (not online yet).

This commit is contained in:
warren%netscape.com 1998-10-06 05:59:16 +00:00
Родитель f9060926e2
Коммит c71d1b6264
4 изменённых файлов: 988 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,573 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
////////////////////////////////////////////////////////////////////////////////
// Plugin Manager Methods to support the JVM Plugin API
////////////////////////////////////////////////////////////////////////////////
#include "nsJVMManager.h"
#include "npglue.h"
#include "prefapi.h"
#include "np.h"
#include "prio.h"
#include "prmem.h"
#include "prthread.h"
#include "pprthred.h"
#include "plstr.h"
#include "jni.h"
#ifdef MOCHA
#include "libmocha.h"
#endif
extern "C" void jvm_InitLCGlue(void); // in lcglue.cpp
#include "xpgetstr.h"
extern "C" int XP_PROGRESS_STARTING_JAVA;
extern "C" int XP_PROGRESS_STARTING_JAVA_DONE;
extern "C" int XP_JAVA_NO_CLASSES;
extern "C" int XP_JAVA_GENERAL_FAILURE;
extern "C" int XP_JAVA_STARTUP_FAILED;
extern "C" int XP_JAVA_DEBUGGER_FAILED;
// FIXME -- need prototypes for these functions!!! XXX
#ifdef XP_MAC
extern "C" {
OSErr ConvertUnixPathToMacPath(const char *, char **);
void startAsyncCursors(void);
void stopAsyncCursors(void);
}
#endif // XP_MAC
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIJVMManagerIID, NS_IJVMMANAGER_IID);
static NS_DEFINE_IID(kIJVMPluginIID, NS_IJVMPLUGIN_IID);
static NS_DEFINE_IID(kISymantecDebugManagerIID, NS_ISYMANTECDEBUGMANAGER_IID);
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_AGGREGATED(nsJVMManager);
NS_METHOD
nsJVMManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
nsJVMManager* jvmmgr = new nsJVMManager(outer);
if (jvmmgr == NULL)
return NS_ERROR_OUT_OF_MEMORY;
jvmmgr->AddRef();
*aInstancePtr = outer ? (void*)jvmmgr->GetInner() : (void*)jvmmgr;
return NS_OK;
}
nsJVMManager::nsJVMManager(nsISupports* outer)
: fJVM(NULL), fStatus(nsJVMStatus_Enabled),
fRegisteredJavaPrefChanged(PR_FALSE), fDebugManager(NULL), fJSJavaVM(NULL),
fClassPathAdditions(new nsVector())
{
NS_INIT_AGGREGATED(outer);
}
nsJVMManager::~nsJVMManager()
{
int count = fClassPathAdditions->GetSize();
for (int i = 0; i < count; i++) {
PR_Free((*fClassPathAdditions)[i]);
}
delete fClassPathAdditions;
if (fJVM) {
/*nsrefcnt c =*/ fJVM->Release(); // Release for QueryInterface in GetJVM
// XXX unload plugin if c == 1 ? (should this be done inside Release?)
}
}
NS_METHOD
nsJVMManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aIID.Equals(kIJVMManagerIID)) {
*aInstancePtr = this;
AddRef();
return NS_OK;
}
#ifdef XP_PC
// Aggregates...
if (fDebugManager == NULL) {
nsresult rslt =
nsSymantecDebugManager::Create(this, kISupportsIID,
(void**)&fDebugManager, this);
if (rslt != NS_OK) return rslt;
}
return fDebugManager->QueryInterface(aIID, aInstancePtr);
#else
return NS_NOINTERFACE;
#endif
}
////////////////////////////////////////////////////////////////////////////////
#if 0
static const char*
ConvertToPlatformPathList(const char* cp)
{
const char* c = strdup(cp);
if (c == NULL)
return NULL;
#ifdef XP_MAC
{
const char* path;
const char* strtok_path;
char* result = (char*) malloc(1);
if (result == NULL)
return NULL;
result[0] = '\0';
path = c;
strtok_path = path;
#ifndef NSPR20
while ((path = XP_STRTOK(strtok_path, PATH_SEPARATOR_STR)))
#else
while ((path = XP_STRTOK(strtok_path, PR_PATH_SEPARATOR_STR)))
#endif
{
const char* macPath;
OSErr err = ConvertUnixPathToMacPath(path, &macPath);
char* r = PR_smprintf("%s\r%s", result, macPath);
strtok_path = NULL;
if (r == NULL)
return result; /* return what we could come up with */
free(result);
result = r;
}
free(c);
return result;
}
#else
return c;
#endif
}
#endif
void
nsJVMManager::ReportJVMError(nsresult err)
{
MWContext* cx = XP_FindSomeContext();
char *s = NULL;
switch (err) {
case NS_JVM_ERROR_NO_CLASSES: {
s = PR_smprintf(XP_GetString(XP_JAVA_NO_CLASSES));
break;
}
case NS_JVM_ERROR_JAVA_ERROR: {
nsIJVMPlugin* plugin = GetJVMPlugin();
PR_ASSERT(plugin != NULL);
if (plugin == NULL) break;
JNIEnv* env;
plugin->GetJNIEnv(&env);
const char* msg = GetJavaErrorString(env);
plugin->ReleaseJNIEnv(env);
#ifdef DEBUG
env->ExceptionDescribe();
#endif
s = PR_smprintf(XP_GetString(XP_JAVA_STARTUP_FAILED),
(msg ? msg : ""));
if (msg) free((void*)msg);
break;
}
case NS_JVM_ERROR_NO_DEBUGGER: {
s = PR_smprintf(XP_GetString(XP_JAVA_DEBUGGER_FAILED));
break;
}
default: {
s = PR_smprintf(XP_GetString(XP_JAVA_GENERAL_FAILURE), err);
break;
}
}
if (s) {
FE_Alert(cx, s);
free(s);
}
}
/* stolen from java_lang_Object.h (jri version) */
#define classname_java_lang_Object "java/lang/Object"
#define name_java_lang_Object_toString "toString"
#define sig_java_lang_Object_toString "()Ljava/lang/String;"
const char*
nsJVMManager::GetJavaErrorString(JNIEnv* env)
{
jthrowable exc = env->ExceptionOccurred();
if (exc == NULL) {
return strdup(""); /* XXX better "no error" message? */
}
/* Got to do this before trying to find a class (like Object).
This is because the runtime refuses to do this with a pending
exception! I think it's broken. */
env->ExceptionClear();
jclass classObject = env->FindClass(classname_java_lang_Object);
jmethodID toString = env->GetMethodID(classObject, name_java_lang_Object_toString, sig_java_lang_Object_toString);
jstring excString = (jstring) env->CallObjectMethod(exc, toString);
jboolean isCopy;
const char* msg = env->GetStringUTFChars(excString, &isCopy);
if (msg != NULL) {
const char* dupmsg = (msg == NULL ? NULL : strdup(msg));
env->ReleaseStringUTFChars(excString, msg);
msg = dupmsg;
}
return msg;
}
////////////////////////////////////////////////////////////////////////////////
PRLogModuleInfo* NSJAVA = NULL;
nsJVMStatus
nsJVMManager::StartupJVM(void)
{
// Be sure to check the prefs first before asking java to startup.
switch (GetJVMStatus()) {
case nsJVMStatus_Disabled:
return nsJVMStatus_Disabled;
case nsJVMStatus_Running:
return nsJVMStatus_Running;
default:
break;
}
#ifdef DEBUG
PRIntervalTime start = PR_IntervalNow();
if (NSJAVA == NULL)
NSJAVA = PR_NewLogModule("NSJAVA");
PR_LOG(NSJAVA, PR_LOG_ALWAYS, ("Starting java..."));
#endif
MWContext* someRandomContext = XP_FindSomeContext();
if (someRandomContext) {
FE_Progress(someRandomContext, XP_GetString(XP_PROGRESS_STARTING_JAVA));
}
PR_ASSERT(fJVM == NULL);
nsIPlugin* plugin = NPL_LoadPluginByType(NPJVM_MIME_TYPE);
if (plugin == NULL) {
fStatus = nsJVMStatus_Failed;
return fStatus;
}
nsresult rslt = plugin->QueryInterface(kIJVMPluginIID, (void**)&fJVM);
if (rslt != NS_OK) {
PR_ASSERT(fJVM == NULL);
fStatus = nsJVMStatus_Failed;
return fStatus;
}
nsJVMInitArgs initargs;
int count = fClassPathAdditions->GetSize();
char* classpathAdditions = NULL;
for (int i = 0; i < count; i++) {
const char* path = (const char*)(*fClassPathAdditions)[i];
char* oldPath = classpathAdditions;
if (oldPath) {
classpathAdditions = PR_smprintf("%s%c%s", oldPath, PR_PATH_SEPARATOR, path);
PR_Free(oldPath);
}
else
classpathAdditions = PL_strdup(path);
}
initargs.version = nsJVMInitArgs_Version;
initargs.classpathAdditions = classpathAdditions;
nsresult err = fJVM->StartupJVM(&initargs);
if (err == NS_OK) {
/* assume the JVM is running. */
fStatus = nsJVMStatus_Running;
}
else {
ReportJVMError(err);
fStatus = nsJVMStatus_Failed;
}
#if 0
JSContext* crippledContext = LM_GetCrippledContext();
MaybeStartupLiveConnect(crippledContext, JS_GetGlobalObject(crippledContext));
#endif
fJVM->Release();
#ifdef DEBUG
PRIntervalTime end = PR_IntervalNow();
PRInt32 d = PR_IntervalToMilliseconds(end - start);
PR_LOG(NSJAVA, PR_LOG_ALWAYS,
("Starting java...%s (%ld ms)",
(fStatus == nsJVMStatus_Running ? "done" : "failed"), d));
#endif
if (someRandomContext) {
FE_Progress(someRandomContext, XP_GetString(XP_PROGRESS_STARTING_JAVA_DONE));
}
return fStatus;
}
nsJVMStatus
nsJVMManager::ShutdownJVM(PRBool fullShutdown)
{
if (fStatus == nsJVMStatus_Running) {
PR_ASSERT(fJVM != NULL);
(void)MaybeShutdownLiveConnect();
nsresult err = fJVM->ShutdownJVM(fullShutdown);
if (err == NS_OK)
fStatus = nsJVMStatus_Enabled;
else {
ReportJVMError(err);
fStatus = nsJVMStatus_Disabled;
}
fJVM = NULL;
}
PR_ASSERT(fJVM == NULL);
return fStatus;
}
////////////////////////////////////////////////////////////////////////////////
static int PR_CALLBACK
JavaPrefChanged(const char *prefStr, void* data)
{
nsJVMManager* mgr = (nsJVMManager*)data;
XP_Bool prefBool;
#if defined(XP_MAC)
// beard: under Mozilla, no way to enable this right now.
prefBool = TRUE;
#else
PREF_GetBoolPref(prefStr, &prefBool);
#endif
mgr->SetJVMEnabled(prefBool);
return 0;
}
void
nsJVMManager::SetJVMEnabled(PRBool enabled)
{
if (enabled) {
if (fStatus != nsJVMStatus_Running)
fStatus = nsJVMStatus_Enabled;
// don't start the JVM here, do it lazily
}
else {
if (fStatus == nsJVMStatus_Running)
(void)ShutdownJVM();
fStatus = nsJVMStatus_Disabled;
}
}
void
nsJVMManager::EnsurePrefCallbackRegistered(void)
{
if (fRegisteredJavaPrefChanged != PR_TRUE) {
fRegisteredJavaPrefChanged = PR_TRUE;
PREF_RegisterCallback("security.enable_java", JavaPrefChanged, this);
JavaPrefChanged("security.enable_java", this);
}
}
nsJVMStatus
nsJVMManager::GetJVMStatus(void)
{
EnsurePrefCallbackRegistered();
return fStatus;
}
#ifdef XP_MAC
#define JSJDLL "LiveConnect"
#endif
PRBool
nsJVMManager::MaybeStartupLiveConnect(void)
{
if (fJSJavaVM)
return PR_TRUE;
do {
static PRBool registeredLiveConnectFactory = PR_FALSE;
if (!registeredLiveConnectFactory) {
NS_DEFINE_CID(kCLiveconnectCID, NS_CLIVECONNECT_CID);
registeredLiveConnectFactory =
(nsRepository::RegisterFactory(kCLiveconnectCID, (const char *)JSJDLL,
PR_FALSE, PR_FALSE) == NS_OK);
}
if (IsLiveConnectEnabled() && StartupJVM() == nsJVMStatus_Running) {
jvm_InitLCGlue();
nsIJVMPlugin* plugin = GetJVMPlugin();
if (plugin) {
#if 0
const char* classpath = NULL;
nsresult err = plugin->GetClassPath(&classpath);
if (err != NS_OK) break;
JavaVM* javaVM = NULL;
err = plugin->GetJavaVM(&javaVM);
if (err != NS_OK) break;
#endif
fJSJavaVM = JSJ_ConnectToJavaVM(NULL, NULL);
if (fJSJavaVM != NULL)
return PR_TRUE;
// plugin->Release(); // GetJVMPlugin no longer calls AddRef
}
}
} while (0);
return PR_FALSE;
}
PRBool
nsJVMManager::MaybeShutdownLiveConnect(void)
{
if (fJSJavaVM) {
JSJ_DisconnectFromJavaVM(fJSJavaVM);
fJSJavaVM = NULL;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool
nsJVMManager::IsLiveConnectEnabled(void)
{
if (LM_GetMochaEnabled()) {
nsJVMStatus status = GetJVMStatus();
return (status == nsJVMStatus_Enabled || status == nsJVMStatus_Running);
}
return PR_FALSE;
}
////////////////////////////////////////////////////////////////////////////////
nsresult
nsJVMManager::AddToClassPath(const char* dirPath)
{
nsIJVMPlugin* jvm = GetJVMPlugin();
/* Add any zip or jar files in this directory to the classpath: */
PRDir* dir = PR_OpenDir(dirPath);
if (dir != NULL) {
PRDirEntry* dirent;
while ((dirent = PR_ReadDir(dir, PR_SKIP_BOTH)) != NULL) {
PRFileInfo info;
char* path = PR_smprintf("%s%c%s", dirPath, PR_DIRECTORY_SEPARATOR, PR_DirName(dirent));
if (path != NULL) {
PRBool freePath = PR_TRUE;
if ((PR_GetFileInfo(path, &info) == PR_SUCCESS)
&& (info.type == PR_FILE_FILE)) {
int len = PL_strlen(path);
/* Is it a zip or jar file? */
if ((len > 4) &&
((PL_strcasecmp(path+len-4, ".zip") == 0) ||
(PL_strcasecmp(path+len-4, ".jar") == 0))) {
fClassPathAdditions->Add((void*)path);
if (jvm) {
/* Add this path to the classpath: */
jvm->AddToClassPath(path);
}
freePath = PR_FALSE;
}
}
// Don't leak the path!
if (freePath)
PR_smprintf_free(path);
}
}
PR_CloseDir(dir);
}
/* Also add the directory to the classpath: */
fClassPathAdditions->Add((void*)dirPath);
if (jvm) {
jvm->AddToClassPath(dirPath);
// jvm->Release(); // GetJVMPlugin no longer calls AddRef
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
class nsJVMFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
nsJVMFactory(void);
virtual ~nsJVMFactory(void);
};
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_IMPL_ISUPPORTS(nsJVMFactory, kIFactoryIID);
nsJVMFactory::nsJVMFactory(void)
{
}
nsJVMFactory::~nsJVMFactory(void)
{
}
NS_METHOD
nsJVMFactory::CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult)
{
return nsJVMManager::Create(aOuter, aIID, aResult);
}
NS_METHOD
nsJVMFactory::LockFactory(PRBool aLock)
{
// nothing to do here since we're not a DLL (yet)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// Bogus stuff that will go away when
// a) we have a persistent registry for CLSID -> Factory mappings, and
// b) when we ship a browser where all this JVM management code is in a DLL.
static NS_DEFINE_CID(kJVMManagerCID, NS_JVMMANAGER_CID);
extern "C" void
jvm_RegisterJVMMgr(void)
{
nsRepository::RegisterFactory(kJVMManagerCID,
new nsJVMFactory(),
PR_TRUE);
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -0,0 +1,127 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsJVMManager_h___
#define nsJVMManager_h___
#include "jvmmgr.h"
#include "xp_core.h" /* include first because of Bool problem */
#include "prtypes.h"
#include "nsCom.h"
#include "nsjvm.h"
#include "nsAgg.h"
#include "jsjava.h"
#include "nsVector.h"
class nsSymantecDebugManager;
struct ThreadLocalStorageAtIndex0 {
PRUint32 refcount;
};
typedef struct ThreadLocalStorageAtIndex0 ThreadLocalStorageAtIndex0;
/*******************************************************************************
* NsJVMManager is the interface to the JVM manager that the browser sees. All
* files that want to include java services should include this header file.
* nsIJVMManager is the more limited interface what the JVM plugin sees.
******************************************************************************/
struct nsJVMManager : public nsIJVMManager {
public:
NS_DECL_AGGREGATED
/* from nsIJVMManager: */
/* NsJVMManager specific methods: */
/* ====> From here on are things only called by the browser, not the plugin... */
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
nsIJVMPlugin* GetJVMPlugin(void) { return fJVM; }
/* Unlike the nsIJVMPlugin::StartupJVM, this version handles putting
* up any error dialog: */
nsJVMStatus StartupJVM(void);
nsJVMStatus ShutdownJVM(PRBool fullShutdown = PR_FALSE);
nsJVMStatus GetJVMStatus(void);
void SetJVMEnabled(PRBool enabled);
void ReportJVMError(nsresult err);
const char* GetJavaErrorString(JNIEnv* env);
nsresult AddToClassPath(const char* dirPath);
PRBool MaybeStartupLiveConnect(void);
PRBool MaybeShutdownLiveConnect(void);
PRBool IsLiveConnectEnabled(void);
JSJavaVM* GetJSJavaVM(void) { return fJSJavaVM; }
protected:
nsJVMManager(nsISupports* outer);
virtual ~nsJVMManager(void);
void EnsurePrefCallbackRegistered(void);
const char* GetJavaErrorString(JRIEnv* env);
nsIJVMPlugin* fJVM;
nsJVMStatus fStatus;
PRBool fRegisteredJavaPrefChanged;
nsISupports* fDebugManager;
JSJavaVM * fJSJavaVM;
nsVector* fClassPathAdditions;
};
/*******************************************************************************
* Symantec Debugger Stuff
******************************************************************************/
class nsSymantecDebugManager : public nsISymantecDebugManager {
public:
NS_DECL_AGGREGATED
NS_IMETHOD
SetDebugAgentPassword(PRInt32 pwd);
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsJVMManager* nsJVMManager);
protected:
nsSymantecDebugManager(nsISupports* outer, nsJVMManager* nsJVMManager);
virtual ~nsSymantecDebugManager(void);
nsJVMManager* fJVMMgr;
};
////////////////////////////////////////////////////////////////////////////////
#define NS_JVMMANAGER_CID \
{ /* 38e7ef10-58df-11d2-8164-006008119d7a */ \
0x38e7ef10, \
0x58df, \
0x11d2, \
{0x81, 0x64, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
#endif // nsJVMManager_h___

Просмотреть файл

@ -0,0 +1,213 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsJVMPluginTagInfo.h"
#include "nsIPluginTagInfo2.h"
#include "plstr.h"
#include "xp.h"
#include "xp_str.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
////////////////////////////////////////////////////////////////////////////////
// nsJVMPluginTagInfo
////////////////////////////////////////////////////////////////////////////////
nsJVMPluginTagInfo::nsJVMPluginTagInfo(nsISupports* outer, nsIPluginTagInfo2* info)
: fPluginTagInfo(info), fSimulatedCodebase(NULL), fSimulatedCode(NULL)
{
NS_INIT_AGGREGATED(outer);
}
nsJVMPluginTagInfo::~nsJVMPluginTagInfo(void)
{
if (fSimulatedCodebase)
PL_strfree(fSimulatedCodebase);
if (fSimulatedCode)
PL_strfree(fSimulatedCode);
}
NS_IMPL_AGGREGATED(nsJVMPluginTagInfo);
NS_METHOD
nsJVMPluginTagInfo::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aIID.Equals(kIJVMPluginTagInfoIID) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
static void
oji_StandardizeCodeAttribute(char* buf)
{
// strip off the ".class" suffix
char* cp;
if ((cp = PL_strrstr(buf, ".class")) != NULL)
*cp = '\0';
// Convert '/' to '.'
cp = buf;
while ((*cp) != '\0') {
if ((*cp) == '/')
(*cp) = '.';
++cp;
}
}
NS_METHOD
nsJVMPluginTagInfo::GetCode(const char* *result)
{
if (fSimulatedCode) {
*result = fSimulatedCode;
return NS_OK;
}
const char* code;
nsresult err = fPluginTagInfo->GetAttribute("code", &code);
if (err == NS_OK && code) {
fSimulatedCode = PL_strdup(code);
oji_StandardizeCodeAttribute(fSimulatedCode);
*result = fSimulatedCode;
return NS_OK;
}
const char* classid;
err = fPluginTagInfo->GetAttribute("classid", &classid);
if (err == NS_OK && classid && PL_strncasecmp(classid, "java:", 5) == 0) {
fSimulatedCode = PL_strdup(classid + 5); // skip "java:"
oji_StandardizeCodeAttribute(fSimulatedCode);
*result = fSimulatedCode;
return NS_OK;
}
// XXX what about "javaprogram:" and "javabean:"?
return NS_ERROR_FAILURE;
}
NS_METHOD
nsJVMPluginTagInfo::GetCodeBase(const char* *result)
{
// If we've already cached and computed the value, use it...
if (fSimulatedCodebase) {
*result = fSimulatedCodebase;
return NS_OK;
}
// See if it's supplied as an attribute...
const char* codebase;
nsresult err = fPluginTagInfo->GetAttribute("codebase", &codebase);
if (err == NS_OK && codebase != NULL) {
*result = codebase;
return NS_OK;
}
// Okay, we'll need to simulate it from the layout tag's base URL.
const char* docBase;
err = fPluginTagInfo->GetDocumentBase(&docBase);
if (err != NS_OK) return err;
PA_LOCK(codebase, const char*, docBase);
if ((fSimulatedCodebase = PL_strdup(codebase)) != NULL) {
char* lastSlash = PL_strrchr(fSimulatedCodebase, '/');
// chop of the filename from the original document base URL to
// generate the codebase.
if (lastSlash != NULL)
*(lastSlash + 1) = '\0';
}
PA_UNLOCK(docBase);
*result = fSimulatedCodebase;
return NS_OK;
}
NS_METHOD
nsJVMPluginTagInfo::GetArchive(const char* *result)
{
return fPluginTagInfo->GetAttribute("archive", result);
}
NS_METHOD
nsJVMPluginTagInfo::GetName(const char* *result)
{
const char* attrName;
nsPluginTagType type;
nsresult err = fPluginTagInfo->GetTagType(&type);
if (err != NS_OK) return err;
switch (type) {
case nsPluginTagType_Applet:
attrName = "name";
break;
default:
attrName = "id";
break;
}
return fPluginTagInfo->GetAttribute(attrName, result);
}
NS_METHOD
nsJVMPluginTagInfo::GetMayScript(PRBool *result)
{
const char* attr;
*result = PR_FALSE;
nsresult err = fPluginTagInfo->GetAttribute("mayscript", &attr);
if (err) return err;
if (PL_strcasecmp(attr, "true") == 0)
{
*result = PR_TRUE;
}
return NS_OK;
}
NS_METHOD
nsJVMPluginTagInfo::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsIPluginTagInfo2* info)
{
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
nsJVMPluginTagInfo* jvmTagInfo = new nsJVMPluginTagInfo(outer, info);
if (jvmTagInfo == NULL)
return NS_ERROR_OUT_OF_MEMORY;
jvmTagInfo->AddRef();
*aInstancePtr = jvmTagInfo->GetInner();
nsresult result = outer->QueryInterface(kIPluginTagInfo2IID,
(void**)&jvmTagInfo->fPluginTagInfo);
if (result != NS_OK) goto error;
outer->Release(); // no need to AddRef outer
return result;
error:
delete jvmTagInfo;
return result;
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsJVMPluginTagInfo_h___
#define nsJVMPluginTagInfo_h___
#include "nsIJVMPluginTagInfo.h"
#include "nsAgg.h"
/*******************************************************************************
* nsJVMPluginTagInfo: The browser makes one of these when it sees an APPLET or
* appropriate OBJECT tag.
******************************************************************************/
class nsIPluginTagInfo2;
class nsJVMPluginTagInfo : public nsIJVMPluginTagInfo {
public:
NS_DECL_AGGREGATED
/* from nsIJVMPluginTagInfo: */
/* ====> These are usually only called by the plugin, not the browser... */
NS_IMETHOD
GetCode(const char* *result);
NS_IMETHOD
GetCodeBase(const char* *result);
NS_IMETHOD
GetArchive(const char* *result);
NS_IMETHOD
GetName(const char* *result);
NS_IMETHOD
GetMayScript(PRBool *result);
/* Methods specific to nsJVMPluginInstancePeer: */
/* ====> From here on are things only called by the browser, not the plugin... */
static NS_METHOD
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsIPluginTagInfo2* info);
protected:
nsJVMPluginTagInfo(nsISupports* outer, nsIPluginTagInfo2* info);
virtual ~nsJVMPluginTagInfo(void);
/* Instance Variables: */
nsIPluginTagInfo2* fPluginTagInfo;
char* fSimulatedCodebase;
char* fSimulatedCode;
};
#endif // nsJVMPluginTagInfo_h___