Checkpoint for mac os x reactivation.

Having trouble with the implementation of getHandleToPeer.

Current problem is that JAWT_DrawingSurface->Lock() is failing.

Why would that be?
This commit is contained in:
edburns%acm.org 2005-05-13 06:40:12 +00:00
parent df6e435fe9
commit f14f0787f1
19 changed files with 378 additions and 65 deletions

View File

@ -91,6 +91,8 @@
executable="gmake"/>
<exec os="Linux" dir="${basedir}/src" failonerror="yes"
executable="make"/>
<exec os="Mac OS X" dir="${basedir}/src" failonerror="yes"
executable="make"/>
<exec os="Windows 2000" dir="${basedir}/src" executable="make"
failonerror="yes"/>

View File

@ -45,6 +45,7 @@ REQUIRES = xpcom \
include $(DEPTH)/config/autoconf.mk
MODULE = javadomjni
LIBRARY_NAME = javadomjni
CPPSRCS = \
@ -76,6 +77,11 @@ EXTRA_LIBS += \
include $(topsrcdir)/config/config.mk
ifeq ($(OS_ARCH),Darwin)
INCLUDES += -I$(MOZ_JDKHOME)/include -I.
DSO_LDOPTS += -L/System/Library/Frameworks/JavaVM.Framework/Libraries -ljvm_compat
DLL_SUFFIX = .jnilib
else
ifeq ($(OS_ARCH),Linux)
INCLUDES += -I$(JAVAHOME)/include -I$(JAVAHOME)/include/linux
else
@ -85,6 +91,7 @@ else
INCLUDES += -I$(JAVAHOME)/include -I$(JAVAHOME)/include/solaris
endif
endif
endif
include $(topsrcdir)/config/rules.mk

View File

@ -58,6 +58,11 @@ EXTRA_LIBS += \
include $(topsrcdir)/config/config.mk
ifeq ($(OS_ARCH),Darwin)
INCLUDES += -I$(MOZ_JDKHOME)/include -I.
DSO_LDOPTS += -L/System/Library/Frameworks/JavaVM.Framework/Libraries -ljvm_compat
DLL_SUFFIX = .jnilib
else
ifeq ($(OS_ARCH),Linux)
INCLUDES += -I$(JAVAHOME)/include -I$(JAVAHOME)/include/linux
DSO_LDOPTS += \
@ -69,7 +74,6 @@ ifeq ($(OS_ARCH),Linux)
-Xlinker -rpath $(JAVAHOME)/jre/lib/i386/native_threads \
-ljvm -lhpi
DEFINES += -DDISABLE_JIT
else
ifeq ($(OS_ARCH),WINNT)
INCLUDES += -I$(JAVAHOME)/include -I$(JAVAHOME)/include/win32
EXTRA_LIBS += \
@ -87,6 +91,7 @@ else
-ljvm -lhpi
endif
endif
endif
# ifeq (($OS_ARCH),SunOS)

View File

@ -556,56 +556,9 @@ JNIEnv* nsJavaDOMImpl::GetJNIEnv() {
#ifndef JAVA_DOM_OJI_ENABLE
void nsJavaDOMImpl::StartJVM(void) {
jsize jvmCount;
JNI_GetCreatedJavaVMs(&jvm, 1, &jvmCount);
if (jvmCount) {
return;
}
JNIEnv *env = NULL;
JDK1_1InitArgs vm_args;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
vm_args.version = 0x00010001;
vm_args.verifyMode = JNI_TRUE;
#ifdef DEBUG
vm_args.verbose = JNI_TRUE;
vm_args.enableVerboseGC = JNI_TRUE;
#endif // DEBUG
char* cp = PR_GetEnv("CLASSPATH");
char* p = new char[strlen(cp) + strlen(vm_args.classpath) + 2];
strcpy(p, vm_args.classpath);
if (cp) {
#ifdef XP_PC
strcat(p, ";");
#else
strcat(p, ":");
#endif
strcat(p, cp);
vm_args.classpath = p;
}
#ifdef DISABLE_JIT
/* workaround to get java dom to work on Linux */
char **props = new char*[2];
props[0]="java.compiler=";
props[1]=0;
vm_args.properties = props;
#endif
#ifdef DEBUG
printf("classpath is \"%s\"\n", vm_args.classpath);
#endif // DEBUG
jint rv = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (rv < 0) {
printf("\n JAVA DOM: could not start jvm\n");
} else {
printf("\n JAVA DOM: successfully started jvm\n");
}
delete[] p;
}
#endif /* JAVA_DOM_OJI_ENABLE */
#if defined(DEBUG)
static void dump_document(nsIDOMDocument* domDoc, const char* urlSpec)
{

View File

@ -104,10 +104,17 @@
<src path="${src.manual.test.dir}"/>
<patternset>
<exclude name="**/*Win32*.java" if="build.unix.classes"/>
<exclude name="**/*Cocoa*.java" if="build.unix.classes"/>
</patternset>
<patternset>
<exclude name="**/*Gtk*.java" if="build.win32.classes"/>
<exclude name="**/*Cocoa*.java" if="build.win32.classes"/>
</patternset>
<patternset>
<exclude name="**/*Gtk*.java" if="build.mac.classes"/>
<exclude name="**/*Win32*.java" if="build.mac.classes"/>
</patternset>
</javac>

View File

@ -89,10 +89,17 @@
<src path="${source.home}"/>
<patternset>
<exclude name="**/Win32*.java" if="build.unix.classes"/>
<exclude name="**/Cocoa*.java" if="build.unix.classes"/>
</patternset>
<patternset>
<exclude name="**/Gtk*.java" if="build.win32.classes"/>
<exclude name="**/Cocoa*.java" if="build.win32.classes"/>
</patternset>
<patternset>
<exclude name="**/Gtk*.java" if="build.mac.classes"/>
<exclude name="**/Win32*.java" if="build.mac.classes"/>
</patternset>
<!-- PENDING(edburns): include additional patternsets for ICE,
@ -130,7 +137,7 @@
</target>
<target name="compile.javah.canvas.headers"
depends="compile.unix.canvas.headers,compile.win32.canvas.headers"/>
depends="compile.unix.canvas.headers,compile.win32.canvas.headers,compile.mac.canvas.headers"/>
<target name="compile.unix.canvas.headers" if="build.unix.classes">
@ -150,6 +157,14 @@
</target>
<target name="compile.mac.canvas.headers" if="build.mac.classes">
<javah destdir="${basedir}/src_moz/cocoa"
class="org.mozilla.webclient.impl.wrapper_native.CocoaBrowserControlCanvas">
<classpath refid="compile.classpath"/>
</javah>
</target>
<target name="compile.src_moz" depends="compile.src_share">
@ -160,6 +175,9 @@
<exec os="Linux" dir="${basedir}/src_moz" executable="make"
failonerror="yes">
</exec>
<exec os="Mac OS X" dir="${basedir}/src_moz" executable="make"
failonerror="yes">
</exec>
<exec os="Windows 2000" dir="${basedir}/src_moz" executable="make"
failonerror="yes"/>
@ -215,6 +233,26 @@ ${myenv.MOZ_JDKHOME}/bin/java ${debug.options} org.mozilla.webclient.test.Embedd
</target>
<target name="create.mac.webclient.scripts"
if="build.mac.classes">
<condition property="debug.options" value="${debug.jvm.args}">
<equals arg1="${myenv.MOZ_DEBUG}" arg2="1"/>
</condition>
<condition property="debug.options" value="">
<not>
<equals arg1="${myenv.MOZ_DEBUG}" arg2="1"/>
</not>
</condition>
<echo file="${basedir}/src_moz/runem">export CLASSPATH=${build.home}:$CLASSPATH
export LD_LIBRARY_PATH=${build.home}/../bin:${build.home}/../bin/components:$LD_LIBRARY_PATH:;${myenv.MOZ_JDKHOME}/jre/bin
${myenv.MOZ_JDKHOME}/bin/java ${debug.options} org.mozilla.webclient.test.EmbeddedMozillaImpl ${build.home}/../bin $*
</echo>
<chmod perm="755" file="${basedir}/src_moz/runem"/>
</target>
<target name="clean.classes_spec">
<delete dir="${build.home}/org/mozilla/webclient"/>
</target>

View File

@ -0,0 +1,82 @@
/*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): edburns &lt;edburns@acm.org&gt;
*/
/*
* CocoaBrowserControlCanvas.java
*
* Created on May 10, 2005, 8:59 PM
*/
package org.mozilla.webclient.impl.wrapper_native;
import org.mozilla.webclient.BrowserControlCanvas;
import org.mozilla.webclient.impl.wrapper_native.WCRunnable;
import org.mozilla.webclient.impl.wrapper_native.NativeEventThread;
import java.awt.Graphics;
/**
*
* @author edburns
*/
public class CocoaBrowserControlCanvas extends BrowserControlCanvas {
/** Creates a new instance of CocoaBrowserControlCanvas */
public CocoaBrowserControlCanvas() {
}
//New method for obtaining access to the Native Peer handle
private native int getHandleToPeer(Graphics graphics);
private int nativeWindow = -1;
/**
* Obtain the native window handle for this
* component's peer.
*
* @returns The native window handle.
*/
protected int getWindow() {
WCRunnable runner = new WCRunnable() {
public Object run() {
Integer result =
new Integer(CocoaBrowserControlCanvas.this.getHandleToPeer(null));
return result;
}
};
Integer result = null;
this.setVisible(true);
repaint();
while (-1 == nativeWindow) {
result = (Integer) NativeEventThread.instance.pushBlockingWCRunnable(runner);
nativeWindow = result.intValue();
}
return nativeWindow;
}
public void paint(Graphics graphics) {
nativeWindow = getHandleToPeer(graphics);
}
}

View File

@ -416,6 +416,9 @@ protected String getPlatformCanvasClassName()
if (-1 != osName.indexOf("indows")) {
platformCanvasClassName = "org.mozilla.webclient.impl.wrapper_native.Win32BrowserControlCanvas";
}
else if (-1 != osName.indexOf("Mac OS X")) {
platformCanvasClassName = "org.mozilla.webclient.impl.wrapper_native.CocoaBrowserControlCanvas";
}
else {
platformCanvasClassName = "org.mozilla.webclient.impl.wrapper_native.GtkBrowserControlCanvas";
}

View File

@ -217,7 +217,7 @@ EmbedEventListener::MouseClick(nsIDOMEvent* aMouseEvent)
return NS_OK;
// Return FALSE to this function to mark the event as not
// consumed...
PRBool return_val = FALSE;
PRBool return_val = PR_FALSE;
PopulatePropertiesFromEvent(aMouseEvent);

View File

@ -111,11 +111,13 @@ nsresult
EmbedWindow::CreateWindow_(PRUint32 width, PRUint32 height)
{
nsresult rv;
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
PR_ASSERT(PR_FALSE);
GtkWidget *ownerAsWidget (GTK_WIDGET(mOwner->parentHWnd));
width = ownerAsWidget->allocation.width;
height = ownerAsWidget->allocation.height;
#elif defined(XP_MACOSX)
void *ownerAsWidget = mOwner->parentHWnd;
#else
HWND ownerAsWidget = mOwner->parentHWnd;
#endif
@ -645,8 +647,10 @@ EmbedWindow::SetTitle(const PRUnichar *aTitle)
NS_IMETHODIMP
EmbedWindow::GetSiteWindow(void **aSiteWindow)
{
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
GtkWidget *ownerAsWidget (GTK_WIDGET(mOwner->parentHWnd));
#elif defined(XP_MACOSX)
void *ownerAsWidget = mOwner->parentHWnd;
#else
HWND ownerAsWidget = mOwner->parentHWnd;
#endif

View File

@ -132,6 +132,12 @@ CPPSRCS += \
$(NULL)
DIRS = gtk
else
ifeq ($(OS_ARCH),Darwin)
CMMSRCS = cocoa/CocoaBrowserControlCanvas.mm
CPPSRCS += cocoa/CocoaBrowserControlCanvasImpl.cpp
DLL_SUFFIX = .jnilib
DSO_LDOPTS += -L/System/Library/Frameworks/JavaVM.Framework/Libraries -ljawt
else
ifeq ($(OS_ARCH),WINNT)
CPPSRCS += \
win32/Win32BrowserControlCanvas.cpp \
@ -143,6 +149,7 @@ CPPSRCS += \
DIRS = gtk
endif
endif
endif
EXTRA_LIBS += \
@ -193,10 +200,14 @@ ifeq ($(OS_ARCH),WINNT)
INCLUDES := -I$(MOZ_JDKHOME)/include -I$(MOZ_JDKHOME)/include/win32 $(INCLUDES) \
-I../src_share -I.
else
ifeq ($(OS_ARCH),Darwin)
INCLUDES := -I$(MOZ_JDKHOME)/include $(INCLUDES) -I../src_share -I.
else
INCLUDES := -I$(MOZ_JDKHOME)/include -I$(MOZ_JDKHOME)/include/solaris $(INCLUDES) \
-I$(DEPTH)/widget/src/gtk -I../src_share
endif
endif
endif
clobber_all:: clobber

View File

@ -140,14 +140,16 @@ NativeBrowserControl::Realize(jobject javaBrowserControl,
mSessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID);
mNavigation->SetSessionHistory(mSessionHistory);
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
PR_ASSERT(PR_FALSE);
GtkWidget *ownerAsWidget (GTK_WIDGET(parentWinPtr));
parentHWnd = ownerAsWidget;
width = ownerAsWidget->allocation.width;
height = ownerAsWidget->allocation.height;
#else
#elif !defined(XP_MACOSX)
parentHWnd = (HWND) parentWinPtr;
#else
parentHWnd = parentWinPtr;
#endif
// create the window

View File

@ -106,9 +106,11 @@ public:
// Relationship ivars
//
#ifdef XP_UNIX
#if defined(XP_UNIX) &&!defined(XP_MACOSX)
GtkWidget * parentHWnd;
#else
#elif defined(XP_MAC) || defined(XP_MACOSX)
void * parentHWnd;
#else !defined(XP_MACOSX)
HWND parentHWnd;
#endif

View File

@ -281,7 +281,7 @@ Java_org_mozilla_webclient_impl_wrapper_1native_NativeEventThread_nativeRemoveAl
}
// Ashu
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
static void event_processor_callback(gpointer data,
gint source,
GdkInputCondition condition) {

View File

@ -34,7 +34,7 @@
#include "ns_util.h"
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
#include <unistd.h>
#include "gdksuperwin.h"
#include "gtkmozarea.h"
@ -43,7 +43,6 @@ extern "C" {
static int wc_x_error (Display *display,
XErrorEvent *error);
}
#endif
PLEventQueue *NativeWrapperFactory::sActionQueue = nsnull;
@ -135,7 +134,7 @@ NativeWrapperFactory::Init(JNIEnv * env, jobject newNativeEventThread)
("NativeBrowserControl_Init: get ActionQueue: %d\n",
mFailureCode));
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
// The gdk_x_error function exits in some cases, we don't
// want that.
@ -171,12 +170,11 @@ NativeWrapperFactory::ProcessEventLoop(void)
return 0;
}
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
while(gtk_events_pending()) {
gtk_main_iteration();
}
#else
// PENDING(mark): Does this work on the Mac?
#elif !defined(XP_MACOSX)
MSG msg;
PRBool wasHandled;
@ -226,7 +224,7 @@ NativeWrapperFactory::IsInitialized(void)
return sInitComplete;
}
#ifdef XP_UNIX
#if defined(XP_UNIX) && !defined(XP_MACOSX)
static int
wc_x_error (Display *display,
XErrorEvent *error)

View File

@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*
*/
#ifndef CocoaBrowserControlCanvas_h
#define CocoaBrowserControlCanvas_h
#include <jni.h>
class CocoaBrowserControlCanvas {
public:
static jint cocoaGetHandleToPeer(JNIEnv *env, jobject canvas, jobject graphics);
};
#endif

View File

@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): edburns <edburns@acm.org>
*/
/*
* CocoaBrowserControlCanvas.cpp
*/
#include <jawt_md.h>
#include <assert.h>
#include "CocoaBrowserControlCanvas.h"
#include "jni_util.h" //for throwing Exceptions to Java
jint CocoaBrowserControlCanvas::cocoaGetHandleToPeer(JNIEnv *env, jobject canvas, jobject graphics) {
printf("debug: edburns: in CocoaBrowserControlCanvas::nativeGetHandleToPeer\n");
JAWT awt;
JAWT_DrawingSurface* ds = NULL;
JAWT_DrawingSurfaceInfo* dsi = NULL;
JAWT_MacOSXDrawingSurfaceInfo* dsi_mac = NULL;
jboolean result = JNI_FALSE;
jint lock = 0;
NSView *view = NULL;
printf("debug: edburns: about to get AWT\n");
// get the AWT
awt.version = JAWT_VERSION_1_4;
printf("debug: edburns: set awt version: ok\n");
result = JAWT_GetAWT(env, &awt);
printf("debug: edburns: got awt: result: %d\n",result);
printf("debug: edburns: additional printf\n");
printf("debug: edburns: got AWT\n");
printf("debug: edburns: about to get drawing surface\n");
fflush(stdout);
// Get the drawing surface. This can be safely cached.
// Anything below the DS (DSI, contexts, etc)
// can possibly change/go away and should not be cached.
ds = awt.GetDrawingSurface(env, canvas);
printf("debug: edburns: got drawing surface: %d\n", ds);
fflush(stdout);
if (NULL == ds) {
util_ThrowExceptionToJava(env, "CocoaBrowserControlCanvas: can't get drawing surface");
}
printf("debug: edburns: about to lock drawing surface: %d\n", ds);
fflush(stdout);
// Lock the drawing surface
// You must lock EACH TIME before drawing
lock = ds->Lock(ds);
printf("debug: edburns: acquired lock: %d\n", lock);
fflush(stdout);
if (NULL == lock) {
util_ThrowExceptionToJava(env, "CocoaBrowserControlCanvas: can't lock drawing surface");
}
assert((lock & JAWT_LOCK_ERROR) == 0);
// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);
// Check DrawingSurfaceInfo. This can be NULL on Mac OS X
// if the windowing system is not ready
if (dsi != NULL) {
// Get the platform-specific drawing info
// We will use this to get at Cocoa and CoreGraphics
// See <JavaVM/jawt_md.h>
dsi_mac = (JAWT_MacOSXDrawingSurfaceInfo*)dsi->platformInfo;
if (NULL == dsi_mac) {
util_ThrowExceptionToJava(env, "CocoaBrowserControlCanvas: can't get DrawingSurfaceInfo");
}
// Get the corresponding peer from the caller canvas
view = dsi_mac->cocoaViewRef;
// Free the DrawingSurfaceInfo
ds->FreeDrawingSurfaceInfo(dsi);
}
// Unlock the drawing surface
// You must unlock EACH TIME when done drawing
ds->Unlock(ds);
// Free the drawing surface (if not caching it)
awt.FreeDrawingSurface(ds);
return (jint) view;
}

View File

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): edburns <edburns@acm.org>
*/
/*
* CocoaBrowserControlCanvas.cpp
*/
#include "org_mozilla_webclient_impl_wrapper_0005fnative_CocoaBrowserControlCanvas.h"
#include "jni_util.h" //for throwing Exceptions to Java
#include "CocoaBrowserControlCanvas.h"
/*
* Class: org_mozilla_webclient_impl_wrapper_0005fnative_CocoaBrowserControlCanvas
* Method: getHandleToPeer
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CocoaBrowserControlCanvas_getHandleToPeer
(JNIEnv *env, jobject canvas, jobject graphics) {
printf("debug: edburns: in CocoaBrowserControlCanvasImpl->nativeGetHandleToPeer\n");
fflush(stdout);
jint result = -1;
result = CocoaBrowserControlCanvas::cocoaGetHandleToPeer(env, canvas, graphics);
return result;
}

View File

@ -56,7 +56,7 @@
#include "ns_globals.h"
// Ashu
#ifdef XP_UNIX
#if defined(XP_UNIX) &&!defined(XP_MACOSX)
#include "nsIWidget.h" // for GTKWidget
#include <gtk/gtk.h>
#endif