mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
fix=Denis Sharypov <sdv@sparc.spb.su> r=akhil.arora@sun.com
19304 convert java dom api to an xpcom module 19305 synchronize with interface changes in nsIDocumentLoaderObserver
This commit is contained in:
parent
252e9c7159
commit
95cb81ad53
12
java/dom/DocumentImpl.java.patch
Normal file
12
java/dom/DocumentImpl.java.patch
Normal file
@ -0,0 +1,12 @@
|
||||
Index: DocumentImpl.java
|
||||
===================================================================
|
||||
RCS file: /cvsroot/mozilla/java/dom/jni/DocumentImpl.java,v
|
||||
retrieving revision 1.4
|
||||
diff -r1.4 DocumentImpl.java
|
||||
40a41,42
|
||||
> import org.mozilla.dom.tests.TestDocLoadListener;
|
||||
>
|
||||
64d65
|
||||
<
|
||||
71a73
|
||||
> DOMAccessorImpl.getInstance().addDocumentLoadListener(new TestDocLoadListener());
|
@ -31,7 +31,7 @@ IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
nsJavaDOMImpl.cpp \
|
||||
nsJavaDOMFactory.cpp
|
||||
nsJavaDOMModule.cpp
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
@ -46,7 +46,6 @@ DSO_LDOPTS += \
|
||||
-ljvm -lhpi
|
||||
|
||||
EXPORTS = \
|
||||
nsJavaDOMCID.h \
|
||||
nsIJavaDOM.h
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
@ -31,7 +31,7 @@ IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
nsJavaDOMImpl.cpp \
|
||||
nsJavaDOMFactory.cpp
|
||||
nsJavaDOMModule.cpp
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
@ -46,7 +46,6 @@ DSO_LDOPTS += \
|
||||
-ljvm -lhpi -lsunwjit
|
||||
|
||||
EXPORTS = \
|
||||
nsJavaDOMCID.h \
|
||||
nsIJavaDOM.h
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
@ -31,7 +31,7 @@ IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
nsJavaDOMImpl.cpp \
|
||||
nsJavaDOMFactory.cpp
|
||||
nsJavaDOMModule.cpp
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
@ -47,7 +47,6 @@ DSO_LDOPTS += \
|
||||
-ljvm -lhpi -lsunwjit
|
||||
|
||||
EXPORTS = \
|
||||
nsJavaDOMCID.h \
|
||||
nsIJavaDOM.h
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
@ -5,17 +5,18 @@ A Java component obtains a org.w3c.dom.Document by registering for
|
||||
Document load notifications. The Document is passed in along with the
|
||||
notifications. The preferred way for a Java component to register for
|
||||
Document load notifications is to register via the DOMAccessor
|
||||
class. However, currently this does not work and one has to apply a
|
||||
patch to webshell/src/nsWebShell.cpp. See the section on Building for
|
||||
instructions on how to apply the patch.
|
||||
class. However until OJI is used to obtain JNIEnv one has to apply
|
||||
two patches
|
||||
|
||||
The nsJavaDOM component by means of this patch registers itself as a
|
||||
DocumentLoadObserver with the DocumentLoader service. It then loads a
|
||||
class called DOMFactory, asks it for a Java DocumentLoadListener and
|
||||
starts sending all document load notifications that it recieves to the
|
||||
Java listener.
|
||||
webshell/src/nsWebShell.cpp.patch
|
||||
java/dom/jni/DocumentImpl.java.patch
|
||||
|
||||
So the first place to start hacking would be DOMFactory.java.
|
||||
The first one inits nsJavaDOM component and starts jvm. The second one
|
||||
registers a document load listener via DOMAccessor.
|
||||
Note:
|
||||
any class that implements the DocumentLoadListener interface may
|
||||
stand for TestDocLoadListener.
|
||||
See the section on Building for instructions on how to apply the patches.
|
||||
|
||||
|
||||
Makefiles
|
||||
@ -43,7 +44,10 @@ apply the patch to nsWebShell.cpp by executing
|
||||
`patch nsWebShell.cpp <nsWebShell.cpp.patch`
|
||||
|
||||
Edit Makefile.in to add -DJAVA_DOM to the list of defines. Then do a
|
||||
g/make in this directory.
|
||||
gmake in this directory.
|
||||
|
||||
Similarly apply the DocumetnImpl.java patch. Then recompile the
|
||||
DocumentImpl class. No changes in makefiles needed.
|
||||
|
||||
Currently, you will have to make the Java class files yourself, which
|
||||
is pretty straight-forward. Just do a javac -d
|
||||
@ -100,14 +104,6 @@ and from Java. The two should be identical. The code to write these
|
||||
files is, essentially, my regression test. Feel free to add to it.
|
||||
|
||||
|
||||
JVM Crash on Exit
|
||||
-----------------
|
||||
|
||||
The JVM dies when apprunner is exiting. Don't know why. WIll need to
|
||||
build a debug version of the JDK to investigate. This will be a
|
||||
non-issue once we start to use OJI to get to the JVM.
|
||||
|
||||
|
||||
OJI
|
||||
---
|
||||
|
||||
@ -118,8 +114,8 @@ OJI-compatible JVM is available, we will move over to using it.
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
Currently tested on Solaris 7 only with Java 2 SDK 1.2.1. egcs-2.91.66
|
||||
and Sun Workshop 4.2 have been know to compile this code
|
||||
Currently tested on Solaris 7 only with Java 2 SDK 1.2.1. egcs-2.91.66,
|
||||
Sun Workshop C++ 4.2 and 5.0 have been know to compile this code
|
||||
fine. gcc-2.8.1 does *not* work. I have not used anything
|
||||
Java2-specific, and it works with JDK1.1.x too (I have been using JDK
|
||||
1.1.6 too).
|
||||
|
@ -22,8 +22,14 @@
|
||||
package org.mozilla.dom;
|
||||
|
||||
public interface DOMAccessor {
|
||||
|
||||
public DOMAccessor getInstance();
|
||||
public void addDocumentLoadListener(DocumentLoadListener listener);
|
||||
public void removeDocumentLoadListener(DocumentLoadListener listener);
|
||||
|
||||
/**
|
||||
* The getInstance method is available, it is not declared because
|
||||
* it is a static method and the Java Language Spec does not allow
|
||||
* us to declare a static method in an interface.
|
||||
*
|
||||
* public static synchronized DOMAccessor getInstance();
|
||||
*/
|
||||
}
|
||||
|
@ -28,13 +28,13 @@ import org.w3c.dom.Document;
|
||||
|
||||
public class DOMAccessorImpl implements DOMAccessor, DocumentLoadListener {
|
||||
|
||||
private DOMAccessor instance = null;
|
||||
private static DOMAccessor instance = null;
|
||||
private Vector documentLoadListeners = new Vector();
|
||||
|
||||
public static native void register();
|
||||
public static native void unregister();
|
||||
|
||||
public synchronized DOMAccessor getInstance() {
|
||||
public static synchronized DOMAccessor getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new DOMAccessorImpl();
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ public class DocumentImpl extends NodeImpl implements Document, DocumentEvent {
|
||||
|
||||
private static native void initialize();
|
||||
|
||||
|
||||
public Event createEvent(String type) throws DOMException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -87,5 +86,5 @@ public class DocumentImpl extends NodeImpl implements Document, DocumentEvent {
|
||||
|
||||
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,13 @@
|
||||
#include "prlog.h"
|
||||
#include "javaDOMGlobals.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIJavaDOM.h"
|
||||
#include "nsJavaDOMCID.h"
|
||||
|
||||
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
||||
|
||||
static NS_DEFINE_IID(kJavaDOMFactoryCID, NS_JAVADOMFACTORY_CID);
|
||||
static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID);
|
||||
static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessorImpl
|
||||
@ -24,12 +22,10 @@ JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_register
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG,
|
||||
("DOMAccessor::register: registering %x\n", jthis));
|
||||
|
||||
nsIDocumentLoader* docLoaderService = nsnull;
|
||||
nsISupports* javaDOM = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv);
|
||||
NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &rv);
|
||||
|
||||
nsresult rv = nsServiceManager::GetService(kJavaDOMFactoryCID,
|
||||
kIJavaDOMIID,
|
||||
(nsISupports**) &javaDOM);
|
||||
if (NS_FAILED(rv) || !javaDOM) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::register: GetService(JavaDOM) failed: %x\n",
|
||||
@ -56,12 +52,10 @@ JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessorImpl_unregister
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG,
|
||||
("DOMAccessor::unregister: unregistering %x\n", jthis));
|
||||
|
||||
nsIDocumentLoader* docLoaderService = nsnull;
|
||||
nsISupports* javaDOM = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsresult rv = nsServiceManager::GetService(kJavaDOMFactoryCID,
|
||||
kIJavaDOMIID,
|
||||
(nsISupports**) &javaDOM);
|
||||
NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv);
|
||||
NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &rv);
|
||||
if (NS_FAILED(rv) || !javaDOM) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::unregister: GetService(JavaDOM) failed %x\n",
|
||||
|
@ -28,17 +28,16 @@ IS_COMPONENT=1
|
||||
LIBRARY_NAME=libjavadom
|
||||
|
||||
CPPSRCS= \
|
||||
nsJavaDOMFactory.cpp \
|
||||
nsJavaDOMImpl.cpp \
|
||||
nsJavaDOMModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsJavaDOMFactory.obj \
|
||||
.\$(OBJDIR)\nsJavaDOMImpl.obj \
|
||||
.\$(OBJDIR)\nsJavaDOMModule.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsJavaDOMCID.h \
|
||||
nsIJavaDOM.h
|
||||
|
||||
LINCS= \
|
||||
|
@ -34,6 +34,9 @@ class nsIURI;
|
||||
#define NS_IJAVADOM_IID \
|
||||
{0x9cc0ca50, 0x0e31, 0x11d3, \
|
||||
{ 0x8a, 0x61, 0x00, 0x04, 0xac, 0x56, 0xc4, 0xa5 }}
|
||||
#define NS_JAVADOM_CID \
|
||||
{0xd6b2e820, 0x9113, 0x11d3, \
|
||||
{ 0x9c, 0x11, 0x0, 0x10, 0x5a , 0xe3, 0x80 , 0x1e }}
|
||||
|
||||
class nsIJavaDOM : public nsIDocumentLoaderObserver {
|
||||
public:
|
||||
@ -45,58 +48,33 @@ class nsIJavaDOM : public nsIDocumentLoaderObserver {
|
||||
const char* aCommand) = 0;
|
||||
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus,
|
||||
#endif
|
||||
nsIDocumentLoaderObserver* aObserver) = 0;
|
||||
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
const char* aContentType,
|
||||
#endif
|
||||
nsIContentViewer* aViewer) = 0;
|
||||
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax) = 0;
|
||||
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
nsString& aMsg) = 0;
|
||||
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus) = 0;
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus) = 0;
|
||||
#endif
|
||||
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
const char *aContentType,
|
||||
const char *aCommand) = 0;
|
||||
};
|
||||
extern nsresult
|
||||
NS_NewJavaDOM(nsIJavaDOM** aJavaDOM);
|
||||
|
||||
#endif /* __nsIJavaDOM_h__ */
|
||||
|
@ -22,12 +22,12 @@
|
||||
#include "prenv.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIContentViewerContainer.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsJavaDOMImpl.h"
|
||||
|
||||
#if defined(DEBUG)
|
||||
@ -81,17 +81,16 @@ NS_IMETHODIMP nsJavaDOMImpl::QueryInterface(REFNSIID aIID, void** aInstance)
|
||||
JavaVM* nsJavaDOMImpl::jvm = NULL;
|
||||
JNIEnv* nsJavaDOMImpl::env = NULL;
|
||||
|
||||
jclass nsJavaDOMImpl::factoryClass = NULL;
|
||||
jclass nsJavaDOMImpl::domAccessorClass = NULL;
|
||||
jclass nsJavaDOMImpl::documentClass = NULL;
|
||||
jclass nsJavaDOMImpl::listenerClass = NULL;
|
||||
jclass nsJavaDOMImpl::gcClass = NULL;
|
||||
|
||||
jobject nsJavaDOMImpl::factory = NULL;
|
||||
jobject nsJavaDOMImpl::docListener = NULL;
|
||||
|
||||
jfieldID nsJavaDOMImpl::documentPtrFID = NULL;
|
||||
|
||||
jmethodID nsJavaDOMImpl::getListenerMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::getInstanceMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::startURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::progressURLLoadMID = NULL;
|
||||
@ -149,24 +148,19 @@ nsJavaDOMImpl::nsJavaDOMImpl()
|
||||
"()V");
|
||||
if (!gcMID) return;
|
||||
|
||||
factoryClass = env->FindClass("org/mozilla/dom/DOMFactory");
|
||||
if (!factoryClass) return;
|
||||
factoryClass = (jclass) env->NewGlobalRef(factoryClass);
|
||||
if (!factoryClass) return;
|
||||
domAccessorClass = env->FindClass("org/mozilla/dom/DOMAccessorImpl");
|
||||
if (!domAccessorClass) return;
|
||||
domAccessorClass = (jclass) env->NewGlobalRef(domAccessorClass);
|
||||
if (!domAccessorClass) return;
|
||||
|
||||
factory = env->AllocObject(factoryClass);
|
||||
if (!factory) return;
|
||||
factory = (jclass) env->NewGlobalRef(factory);
|
||||
if (!factory) return;
|
||||
|
||||
getListenerMID =
|
||||
env->GetMethodID(factoryClass,
|
||||
"getDocumentLoadListener",
|
||||
"()Lorg/mozilla/dom/DocumentLoadListener;");
|
||||
if (!getListenerMID) return;
|
||||
getInstanceMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"getInstance",
|
||||
"()Lorg/mozilla/dom/DOMAccessor;");
|
||||
if (!getInstanceMID) return;
|
||||
|
||||
docListener =
|
||||
env->CallObjectMethod(factory, getListenerMID);
|
||||
env->CallStaticObjectMethod(domAccessorClass, getInstanceMID);
|
||||
if (!docListener) return;
|
||||
docListener = (jclass) env->NewGlobalRef(docListener);
|
||||
if (!docListener) return;
|
||||
@ -244,13 +238,13 @@ PRBool nsJavaDOMImpl::Cleanup()
|
||||
|
||||
nsIDOMDocument* nsJavaDOMImpl::GetDocument(nsIDocumentLoader* loader)
|
||||
{
|
||||
nsIContentViewerContainer* container = nsnull;
|
||||
nsIWebShell* container = nsnull;
|
||||
nsIContentViewer* contentv = nsnull;
|
||||
nsIDocumentViewer* docv = nsnull;
|
||||
nsIDocument* document = nsnull;
|
||||
nsIDOMDocument* domDoc = nsnull;
|
||||
|
||||
nsresult rv = loader->GetContainer(&container);
|
||||
nsresult rv = loader->GetContainer((nsISupports**)&container);
|
||||
if (NS_SUCCEEDED(rv) && container)
|
||||
rv = container->GetContentViewer(&contentv);
|
||||
|
||||
@ -313,24 +307,14 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStartDocumentLoad(nsIDocumentLoader* loader,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus,
|
||||
#endif
|
||||
nsIDocumentLoaderObserver* aObserver)
|
||||
{
|
||||
char* urlSpec = (char*) "";
|
||||
#ifdef NECKO
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
url->GetSpec(&urlSpec);
|
||||
#else
|
||||
if (aURL)
|
||||
aURL->GetSpec(&urlSpec);
|
||||
#endif
|
||||
jstring jURL = env->NewStringUTF(urlSpec);
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
@ -350,34 +334,19 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
const char* aContentType,
|
||||
#endif
|
||||
nsIContentViewer* aViewer)
|
||||
{
|
||||
char* urlSpec = (char*) "";
|
||||
#ifdef NECKO
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
url->GetSpec(&urlSpec);
|
||||
#else
|
||||
if (aURL)
|
||||
aURL->GetSpec(&urlSpec);
|
||||
#endif
|
||||
jstring jURL = env->NewStringUTF(urlSpec);
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
char* contentType = (char*) "";
|
||||
#ifdef NECKO
|
||||
if (channel)
|
||||
channel->GetContentType(&contentType);
|
||||
#else
|
||||
if (aContentType)
|
||||
contentType = aContentType;
|
||||
#endif
|
||||
jstring jContentType = env->NewStringUTF(contentType);
|
||||
if (!jContentType) return NS_ERROR_FAILURE;
|
||||
|
||||
@ -397,23 +366,14 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax)
|
||||
{
|
||||
char* urlSpec = (char*) "";
|
||||
#ifdef NECKO
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
url->GetSpec(&urlSpec);
|
||||
#else
|
||||
if (aURL)
|
||||
aURL->GetSpec(&urlSpec);
|
||||
#endif
|
||||
jstring jURL = env->NewStringUTF(urlSpec);
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
@ -434,22 +394,13 @@ NS_IMETHODIMP nsJavaDOMImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
nsString& aMsg)
|
||||
{
|
||||
char* urlSpec = (char*) "";
|
||||
#ifdef NECKO
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
url->GetSpec(&urlSpec);
|
||||
#else
|
||||
if (aURL)
|
||||
aURL->GetSpec(&urlSpec);
|
||||
#endif
|
||||
jstring jURL = env->NewStringUTF(urlSpec);
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
@ -473,23 +424,13 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus)
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus)
|
||||
#endif
|
||||
{
|
||||
char* urlSpec = (char*) "";
|
||||
#ifdef NECKO
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
url->GetSpec(&urlSpec);
|
||||
#else
|
||||
if (aURL)
|
||||
aURL->GetSpec(&urlSpec);
|
||||
#endif
|
||||
jstring jURL = env->NewStringUTF(urlSpec);
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
@ -513,11 +454,7 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
const char *aContentType,
|
||||
const char *aCommand)
|
||||
{
|
||||
@ -672,3 +609,17 @@ static const char* describe_type(int type)
|
||||
return "ERROR";
|
||||
}
|
||||
#endif
|
||||
|
||||
nsresult NS_NewJavaDOM(nsIJavaDOM** aJavaDOM)
|
||||
{
|
||||
if (! aJavaDOM)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aJavaDOM = new nsJavaDOMImpl();
|
||||
if (! *aJavaDOM)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aJavaDOM);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -21,56 +21,29 @@ class nsJavaDOMImpl : public nsIJavaDOM {
|
||||
const char* aCommand);
|
||||
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus,
|
||||
#endif
|
||||
nsIDocumentLoaderObserver* aObserver);
|
||||
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
const char* aContentType,
|
||||
#endif
|
||||
nsIContentViewer* aViewer);
|
||||
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax);
|
||||
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
nsString& aMsg);
|
||||
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus);
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus);
|
||||
#endif
|
||||
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
const char *aContentType,
|
||||
const char *aCommand);
|
||||
|
||||
@ -78,17 +51,16 @@ class nsJavaDOMImpl : public nsIJavaDOM {
|
||||
static JavaVM* jvm;
|
||||
static JNIEnv* env;
|
||||
|
||||
static jclass factoryClass;
|
||||
static jclass domAccessorClass;
|
||||
static jclass documentClass;
|
||||
static jclass listenerClass;
|
||||
static jclass gcClass;
|
||||
|
||||
static jobject factory;
|
||||
static jobject docListener;
|
||||
|
||||
static jfieldID documentPtrFID;
|
||||
|
||||
static jmethodID getListenerMID;
|
||||
static jmethodID getInstanceMID;
|
||||
static jmethodID startURLLoadMID;
|
||||
static jmethodID endURLLoadMID;
|
||||
static jmethodID progressURLLoadMID;
|
||||
|
@ -1,38 +1,28 @@
|
||||
Index: nsWebShell.cpp
|
||||
===================================================================
|
||||
RCS file: /cvsroot/mozilla/webshell/src/nsWebShell.cpp,v
|
||||
retrieving revision 1.260
|
||||
diff -r1.260 nsWebShell.cpp
|
||||
70a71,75
|
||||
retrieving revision 1.308
|
||||
diff -r1.308 nsWebShell.cpp
|
||||
70a71,74
|
||||
> #ifdef JAVA_DOM
|
||||
> #include "nsIJavaDOM.h"
|
||||
> #include "nsJavaDOMCID.h"
|
||||
> #endif // JAVA_DOM
|
||||
>
|
||||
554a560,564
|
||||
554a559,563
|
||||
> #ifdef JAVA_DOM
|
||||
> static NS_DEFINE_IID(kJavaDOMFactoryCID, NS_JAVADOMFACTORY_CID);
|
||||
> static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
|
||||
> static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID);
|
||||
> #endif // JAVA_DOM
|
||||
>
|
||||
566a577
|
||||
566a576
|
||||
>
|
||||
999a1011,1028
|
||||
958a969,977
|
||||
> #ifdef JAVA_DOM
|
||||
> nsISupports* javaDOM = nsnull;
|
||||
> nsresult jrv = nsServiceManager::GetService(kJavaDOMFactoryCID,
|
||||
> kIJavaDOMIID,
|
||||
> (nsISupports**) &javaDOM);
|
||||
> if (NS_FAILED(jrv) || !javaDOM) {
|
||||
> fprintf(stderr,
|
||||
> "nsWebShell::Init: GetService of JavaDOM failed (error %x)\n",
|
||||
> jrv);
|
||||
> } else {
|
||||
> jrv = docLoaderService->AddObserver((nsIDocumentLoaderObserver*)javaDOM);
|
||||
> if (NS_FAILED(jrv)) {
|
||||
> fprintf(stderr,
|
||||
> "nsWebShell::Init: AddObserver of JavaDOM failed (error %x)\n",
|
||||
> jrv);
|
||||
> }
|
||||
> }
|
||||
> nsresult jrv = NS_OK;
|
||||
> NS_WITH_SERVICE(nsISupports, javaDOM, kJavaDOMCID, &jrv);
|
||||
> if (NS_FAILED(jrv) || !javaDOM) {
|
||||
> fprintf(stderr,
|
||||
> "nsWebShell::Init: GetService of JavaDOM failed (error %x)\n",
|
||||
> jrv);
|
||||
> }
|
||||
> #endif // JAVA_DOM
|
||||
|
41
java/dom/tests/src/TestDOMAccessorApplet.java
Normal file
41
java/dom/tests/src/TestDOMAccessorApplet.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
The contents of this file are subject to the Mozilla Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
The Initial Developer of the Original Code is Sun Microsystems,
|
||||
Inc. Portions created by Sun are
|
||||
Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.tests;
|
||||
|
||||
import java.applet.Applet;
|
||||
import org.mozilla.dom.DOMAccessor;
|
||||
import org.mozilla.dom.DOMAccessorImpl;
|
||||
import org.mozilla.dom.tests.TestDocLoadListener;
|
||||
|
||||
public class TestDOMAccessorApplet extends java.applet.Applet
|
||||
{
|
||||
private DOMAccessor accessor;
|
||||
|
||||
public void init()
|
||||
{
|
||||
accessor = DOMAccessorImpl.getInstance();
|
||||
accessor.addDocumentLoadListener(new TestDocLoadListener());
|
||||
System.out.println("inited......");
|
||||
System.out.println("accsessor: " + accessor);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
Contributor(s):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom;
|
||||
package org.mozilla.dom.tests;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
@ -33,9 +33,11 @@ import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class DOMFactory implements DocumentLoadListener {
|
||||
import org.mozilla.dom.DocumentLoadListener;
|
||||
|
||||
private static final boolean debug = false;
|
||||
public class TestDocLoadListener implements DocumentLoadListener {
|
||||
|
||||
private static final boolean debug = true;
|
||||
|
||||
public DocumentLoadListener getDocumentLoadListener() {
|
||||
return this;
|
||||
@ -54,11 +56,8 @@ public class DOMFactory implements DocumentLoadListener {
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
|
||||
if (url.endsWith(".xul") ||
|
||||
url.endsWith(".js") ||
|
||||
url.endsWith(".css") ||
|
||||
url.startsWith("file:")) return;
|
||||
|
||||
if (!(url.endsWith(".xml") || url.endsWith(".html"))) return;
|
||||
|
||||
if (doc == null) return;
|
||||
Element element = doc.getDocumentElement();
|
||||
if (element == null) return;
|
11
java/dom/tests/src/testa.html
Normal file
11
java/dom/tests/src/testa.html
Normal file
@ -0,0 +1,11 @@
|
||||
<html>
|
||||
<body name="test_dom_accessor">
|
||||
This should run DOMAccessor test.
|
||||
<applet code="TestDOMAccessorApplet.class"
|
||||
width=0
|
||||
height=0
|
||||
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason.">
|
||||
Your browser is completely ignoring the <APPLET> tag!
|
||||
</applet>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user