зеркало из https://github.com/mozilla/pjs.git
This checkin enables Navigation.stop() to work.
I'm working towards getting equivalent functionality to <https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/jdic/browser/WebBrowser.html> working by JavaOne SF 2004. At this point, all that remains are refresh(), back(), forward(), and post(). All but post() are trivial. M classes_spec/org/mozilla/webclient/Navigation2.java - remove "blocking" methods since we don't need them now that we have DocumentLoadListener working again. M classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java - remove "blocking" methods since we don't need them now that we have DocumentLoadListener working again. - implement stop(). M classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java - throw IllegalStateException if you try to get a BrowserControl instance after appTerminate() has been called. - throw IllegalStateException if appTerminate() is called more than once. M src_moz/NavigationImpl.cpp - call through to stop M test/automated/src/classes/org/mozilla/webclient/NavigationTest.java - test first test for stop.
This commit is contained in:
Родитель
ad838066be
Коммит
529b8262f9
|
@ -52,13 +52,5 @@ public void post(String absoluteUrl,
|
|||
String target,
|
||||
String postData,
|
||||
String postHeaders);
|
||||
|
||||
public void loadURLBlocking(String absoluteURL);
|
||||
|
||||
public void loadFromStreamBlocking(InputStream stream, String uri,
|
||||
String contentType, int contentLength,
|
||||
Properties loadInfo);
|
||||
|
||||
|
||||
}
|
||||
// end of interface Navigation2
|
||||
|
|
|
@ -92,22 +92,6 @@ public void loadURL(String absoluteURL)
|
|||
});
|
||||
}
|
||||
|
||||
public void loadURLBlocking(String absoluteURL) {
|
||||
ParameterCheck.nonNull(absoluteURL);
|
||||
getWrapperFactory().verifyInitialized();
|
||||
final int bc = getNativeBrowserControl();
|
||||
final String url = new String(absoluteURL);
|
||||
Assert.assert_it(-1 != bc);
|
||||
|
||||
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
|
||||
public Object run() {
|
||||
NavigationImpl.this.nativeLoadURL(bc, url);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void loadFromStream(InputStream stream, String uri,
|
||||
String contentType, int contentLength,
|
||||
Properties loadInfo) {
|
||||
|
@ -135,34 +119,6 @@ public void loadURL(String absoluteURL)
|
|||
});
|
||||
}
|
||||
|
||||
public void loadFromStreamBlocking(InputStream stream, String uri,
|
||||
String contentType, int contentLength,
|
||||
Properties loadInfo) {
|
||||
ParameterCheck.nonNull(stream);
|
||||
ParameterCheck.nonNull(uri);
|
||||
ParameterCheck.nonNull(contentType);
|
||||
if (contentLength < -1 || contentLength == 0) {
|
||||
throw new RangeException("contentLength value " + contentLength +
|
||||
" is out of range. It is should be either -1 or greater than 0.");
|
||||
}
|
||||
|
||||
final InputStream finalStream = stream;
|
||||
final String finalUri = uri;
|
||||
final String finalContentType = contentType;
|
||||
final int finalContentLength = contentLength;
|
||||
final Properties finalLoadInfo = loadInfo;
|
||||
|
||||
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
|
||||
public Object run() {
|
||||
nativeLoadFromStream(NavigationImpl.this.getNativeBrowserControl(),
|
||||
finalStream, finalUri,
|
||||
finalContentType,
|
||||
finalContentLength, finalLoadInfo);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void refresh(long loadFlags)
|
||||
{
|
||||
ParameterCheck.noLessThan(loadFlags, 0);
|
||||
|
@ -179,9 +135,13 @@ public void stop()
|
|||
getWrapperFactory().verifyInitialized();
|
||||
Assert.assert_it(-1 != getNativeBrowserControl());
|
||||
|
||||
synchronized(getBrowserControl()) {
|
||||
nativeStop(getNativeBrowserControl());
|
||||
}
|
||||
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
|
||||
public Object run() {
|
||||
nativeStop(getNativeBrowserControl());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void setPrompt(Prompt yourPrompt)
|
||||
|
@ -275,7 +235,7 @@ public static void main(String [] args)
|
|||
|
||||
Log.setApplicationName("NavigationImpl");
|
||||
Log.setApplicationVersion("0.0");
|
||||
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.8 2004-06-02 14:31:23 edburns%acm.org Exp $");
|
||||
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.9 2004-06-16 14:37:33 edburns%acm.org Exp $");
|
||||
|
||||
try {
|
||||
org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]);
|
||||
|
|
|
@ -86,6 +86,7 @@ public class WrapperFactoryImpl extends Object implements WrapperFactory {
|
|||
|
||||
protected String platformCanvasClassName = null;
|
||||
protected boolean initialized = false;
|
||||
protected boolean terminated = false;
|
||||
|
||||
|
||||
// Relationship Instance Variables
|
||||
|
@ -136,6 +137,10 @@ public class WrapperFactoryImpl extends Object implements WrapperFactory {
|
|||
|
||||
public BrowserControl newBrowserControl() throws InstantiationException, IllegalAccessException, IllegalStateException {
|
||||
verifyInitialized();
|
||||
|
||||
if (terminated) {
|
||||
throw new IllegalStateException("Already terminated");
|
||||
}
|
||||
|
||||
BrowserControl result = new BrowserControlImpl(this);
|
||||
final int nativeBrowserControl = nativeCreateBrowserControl();
|
||||
|
@ -333,6 +338,10 @@ public class WrapperFactoryImpl extends Object implements WrapperFactory {
|
|||
|
||||
public void terminate() throws Exception
|
||||
{
|
||||
if (terminated) {
|
||||
throw new IllegalStateException("Already terminated");
|
||||
}
|
||||
|
||||
eventThread.pushBlockingWCRunnable(new WCRunnable() {
|
||||
public Object run() {
|
||||
Assert.assert_it(null != bookmarks);
|
||||
|
@ -350,6 +359,7 @@ public void terminate() throws Exception
|
|||
((ImplObject)profileManager).delete();
|
||||
profileManager = null;
|
||||
nativeTerminate(nativeWrapperFactory);
|
||||
WrapperFactoryImpl.this.terminated = true;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativeLoadURL
|
||||
(JNIEnv *env, jobject obj, jint nativeBCPtr, jstring urlString)
|
||||
{
|
||||
jobject jobj = obj;
|
||||
|
||||
#if DEBUG_RAPTOR_CANVAS
|
||||
const char * urlChars = (char *) ::util_GetStringUTFChars(env,
|
||||
urlString);
|
||||
|
@ -299,27 +297,27 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
|
|||
return;
|
||||
}
|
||||
|
||||
*********************/
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativeStop
|
||||
(JNIEnv *env, jobject obj, jint nativeBCPtr)
|
||||
{
|
||||
JNIEnv * pEnv = env;
|
||||
jobject jobj = obj;
|
||||
|
||||
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
|
||||
|
||||
if (nativeBrowserControl == nsnull) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellStop");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nativeBrowserControl->initComplete) {
|
||||
wsStopEvent * actionEvent = new wsStopEvent(nativeBrowserControl->webNavigation);
|
||||
PLEvent * event = (PLEvent*) *actionEvent;
|
||||
|
||||
::util_PostEvent(nativeBrowserControl, event);
|
||||
}
|
||||
|
||||
if (nativeBrowserControl == nsnull) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: null passed to nativeLoadURL");
|
||||
return;
|
||||
}
|
||||
|
||||
nsresult rv =
|
||||
nativeBrowserControl->mNavigation->Stop(nsIWebNavigation::STOP_ALL);
|
||||
if (NS_FAILED(rv)) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: Can't stop load");
|
||||
}
|
||||
}
|
||||
|
||||
/***********************
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativeSetPrompt
|
||||
(JNIEnv *env, jobject obj, jint nativeBCPtr, jobject userPrompt)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Id: NavigationTest.java,v 1.12 2004-06-14 15:34:42 edburns%acm.org Exp $
|
||||
* $Id: NavigationTest.java,v 1.13 2004-06-16 14:37:34 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
|
@ -27,6 +27,7 @@
|
|||
package org.mozilla.webclient;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import junit.framework.TestResult;
|
||||
import junit.framework.Test;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
@ -42,11 +43,29 @@ import java.io.FileInputStream;
|
|||
public class NavigationTest extends WebclientTestCase {
|
||||
|
||||
public NavigationTest(String name) {
|
||||
super(name);
|
||||
super(name);
|
||||
try {
|
||||
BrowserControlFactory.setAppData(getBrowserBinDir());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return (new TestSuite(NavigationTest.class));
|
||||
TestSuite result = new TestSuite() {
|
||||
public void run(TestResult result) {
|
||||
super.run(result);
|
||||
try {
|
||||
BrowserControlFactory.appTerminate();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
};
|
||||
result.addTestSuite(NavigationTest.class);
|
||||
return (result);
|
||||
}
|
||||
|
||||
static EventRegistration2 eventRegistration;
|
||||
|
@ -61,11 +80,12 @@ public class NavigationTest extends WebclientTestCase {
|
|||
// Testcases
|
||||
//
|
||||
|
||||
public void testNavigation() throws Exception {
|
||||
/*************
|
||||
|
||||
public void testLoad() throws Exception {
|
||||
BrowserControl firstBrowserControl = null;
|
||||
EndDocumentSelectionVerifier listener = null;
|
||||
DocumentListener listener = null;
|
||||
Selection selection = null;
|
||||
BrowserControlFactory.setAppData(getBrowserBinDir());
|
||||
firstBrowserControl = BrowserControlFactory.newBrowserControl();
|
||||
assertNotNull(firstBrowserControl);
|
||||
BrowserControlCanvas canvas = (BrowserControlCanvas)
|
||||
|
@ -99,7 +119,7 @@ public class NavigationTest extends WebclientTestCase {
|
|||
NavigationTest.keepWaiting = true;
|
||||
|
||||
System.out.println("Loading url: " + testPage.toURL().toString());
|
||||
eventRegistration.addDocumentLoadListener(listener = new EndDocumentSelectionVerifier() {
|
||||
eventRegistration.addDocumentLoadListener(listener = new DocumentListener() {
|
||||
public void doEndCheck() {
|
||||
currentPage.selectAll();
|
||||
Selection selection = currentPage.getSelection();
|
||||
|
@ -123,7 +143,7 @@ public class NavigationTest extends WebclientTestCase {
|
|||
//
|
||||
RandomHTMLInputStream rhis = new RandomHTMLInputStream(10, false);
|
||||
|
||||
eventRegistration.addDocumentLoadListener(listener = new EndDocumentSelectionVerifier() {
|
||||
eventRegistration.addDocumentLoadListener(listener = new DocumentListener() {
|
||||
public void doEndCheck() {
|
||||
currentPage.selectAll();
|
||||
Selection selection = currentPage.getSelection();
|
||||
|
@ -148,7 +168,7 @@ public class NavigationTest extends WebclientTestCase {
|
|||
NavigationTest.keepWaiting = true;
|
||||
|
||||
FileInputStream fis = new FileInputStream(testPage);
|
||||
eventRegistration.addDocumentLoadListener(listener = new EndDocumentSelectionVerifier() {
|
||||
eventRegistration.addDocumentLoadListener(listener = new DocumentListener() {
|
||||
public void doEndCheck() {
|
||||
currentPage.selectAll();
|
||||
Selection selection = currentPage.getSelection();
|
||||
|
@ -168,10 +188,69 @@ public class NavigationTest extends WebclientTestCase {
|
|||
|
||||
frame.setVisible(false);
|
||||
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
|
||||
BrowserControlFactory.appTerminate();
|
||||
}
|
||||
|
||||
public static abstract class EndDocumentSelectionVerifier implements DocumentLoadListener {
|
||||
****************/
|
||||
|
||||
public void testStop() throws Exception {
|
||||
DocumentListener listener = null;
|
||||
BrowserControl 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);
|
||||
|
||||
final Navigation2 nav = (Navigation2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
|
||||
assertNotNull(nav);
|
||||
final CurrentPage2 currentPage = (CurrentPage2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
|
||||
NavigationTest.keepWaiting = true;
|
||||
//
|
||||
// try loading from the dreaded RandomHTMLInputStream
|
||||
//
|
||||
RandomHTMLInputStream rhis = new RandomHTMLInputStream(10, false);
|
||||
|
||||
eventRegistration.addDocumentLoadListener(listener = new DocumentListener() {
|
||||
private int progressCalls = 0;
|
||||
|
||||
public void doProgressCheck() {
|
||||
if (5 == ++progressCalls) {
|
||||
nav.stop();
|
||||
NavigationTest.keepWaiting = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
nav.loadFromStream(rhis, "http://randomstream.com/",
|
||||
"text/html", -1, null);
|
||||
|
||||
// keep waiting until the previous load completes
|
||||
while (NavigationTest.keepWaiting) {
|
||||
Thread.currentThread().sleep(1000);
|
||||
}
|
||||
eventRegistration.removeDocumentLoadListener(listener);
|
||||
|
||||
currentPage.selectAll();
|
||||
Selection selection = currentPage.getSelection();
|
||||
assertTrue(-1 != selection.toString().indexOf("START Random Data"));
|
||||
assertTrue(-1 == selection.toString().indexOf("END Random Data"));
|
||||
System.out.println("Selection is: " + selection.toString());
|
||||
|
||||
frame.setVisible(false);
|
||||
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
|
||||
}
|
||||
|
||||
public static abstract class DocumentListener implements DocumentLoadListener {
|
||||
|
||||
public void eventDispatched(WebclientEvent event) {
|
||||
if (event instanceof DocumentLoadEvent) {
|
||||
|
@ -179,11 +258,16 @@ public class NavigationTest extends WebclientTestCase {
|
|||
case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK):
|
||||
doEndCheck();
|
||||
break;
|
||||
case ((int) DocumentLoadEvent.PROGRESS_URL_LOAD_EVENT_MASK):
|
||||
doProgressCheck();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void doEndCheck();
|
||||
public void doEndCheck() {}
|
||||
|
||||
public void doProgressCheck() {}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче