M dom/jni/javaDOMEventsGlobals.cpp\
- fix bug where eventType was incorrectly getting accessed as a const char * M webclient/src_moz/AjaxListener.cpp - Create a Java DOM instance from the Ajax response. M webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java - Resurrect the DOMViewer. Make it show the tree for ajax responses. git-svn-id: svn://10.0.0.236/trunk@221545 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "nsIXMLHTTPRequest.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
#include "NativeBrowserControl.h"
|
||||
#include "NativeWrapperFactory.h"
|
||||
@@ -214,6 +215,11 @@ AjaxListener::ObserveAjax(nsIRequest *request,
|
||||
PRInt32 readyState = 0;
|
||||
char buf[20];
|
||||
jstring jStr = nsnull;
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
jlong documentLong = nsnull;
|
||||
jclass clazz = nsnull;
|
||||
jmethodID mid = nsnull;
|
||||
jobject javaDOMDocument;
|
||||
|
||||
browserControl->ContentStateChange();
|
||||
|
||||
@@ -300,6 +306,38 @@ AjaxListener::ObserveAjax(nsIRequest *request,
|
||||
(jobject) pShareContext);
|
||||
|
||||
}
|
||||
|
||||
// store the response xml
|
||||
if (NS_SUCCEEDED(rv=ajax->GetResponseXML(getter_AddRefs(domDocument)))){
|
||||
documentLong = (jlong) domDocument.get();
|
||||
|
||||
if (nsnull == (clazz =
|
||||
::util_FindClass(mJNIEnv,
|
||||
"org/mozilla/dom/DOMAccessor"))) {
|
||||
::util_ThrowExceptionToJava(mJNIEnv, "Exception: Can't get DOMAccessor class");
|
||||
return nsnull;
|
||||
}
|
||||
if (nsnull==(mid =
|
||||
mJNIEnv->GetStaticMethodID(clazz, "getNodeByHandle",
|
||||
"(J)Lorg/w3c/dom/Node;"))){
|
||||
::util_ThrowExceptionToJava(mJNIEnv, "Exception: Can't get DOM Node.");
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
javaDOMDocument = (jobject)
|
||||
util_CallStaticObjectMethodlongArg(mJNIEnv,
|
||||
clazz, mid,
|
||||
documentLong);
|
||||
javaDOMDocument = ::util_NewGlobalRef(mJNIEnv, javaDOMDocument);
|
||||
if (nsnull != javaDOMDocument) {
|
||||
::util_StoreIntoPropertiesObject(mJNIEnv, properties,
|
||||
RESPONSE_XML_KEY,
|
||||
javaDOMDocument,
|
||||
(jobject) pShareContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DOCUMENT_LOADER_EVENT_MASK_NAMES maskValue = END_AJAX_EVENT_MASK;
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
@@ -74,6 +75,7 @@ public class TestBrowser extends JPanel {
|
||||
JButton jBackButton = new JButton("Back",
|
||||
new ImageIcon(getClass().getResource("images/Back.png")));
|
||||
JButton jCopyButton = new JButton("Copy");
|
||||
JButton jDOMButton = new JButton("Show DOM");
|
||||
|
||||
JPanel jAddressPanel = new JPanel();
|
||||
JLabel jAddressLabel = new JLabel();
|
||||
@@ -163,6 +165,12 @@ public class TestBrowser extends JPanel {
|
||||
jCopyButton.setMaximumSize(new Dimension(75, 27));
|
||||
jCopyButton.setPreferredSize(new Dimension(75, 27));
|
||||
jCopyButton.addActionListener(new TestBrowser_jCopyButton_actionAdapter(this));
|
||||
|
||||
jDOMButton.setToolTipText("Copy current selection");
|
||||
jDOMButton.setHorizontalTextPosition(SwingConstants.TRAILING);
|
||||
jDOMButton.setMaximumSize(new Dimension(75, 27));
|
||||
jDOMButton.setPreferredSize(new Dimension(75, 27));
|
||||
jDOMButton.addActionListener(new TestBrowser_jDOMButton_actionAdapter(this));
|
||||
|
||||
jForwardButton.setToolTipText("Go forward one page");
|
||||
jForwardButton.setEnabled(false);
|
||||
@@ -204,6 +212,8 @@ public class TestBrowser extends JPanel {
|
||||
jBrowserToolBar.add(jStopButton, null);
|
||||
jBrowserToolBar.add(jViewSourceButton, null);
|
||||
jBrowserToolBar.add(jCopyButton, null);
|
||||
jBrowserToolBar.add(jDOMButton, null);
|
||||
|
||||
jBrowserToolBar.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createEtchedBorder(),
|
||||
BorderFactory.createEmptyBorder(2, 2, 2, 0)));
|
||||
@@ -246,6 +256,11 @@ public class TestBrowser extends JPanel {
|
||||
map.get("status"));
|
||||
System.out.println("responseText: " +
|
||||
map.get("responseText"));
|
||||
Document responseDOM = (Document) map.get("responseXML");
|
||||
if (null != responseDOM) {
|
||||
DOMViewerFrame domViewer = getDOMViewerFrame();
|
||||
domViewer.setDocument(responseDOM);
|
||||
}
|
||||
// INTENTIONAL FALL THROUGH
|
||||
case ((int) DocumentLoadEvent.START_AJAX_EVENT_MASK):
|
||||
System.out.println("requestMethod: " +
|
||||
@@ -468,6 +483,21 @@ public class TestBrowser extends JPanel {
|
||||
currentPage.copyCurrentSelectionToSystemClipboard();
|
||||
}
|
||||
|
||||
void jDOMButton_actionPerformed(ActionEvent e) {
|
||||
Document doc = currentPage.getDOM();
|
||||
DOMViewerFrame viewer = getDOMViewerFrame();
|
||||
viewer.setDocument(doc);
|
||||
viewer.setVisible(true);
|
||||
}
|
||||
|
||||
private DOMViewerFrame getDOMViewerFrame() {
|
||||
if (null == domViewer) {
|
||||
domViewer = new DOMViewerFrame("DOM Viewer", this);
|
||||
domViewer.setSize(new Dimension(300, 600));
|
||||
domViewer.setLocation(645, 0);
|
||||
}
|
||||
return domViewer;
|
||||
}
|
||||
|
||||
void jForwardButton_actionPerformed(ActionEvent e) {
|
||||
history.forward();
|
||||
@@ -487,18 +517,7 @@ public class TestBrowser extends JPanel {
|
||||
System.out.println(source);
|
||||
/*****
|
||||
if (null != doc) {
|
||||
Document doc = currentPage.getDOM();
|
||||
currentPage.selectAll();
|
||||
Selection selection = currentPage.getSelection();
|
||||
System.out.println(selection.toString());
|
||||
|
||||
if (null == domViewer) {
|
||||
domViewer = new DOMViewerFrame("DOM Viewer", this);
|
||||
domViewer.setSize(new Dimension(300, 600));
|
||||
domViewer.setLocation(645, 0);
|
||||
}
|
||||
domViewer.setDocument(doc);
|
||||
domViewer.setVisible(true);
|
||||
|
||||
}
|
||||
******/
|
||||
}
|
||||
@@ -547,6 +566,17 @@ class TestBrowser_jCopyButton_actionAdapter implements java.awt.event.ActionList
|
||||
}
|
||||
}
|
||||
|
||||
class TestBrowser_jDOMButton_actionAdapter implements java.awt.event.ActionListener {
|
||||
TestBrowser adaptee;
|
||||
|
||||
TestBrowser_jDOMButton_actionAdapter(TestBrowser adaptee) {
|
||||
this.adaptee = adaptee;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
adaptee.jDOMButton_actionPerformed(e);
|
||||
}
|
||||
}
|
||||
|
||||
class TestBrowser_jForwardButton_actionAdapter implements java.awt.event.ActionListener {
|
||||
TestBrowser adaptee;
|
||||
|
||||
Reference in New Issue
Block a user