Mozilla/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp
edburns%acm.org 1442832df2 bug 40330
a=edburns
r=drapeau

This checkin creates a dependency on the mozilla java dom module.

Please see mozilla\java\dom\README to build the java dom.
Note that you can just run make in mozilla\java and everything
should be built correctly.

A webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMCellRenderer.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeDumper.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeNotifier.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java

M Makefile.win
M README
M webclient/classes_spec/Makefile.unix
M webclient/classes_spec/Makefile.win
M webclient/classes_spec/org/mozilla/webclient/CurrentPage.java
M webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java
M webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java
M webclient/src_moz/CurrentPageImpl.cpp
M webclient/src_moz/DocumentLoaderObserverImpl.cpp
M webclient/src_moz/Makefile.win
M webclient/src_moz/WindowControlImpl.cpp
M webclient/src_moz/jni_util.h


git-svn-id: svn://10.0.0.236/trunk@71490 18797224-902f-48f8-a5cc-f745e15eee43
2000-06-04 22:16:36 +00:00

401 lines
13 KiB
C++

/* -*- 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): Kirk Baker <kbaker@eb.com>
* Ian Wilkinson <iw@ennoble.com>
* Mark Lin <mark.lin@eng.sun.com>
* Mark Goddard
* Ed Burns <edburns@acm.org>
* Ann Sunhachawee
*/
/*
* CurrentPageImpl.cpp
*/
#include "CurrentPageImpl.h"
#include "jni_util.h"
#include "jni_util_export.h"
#include "rdf_util.h"
#include "nsActions.h"
#include "nsLayoutCID.h"
#include "nsCRT.h"
#include "nsIPresShell.h"
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsIFindComponent.h"
#include "nsISearchContext.h"
#include "nsIDocShell.h"
#include "nsIDOMSelection.h"
#include "nsIDocumentViewer.h"
#include "nsIDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMRange.h"
#include "nsIContentViewer.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeCopyCurrentSelectionToSystemClipboard
(JNIEnv *env, jobject obj, jint webShellPtr)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
nsCOMPtr<nsIPresShell> presShell;
nsresult rv;
rv = initContext->docShell->GetPresShell(getter_AddRefs(presShell));
// PENDING() should this be done using an nsActionEvent subclass?
if (NS_FAILED(rv)) {
initContext->initFailCode = kHistoryWebShellError;
::util_ThrowExceptionToJava(env, "Exception: can't Copy to Clipboard");
return;
}
presShell->DoCopy();
/***
This looks like the right way to do it, but as of 01/13/00, it
doesn't work. See a post on n.p.m.embedding:
Message-ID: <85ll4n$nli$1@nnrp1.deja.com>
**/
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeFindInPage
* Signature: (Ljava/lang/String;ZZ)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeFindInPage
(JNIEnv *env, jobject obj, jint webShellPtr, jstring searchString, jboolean forward, jboolean matchCase)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
//First get the FindComponent object
nsresult rv;
NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_PROGID, &rv);
if (NS_FAILED(rv)) {
initContext->initFailCode = kFindComponentError;
::util_ThrowExceptionToJava(env, "Exception: can't access FindComponent Service");
return;
}
// Create a Search Context for the FindComponent
nsCOMPtr<nsISupports> searchContext;
rv = findComponent->CreateContext(initContext->webShell, nsnull, getter_AddRefs(searchContext));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSearchContextError;
::util_ThrowExceptionToJava(env, "Exception: can't create SearchContext for Find");
return;
}
nsCOMPtr<nsISearchContext> srchcontext;
rv = searchContext->QueryInterface(NS_GET_IID(nsISearchContext), getter_AddRefs(srchcontext));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSearchContextError;
::util_ThrowExceptionToJava(env, "Exception: can't create SearchContext for Find");
return;
}
PRUnichar * aString;
srchcontext->GetSearchString(& aString);
PRUnichar * srchString = (PRUnichar *) ::util_GetStringChars(env, searchString);
srchcontext->SetSearchString(srchString);
srchcontext->SetSearchBackwards(!forward);
srchcontext->SetCaseSensitive(matchCase);
// Pass searchContext to findComponent for the actual find call
PRBool found = PR_TRUE;
findComponent->FindNext(srchcontext, &found);
// Save in initContext struct for future findNextInPage calls
initContext->searchContext = srchcontext;
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeFindNextInPage
* Signature: (Z)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeFindNextInPage
(JNIEnv *env, jobject obj, jint webShellPtr, jboolean forward)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
//First get the FindComponent object
nsresult rv;
NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_PROGID, &rv);
if (NS_FAILED(rv)) {
initContext->initFailCode = kFindComponentError;
::util_ThrowExceptionToJava(env, "Exception: can't access FindComponent Service");
return;
}
// Get the searchContext from the initContext struct
nsCOMPtr<nsISearchContext> searchContext = initContext->searchContext;
if (nsnull == searchContext) {
initContext->initFailCode = kSearchContextError;
::util_ThrowExceptionToJava(env, "Exception: NULL SearchContext received for FindNext");
return;
}
// Pass searchContext to findComponent for the actual find call
PRBool found = PR_TRUE;
findComponent->FindNext(searchContext, &found);
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeGetCurrentURL
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetCurrentURL
(JNIEnv *env, jobject obj, jint webShellPtr)
{
JNIEnv * pEnv = env;
jobject jobj = obj;
char * charResult = nsnull;
jstring urlString = nsnull;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetURL");
return nsnull;
}
if (initContext->initComplete) {
nsISessionHistory *yourHistory;
nsresult rv;
rv = initContext->webShell->GetSessionHistory(yourHistory);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: can't get SessionHistory from webshell");
return urlString;
}
wsGetURLEvent * actionEvent = new wsGetURLEvent(yourHistory);
PLEvent * event = (PLEvent*) *actionEvent;
charResult = (char *) ::util_PostSynchronousEvent(initContext, event);
if (charResult != nsnull) {
urlString = ::util_NewStringUTF(env, (const char *) charResult);
}
else {
::util_ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned NULL");
return nsnull;
}
nsCRT::free(charResult);
}
return urlString;
}
JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetDOM
(JNIEnv *env, jobject obj, jint webShellPtr)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
jobject result = nsnull;
jlong documentLong = nsnull;
jclass clazz = nsnull;
jmethodID mid = nsnull;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetDOM");
return nsnull;
}
if (nsnull == initContext->currentDocument ||
nsnull == (documentLong = (jlong) initContext->currentDocument.get())){
return nsnull;
}
if (nsnull == (clazz = ::util_FindClass(env,
"org/mozilla/dom/DOMAccessor"))) {
::util_ThrowExceptionToJava(env, "Exception: Can't get DOMAccessor class");
return nsnull;
}
if (nsnull == (mid = env->GetStaticMethodID(clazz, "getNodeByHandle",
"(J)Lorg/w3c/dom/Node;"))) {
::util_ThrowExceptionToJava(env, "Exception: Can't get DOM Node.");
return nsnull;
}
result = env->CallStaticObjectMethod(clazz, mid, documentLong);
return result;
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeGetSource
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSource
(JNIEnv * env, jobject jobj)
{
jstring result = nsnull;
return result;
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeGetSourceBytes
* Signature: ()[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSourceBytes
(JNIEnv * env, jobject jobj, jint webShellPtr, jboolean mode)
{
/*
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
nsCOMPtr <nsIDocShell> docShell = initContext->docShell;
if (mode)
docShell->SetViewMode(nsIDocShell::viewSource);
else
docShell->SetViewMode(nsIDocShell::viewNormal);
*/
jbyteArray result = nsnull;
return result;
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeResetFind
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeResetFind
(JNIEnv * env, jobject obj, jint webShellPtr)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
initContext->searchContext = nsnull;
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeSelectAll
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeSelectAll
(JNIEnv * env, jobject obj, jint webShellPtr)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
nsCOMPtr<nsIPresShell> presShell;
nsresult rv;
rv = initContext->docShell->GetPresShell(getter_AddRefs(presShell));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get PresShell");
return;
}
nsCOMPtr<nsIDOMSelection> selection;
rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMSelection");
return;
}
nsCOMPtr<nsIContentViewer> contentViewer;
rv = initContext->docShell->GetContentViewer(getter_AddRefs(contentViewer));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get contentViewer");
return;
}
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(contentViewer));
nsCOMPtr<nsIDocument> doc;
rv = docViewer->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get Document object");
return;
}
nsCOMPtr<nsIDOMHTMLDocument> htmldoc;
rv = doc->QueryInterface(kIDOMHTMLDocumentIID, getter_AddRefs(htmldoc));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMHTMLDocument");
return;
}
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
rv = htmldoc->GetBody(getter_AddRefs(bodyElement));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMHTMLElement");
return;
}
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
if (!bodyNode) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMNode");
return;
}
rv = selection->ClearSelection();
nsCOMPtr<nsIDOMRange> range;
rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull,
NS_GET_IID(nsIDOMRange),
getter_AddRefs(range));
rv = range->SelectNodeContents(bodyNode);
rv = selection->AddRange(range);
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get final Select working");
return;
}
}