Initial import of the mozilla component that plugs into the

Waterfall Pluggable JVM by Nikolay Igotti.
This commit is contained in:
edburns%acm.org 2001-05-09 18:51:36 +00:00
Родитель c699c249ad
Коммит 5942733019
33 изменённых файлов: 5709 добавлений и 0 удалений

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

@ -0,0 +1,56 @@
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: Makefile.in,v 1.1 2001/05/09 18:51:31 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,95 @@
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: README.txt,v 1.1 2001/05/09 18:51:32 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
Introduction
This module is an attempt to supply Mozilla with reasonable implementation
of OJI interfaces. This module uses generic low level library called Waterfall
as JVM provider. Its JVM integration part is written from scratch, but for
sake of completness applet viewer from Java Plugin included, so currently
we couldn't publish Waterfall under GPL.
If someone could write reasonable applet viewer, or if I'll
do it at some moment (currently it's work in progress) - it will be complete
GPL code.
Waterfall
Anyway, anyone could be able to get Waterfall binaries for Mozilla.
On Unix platforms (Solaris, Linux) it gives much better performance then
Java Plugin (as runs in the same process).
Currently Waterfall known to work on following configurations:
- OS: Solaris
ARCH: Sparc
OS Version: 5.8 (maybe 5.7 with patches)
JDK: Sun 1.3.1
VM type: hotspot
Status: works OK
- OS: Solaris
ARCH: i386
OS Version: 5.7, 5.8
JDK: Sun 1.3.1
VM type: hotspot
Status: test program sometimes crashes after AWT loading,
seems bug in x86 Solaris or GTK+,
otherwise works OK
- OS: Linux
ARCH: i386
OS Version: 2.2, glibc 2.2
JDK: Sun 1.3.1
VM type: hotspot
Status: works OK
- OS: Linux
ARCH: i386
OS Version: 2.2, glibc 2.2
JDK: IBM 1.3
VM type: classic
Status: works OK
- OS: Windows
ARCH: i386
OS Version: NT4.0 (should work on other Win32 systems as far)
JDK: Sun 1.3
VM type: hotspot
Status: works OK
Also planned porting Waterfall to Mac and other possible platforms.
Running
Unix:
edit set_env.sh to fit your environment (you need Waterfall headers
and binaries) and add
source set_env.sh
to script running Mozilla
Windows:
edit set_env.bat to fit your environment (you need Waterfall headers
and binaries) and run
set_env.bat
before running Mozilla

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

@ -0,0 +1,33 @@
@REM
@REM The contents of this file are subject to the Mozilla Public
@REM License Version 1.1 (the "License"); you may not use this file
@REM except in compliance with the License. You may obtain a copy of
@REM the License at http://www.mozilla.org/MPL/
@REM
@REM Software distributed under the License is distributed on an "AS
@REM IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
@REM implied. See the License for the specific language governing
@REM rights and limitations under the License.
@REM
@REM The Original Code is The Waterfall Java Plugin Module
@REM
@REM The Initial Developer of the Original Code is Sun Microsystems Inc
@REM Portions created by Sun Microsystems Inc are Copyright (C) 2001
@REM All Rights Reserved.
@REM
@REM $Id: set_env.bat,v 1.1 2001/05/09 18:51:33 edburns%acm.org Exp $
@REM
@REM
@REM Contributor(s):
@REM
@REM Nikolay N. Igotti <inn@sparc.spb.su>
@echo off
rem Set those variables
set WFDIR=f:\nike\wf
rem set WFJDKHOME=c:\jdk1.3
rem end of customizable part
set WFHOME=%WFDIR%\build\win32
echo WFJDKHOME is %WFJDKHOME%
echo WFHOME is %WFHOME%

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

@ -0,0 +1,36 @@
#!/bin/sh
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: set_env.sh,v 1.1 2001/05/09 18:51:33 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
# Set those variables
# for me this var set in .bashrc so I don't need it here
#WFJDKHOME=/usr/java/jdk1.3.0_02
WFDIR=/usr/local/home/nike/mozilla/wf
# end of customizable part
CURDIR=`pwd`
cd ${WFDIR}/build/unix
source ./set_paths
cd ${CURDIR}
export WFDIR WFJDKHOME

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

@ -0,0 +1,28 @@
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: makefile.win,v 1.1 2001/05/09 18:51:31 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
DEPTH=..\..\..
DIRS=public src
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,68 @@
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: Makefile.in,v 1.1 2001/05/09 18:51:34 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = oji_jvm
XPIDLSRCS = \
nsoji2.idl \
nsIPluggableJVM.idl \
nsIJavaHTMLObject.idl \
nsIJavaObjectInfo.idl \
nsIJavaPluginInstanceProxy.idl \
nsIWFInstanceWrapper.idl \
nsIBrowserJavaSupport.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,39 @@
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: makefile.win,v 1.1 2001/05/09 18:51:34 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
DEPTH = ..\..\..\..
MODULE = oji_jvm
XPIDLSRCS = \
.\nsoji2.idl \
.\nsIPluggableJVM.idl \
.\nsIJavaHTMLObject.idl \
.\nsIJavaObjectInfo.idl \
.\nsIJavaPluginInstanceProxy.idl \
.\nsIWFInstanceWrapper.idl \
.\nsIBrowserJavaSupport.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,35 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsIBrowserJavaSupport.idl,v 1.1 2001/05/09 18:51:34 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsoji2.idl"
#include "nsIJavaPluginInstanceProxy.idl"
[uuid(f016284f-24f5-4471-aca5-c53746046246)]
interface nsIBrowserJavaSupport : nsISupports
{
void GetProxyForURL(in string url, out string proxy);
void JSCall(in jp_jint jstid, inout jp_CallInfo call);
};

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

@ -0,0 +1,129 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsIJavaHTMLObject.idl,v 1.1 2001/05/09 18:51:34 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsoji2.idl"
#include "nsIPluggableJVM.idl"
%{C++
#include "nsIDOMElement.h"
%}
native nsIDOMElement(nsIDOMElement*);
/**
* this is instance of visible object on browser's page controlled by
* Java code, like <APPLET> or <OBJECT> tag content.
*/
[scriptable, uuid(d0bc700b-aadb-417f-b584-5d644bb3432f)]
interface nsIJavaHTMLObject : nsISupports {
/**
* Initialization stuff. Used by browser when it wishes to create
* Java-driven object on page. Argument is nsISupports
* to simplify using new OJI module - it can be nsIPluginInstancePeer
* for older cases and smth else in the future.
* Second one argument is JVM which should be responsible for this object.
*/
void Initialize(in nsISupports peer, in nsIPluggableJVM jvm);
/**
* Starts/resumes this object's operations.
*/
void Start();
/**
* Stops/suspends this object's operations
*/
void Stop();
/**
* Die!
*/
void Destroy();
/**
* Method to set drawing window.
* I intentionally will not allow generic Java object here to
* avoid mess. Register window in nsIPluggableJVM first (from C++) or
* in Plugin class (from Java).
*/
[noscript] void SetWindow(in jp_jint ID);
/**
* Get object peer in browser/host application.
*/
void GetPeer(out nsISupports peer);
/**
* Set type of this Java object
*/
[noscript] void SetType(in jp_jint type);
/**
* Get Java JSObject for this object.
*/
[noscript] void GetJavaPeer(out jp_jobject ID);
// can ask owner document from this guy
[noscript] void GetDOMElement(out nsIDOMElement result);
/**
* Methods called by Java side
*/
[noscript] void PostEvent(in jp_jint event, in jp_jlong data);
[noscript] void SendEvent(in jp_jint event, in jp_jlong data);
// peer event types, synchronize with HostObjectPeer.java
const long PE_NOPE = 0;
const long PE_CREATE = 1;
const long PE_SETWINDOW = 2;
const long PE_DESTROY = 3;
const long PE_START = 4;
const long PE_STOP = 5;
const long PE_NEWPARAMS = 6;
const long PE_SETTYPE = 7;
// generic event sent by browser
const long PE_PEEREVENT = 8;
const long PE_GETPEER = 9;
// java event types
const long JE_NOPE = 0;
const long JE_SHOWSTATUS = 1;
const long JE_SHOWDOCUMENT = 2;
// generic event sent by applet
const long JE_APPLETEVENT = 3;
// error requiring browser's attention happened in applet
const long JE_APPLETERROR = 4;
// error requiring browser's attention happened in JVM
const long JE_JVMERROR = 5;
// peer's host applications
const long PV_UNKNOWN = 0;
const long PV_MOZILLA6 = 1;
// peer's types
const long PT_UNKNOWN = 0;
const long PT_EMBED = 1;
const long PT_OBJECT = 2;
const long PT_APPLET = 3;
const long PT_PLUGLET = 4;
};

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

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsIJavaObjectInfo.idl,v 1.1 2001/05/09 18:51:34 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsoji2.idl"
#include "nsIJavaHTMLObject.idl"
#include "nsIWFInstanceWrapper.idl"
%{C++
enum nsJavaObjectType
{
nsJavaObjectType_Unknown,
nsJavaObjectType_Embed,
nsJavaObjectType_Object,
nsJavaObjectType_Applet,
nsJavaObjectType_Pluglet
};
/* opaque structure to be used to pass as bridge between Java and Mozilla
applet operations */
struct JavaObjectWrapper;
%}
native nsJavaObjectType(nsJavaObjectType);
native JavaObjectWrapper(JavaObjectWrapper*);
[uuid(f7eb8258-e2a3-404f-ae11-b9d8a976e993)]
interface nsIJavaObjectInfo : nsISupports
{
// I don't know why attributes and parameters different -
// so let's consider them as the same thing
void addParameter(in string key, in string value);
void getParameters([array, size_is(count)] out string keys,
[array, size_is(count)] out string values,
[retval] out PRUint32 count);
/* I'm not sure which attributes should be readonly */
attribute string docBase;
attribute string encoding;
attribute string alignment;
attribute PRUint32 width;
attribute PRUint32 height;
readonly attribute nsJavaObjectType type;
void getOwner(out nsIJavaHTMLObject owner);
void getWrapper(out JavaObjectWrapper wrapper);
// XXX: temporary - keep it last
void getPluginWrapper(out nsIWFInstanceWrapper wrapper);
};

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

@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsIJavaPluginInstanceProxy.idl,v 1.1 2001/05/09 18:51:34 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
/**
* this is an utility interface used by Java plugin to perform all
* required by Java UI calls in UI thread.
*
* Author: Nikolay Igotti (inn@sparc.spb.su)
*/
#include "nsISupports.idl"
#include "nsoji2.idl"
%{C++
#define NS_JAVAPLUGININSTANCEPROXY_CID \
{ /* d0e94e41-65e1-49dc-9cbf-7ade042f4c16 */ \
0xd0e94e41, \
0x65e1, \
0x49dc, \
{0x9c, 0xbf, 0x7a, 0xde, 0x04, 0x2f, 0x4c, 0x16} \
}
%}
/* The main usage of this interface is to supply Java plugin with thread-safe
applet context. If something else will be required to be wrapped -
extend this one. Here listed all AppletContext methods with comments:
Applet getApplet(String name);
Note: everthing will happen inside JVM - SKIPPED
Enumeration getApplets();
Note: not requires interaction with browser's UI as all applets
anyway registred in plugin - SKIPPED
AudioClip getAudioClip(URL url);
Note: XXX: maybe requires interaction with browser's UI but I don't know
how to describe audio clip - SKIPPED
Image getImage(URL url);
Note: everything will happen inside JVM - SKIPPED
void showDocument(URL url) ;
Note: superseded by next method - WRAPPED by next method
void showDocument(URL url, String target);
Note: requires interaction with browser - WRAPPED.
void showStatus(String status);
Note: requires interaction with browser - WRAPPED.
*/
[uuid(6706fc34-05b7-4656-9c58-b92ffb220a8a)]
interface nsIJavaPluginInstanceProxy : nsISupports {
void ShowStatus(in string status);
void ShowDocument(in string url, in string target);
void GetJSThread(out jp_jint jstid);
};
[uuid(bc704bd3-f962-47ff-9e88-a48c941d78e9)]
interface nsIJavaPluginProxy : nsISupports {
void GetProxyForURL(in string url, out string proxy);
void JSCall(in jp_jint jstid, inout jp_CallInfo call);
};

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

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsIJavaPluginInstanceWrapper.idl,v 1.1 2001/05/09 18:51:34 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsoji2.idl"
/**
* Thread-safe java plugin instance wrapper.
* nsIJavaPluginInstanceProxy exists as probably not all methods
* here should be forwarded to main thread, and we need IDL description for
* interthread proxy.
*/
[uuid(364eb8a7-8b4b-49b5-bbb5-c34ab2bc2189)]
interface nsIJavaPluginInstanceWrapper : nsISupports
{
void ShowStatus(in string status);
void ShowDocument(in string url, in string target);
void GetJSThread(out jp_jint jstid);
};

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

@ -0,0 +1,152 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsIPluggableJVM.idl,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsoji2.idl"
#include "nsIBrowserJavaSupport.idl"
interface nsIJavaHTMLObject;
/** this is generic JVM inside browser. You can have
* more control on this then using nsIJVMPlugin interface.
* This stuff SHOULD NOT depend on particular JNI/JVM.
* XXX: now it does :), but only in nsoji2.idl and generated .h files.
*/
/** One more important issue: maybe it has sense to divide functionality
* onto threading, drawing, scripting, startup/shutdown parts,
* but I'd like to avoid scattering functionality, so everything
* is in one place. But interface users should expect that some interface
* method aren't implemented, especially LiveConnect related.
*/
%{C++
#define NS_PLUGGABLEJVM_CID \
{ /* 43abebc6-a9b1-419f-acbe-677474edead1 */ \
0x43abebc6, \
0xa9b1, \
0x419f, \
{0xac, 0xbe, 0x67, 0x74, 0x74, 0xed, 0xea, 0xd1} \
}
%}
[uuid(931c3870-c12d-4bff-8e80-005dd29fee01)]
interface nsIPluggableJVM : nsISupports {
/**********************************************************/
// Here drawing context stuff
/**
* This method registers native window handle rwin
* as Java frame, returns Java object and integer ID
* of this window. Until UnregisterWindow() is called
* it is valid handle. Generally only one thread should
* work with registration/unregistration of one window.
* Also when native peer is destroyed unregister window should be called
* before - otherwise JVM may crash.
*/
void RegisterWindow(in nsNativeWindow rwin,
out jp_jint ID);
/**
* Unregister window and remove Java peer. Call carefully.
*/
void UnregisterWindow(in jp_jint ID);
/**********************************************************/
// Here threading stuff
/**
* Create Java monitor assotiated with given native monitor
*/
void RegisterMonitor(in nsNativeMonitor rmon,
out jp_jint ID);
/**
* Unregister monitor. Call carefully.
*/
void UnregisterMonitor(in jp_jint ID);
/**********************************************************/
// Here scripting stuff (javascript based)
/**
* Get JavaScript Java object used for LiveConnect.
*/
void GetJavaWrapper(in jp_jint jsobj, out jp_jobject jobj);
/**
* Get native JS object from Java object
**/
void UnwrapJavaWrapper(in jp_jobject jobj, out jp_jint jsobj);
/**
* Returns JNIEnv of current context. Required due current way
* of LiveConnect implementation.
*/
void GetJNIEnv(out jp_JNIEnv env);
/**********************************************************/
// Here JVM control stuff
/**
* Run JVM with given classpath.
* Status depends on success of this operation.
*/
void StartupJVM(in string classPath,
out nsJVMStatus status,
in jp_jlong support);
/**
* Shutdown JVM.
*/
void ShutdownJVM(in PRBool fullShutdown, out nsJVMStatus status);
/**********************************************************/
// generic object management
void CreateJavaPeer(in nsIJavaHTMLObject obj,
in string cid,
out jp_jint id);
void PostEventToJavaPeer(in jp_jint obj_id,
in jp_jint evt_id,
in jp_jlong evt_data);
void SendEventToJavaPeer(in jp_jint obj_id,
in jp_jint evt_id,
in jp_jlong evt_data,
out jp_jint result);
void JavaPeerCall(in jp_jint obj_id,
in jp_jint data1,
in jp_jlong data2);
void DestroyJavaPeer(in jp_jint id);
void ExtensionCall(in jp_jint arg1, in jp_jlong arg2);
/*********************************************************/
// utility stuff, like console handling
void SetConsoleVisibility(in boolean visibility);
void GetConsoleVisibility(out boolean visibility);
void PrintToConsole(in string msg, in string encoding);
};

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

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsIWFInstanceWrapper.idl,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsoji2.idl"
/**
* Thread-safe java plugin instance wrapper.
* nsIWFInstanceProxy exists as probably not all methods
* here should be forwarded to main thread, and we need IDL description for
* interthread proxy.
*/
[uuid(364eb8a7-8b4b-49b5-bbb5-c34ab2bc2189)]
interface nsIWFInstanceWrapper : nsISupports
{
void ShowStatus(in string status);
void ShowDocument(in string url, in string target);
void GetJSThread(out jp_jint jstid);
};

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

@ -0,0 +1,85 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsoji2.idl,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsISupports.idl"
%{C++
// external C++ includes here - they can be Mozilla dependent, but not
// JDK dependent
// we using older plugin stuff for easyness of integration
// this should be removed in future
//several hacks to live with current Mozilla tree
#define JNI_H
#define JRI_H
#define JRI_MD_H
#include "jvmp.h"
#include "nsplugindefs.h"
#include "nsIPluginInstancePeer.h"
//Java Script stuff
#include "jsapi.h"
typedef enum nsPluggableJVMStatus {
nsPluggableJVMStatus_Enabled, /* but not Running */
nsPluggableJVMStatus_Disabled, /* explicitly disabled */
nsPluggableJVMStatus_Running, /* enabled and started */
nsPluggableJVMStatus_Failed /* enabled but failed to start */
} nsPluggableJVMStatus;
typedef struct _nsPluginThread nsPluginThread;
// Auxilary macroses
#define OJI_LOG(s1) { fprintf (stderr, "MOZWF: "); \
fprintf(stderr, s1); fprintf(stderr, "\n"); }
#define OJI_LOG2(s1, s2) { fprintf (stderr, "MOZWF: "); \
fprintf(stderr, s1, s2); fprintf(stderr, "\n"); }
#define OJI_LOG3(s1, s2, s3) { fprintf (stderr, "MOZWF: "); \
fprintf(stderr, s1, s2, s3); fprintf(stderr, "\n"); }
#define OJI_LOG4(s1, s2, s3, s4) { fprintf (stderr, "MOZWF: "); \
fprintf(stderr, s1, s2, s3 ,s4); fprintf(stderr, "\n"); }
#define OJI_LOG5(s1, s2, s3, s4, s5) { fprintf (stderr, "MOZWF: "); \
fprintf(stderr, s1, s2, s3 ,s4, s5); fprintf(stderr, "\n"); }
%}
// native types
native nsNativeWindow(nsPluginWindow*);
native nsNativeMonitor(PRMonitor*);
native nsJVMStatus(nsPluggableJVMStatus);
// hackz - should be in jvmp.h
native jp_jobject(jobject);
native jp_jint(jint);
native jp_jlong(jlong);
native jp_JNIEnv(JNIEnv*);
native jp_CallInfo(struct JSObject_CallInfo*);
// hackz - should be scripting engine independent
native nsScriptRuntime(JSRuntime*);
native nsScriptContext(JSContext*);
native nsScriptObject(JSObject*);
// interfaces to be IDL'ized
interface nsISecureEnv;
interface nsIPluginInstancePeer;

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

@ -0,0 +1,83 @@
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: Makefile.in,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
uname = $(shell uname)
ifeq ($(uname), SunOS)
PLATFORM = solaris
endif
ifeq ($(uname), Linux)
PLATFORM = linux
endif
include $(DEPTH)/config/autoconf.mk
MODULE = oji_jvm
IS_COMPONENT = 1
LIBRARY_NAME = ojijvm
CPPSRCS = \
nsPluggableJVM.cpp \
nsCJVMFactory.cpp \
nsJavaHTMLObjectFactory.cpp \
nsJavaHTMLObject.cpp \
nsAppletHTMLObject.cpp \
nsJavaObjectInfo.cpp \
nsWFSecureEnv.cpp \
nsWFSecurityContext.cpp \
$(NULL)
include $(DEPTH)/config/rules.mk
INCLUDES := -I$(WFDIR)/public -I$(WFDIR)/public/$(PLATFORM) -I$(WFJDKHOME)/include -I$(WFJDKHOME)/include/$(PLATFORM) $(INCLUDES)

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

@ -0,0 +1,57 @@
#
# 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 The Waterfall Java Plugin Module
#
# The Initial Developer of the Original Code is Sun Microsystems Inc
# Portions created by Sun Microsystems Inc are Copyright (C) 2001
# All Rights Reserved.
#
# $Id: makefile.win,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
#
#
# Contributor(s):
#
# Nikolay N. Igotti <inn@sparc.spb.su>
#!nmake
DEPTH = ..\..\..\..
include <$(DEPTH)\config\config.mak>
MODULE=ojijvm
IS_COMPONENT=1
MAKE_OBJ_TYPE=DLL
DLLNAME=ojijvm
DLL=.\$(OBJDIR)\$(DLLNAME).dll
OBJS = \
.\$(OBJDIR)\nsPluggableJVM.obj \
.\$(OBJDIR)\nsCJVMFactory.obj \
.\$(OBJDIR)\nsJavaHTMLObjectFactory.obj \
.\$(OBJDIR)\nsJavaHTMLObject.obj \
.\$(OBJDIR)\nsAppletHTMLObject.obj \
.\$(OBJDIR)\nsJavaObjectInfo.obj \
.\$(OBJDIR)\nsWFSecureEnv.obj \
.\$(OBJDIR)\nsWFSecurityContext.obj \
$(NULL)
EXPORTS = \
$(NULL)
LINCS = -I$(WFDIR)/public -I$(WFDIR)/public/win32 -I$(WFJDKHOME)/include -I$(WFJDKHOME)/include/win32
LLIBS = \
$(DIST)\lib\xpcom.lib \
$(LIBNSPR)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components

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

@ -0,0 +1,459 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsAppletHTMLObject.cpp,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsAppletHTMLObject.h"
#include "nsJavaHTMLObject.h"
#include "nsJavaObjectInfo.h"
#include "nsIPluginTagInfo.h"
#include "nsIProxyObjectManager.h"
#include "nsIServiceManager.h"
#include "nsIPluginManager2.h"
#include "nsIJavaPluginInstanceProxy.h"
#include "nsIWFInstanceWrapper.h"
#include "nsIJVMPluginInstance.h"
#include "wf_moz6_common.h"
#include "nsIThread.h"
static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kIPluginManager2IID, NS_IPLUGINMANAGER2_IID);
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kIPluginInstancePeer2IID, NS_IPLUGININSTANCEPEER2_IID);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
NS_IMPL_THREADSAFE_ISUPPORTS3(nsAppletHTMLObject,
nsIPluginInstance,
nsIWFInstanceWrapper,
nsIJVMPluginInstance)
nsAppletHTMLObject::nsAppletHTMLObject(nsJavaHTMLObjectFactory *factory)
{
NS_INIT_ISUPPORTS();
m_factory = factory;
m_mgr = nsnull;
NS_ADDREF(m_factory);
m_peer = m_peer2 = nsnull;
m_dead = PR_FALSE;
nsCOMPtr<nsIThread> mainIThread;
nsIThread::GetMainThread(getter_AddRefs(mainIThread));
mainIThread->GetPRThread(&m_mainThread);
}
nsAppletHTMLObject::~nsAppletHTMLObject(void) {
OJI_LOG("nsAppletHTMLObject::~nsAppletHTMLObject");
if (m_factory) NS_RELEASE(m_factory);
}
NS_IMETHODIMP
nsAppletHTMLObject::Initialize(nsIPluginInstancePeer *peer)
{
nsresult res;
OJI_LOG("nsAppletHTMLObject::Initialize");
m_peer = peer;
NS_ADDREF(m_peer);
peer->QueryInterface(kIPluginInstancePeer2IID,
(void **)&m_peer2);
m_jobject = new nsJavaHTMLObject(m_factory);
NS_ADDREF(m_jobject);
res = nsServiceManager::GetService(kPluginManagerCID,
kIPluginManagerIID,
getter_AddRefs(m_mgr));
if (NS_FAILED(res)) return res;
m_id = 0;
if (NS_FAILED(res = m_factory->GetJVM(&m_jvm))) return res;
if (NS_FAILED(res = m_jvm->GetJNIEnv(&m_env))) return res;
if (NS_FAILED(res = m_jobject->Initialize(peer, m_jvm))) return res;
// find out applet information from our peer and explain it
// to nsJavaHTMLObject
// in new API nsJavaHTMLObject should get everything needed
// from peer
nsJavaObjectInfo* info =
new nsJavaObjectInfo((nsIWFInstanceWrapper*)this);
NS_ADDREF(info);
nsIPluginTagInfo *tagInfo;
if (NS_SUCCEEDED(res = peer->QueryInterface(kIPluginTagInfoIID,
(void **)&tagInfo)))
{
PRUint16 argc = 0, i;
char **keys, **vals;
tagInfo->GetAttributes(argc, (const char* const* &)keys,
(const char* const* &) vals);
for (i=0; i<argc; i++)
info->AddParameter(keys[i], vals[i]);
NS_RELEASE(tagInfo);
}
nsIPluginTagInfo2 *extTagInfo;
if (NS_SUCCEEDED(res = peer->QueryInterface(kIPluginTagInfo2IID,
(void **)&extTagInfo)))
{
nsPluginTagType tagType = nsPluginTagType_Unknown;
if (NS_SUCCEEDED(extTagInfo->GetTagType(&tagType)))
{
if (tagType == nsPluginTagType_Applet ||
tagType == nsPluginTagType_Object)
{
PRUint16 argc = 0, i;
char **keys, **vals;
extTagInfo->GetParameters(argc,
(const char*const*&)keys,
(const char*const*&) vals);
for (i=0; i<argc; i++)
info->AddParameter(keys[i], vals[i]);
}
nsJavaObjectType type = mapType(tagType);
info->SetType(type);
if (NS_FAILED(res = m_jobject->SetType(type)))
return res;
}
const char *docbase = NULL;
if (NS_FAILED(res = extTagInfo->GetDocumentBase(&docbase)))
{
OJI_LOG("Failed to obtain doc base");
}
if (docbase != NULL)
{
char *slash = strrchr((char*)docbase, '/');
if (slash != NULL) *(slash+1) = 0;
OJI_LOG2("real docbase is %s", docbase);
info->SetDocBase(docbase);
}
NS_RELEASE(extTagInfo);
}
// really it's crucial to call SetType() _before_ passing Java object info
// otherwise parameters will be passed to wrapper - and silently ignored
res = m_jobject->SetJavaObjectInfo(info);
NS_RELEASE(info);
return res;
}
NS_IMETHODIMP
nsAppletHTMLObject::GetPeer(nsIPluginInstancePeer* *resultingPeer)
{
//OJI_LOG("nsAppletHTMLObject::GetPeer");
if (m_dead) return NS_ERROR_FAILURE;
*resultingPeer = m_peer;
NS_ADDREF(m_peer);
return NS_OK;
}
NS_IMETHODIMP
nsAppletHTMLObject::Start(void)
{
OJI_LOG("nsAppletHTMLObject::Start");
m_dead = PR_FALSE;
return m_jobject->Start();
}
NS_IMETHODIMP
nsAppletHTMLObject::Stop(void)
{
OJI_LOG("nsAppletHTMLObject::Stop");
if (m_jobject) m_jobject->Stop();
if (m_id && m_jvm) m_jvm->UnregisterWindow(m_id);
m_id = 0;
m_dead = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsAppletHTMLObject::Destroy(void)
{
OJI_LOG("nsAppletHTMLObject::Destroy");
m_dead = PR_TRUE;
if (m_jobject)
{
m_jobject->Destroy();
NS_RELEASE(m_jobject);
}
if (m_peer) NS_RELEASE(m_peer);
if (m_peer2) NS_RELEASE(m_peer2);
if (m_jvm) NS_RELEASE(m_jvm);
//OJI_LOG2("mRefCnt=%d",mRefCnt);
return NS_OK;
}
// XXX: for now, this code can leak window descriptors,
// as not unregisters old window, if new one has come
// with another native handle.
// SetWindow() with size changing hopefully works well
NS_IMETHODIMP
nsAppletHTMLObject::SetWindow(nsPluginWindow* window)
{
OJI_LOG2("nsAppletHTMLObject::SetWindow(%p)",
window != nsnull ? (void*)window->window : 0x0);
nsresult res = NS_OK;
if (m_jvm == NULL)
{
OJI_LOG("m_jvm is NULL");
return NS_ERROR_FAILURE;
}
if (window != NULL)
{
jint new_id;
res = m_jvm->RegisterWindow(window, &new_id);
if (NS_FAILED(res)) return res;
//if (m_id != 0 && new_id != m_id) m_jvm->UnregisterWindow(m_id);
m_id = new_id;
}
else
{
if (m_id != 0) m_jvm->UnregisterWindow(m_id);
m_id = 0;
}
return m_jobject->SetWindow(m_id);
}
NS_IMETHODIMP
nsAppletHTMLObject::NewStream(nsIPluginStreamListener** listener)
{
OJI_LOG("nsAppletHTMLObject::NewStream");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsAppletHTMLObject::Print(nsPluginPrint* platformPrint)
{
OJI_LOG("nsAppletHTMLObject::Print");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsAppletHTMLObject::GetValue(nsPluginInstanceVariable variable, void *value)
{
OJI_LOG2("nsAppletHTMLObject::GetValue: %d", variable);
if (variable == nsPluginInstanceVariable_DoCacheBool)
{
//OJI_LOG("SET NO PLUGIN CACHING");
*(PRBool*)value = PR_FALSE;
return NS_OK;
}
return NS_OK;
}
NS_IMETHODIMP
nsAppletHTMLObject::HandleEvent(nsPluginEvent* event, PRBool* handled)
{
OJI_LOG("nsAppletHTMLObject::HandleEvent");
return NS_ERROR_NOT_IMPLEMENTED;
}
nsJavaObjectType
nsAppletHTMLObject::mapType(nsPluginTagType pluginType)
{
switch (pluginType)
{
case nsPluginTagType_Applet:
return nsJavaObjectType_Applet;
case nsPluginTagType_Object:
return nsJavaObjectType_Object;
case nsPluginTagType_Embed:
return nsJavaObjectType_Embed;
default:
return nsJavaObjectType_Unknown;
}
}
/* HERE INTERTHREAD PROXY STUFF FOLLOWS */
// utility proxy class
class nsJavaPluginInstanceProxy : public nsIJavaPluginInstanceProxy
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIJAVAPLUGININSTANCEPROXY
nsJavaPluginInstanceProxy();
virtual ~nsJavaPluginInstanceProxy();
NS_IMETHOD Init(nsAppletHTMLObject* owner);
protected:
nsAppletHTMLObject* m_owner;
};
NS_IMPL_THREADSAFE_ISUPPORTS1(nsJavaPluginInstanceProxy,
nsIJavaPluginInstanceProxy);
nsJavaPluginInstanceProxy::nsJavaPluginInstanceProxy()
{
NS_INIT_ISUPPORTS();
}
NS_IMETHODIMP
nsJavaPluginInstanceProxy::Init(nsAppletHTMLObject* owner)
{
m_owner = owner;
NS_ADDREF(owner);
return NS_OK;
}
nsJavaPluginInstanceProxy::~nsJavaPluginInstanceProxy()
{
NS_RELEASE(m_owner);
}
NS_IMETHODIMP
nsJavaPluginInstanceProxy::ShowDocument(const char* url,
const char* target)
{
return m_owner->doShowDocument(url, target);
}
NS_IMETHODIMP
nsJavaPluginInstanceProxy::ShowStatus(const char* status)
{
return m_owner->doShowStatus(status);
}
NS_IMETHODIMP
nsJavaPluginInstanceProxy::GetJSThread(jint* jstid)
{
return m_owner->doGetJSThread(jstid);
}
// Here follows thread-safe versions of methods of plugin API
NS_IMETHODIMP
nsAppletHTMLObject::ShowStatus(const char* status)
{
nsresult rv = NS_OK;
if (m_dead) return NS_ERROR_FAILURE;
if (PR_GetCurrentThread() == m_mainThread) return doShowStatus(status);
nsCOMPtr<nsJavaPluginInstanceProxy> inst =
new nsJavaPluginInstanceProxy();
inst->Init(this);
nsCOMPtr<nsIJavaPluginInstanceProxy> instProxy;
NS_WITH_SERVICE(nsIProxyObjectManager, proxyObjectManager,
kProxyObjectManagerCID, &rv);
rv = proxyObjectManager->
GetProxyForObject(NS_UI_THREAD_EVENTQ,
NS_GET_IID(nsIJavaPluginInstanceProxy),
NS_STATIC_CAST(nsISupports*, inst),
PROXY_ASYNC | PROXY_ALWAYS,
getter_AddRefs(instProxy));
if (NS_FAILED(rv)) return rv;
//OJI_LOG(">>>>>>>>>>>>>>>>>>>");
rv = instProxy->ShowStatus(status);
//OJI_LOG2("ShowStatus(%s) done ", status);
return rv;
}
NS_IMETHODIMP
nsAppletHTMLObject::ShowDocument(const char* url,
const char* target)
{
nsresult rv = NS_OK;
if (m_dead) return NS_ERROR_FAILURE;
if (PR_GetCurrentThread() == m_mainThread)
return doShowDocument(url, target);
nsCOMPtr<nsJavaPluginInstanceProxy> inst =
new nsJavaPluginInstanceProxy();
inst->Init(this);
nsCOMPtr<nsIJavaPluginInstanceProxy> instProxy;
NS_WITH_SERVICE(nsIProxyObjectManager, proxyObjectManager,
kProxyObjectManagerCID, &rv);
rv = proxyObjectManager->
GetProxyForObject(NS_UI_THREAD_EVENTQ,
NS_GET_IID(nsIJavaPluginInstanceProxy),
NS_STATIC_CAST(nsISupports*, inst),
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(instProxy));
if (NS_FAILED(rv)) return rv;
rv = instProxy->ShowDocument(url, target);
return rv;
}
NS_IMETHODIMP
nsAppletHTMLObject::GetJSThread(jint* jstid)
{
PRUint32 jsThreadID = 0;
if (m_dead) return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(m_peer2->GetJSThread(&jsThreadID)))
*jstid = (jint)(jsThreadID);
return NS_OK;
/*
nsresult rv = NS_OK;
if (m_dead) return NS_ERROR_FAILURE;
nsCOMPtr<nsJavaPluginInstanceProxy> inst =
new nsJavaPluginInstanceProxy();
inst->Init(this);
nsCOMPtr<nsIJavaPluginInstanceProxy> instProxy;
NS_WITH_SERVICE(nsIProxyObjectManager, proxyObjectManager,
kProxyObjectManagerCID, &rv);
rv = proxyObjectManager->
GetProxyForObject(NS_UI_THREAD_EVENTQ,
NS_GET_IID(nsIJavaPluginInstanceProxy),
NS_STATIC_CAST(nsISupports*, inst),
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(instProxy));
if (NS_FAILED(rv)) return rv;
rv = instProxy->GetJSThread(jstid);
return rv; */
}
// Here follows thread-unsafe versions of methods of plugin API
NS_IMETHODIMP
nsAppletHTMLObject::doShowStatus(const char* status)
{
if (m_dead) return NS_ERROR_FAILURE;
return m_peer->ShowStatus(status);
}
NS_IMETHODIMP
nsAppletHTMLObject::doShowDocument(const char* url,
const char* target)
{
if (m_dead) return NS_ERROR_FAILURE;
return m_mgr->GetURL((nsIPluginInstance*)this, url, target,
NULL, NULL, NULL, PR_FALSE);
}
NS_IMETHODIMP
nsAppletHTMLObject::doGetJSThread(jint* jstid)
{
PRUint32 jsThreadID = 0;
if (m_dead) return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(m_peer2->GetJSThread(&jsThreadID)))
*jstid = (jint)(jsThreadID);
return NS_OK;
}
NS_IMETHODIMP
nsAppletHTMLObject::GetJavaObject(jobject *result)
{
if (!result || !m_jobject) return NS_ERROR_FAILURE;
return m_jobject->GetJavaPeer(result);
}
NS_IMETHODIMP
nsAppletHTMLObject::GetText(const char* *result)
{
OJI_LOG("nsAppletHTMLObject::GetText");
return NS_OK;
}

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

@ -0,0 +1,102 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsAppletHTMLObject.h,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef __nsAppletHTMLObject_h
#define __nsAppletHTMLObject_h
#include "nsCOMPtr.h"
#include "nsIPluginInstance.h"
#include "nsplugindefs.h"
#include "nsJavaHTMLObjectFactory.h"
#include "nsIJavaObjectInfo.h"
#include "nsIPluginTagInfo2.h"
#include "nsIPluginManager.h"
#include "nsIPluginManager2.h"
#include "nsIPluginInstancePeer.h"
#include "nsIPluginInstancePeer2.h"
#include "nsIJVMPluginInstance.h"
//#include "nsIPluginStreamListener.h"
class nsJavaHTMLObject;
/**
* this class is just wrapper forwarding functionality from
* older plugin based API to newer OJI2 based API
*/
class nsAppletHTMLObject : public nsIPluginInstance,
public nsIWFInstanceWrapper,
public nsIJVMPluginInstance
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWFINSTANCEWRAPPER
nsAppletHTMLObject(nsJavaHTMLObjectFactory *factory);
virtual ~nsAppletHTMLObject(void);
// from nsIPluginInstance
NS_IMETHOD Initialize(nsIPluginInstancePeer *peer);
NS_IMETHOD GetPeer(nsIPluginInstancePeer* *resultingPeer);
NS_IMETHOD Start(void);
NS_IMETHOD Stop(void);
NS_IMETHOD Destroy(void);
NS_IMETHOD SetWindow(nsPluginWindow* window);
NS_IMETHOD NewStream(nsIPluginStreamListener** listener);
NS_IMETHOD Print(nsPluginPrint* platformPrint);
NS_IMETHOD GetValue(nsPluginInstanceVariable variable, void *value);
NS_IMETHOD HandleEvent(nsPluginEvent* event, PRBool* handled);
// from nsIJVMPluginInstance
NS_IMETHOD GetJavaObject(jobject *result);
NS_IMETHOD GetText(const char* *result);
// friend proxy class
friend class nsJavaPluginInstanceProxy;
protected:
nsJavaHTMLObject* m_jobject;
nsJavaHTMLObjectFactory* m_factory;
jint m_id;
nsIPluggableJVM* m_jvm;
JNIEnv* m_env; /* cached JNIEnv of main Mozilla thread */
nsJavaObjectType mapType(nsPluginTagType pluginType);
// methods that can be called from main thread to do real job
NS_IMETHOD doShowStatus(const char* status);
NS_IMETHOD doShowDocument(const char* url,
const char* target);
NS_IMETHOD doGetJSThread(jint *jstid);
// kind of caching
nsIPluginInstancePeer* m_peer;
nsIPluginInstancePeer2* m_peer2;
nsCOMPtr<nsIPluginManager> m_mgr;
// workaround for incorrect lifecycle of plugin peer
PRBool m_dead;
PRThread* m_mainThread;
};
#endif

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

@ -0,0 +1,67 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsCJVMFactory.cpp,v 1.1 2001/05/09 18:51:35 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
/* -*- 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.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/NPL/
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsJavaHTMLObjectFactory.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
static NS_DEFINE_CID(kCPluggableJVMCID, NS_PLUGGABLEJVM_CID);
// The list of components we register
static nsModuleComponentInfo components[] =
{
{ "Waterfall API-based JVM Service",
NS_PLUGGABLEJVM_CID,
NS_INLINE_PLUGIN_CONTRACTID_PREFIX NS_JVM_MIME_TYPE,
nsJavaHTMLObjectFactory::Create,
},
};
NS_IMPL_NSGETMODULE("nsCJVMModule", components);

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

@ -0,0 +1,219 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsJavaHTMLObject.cpp,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsJavaHTMLObjectFactory.h"
#include "nsJavaHTMLObject.h"
NS_IMPL_ISUPPORTS1(nsJavaHTMLObject, nsIJavaHTMLObject)
nsJavaHTMLObject::nsJavaHTMLObject(nsJavaHTMLObjectFactory* f)
{
NS_INIT_ISUPPORTS();
m_factory = f;
NS_ADDREF(f);
m_id = 0;
m_jvm = NULL;
m_info = NULL;
}
nsJavaHTMLObject::~nsJavaHTMLObject()
{
OJI_LOG("nsJavaHTMLObject::~nsJavaHTMLObject");
if (m_factory) NS_RELEASE(m_factory);
}
/* [noscript] void SetWindow (in jp_jint ID); */
NS_IMETHODIMP nsJavaHTMLObject::SetWindow(jint ID)
{
OJI_LOG2("nsJavaHTMLObject::SetWindow(%ld)", ID);
if (m_id == 0)
{
OJI_LOG("SetWindow() for not inited obj!");
return NS_ERROR_FAILURE;
}
nsresult res;
if (ID == 0) return NS_OK;
// this is part of generic policy to minimize time occupied in main thread
// if this event will be proceed when user leaves page - nothing wrong, window
// will be just unregistered and Java-side SetWindow() will fail
// also it prevents possible deadlocks, when Java calls back to browser and
// browser main thread waits here and can't perform call
if (NS_FAILED(res = PostEvent((jint)PE_SETWINDOW, (jlong)ID)))
return res;
return NS_OK;
}
/* void Initialize (in nsISupports peer, in nsIPluggableJVM jvm); */
NS_IMETHODIMP
nsJavaHTMLObject::Initialize(nsISupports *peer,
nsIPluggableJVM *jvm)
{
nsresult res;
m_instance_peer = peer;
NS_ADDREF(m_instance_peer);
m_jvm = jvm;
NS_ADDREF(m_jvm);
m_id = 0;
if (NS_FAILED(res = m_jvm->CreateJavaPeer(this,
WF_APPLETPEER_CID,
&m_id)))
return res;
if (m_id == 0) return NS_ERROR_FAILURE;
OJI_LOG2("nsJavaHTMLObject::Initialize: got id %d", (int)m_id);
return NS_OK;
}
/* void Start (); */
NS_IMETHODIMP
nsJavaHTMLObject::Start()
{
nsresult res;
if (NS_FAILED(res = PostEvent((jint)PE_START, (jlong)m_id)))
return res;
return NS_OK;
}
/* void Stop (); */
NS_IMETHODIMP
nsJavaHTMLObject::Stop()
{
nsresult res;
if (NS_FAILED(res = PostEvent((jint)PE_STOP, (jlong)m_id)))
return res;
return NS_OK;
}
/* void Destroy (); */
NS_IMETHODIMP
nsJavaHTMLObject::Destroy()
{
nsresult res;
if (!m_jvm) return NS_ERROR_FAILURE;
if (NS_FAILED(res
= SendEvent((jint)PE_DESTROY, (jlong)m_id)))
return res;
if (NS_FAILED(res
= m_jvm->DestroyJavaPeer(m_id)))
return res;
//if (ID) m_jvm->UnregisterWindow(ID);
if (m_instance_peer) NS_RELEASE(m_instance_peer);
if (m_info) NS_RELEASE(m_info);
return NS_OK;
}
/* void GetPeer (out nsISupports peer); */
NS_IMETHODIMP
nsJavaHTMLObject::GetPeer(nsISupports **peer)
{
*peer = m_instance_peer;
NS_ADDREF(m_instance_peer);
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObject::SetJavaObjectInfo(nsIJavaObjectInfo* info)
{
if (m_info) NS_RELEASE(m_info);
m_info = info;
NS_ADDREF(m_info);
nsresult res;
JavaObjectWrapper* wrapper;
if (NS_FAILED(res = m_info->GetWrapper(&wrapper)))
return res;
if (NS_FAILED(res = PostEvent((jint)PE_NEWPARAMS, PTR_TO_JLONG(wrapper))))
return res;
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObject::GetJavaObjectInfo(nsIJavaObjectInfo* *info)
{
*info = m_info;
NS_ADDREF(m_info);
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObject::GetJavaPeer(jobject *pObj)
{
nsresult res;
OJI_LOG("nsJavaHTMLObject::GetJavaPeer");
if (!pObj) return NS_ERROR_NULL_POINTER;
*pObj = NULL;
// both ways should be OK, but event seems to work better in generic case
// as synchronized with other applet events
#if 0
if (NS_FAILED(res = m_jvm->JavaPeerCall(m_id,
PE_GETPEER,
PTR_TO_JLONG(pObj))))
return res;
#else
if (NS_FAILED(res = SendEvent(PE_GETPEER,
PTR_TO_JLONG(pObj))))
return res;
#endif
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObject::SetType(jint type)
{
nsresult res;
if (NS_FAILED(res = SendEvent(PE_SETTYPE, (jlong)type)))
return res;
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObject::GetDOMElement(nsIDOMElement* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsJavaHTMLObject::PostEvent(jint id, jlong data)
{
nsresult res;
if (!m_jvm || !m_id) return NS_ERROR_FAILURE;
if (NS_FAILED(res = m_jvm->PostEventToJavaPeer(m_id, id, data)))
return res;
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObject::SendEvent(jint id, jlong data)
{
nsresult res;
if (!m_jvm || !m_id) return NS_ERROR_FAILURE;
if (NS_FAILED(res = m_jvm->SendEventToJavaPeer(m_id, id, data, nsnull)))
return res;
return NS_OK;
}

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

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsJavaHTMLObject.h,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef __nsJavaHTMLObject_h
#define __nsJavaHTMLObject_h
#include "nsIJavaHTMLObject.h"
#include "nsIPluggableJVM.h"
#include "nsJavaHTMLObjectFactory.h"
#include "nsIJavaObjectInfo.h"
class nsJavaHTMLObject : public nsIJavaHTMLObject
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIJAVAHTMLOBJECT
nsJavaHTMLObject(nsJavaHTMLObjectFactory* f);
virtual ~nsJavaHTMLObject();
// generally bad idea, but I don't like to add smth plugin API
// specific into nsJavaHTMLObject
// ideally all this info should be obtained from peer
NS_IMETHOD SetJavaObjectInfo(nsIJavaObjectInfo* info);
NS_IMETHOD GetJavaObjectInfo(nsIJavaObjectInfo* *info);
protected:
nsJavaHTMLObjectFactory* m_factory;
nsISupports* m_instance_peer;
nsIPluggableJVM* m_jvm;
nsIJavaObjectInfo* m_info;
jint m_id;
};
#endif // __nsJavaHTMLObject_h

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

@ -0,0 +1,719 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsJavaHTMLObjectFactory.cpp,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsJavaHTMLObjectFactory.h"
#include "nsPluggableJVM.h"
#include "nsIFactory.h"
#include "nsIPluginInstance.h"
#include "nsJavaHTMLObject.h"
#include "nsAppletHTMLObject.h"
#include "nsIProxyObjectManager.h"
#include "nsIBrowserJavaSupport.h"
#include "nsIPluginInstancePeer.h"
#include "nsIPluginInstancePeer2.h"
#include "nsWFSecureEnv.h"
#include "nsWFSecurityContext.h"
#include "nsIThread.h"
#include "nsIJVMConsole.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID);
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIJavaHTMLObjectIID, NS_IJAVAHTMLOBJECT_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIPluggableJVMIID, NS_IPLUGGABLEJVM_IID);
static NS_DEFINE_IID(kIBrowserJavaSupportIID, NS_IBROWSERJAVASUPPORT_IID);
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kIPluginManager2IID, NS_IPLUGINMANAGER2_IID);
static NS_DEFINE_IID(kILiveConnectIID, NS_ILIVECONNECT_IID);
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kIPluginInstancePeer2IID, NS_IPLUGININSTANCEPEER2_IID);
static NS_DEFINE_IID(kIJVMPluginIID, NS_IJVMPLUGIN_IID);
static NS_DEFINE_IID(kIServiceManagerIID, NS_ISERVICEMANAGER_IID);
static NS_DEFINE_IID(kIJVMManagerIID, NS_IJVMMANAGER_IID);
static NS_DEFINE_IID(kIJVMConsoleIID, NS_IJVMCONSOLE_IID);
static NS_DEFINE_CID(kCLiveConnectCID, NS_CLIVECONNECT_CID);
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
static NS_DEFINE_CID(kCJVMManagerCID, NS_JVMMANAGER_CID);
nsJavaHTMLObjectFactory* nsJavaHTMLObjectFactory::instance = nsnull;
NS_IMPL_THREADSAFE_ISUPPORTS5(nsJavaHTMLObjectFactory, \
nsIFactory, \
nsIPlugin, \
nsIJVMPlugin, \
nsIJVMConsole, \
nsIBrowserJavaSupport)
static int GetProxyForURL(void* handle,
char* url,
char* *proxy)
{
nsresult res;
nsIBrowserJavaSupport* obj = (nsIBrowserJavaSupport*)handle;
res = obj->GetProxyForURL(url, proxy);
return res;
}
static int JSCall(void* handle, jint jstid, struct JSObject_CallInfo** call)
{
nsresult res;
nsIBrowserJavaSupport* obj = (nsIBrowserJavaSupport*)handle;
res = obj->JSCall(jstid, call);
return res;
}
nsJavaHTMLObjectFactory::nsJavaHTMLObjectFactory() {
NS_INIT_ISUPPORTS();
m_mgr2 = nsnull;
m_jvm = new nsPluggableJVM();
NS_ADDREF(m_jvm);
nsCOMPtr<nsIThread> mainIThread;
nsIThread::GetMainThread(getter_AddRefs(mainIThread));
mainIThread->GetPRThread(&m_mainThread);
instance = this;
m_jsjRecursion = 0;
}
nsJavaHTMLObjectFactory::~nsJavaHTMLObjectFactory() {
OJI_LOG("nsJavaHTMLObjectFactory::~nsJavaHTMLObjectFactory");
NS_RELEASE(m_jvm);
free(m_wrapper);
}
NS_METHOD
nsJavaHTMLObjectFactory::Create(nsISupports* outer,
const nsIID& aIID,
void* *aInstancePtr)
{
//OJI_LOG2("nsJavaHTMLObjectFactory::Create with %p", outer);
//OJI_LOG2("it is %s", aIID.ToString());
if (!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
*aInstancePtr = nsnull;
nsresult rv = NS_OK;
if (!instance)
{
instance = new nsJavaHTMLObjectFactory();
rv = instance->Initialize();
if (NS_FAILED(rv)) return rv;
}
if (aIID.Equals(kIPluginIID) || aIID.Equals(kIFactoryIID))
{
return instance->QueryInterface(aIID, aInstancePtr);
}
if (aIID.Equals(kIPluginInstanceIID) || aIID.Equals(kIJavaHTMLObjectIID))
{
return instance->CreateInstance(outer,
aIID,
aInstancePtr);
}
OJI_LOG2("nsJavaHTMLObjectFactory::Create: no matching ifaces for %s",
aIID.ToString());
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::CreateInstance(nsISupports *aOuter,
const nsIID & aIID,
void **result)
{
*result = NULL;
if (aOuter != NULL)
{
OJI_LOG("Aggregation of nsJavaHTMLObjectFactory failed");
return NS_ERROR_NO_AGGREGATION;
}
if (!m_jvm) return NS_ERROR_FAILURE;
// XXX: remove me when it'll be called by Mozilla
//if (NS_FAILED(Initialize())) return NS_ERROR_FAILURE;
if (aIID.Equals(kIJavaHTMLObjectIID))
{
OJI_LOG("NEW API - creating IJavaHTMLObject");
nsJavaHTMLObject* instance = new nsJavaHTMLObject(this);
*result = (nsIJavaHTMLObject*) instance;
NS_ADDREF(instance);
return NS_OK;
}
// it's current Mozilla API where it ask us to create PluginInstance
// give it a wrapper
if (aIID.Equals(kIPluginInstanceIID))
{
OJI_LOG("OLD API - creating IPluginInstance");
nsAppletHTMLObject* instance = new nsAppletHTMLObject(this);
*result = (nsIPluginInstance *) instance;
NS_ADDREF(instance);
return NS_OK;
}
if (aIID.Equals(kIPluginIID))
{
OJI_LOG("request for factory");
return QueryInterface(kIPluginIID, result);
}
return NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::Initialize(void)
{
//OJI_LOG2("nsJavaHTMLObjectFactory::Initialize: %p", this);
static int inited = 0;
if (inited) return NS_OK;
nsresult res;
nsPluggableJVMStatus status;
res = nsServiceManager::GetService(kPluginManagerCID,
kIPluginManagerIID,
getter_AddRefs(m_mgr));
if (NS_FAILED(res)) return res;
res = nsServiceManager::GetService(kCJVMManagerCID,
kIJVMManagerIID,
getter_AddRefs(m_jvmMgr));
if (NS_FAILED(res)) return res;
m_mgr2 = do_QueryInterface(m_mgr);
if (m_mgr2 == nsnull) return NS_ERROR_FAILURE;
m_wrapper = (BrowserSupportWrapper*) malloc(sizeof(BrowserSupportWrapper));
m_wrapper->info = (void*)(nsIBrowserJavaSupport*)this;
m_wrapper->GetProxyForURL = &::GetProxyForURL;
m_wrapper->JSCall = &::JSCall;
res = m_jvm->StartupJVM("", &status, PTR_TO_JLONG(m_wrapper));
if (NS_FAILED(res) || status != nsPluggableJVMStatus_Running)
return NS_ERROR_FAILURE;
m_jvm->GetJNIEnv(&m_env);
inited = 1;
OJI_LOG("nsJavaHTMLObjectFactory::Initialize done");
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::CreatePluginInstance(nsISupports *aOuter,
REFNSIID aIID,
const char * aMimeType,
void **result)
{
return CreateInstance(aOuter, aIID, result);
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::GetMIMEDescription(const char **resDesc)
{
*resDesc =
"application/x-java-vm::Java(tm) Plug-in"
";application/x-java-applet::Java(tm) Plug-in"
";application/x-java-applet:version=1.1::Java(tm) Plug-in"
";application/x-java-applet:version=1.1.1::Java(tm) Plug-in"
";application/x-java-applet:version=1.1.2::Java(tm) Plug-in"
";application/x-java-applet:version=1.1.3::Java(tm) Plug-in"
";application/x-java-applet:version=1.2::Java(tm) Plug-in"
";application/x-java-applet:version=1.2.1::Java(tm) Plug-in"
";application/x-java-applet:version=1.2.2::Java(tm) Plug-in"
";application/x-java-applet:version=1.3::Java(tm) Plug-in"
";application/x-java-bean::Java(tm) Plug-in"
";application/x-java-bean:version=1.1::Java(tm) Plug-in"
";application/x-java-bean:version=1.1.1::Java(tm) Plug-in"
";application/x-java-bean:version=1.1.2::Java(tm) Plug-in"
";application/x-java-bean:version=1.1.3::Java(tm) Plug-in"
";application/x-java-bean:version=1.2::Java(tm) Plug-in"
";application/x-java-bean:version=1.2.1::Java(tm) Plug-in"
";application/x-java-bean:version=1.2.2::Java(tm) Plug-in"
";application/x-java-bean:version=1.3::Java(tm) Plug-in"
"";
return NS_OK;
}
NS_IMETHODIMP nsJavaHTMLObjectFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::Shutdown(void)
{
OJI_LOG("nsJavaHTMLObjectFactory::Shutdown");
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::GetValue(nsPluginVariable variable,
void *value)
{
nsresult err = NS_OK;
return err;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::GetJVM(nsIPluggableJVM* *jvm)
{
if ((jvm != NULL) && (m_jvm != NULL))
{
*jvm = m_jvm;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::Show()
{
if (m_jvm) return m_jvm->SetConsoleVisibility(PR_TRUE);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::Hide()
{
if (m_jvm) return m_jvm->SetConsoleVisibility(PR_FALSE);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::IsVisible(PRBool *result)
{
if (m_jvm) return m_jvm->GetConsoleVisibility(result);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::Print(const char* msg,
const char* encodingName)
{
if (m_jvm) return m_jvm->PrintToConsole(msg, encodingName);
return NS_ERROR_FAILURE;
}
/* HERE INTERTHREAD PROXY STUFF FOLLOWS */
// utility proxy class
class nsJavaPluginProxy : public nsIJavaPluginProxy
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIJAVAPLUGINPROXY
nsJavaPluginProxy();
virtual ~nsJavaPluginProxy();
NS_IMETHOD Init(nsJavaHTMLObjectFactory* owner);
protected:
nsJavaHTMLObjectFactory* m_owner;
};
NS_IMPL_THREADSAFE_ISUPPORTS1(nsJavaPluginProxy,
nsIJavaPluginProxy);
nsJavaPluginProxy::nsJavaPluginProxy()
{
NS_INIT_ISUPPORTS();
}
NS_IMETHODIMP
nsJavaPluginProxy::Init(nsJavaHTMLObjectFactory* owner)
{
m_owner = owner;
NS_ADDREF(owner);
return NS_OK;
}
nsJavaPluginProxy::~nsJavaPluginProxy()
{
NS_RELEASE(m_owner);
}
NS_IMETHODIMP
nsJavaPluginProxy::GetProxyForURL(const char* url,
char* *result)
{
return m_owner->doGetProxyForURL(url, result);
}
NS_IMETHODIMP
nsJavaPluginProxy::JSCall(jint jstid, struct JSObject_CallInfo** call)
{
return m_owner->doJSCall(jstid, call);
}
/* END OF INTERTHREAD STUFF */
NS_IMETHODIMP
nsJavaHTMLObjectFactory::GetProxyForURL(const char *url, char **proxy)
{
nsresult rv = NS_OK;
if (PR_GetCurrentThread() == m_mainThread)
return doGetProxyForURL(url, proxy);
nsCOMPtr<nsJavaPluginProxy> inst =
new nsJavaPluginProxy();
inst->Init(this);
nsCOMPtr<nsIJavaPluginProxy> instProxy;
NS_WITH_SERVICE(nsIProxyObjectManager, proxyObjectManager,
kProxyObjectManagerCID, &rv);
rv = proxyObjectManager->
GetProxyForObject(NS_UI_THREAD_EVENTQ,
NS_GET_IID(nsIJavaPluginProxy),
NS_STATIC_CAST(nsISupports*, inst),
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(instProxy));
if (NS_FAILED(rv)) return rv;
rv = instProxy->GetProxyForURL(url, proxy);
return rv;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::JSCall(jint jstid, struct JSObject_CallInfo** call)
{
nsresult rv = NS_OK;
// TODO: I dunno why, but if not proxify it, some calls like GetWindow
// just fails, maybe due timing issues. I have to investigate it in the
// future.
// if this thread is already main thread - don't forward anything
//if (PR_GetCurrentThread() == m_mainThread) return doJSCall(jstid, call);
nsCOMPtr<nsJavaPluginProxy> inst = new nsJavaPluginProxy();
inst->Init(this);
nsCOMPtr<nsIJavaPluginProxy> instProxy;
NS_WITH_SERVICE(nsIProxyObjectManager, proxyObjectManager,
kProxyObjectManagerCID, &rv);
rv = proxyObjectManager->
GetProxyForObject(NS_UI_THREAD_EVENTQ,
NS_GET_IID(nsIJavaPluginProxy),
NS_STATIC_CAST(nsISupports*, inst),
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(instProxy));
if (NS_FAILED(rv)) return rv;
rv = instProxy->JSCall(jstid, call);
return rv;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::doGetProxyForURL(const char* url,
char* *proxy)
{
if (!m_mgr2)
{
*proxy = nsCRT::strdup(""); // falls back to direct connection
return NS_OK;
}
return m_mgr2->FindProxyForURL(url, proxy);
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::doJSCall(jint jstid, struct JSObject_CallInfo** call)
{
// placed here to avoid lifetime pain in switch
nsCOMPtr<nsIPluginInstance> plugin = nsnull;
nsCOMPtr<nsISecurityContext> pContext = nsnull;
nsresult rv = NS_OK;
if ((*call)->pWrapper && (*call)->pWrapper->dead)
{
OJI_LOG("JSObject dead before JS call can be performed.");
return NS_ERROR_FAILURE;
}
NS_WITH_SERVICE(nsIJVMManager, pJVMManager, kCJVMManagerCID, &rv);
if (NS_FAILED(rv))
{
OJI_LOG2("cannot get JVMManager service: %x", rv);
return rv;
}
if (m_liveConnect == nsnull && NS_FAILED(rv = initLiveConnect()))
{
OJI_LOG2("Cannot init Live Connect: %x", rv);
return rv;
}
JNIEnv* pProxyJNIEnv = nsnull;
if (NS_FAILED(rv = pJVMManager->CreateProxyJNI(NULL, &pProxyJNIEnv)))
{
OJI_LOG2("Cannot create proxy JNI: %x", rv);
return rv;
}
if (NS_FAILED(rv=nsWFSecurityContext::Create(NULL, m_jvm,
(*call)->jAccessControlContext,
(*call)->pszUrl,
kISupportsIID,
getter_AddRefs(pContext))))
{
OJI_LOG2("Cannot create proper security context: %x", rv);
return rv;
}
m_jsjRecursion++;
if (m_jsjRecursion > 1) OJI_LOG2("incremented depth=%d!!!",
(int)m_jsjRecursion);
switch ((*call)->type)
{
case JS_GetWindow:
OJI_LOG2("JS_GetWindow: %p", (*call)->data.__getWindow.pPlugin);
plugin = do_QueryInterface((nsISupports*)((*call)->data.__getWindow.pPlugin));
if (plugin == nsnull)
{
OJI_LOG("Bug in internals - pPlugin field is incorrect");
break;
}
if (NS_FAILED(m_liveConnect->GetWindow(pProxyJNIEnv,
plugin,
NULL,
0,
(nsISupports*)pContext,
(jsobject*) &((*call)->data.__getWindow.iNativeJSObject))))
OJI_LOG("Liveconnect::GetWindow failed");
break;
case JS_Eval:
{
jobject ret = NULL;
OJI_LOG2("JS_Eval: script len=%d", (*call)->data.__eval.iEvalLen);
if (NS_FAILED(m_liveConnect->Eval(pProxyJNIEnv,
(jsobject)(*call)->data.__eval.iNativeJSObject,
(*call)->data.__eval.pszEval,
(*call)->data.__eval.iEvalLen,
NULL,
0,
(nsISupports*)pContext,
&ret)))
{
OJI_LOG("Liveconnect::Eval failed");
}
else
{
if (ret != NULL)
(*call)->data.__eval.jResult = m_env->NewGlobalRef(ret);
}
break;
}
case JS_ToString:
{
jstring ret = NULL;
m_liveConnect->ToString(pProxyJNIEnv,
(jsobject)(*call)->data.__toString.iNativeJSObject,
&ret);
if (ret != NULL)
(*call)->data.__toString.jResult = (jstring)(m_env->NewGlobalRef(ret));
break;
}
case JS_Finalize:
OJI_LOG2("JS_Finalize: %x",
(int)(*call)->data.__finalize.iNativeJSObject);
m_liveConnect->FinalizeJSObject(pProxyJNIEnv,
(jsobject)(*call)->data.__finalize.iNativeJSObject);
break;
case JS_Call:
{
jobject ret = NULL;
OJI_LOG2("JS_Call: obj=%x",
(int)(*call)->data.__call.iNativeJSObject);
if (NS_FAILED(m_liveConnect->Call(pProxyJNIEnv,
(jsobject)
(*call)->data.__call.iNativeJSObject,
(*call)->data.__call.pszMethodName,
(*call)->data.__call.iMethodNameLen,
(*call)->data.__call.jArgs,
/* (void**)&pPrincipal, */ NULL,
/* principalLen, */ 0,
(nsISupports*)pContext,
&ret)))
{
OJI_LOG("Call failed");
break;
}
if (ret != NULL)
(*call)->data.__call.jResult = m_env->NewGlobalRef(ret);
}
break;
case JS_GetMember:
{
jobject ret = NULL;
m_liveConnect->GetMember(pProxyJNIEnv,
(jsobject)(*call)->data.__getMember.iNativeJSObject,
(*call)->data.__getMember.pszName,
(*call)->data.__getMember.iNameLen,
/* (void**)&pPrincipal, */ NULL,
/* principalLen, */ 0,
(nsISupports*)pContext,
&ret);
if (ret != NULL)
(*call)->data.__getMember.jResult = m_env->NewGlobalRef(ret);
break;
}
case JS_SetMember:
m_liveConnect->SetMember(pProxyJNIEnv,
(jsobject)(*call)->data.__setMember.iNativeJSObject,
(*call)->data.__setMember.pszName,
(*call)->data.__setMember.iNameLen,
(*call)->data.__setMember.jValue,
/* (void**)&pPrincipal, */ NULL,
/* principalLen, */ 0,
(nsISupports*)pContext);
break;
case JS_RemoveMember:
m_liveConnect->RemoveMember(pProxyJNIEnv,
(jsobject)(*call)->data.__removeMember.iNativeJSObject,
(*call)->data.__removeMember.pszName,
(*call)->data.__removeMember.iNameLen,
/* (void**)&pPrincipal, */ NULL,
/* principalLen, */ 0,
(nsISupports*)pContext);
break;
case JS_GetSlot:
{
jobject ret = NULL;
m_liveConnect->GetSlot(pProxyJNIEnv,
(jsobject)(*call)->data.__getSlot.iNativeJSObject,
(*call)->data.__getSlot.iIndex,
/* (void**)&pPrincipal, */ NULL,
/* principalLen, */ 0,
(nsISupports*)pContext,
&ret);
if (ret != NULL)
(*call)->data.__getSlot.jResult = m_env->NewGlobalRef(ret);
break;
}
case JS_SetSlot:
m_liveConnect->SetSlot(pProxyJNIEnv,
(jsobject)(*call)->data.__setSlot.iNativeJSObject,
(*call)->data.__setSlot.iIndex,
(*call)->data.__setSlot.jValue,
/* (void**)&pPrincipal, */ NULL,
/* principalLen, */ 0,
(nsISupports*)pContext);
break;
default:
OJI_LOG2("UNKNOWN CALL: %d", (*call)->type);
}
jthrowable jException = m_env->ExceptionOccurred();
if (jException != NULL)
{
OJI_LOG("exception in doJSCall");
m_env->ExceptionDescribe();
// Clean up exception
m_env->ExceptionClear();
// Store the exception in JSObject_CallInfo
(*call)->jException =
NS_STATIC_CAST(jthrowable, m_env->NewGlobalRef(jException));
// Release local ref
m_env->DeleteLocalRef(jException);
}
m_jsjRecursion--;
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::AddToClassPath(const char* dirPath)
{
OJI_LOG("nsJavaHTMLObjectFactory::AddToClassPath");
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::RemoveFromClassPath(const char* dirPath)
{
OJI_LOG("nsJavaHTMLObjectFactory::RemoveFromClassPath");
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::GetClassPath(const char* *result)
{
OJI_LOG("nsJavaHTMLObjectFactory::GetClassPath");
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::GetJavaWrapper(JNIEnv* jenv,
jint jsobj,
jobject *jobj)
{
OJI_LOG2("GetJavaWrapper for %x", (int)jsobj);
if (!m_jvm || !jobj) return NS_ERROR_FAILURE;
*jobj = NULL;
return m_jvm->GetJavaWrapper(jsobj, jobj);
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::CreateSecureEnv(JNIEnv* proxyEnv,
nsISecureEnv* *outSecureEnv)
{
return nsWFSecureEnv::Create(m_jvm,
kISupportsIID, (void**)outSecureEnv);
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::SpendTime(PRUint32 timeMillis)
{
OJI_LOG("nsJavaHTMLObjectFactory::SpendTime");
return NS_OK;
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::UnwrapJavaWrapper(JNIEnv* jenv,
jobject jobj,
jint* jsobj)
{
OJI_LOG2("nsJavaHTMLObjectFactory::UnwrapJavaWrapper for %x", (int)jobj);
if (!m_jvm || !jsobj) return NS_ERROR_FAILURE;
*jsobj = 0;
return m_jvm->UnwrapJavaWrapper(jobj, jsobj);
}
NS_IMETHODIMP
nsJavaHTMLObjectFactory::initLiveConnect()
{
nsresult res;
res = nsServiceManager::GetService(kCLiveConnectCID,
kILiveConnectIID,
getter_AddRefs(m_liveConnect));
if (NS_FAILED(res))
{
OJI_LOG2("cannot get LiveConnect service from browser: %x", res);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -0,0 +1,124 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsJavaHTMLObjectFactory.h,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef __nsJavaHTMLObjectFactory_h
#define __nsJavaHTMLObjectFactory_h
#include "nsCOMPtr.h"
#include "nsPluggableJVM.h"
#include "nsIBrowserJavaSupport.h"
#include "nsIPlugin.h"
#include "nsIPluginManager.h"
#include "nsIPluginManager2.h"
#include "nsILiveconnect.h"
#include "nsILiveConnectManager.h"
#include "nsIJavaObjectInfo.h"
#include "nsIJVMPlugin.h"
#include "nsIJVMManager.h"
#include "nsIJVMConsole.h"
#include "nsIServiceManager.h"
#include "wf_moz6_common.h"
/* this class is derived from nsIPlugin as I don't like idea
* to touch Mozilla internals in applet handling rigth now
*/
class nsJavaHTMLObjectFactory : public nsIPlugin,
public nsIJVMPlugin,
public nsIBrowserJavaSupport,
public nsIJVMConsole
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIBROWSERJAVASUPPORT
virtual ~nsJavaHTMLObjectFactory(void);
// nsIFactory
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID & iid,
void **result);
NS_IMETHOD LockFactory(PRBool aLock);
// nsIPlugin
NS_IMETHOD CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID,
const char* aPluginMIMEType,
void **aResult);
NS_IMETHOD Initialize(void);
NS_IMETHOD Shutdown(void);
NS_IMETHOD GetMIMEDescription(const char* *resultingDesc);
NS_IMETHOD GetValue(nsPluginVariable variable, void *value);
// nsIJVMPlugin
NS_IMETHOD AddToClassPath(const char* dirPath);
NS_IMETHOD RemoveFromClassPath(const char* dirPath);
NS_IMETHOD GetClassPath(const char* *result);
NS_IMETHOD GetJavaWrapper(JNIEnv* jenv, jint obj, jobject *jobj);
NS_IMETHOD CreateSecureEnv(JNIEnv* proxyEnv, nsISecureEnv* *outSecureEnv);
NS_IMETHOD SpendTime(PRUint32 timeMillis);
NS_IMETHOD UnwrapJavaWrapper(JNIEnv* jenv, jobject jobj, jint* obj);
// nsIJVMConsole
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD IsVisible(PRBool *result);
NS_IMETHOD Print(const char* msg, const char* encodingName = NULL);
// the only way to create instance using this factory
static NS_METHOD Create(nsISupports* outer,
const nsIID& aIID,
void* *aInstancePtr);
// Get JVM used by this factory now
// doesn't NS_ADDREF result
NS_IMETHOD GetJVM(nsIPluggableJVM* *jvm);
// friend proxy class
friend class nsJavaPluginProxy;
static nsJavaHTMLObjectFactory* instance;
protected:
nsJavaHTMLObjectFactory();
nsPluggableJVM* m_jvm;
nsCOMPtr<nsIPluginManager> m_mgr;
nsCOMPtr<nsIPluginManager2> m_mgr2;
nsCOMPtr<nsILiveconnect> m_liveConnect;
nsCOMPtr<nsIJVMManager> m_jvmMgr;
BrowserSupportWrapper* m_wrapper;
JNIEnv* m_env;
NS_IMETHOD doGetProxyForURL(const char* url,
char* *target);
NS_IMETHOD doJSCall(jint jstid, struct JSObject_CallInfo** call);
NS_IMETHOD initLiveConnect();
PRThread* m_mainThread;
jint m_jsjRecursion;
};
#endif //__nsJavaHTMLObjectFactory_h

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

@ -0,0 +1,283 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsJavaObjectInfo.cpp,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsJavaObjectInfo.h"
#include "nsCOMPtr.h"
#include "nsIWFInstanceWrapper.h"
#include "nsIPluginInstance.h"
#include "wf_moz6_common.h"
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIWFInstanceWrapperIID, NS_IWFINSTANCEWRAPPER_IID);
static int GetParameters(void* handle, char*** keys,
char*** vals, int* count)
{
nsIJavaObjectInfo* obj = (nsIJavaObjectInfo*)handle;
return obj->GetParameters(keys, vals, (PRUint32*)count);
}
static int ShowDocument(void* handle, char* url, char* target)
{
nsresult res;
nsIJavaObjectInfo* obj = (nsIJavaObjectInfo*)handle;
nsCOMPtr<nsIWFInstanceWrapper> wrapper;
if (NS_FAILED(res = obj->GetPluginWrapper(getter_AddRefs(wrapper))))
return res;
return (wrapper->ShowDocument(url, target));
}
static int ShowStatus(void* handle, char* status)
{
nsresult res;
nsIJavaObjectInfo* obj = (nsIJavaObjectInfo*)handle;
nsCOMPtr<nsIWFInstanceWrapper> wrapper;
if (NS_FAILED(res = obj->GetPluginWrapper(getter_AddRefs(wrapper))))
return res;
return (wrapper->ShowStatus(status));
}
static int GetJSThread(void* handle, jint* jstid)
{
nsresult res;
nsIJavaObjectInfo* obj = (nsIJavaObjectInfo*)handle;
nsCOMPtr<nsIWFInstanceWrapper> wrapper;
if (NS_FAILED(res = obj->GetPluginWrapper(getter_AddRefs(wrapper))))
return res;
return (wrapper->GetJSThread(jstid));
}
static int WrapperAddRef(JavaObjectWrapper* me)
{
return 1;
}
static int WrapperRelease(JavaObjectWrapper* me)
{
//if (--me->counter > 0) return me->counter;
nsIPluginInstance* plugin = (nsIPluginInstance*)(me->plugin);
if (plugin) NS_RELEASE(plugin);
free(me);
return 0;
}
NS_IMPL_ISUPPORTS1(nsJavaObjectInfo, nsIJavaObjectInfo)
nsJavaObjectInfo::nsJavaObjectInfo(nsISupports* instance)
{
NS_INIT_ISUPPORTS();
m_argc = 0;
m_size = 5;
m_step = 3;
m_keys = (char**) malloc(m_size*sizeof(char*));
m_vals = (char**) malloc(m_size*sizeof(char*));
m_docbase = NULL;
m_instance = instance;
// backward compatibility with plugin API - fix when new API will appear
if (NS_FAILED(m_instance->QueryInterface(kIWFInstanceWrapperIID,
(void**)&m_jpiwrapper)))
OJI_LOG("FAILED to get nsIWFInstanceWrapper");
nsIPluginInstance* plugin = nsnull;
if (NS_FAILED(m_instance->QueryInterface(kIPluginInstanceIID,
(void**)&plugin)))
OJI_LOG("FAILED to get nsIPluginInstance");
/* member initializers and constructor code */
m_wrapper = (JavaObjectWrapper*) malloc(sizeof(JavaObjectWrapper));
m_wrapper->info = (void*)this;
m_wrapper->plugin = (void*)plugin;
m_wrapper->GetParameters = &::GetParameters;
m_wrapper->ShowDocument = &::ShowDocument;
m_wrapper->ShowStatus = &::ShowStatus;
m_wrapper->GetJSThread = &::GetJSThread;
m_wrapper->dead = 0;
}
nsJavaObjectInfo::~nsJavaObjectInfo()
{
OJI_LOG("nsJavaObjectInfo::~nsJavaObjectInfo");
for (PRUint32 i=0; i < m_argc; i++)
{
if (m_keys[i]) free(m_keys[i]);
if (m_vals[i]) free(m_vals[i]);
}
free(m_keys);
free(m_vals);
if (m_jpiwrapper) NS_RELEASE(m_jpiwrapper);
WrapperRelease(m_wrapper);
// if m_wrapper is hold by someone else, like Java native method
// set field in wrapper that it cannot be used anymore and should be released
//m_wrapper->dead = 1;
//m_wrapper->Release(m_wrapper);
}
/* void addParameter (in string key, in string value); */
NS_IMETHODIMP
nsJavaObjectInfo::AddParameter(const char *key, const char *value)
{
OJI_LOG3("adding {%s} => {%s}", key, value);
if (m_argc >= m_size)
{
//OJI_LOG3("Enlarge vector from %d to %d", m_size, m_size+m_step);
m_size += m_step;
m_keys = (char**) realloc(m_keys, m_size*sizeof(char*));
m_vals = (char**) realloc(m_vals, m_size*sizeof(char*));
}
m_keys[m_argc] = strdup(key);
m_vals[m_argc] = strdup(value);
m_argc++;
return NS_OK;
}
/* void getParameters ([array, size_is (count)] out string keys, [array, size_is
(count)] out string values, [retval] out PRUint32 count); */
NS_IMETHODIMP
nsJavaObjectInfo::GetParameters(char ***keys, char ***values,
PRUint32 *count)
{
*keys = m_keys;
*values = m_vals;
*count = m_argc;
return NS_OK;
}
/* attribute string docBase; */
NS_IMETHODIMP
nsJavaObjectInfo::GetDocBase(char * *aDocBase)
{
*aDocBase = m_docbase;
return NS_OK;
}
NS_IMETHODIMP
nsJavaObjectInfo::SetDocBase(const char * aDocBase)
{
free(m_docbase);
m_docbase = strdup(aDocBase);
AddParameter("docbase", aDocBase);
return NS_OK;
}
/* attribute string encoding; */
NS_IMETHODIMP
nsJavaObjectInfo::GetEncoding(char * *aEncoding)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsJavaObjectInfo::SetEncoding(const char * aEncoding)
{
AddParameter("encoding", aEncoding);
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute string alignment; */
NS_IMETHODIMP
nsJavaObjectInfo::GetAlignment(char * *aAlignment)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsJavaObjectInfo::SetAlignment(const char * aAlignment)
{
AddParameter("align", aAlignment);
return NS_ERROR_NOT_IMPLEMENTED;
}
// ask peer
/* attribute PRUint32 width; */
NS_IMETHODIMP
nsJavaObjectInfo::GetWidth(PRUint32 *aWidth)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsJavaObjectInfo::SetWidth(PRUint32 aWidth)
{
//char buf[10];
//snprintf(buf, 9, "%d", aWidth);
//AddParameter("width", buf);
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute PRUint32 height; */
NS_IMETHODIMP
nsJavaObjectInfo::GetHeight(PRUint32 *aHeight)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsJavaObjectInfo::SetHeight(PRUint32 aHeight)
{
//char buf[10];
//snprintf(buf, 9, "%d", aHeight);
//AddParameter("height", buf);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsJavaObjectInfo::SetType(nsJavaObjectType type)
{
m_type = type;
return NS_OK;
}
NS_IMETHODIMP
nsJavaObjectInfo::GetType(nsJavaObjectType* type)
{
*type = m_type;
return NS_OK;
}
NS_IMETHODIMP
nsJavaObjectInfo::GetOwner(nsIJavaHTMLObject **owner)
{
*owner = m_owner;
NS_ADDREF(m_owner);
return NS_OK;
}
NS_IMETHODIMP
nsJavaObjectInfo::GetWrapper(JavaObjectWrapper* *res)
{
*res = m_wrapper;
return NS_OK;
}
NS_IMETHODIMP
nsJavaObjectInfo::GetPluginWrapper(nsIWFInstanceWrapper* *wrapper)
{
*wrapper = m_jpiwrapper;
NS_ADDREF(m_jpiwrapper);
return NS_OK;
}

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

@ -0,0 +1,54 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsJavaObjectInfo.h,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef __nsJavaObjectInfo_h__
#define __nsJavaObjectInfo_h__
#include "nsIJavaObjectInfo.h"
#include "nsIJavaHTMLObject.h"
#include "nsIWFInstanceWrapper.h"
class nsJavaObjectInfo : public nsIJavaObjectInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIJAVAOBJECTINFO
nsJavaObjectInfo(nsISupports* peer);
virtual ~nsJavaObjectInfo();
NS_IMETHOD SetType(nsJavaObjectType type);
private:
char **m_keys, **m_vals;
PRUint32 m_argc, m_size, m_step;
char* m_docbase;
nsISupports* m_instance;
nsJavaObjectType m_type;
nsIJavaHTMLObject* m_owner;
JavaObjectWrapper* m_wrapper;
nsIWFInstanceWrapper* m_jpiwrapper;
};
#endif

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

@ -0,0 +1,459 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsPluggableJVM.cpp,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsoji2.h"
#include "nsPluggableJVM.h"
#include "nsIJavaHTMLObject.h"
#include "wf_moz6_common.h"
// just as I'm lazy to Create/Cleanup Java calls
#include "nsWFSecureEnv.h"
NS_IMPL_ISUPPORTS1(nsPluggableJVM, nsIPluggableJVM)
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPluggableJVMIID, NS_IPLUGGABLEJVM_IID);
nsPluggableJVM::nsPluggableJVM()
{
NS_INIT_ISUPPORTS();
m_extID = 0;
m_dll = nsnull;
}
nsPluggableJVM::~nsPluggableJVM()
{
OJI_LOG("nsPluggableJVM::~nsPluggableJVM");
if (m_jvmp_context)
{
if (m_extID)
(m_jvmp_context->JVMP_UnregisterExtension)(m_ctx, m_extID);
}
}
NS_IMETHODIMP
nsPluggableJVM::RegisterWindow(nsPluginWindow* rwin,
jint *ID)
{
JVMP_DrawingSurfaceInfo w;
OJI_LOG("nsPluggableJVM::RegisterWindow");
w.window = (JPluginWindow *)rwin->window;
w.x = rwin->x;
w.y = rwin->y;
w.width = rwin->width;
w.height = rwin->height;
if ((m_jvmp_context->JVMP_RegisterWindow)(m_ctx, &w, ID) != JNI_TRUE)
{
OJI_LOG("can\'t register window");
return NS_ERROR_FAILURE;
};
OJI_LOG2("Registed our native window with ID %ld", *ID);
return NS_OK;
}
/* void UnregisterWindow (in jp_jint ID); */
NS_IMETHODIMP
nsPluggableJVM::UnregisterWindow(jint ID)
{
if ((m_jvmp_context->JVMP_UnregisterWindow)(m_ctx, ID) != JNI_TRUE)
{
OJI_LOG("can\'t unregister window");
return NS_ERROR_FAILURE;
};
return NS_OK;
}
NS_IMETHODIMP
nsPluggableJVM::RegisterMonitor(PRMonitor* rmon, jint *pID)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void UnregisterMonitor (in jp_jint ID); */
NS_IMETHODIMP
nsPluggableJVM::UnregisterMonitor(jint ID)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsPluggableJVM::GetJavaWrapper(jint obj, jobject *wrapper)
{
struct Java_CallInfo* call;
nsresult rv = NS_OK;
*wrapper = NULL;
if (!m_extID) return NS_ERROR_FAILURE;
nsWFSecureEnv::CreateJavaCallInfo(&call, NULL);
call->type = Java_WrapJSObject;
call->jException = NULL;
call->data.__wrapJSObject.jsObject = obj;
call->data.__wrapJSObject.jstid = (jint)PR_GetCurrentThread();
rv = ExtensionCall(1, PTR_TO_JLONG(call));
if (!NS_FAILED(rv))
{
// XXX: do smth meaningful with possible Java exception
if (call->jException) {
DeleteLocalRef(call->jException);
rv = NS_ERROR_FAILURE;
} else {
// global ref already created
*wrapper = call->data.__wrapJSObject.jObject;
}
}
nsWFSecureEnv::CleanupJavaCallInfo(call, NULL);
return rv;
}
NS_IMETHODIMP
nsPluggableJVM::UnwrapJavaWrapper(jobject jobj, jint *jsobj)
{
struct Java_CallInfo* call;
nsresult rv = NS_OK;
if (jsobj == NULL || !m_extID) return NS_ERROR_FAILURE;
if (jobj == NULL)
{
*jsobj = 0;
return NS_OK;
}
*jsobj = 0;
nsWFSecureEnv::CreateJavaCallInfo(&call, NULL);
call->type = Java_UnwrapJObject;
call->jException = NULL;
call->data.__unwrapJObject.jObject = jobj;
call->data.__unwrapJObject.jstid = (jint)PR_GetCurrentThread();
rv = ExtensionCall(1, PTR_TO_JLONG(call));
if (!NS_FAILED(rv))
{
// XXX: do smth meaningful with possible Java exception
if (call->jException) {
DeleteLocalRef(call->jException);
rv = NS_ERROR_FAILURE;
} else {
*jsobj = call->data.__unwrapJObject.jsObject;
}
}
nsWFSecureEnv::CleanupJavaCallInfo(call, NULL);
return rv;
}
NS_IMETHODIMP
nsPluggableJVM::GetJNIEnv(JNIEnv* *env)
{
JVMP_CallingContext* ctx;
int res;
res = (m_jvmp_context->JVMP_GetCallingContext)(&ctx);
if (res != JNI_TRUE) return NS_ERROR_FAILURE;
*env = ctx->env;
return NS_OK;;
}
static int newPrincipalsFromStrings(jbyte** *resprin,
jint* *reslen, jint num, ...)
{
jint* prins_len;
jbyte* *prins;
char* str;
jint i, len;
va_list ap;
prins_len = (jint*)malloc(num*sizeof(jint));
if (!prins_len) return 0;
prins = (jbyte**)malloc(num*sizeof(jbyte**));
if (!prins) return 0;
va_start(ap, num);
for (i=0; i<num; i++)
{
str = va_arg(ap, char*);
len = str ? strlen(str) : 0;
prins[i] = (jbyte*)malloc(len);
if (!prins[i]) return 0;
prins_len[i] = len;
/* not copy last 0 */
memcpy(prins[i], str, len);
}
va_end(ap);
*resprin = prins;
*reslen = prins_len;
return 1;
}
static int deletePrincipals(jbyte** prins, jint* plen, jint len)
{
int i;
for (i=0; i<len; i++) free(prins[i]);
free(prins);
free(plen);
return 1;
}
NS_IMETHODIMP
nsPluggableJVM::StartupJVM(const char *classPath,
nsPluggableJVMStatus *status,
jlong sup)
{
JavaVMInitArgs vm_args;
jint res;
OJI_LOG("nsPluggableJVM::StartupJVM");
*status = nsPluggableJVMStatus_Failed;
if (sup == nsnull) return NS_ERROR_FAILURE;
const char* plugin_home = getenv("WFHOME");
if (plugin_home == NULL) {
OJI_LOG("Env variable JAVA_PLUGIN_HOME not set");
return NS_ERROR_FAILURE;
}
if (NS_FAILED(loadPluginDLL(plugin_home)))
return NS_ERROR_FAILURE;
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_2;
// XXX: add classpath here
if (NS_FAILED(initJVM(&m_ctx, &vm_args)))
return NS_ERROR_FAILURE;
// initialize capability mechanism
JVMP_SecurityCap cap;
JVMP_FORBID_ALL_CAPS(cap);
JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSTEM);
JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSEVENT)
JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_EVENT);
JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_CALL);
jbyte** prins;
jint pnum = 2;
jint* plen;
if (!newPrincipalsFromStrings(&prins, &plen,
pnum, "CAPS", "MOZILLA"))
return JNI_FALSE;
if ((m_jvmp_context->JVMP_EnableCapabilities)
(m_ctx, &cap, pnum, plen, prins) != JNI_TRUE)
{
OJI_LOG("Can\'t enable caps");
return JNI_FALSE;
};
deletePrincipals(prins, plen, pnum);
SetConsoleVisibility(PR_TRUE);
char* ext_dll = PR_GetLibraryName(plugin_home, LIBEXT);
OJI_LOG2("JVMP_RegisterExtension: %s", ext_dll);
res = (m_jvmp_context->JVMP_RegisterExtension)(m_ctx,
ext_dll,
&m_extID,
sup);
PR_Free(ext_dll);
if (res != JNI_TRUE || m_extID == 0) return NS_ERROR_FAILURE;
OJI_LOG("JVMP_RegisterExtension OK");
*status = nsPluggableJVMStatus_Running;
return NS_OK;
}
/* void ShutdownJVM (in PRBool fullShutdown, out nsJVMStatus status); */
NS_IMETHODIMP
nsPluggableJVM::ShutdownJVM(PRBool fullShutdown, nsPluggableJVMStatus *status)
{
if ((m_jvmp_context->JVMP_UnregisterExtension(m_ctx, m_extID) != JNI_TRUE))
return NS_ERROR_FAILURE;
if ((m_jvmp_context->JVMP_StopJVM(m_ctx) != JNI_TRUE))
return NS_ERROR_FAILURE;
m_jvmp_context = NULL;
return NS_OK;
}
nsresult
nsPluggableJVM::loadPluginDLL(const char* plugin_home)
{
char* plugin_dll = PR_GetLibraryName(plugin_home, LIBJVMP);
JVMP_GetPlugin_t fJVMP_GetPlugin;
char errorMsg[1024] = "<unknown; can't get error from NSPR>";
OJI_LOG2("Loading JVMP from %s", plugin_dll);
m_dll = PR_LoadLibrary(plugin_dll);
PR_Free(plugin_dll);
if (!m_dll)
{
if (PR_GetErrorTextLength() < (int) sizeof(errorMsg))
PR_GetErrorText(errorMsg);
OJI_LOG2("Cannot load plugin DLL: %s", errorMsg);
return NS_ERROR_FAILURE;
}
fJVMP_GetPlugin =
(JVMP_GetPlugin_t) PR_FindSymbol(m_dll, "JVMP_GetPlugin");
if (!fJVMP_GetPlugin)
{
if (PR_GetErrorTextLength() < (int) sizeof(errorMsg))
PR_GetErrorText(errorMsg);
OJI_LOG2("Cannot resolve JVMP_GetPlugin: %s", errorMsg);
return NS_ERROR_FAILURE;
}
(*fJVMP_GetPlugin)(&m_jvmp_context);
return NS_OK;
}
nsresult
nsPluggableJVM::initJVM(JVMP_CallingContext* *penv,
JavaVMInitArgs* vm_args)
{
jint res = (m_jvmp_context->JVMP_GetRunningJVM)(penv, vm_args, JNI_TRUE);
if (res == JNI_TRUE)
{
OJI_LOG("OK GOT JVM!!!!");
return NS_OK;
}
else
{
OJI_LOG("BAD - NO JVM!!!!");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsPluggableJVM::CreateJavaPeer(nsIJavaHTMLObject *obj,
const char* cid,
jint *pid)
{
if ((m_jvmp_context->JVMP_CreatePeer)(m_ctx, cid, 0, pid))
return NS_OK;
return NS_ERROR_FAILURE;
}
/* void PostEventToJavaPeer (in jp_jint obj_id, in jp_jint evt_id, in jp_jint evt_data); */
NS_IMETHODIMP
nsPluggableJVM::PostEventToJavaPeer(jint obj_id, jint evt_id,
jlong evt_data)
{
if ((m_jvmp_context->JVMP_PostEvent)(m_ctx, obj_id,
evt_id, evt_data, JVMP_PRIORITY_NORMAL) == JNI_FALSE)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsPluggableJVM::JavaPeerCall(jint obj_id,
jint data1,
jlong data2)
{
if ((m_jvmp_context->JVMP_DirectPeerCall)(m_ctx, obj_id,
data1, data2) == JNI_FALSE)
return NS_ERROR_FAILURE;
return NS_OK;
}
/* void SendEventToJavaPeer (in jp_jint obj_id, in jp_jint evt_id, in jp_jint evt_data); */
NS_IMETHODIMP
nsPluggableJVM::SendEventToJavaPeer(jint obj_id, jint evt_id,
jlong evt_data, jint* result)
{
jint r = (m_jvmp_context->JVMP_SendEvent)(m_ctx, obj_id,
evt_id, evt_data, JVMP_PRIORITY_NORMAL);
if (r == JNI_FALSE)
{
return NS_ERROR_FAILURE;
}
if (result) *result = r;
return NS_OK;
}
/* void DestroyJavaPeer (in jp_jint id); */
NS_IMETHODIMP
nsPluggableJVM::DestroyJavaPeer(jint id)
{
if ((m_jvmp_context->JVMP_DestroyPeer)(m_ctx, id))
return NS_OK;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsPluggableJVM::ExtensionCall(jint arg1, jlong arg2)
{
if (m_extID == 0) return NS_ERROR_FAILURE;
if ((m_jvmp_context->JVMP_DirectExtCall)(m_ctx, m_extID, arg1, arg2))
return NS_OK;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsPluggableJVM::DeleteGlobalRef(jobject jobj)
{
m_ctx->env->DeleteGlobalRef(jobj);
return NS_OK;
}
NS_IMETHODIMP
nsPluggableJVM::DeleteLocalRef(jobject jobj)
{
m_ctx->env->DeleteLocalRef(jobj);
return NS_OK;
}
NS_IMETHODIMP
nsPluggableJVM::GetWFCtx(JVMP_RuntimeContext* *rt_ctx,
JVMP_CallingContext* *c_ctx)
{
if (!m_jvmp_context) return NS_ERROR_FAILURE;
*rt_ctx = m_jvmp_context;
if ((m_jvmp_context->JVMP_GetCallingContext)(c_ctx) != JNI_TRUE)
{
OJI_LOG2("JVMP_GetCallingContext failed: %ld", (*c_ctx)->err);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsPluggableJVM::SetConsoleVisibility(PRBool visibility)
{
//OJI_LOG2("nsPluggableJVM::SetConsoleVisibility: %d", visibility);
jint rv = (m_jvmp_context->JVMP_PostSysEvent)(m_ctx,
JVMP_CMD_CTL_CONSOLE,
(jlong) (visibility ? 1 : 0),
JVMP_PRIORITY_NORMAL);
return (rv == JNI_TRUE ? NS_OK : NS_ERROR_FAILURE);
}
NS_IMETHODIMP
nsPluggableJVM::GetConsoleVisibility(PRBool *pVisibility)
{
// this call uses hacky feature of JVMP_Send*Event():
// returned value can be used to return value from event handler
jint rv = (m_jvmp_context->JVMP_SendSysEvent)(m_ctx,
JVMP_CMD_CTL_CONSOLE,
(jlong)2,
JVMP_PRIORITY_NORMAL);
*pVisibility = (rv == 2 ? PR_TRUE : PR_FALSE);
return NS_OK;
}
NS_IMETHODIMP
nsPluggableJVM::PrintToConsole(const char* msg,
const char* encoding)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsPluggableJVM.h,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef __nsPluggableJVM_h__
#define __nsPluggableJVM_h__
#include "nsIPluggableJVM.h"
#include "nsIBrowserJavaSupport.h"
#include "nsCOMPtr.h"
#include "nspr.h"
// Waterfall interface
#include "jvmp.h"
#define LIBJVMP "jvmp"
#define LIBEXT "wf_moz6"
class nsPluggableJVM : public nsIPluggableJVM {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPLUGGABLEJVM
nsPluggableJVM();
virtual ~nsPluggableJVM();
NS_IMETHOD GetWFCtx(JVMP_RuntimeContext* *rt_ctx,
JVMP_CallingContext* *c_ctx);
NS_IMETHOD DeleteGlobalRef(jobject jobj);
NS_IMETHOD DeleteLocalRef(jobject jobj);
protected:
// pointer to WF plugin context
JVMP_RuntimeContext* m_jvmp_context;
// Waterfall DLL handle
PRLibrary* m_dll;
// this field contains JVMP_CallingContext only for main NS thread
// other threads should use JVMP_GetCallingContext()
JVMP_CallingContext* m_ctx;
// descriptor provided by Waterfall library for proper Mozilla extension
jint m_extID;
// browser Java support field
nsCOMPtr<nsIBrowserJavaSupport> m_support;
// just load Waterfall and set up m_jvmp_context correctly
NS_METHOD loadPluginDLL(const char* plugin_home);
// start up JVM and set up m_ctx correctly - call from main thread
NS_METHOD initJVM(JVMP_CallingContext* *penv,
JavaVMInitArgs* vm_args);
};
#endif /* __nsPluggableJVM_h__ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,271 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsWFSecureEnv.h,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef __nsWFSecureEnv_h
#define __nsWFSecureEnv_h
#include "nsoji2.h"
#include "nsISecureEnv.h"
#include "nsPluggableJVM.h"
#include "wf_moz6_common.h"
class nsWFSecureEnv : public nsISecureEnv
{
public:
NS_DECL_ISUPPORTS
static NS_METHOD Create(nsPluggableJVM* jvm,
const nsIID& aIID,
void* *aInstancePtr);
static NS_METHOD CreateJavaCallInfo(Java_CallInfo* *pCall,
nsISecurityContext* ctx);
static NS_METHOD CleanupJavaCallInfo(Java_CallInfo* pCall,
nsISecurityContext* ctx);
// here follows methods from nsISecureEnv - no IDL and
// cute macroses yet :(
NS_IMETHOD NewObject(/*[in]*/ jclass clazz,
/*[in]*/ jmethodID methodID,
/*[in]*/ jvalue *args,
/*[out]*/ jobject* result,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD CallMethod(/*[in]*/ jni_type ret_type,
/*[in]*/ jobject obj,
/*[in]*/ jmethodID methodID,
/*[in]*/ jvalue *args,
/*[out]*/ jvalue* result,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD CallNonvirtualMethod(/*[in]*/ jni_type ret_type,
/*[in]*/ jobject obj,
/*[in]*/ jclass clazz,
/*[in]*/ jmethodID methodID,
/*[in]*/ jvalue *args,
/*[out]*/ jvalue* result,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD GetField(/*[in]*/ jni_type field_type,
/*[in]*/ jobject obj,
/*[in]*/ jfieldID fieldID,
/*[out]*/ jvalue* result,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD SetField(/*[in]*/ jni_type field_type,
/*[in]*/ jobject obj,
/*[in]*/ jfieldID fieldID,
/*[in]*/ jvalue val,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD CallStaticMethod(/*[in]*/ jni_type ret_type,
/*[in]*/ jclass clazz,
/*[in]*/ jmethodID methodID,
/*[in]*/ jvalue *args,
/*[out]*/ jvalue* result,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD GetStaticField(/*[in]*/ jni_type field_type,
/*[in]*/ jclass clazz,
/*[in]*/ jfieldID fieldID,
/*[out]*/ jvalue* result,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD SetStaticField(/*[in]*/ jni_type field_type,
/*[in]*/ jclass clazz,
/*[in]*/ jfieldID fieldID,
/*[in]*/ jvalue val,
/*[in]*/ nsISecurityContext* ctx = NULL);
NS_IMETHOD GetVersion(/*[out]*/ jint* version);
NS_IMETHOD DefineClass(/*[in]*/ const char* name,
/*[in]*/ jobject loader,
/*[in]*/ const jbyte *buf,
/*[in]*/ jsize len,
/*[out]*/ jclass* clazz);
NS_IMETHOD FindClass(/*[in]*/ const char* name,
/*[out]*/ jclass* clazz);
NS_IMETHOD GetSuperclass(/*[in]*/ jclass sub,
/*[out]*/ jclass* super);
NS_IMETHOD IsAssignableFrom(/*[in]*/ jclass sub,
/*[in]*/ jclass super,
/*[out]*/ jboolean* result);
NS_IMETHOD Throw(/*[in]*/ jthrowable obj,
/*[out]*/ jint* result);
NS_IMETHOD ThrowNew(/*[in]*/ jclass clazz,
/*[in]*/ const char *msg,
/*[out]*/ jint* result);
NS_IMETHOD ExceptionOccurred(/*[out]*/ jthrowable* result);
NS_IMETHOD ExceptionDescribe(void);
NS_IMETHOD ExceptionClear(void);
NS_IMETHOD FatalError(/*[in]*/ const char* msg);
NS_IMETHOD NewGlobalRef(/*[in]*/ jobject lobj,
/*[out]*/ jobject* result);
NS_IMETHOD DeleteGlobalRef(/*[in]*/ jobject gref);
NS_IMETHOD DeleteLocalRef(/*[in]*/ jobject obj);
NS_IMETHOD IsSameObject(/*[in]*/ jobject obj1,
/*[in]*/ jobject obj2,
/*[out]*/ jboolean* result);
NS_IMETHOD AllocObject(/*[in]*/ jclass clazz,
/*[out]*/ jobject* result);
NS_IMETHOD GetObjectClass(/*[in]*/ jobject obj,
/*[out]*/ jclass* result);
NS_IMETHOD IsInstanceOf(/*[in]*/ jobject obj,
/*[in]*/ jclass clazz,
/*[out]*/ jboolean* result);
NS_IMETHOD GetMethodID(/*[in]*/ jclass clazz,
/*[in]*/ const char* name,
/*[in]*/ const char* sig,
/*[out]*/ jmethodID* id);
NS_IMETHOD GetFieldID(/*[in]*/ jclass clazz,
/*[in]*/ const char* name,
/*[in]*/ const char* sig,
/*[out]*/ jfieldID* id);
NS_IMETHOD GetStaticMethodID(/*[in]*/ jclass clazz,
/*[in]*/ const char* name,
/*[in]*/ const char* sig,
/*[out]*/ jmethodID* id);
NS_IMETHOD GetStaticFieldID(/*[in]*/ jclass clazz,
/*[in]*/ const char* name,
/*[in]*/ const char* sig,
/*[out]*/ jfieldID* id);
NS_IMETHOD NewString(/*[in]*/ const jchar* unicode,
/*[in]*/ jsize len,
/*[out]*/ jstring* result);
NS_IMETHOD GetStringLength(/*[in]*/ jstring str,
/*[out]*/ jsize* result);
NS_IMETHOD GetStringChars(/*[in]*/ jstring str,
/*[in]*/ jboolean *isCopy,
/*[out]*/ const jchar** result);
NS_IMETHOD ReleaseStringChars(/*[in]*/ jstring str,
/*[in]*/ const jchar *chars);
NS_IMETHOD NewStringUTF(/*[in]*/ const char *utf,
/*[out]*/ jstring* result);
NS_IMETHOD GetStringUTFLength(/*[in]*/ jstring str,
/*[out]*/ jsize* result);
NS_IMETHOD GetStringUTFChars(/*[in]*/ jstring str,
/*[in]*/ jboolean *isCopy,
/*[out]*/ const char** result);
NS_IMETHOD ReleaseStringUTFChars(/*[in]*/ jstring str,
/*[in]*/ const char *chars);
NS_IMETHOD GetArrayLength(/*[in]*/ jarray array,
/*[out]*/ jsize* result);
NS_IMETHOD GetObjectArrayElement(/*[in]*/ jobjectArray array,
/*[in]*/ jsize index,
/*[out]*/ jobject* result);
NS_IMETHOD SetObjectArrayElement(/*[in]*/ jobjectArray array,
/*[in]*/ jsize index,
/*[in]*/ jobject val);
NS_IMETHOD NewObjectArray(/*[in]*/ jsize len,
/*[in]*/ jclass clazz,
/*[in]*/ jobject init,
/*[out]*/ jobjectArray* result);
NS_IMETHOD NewArray(/*[in]*/ jni_type element_type,
/*[in]*/ jsize len,
/*[out]*/ jarray* result);
NS_IMETHOD GetArrayElements(/*[in]*/ jni_type element_type,
/*[in]*/ jarray array,
/*[in]*/ jboolean *isCopy,
/*[out]*/ void* result);
NS_IMETHOD ReleaseArrayElements(/*[in]*/ jni_type element_type,
/*[in]*/ jarray array,
/*[in]*/ void *elems,
/*[in]*/ jint mode);
NS_IMETHOD GetArrayRegion(/*[in]*/ jni_type element_type,
/*[in]*/ jarray array,
/*[in]*/ jsize start,
/*[in]*/ jsize len,
/*[out]*/ void* buf);
NS_IMETHOD SetArrayRegion(/*[in]*/ jni_type element_type,
/*[in]*/ jarray array,
/*[in]*/ jsize start,
/*[in]*/ jsize len,
/*[in]*/ void* buf);
NS_IMETHOD RegisterNatives(/*[in]*/ jclass clazz,
/*[in]*/ const JNINativeMethod *methods,
/*[in]*/ jint nMethods,
/*[out]*/ jint* result);
NS_IMETHOD UnregisterNatives(/*[in]*/ jclass clazz,
/*[out]*/ jint* result);
NS_IMETHOD MonitorEnter(/*[in]*/ jobject obj,
/*[out]*/ jint* result);
NS_IMETHOD MonitorExit(/*[in]*/ jobject obj,
/*[out]*/ jint* result);
NS_IMETHOD GetJavaVM(/*[in]*/ JavaVM **vm,
/*[out]*/ jint* result);
nsWFSecureEnv(nsPluggableJVM* jvm);
virtual ~nsWFSecureEnv(void);
protected:
nsPluggableJVM* m_jvm;
// as for now all LiveConnect calls comes from the main thread,
// it's correct to use one JNI env and cache it here.
// if LiveConnect will be truly mutlithreaded - it should be rewritten
JNIEnv* m_env;
JVMP_RuntimeContext* m_rtctx;
JVMP_CallingContext* m_ctx;
};
#endif //ifndef __nsWFSecureEnv_h

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

@ -0,0 +1,152 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsWFSecurityContext.cpp,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#include "nsWFSecurityContext.h"
#include "plstr.h"
#include "nsCRT.h"
NS_DEFINE_IID(kISecurityContextIID, NS_ISECURITYCONTEXT_IID);
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////
// from nsISupports and AggregatedQueryInterface:
// Thes macro expands to the aggregated query interface scheme.
NS_IMPL_AGGREGATED(nsWFSecurityContext);
NS_METHOD
nsWFSecurityContext::AggregatedQueryInterface(const nsIID& aIID,
void** aInstancePtr)
{
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = GetInner();
AddRef();
return NS_OK;
}
if (aIID.Equals(kISecurityContextIID)) {
*aInstancePtr = (nsISecurityContext *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsWFSecurityContext::nsWFSecurityContext(nsISupports *aOuter,
nsPluggableJVM* pIJavaVM,
jobject ctx,
const char* url):
m_jvm(pIJavaVM), context(NULL), m_url(NULL), m_olen(0)
{
NS_INIT_AGGREGATED(aOuter);
JNIEnv* env = nsnull;
m_jvm->GetJNIEnv(&env);
if (env) context = env->NewGlobalRef(ctx);
if (url) {
m_url = nsCRT::strdup(url);
char* s = m_url;
int slashes=0;
while(s && *s)
{
if (*s++ == '/') slashes++;
if (slashes == 3) break;
m_olen++;
}
}
//fprintf(stderr, "url=%s\n", url);
}
nsWFSecurityContext::~nsWFSecurityContext()
{
JNIEnv* env = nsnull;
m_jvm->GetJNIEnv(&env);
if (env && context)
env->DeleteGlobalRef(context);
if (m_url) nsCRT::free(m_url);
}
NS_METHOD
nsWFSecurityContext::Create(nsISupports* outer,
nsPluggableJVM* pIJavaVM,
jobject ctx,
const char* url,
const nsIID& aIID,
void* *aInstancePtr)
{
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE;
nsWFSecurityContext* context =
new nsWFSecurityContext(outer, pIJavaVM, ctx, url);
if (context == NULL)
return NS_ERROR_OUT_OF_MEMORY;
context->AddRef();
*aInstancePtr = context->GetInner();
*aInstancePtr = (outer != NULL) ?
(void *)context->GetInner(): (void *)context;
return NS_OK;
}
// XXX: not the best implementation, but this method never got called AFAIK,
// maybe beside LiveConnect with signed scripts, but it's not implemented
// anyway.
NS_IMETHODIMP
nsWFSecurityContext::Implies(const char* target,
const char* action,
PRBool* bActionAllowed)
{
OJI_LOG3("nsWFSecurityContext::Implies: %s %s",target, action);
if (target == NULL || bActionAllowed == NULL)
return NS_ERROR_NULL_POINTER;
*bActionAllowed = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsWFSecurityContext::GetOrigin(char* buf, int len)
{
int total = m_olen > len ? len : m_olen;
nsCRT::memcpy(buf, m_url, total);
buf[total] = '\0';
return NS_OK;
}
NS_IMETHODIMP
nsWFSecurityContext::GetCertificateID(char* buf, int len)
{
//::PL_strncpy(buf, "", len);
buf[0] = 0;
return NS_OK;
}

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

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: nsWFSecurityContext.h,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef nsWFSecurityContext_h___
#define nsWFSecurityContext_h___
#include "nsPluggableJVM.h"
#include "nsISecurityContext.h"
#include "nsAgg.h"
class nsWFSecurityContext : public nsISecurityContext
{
public:
// from nsISupports and AggregatedQueryInterface:
NS_DECL_AGGREGATED
static NS_METHOD Create(nsISupports* outer,
nsPluggableJVM* pIJavaVM,
jobject ctx,
const char* url,
const nsIID& aIID,
void* *aInstancePtr);
NS_IMETHOD Implies(const char* target,
const char* action,
PRBool* bActionAllowed);
NS_IMETHOD GetOrigin(char* buf, int len);
NS_IMETHOD GetCertificateID(char* buf, int len);
nsWFSecurityContext(nsISupports *aOuter,
nsPluggableJVM* pIJavaVM,
jobject ctx,
const char* url);
virtual ~nsWFSecurityContext(void);
protected:
nsPluggableJVM* m_jvm;
jobject context;
char* m_url;
int m_olen;
};
#endif

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

@ -0,0 +1,274 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 The Waterfall Java Plugin Module
*
* The Initial Developer of the Original Code is Sun Microsystems Inc
* Portions created by Sun Microsystems Inc are Copyright (C) 2001
* All Rights Reserved.
*
* $Id: wf_moz6_common.h,v 1.1 2001/05/09 18:51:36 edburns%acm.org Exp $
*
*
* Contributor(s):
*
* Nikolay N. Igotti <inn@sparc.spb.su>
*/
#ifndef __wf_moz6_common_h
#define __wf_moz6_common_h
/** Ideology behind this file:
* To keep generic binary compatibility, and be independent from Mozilla
* build system for Mozilla extension (not very good idea, but currently
* it's more convinient) we need some kind of fixed API/ABI between
* extension and Java service in browser. This file is _only_ (beside
* jvmp.h) common header between Java component and extension. It's written
* in pure C and has no Mozilla dependencies. So JVM service in browser fills
* propers callbacks and the extension, if wishes to perform some call to
* Mozilla uses those callbacks (and maybe even in another direction, but
* it's not recommened - use JVMP_Direct*Call for such purposes).
* Here described structures for
* - common browser configuration callbacks (show status, show document,
* get proxy config, add anything you want)
* - LiveConnect calls and security
* JavaObjectWrapper is wrapper for java-driven objects on browser side,
* usually lifetime coincides with lifetime of web page.
* If underlying native object is dead, proper field is 1.
* SecurityContextWrapper is wrapper for security context is
* LiveConnect calls, lifetime coincide with lifetime
* of LiveConnect call.
* BrowserSupportWrapper is wrapper for global JVM service object,
* exist always until JVM service is loaded, can be
* used for global operations not related to browser
* NB: If any other browser will implement those callbacks and be kind enough
* to follow Mozilla protocol in inline plugin handling, it will have
* Java + applets + LiveConnect for free. For example MSIE code can be written
* in such a manner.
**/
struct SecurityContextWrapper {
void* info;
int (*Implies) (void* handle, const char* target,
const char* action, int *bAllowedAccess);
int (*GetOrigin)(void* handle, char *buffer, int len);
int (*GetCertificateID)(void* handle, char *buffer, int len);
int dead;
};
typedef struct SecurityContextWrapper SecurityContextWrapper;
struct JavaObjectWrapper;
typedef struct JavaObjectWrapper JavaObjectWrapper;
#define WF_APPLETPEER_CID "@sun.com/wf/mozilla/appletpeer;1"
enum JSCallType { // Possible JS call type
JS_Unknown = 0,
JS_GetWindow = 1,
JS_ToString,
JS_Eval,
JS_Call,
JS_GetMember,
JS_SetMember,
JS_RemoveMember,
JS_GetSlot,
JS_SetSlot,
JS_Finalize
};
struct JSObject_CallInfo
{
const char* pszUrl; // URL of the CodeSource object in the Java call
jobjectArray jCertArray; // Certificate array of the CodeSource object
jintArray jCertLengthArray; // Certificate length array of the CodeSource object
int iNumOfCerts; // Number of certificates in the cert and cert length array
jobject jAccessControlContext; // AccessControlContext object that represents the Java callstack
enum JSCallType type; // Type of JSObject call
jthrowable jException; // Java exception object as the result of the call
JavaObjectWrapper* pWrapper; // native-Java glueing object
union {
struct __GetWindow {
void* pPlugin; // Plug-in instance corresponded to the JSObject call
jint iNativeJSObject; // Native JS object as the result of the GetWindow call
} __getWindow;
struct __Finalize {
jint iNativeJSObject; // Native JS object that needs to be finalized
} __finalize;
struct __ToString {
jint iNativeJSObject; // Native JS object that corresponded to the JSObject.toString
jstring jResult; // Result of JSObject.toString
} __toString;
struct __Call {
const jchar* pszMethodName; // Method name
int iMethodNameLen; // Length of method name
jobjectArray jArgs; // Argument for the JSObject.Call
jint iNativeJSObject; // Native JS object corresponded to the JSObject.call
jobject jResult; // Result of JSObject.call
} __call;
struct __Eval {
const jchar* pszEval; // String to be evaluated
int iEvalLen; // Length of the evaluatation string
jint iNativeJSObject; // Native JS object corresponded to the JSObject.eval
jobject jResult; // Result of JSObject.eval
} __eval;
struct __GetMember {
const jchar* pszName; // Member name
int iNameLen; // Length of member name
jint iNativeJSObject; // Native JS object corresponded to the JSObject.getMember
jobject jResult; // Result of JSObject.getMember
} __getMember;
struct __SetMember {
const jchar* pszName; // Member name
int iNameLen; // Length of member name
jint iNativeJSObject; // Native JS object corresponded to the JSObject.setMember
jobject jValue; // Result of JSObject.setMember
} __setMember;
struct __RemoveMember {
const jchar* pszName; // Member name
int iNameLen; // Length of member name
jint iNativeJSObject; // Native JS object corresponded to the JSObject.removeMember
} __removeMember;
struct __GetSlot {
int iIndex; // Slot number
jint iNativeJSObject; // Native JS object corresponded to the JSObject.getSlot
jobject jResult; // Result of JSObject.getSlot
} __getSlot;
struct __SetSlot {
int iIndex; // Slot number
jobject jValue; // Value to set in the slot
jint iNativeJSObject; // Native JS object corresponded to the JSObject.setSlot
} __setSlot;
} data;
};
enum JavaCallType {
Java_Unknown = 0,
Java_WrapJSObject,
Java_CreateObject,
Java_CallMethod,
Java_CallStaticMethod,
Java_CallNonvirtualMethod,
Java_SetField,
Java_SetStaticField,
Java_GetField,
Java_GetStaticField,
Java_UnwrapJObject
};
/* just a copy of enum jni_type from nsISecureEnv, as I have to get
it from somewhere - values are the same, so can convert flawlessly */
enum jvmp_jni_type
{
jvmp_jobject_type = 0,
jvmp_jboolean_type,
jvmp_jbyte_type,
jvmp_jchar_type,
jvmp_jshort_type,
jvmp_jint_type,
jvmp_jlong_type,
jvmp_jfloat_type,
jvmp_jdouble_type,
jvmp_jvoid_type
};
struct Java_CallInfo
{
enum JavaCallType type;
jthrowable jException;
SecurityContextWrapper* security;
union {
struct __WrapJSObject {
jint jsObject;
jint jstid;
jobject jObject ;
} __wrapJSObject;
struct __CreateObject {
jclass clazz;
jmethodID methodID;
jvalue *args;
jobject result;
} __createObject;
struct __CallMethod {
enum jvmp_jni_type type;
jobject obj;
jmethodID methodID;
jvalue *args;
jvalue result;
} __callMethod;
struct __CallStaticMethod {
enum jvmp_jni_type type;
jclass clazz;
jmethodID methodID;
jvalue *args;
jvalue result;
} __callStaticMethod;
struct __CallNonvirtualMethod {
enum jvmp_jni_type type;
jobject obj;
jclass clazz;
jmethodID methodID;
jvalue *args;
jvalue result;
} __callNonvirtualMethod;
struct __GetField {
enum jvmp_jni_type type;
jobject obj;
jfieldID fieldID;
jvalue result;
} __getField;
struct __GetStaticField {
enum jvmp_jni_type type;
jclass clazz;
jfieldID fieldID;
jvalue result;
} __getStaticField;
struct __SetField {
enum jvmp_jni_type type;
jobject obj;
jfieldID fieldID;
jvalue value;
} __setField;
struct __SetStaticField {
enum jvmp_jni_type type;
jclass clazz;
jfieldID fieldID;
jvalue value;
} __setStaticField;
struct __UnwrapJObject {
jobject jObject;
jint jstid;
jint jsObject ;
} __unwrapJObject;
} data;
};
struct JavaObjectWrapper
{
void* info;
void* plugin;
int (*GetParameters)(void* handle, char ***keys,
char ***values, int *count);
int (*ShowDocument)(void* handle, char* url, char* target);
int (*ShowStatus)(void* handle, char* status);
int (*GetJSThread)(void* handle, jint* jstid);
int dead;
};
struct BrowserSupportWrapper
{
void* info;
int (*GetProxyForURL)(void* handle, char* url, char** proxy);
int (*JSCall)(void* handle, jint jstid,
struct JSObject_CallInfo** jscall);
};
typedef struct BrowserSupportWrapper BrowserSupportWrapper;
#endif