mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 335696 - Provide helper method for embedding in AWT/Swing (Mac only for the moment). r=bsmeberg
This commit is contained in:
parent
2a7f6d50e8
commit
3fe0aaa751
@ -84,10 +84,11 @@ enum {
|
||||
kFunc_CallXPCOMMethod,
|
||||
kFunc_FinalizeProxy,
|
||||
kFunc_IsSameXPCOMObject,
|
||||
kFunc_ReleaseProfileLock
|
||||
kFunc_ReleaseProfileLock,
|
||||
kFunc_GetNativeHandleFromAWT
|
||||
};
|
||||
|
||||
#define JX_NUM_FUNCS 15
|
||||
#define JX_NUM_FUNCS 16
|
||||
|
||||
|
||||
// Get path string from java.io.File object.
|
||||
@ -161,6 +162,8 @@ LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
|
||||
(NSFuncPtr*) &aFunctions[kFunc_IsSameXPCOMObject] },
|
||||
{ "Java_org_mozilla_xpcom_ProfileLock_release",
|
||||
(NSFuncPtr*) &aFunctions[kFunc_ReleaseProfileLock] },
|
||||
{ "Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT",
|
||||
(NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
|
||||
{ nsnull, nsnull }
|
||||
};
|
||||
|
||||
@ -219,6 +222,8 @@ RegisterNativeMethods(JNIEnv* env, void** aFunctions)
|
||||
JNINativeMethod mozilla_methods[] = {
|
||||
{ "initializeNative", "()V",
|
||||
(void*) aFunctions[kFunc_Initialize] },
|
||||
{ "getNativeHandleFromAWT", "(Ljava/lang/Object;)J",
|
||||
(void*) aFunctions[kFunc_GetNativeHandleFromAWT] }
|
||||
};
|
||||
|
||||
JNINativeMethod gre_methods[] = {
|
||||
|
@ -40,16 +40,24 @@ import java.io.File;
|
||||
|
||||
public interface IMozilla {
|
||||
|
||||
/**
|
||||
* Initialize the Mozilla object with the given XULRunner path. All
|
||||
* subsequent Mozilla method invocations be done against the given XULRunner
|
||||
* version.
|
||||
*
|
||||
* @param aLibXULDirectory path of XULRunner build to use
|
||||
*
|
||||
* @throws XPCOMInitializationException if failure occurred during
|
||||
* initialization
|
||||
*/
|
||||
void initialize(File aLibXULDirectory) throws XPCOMInitializationException;
|
||||
/**
|
||||
* Initialize the Mozilla object with the given XULRunner path. All
|
||||
* subsequent Mozilla method invocations be done against the given XULRunner
|
||||
* version.
|
||||
*
|
||||
* @param aLibXULDirectory path of XULRunner build to use
|
||||
*
|
||||
* @throws XPCOMInitializationException if failure occurred during
|
||||
* initialization
|
||||
*/
|
||||
void initialize(File aLibXULDirectory) throws XPCOMInitializationException;
|
||||
|
||||
/**
|
||||
* Return the native window handle for an AWT component.
|
||||
*
|
||||
* @param widget An AWT component (such as Canvas, Frame) that is backed by
|
||||
* a real native window.
|
||||
* @return the pointer to the native window (platform specific)
|
||||
*/
|
||||
long getNativeHandleFromAWT(Object widget);
|
||||
}
|
||||
|
@ -1026,4 +1026,13 @@ public class Mozilla implements IMozilla, IGRE, IXPCOM, IXPCOMError {
|
||||
return iid;
|
||||
}
|
||||
|
||||
public long getNativeHandleFromAWT(Object widget) {
|
||||
try {
|
||||
return mozilla.getNativeHandleFromAWT(widget);
|
||||
} catch (NullPointerException e) {
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
47
extensions/java/xpcom/src/MacJawt.mm
Normal file
47
extensions/java/xpcom/src/MacJawt.mm
Normal file
@ -0,0 +1,47 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Java XPCOM Bindings.
|
||||
*
|
||||
* The Initial Developer of the Original Code is IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* IBM Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Javier Pedemonte (jhpedemonte@gmail.com)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <jni.h>
|
||||
#import <JavaVM/jawt_md.h>
|
||||
#include "prtypes.h"
|
||||
|
||||
|
||||
PRUint64 GetPlatformHandle(JAWT_DrawingSurfaceInfo* dsi)
|
||||
{
|
||||
JAWT_MacOSXDrawingSurfaceInfo* dsi_mac =
|
||||
static_cast<JAWT_MacOSXDrawingSurfaceInfo*> (dsi->platformInfo);
|
||||
return reinterpret_cast<PRUint64> (dsi_mac->cocoaViewRef);
|
||||
}
|
@ -64,6 +64,10 @@ CPPSRCS = \
|
||||
nsJavaXPCOMBindingUtils.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH),Darwin)
|
||||
CMMSRCS = MacJawt.mm
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDES = -I$(JAVA_INCLUDE_PATH)
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
@ -72,9 +76,13 @@ else
|
||||
ifeq ($(OS_ARCH),OS2)
|
||||
LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/OS2
|
||||
else
|
||||
ifeq ($(OS_ARCH),Darwin)
|
||||
LOCAL_INCLUDES += -I/System/Library/Frameworks/CoreFoundation.framework/Headers
|
||||
else
|
||||
LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/linux
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# Don't set JAVA_LIBRARY_NAME, since we don't want to build during 'libs'
|
||||
# stage, but rather when explicitly called.
|
||||
|
@ -72,5 +72,7 @@ void XXXNeverCalled_javaxpcom()
|
||||
JAVAPROXY_NATIVE(isSameXPCOMObject) (nsnull, nsnull, nsnull, nsnull);
|
||||
|
||||
LOCKPROXY_NATIVE(release) (nsnull, nsnull, nsnull);
|
||||
|
||||
MOZILLA_NATIVE(getNativeHandleFromAWT) (nsnull, nsnull, nsnull);
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,10 @@
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
#include "jawt.h"
|
||||
#endif
|
||||
|
||||
|
||||
extern "C" NS_EXPORT void
|
||||
MOZILLA_NATIVE(initialize) (JNIEnv* env, jobject)
|
||||
@ -314,3 +318,41 @@ GRE_NATIVE(notifyProfile) (JNIEnv *env, jobject)
|
||||
XRE_NotifyProfile();
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
extern PRUint64 GetPlatformHandle(JAWT_DrawingSurfaceInfo* dsi);
|
||||
#endif
|
||||
|
||||
extern "C" NS_EXPORT jlong
|
||||
MOZILLA_NATIVE(getNativeHandleFromAWT) (JNIEnv* env, jobject clazz,
|
||||
jobject widget)
|
||||
{
|
||||
PRUint64 handle = 0;
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
JAWT awt;
|
||||
awt.version = JAWT_VERSION_1_4;
|
||||
jboolean result = JAWT_GetAWT(env, &awt);
|
||||
if (result == JNI_FALSE)
|
||||
return 0;
|
||||
|
||||
JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, widget);
|
||||
if (ds != nsnull) {
|
||||
jint lock = ds->Lock(ds);
|
||||
if (!(lock & JAWT_LOCK_ERROR)) {
|
||||
JAWT_DrawingSurfaceInfo* dsi = ds->GetDrawingSurfaceInfo(ds);
|
||||
if (dsi) {
|
||||
handle = GetPlatformHandle(dsi);
|
||||
ds->FreeDrawingSurfaceInfo(dsi);
|
||||
}
|
||||
|
||||
ds->Unlock(ds);
|
||||
}
|
||||
|
||||
awt.FreeDrawingSurface(ds);
|
||||
}
|
||||
#else
|
||||
NS_WARNING("getNativeHandleFromAWT JNI method not implemented");
|
||||
#endif
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
@ -104,4 +104,7 @@ JAVAPROXY_NATIVE(isSameXPCOMObject) (JNIEnv *env, jclass that, jobject aProxy1,
|
||||
extern "C" NS_EXPORT void
|
||||
LOCKPROXY_NATIVE(release) (JNIEnv *env, jclass that, jlong aLockObject);
|
||||
|
||||
extern "C" NS_EXPORT jlong
|
||||
MOZILLA_NATIVE(getNativeHandleFromAWT) (JNIEnv* env, jobject, jobject widget);
|
||||
|
||||
#endif // _nsJavaInterfaces_h_
|
||||
|
@ -43,12 +43,14 @@ import org.mozilla.xpcom.XPCOMInitializationException;
|
||||
|
||||
public class MozillaImpl implements IMozilla {
|
||||
|
||||
public void initialize(File aLibXULDirectory)
|
||||
throws XPCOMInitializationException {
|
||||
JavaXPCOMMethods.registerJavaXPCOMMethods(aLibXULDirectory);
|
||||
initializeNative();
|
||||
}
|
||||
public void initialize(File aLibXULDirectory)
|
||||
throws XPCOMInitializationException {
|
||||
JavaXPCOMMethods.registerJavaXPCOMMethods(aLibXULDirectory);
|
||||
initializeNative();
|
||||
}
|
||||
|
||||
private native void initializeNative();
|
||||
private native void initializeNative();
|
||||
|
||||
public native long getNativeHandleFromAWT(Object widget);
|
||||
|
||||
}
|
||||
|
@ -97,15 +97,21 @@ LOCAL_INCLUDES += \
|
||||
-I$(topsrcdir)/extensions/java/xpcom/src \
|
||||
-I$(JAVA_INCLUDE_PATH) \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
CPPSRCS += dlldeps-javaxpcom.cpp
|
||||
LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/win32
|
||||
else
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
EXTRA_DSO_LDOPTS += -framework JavaVM
|
||||
else
|
||||
LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/linux
|
||||
endif
|
||||
endif
|
||||
|
||||
SHARED_LIBRARY_LIBS += \
|
||||
$(DEPTH)/extensions/java/xpcom/src/$(LIB_PREFIX)javaxpcom.$(LIB_SUFFIX)
|
||||
endif
|
||||
endif #MOZ_JAVAXPCOM
|
||||
|
||||
ifdef MOZ_ENABLE_LIBXUL
|
||||
include $(srcdir)/libxul-config.mk
|
||||
|
Loading…
Reference in New Issue
Block a user