This Change-bundle verifies that loadURL works as expected. Next will

be to verify that loadFromStream works as expected.

M build-tests.xml

- win32 gtk stuff.  I can't figure out why this file in particular gets
  messed up when I move from Unix to Windows and back.  Can anyone tell me
  why?

M classes_spec/org/mozilla/webclient/Navigation2.java
M classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java

- added method loadURLBlocking().

M classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java
M src_moz/CurrentPageImpl.cpp

- activated selectAll() and getSelection()

M src_moz/EmbedWindow.cpp
M src_moz/EmbedWindow.h

- imbued this class with selection related methods selectAll and
  getSelection()

M src_moz/Makefile.in

- activated CurrentPageImpl.cpp

M test/automated/src/classes/org/mozilla/webclient/NavigationTest.java

- new test content.
This commit is contained in:
edburns%acm.org 2004-04-28 14:39:54 +00:00
Родитель a7cd76fc77
Коммит 46bfb37763
11 изменённых файлов: 646 добавлений и 282 удалений

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

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

@ -50,5 +50,7 @@ public void post(String absoluteUrl,
String postData,
String postHeaders);
public void loadURLBlocking(String absoluteURL);
}
// end of interface Navigation2

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

@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -101,14 +100,17 @@ public void copyCurrentSelectionToSystemClipboard()
}
public Selection getSelection() {
Selection selection = new SelectionImpl();
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
synchronized(getBrowserControl()) {
nativeGetSelection(getNativeBrowserControl(), selection);
}
final Selection selection = new SelectionImpl();
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
public Object run() {
nativeGetSelection(CurrentPageImpl.this.getNativeBrowserControl(),
selection);
return null;
}
});
return selection;
}
@ -258,13 +260,15 @@ public void resetFind()
}
}
public void selectAll()
{
public void selectAll() {
getWrapperFactory().verifyInitialized();
synchronized(getBrowserControl()) {
nativeSelectAll(getNativeBrowserControl());
}
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
public Object run() {
nativeSelectAll(CurrentPageImpl.this.getNativeBrowserControl());
return null;
}
});
}
public void print()
@ -332,7 +336,7 @@ public static void main(String [] args)
Assert.setEnabled(true);
Log.setApplicationName("CurrentPageImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.3 2004-04-10 21:50:38 edburns%acm.org Exp $");
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.4 2004-04-28 14:39:54 edburns%acm.org Exp $");
}

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

@ -92,28 +92,77 @@ public void loadURL(String absoluteURL)
});
}
public void loadFromStream(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.");
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;
}
});
}
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
public void loadFromStream(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.pushRunnable(new Runnable() {
public void run() {
nativeLoadFromStream(NavigationImpl.this.getNativeBrowserControl(),
finalStream, finalUri,
finalContentType,
finalContentLength, finalLoadInfo);
}
});
}
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;
}
});
}
synchronized(getBrowserControl()) {
nativeLoadFromStream(getNativeBrowserControl(), stream,
uri, contentType, contentLength,
loadInfo);
}
}
public void refresh(long loadFlags)
{
ParameterCheck.noLessThan(loadFlags, 0);
@ -226,7 +275,7 @@ public static void main(String [] args)
Log.setApplicationName("NavigationImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.5 2004-04-17 21:25:11 edburns%acm.org Exp $");
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.6 2004-04-28 14:39:54 edburns%acm.org Exp $");
try {
org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]);

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

@ -32,84 +32,90 @@
#include "org_mozilla_webclient_impl_wrapper_0005fnative_CurrentPageImpl.h"
#include "CurrentPageActionEvents.h"
#include "ns_util.h"
#include "rdf_util.h"
#include "NativeBrowserControl.h"
#include "EmbedWindow.h"
#include "nsCRT.h"
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeCopyCurrentSelectionToSystemClipboard
(JNIEnv *env, jobject obj, jint webShellPtr)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
#if 0 // convenience
if (initContext->initComplete) {
wsCopySelectionEvent * actionEvent = new wsCopySelectionEvent(initContext);
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeCopyCurrentSelectionToSystemClipboard
(JNIEnv *env, jobject obj, jint nativeBCPtr)
{
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (nativeBrowserControl->initComplete) {
wsCopySelectionEvent * actionEvent = new wsCopySelectionEvent(nativeBrowserControl);
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostEvent(initContext, event);
::util_PostEvent(nativeBrowserControl, event);
}
}
#endif // if 0
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeGetSelection
(JNIEnv *env, jobject obj, jint webShellPtr, jobject selection)
(JNIEnv *env, jobject obj, jint nativeBCPtr, jobject selection)
{
NativeBrowserControl *initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl *nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed nativeGetSelection");
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed nativeGetSelection");
return;
}
PR_ASSERT(initContext->initComplete);
if (selection == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null Selection object passed to raptorWebShellGetSelection");
::util_ThrowExceptionToJava(env, "Exception: null Selection object passed to nativeGetSelection");
return;
}
nsresult rv = nativeBrowserControl->mWindow->GetSelection(env,
selection);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't get Selection from browser");
return;
}
wsGetSelectionEvent *actionEvent = new wsGetSelectionEvent(env, initContext, selection);
PLEvent *event = (PLEvent *) *actionEvent;
::util_PostSynchronousEvent(initContext, event);
}
#if 0 // convenience
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeHighlightSelection
(JNIEnv *env, jobject obj, jint webShellPtr, jobject startContainer, jobject endContainer, jint startOffset, jint endOffset)
(JNIEnv *env, jobject obj, jint nativeBCPtr, jobject startContainer, jobject endContainer, jint startOffset, jint endOffset)
{
NativeBrowserControl *initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl *nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeHighlightSelection");
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeHighlightSelection");
return;
}
PR_ASSERT(initContext->initComplete);
PR_ASSERT(nativeBrowserControl->initComplete);
wsHighlightSelectionEvent *actionEvent = new wsHighlightSelectionEvent(env, initContext, startContainer, endContainer, (PRInt32) startOffset, (PRInt32) endOffset);
wsHighlightSelectionEvent *actionEvent = new wsHighlightSelectionEvent(env, nativeBrowserControl, startContainer, endContainer, (PRInt32) startOffset, (PRInt32) endOffset);
PLEvent *event = (PLEvent *) *actionEvent;
::util_PostSynchronousEvent(initContext, event);
::util_PostSynchronousEvent(nativeBrowserControl, event);
}
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeClearAllSelections
(JNIEnv *env, jobject obj, jint webShellPtr)
(JNIEnv *env, jobject obj, jint nativeBCPtr)
{
NativeBrowserControl *initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl *nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeClearAllSelections");
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeClearAllSelections");
return;
}
PR_ASSERT(initContext->initComplete);
PR_ASSERT(nativeBrowserControl->initComplete);
wsClearAllSelectionEvent *actionEvent = new wsClearAllSelectionEvent(initContext);
wsClearAllSelectionEvent *actionEvent = new wsClearAllSelectionEvent(nativeBrowserControl);
PLEvent *event = (PLEvent *) *actionEvent;
::util_PostSynchronousEvent(initContext, event);
::util_PostSynchronousEvent(nativeBrowserControl, event);
}
/*
@ -118,24 +124,24 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
* Signature: (Ljava/lang/String;ZZ)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeFindInPage
(JNIEnv *env, jobject obj, jint webShellPtr, jstring searchString, jboolean forward, jboolean matchCase)
(JNIEnv *env, jobject obj, jint nativeBCPtr, jstring searchString, jboolean forward, jboolean matchCase)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
jstring searchStringGlobalRef = (jstring) ::util_NewGlobalRef(env, searchString);
if (!searchStringGlobalRef) {
initContext->initFailCode = kFindComponentError;
nativeBrowserControl->initFailCode = kFindComponentError;
::util_ThrowExceptionToJava(env, "Exception: Can't create global ref for search string");
return;
}
if (initContext->initComplete) {
wsFindEvent * actionEvent = new wsFindEvent(initContext, searchStringGlobalRef,
if (nativeBrowserControl->initComplete) {
wsFindEvent * actionEvent = new wsFindEvent(nativeBrowserControl, searchStringGlobalRef,
forward, matchCase);
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostEvent(initContext, event);
::util_PostEvent(nativeBrowserControl, event);
}
@ -149,18 +155,18 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
* Signature: (Z)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeFindNextInPage
(JNIEnv *env, jobject obj, jint webShellPtr)
(JNIEnv *env, jobject obj, jint nativeBCPtr)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
//First get the FindComponent object
PRBool found = PR_TRUE;
if (initContext->initComplete) {
wsFindEvent * actionEvent = new wsFindEvent(initContext);
if (nativeBrowserControl->initComplete) {
wsFindEvent * actionEvent = new wsFindEvent(nativeBrowserControl);
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostEvent(initContext, event);
::util_PostEvent(nativeBrowserControl, event);
}
}
@ -171,25 +177,25 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeGetCurrentURL
(JNIEnv *env, jobject obj, jint webShellPtr)
(JNIEnv *env, jobject obj, jint nativeBCPtr)
{
JNIEnv * pEnv = env;
jobject jobj = obj;
char * charResult = nsnull;
jstring urlString = nsnull;
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetURL");
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellGetURL");
return nsnull;
}
if (initContext->initComplete) {
wsGetURLEvent * actionEvent = new wsGetURLEvent(initContext);
if (nativeBrowserControl->initComplete) {
wsGetURLEvent * actionEvent = new wsGetURLEvent(nativeBrowserControl);
PLEvent * event = (PLEvent*) *actionEvent;
charResult = (char *) ::util_PostSynchronousEvent(initContext, event);
charResult = (char *) ::util_PostSynchronousEvent(nativeBrowserControl, event);
if (charResult != nsnull) {
urlString = ::util_NewStringUTF(env, (const char *) charResult);
@ -206,20 +212,20 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Curren
}
JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeGetDOM
(JNIEnv *env, jobject obj, jint webShellPtr)
(JNIEnv *env, jobject obj, jint nativeBCPtr)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
jobject result = nsnull;
jlong documentLong = nsnull;
jclass clazz = nsnull;
jmethodID mid = nsnull;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetDOM");
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellGetDOM");
return nsnull;
}
if (nsnull == initContext->currentDocument ||
nsnull == (documentLong = (jlong) initContext->currentDocument.get())){
if (nsnull == nativeBrowserControl->currentDocument ||
nsnull == (documentLong = (jlong) nativeBrowserControl->currentDocument.get())){
return nsnull;
}
@ -236,7 +242,7 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Curren
wsGetDOMEvent * actionEvent = new wsGetDOMEvent(env, clazz, mid, documentLong);
PLEvent * event = (PLEvent*) *actionEvent;
result = (jobject) ::util_PostSynchronousEvent(initContext, event);
result = (jobject) ::util_PostSynchronousEvent(nativeBrowserControl, event);
return result;
@ -268,18 +274,18 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Curren
/* PENDING(ashuk): remove this from here and in the motif directory
JNIEXPORT jbyteArray JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeGetSourceBytes
(JNIEnv * env, jobject jobj, jint webShellPtr, jboolean viewMode)
(JNIEnv * env, jobject jobj, jint nativeBCPtr, jboolean viewMode)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (initContext->initComplete) {
if (nativeBrowserControl->initComplete) {
wsViewSourceEvent * actionEvent =
new wsViewSourceEvent(initContext->docShell, ((JNI_TRUE == viewMode)? PR_TRUE : PR_FALSE));
new wsViewSourceEvent(nativeBrowserControl->docShell, ((JNI_TRUE == viewMode)? PR_TRUE : PR_FALSE));
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostEvent(initContext, event);
::util_PostEvent(nativeBrowserControl, event);
}
jbyteArray result = nsnull;
@ -294,13 +300,14 @@ JNIEXPORT jbyteArray JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Cur
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeResetFind
(JNIEnv * env, jobject obj, jint webShellPtr)
(JNIEnv * env, jobject obj, jint nativeBCPtr)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
}
#endif // if 0
/*
* Class: org_mozilla_webclient_impl_wrapper_0005fnative_CurrentPageImpl
@ -308,29 +315,36 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeSelectAll
(JNIEnv * env, jobject obj, jint webShellPtr)
(JNIEnv * env, jobject obj, jint nativeBCPtr)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
if (initContext->initComplete) {
wsSelectAllEvent * actionEvent = new wsSelectAllEvent(initContext);
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostEvent(initContext, event);
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null passed to nativeSelectAll");
return;
}
nsresult rv = nativeBrowserControl->mWindow->SelectAll();
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't selectAll");
return;
}
}
#if 0 // convenience
/*
* Class: org_mozilla_webclient_impl_wrapper_0005fnative_CurrentPageImpl
* Method: nativePrint
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativePrint
(JNIEnv * env, jobject obj, jint webShellPtr)
(JNIEnv * env, jobject obj, jint nativeBCPtr)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
if (initContext->initComplete) {
wsPrintEvent * actionEvent = new wsPrintEvent(initContext);
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (nativeBrowserControl->initComplete) {
wsPrintEvent * actionEvent = new wsPrintEvent(nativeBrowserControl);
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostEvent(initContext, event);
::util_PostEvent(nativeBrowserControl, event);
}
}
@ -340,13 +354,14 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativePrintPreview
(JNIEnv * env, jobject obj, jint webShellPtr, jboolean preview)
(JNIEnv * env, jobject obj, jint nativeBCPtr, jboolean preview)
{
NativeBrowserControl* initContext = (NativeBrowserControl *) webShellPtr;
if (initContext->initComplete) {
wsPrintPreviewEvent * actionEvent = new wsPrintPreviewEvent(initContext, preview);
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
if (nativeBrowserControl->initComplete) {
wsPrintPreviewEvent * actionEvent = new wsPrintPreviewEvent(nativeBrowserControl, preview);
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostEvent(initContext, event);
::util_PostEvent(nativeBrowserControl, event);
}
}
# endif // if 0

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

@ -29,12 +29,26 @@
#include <nsCWebBrowser.h>
#include <nsIComponentManager.h>
#include <nsIDocShellTreeItem.h>
#include "nsIDOMWindowInternal.h"
#include "nsIDOMWindow.h"
#include "nsISelection.h"
#include "nsIDOMRange.h"
#include "nsIDOMNode.h"
#include "nsIWidget.h"
#include "nsReadableUtils.h"
#include "nsIContentViewer.h"
#include "nsIContentViewerEdit.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "NativeBrowserControl.h"
#include "EmbedWindow.h"
#include "jni_util.h"
#include "nsCRT.h"
EmbedWindow::EmbedWindow(void)
{
mOwner = nsnull;
@ -109,6 +123,150 @@ EmbedWindow::ReleaseChildren(void)
mWebBrowser = 0;
}
nsresult
EmbedWindow::SelectAll()
{
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mWebBrowser);
if (!docShell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIContentViewer> contentViewer;
nsresult rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
if (!contentViewer) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIContentViewerEdit> contentViewerEdit(do_QueryInterface(contentViewer));
if (!contentViewerEdit) {
return NS_ERROR_FAILURE;
}
rv = contentViewerEdit->SelectAll();
return rv;
}
nsresult
EmbedWindow::GetSelection(JNIEnv *env, jobject mSelection)
{
nsresult rv = NS_ERROR_FAILURE;
// Get the DOM window
nsCOMPtr<nsIDOMWindow> domWindow;
rv = mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (NS_FAILED(rv) || !domWindow) {
return rv;
}
// Get the selection object of the DOM window
nsCOMPtr<nsISelection> selection;
rv = domWindow->GetSelection(getter_AddRefs(selection));
if (NS_FAILED(rv) || !selection) {
return rv;
}
// Get the range count
PRInt32 rangeCount;
rv = selection->GetRangeCount(&rangeCount);
if (NS_FAILED(rv) || rangeCount == 0) {
return rv;
}
// Get the actual selection string
PRUnichar *selectionStr;
rv = selection->ToString(&selectionStr);
if (NS_FAILED(rv)) {
return rv;
}
jstring string =
env->NewString((jchar*)selectionStr, nsCRT::strlen(selectionStr));
// string is now GC'd by Java
nsMemory::Free((void *) selectionStr);
// Get the first range object of the selection object
nsCOMPtr<nsIDOMRange> range;
rv = selection->GetRangeAt(0, getter_AddRefs(range));
if (NS_FAILED(rv) || !range) {
return rv;
}
// Get the properties of the range object (startContainer,
// startOffset, endContainer, endOffset)
PRInt32 startOffset;
PRInt32 endOffset;
nsCOMPtr<nsIDOMNode> startContainer;
nsCOMPtr<nsIDOMNode> endContainer;
// start container
rv = range->GetStartContainer(getter_AddRefs(startContainer));
if (NS_FAILED(rv)) {
return rv;
}
// end container
rv = range->GetEndContainer(getter_AddRefs(endContainer));
if (NS_FAILED(rv)) {
return rv;
}
// start offset
rv = range->GetStartOffset(&startOffset);
if (NS_FAILED(rv)) {
return rv;
}
// end offset
rv = range->GetEndOffset(&endOffset);
if (NS_FAILED(rv)) {
return rv;
}
// get a handle on to acutal (java) Node representing the start
// and end containers
jlong node1Long = nsnull;
jlong node2Long = nsnull;
nsCOMPtr<nsIDOMNode> node1Ptr(do_QueryInterface(startContainer));
nsCOMPtr<nsIDOMNode> node2Ptr(do_QueryInterface(endContainer));
if (nsnull == (node1Long = (jlong)node1Ptr.get())) {
return NS_ERROR_NULL_POINTER;
}
if (nsnull == (node2Long = (jlong)node2Ptr.get())) {
return NS_ERROR_NULL_POINTER;
}
jclass clazz = nsnull;
jmethodID mid = nsnull;
if (nsnull == (clazz = ::util_FindClass(env,
"org/mozilla/dom/DOMAccessor"))) {
return NS_ERROR_NULL_POINTER;
}
if (nsnull == (mid = env->GetStaticMethodID(clazz, "getNodeByHandle",
"(J)Lorg/w3c/dom/Node;"))) {
return NS_ERROR_NULL_POINTER;
}
jobject node1 = (jobject) ((void *)::util_CallStaticObjectMethodlongArg(env, clazz, mid, node1Long));
jobject node2 = (jobject) ((void *)::util_CallStaticObjectMethodlongArg(env, clazz, mid, node2Long));
// prepare the (java) Selection object that is to be returned.
if (nsnull == (clazz = ::util_FindClass(env, "org/mozilla/webclient/Selection"))) {
return NS_ERROR_NULL_POINTER;
}
if (nsnull == (mid = env->GetMethodID(clazz, "init",
"(Ljava/lang/String;Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;II)V"))) {
return NS_ERROR_NULL_POINTER;
}
env->CallVoidMethod(mSelection, mid,
string, node1, node2,
(jint)startOffset, (jint)endOffset);
return NS_OK;
}
// nsISupports
NS_IMPL_ADDREF(EmbedWindow)

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

@ -43,6 +43,8 @@
class NativeBrowserControl;
#include "ns_util.h"
class EmbedWindow : public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIEmbeddingSiteWindow,
@ -58,6 +60,9 @@ public:
nsresult Init (NativeBrowserControl *aOwner);
nsresult CreateWindow_ (PRUint32 width, PRUint32 height);
void ReleaseChildren (void);
nsresult SelectAll ();
nsresult GetSelection (JNIEnv *env, jobject selection);
NS_DECL_ISUPPORTS

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

@ -89,18 +89,18 @@ REQUIRES = xpcom \
# nsActions.cpp \
# CBrowserContainer.cpp \
# PromptActionEvents.cpp \
# CurrentPageImpl.cpp \
# CurrentPageActionEvents.cpp \
# HistoryImpl.cpp \
# HistoryActionEvents.cpp \
# ISupportsPeer.cpp \
# NativeEventThreadActionEvents.cpp \
# NavigationActionEvents.cpp \
# InputStreamShim.cpp \
# WindowControlActionEvents.cpp \
# WindowCreator.cpp \
CPPSRCS = \
InputStreamShim.cpp \
CurrentPageImpl.cpp \
NativeBrowserControl.cpp \
NativeWrapperFactory.cpp \
EmbedWindow.cpp \

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

@ -99,7 +99,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
nsString *uriNsString = nsnull;
wsLoadFromStreamEvent *actionEvent = nsnull;
if (nativeBrowserControl == nsnull || !nativeBrowserControl->initComplete) {
if (nativeBrowserControl == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeLoadFromStream");
return;
}
@ -110,19 +110,19 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to convert java string to native format");
goto NLFS_CLEANUP;
}
if (!(uriNsString =
new nsString(uriStringUniChars, uriStringUniCharsLength))) {
::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to convert native string to nsString");
goto NLFS_CLEANUP;
}
// the deleteGlobalRef is done in the wsLoadFromStream destructor
if (!(globalStream = ::util_NewGlobalRef(env, stream))) {
::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to create gloabal ref to stream");
goto NLFS_CLEANUP;
}
if (loadProperties) {
// the deleteGlobalRef is done in the wsLoadFromStream destructor
if (!(globalLoadProperties =
@ -131,7 +131,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio
goto NLFS_CLEANUP;
}
}
if (!(actionEvent = new wsLoadFromStreamEvent(nativeBrowserControl,
(void *) globalStream,
*uriNsString,
@ -153,6 +153,8 @@ 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)

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

@ -1,5 +1,5 @@
/*
* $Id: NavigationTest.java,v 1.3 2004-04-22 06:41:02 edburns%acm.org Exp $
* $Id: NavigationTest.java,v 1.4 2004-04-28 14:39:54 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -71,14 +71,29 @@ public class NavigationTest extends WebclientTestCase {
frame.setVisible(true);
canvas.setVisible(true);
Navigation nav = (Navigation)
Navigation2 nav = (Navigation2)
firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
assertNotNull(nav);
File testPage = new File(getBrowserBinDir(),
"../../java/webclient/test/automated/src/test/NavigationTest.txt");
System.out.println("Loading url: " + testPage.toURL().toString());
nav.loadURL(testPage.toURL().toString());
nav.loadURLBlocking(testPage.toURL().toString());
CurrentPage2 currentPage = (CurrentPage2)
firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
assertNotNull(currentPage);
currentPage.selectAll();
Selection selection = currentPage.getSelection();
assertTrue(-1 != selection.toString().indexOf("This test file is for the NavigationTest."));
System.out.println("Selection is: " + selection.toString());
/*********
RandomHTMLInputStream rhis = new RandomHTMLInputStream(3);
nav.loadFromStream(rhis, "http://randomstream.com/",
"text/html", -1, null);
************/
frame.setVisible(false);
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
BrowserControlFactory.appTerminate();

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

@ -0,0 +1,268 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*/
package org.mozilla.webclient;
/*
* RandomHTMLInputStream.java
*/
import org.mozilla.util.Assert;
import org.mozilla.util.ParameterCheck;
import java.io.InputStream;
import java.io.IOException;
import java.util.Random;
/**
* This class simulates a nasty, misbehavin' InputStream.
* It randomly throws IOExceptions, blocks on read, and is bursty.
*/
public class RandomHTMLInputStream extends InputStream
{
//
// Class variables
//
private static final int MAX_AVAILABLE = 4096;
/**
* This makes it so only when we get a random between 0 and 100 number
* that evenly divides by three do we throw an IOException
*/
private static final int EXCEPTION_DIVISOR = 179;
private static final byte [] CHARSET;
//
// relationship ivars
//
private Random random;
//
// attribute ivars
//
private boolean isClosed;
private boolean firstRead;
/**
* the number of times that read(bytearray) can be called and still get
* data.
*/
private int numReads;
private int available;
/**
* @param yourNumReads must be at least 2
*/
static {
String charSet = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890[]{}";
CHARSET = charSet.getBytes();
}
public RandomHTMLInputStream(int yourNumReads)
{
ParameterCheck.greaterThan(yourNumReads, 1);
random = new Random();
Assert.assert_it(null != random);
isClosed = false;
firstRead = true;
numReads = yourNumReads;
available = random.nextInt(MAX_AVAILABLE);
}
public int available() throws IOException
{
int result;
if (shouldThrowException()) {
throw new IOException("It's time for an IOException!");
}
if (isClosed) {
result = -1;
}
else {
result = available;
}
return result;
}
public int read() throws IOException
{
int result = 0;
if (shouldThrowException()) {
throw new IOException("It's time for an IOException!");
}
if (0 < available) {
result = (int) 'a';
available--;
}
else {
result = -1;
}
return result;
}
public int read(byte[] b, int off, int len) throws IOException
{
if (shouldThrowException()) {
throw new IOException("It's time for an IOException!");
}
byte [] bytes;
int i = 0;
int max = 0;
int numRead = -1;
// write case 0, no more reads left
if (0 == numReads || isClosed) {
return -1;
}
if (len <= available) {
max = len;
}
else {
max = available;
}
if (firstRead) {
String htmlHead = "<HTML><BODY><PRE>START Random Data";
numRead = htmlHead.length();
// write case 1, yes enough length to write htmlHead
if (numRead < len && len <= available) {
bytes = htmlHead.getBytes();
for (i = 0; i < numRead; i++) {
b[off+i] = bytes[i];
}
available -= numRead;
}
else {
// write case 2, not enough length to write htmlHead
for (i = 0; i < max; i++) {
b[off+i] = (byte) random.nextInt(8);
}
numRead = max;
available -= max;
}
firstRead = false;
}
else {
// if this is the last read
if (1 == numReads) {
String htmlTail = "\nEND Random Data</PRE></BODY></HTML>";
numRead = htmlTail.length();
// write case 3, yes enough length to write htmlTail
if (numRead < len && len <= available) {
bytes = htmlTail.getBytes();
for (i = 0; i < numRead; i++) {
b[off+i] = bytes[i];
}
available -= numRead;
}
else {
// write case 4, not enough length to write htmlTail
for (i = 0; i < max; i++) {
b[off+i] = (byte) random.nextInt(8);
}
numRead = max;
available -= max;
}
}
else {
// if it's time to block
if (random.nextBoolean()) {
try {
System.out.println("RandomHTMLInputStream:: sleeping");
Thread.sleep(3000);
}
catch (Exception e) {
throw new IOException(e.getMessage());
}
}
// write case 5, write some random bytes to fit length
// this is not the first or the last read, just cough up
// some random bytes.
bytes = new byte[max];
for (i = 0; i < max; i++) {
if (0 == (i % 78)) {
b[off+i] = (byte) '\n';
}
else {
b[off+i] = CHARSET[random.nextInt(CHARSET.length)];
}
}
numRead = max;
available -= max;
}
}
available = random.nextInt(MAX_AVAILABLE);
numReads--;
return numRead;
}
public void close() throws IOException
{
if (shouldThrowException()) {
throw new IOException("It's time for an IOException!");
}
isClosed = true;
}
private boolean shouldThrowException()
{
int nextInt = random.nextInt(10000);
boolean result = false;
if (nextInt > EXCEPTION_DIVISOR) {
result = (0 == (nextInt % EXCEPTION_DIVISOR));
}
return result;
}
}