mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Ok after this checkin we now have all the functionality of Sun's JDIC
WebBrowser <https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/jdic/browser/WebBrowser.html>, with the following exceptions: - we're based on mozilla 1.6 - it only works on windows - we don't have mouse event support - we only support mozilla, not IE So, webclient still has a ways to go until we reach its former glory. However, I'm going to get together a 2.0 alpha release, including build instructions, from what we have now. I'd love it if someone could get the unit tests working on GNU/Linux again. I think the problem has to do with our old friend GDKSUPERWIN. M webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java M webclient/src_moz/NavigationImpl.cpp - re-enable POST M webclient/src_moz/EmbedWindow.cpp M webclient/src_moz/EmbedWindow.h - expose DocShell post method. M webclient/test/automated/src/classes/org/mozilla/util/THTTPD.java M webclient/test/automated/src/classes/org/mozilla/webclient/NavigationTest.java - test code for POST
This commit is contained in:
parent
22fe703b59
commit
7bb66a6538
@ -166,17 +166,21 @@ public void setPrompt(Prompt yourPrompt)
|
||||
// Methods from Navigation2
|
||||
//
|
||||
|
||||
public void post(String absoluteUrl,
|
||||
String target,
|
||||
String postData,
|
||||
String postHeaders)
|
||||
public void post(String argUrl,
|
||||
String argTarget,
|
||||
String argPostData,
|
||||
String argPostHeaders)
|
||||
{
|
||||
ParameterCheck.nonNull(absoluteUrl);
|
||||
ParameterCheck.nonNull(argUrl);
|
||||
getWrapperFactory().verifyInitialized();
|
||||
Assert.assert_it(-1 != getNativeBrowserControl());
|
||||
|
||||
int postDataLength = 0;
|
||||
int postHeadersLength = 0;
|
||||
final String url = new String(argUrl);
|
||||
final String target = argTarget;
|
||||
final String postData = argPostData;
|
||||
final String postHeaders = argPostHeaders;
|
||||
final int postDataLength;
|
||||
final int postHeadersLength;
|
||||
|
||||
// PENDING(edburns): make it so the url doesn't have to be absolute.
|
||||
|
||||
@ -184,22 +188,30 @@ public void post(String absoluteUrl,
|
||||
// "\r\n" as specified in Navigation.java
|
||||
|
||||
if (postData != null){
|
||||
postDataLength = postData.length();
|
||||
postDataLength = postData.length();
|
||||
}
|
||||
|
||||
else {
|
||||
postDataLength = 0;
|
||||
}
|
||||
|
||||
if (postHeaders != null){
|
||||
postHeadersLength = postHeaders.length();
|
||||
postHeadersLength = postHeaders.length();
|
||||
}
|
||||
else {
|
||||
postHeadersLength = 0;
|
||||
}
|
||||
|
||||
synchronized(getBrowserControl()) {
|
||||
nativePost(getNativeBrowserControl(),
|
||||
absoluteUrl,
|
||||
target,
|
||||
postDataLength,
|
||||
postData,
|
||||
postHeadersLength,
|
||||
postHeaders);
|
||||
}
|
||||
NativeEventThread.instance.pushRunnable(new Runnable() {
|
||||
public void run() {
|
||||
nativePost(NavigationImpl.this.getNativeBrowserControl(),
|
||||
url,
|
||||
target,
|
||||
postDataLength,
|
||||
postData,
|
||||
postHeadersLength,
|
||||
postHeaders);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
@ -241,7 +253,7 @@ public static void main(String [] args)
|
||||
|
||||
Log.setApplicationName("NavigationImpl");
|
||||
Log.setApplicationVersion("0.0");
|
||||
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.10 2004/06/23 17:08:14 edburns%acm.org Exp $");
|
||||
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.11 2004/06/24 16:23:42 edburns%acm.org Exp $");
|
||||
|
||||
try {
|
||||
org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]);
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIDocShellLoadInfo.h"
|
||||
|
||||
#include "nsNetUtil.h" // for NS_NewPostDataStream
|
||||
|
||||
#include "NativeBrowserControl.h"
|
||||
#include "EmbedWindow.h"
|
||||
@ -284,6 +284,67 @@ EmbedWindow::LoadStream(nsIInputStream *aStream, nsIURI * aURI,
|
||||
aLoadInfo);
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedWindow::Post(nsIURI *absoluteURL,
|
||||
const PRUnichar *target,
|
||||
PRInt32 targetLength,
|
||||
PRInt32 postDataLength,
|
||||
const char *postData,
|
||||
PRInt32 postHeadersLength,
|
||||
const char *postHeaders)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mWebBrowser);
|
||||
nsCOMPtr<nsIDocShellLoadInfo> docShellLoadInfo = nsnull;
|
||||
if (!docShell) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = docShell->CreateLoadInfo(getter_AddRefs(docShellLoadInfo));
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
docShellLoadInfo->SetReferrer(absoluteURL);
|
||||
docShellLoadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);
|
||||
docShellLoadInfo->SetInheritOwner(PR_TRUE);
|
||||
docShellLoadInfo->SetTarget(target);
|
||||
|
||||
// create the streams
|
||||
nsCOMPtr<nsIInputStream> postDataStream = nsnull;
|
||||
nsCOMPtr<nsIInputStream> headersDataStream = nsnull;
|
||||
nsCOMPtr<nsIInputStream> inputStream = nsnull;
|
||||
|
||||
if (postData) {
|
||||
nsCAutoString postDataStr(postData);
|
||||
NS_NewPostDataStream(getter_AddRefs(postDataStream),
|
||||
PR_FALSE,
|
||||
postDataStr, 0);
|
||||
}
|
||||
|
||||
if (postHeaders) {
|
||||
NS_NewByteInputStream(getter_AddRefs(inputStream),
|
||||
postHeaders, postHeadersLength);
|
||||
if (inputStream) {
|
||||
headersDataStream = do_QueryInterface(inputStream, &rv);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
docShellLoadInfo->SetPostDataStream(postDataStream);
|
||||
docShellLoadInfo->SetHeadersStream(headersDataStream);
|
||||
|
||||
rv = docShell->LoadURI(absoluteURL, docShellLoadInfo,
|
||||
nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedWindow::AddWebBrowserListener(nsIWeakReference *aListener,
|
||||
const nsIID & aIID)
|
||||
|
@ -73,6 +73,15 @@ public:
|
||||
const nsACString &aContentCharset,
|
||||
nsIDocShellLoadInfo * aLoadInfo);
|
||||
|
||||
nsresult Post (nsIURI *absoluteURL,
|
||||
const PRUnichar *target,
|
||||
PRInt32 targetLength,
|
||||
PRInt32 postDataLength,
|
||||
const char *postData,
|
||||
PRInt32 postHeadersLength,
|
||||
const char *postHeaders);
|
||||
|
||||
|
||||
nsresult AddWebBrowserListener(nsIWeakReference *aListener,
|
||||
const nsIID & aIID);
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include "NativeBrowserControl.h"
|
||||
#include "NavigationActionEvents.h"
|
||||
#include "EmbedWindow.h"
|
||||
#include "ns_util.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativeLoadURL
|
||||
@ -150,10 +151,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
|
||||
// wsLoadFromStreamEvent destructor.
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativePost
|
||||
(JNIEnv *env, jobject obj, jint nativeBCPtr, jstring absoluteURL, jstring target, jint postDataLength,
|
||||
jstring postData, jint postHeadersLength, jstring postHeaders)
|
||||
@ -166,30 +163,30 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
|
||||
const char *postDataChars = nsnull;
|
||||
const char *postHeadersChars = nsnull;
|
||||
char *headersAndData = nsnull;
|
||||
wsPostEvent *actionEvent = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID,
|
||||
&rv);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_ConvertUCS2toUTF8 uriACString(urlChars);
|
||||
|
||||
if (!ioService || NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nativeBrowserControl == nsnull || !nativeBrowserControl->initComplete) {
|
||||
if (nativeBrowserControl == nsnull) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativePost");
|
||||
return;
|
||||
}
|
||||
|
||||
urlChars = (PRUnichar *) ::util_GetStringChars(env, absoluteURL);
|
||||
urlLen = (PRInt32) ::util_GetStringLength(env, absoluteURL);
|
||||
NS_ConvertUCS2toUTF8 uriACString(urlChars);
|
||||
|
||||
if (::util_ExceptionOccurred(env)) {
|
||||
::util_ThrowExceptionToJava(env, "nativePost Exception: unable to extract Java string");
|
||||
goto NPFS_CLEANUP;
|
||||
}
|
||||
|
||||
|
||||
if (target){
|
||||
targetChars = (PRUnichar *) ::util_GetStringChars(env, target);
|
||||
targetLen = (PRInt32) ::util_GetStringLength(env, target);
|
||||
@ -242,23 +239,17 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
|
||||
goto NPFS_CLEANUP;
|
||||
}
|
||||
|
||||
|
||||
if (!(actionEvent = new wsPostEvent(nativeBrowserControl,
|
||||
uri,
|
||||
targetChars,
|
||||
targetLen,
|
||||
(PRInt32) postDataLength,
|
||||
headersAndData ? headersAndData : postDataChars,
|
||||
(PRInt32) postHeadersLength,
|
||||
postHeadersChars))) {
|
||||
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativePost: can't create wsPostEvent");
|
||||
goto NPFS_CLEANUP;
|
||||
}
|
||||
|
||||
::util_PostSynchronousEvent(nativeBrowserControl, (PLEvent *) *actionEvent);
|
||||
|
||||
rv = nativeBrowserControl->mWindow->Post(uri,
|
||||
targetChars,
|
||||
targetLen,
|
||||
(PRInt32) postDataLength,
|
||||
headersAndData ? headersAndData : postDataChars,
|
||||
(PRInt32) postHeadersLength,
|
||||
postHeadersChars);
|
||||
|
||||
NPFS_CLEANUP:
|
||||
|
||||
if (urlChars != nsnull)
|
||||
::util_ReleaseStringChars(env, absoluteURL, (const jchar *) urlChars);
|
||||
if (targetChars != nsnull)
|
||||
@ -271,7 +262,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
|
||||
delete [] headersAndData;
|
||||
return;
|
||||
}
|
||||
*********************/
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativeRefresh
|
||||
(JNIEnv *env, jobject obj, jint nativeBCPtr, jlong loadFlags)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: THTTPD.java,v 1.3 2004/06/23 19:21:06 edburns%acm.org Exp $
|
||||
* $Id: THTTPD.java,v 1.4 2004/06/24 16:23:42 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -31,6 +31,7 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@ -51,7 +52,9 @@ public class THTTPD extends Object {
|
||||
protected int count = 0;
|
||||
|
||||
public final static int REQUEST_GET = 2;
|
||||
public final static int REQUEST_POST = 2;
|
||||
public final static int REQUEST_POST = 3;
|
||||
|
||||
protected StringBuffer requestData = null;
|
||||
|
||||
public ServerThread(String name, File root,
|
||||
int maxRequests) {
|
||||
@ -59,6 +62,17 @@ public class THTTPD extends Object {
|
||||
this.root = root;
|
||||
this.maxRequests = maxRequests;
|
||||
keepRunning = true;
|
||||
requestData = new StringBuffer();
|
||||
}
|
||||
|
||||
public String getRequestData() {
|
||||
String result = null;
|
||||
if (null != requestData) {
|
||||
synchronized (requestData) {
|
||||
result = requestData.toString();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected int soTimeout = -1;
|
||||
@ -81,13 +95,15 @@ public class THTTPD extends Object {
|
||||
BufferedReader
|
||||
responseReader = null,
|
||||
requestReader = null;
|
||||
InputStream socketInputStream = null;
|
||||
BufferedWriter
|
||||
responseWriter = null;
|
||||
String
|
||||
requestLine = null,
|
||||
curLine = null;
|
||||
File responseFile = null;
|
||||
StringBuffer responseString = null;
|
||||
StringBuffer
|
||||
responseString = null;
|
||||
|
||||
V();
|
||||
|
||||
@ -104,16 +120,30 @@ public class THTTPD extends Object {
|
||||
serverSocket.setSoTimeout(getSoTimeout());
|
||||
}
|
||||
socket = serverSocket.accept();
|
||||
requestReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
requestReader = new BufferedReader(new InputStreamReader(socketInputStream = socket.getInputStream()));
|
||||
requestLine = requestReader.readLine();
|
||||
|
||||
while (null != (curLine = requestReader.readLine())) {
|
||||
if (curLine.trim().length() == 0) {
|
||||
break;
|
||||
synchronized (requestData) {
|
||||
requestData.delete(0, requestData.length());
|
||||
requestData.append(requestLine);
|
||||
while (null != (curLine = requestReader.readLine())) {
|
||||
requestData.append(curLine);
|
||||
if (curLine.trim().length() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (getRequestMethod(requestLine)) {
|
||||
case REQUEST_POST:
|
||||
while (null != (curLine = requestReader.readLine())) {
|
||||
requestData.append(curLine);
|
||||
if (socketInputStream.available() <= 0 ||
|
||||
curLine.trim().length() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// intentional fall through!
|
||||
case REQUEST_GET:
|
||||
responseWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||
if (null !=
|
||||
@ -154,6 +184,12 @@ public class THTTPD extends Object {
|
||||
|
||||
protected int getRequestMethod(String requestLine) {
|
||||
int result = REQUEST_GET;
|
||||
if (0 == requestLine.indexOf("GET")) {
|
||||
result = REQUEST_GET;
|
||||
}
|
||||
else if (0 == requestLine.indexOf("POST")) {
|
||||
result = REQUEST_POST;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: NavigationTest.java,v 1.17 2004/06/23 19:21:06 edburns%acm.org Exp $
|
||||
* $Id: NavigationTest.java,v 1.18 2004/06/24 16:23:42 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
@ -389,4 +389,65 @@ public class NavigationTest extends WebclientTestCase {
|
||||
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
|
||||
}
|
||||
|
||||
public void testHttpPost() throws Exception {
|
||||
BrowserControl firstBrowserControl = null;
|
||||
DocumentLoadListenerImpl listener = null;
|
||||
Selection selection = null;
|
||||
firstBrowserControl = BrowserControlFactory.newBrowserControl();
|
||||
assertNotNull(firstBrowserControl);
|
||||
BrowserControlCanvas canvas = (BrowserControlCanvas)
|
||||
firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME);
|
||||
eventRegistration = (EventRegistration2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME);
|
||||
|
||||
assertNotNull(canvas);
|
||||
Frame frame = new Frame();
|
||||
frame.setUndecorated(true);
|
||||
frame.setBounds(0, 0, 640, 480);
|
||||
frame.add(canvas, BorderLayout.CENTER);
|
||||
frame.setVisible(true);
|
||||
canvas.setVisible(true);
|
||||
|
||||
Navigation2 nav = (Navigation2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
|
||||
assertNotNull(nav);
|
||||
final CurrentPage2 currentPage = (CurrentPage2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
|
||||
assertNotNull(currentPage);
|
||||
|
||||
//
|
||||
// try loading a file over HTTP
|
||||
//
|
||||
|
||||
NavigationTest.keepWaiting = true;
|
||||
|
||||
|
||||
eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() {
|
||||
public void doEndCheck() {
|
||||
currentPage.selectAll();
|
||||
Selection selection = currentPage.getSelection();
|
||||
NavigationTest.keepWaiting = false;
|
||||
assertTrue(-1 != selection.toString().indexOf("This file was downloaded over HTTP."));
|
||||
System.out.println("Selection is: " +
|
||||
selection.toString());
|
||||
}
|
||||
});
|
||||
|
||||
String url = "http://localhost:5243/HttpNavigationTest.txt";
|
||||
|
||||
Thread.currentThread().sleep(3000);
|
||||
|
||||
nav.post(url, null, "PostData\r\n", "X-WakaWaka: true\r\n\r\n");
|
||||
|
||||
// keep waiting until the previous load completes
|
||||
while (NavigationTest.keepWaiting) {
|
||||
Thread.currentThread().sleep(1000);
|
||||
}
|
||||
eventRegistration.removeDocumentLoadListener(listener);
|
||||
|
||||
frame.setVisible(false);
|
||||
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user