r=ashuk
a=edburns

This fix makes it so bookmarks work with the tip of the branch as of 11/01/00.

This fix removes the necessity to modify xpcom/base/nsDebug.cpp to
remove the thread safety assertions.

This fix primarily does two things:

1. Make nsActionEvents for all bookmarks/rdf actions

2. Remove the synchronized(this.browserControlCanvas.getTreeLock()) call
around nativeProcessEvents() in NativeEventThread.run().

Files in this fix:

M classes_spec/org/mozilla/webclient/test/EMWindow.java
M classes_spec/org/mozilla/webclient/wrapper_native/BookmarkEntryImpl.java
M classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java
M classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java
M classes_spec/org/mozilla/webclient/wrapper_native/RDFEnumeration.java
M classes_spec/org/mozilla/webclient/wrapper_native/RDFTreeNode.java
M src_moz/BookmarksImpl.cpp
M src_moz/RDFEnumeration.cpp
M src_moz/RDFTreeNode.cpp
M src_moz/nsActions.cpp
M src_moz/nsActions.h
M src_moz/motif/NativeLoaderStub.cpp
This commit is contained in:
edburns%acm.org 2000-11-03 03:16:55 +00:00
Родитель 1292cec99e
Коммит 4808ba00e2
12 изменённых файлов: 1128 добавлений и 513 удалений

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

@ -54,7 +54,7 @@ import org.w3c.dom.Document;
* This is a test application for using the BrowserControl.
*
* @version $Id: EMWindow.java,v 1.23 2000-11-03 01:25:31 ashuk%eng.sun.com Exp $
* @version $Id: EMWindow.java,v 1.24 2000-11-03 03:16:46 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlFactory
@ -171,8 +171,8 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
stopButton.setEnabled(false);
refreshButton = makeItem(buttonsPanel, "Refresh", 3, 0, 1, 1, 0.0, 0.0);
refreshButton.setEnabled(false);
// makeItem(buttonsPanel, "Bookmarks", 4, 0, 1, 1, 0.0, 0.0);
// makeItem(buttonsPanel, "DOMViewer", 5, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "Bookmarks", 4, 0, 1, 1, 0.0, 0.0);
// makeItem(buttonsPanel, "DOMViewer", 5, 0, 1, 1, 0.0, 0.0);
// Create the control panel
controlPanel = new Panel();
@ -260,7 +260,6 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
eventRegistration.addDocumentLoadListener(this);
eventRegistration.addMouseListener(this);
/*********
// PENDING(edburns): test code, replace with production code
bookmarks =
(Bookmarks)
@ -268,6 +267,8 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
System.out.println("debug: edburns: got Bookmarks instance");
bookmarksTree = bookmarks.getBookmarks();
/*********
TreeNode bookmarksRoot = (TreeNode) bookmarksTree.getRoot();
System.out.println("debug: edburns: testing the Enumeration");

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

@ -59,9 +59,10 @@ Properties properties = null;
// Constructors and Initializers
//
protected BookmarkEntryImpl(int nativeNode, RDFTreeNode yourParent)
protected BookmarkEntryImpl(int nativeWebShell, int nativeNode,
RDFTreeNode yourParent)
{
super(nativeNode, yourParent);
super(nativeWebShell, nativeNode, yourParent);
}
//
@ -76,10 +77,10 @@ protected BookmarkEntryImpl(int nativeNode, RDFTreeNode yourParent)
// Abstract Method Implementations
//
protected RDFTreeNode newRDFTreeNode(int nativeNode,
protected RDFTreeNode newRDFTreeNode(int nativeWebShell, int nativeNode,
RDFTreeNode yourParent)
{
return new BookmarkEntryImpl(nativeNode, yourParent);
return new BookmarkEntryImpl(nativeWebShell, nativeNode, yourParent);
}
//
@ -123,7 +124,7 @@ public Properties getProperties()
public boolean isFolder()
{
return nativeIsContainer(getNativeRDFNode());
return nativeIsContainer(nativeWebShell, getNativeRDFNode());
}
// ----VERTIGO_TEST_START
@ -138,7 +139,7 @@ public static void main(String [] args)
Log.setApplicationName("BookmarkEntryImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BookmarkEntryImpl.java,v 1.2 2000-08-04 21:46:10 edburns%acm.org Exp $");
Log.setApplicationVersionDate("$Id: BookmarkEntryImpl.java,v 1.3 2000-11-03 03:16:48 edburns%acm.org Exp $");
}

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

@ -31,7 +31,6 @@ import org.mozilla.util.ParameterCheck;
import org.mozilla.webclient.BrowserControl;
import org.mozilla.webclient.Bookmarks;
import org.mozilla.webclient.BookmarkEntry;
import org.mozilla.webclient.WindowControl;
import org.mozilla.webclient.WrapperFactory;
import javax.swing.tree.TreeModel;
@ -152,7 +151,8 @@ public TreeModel getBookmarks() throws IllegalStateException
throw new IllegalStateException("BookmarksImpl.getBookmarks(): Can't get bookmarks from native browser.");
}
// if we can't create a root, or we can't create a tree
if ((null == (root = new BookmarkEntryImpl(nativeBookmarks, null))) ||
if ((null == (root = new BookmarkEntryImpl(nativeWebShell,
nativeBookmarks, null))) ||
(null == (bookmarksTree = new DefaultTreeModel(root)))) {
throw new IllegalStateException("BookmarksImpl.getBookmarks(): Can't create RDFTreeModel.");
}
@ -177,8 +177,9 @@ public BookmarkEntry newBookmarkEntry(String url)
int newNode;
System.out.println("debug: edburns: BookmarksImpl.newBookmarkEntry: url:" + url);
if (-1 != (newNode = nativeNewRDFNode(url, false))) {
result = new BookmarkEntryImpl(newNode, null);
if (-1 != (newNode = nativeNewRDFNode(nativeWebShell, url, false))) {
result = new BookmarkEntryImpl(nativeWebShell,
newNode, null);
// use put instead of setProperty for jdk1.1.x compatibility.
result.getProperties().put(BookmarkEntry.URL, url);
}
@ -194,8 +195,8 @@ public BookmarkEntry newBookmarkFolder(String name)
int newNode;
System.out.println("debug: edburns: BookmarksImpl.newBookmarkFolder: name:" + name);
if (-1 != (newNode = nativeNewRDFNode(name, true))) {
result = new BookmarkEntryImpl(newNode, null);
if (-1 != (newNode = nativeNewRDFNode(nativeWebShell, name, true))) {
result = new BookmarkEntryImpl(nativeWebShell, newNode, null);
result.getProperties().put(BookmarkEntry.NAME, name);
}
@ -214,7 +215,8 @@ private native int nativeGetBookmarks(int webShellPtr);
*/
private native int nativeNewRDFNode(String url, boolean isFolder);
private native int nativeNewRDFNode(int webShellPtr, String url,
boolean isFolder);
// ----VERTIGO_TEST_START
@ -228,7 +230,7 @@ public static void main(String [] args)
Log.setApplicationName("BookmarksImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BookmarksImpl.java,v 1.6 2000-09-19 00:18:14 edburns%acm.org Exp $");
Log.setApplicationVersionDate("$Id: BookmarksImpl.java,v 1.7 2000-11-03 03:16:49 edburns%acm.org Exp $");
try {
org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]);

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

@ -222,9 +222,7 @@ public void run()
return;
}
synchronized (this.browserControlCanvas.getTreeLock()) {
nativeProcessEvents(nativeWebShell);
}
nativeProcessEvents(nativeWebShell);
if (null != listenersToAdd && !listenersToAdd.isEmpty()) {
tempEnum = listenersToAdd.elements();

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

@ -66,12 +66,24 @@ private int nativeEnum = -1;
private int nativeContainer = -1;
/**
* a handle to the actual mozilla webShell, owned, allocated, and
* released by WindowControl
*/
public int nativeWebShell = -1;
//
// Constructors and Initializers
//
public RDFEnumeration(RDFTreeNode enumParent)
public RDFEnumeration(int yourNativeWebShell, RDFTreeNode enumParent)
{
nativeWebShell = yourNativeWebShell;
parent = enumParent;
nativeRDFNode = parent.getNativeRDFNode();
}
@ -90,7 +102,7 @@ public RDFEnumeration(RDFTreeNode enumParent)
protected void finalize() throws Throwable
{
nativeFinalize();
nativeFinalize(nativeWebShell);
super.finalize();
}
@ -101,8 +113,7 @@ protected void finalize() throws Throwable
public boolean hasMoreElements()
{
Assert.assert(-1 != nativeRDFNode);
return nativeHasMoreElements(nativeRDFNode);
return nativeHasMoreElements(nativeWebShell, nativeRDFNode);
}
public Object nextElement()
@ -111,8 +122,10 @@ public Object nextElement()
Object result = null;
int nextNativeRDFNode;
if (-1 != (nextNativeRDFNode = nativeNextElement(nativeRDFNode))) {
result = parent.newRDFTreeNode(nextNativeRDFNode, parent);
if (-1 != (nextNativeRDFNode = nativeNextElement(nativeWebShell,
nativeRDFNode))) {
result = parent.newRDFTreeNode(nativeWebShell,
nextNativeRDFNode, parent);
}
return result;
@ -122,7 +135,8 @@ public Object nextElement()
// Native Methods
//
private native boolean nativeHasMoreElements(int nativeRDFNode);
private native boolean nativeHasMoreElements(int webShellPtr,
int nativeRDFNode);
/**
@ -130,8 +144,9 @@ private native boolean nativeHasMoreElements(int nativeRDFNode);
*/
private native int nativeNextElement(int nativeRDFNode);
protected native void nativeFinalize();
private native int nativeNextElement(int webShellPtr,
int nativeRDFNode);
protected native void nativeFinalize(int webShellPtr);
// ----VERTIGO_TEST_START
@ -145,7 +160,7 @@ public static void main(String [] args)
Log.setApplicationName("RDFEnumeration");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: RDFEnumeration.java,v 1.1 2000-03-04 01:10:56 edburns%acm.org Exp $");
Log.setApplicationVersionDate("$Id: RDFEnumeration.java,v 1.2 2000-11-03 03:16:50 edburns%acm.org Exp $");
}

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

@ -53,12 +53,24 @@ private int nativeRDFNode = -1;
private RDFTreeNode parent;
/**
* a handle to the actual mozilla webShell, owned, allocated, and
* released by WindowControl
*/
public int nativeWebShell = -1;
//
// Constructors and Initializers
//
protected RDFTreeNode(int nativeNode, RDFTreeNode yourParent)
protected RDFTreeNode(int yourNativeWebShell,
int nativeNode, RDFTreeNode yourParent)
{
nativeWebShell = yourNativeWebShell;
nativeRDFNode = nativeNode;
parent = yourParent;
}
@ -76,7 +88,8 @@ protected RDFTreeNode(int nativeNode, RDFTreeNode yourParent)
// Abstract Methods
//
protected abstract RDFTreeNode newRDFTreeNode(int nativeNode,
protected abstract RDFTreeNode newRDFTreeNode(int nativeWebShell,
int nativeNode,
RDFTreeNode yourParent);
int getNativeRDFNode()
@ -106,7 +119,7 @@ public String toString()
{
String result = null;
if (-1 != nativeRDFNode) {
result = nativeToString(nativeRDFNode);
result = nativeToString(nativeWebShell, nativeRDFNode);
}
else {
result = super.toString();
@ -124,7 +137,7 @@ public Enumeration children()
Assert.assert(-1 != nativeRDFNode);
Enumeration enum = null;
enum = new RDFEnumeration(this);
enum = new RDFEnumeration(nativeWebShell, this);
return enum;
}
@ -143,9 +156,10 @@ public TreeNode getChildAt(int childIndex)
int childNode;
if (!isLeaf()) {
if (-1 != (childNode = nativeGetChildAt(nativeRDFNode, childIndex))) {
result = newRDFTreeNode(childNode, this);
}
if (-1 != (childNode = nativeGetChildAt(nativeWebShell, nativeRDFNode,
childIndex))) {
result = newRDFTreeNode(nativeWebShell, childNode, this);
}
}
return result;
@ -156,7 +170,7 @@ public int getChildCount()
Assert.assert(-1 != nativeRDFNode);
int result = -1;
result = nativeGetChildCount(nativeRDFNode);
result = nativeGetChildCount(nativeWebShell, nativeRDFNode);
return result;
}
@ -166,8 +180,8 @@ public int getIndex(TreeNode node)
Assert.assert(-1 != nativeRDFNode);
int result = -1;
if (node instanceof RDFTreeNode) {
result = nativeGetIndex(nativeRDFNode,
((RDFTreeNode)node).nativeRDFNode);
result = nativeGetIndex(nativeWebShell, nativeRDFNode,
((RDFTreeNode)node).nativeRDFNode);
}
return result;
@ -183,7 +197,7 @@ public boolean isLeaf()
{
Assert.assert(-1 != nativeRDFNode);
return nativeIsLeaf(nativeRDFNode);
return nativeIsLeaf(nativeWebShell, nativeRDFNode);
}
@ -202,7 +216,9 @@ public void insert(MutableTreeNode child, int index)
int childNativeRDFNode = childNode.getNativeRDFNode();
// hook up the child to its native peer
nativeInsertElementAt(nativeRDFNode, childNativeRDFNode, index);
nativeInsertElementAt(nativeWebShell, nativeRDFNode,
childNativeRDFNode, index);
// hook up the child to its java parent
childNode.setParent(this);
@ -239,8 +255,8 @@ public void setUserObject(Object object)
// Native methods
//
public native boolean nativeIsLeaf(int nativeRDFNode);
public native boolean nativeIsContainer(int nativeRDFNode);
public native boolean nativeIsLeaf(int webShellPtr, int nativeRDFNode);
public native boolean nativeIsContainer(int webShellPtr, int nativeRDFNode);
/**
@ -248,11 +264,14 @@ public native boolean nativeIsContainer(int nativeRDFNode);
*/
public native int nativeGetChildAt(int nativeRDFNode, int childIndex);
public native int nativeGetChildCount(int nativeRDFNode);
public native int nativeGetIndex(int nativeRDFNode, int childRDFNode);
public native String nativeToString(int nativeRDFNode);
public native void nativeInsertElementAt(int parentNativeRDFNode,
public native int nativeGetChildAt(int webShellPtr, int nativeRDFNode,
int childIndex);
public native int nativeGetChildCount(int webShellPtr, int nativeRDFNode);
public native int nativeGetIndex(int webShellPtr, int nativeRDFNode,
int childRDFNode);
public native String nativeToString(int webShellPtr, int nativeRDFNode);
public native void nativeInsertElementAt(int webShellPtr,
int parentNativeRDFNode,
int childNativeRDFNode, int index);
// ----VERTIGO_TEST_START
@ -267,7 +286,7 @@ public static void main(String [] args)
Log.setApplicationName("RDFTreeNode");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: RDFTreeNode.java,v 1.1 2000-03-04 01:10:56 edburns%acm.org Exp $");
Log.setApplicationVersionDate("$Id: RDFTreeNode.java,v 1.2 2000-11-03 03:16:50 edburns%acm.org Exp $");
}

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

@ -24,6 +24,7 @@
#include "rdf_util.h"
#include "ns_util.h"
#include "nsActions.h"
#include "nsCOMPtr.h"
@ -39,64 +40,63 @@ Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_nativeAddBookmark
JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_nativeGetBookmarks
(JNIEnv *env, jobject obj, jint webShellPtr)
{
nsresult rv;
jint result = -1;
rv = rdf_InitRDFUtils();
if (NS_FAILED(rv)) {
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeGetBookmarks");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't initialize RDF Utils");
return result;
}
result = (jint) kNC_BookmarksRoot.get();
wsInitBookmarksEvent *actionEvent = new wsInitBookmarksEvent(initContext);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (jint) voidResult;
return result;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_nativeNewRDFNode
(JNIEnv *env, jobject obj, jstring urlString, jboolean isFolder)
(JNIEnv *env, jobject obj, jint webShellPtr, jstring urlString,
jboolean isFolder)
{
nsCOMPtr<nsIRDFResource> newNode;
nsresult rv;
jint result = -1;
nsCAutoString uri("NC:BookmarksRoot");
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
const char *url = ::util_GetStringUTFChars(env, urlString);
uri.Append("#$");
uri.Append(url);
PRUnichar *uriUni = uri.ToNewUnicode();
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeNewRDFNode");
return result;
}
rv = gRDF->GetUnicodeResource(uriUni, getter_AddRefs(newNode));
nsCRT::free(uriUni);
::util_ReleaseStringUTFChars(env, urlString, url);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create new nsIRDFResource.");
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't get new RDFNode");
return result;
}
if (isFolder) {
rv = gRDFCU->MakeSeq(gBookmarksDataSource, newNode, nsnull);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: unable to make new folder as a sequence.");
return result;
}
rv = gBookmarksDataSource->Assert(newNode, kRDF_type,
kNC_Folder, PR_TRUE);
if (rv != NS_OK) {
::util_ThrowExceptionToJava(env, "Exception: unable to mark new folder as folder.");
return result;
}
const char *url = ::util_GetStringUTFChars(env, urlString);
if (!url) {
::util_ThrowExceptionToJava(env, "Exception: can't get new RDFNode, can't create url string");
return result;
}
/*
* Do the AddRef here.
*/
result = (jint)newNode.get();
((nsISupports *)result)->AddRef();
wsNewRDFNodeEvent *actionEvent = new wsNewRDFNodeEvent(initContext,
url,
(PRBool) isFolder);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (jint) voidResult;
::util_ReleaseStringUTFChars(env, urlString, url);
return result;
}

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

@ -25,6 +25,7 @@
#include "rdf_util.h"
#include "rdf_progids.h"
#include "ns_util.h"
#include "nsActions.h"
#include "nsIRDFContainer.h"
#include "nsIServiceManager.h"
@ -35,218 +36,92 @@
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
//
// Local function prototypes
//
/**
* pull the int for the field nativeEnum from the java object obj.
*/
jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode);
//
// JNI methods
//
JNIEXPORT jboolean JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeHasMoreElements
(JNIEnv *env, jobject obj, jint nativeRDFNode)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode)
{
nsresult rv;
jboolean result = JNI_FALSE;
PRBool prResult = PR_FALSE;
// assert -1 != nativeRDFNode
jint nativeEnum;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jboolean result = JNI_FALSE;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeIsContainer");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't see if isContainer");
return result;
}
wsRDFHasMoreElementsEvent *actionEvent =
new wsRDFHasMoreElementsEvent(initContext,
(PRUint32) nativeRDFNode,
(void *) obj);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (0 != voidResult) ? JNI_TRUE : JNI_FALSE;
if (-1 == (nativeEnum = getNativeEnumFromJava(env, obj, nativeRDFNode))) {
::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't get nativeEnum from nativeRDFNode.");
return result;
}
nsCOMPtr<nsISimpleEnumerator> enumerator = (nsISimpleEnumerator *)nativeEnum;
rv = enumerator->HasMoreElements(&prResult);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't ask nsISimpleEnumerator->HasMoreElements().");
return result;
}
result = (PR_FALSE == prResult) ? JNI_FALSE : JNI_TRUE;
return result;
return result;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeNextElement
(JNIEnv *env, jobject obj, jint nativeRDFNode)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode)
{
nsresult rv;
jint result = -1;
PRBool hasMoreElements = PR_FALSE;
// assert -1 != nativeRDFNode
jint nativeEnum;
nsCOMPtr<nsISupports> supportsResult;
nsCOMPtr<nsIRDFNode> nodeResult;
if (-1 == (nativeEnum = getNativeEnumFromJava(env, obj, nativeRDFNode))) {
::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't get nativeEnum from nativeRDFNode.");
return result;
}
nsCOMPtr<nsISimpleEnumerator> enumerator = (nsISimpleEnumerator *)nativeEnum;
rv = enumerator->HasMoreElements(&hasMoreElements);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't ask nsISimpleEnumerator->HasMoreElements().");
return result;
}
if (!hasMoreElements) {
return result;
}
rv = enumerator->GetNext(getter_AddRefs(supportsResult));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("Exception: nativeNextElement: Can't get next from enumerator.\n"));
}
return result;
}
// make sure it's an RDFNode
rv = supportsResult->QueryInterface(NS_GET_IID(nsIRDFNode),
getter_AddRefs(nodeResult));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("Exception: nativeNextElement: next from enumerator is not an nsIRDFNode.\n"));
}
return result;
}
result = (jint)nodeResult.get();
((nsISupports *)result)->AddRef();
return result;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jint result = -1;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeIsContainer");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't see if isContainer");
return result;
}
wsRDFNextElementEvent *actionEvent =
new wsRDFNextElementEvent(initContext,
(PRUint32) nativeRDFNode,
(void *) obj);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (jint) voidResult;
return result;
}
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeFinalize
(JNIEnv *env, jobject obj)
(JNIEnv *env, jobject obj, jint webShellPtr)
{
jint nativeEnum, nativeContainer;
// release the nsISimpleEnumerator
if (-1 == (nativeEnum =
::util_GetIntValueFromInstance(env, obj, "nativeEnum"))) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeFinalize: Can't get fieldID for nativeEnum.\n"));
}
return;
}
nsCOMPtr<nsISimpleEnumerator> enumerator =
(nsISimpleEnumerator *) nativeEnum;
((nsISupports *)enumerator.get())->Release();
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
// release the nsIRDFContainer
if (-1 == (nativeContainer =
::util_GetIntValueFromInstance(env, obj, "nativeContainer"))) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeFinalize: Can't get fieldID for nativeContainerFieldID.\n"));
}
return;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeFinalize");
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't finalize");
}
nsCOMPtr<nsIRDFContainer> container =
(nsIRDFContainer *) nativeContainer;
((nsISupports *)container.get())->Release();
wsRDFFinalizeEvent *actionEvent =
new wsRDFFinalizeEvent((void *) obj);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
if (NS_FAILED((nsresult) voidResult)) {
::util_ThrowExceptionToJava(env, "Exception: Can't Finalize");
}
return;
}
//
// Local functions
//
jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode)
{
nsresult rv;
jint result = -1;
result = ::util_GetIntValueFromInstance(env, obj, "nativeEnum");
// if the field has been initialized, just return the value
if (-1 != result) {
// NORMAL EXIT 1
return result;
}
// else, we need to create the enum
nsCOMPtr<nsIRDFNode> node = (nsIRDFNode *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> nodeResource;
nsCOMPtr<nsIRDFContainer> container;
nsCOMPtr<nsISimpleEnumerator> enumerator;
rv = node->QueryInterface(NS_GET_IID(nsIRDFResource),
getter_AddRefs(nodeResource));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("getNativeEnumFromJava: Argument nativeRDFNode isn't an nsIRDFResource.\n"));
}
return -1;
}
PR_ASSERT(gComponentManager);
// get a container in order to get the enum
rv = gComponentManager->CreateInstance(kRDFContainerCID,
nsnull,
NS_GET_IID(nsIRDFContainer),
getter_AddRefs(container));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("recursiveResourceTraversal: can't get a new container\n"));
}
return -1;
}
rv = container->Init(gBookmarksDataSource, nodeResource);
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("getNativeEnumFromJava: Can't Init container.\n"));
}
return -1;
}
rv = container->GetElements(getter_AddRefs(enumerator));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("getNativeEnumFromJava: Can't get enumeration from container.\n"));
}
return -1;
}
// IMPORTANT: Store the enum back into java
::util_SetIntValueForInstance(env,obj,"nativeEnum",(jint)enumerator.get());
// IMPORTANT: make sure it doesn't get deleted when it goes out of scope
((nsISupports *)enumerator.get())->AddRef();
// PENDING(edburns): I'm not sure if we need to keep the
// nsIRDFContainer from being destructed in order to maintain the
// validity of the nsISimpleEnumerator that came from the container.
// Just to be safe, I'm doing so.
::util_SetIntValueForInstance(env, obj, "nativeContainer",
(jint) container.get());
((nsISupports *)container.get())->AddRef();
// NORMAL EXIT 2
result = (jint)enumerator.get();
return result;
}

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

@ -25,14 +25,12 @@
#include "rdf_util.h"
#include "rdf_progids.h"
#include "ns_util.h"
#include "nsActions.h"
#include "nsIServiceManager.h"
#include "prlog.h" // for PR_ASSERT
#include "nsRDFCID.h" // for NS_RDFCONTAINER_CID
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
//
// Local function prototypes
@ -43,48 +41,56 @@ static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
//
JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsLeaf
(JNIEnv *env, jobject obj, jint nativeRDFNode)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode)
{
nsCOMPtr<nsIRDFNode> node = (nsIRDFNode *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> nodeResource;
nsresult rv;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jint childCount = -1;
jboolean result = JNI_FALSE;
PRInt32 count;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeGetChildCount");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't getChildAt");
return result;
}
wsRDFGetChildCountEvent *actionEvent =
new wsRDFGetChildCountEvent(initContext,
(PRUint32) nativeRDFNode);
PLEvent * event = (PLEvent*) *actionEvent;
rv = node->QueryInterface(NS_GET_IID(nsIRDFResource),
getter_AddRefs(nodeResource));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeIsLeaf: nativeRDFNode is not an RDFResource.");
return result;
}
rv = rdf_getChildCount(nodeResource, &count);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeIsLeaf: can't get child count from nativeRDFNode.");
return result;
}
result = (0 == count) ? JNI_TRUE : JNI_FALSE;
voidResult = ::util_PostSynchronousEvent(initContext, event);
childCount = (jint) voidResult;
result = (childCount == 0) ? JNI_TRUE : JNI_FALSE;
return result;
}
JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsContainer
(JNIEnv *env, jobject obj, jint nativeRDFNode)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode)
{
nsCOMPtr<nsIRDFNode> node = (nsIRDFNode *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> nodeResource;
nsresult rv;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jboolean result = JNI_FALSE;
PRBool prBool;
rv = node->QueryInterface(NS_GET_IID(nsIRDFResource),
getter_AddRefs(nodeResource));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeIsContainer: nativeRDFNode is not an RDFResource.");
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeIsContainer");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't see if isContainer");
return result;
}
rv = gRDFCU->IsContainer(gBookmarksDataSource, nodeResource,
&prBool);
result = (prBool == PR_FALSE) ? JNI_FALSE : JNI_TRUE;
wsRDFIsContainerEvent *actionEvent = new wsRDFIsContainerEvent(initContext,
(PRUint32) nativeRDFNode);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (0 != voidResult) ? JNI_TRUE : JNI_FALSE;
return result;
}
@ -93,198 +99,146 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNod
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildAt
(JNIEnv *env, jobject obj, jint nativeRDFNode, jint childIndex)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode,
jint childIndex)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jint result = -1;
nsresult rv;
// PENDING(edburns): assert rdf_InitRDFUtils()
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> child;
rv = rdf_getChildAt(childIndex, parent, getter_AddRefs(child));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeGetChildAt: Can't get child.");
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeGetChildAt");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't getChildAt");
return result;
}
result = (jint)child.get();
((nsISupports *)result)->AddRef();
wsRDFGetChildAtEvent *actionEvent =
new wsRDFGetChildAtEvent(initContext,
(PRUint32) nativeRDFNode,
(PRUint32) childIndex);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (jint) voidResult;
return result;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildCount
(JNIEnv *env, jobject obj, jint nativeRDFNode)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jint result = -1;
PRInt32 count;
nsresult rv;
// PENDING(edburns): assert rdf_InitRDFUtils()
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) nativeRDFNode;
rv = rdf_getChildCount(parent, &count);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count.");
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeGetChildCount");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't getChildAt");
return result;
}
result = (jint)count;
wsRDFGetChildCountEvent *actionEvent =
new wsRDFGetChildCountEvent(initContext,
(PRUint32) nativeRDFNode);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (jint) voidResult;
return result;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetIndex
(JNIEnv *env, jobject obj, jint nativeRDFNode, jint childRDFNode)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode,
jint childRDFNode)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jint result = -1;
PRInt32 index;
nsresult rv;
// PENDING(edburns): assert rdf_InitRDFUtils()
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> child = (nsIRDFResource *) childRDFNode;
rv = rdf_getIndexOfChild(parent, child, &index);
result = (jint) index;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeGetChildIndex");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't getChildIndex");
return result;
}
wsRDFGetChildIndexEvent *actionEvent =
new wsRDFGetChildIndexEvent(initContext,
(PRUint32) nativeRDFNode,
(PRUint32) childRDFNode);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (jint) voidResult;
return result;
}
JNIEXPORT jstring JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString
(JNIEnv *env, jobject obj, jint nativeRDFNode)
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode)
{
nsCOMPtr<nsIRDFResource> currentResource =
(nsIRDFResource *) nativeRDFNode;
nsCOMPtr<nsIRDFNode> node;
nsCOMPtr<nsIRDFLiteral> literal;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
jstring result = nsnull;
PRBool isContainer = PR_FALSE;
nsresult rv;
const PRUnichar *textForNode = nsnull;
rv = gRDFCU->IsContainer(gBookmarksDataSource, currentResource,
&isContainer);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeToString: Can't tell if RDFResource is container.");
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeToString");
return result;
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't toString");
return result;
}
wsRDFToStringEvent *actionEvent =
new wsRDFToStringEvent(initContext,
(PRUint32) nativeRDFNode);
PLEvent * event = (PLEvent*) *actionEvent;
if (isContainer) {
// It's a bookmarks folder
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_Name, PR_TRUE,
getter_AddRefs(node));
// get the name of the folder
if (rv == 0) {
// if so, make sure it's an nsIRDFLiteral
rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral),
getter_AddRefs(literal));
if (NS_SUCCEEDED(rv)) {
rv = literal->GetValueConst(&textForNode);
}
else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node is not an nsIRDFLiteral.\n"));
}
}
}
}
else {
// It's a bookmark or a Separator
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_URL, PR_TRUE,
getter_AddRefs(node));
// See if it has a Name
if (0 != rv) {
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_Name, PR_TRUE,
getter_AddRefs(node));
}
if (0 == rv) {
rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral),
getter_AddRefs(literal));
if (NS_SUCCEEDED(rv)) {
// get the value of the literal
rv = literal->GetValueConst(&textForNode);
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node doesn't have a value.\n"));
}
}
}
else {
rdf_printArcLabels(currentResource);
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node is not an nsIRDFLiteral.\n"));
}
}
}
else {
rdf_printArcLabels(currentResource);
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node doesn't have a URL.\n"));
}
}
}
voidResult = ::util_PostSynchronousEvent(initContext, event);
result = (jstring) voidResult;
if (nsnull != textForNode) {
nsString * string = new nsString(textForNode);
int length = 0;
if (nsnull != string) {
length = string->Length();
}
result = ::util_NewString(env, (const jchar *) textForNode, length);
}
else {
result = ::util_NewStringUTF(env, "");
}
return result;
}
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt
(JNIEnv *env, jobject obj, jint parentRDFNode,
(JNIEnv *env, jobject obj, jint webShellPtr, jint parentRDFNode,
jint childRDFNode, jint childIndex)
{
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) parentRDFNode;
nsCOMPtr<nsIRDFResource> newChild = (nsIRDFResource *) childRDFNode;
nsCOMPtr<nsIRDFContainer> container;
nsresult rv;
PRBool isContainer;
rv = gRDFCU->IsContainer(gBookmarksDataSource, parent,
&isContainer);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: RDFResource is not a container.");
return;
}
PR_ASSERT(gComponentManager);
// get a container in order to create a child
rv = gComponentManager->CreateInstance(kRDFContainerCID,
nsnull,
NS_GET_IID(nsIRDFContainer),
getter_AddRefs(container));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create container.");
return;
}
rv = container->Init(gBookmarksDataSource, parent);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create container.");
return;
}
rv = container->InsertElementAt(newChild, childIndex, PR_TRUE);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't insert element into parent container.");
return;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
void * voidResult = nsnull;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeInsertElementAt");
}
if (!initContext->initComplete) {
::util_ThrowExceptionToJava(env, "Exception: can't InsertElementAt");
}
wsRDFInsertElementAtEvent *actionEvent =
new wsRDFInsertElementAtEvent(initContext,
(PRUint32) parentRDFNode,
(PRUint32) childRDFNode,
(PRUint32) childIndex);
PLEvent * event = (PLEvent*) *actionEvent;
voidResult = ::util_PostSynchronousEvent(initContext, event);
if (NS_FAILED((nsresult) voidResult)) {
::util_ThrowExceptionToJava(env, "Exception: Can't InsertElementAt");
}
return;
}

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

@ -110,7 +110,7 @@ void (* nativeInitialize) (JNIEnv *, jobject, jint);
void (* nativeProcessEvents) (JNIEnv *, jobject, jint);
// from BookmarksImpl.h
jint (* nativeGetBookmarks) (JNIEnv *, jobject, jint);
jint (* nativeNewRDFNode) (JNIEnv *, jobject, jstring, jboolean);
jint (* nativeNewRDFNode) (JNIEnv *, jobject, jint, jstring, jboolean);
// from CurrentPageImpl.h
void (* nativeCopyCurrentSelectionToSystemClipboard) (JNIEnv *, jobject, jint);
void (* nativeFindInPage) (JNIEnv *, jobject, jint, jstring, jboolean, jboolean);
@ -143,17 +143,17 @@ void (* nativeLoadURL) (JNIEnv *, jobject, jint, jstring);
void (* nativeRefresh) (JNIEnv *, jobject, jint, jlong);
void (* nativeStop) (JNIEnv *, jobject, jint);
// from RDFEnumeration.h
void (* nativeFinalize) (JNIEnv *, jobject);
jboolean (* nativeHasMoreElements) (JNIEnv *, jobject, jint);
jint (* nativeNextElement) (JNIEnv *, jobject, jint);
void (* nativeFinalize) (JNIEnv *, jobject, jint);
jboolean (* nativeHasMoreElements) (JNIEnv *, jobject, jint, jint);
jint (* nativeNextElement) (JNIEnv *, jobject, jint, jint);
// from RDFTreeNode.h
jint (* nativeGetChildAt) (JNIEnv *, jobject, jint, jint);
jint (* nativeGetChildCount) (JNIEnv *, jobject, jint);
jint (* nativeGetIndex) (JNIEnv *, jobject, jint, jint);
void (* nativeInsertElementAt) (JNIEnv *, jobject, jint, jint, jint);
jboolean (* nativeIsContainer) (JNIEnv *, jobject, jint);
jboolean (* nativeIsLeaf) (JNIEnv *, jobject, jint);
jstring (* nativeToString) (JNIEnv *, jobject, jint);
jint (* nativeGetChildAt) (JNIEnv *, jobject, jint, jint, jint);
jint (* nativeGetChildCount) (JNIEnv *, jobject, jint, jint);
jint (* nativeGetIndex) (JNIEnv *, jobject, jint, jint, jint);
void (* nativeInsertElementAt) (JNIEnv *, jobject, jint, jint, jint, jint);
jboolean (* nativeIsContainer) (JNIEnv *, jobject, jint, jint);
jboolean (* nativeIsLeaf) (JNIEnv *, jobject, jint, jint);
jstring (* nativeToString) (JNIEnv *, jobject, jint, jint);
// from WindowControlImpl.h
jint (* nativeCreateInitContext) (JNIEnv *, jobject, jint, jint, jint, jint, jint, jobject);
void (* nativeMoveWindowTo) (JNIEnv *, jobject, jint, jint, jint);
@ -216,44 +216,44 @@ void locateBrowserControlStubFunctions(void * dll) {
printf("got dlsym error %s\n", dlerror());
}
nativeGetChildAt = (jint (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildAt");
nativeGetChildAt = (jint (*) (JNIEnv *, jobject, jint, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildAt");
if (!nativeGetChildAt) {
printf("got dlsym error %s\n", dlerror());
}
nativeGetChildCount = (jint (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildCount");
nativeGetChildCount = (jint (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildCount");
if (!nativeGetChildCount) {
printf("got dlsym error %s\n", dlerror());
}
nativeGetIndex = (jint (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetIndex");
nativeGetIndex = (jint (*) (JNIEnv *, jobject, jint, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetIndex");
if (!nativeGetIndex) {
printf("got dlsym error %s\n", dlerror());
}
nativeInsertElementAt = (void (*) (JNIEnv *, jobject, jint, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt");
nativeInsertElementAt = (void (*) (JNIEnv *, jobject, jint, jint, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt");
if (!nativeInsertElementAt) {
printf("got dlsym error %s\n", dlerror());
}
nativeIsContainer = (jboolean (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsContainer");
nativeIsContainer = (jboolean (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsContainer");
if (!nativeIsContainer) {
printf("got dlsym error %s\n", dlerror());
}
nativeIsLeaf = (jboolean (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsLeaf");
nativeIsLeaf = (jboolean (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsLeaf");
if (!nativeIsLeaf) {
printf("got dlsym error %s\n", dlerror());
}
nativeToString = (jstring (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString");
nativeToString = (jstring (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString");
if (!nativeToString) {
printf("got dlsym error %s\n", dlerror());
}
nativeFinalize = (void (*) (JNIEnv *, jobject)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeFinalize");
nativeFinalize = (void (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeFinalize");
if (!nativeFinalize) {
printf("got dlsym error %s\n", dlerror());
}
nativeHasMoreElements = (jboolean (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeHasMoreElements");
nativeHasMoreElements = (jboolean (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeHasMoreElements");
if (!nativeHasMoreElements) {
printf("got dlsym error %s\n", dlerror());
}
nativeNextElement = (jint (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeNextElement");
nativeNextElement = (jint (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeNextElement");
if (!nativeNextElement) {
printf("got dlsym error %s\n", dlerror());
}
@ -375,7 +375,7 @@ void locateBrowserControlStubFunctions(void * dll) {
if (!nativeGetBookmarks) {
printf("got dlsym error %s\n", dlerror());
}
nativeNewRDFNode = (jint (*) (JNIEnv *, jobject, jstring, jboolean)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_nativeNewRDFNode");
nativeNewRDFNode = (jint (*) (JNIEnv *, jobject, jint, jstring, jboolean)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_nativeNewRDFNode");
if (!nativeNewRDFNode) {
printf("got dlsym error %s\n", dlerror());
}
@ -484,8 +484,8 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_nativeNewRDFNode
(JNIEnv * env, jobject obj, jstring url, jboolean isFolder) {
return (* nativeNewRDFNode) (env, obj, url, isFolder);
(JNIEnv * env, jobject obj, jint webShellPtr, jstring url, jboolean isFolder) {
return (* nativeNewRDFNode) (env, obj, webShellPtr, url, isFolder);
}
@ -783,8 +783,8 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl
*/
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeFinalize
(JNIEnv *env, jobject obj) {
(* nativeFinalize) (env, obj);
(JNIEnv *env, jobject obj, jint webShellPtr) {
(* nativeFinalize) (env, obj, webShellPtr);
}
/*
@ -794,8 +794,8 @@ Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeFinalize
*/
JNIEXPORT jboolean JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeHasMoreElements
(JNIEnv *env, jobject obj, jint nativeRDFNode) {
return (* nativeHasMoreElements) (env, obj, nativeRDFNode);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode) {
return (* nativeHasMoreElements) (env, obj, webShellPtr, nativeRDFNode);
}
/*
@ -805,8 +805,8 @@ Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeHasMoreElements
*/
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeNextElement
(JNIEnv *env, jobject obj, jint nativeRDFNode) {
return (* nativeNextElement) (env, obj, nativeRDFNode);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode) {
return (* nativeNextElement) (env, obj, webShellPtr, nativeRDFNode);
}
@ -819,8 +819,10 @@ Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeNextElement
*/
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildAt
(JNIEnv *env, jobject obj, jint nativeRDFNode, jint childIndex) {
return (* nativeGetChildAt) (env, obj, nativeRDFNode, childIndex);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode,
jint childIndex) {
return (* nativeGetChildAt) (env, obj, webShellPtr, nativeRDFNode,
childIndex);
}
/*
@ -830,8 +832,8 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildAt
*/
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildCount
(JNIEnv *env, jobject obj, jint nativeRDFNode) {
return (* nativeGetChildCount) (env, obj, nativeRDFNode);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode) {
return (* nativeGetChildCount) (env, obj, webShellPtr, nativeRDFNode);
}
/*
@ -841,8 +843,10 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildCount
*/
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetIndex
(JNIEnv *env, jobject obj, jint nativeRDFNode, jint childRDFNode) {
return (* nativeGetIndex) (env, obj, nativeRDFNode, childRDFNode);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode,
jint childRDFNode) {
return (* nativeGetIndex) (env, obj, webShellPtr, nativeRDFNode,
childRDFNode);
}
/*
@ -852,8 +856,10 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetIndex
*/
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt
(JNIEnv *env, jobject obj, jint parentRDFNode, jint childRDFNode, jint childIndex) {
(* nativeInsertElementAt) (env, obj, parentRDFNode, childRDFNode, childIndex);
(JNIEnv *env, jobject obj, jint webShellPtr, jint parentRDFNode,
jint childRDFNode, jint childIndex) {
(* nativeInsertElementAt) (env, obj, webShellPtr, parentRDFNode,
childRDFNode, childIndex);
}
/*
@ -862,8 +868,8 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsContainer
(JNIEnv *env, jobject obj, jint nativeRDFNode) {
return (* nativeIsContainer) (env, obj, nativeRDFNode);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode) {
return (* nativeIsContainer) (env, obj, webShellPtr, nativeRDFNode);
}
/*
@ -872,8 +878,8 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNod
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsLeaf
(JNIEnv *env, jobject obj, jint nativeRDFNode) {
return (* nativeIsLeaf) (env, obj, nativeRDFNode);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode) {
return (* nativeIsLeaf) (env, obj, webShellPtr, nativeRDFNode);
}
/*
@ -883,8 +889,8 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNod
*/
JNIEXPORT jstring JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString
(JNIEnv *env, jobject obj, jint nativeRDFNode) {
return (* nativeToString) (env, obj, nativeRDFNode);
(JNIEnv *env, jobject obj, jint webShellPtr, jint nativeRDFNode) {
return (* nativeToString) (env, obj, webShellPtr, nativeRDFNode);
}

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

@ -44,9 +44,26 @@
#include "nsIContentViewerEdit.h"
#include "ns_util.h"
#include "rdf_util.h"
#include "nsEmbedAPI.h" // for NS_TermEmbedding
#include "nsRDFCID.h" // for NS_RDFCONTAINER_CID
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
//
// Local function prototypes
//
/**
* pull the int for the field nativeEnum from the java object obj.
*/
jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode);
void * handleEvent (PLEvent * event);
void destroyEvent (PLEvent * event);
@ -753,7 +770,125 @@ wsDeallocateInitContextEvent::handleEvent ()
return (void *) NS_OK;
} // handleEvent()
wsInitBookmarksEvent::wsInitBookmarksEvent(WebShellInitContext* yourInitContext) :
nsActionEvent(),
mInitContext(yourInitContext)
{
}
void *
wsInitBookmarksEvent::handleEvent ()
{
void *result = nsnull;
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
nsresult rv;
rv = rdf_InitRDFUtils();
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: can't initialize RDF Utils");
return (void *) result;
}
result = (void *) kNC_BookmarksRoot.get();
return result;
} // handleEvent()
wsNewRDFNodeEvent::wsNewRDFNodeEvent(WebShellInitContext* yourInitContext,
const char * yourUrlString,
PRBool yourIsFolder) :
nsActionEvent(),
mInitContext(yourInitContext), mUrlString(yourUrlString),
mIsFolder(yourIsFolder)
{
}
void *
wsNewRDFNodeEvent::handleEvent ()
{
void *result = nsnull;
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
nsresult rv;
nsCOMPtr<nsIRDFResource> newNode;
nsCAutoString uri("NC:BookmarksRoot");
JNIEnv *env = (JNIEnv*) JNU_GetEnv(gVm, JNI_VERSION);
const char *url = mUrlString;
uri.Append("#$");
uri.Append(url);
PRUnichar *uriUni = uri.ToNewUnicode();
rv = gRDF->GetUnicodeResource(uriUni, getter_AddRefs(newNode));
nsCRT::free(uriUni);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create new nsIRDFResource.");
return result;
}
if (mIsFolder) {
rv = gRDFCU->MakeSeq(gBookmarksDataSource, newNode, nsnull);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: unable to make new folder as a sequence.");
return result;
}
rv = gBookmarksDataSource->Assert(newNode, kRDF_type,
kNC_Folder, PR_TRUE);
if (rv != NS_OK) {
::util_ThrowExceptionToJava(env, "Exception: unable to mark new folder as folder.");
return result;
}
}
/*
* Do the AddRef here.
*/
result = (void *)newNode.get();
((nsISupports *)result)->AddRef();
return result;
} // handleEvent()
wsRDFIsContainerEvent::wsRDFIsContainerEvent(WebShellInitContext* yourInitContext,
PRUint32 yourNativeRDFNode) :
nsActionEvent(),
mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode)
{
}
void *
wsRDFIsContainerEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
nsCOMPtr<nsIRDFNode> node = (nsIRDFNode *) mNativeRDFNode;
nsCOMPtr<nsIRDFResource> nodeResource;
nsresult rv;
jboolean result = JNI_FALSE;
PRBool prBool;
rv = node->QueryInterface(NS_GET_IID(nsIRDFResource),
getter_AddRefs(nodeResource));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeIsContainer: nativeRDFNode is not an RDFResource.");
return nsnull;
}
rv = gRDFCU->IsContainer(gBookmarksDataSource, nodeResource,
&prBool);
result = (prBool == PR_FALSE) ? JNI_FALSE : JNI_TRUE;
return (void *) result;
} // handleEvent()
void *
wsFindEvent::handleEvent ()
@ -775,6 +910,94 @@ wsFindEvent::wsFindEvent(nsIFindComponent * findcomponent, nsISearchContext * sr
{
}
wsRDFGetChildAtEvent::wsRDFGetChildAtEvent(WebShellInitContext* yourInitContext,
PRUint32 yourNativeRDFNode,
PRUint32 yourChildIndex) :
nsActionEvent(),
mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode),
mChildIndex(yourChildIndex)
{
}
void *
wsRDFGetChildAtEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
jint result = -1;
nsresult rv;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
// PENDING(edburns): assert rdf_InitRDFUtils()
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) mNativeRDFNode;
nsCOMPtr<nsIRDFResource> child;
rv = rdf_getChildAt(mChildIndex, parent, getter_AddRefs(child));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeGetChildAt: Can't get child.");
return nsnull;
}
result = (jint)child.get();
((nsISupports *)result)->AddRef();
return (void *) result;
} // handleEvent()
wsRDFGetChildCountEvent::wsRDFGetChildCountEvent(WebShellInitContext* yourInitContext,
PRUint32 yourNativeRDFNode) :
nsActionEvent(),
mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode)
{
}
void *
wsRDFGetChildCountEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
jint result = -1;
PRInt32 count;
nsresult rv;
// PENDING(edburns): assert rdf_InitRDFUtils()
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) mNativeRDFNode;
rv = rdf_getChildCount(parent, &count);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count.");
return nsnull;
}
result = (jint)count;
return (void *) result;
} // handleEvent()
wsRDFGetChildIndexEvent::wsRDFGetChildIndexEvent(WebShellInitContext* yourInitContext,
PRUint32 yourNativeRDFNode,
PRUint32 yourChildRDFNode) :
nsActionEvent(),
mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode),
mChildRDFNode(yourChildRDFNode)
{
}
void *
wsRDFGetChildIndexEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
jint result = -1;
PRInt32 index;
nsresult rv;
// PENDING(edburns): assert rdf_InitRDFUtils()
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) mNativeRDFNode;
nsCOMPtr<nsIRDFResource> child = (nsIRDFResource *) mChildRDFNode;
rv = rdf_getIndexOfChild(parent, child, &index);
result = (jint) index;
return (void *) result;
} // handleEvent()
void *
wsSelectAllEvent::handleEvent ()
@ -794,6 +1017,274 @@ wsSelectAllEvent::wsSelectAllEvent(nsIContentViewerEdit * contentViewerEdit) :
{
}
wsRDFToStringEvent::wsRDFToStringEvent(WebShellInitContext* yourInitContext,
PRUint32 yourNativeRDFNode) :
nsActionEvent(),
mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode)
{
}
void *
wsRDFToStringEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIRDFResource> currentResource =
(nsIRDFResource *) mNativeRDFNode;
nsCOMPtr<nsIRDFNode> node;
nsCOMPtr<nsIRDFLiteral> literal;
jstring result = nsnull;
PRBool isContainer = PR_FALSE;
nsresult rv;
const PRUnichar *textForNode = nsnull;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
rv = gRDFCU->IsContainer(gBookmarksDataSource, currentResource,
&isContainer);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeToString: Can't tell if RDFResource is container.");
return nsnull;
}
if (isContainer) {
// It's a bookmarks folder
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_Name, PR_TRUE,
getter_AddRefs(node));
// get the name of the folder
if (rv == 0) {
// if so, make sure it's an nsIRDFLiteral
rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral),
getter_AddRefs(literal));
if (NS_SUCCEEDED(rv)) {
rv = literal->GetValueConst(&textForNode);
}
else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node is not an nsIRDFLiteral.\n"));
}
}
}
}
else {
// It's a bookmark or a Separator
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_URL, PR_TRUE,
getter_AddRefs(node));
// See if it has a Name
if (0 != rv) {
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_Name, PR_TRUE,
getter_AddRefs(node));
}
if (0 == rv) {
rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral),
getter_AddRefs(literal));
if (NS_SUCCEEDED(rv)) {
// get the value of the literal
rv = literal->GetValueConst(&textForNode);
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node doesn't have a value.\n"));
}
}
}
else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node is not an nsIRDFLiteral.\n"));
}
}
}
else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node doesn't have a URL.\n"));
}
}
}
if (nsnull != textForNode) {
nsString * string = new nsString(textForNode);
int length = 0;
if (nsnull != string) {
length = string->Length();
}
result = ::util_NewString(env, (const jchar *) textForNode, length);
}
else {
result = ::util_NewStringUTF(env, "");
}
return (void *) result;
} // handleEvent()
wsRDFInsertElementAtEvent::wsRDFInsertElementAtEvent(WebShellInitContext* yourInitContext,
PRUint32 yourParentRDFNode,
PRUint32 yourChildRDFNode,
PRUint32 yourChildIndex) :
nsActionEvent(),
mInitContext(yourInitContext), mParentRDFNode(yourParentRDFNode),
mChildRDFNode(yourChildRDFNode), mChildIndex(yourChildIndex)
{
}
void *
wsRDFInsertElementAtEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) mParentRDFNode;
nsCOMPtr<nsIRDFResource> newChild = (nsIRDFResource *) mChildRDFNode;
nsCOMPtr<nsIRDFContainer> container;
nsresult rv;
PRBool isContainer;
rv = gRDFCU->IsContainer(gBookmarksDataSource, parent,
&isContainer);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: RDFResource is not a container.");
return (void *) NS_ERROR_UNEXPECTED;
}
PR_ASSERT(gComponentManager);
// get a container in order to create a child
rv = gComponentManager->CreateInstance(kRDFContainerCID,
nsnull,
NS_GET_IID(nsIRDFContainer),
getter_AddRefs(container));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create container.");
return (void *) NS_ERROR_UNEXPECTED;
}
rv = container->Init(gBookmarksDataSource, parent);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create container.");
return (void *) NS_ERROR_UNEXPECTED;
}
rv = container->InsertElementAt(newChild, mChildIndex, PR_TRUE);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't insert element into parent container.");
return (void *) NS_ERROR_UNEXPECTED;
}
return (void *) NS_OK;
} // handleEvent()
wsRDFHasMoreElementsEvent::wsRDFHasMoreElementsEvent(WebShellInitContext* yourInitContext,
PRUint32 yourNativeRDFNode,
void *yourJobject) :
nsActionEvent(),
mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode),
mJobject(yourJobject)
{
}
void *
wsRDFHasMoreElementsEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
nsresult rv;
jboolean result = JNI_FALSE;
PRBool prResult = PR_FALSE;
// assert -1 != nativeRDFNode
jint nativeEnum;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
if (-1 == (nativeEnum = getNativeEnumFromJava(env, (jobject) mJobject,
mNativeRDFNode))) {
::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't get nativeEnum from nativeRDFNode.");
return (void *) NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsISimpleEnumerator> enumerator = (nsISimpleEnumerator *)nativeEnum;
rv = enumerator->HasMoreElements(&prResult);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't ask nsISimpleEnumerator->HasMoreElements().");
return (void *) NS_ERROR_UNEXPECTED;
}
result = (PR_FALSE == prResult) ? JNI_FALSE : JNI_TRUE;
return (void *) result;
} // handleEvent()
wsRDFNextElementEvent::wsRDFNextElementEvent(WebShellInitContext* yourInitContext,
PRUint32 yourNativeRDFNode,
void *yourJobject) :
nsActionEvent(),
mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode),
mJobject(yourJobject)
{
}
void *
wsRDFNextElementEvent::handleEvent ()
{
if (!mInitContext) {
return (void *) NS_ERROR_UNEXPECTED;
}
nsresult rv;
jint result = -1;
PRBool hasMoreElements = PR_FALSE;
// assert -1 != nativeRDFNode
jint nativeEnum;
nsCOMPtr<nsISupports> supportsResult;
nsCOMPtr<nsIRDFNode> nodeResult;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
if (-1 == (nativeEnum = getNativeEnumFromJava(env, (jobject) mJobject,
mNativeRDFNode))) {
::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't get nativeEnum from nativeRDFNode.");
return (void *) NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsISimpleEnumerator> enumerator = (nsISimpleEnumerator *)nativeEnum;
rv = enumerator->HasMoreElements(&hasMoreElements);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't ask nsISimpleEnumerator->HasMoreElements().");
return (void *) NS_ERROR_UNEXPECTED;
}
if (!hasMoreElements) {
return (void *) NS_ERROR_UNEXPECTED;
}
rv = enumerator->GetNext(getter_AddRefs(supportsResult));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("Exception: nativeNextElement: Can't get next from enumerator.\n"));
}
return (void *) NS_ERROR_UNEXPECTED;
}
// make sure it's an RDFNode
rv = supportsResult->QueryInterface(NS_GET_IID(nsIRDFNode),
getter_AddRefs(nodeResult));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("Exception: nativeNextElement: next from enumerator is not an nsIRDFNode.\n"));
}
return (void *) NS_ERROR_UNEXPECTED;
}
result = (jint)nodeResult.get();
((nsISupports *)result)->AddRef();
return (void *) result;
} // handleEvent()
void *
wsCopySelectionEvent::handleEvent ()
@ -813,6 +1304,132 @@ wsCopySelectionEvent::wsCopySelectionEvent(nsIContentViewerEdit * contentViewerE
{
}
wsRDFFinalizeEvent::wsRDFFinalizeEvent(void *yourJobject) :
nsActionEvent(),
mJobject(yourJobject)
{
}
// EOF
void *
wsRDFFinalizeEvent::handleEvent ()
{
if (!mJobject) {
return (void *) NS_ERROR_UNEXPECTED;
}
jint nativeEnum, nativeContainer;
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
// release the nsISimpleEnumerator
if (-1 == (nativeEnum =
::util_GetIntValueFromInstance(env, (jobject) mJobject,
"nativeEnum"))) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeFinalize: Can't get fieldID for nativeEnum.\n"));
}
return (void *) NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsISimpleEnumerator> enumerator =
(nsISimpleEnumerator *) nativeEnum;
((nsISupports *)enumerator.get())->Release();
// release the nsIRDFContainer
if (-1 == (nativeContainer =
::util_GetIntValueFromInstance(env, (jobject) mJobject,
"nativeContainer"))) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeFinalize: Can't get fieldID for nativeContainerFieldID.\n"));
}
return (void *) NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIRDFContainer> container =
(nsIRDFContainer *) nativeContainer;
((nsISupports *)container.get())->Release();
return (void *) NS_OK;
} // handleEvent()
//
// Local functions
//
jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode)
{
nsresult rv;
jint result = -1;
result = ::util_GetIntValueFromInstance(env, obj, "nativeEnum");
// if the field has been initialized, just return the value
if (-1 != result) {
// NORMAL EXIT 1
return result;
}
// else, we need to create the enum
nsCOMPtr<nsIRDFNode> node = (nsIRDFNode *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> nodeResource;
nsCOMPtr<nsIRDFContainer> container;
nsCOMPtr<nsISimpleEnumerator> enumerator;
rv = node->QueryInterface(NS_GET_IID(nsIRDFResource),
getter_AddRefs(nodeResource));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("getNativeEnumFromJava: Argument nativeRDFNode isn't an nsIRDFResource.\n"));
}
return -1;
}
PR_ASSERT(gComponentManager);
// get a container in order to get the enum
rv = gComponentManager->CreateInstance(kRDFContainerCID,
nsnull,
NS_GET_IID(nsIRDFContainer),
getter_AddRefs(container));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("recursiveResourceTraversal: can't get a new container\n"));
}
return -1;
}
rv = container->Init(gBookmarksDataSource, nodeResource);
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("getNativeEnumFromJava: Can't Init container.\n"));
}
return -1;
}
rv = container->GetElements(getter_AddRefs(enumerator));
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("getNativeEnumFromJava: Can't get enumeration from container.\n"));
}
return -1;
}
// IMPORTANT: Store the enum back into java
::util_SetIntValueForInstance(env,obj,"nativeEnum",(jint)enumerator.get());
// IMPORTANT: make sure it doesn't get deleted when it goes out of scope
((nsISupports *)enumerator.get())->AddRef();
// PENDING(edburns): I'm not sure if we need to keep the
// nsIRDFContainer from being destructed in order to maintain the
// validity of the nsISimpleEnumerator that came from the container.
// Just to be safe, I'm doing so.
::util_SetIntValueForInstance(env, obj, "nativeContainer",
(jint) container.get());
((nsISupports *)container.get())->AddRef();
// NORMAL EXIT 2
result = (jint)enumerator.get();
return result;
}

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

@ -359,6 +359,15 @@ protected:
WebShellInitContext *mInitContext;
};
class wsInitBookmarksEvent : public nsActionEvent {
public:
wsInitBookmarksEvent(WebShellInitContext *yourInitContext);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
};
class wsFindEvent : public nsActionEvent {
public:
wsFindEvent(nsIFindComponent *findComponent,
@ -370,6 +379,28 @@ protected:
nsISearchContext * mSearchContext;
};
class wsNewRDFNodeEvent : public nsActionEvent {
public:
wsNewRDFNodeEvent(WebShellInitContext *yourInitContext,
const char *yourUrlString, PRBool yourIsFolder);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
const char *mUrlString;
PRBool mIsFolder;
};
class wsRDFIsContainerEvent : public nsActionEvent {
public:
wsRDFIsContainerEvent(WebShellInitContext *yourInitContext,
PRUint32 yourNativeRDFNode);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mNativeRDFNode;
};
class wsSelectAllEvent : public nsActionEvent {
public:
@ -380,6 +411,28 @@ protected:
nsIContentViewerEdit * mContentViewerEdit;
};
class wsRDFGetChildAtEvent : public nsActionEvent {
public:
wsRDFGetChildAtEvent(WebShellInitContext *yourInitContext,
PRUint32 yourNativeRDFNode, PRUint32 childIndex);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mNativeRDFNode;
PRUint32 mChildIndex;
};
class wsRDFGetChildCountEvent : public nsActionEvent {
public:
wsRDFGetChildCountEvent(WebShellInitContext *yourInitContext,
PRUint32 yourNativeRDFNode);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mNativeRDFNode;
};
class wsCopySelectionEvent : public nsActionEvent {
public:
@ -390,6 +443,80 @@ protected:
nsIContentViewerEdit * mContentViewerEdit;
};
class wsRDFGetChildIndexEvent : public nsActionEvent {
public:
wsRDFGetChildIndexEvent(WebShellInitContext *yourInitContext,
PRUint32 yourNativeRDFNode,
PRUint32 yourChildRDFNode);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mNativeRDFNode;
PRUint32 mChildRDFNode;
};
class wsRDFToStringEvent : public nsActionEvent {
public:
wsRDFToStringEvent(WebShellInitContext *yourInitContext,
PRUint32 yourNativeRDFNode);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mNativeRDFNode;
};
class wsRDFInsertElementAtEvent : public nsActionEvent {
public:
wsRDFInsertElementAtEvent(WebShellInitContext *yourInitContext,
PRUint32 yourParentRDFNode,
PRUint32 yourChildRDFNode,
PRUint32 yourChildIndex);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mParentRDFNode;
PRUint32 mChildRDFNode;
PRUint32 mChildIndex;
};
class wsRDFHasMoreElementsEvent : public nsActionEvent {
public:
wsRDFHasMoreElementsEvent(WebShellInitContext *yourInitContext,
PRUint32 mNativeRDFNode,
void *yourJobject);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mNativeRDFNode;
void *mJobject;
};
class wsRDFNextElementEvent : public nsActionEvent {
public:
wsRDFNextElementEvent(WebShellInitContext *yourInitContext,
PRUint32 mNativeRDFNode,
void *yourJobject);
void * handleEvent(void);
protected:
WebShellInitContext *mInitContext;
PRUint32 mNativeRDFNode;
void *mJobject;
};
class wsRDFFinalizeEvent : public nsActionEvent {
public:
wsRDFFinalizeEvent(void *yourJobject);
void * handleEvent(void);
protected:
void *mJobject;
};
#endif /* nsActions_h___ */