Directly using VirtualBox from Java #5
43 changed files with 11633 additions and 14 deletions
47
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/MacJawt.mm
Executable file
47
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/MacJawt.mm
Executable 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);
|
||||||
|
}
|
81
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/dlldeps-javaxpcom.cpp
Executable file
81
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/dlldeps-javaxpcom.cpp
Executable file
|
@ -0,0 +1,81 @@
|
||||||
|
/* ***** 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 "nsJavaInterfaces.h"
|
||||||
|
|
||||||
|
|
||||||
|
void XXXNeverCalled_javaxpcom()
|
||||||
|
{
|
||||||
|
MOZILLA_NATIVE(initialize) (nsnull, nsnull);
|
||||||
|
|
||||||
|
GRE_NATIVE(initEmbedding) (nsnull, nsnull, nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
GRE_NATIVE(termEmbedding) (nsnull, nsnull);
|
||||||
|
|
||||||
|
GRE_NATIVE(lockProfileDirectory) (nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
GRE_NATIVE(notifyProfile) (nsnull, nsnull);
|
||||||
|
|
||||||
|
GRE_NATIVE(lockProfileDirectory) (nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
GRE_NATIVE(notifyProfile) (nsnull, nsnull);
|
||||||
|
|
||||||
|
XPCOM_NATIVE(initXPCOM) (nsnull, nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
XPCOM_NATIVE(shutdownXPCOM) (nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
XPCOM_NATIVE(newLocalFile) (nsnull, nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
XPCOM_NATIVE(getComponentManager) (nsnull, nsnull);
|
||||||
|
|
||||||
|
XPCOM_NATIVE(getComponentRegistrar) (nsnull, nsnull);
|
||||||
|
|
||||||
|
XPCOM_NATIVE(getServiceManager) (nsnull, nsnull);
|
||||||
|
|
||||||
|
JAVAPROXY_NATIVE(callXPCOMMethod) (nsnull, nsnull, nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
JAVAPROXY_NATIVE(finalizeProxy) (nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
JAVAPROXY_NATIVE(isSameXPCOMObject) (nsnull, nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
LOCKPROXY_NATIVE(release) (nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
MOZILLA_NATIVE(getNativeHandleFromAWT) (nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
JXUTILS_NATIVE(wrapJavaObject) (nsnull, nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
JXUTILS_NATIVE(wrapXPCOMObject) (nsnull, nsnull, nsnull, nsnull);
|
||||||
|
}
|
253
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsAppFileLocProviderProxy.cpp
Executable file
253
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsAppFileLocProviderProxy.cpp
Executable file
|
@ -0,0 +1,253 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 "nsAppFileLocProviderProxy.h"
|
||||||
|
#include "nsJavaXPCOMBindingUtils.h"
|
||||||
|
#include "nsILocalFile.h"
|
||||||
|
#include "nsISimpleEnumerator.h"
|
||||||
|
|
||||||
|
|
||||||
|
nsAppFileLocProviderProxy::nsAppFileLocProviderProxy(jobject aJavaObject)
|
||||||
|
{
|
||||||
|
mJavaLocProvider = GetJNIEnv()->NewGlobalRef(aJavaObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAppFileLocProviderProxy::~nsAppFileLocProviderProxy()
|
||||||
|
{
|
||||||
|
GetJNIEnv()->DeleteGlobalRef(mJavaLocProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS2(nsAppFileLocProviderProxy,
|
||||||
|
nsIDirectoryServiceProvider,
|
||||||
|
nsIDirectoryServiceProvider2)
|
||||||
|
|
||||||
|
|
||||||
|
// nsIDirectoryServiceProvider
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsAppFileLocProviderProxy::GetFile(const char* aProp, PRBool* aIsPersistant,
|
||||||
|
nsIFile** aResult)
|
||||||
|
{
|
||||||
|
// Setup params for calling Java function
|
||||||
|
JNIEnv* env = GetJNIEnv();
|
||||||
|
jstring prop = env->NewStringUTF(aProp);
|
||||||
|
if (!prop)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
jbooleanArray persistant = env->NewBooleanArray(1);
|
||||||
|
if (!persistant)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
// Create method ID
|
||||||
|
jmethodID mid = nsnull;
|
||||||
|
jclass clazz = env->GetObjectClass(mJavaLocProvider);
|
||||||
|
if (clazz) {
|
||||||
|
mid = env->GetMethodID(clazz, "getFile",
|
||||||
|
"(Ljava/lang/String;[Z)Ljava/io/File;");
|
||||||
|
}
|
||||||
|
if (!mid)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
// Call Java function
|
||||||
|
jobject javaFile = nsnull;
|
||||||
|
javaFile = env->CallObjectMethod(mJavaLocProvider, mid, prop, persistant);
|
||||||
|
if (javaFile == nsnull || env->ExceptionCheck())
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
// Set boolean output value
|
||||||
|
env->GetBooleanArrayRegion(persistant, 0, 1, (jboolean*) aIsPersistant);
|
||||||
|
|
||||||
|
// Set nsIFile result value
|
||||||
|
nsCOMPtr<nsILocalFile> localFile;
|
||||||
|
nsresult rv = File_to_nsILocalFile(env, javaFile, getter_AddRefs(localFile));
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// nsIDirectoryServiceProvider2
|
||||||
|
|
||||||
|
class DirectoryEnumerator : public nsISimpleEnumerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
DirectoryEnumerator(jobjectArray aJavaFileArray)
|
||||||
|
: mIndex(0)
|
||||||
|
{
|
||||||
|
JNIEnv* env = GetJNIEnv();
|
||||||
|
mJavaFileArray = static_cast<jobjectArray>
|
||||||
|
(env->NewGlobalRef(aJavaFileArray));
|
||||||
|
mArraySize = env->GetArrayLength(aJavaFileArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
~DirectoryEnumerator()
|
||||||
|
{
|
||||||
|
GetJNIEnv()->DeleteGlobalRef(mJavaFileArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHOD HasMoreElements(PRBool* aResult)
|
||||||
|
{
|
||||||
|
if (!mJavaFileArray) {
|
||||||
|
*aResult = PR_FALSE;
|
||||||
|
} else {
|
||||||
|
*aResult = (mIndex < mArraySize);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHOD GetNext(nsISupports** aResult)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
JNIEnv* env = GetJNIEnv();
|
||||||
|
jobject javaFile = env->GetObjectArrayElement(mJavaFileArray, mIndex++);
|
||||||
|
if (javaFile) {
|
||||||
|
nsCOMPtr<nsILocalFile> localFile;
|
||||||
|
rv = File_to_nsILocalFile(env, javaFile, getter_AddRefs(localFile));
|
||||||
|
env->DeleteLocalRef(javaFile);
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
env->ExceptionClear();
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
jobjectArray mJavaFileArray;
|
||||||
|
PRUint32 mArraySize;
|
||||||
|
PRUint32 mIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS1(DirectoryEnumerator, nsISimpleEnumerator)
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsAppFileLocProviderProxy::GetFiles(const char* aProp,
|
||||||
|
nsISimpleEnumerator** aResult)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
// Setup params for calling Java function
|
||||||
|
JNIEnv* env = GetJNIEnv();
|
||||||
|
jstring prop = env->NewStringUTF(aProp);
|
||||||
|
if (!prop)
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
// Create method ID
|
||||||
|
jmethodID mid = nsnull;
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
jclass clazz = env->GetObjectClass(mJavaLocProvider);
|
||||||
|
if (clazz) {
|
||||||
|
mid = env->GetMethodID(clazz, "getFiles",
|
||||||
|
"(Ljava/lang/String;)[Ljava/io/File;");
|
||||||
|
env->DeleteLocalRef(clazz);
|
||||||
|
}
|
||||||
|
if (!mid)
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call Java function
|
||||||
|
jobject javaFileArray = nsnull;
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
javaFileArray = env->CallObjectMethod(mJavaLocProvider, mid, prop);
|
||||||
|
|
||||||
|
// Handle any exception thrown by Java method.
|
||||||
|
jthrowable exp = env->ExceptionOccurred();
|
||||||
|
if (exp) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
env->ExceptionDescribe();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If the exception is an instance of XPCOMException, then get the
|
||||||
|
// nsresult from the exception instance. Else, default to
|
||||||
|
// NS_ERROR_FAILURE.
|
||||||
|
if (env->IsInstanceOf(exp, xpcomExceptionClass)) {
|
||||||
|
jfieldID fid;
|
||||||
|
fid = env->GetFieldID(xpcomExceptionClass, "errorcode", "J");
|
||||||
|
if (fid) {
|
||||||
|
rv = env->GetLongField(exp, fid);
|
||||||
|
} else {
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
NS_ASSERTION(fid, "Couldn't get 'errorcode' field of XPCOMException");
|
||||||
|
} else {
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No exception thrown. Check the result.
|
||||||
|
if (javaFileArray == nsnull) {
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
// Parse return value
|
||||||
|
*aResult = new DirectoryEnumerator(static_cast<jobjectArray>
|
||||||
|
(javaFileArray));
|
||||||
|
NS_ADDREF(*aResult);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle error conditions
|
||||||
|
*aResult = nsnull;
|
||||||
|
env->ExceptionClear();
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
NS_NewAppFileLocProviderProxy(jobject aJavaLocProvider,
|
||||||
|
nsIDirectoryServiceProvider** aResult)
|
||||||
|
{
|
||||||
|
nsAppFileLocProviderProxy* provider =
|
||||||
|
new nsAppFileLocProviderProxy(aJavaLocProvider);
|
||||||
|
if (provider == nsnull)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
NS_ADDREF(provider);
|
||||||
|
|
||||||
|
*aResult = provider;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
65
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsAppFileLocProviderProxy.h
Executable file
65
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsAppFileLocProviderProxy.h
Executable file
|
@ -0,0 +1,65 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef _nsAppFileLocProviderProxy_h_
|
||||||
|
#define _nsAppFileLocProviderProxy_h_
|
||||||
|
|
||||||
|
#include "nsIDirectoryService.h"
|
||||||
|
#include "jni.h"
|
||||||
|
|
||||||
|
|
||||||
|
class nsAppFileLocProviderProxy : public nsIDirectoryServiceProvider2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsAppFileLocProviderProxy(jobject aJavaLocProvider);
|
||||||
|
~nsAppFileLocProviderProxy();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
|
||||||
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
|
||||||
|
|
||||||
|
private:
|
||||||
|
jobject mJavaLocProvider;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" nsresult
|
||||||
|
NS_NewAppFileLocProviderProxy(jobject aJavaLocProvider,
|
||||||
|
nsIDirectoryServiceProvider** aResult);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //_nsAppFileLocProviderProxy_h_
|
||||||
|
|
475
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsFileStreams.cpp
Executable file
475
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsFileStreams.cpp
Executable file
|
@ -0,0 +1,475 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* ***** 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 mozilla.org code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Netscape Communications Corporation.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif defined(XP_MAC)
|
||||||
|
#include <Files.h>
|
||||||
|
#elif defined(XP_WIN)
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(XP_OS2)
|
||||||
|
#define INCL_DOSERRORS
|
||||||
|
#include <os2.h>
|
||||||
|
#else
|
||||||
|
// XXX add necessary include file for ftruncate (or equivalent)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(XP_MAC)
|
||||||
|
#include "pprio.h"
|
||||||
|
#else
|
||||||
|
#include "private/pprio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "nsFileStreams.h"
|
||||||
|
#include "nsILocalFile.h"
|
||||||
|
#include "nsXPIDLString.h"
|
||||||
|
#include "prerror.h"
|
||||||
|
#include "nsCRT.h"
|
||||||
|
#include "nsInt64.h"
|
||||||
|
#include "nsIFile.h"
|
||||||
|
|
||||||
|
#define NS_NO_INPUT_BUFFERING 1 // see http://bugzilla.mozilla.org/show_bug.cgi?id=41067
|
||||||
|
|
||||||
|
#if defined(PR_LOGGING)
|
||||||
|
//
|
||||||
|
// Log module for nsFileTransport logging...
|
||||||
|
//
|
||||||
|
// To enable logging (see prlog.h for full details):
|
||||||
|
//
|
||||||
|
// set NSPR_LOG_MODULES=nsFileIO:5
|
||||||
|
// set NSPR_LOG_FILE=nspr.log
|
||||||
|
//
|
||||||
|
// this enables PR_LOG_DEBUG level information and places all output in
|
||||||
|
// the file nspr.log
|
||||||
|
//
|
||||||
|
PRLogModuleInfo* gFileIOLog = nsnull;
|
||||||
|
|
||||||
|
#endif /* PR_LOGGING */
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// nsFileStream
|
||||||
|
|
||||||
|
nsFileStream::nsFileStream()
|
||||||
|
: mFD(nsnull)
|
||||||
|
, mCloseFD(PR_TRUE)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
nsFileStream::~nsFileStream()
|
||||||
|
{
|
||||||
|
if (mCloseFD)
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsFileStream, nsISeekableStream)
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsFileStream::InitWithFileDescriptor(PRFileDesc* fd, nsISupports* parent)
|
||||||
|
{
|
||||||
|
NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED);
|
||||||
|
//
|
||||||
|
// this file stream is dependent on its parent to keep the
|
||||||
|
// file descriptor valid. an owning reference to the parent
|
||||||
|
// prevents the file descriptor from going away prematurely.
|
||||||
|
//
|
||||||
|
mFD = fd;
|
||||||
|
mCloseFD = PR_FALSE;
|
||||||
|
mParent = parent;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsFileStream::Close()
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
if (mFD) {
|
||||||
|
if (mCloseFD)
|
||||||
|
if (PR_Close(mFD) == PR_FAILURE)
|
||||||
|
rv = NS_BASE_STREAM_OSERROR;
|
||||||
|
mFD = nsnull;
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileStream::Seek(PRInt32 whence, PRInt64 offset)
|
||||||
|
{
|
||||||
|
if (mFD == nsnull)
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
|
||||||
|
nsInt64 cnt = PR_Seek64(mFD, offset, (PRSeekWhence)whence);
|
||||||
|
if (cnt == nsInt64(-1)) {
|
||||||
|
return NS_ErrorAccordingToNSPR();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileStream::Tell(PRInt64 *result)
|
||||||
|
{
|
||||||
|
if (mFD == nsnull)
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
|
||||||
|
nsInt64 cnt = PR_Seek64(mFD, 0, PR_SEEK_CUR);
|
||||||
|
if (cnt == nsInt64(-1)) {
|
||||||
|
return NS_ErrorAccordingToNSPR();
|
||||||
|
}
|
||||||
|
*result = cnt;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileStream::SetEOF()
|
||||||
|
{
|
||||||
|
if (mFD == nsnull)
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
|
||||||
|
#if defined(XP_UNIX) || defined(XP_MAC) || defined(XP_OS2) || defined(XP_BEOS)
|
||||||
|
// Some system calls require an EOF offset.
|
||||||
|
PRInt64 offset;
|
||||||
|
nsresult rv = Tell(&offset);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
||||||
|
if (ftruncate(PR_FileDesc2NativeHandle(mFD), offset) != 0) {
|
||||||
|
NS_ERROR("ftruncate failed");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
#elif defined(XP_MAC)
|
||||||
|
if (::SetEOF(PR_FileDesc2NativeHandle(mFD), offset) != 0) {
|
||||||
|
NS_ERROR("SetEOF failed");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
#elif defined(XP_WIN)
|
||||||
|
if (!SetEndOfFile((HANDLE) PR_FileDesc2NativeHandle(mFD))) {
|
||||||
|
NS_ERROR("SetEndOfFile failed");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
#elif defined(XP_OS2)
|
||||||
|
if (DosSetFileSize((HFILE) PR_FileDesc2NativeHandle(mFD), offset) != NO_ERROR) {
|
||||||
|
NS_ERROR("DosSetFileSize failed");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// XXX not implemented
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// nsFileInputStream
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS_INHERITED3(nsFileInputStream,
|
||||||
|
nsFileStream,
|
||||||
|
nsIInputStream,
|
||||||
|
nsIFileInputStream,
|
||||||
|
nsILineInputStream)
|
||||||
|
|
||||||
|
NS_METHOD
|
||||||
|
nsFileInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||||
|
{
|
||||||
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
||||||
|
|
||||||
|
nsFileInputStream* stream = new nsFileInputStream();
|
||||||
|
if (stream == nsnull)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
NS_ADDREF(stream);
|
||||||
|
nsresult rv = stream->QueryInterface(aIID, aResult);
|
||||||
|
NS_RELEASE(stream);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsFileInputStream::Open(nsIFile* aFile, PRInt32 aIOFlags, PRInt32 aPerm)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
// If the previous file is open, close it
|
||||||
|
if (mFD) {
|
||||||
|
rv = Close();
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open the file
|
||||||
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile, &rv);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
if (aIOFlags == -1)
|
||||||
|
aIOFlags = PR_RDONLY;
|
||||||
|
if (aPerm == -1)
|
||||||
|
aPerm = 0;
|
||||||
|
|
||||||
|
PRFileDesc* fd;
|
||||||
|
rv = localFile->OpenNSPRFileDesc(aIOFlags, aPerm, &fd);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
mFD = fd;
|
||||||
|
|
||||||
|
if (mBehaviorFlags & DELETE_ON_CLOSE) {
|
||||||
|
// POSIX compatible filesystems allow a file to be unlinked while a
|
||||||
|
// file descriptor is still referencing the file. since we've already
|
||||||
|
// opened the file descriptor, we'll try to remove the file. if that
|
||||||
|
// fails, then we'll just remember the nsIFile and remove it after we
|
||||||
|
// close the file descriptor.
|
||||||
|
rv = aFile->Remove(PR_FALSE);
|
||||||
|
if (NS_FAILED(rv) && !(mBehaviorFlags & REOPEN_ON_REWIND)) {
|
||||||
|
// If REOPEN_ON_REWIND is not happenin', we haven't saved the file yet
|
||||||
|
mFile = aFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::Init(nsIFile* aFile, PRInt32 aIOFlags, PRInt32 aPerm,
|
||||||
|
PRInt32 aBehaviorFlags)
|
||||||
|
{
|
||||||
|
NS_ENSURE_TRUE(!mFD, NS_ERROR_ALREADY_INITIALIZED);
|
||||||
|
NS_ENSURE_TRUE(!mParent, NS_ERROR_ALREADY_INITIALIZED);
|
||||||
|
|
||||||
|
mBehaviorFlags = aBehaviorFlags;
|
||||||
|
|
||||||
|
// If the file will be reopened on rewind, save the info to open the file
|
||||||
|
if (mBehaviorFlags & REOPEN_ON_REWIND) {
|
||||||
|
mFile = aFile;
|
||||||
|
mIOFlags = aIOFlags;
|
||||||
|
mPerm = aPerm;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Open(aFile, aIOFlags, aPerm);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::Close()
|
||||||
|
{
|
||||||
|
nsresult rv = nsFileStream::Close();
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
if (mFile && (mBehaviorFlags & DELETE_ON_CLOSE)) {
|
||||||
|
rv = mFile->Remove(PR_FALSE);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to delete file");
|
||||||
|
// If we don't need to save the file for reopening, free it up
|
||||||
|
if (!(mBehaviorFlags & REOPEN_ON_REWIND)) {
|
||||||
|
mFile = nsnull;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::Available(PRUint32* aResult)
|
||||||
|
{
|
||||||
|
if (!mFD) {
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRInt32 avail = PR_Available(mFD);
|
||||||
|
if (avail == -1) {
|
||||||
|
return NS_ErrorAccordingToNSPR();
|
||||||
|
}
|
||||||
|
*aResult = avail;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aResult)
|
||||||
|
{
|
||||||
|
if (!mFD) {
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRInt32 bytesRead = PR_Read(mFD, aBuf, aCount);
|
||||||
|
if (bytesRead == -1) {
|
||||||
|
return NS_ErrorAccordingToNSPR();
|
||||||
|
}
|
||||||
|
// Check if we're at the end of file and need to close
|
||||||
|
if (mBehaviorFlags & CLOSE_ON_EOF) {
|
||||||
|
if (bytesRead == 0) {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*aResult = bytesRead;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::ReadLine(nsACString& aLine, PRBool* aResult)
|
||||||
|
{
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
|
||||||
|
PRUint32 aCount, PRUint32* aResult)
|
||||||
|
{
|
||||||
|
// ReadSegments is not implemented because it would be inefficient when
|
||||||
|
// the writer does not consume all data. If you want to call ReadSegments,
|
||||||
|
// wrap a BufferedInputStream around the file stream. That will call
|
||||||
|
// Read().
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::IsNonBlocking(PRBool *aNonBlocking)
|
||||||
|
{
|
||||||
|
*aNonBlocking = PR_FALSE;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileInputStream::Seek(PRInt32 aWhence, PRInt64 aOffset)
|
||||||
|
{
|
||||||
|
if (!mFD) {
|
||||||
|
if (mBehaviorFlags & REOPEN_ON_REWIND) {
|
||||||
|
nsresult rv = Reopen();
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsFileStream::Seek(aWhence, aOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// nsFileOutputStream
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS_INHERITED2(nsFileOutputStream,
|
||||||
|
nsFileStream,
|
||||||
|
nsIOutputStream,
|
||||||
|
nsIFileOutputStream)
|
||||||
|
|
||||||
|
NS_METHOD
|
||||||
|
nsFileOutputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||||
|
{
|
||||||
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
||||||
|
|
||||||
|
nsFileOutputStream* stream = new nsFileOutputStream();
|
||||||
|
if (stream == nsnull)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
NS_ADDREF(stream);
|
||||||
|
nsresult rv = stream->QueryInterface(aIID, aResult);
|
||||||
|
NS_RELEASE(stream);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileOutputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm,
|
||||||
|
PRInt32 behaviorFlags)
|
||||||
|
{
|
||||||
|
NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED);
|
||||||
|
|
||||||
|
nsresult rv;
|
||||||
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
if (ioFlags == -1)
|
||||||
|
ioFlags = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE;
|
||||||
|
if (perm <= 0)
|
||||||
|
perm = 0664;
|
||||||
|
|
||||||
|
PRFileDesc* fd;
|
||||||
|
rv = localFile->OpenNSPRFileDesc(ioFlags, perm, &fd);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
mFD = fd;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileOutputStream::Close()
|
||||||
|
{
|
||||||
|
return nsFileStream::Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileOutputStream::Write(const char *buf, PRUint32 count, PRUint32 *result)
|
||||||
|
{
|
||||||
|
if (mFD == nsnull)
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
|
||||||
|
PRInt32 cnt = PR_Write(mFD, buf, count);
|
||||||
|
if (cnt == -1) {
|
||||||
|
return NS_ErrorAccordingToNSPR();
|
||||||
|
}
|
||||||
|
*result = cnt;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileOutputStream::Flush(void)
|
||||||
|
{
|
||||||
|
if (mFD == nsnull)
|
||||||
|
return NS_BASE_STREAM_CLOSED;
|
||||||
|
|
||||||
|
PRInt32 cnt = PR_Sync(mFD);
|
||||||
|
if (cnt == -1) {
|
||||||
|
return NS_ErrorAccordingToNSPR();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileOutputStream::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)
|
||||||
|
{
|
||||||
|
NS_NOTREACHED("WriteFrom (see source comment)");
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
// File streams intentionally do not support this method.
|
||||||
|
// If you need something like this, then you should wrap
|
||||||
|
// the file stream using nsIBufferedOutputStream
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||||
|
{
|
||||||
|
NS_NOTREACHED("WriteSegments (see source comment)");
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
// File streams intentionally do not support this method.
|
||||||
|
// If you need something like this, then you should wrap
|
||||||
|
// the file stream using nsIBufferedOutputStream
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileOutputStream::IsNonBlocking(PRBool *aNonBlocking)
|
||||||
|
{
|
||||||
|
*aNonBlocking = PR_FALSE;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
153
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsFileStreams.h
Executable file
153
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsFileStreams.h
Executable file
|
@ -0,0 +1,153 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/* ***** 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 mozilla.org code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Netscape Communications Corporation.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef nsFileStreams_h__
|
||||||
|
#define nsFileStreams_h__
|
||||||
|
|
||||||
|
#include "nsIFileStreams.h"
|
||||||
|
#include "nsIFile.h"
|
||||||
|
#include "nsIInputStream.h"
|
||||||
|
#include "nsIOutputStream.h"
|
||||||
|
#include "nsISeekableStream.h"
|
||||||
|
#include "nsILineInputStream.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "prlog.h"
|
||||||
|
#include "prio.h"
|
||||||
|
|
||||||
|
template<class CharType> class nsLineBuffer;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class nsFileStream : public nsISeekableStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSISEEKABLESTREAM
|
||||||
|
|
||||||
|
nsFileStream();
|
||||||
|
virtual ~nsFileStream();
|
||||||
|
|
||||||
|
nsresult Close();
|
||||||
|
nsresult InitWithFileDescriptor(PRFileDesc* fd, nsISupports* parent);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PRFileDesc* mFD;
|
||||||
|
nsCOMPtr<nsISupports> mParent; // strong reference to parent nsFileIO,
|
||||||
|
// which ensures mFD remains valid.
|
||||||
|
PRBool mCloseFD;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class nsFileInputStream : public nsFileStream,
|
||||||
|
public nsIFileInputStream,
|
||||||
|
public nsILineInputStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
NS_DECL_NSIINPUTSTREAM
|
||||||
|
NS_DECL_NSIFILEINPUTSTREAM
|
||||||
|
NS_DECL_NSILINEINPUTSTREAM
|
||||||
|
|
||||||
|
// Overrided from nsFileStream
|
||||||
|
NS_IMETHOD Seek(PRInt32 aWhence, PRInt64 aOffset);
|
||||||
|
|
||||||
|
nsFileInputStream() : nsFileStream()
|
||||||
|
{
|
||||||
|
mBehaviorFlags = 0;
|
||||||
|
}
|
||||||
|
virtual ~nsFileInputStream()
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
static NS_METHOD
|
||||||
|
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* The file being opened. Only stored when DELETE_ON_CLOSE or
|
||||||
|
* REOPEN_ON_REWIND are true.
|
||||||
|
*/
|
||||||
|
nsCOMPtr<nsIFile> mFile;
|
||||||
|
/**
|
||||||
|
* The IO flags passed to Init() for the file open.
|
||||||
|
* Only set for REOPEN_ON_REWIND.
|
||||||
|
*/
|
||||||
|
PRInt32 mIOFlags;
|
||||||
|
/**
|
||||||
|
* The permissions passed to Init() for the file open.
|
||||||
|
* Only set for REOPEN_ON_REWIND.
|
||||||
|
*/
|
||||||
|
PRInt32 mPerm;
|
||||||
|
/**
|
||||||
|
* Flags describing our behavior. See the IDL file for possible values.
|
||||||
|
*/
|
||||||
|
PRInt32 mBehaviorFlags;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* Internal, called to open a file. Parameters are the same as their
|
||||||
|
* Init() analogues.
|
||||||
|
*/
|
||||||
|
nsresult Open(nsIFile* file, PRInt32 ioFlags, PRInt32 perm);
|
||||||
|
/**
|
||||||
|
* Reopen the file (for OPEN_ON_READ only!)
|
||||||
|
*/
|
||||||
|
nsresult Reopen() { return Open(mFile, mIOFlags, mPerm); }
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class nsFileOutputStream : public nsFileStream,
|
||||||
|
public nsIFileOutputStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
NS_DECL_NSIOUTPUTSTREAM
|
||||||
|
NS_DECL_NSIFILEOUTPUTSTREAM
|
||||||
|
|
||||||
|
nsFileOutputStream() : nsFileStream() {}
|
||||||
|
virtual ~nsFileOutputStream() { nsFileOutputStream::Close(); }
|
||||||
|
|
||||||
|
static NS_METHOD
|
||||||
|
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#endif // nsFileStreams_h__
|
209
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsIFileStreams.h
Executable file
209
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsIFileStreams.h
Executable file
|
@ -0,0 +1,209 @@
|
||||||
|
/*
|
||||||
|
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsIFileStreams.idl
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __gen_nsIFileStreams_h__
|
||||||
|
#define __gen_nsIFileStreams_h__
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __gen_nsIInputStream_h__
|
||||||
|
#include "nsIInputStream.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __gen_nsIOutputStream_h__
|
||||||
|
#include "nsIOutputStream.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* For IDL files that don't want to include root IDL files. */
|
||||||
|
#ifndef NS_NO_VTABLE
|
||||||
|
#define NS_NO_VTABLE
|
||||||
|
#endif
|
||||||
|
class nsIFile; /* forward declaration */
|
||||||
|
|
||||||
|
|
||||||
|
/* starting interface: nsIFileInputStream */
|
||||||
|
#define NS_IFILEINPUTSTREAM_IID_STR "e3d56a20-c7ec-11d3-8cda-0060b0fc14a3"
|
||||||
|
|
||||||
|
#define NS_IFILEINPUTSTREAM_IID \
|
||||||
|
{0xe3d56a20, 0xc7ec, 0x11d3, \
|
||||||
|
{ 0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3 }}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An input stream that allows you to read from a file.
|
||||||
|
*/
|
||||||
|
class NS_NO_VTABLE nsIFileInputStream : public nsIInputStream {
|
||||||
|
public:
|
||||||
|
|
||||||
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFILEINPUTSTREAM_IID)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param file file to read from (must QI to nsILocalFile)
|
||||||
|
* @param ioFlags file open flags listed in prio.h
|
||||||
|
* @param perm file mode bits listed in prio.h
|
||||||
|
* @param behaviorFlags flags specifying various behaviors of the class
|
||||||
|
* (see enumerations in the class)
|
||||||
|
*/
|
||||||
|
/* void init (in nsIFile file, in long ioFlags, in long perm, in long behaviorFlags); */
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this is set, the file will be deleted by the time the stream is
|
||||||
|
* closed. It may be removed before the stream is closed if it is possible
|
||||||
|
* to delete it and still read from it.
|
||||||
|
*
|
||||||
|
* If OPEN_ON_READ is defined, and the file was recreated after the first
|
||||||
|
* delete, the file will be deleted again when it is closed again.
|
||||||
|
*/
|
||||||
|
enum { DELETE_ON_CLOSE = 2 };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this is set, the file will close automatically when the end of the
|
||||||
|
* file is reached.
|
||||||
|
*/
|
||||||
|
enum { CLOSE_ON_EOF = 4 };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this is set, the file will be reopened whenever Seek(0) occurs. If
|
||||||
|
* the file is already open and the seek occurs, it will happen naturally.
|
||||||
|
* (The file will only be reopened if it is closed for some reason.)
|
||||||
|
*/
|
||||||
|
enum { REOPEN_ON_REWIND = 8 };
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Use this macro when declaring classes that implement this interface. */
|
||||||
|
#define NS_DECL_NSIFILEINPUTSTREAM \
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags); \
|
||||||
|
|
||||||
|
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
||||||
|
#define NS_FORWARD_NSIFILEINPUTSTREAM(_to) \
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags) { return _to Init(file, ioFlags, perm, behaviorFlags); } \
|
||||||
|
|
||||||
|
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
|
||||||
|
#define NS_FORWARD_SAFE_NSIFILEINPUTSTREAM(_to) \
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags) { return !_to ? NS_ERROR_NULL_POINTER : _to->Init(file, ioFlags, perm, behaviorFlags); } \
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Use the code below as a template for the implementation class for this interface. */
|
||||||
|
|
||||||
|
/* Header file */
|
||||||
|
class nsFileInputStream : public nsIFileInputStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIFILEINPUTSTREAM
|
||||||
|
|
||||||
|
nsFileInputStream();
|
||||||
|
|
||||||
|
private:
|
||||||
|
~nsFileInputStream();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* additional members */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Implementation file */
|
||||||
|
NS_IMPL_ISUPPORTS1(nsFileInputStream, nsIFileInputStream)
|
||||||
|
|
||||||
|
nsFileInputStream::nsFileInputStream()
|
||||||
|
{
|
||||||
|
/* member initializers and constructor code */
|
||||||
|
}
|
||||||
|
|
||||||
|
nsFileInputStream::~nsFileInputStream()
|
||||||
|
{
|
||||||
|
/* destructor code */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* void init (in nsIFile file, in long ioFlags, in long perm, in long behaviorFlags); */
|
||||||
|
NS_IMETHODIMP nsFileInputStream::Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags)
|
||||||
|
{
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of implementation class template. */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* starting interface: nsIFileOutputStream */
|
||||||
|
#define NS_IFILEOUTPUTSTREAM_IID_STR "e6f68040-c7ec-11d3-8cda-0060b0fc14a3"
|
||||||
|
|
||||||
|
#define NS_IFILEOUTPUTSTREAM_IID \
|
||||||
|
{0xe6f68040, 0xc7ec, 0x11d3, \
|
||||||
|
{ 0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3 }}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An output stream that lets you stream to a file.
|
||||||
|
*/
|
||||||
|
class NS_NO_VTABLE nsIFileOutputStream : public nsIOutputStream {
|
||||||
|
public:
|
||||||
|
|
||||||
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFILEOUTPUTSTREAM_IID)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param file - file to write to (must QI to nsILocalFile)
|
||||||
|
* @param ioFlags - file open flags listed in prio.h
|
||||||
|
* @param perm - file mode bits listed in prio.h
|
||||||
|
* @param behaviorFlags flags specifying various behaviors of the class
|
||||||
|
* (currently none supported)
|
||||||
|
*/
|
||||||
|
/* void init (in nsIFile file, in long ioFlags, in long perm, in long behaviorFlags); */
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Use this macro when declaring classes that implement this interface. */
|
||||||
|
#define NS_DECL_NSIFILEOUTPUTSTREAM \
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags);
|
||||||
|
|
||||||
|
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
||||||
|
#define NS_FORWARD_NSIFILEOUTPUTSTREAM(_to) \
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags) { return _to Init(file, ioFlags, perm, behaviorFlags); }
|
||||||
|
|
||||||
|
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
|
||||||
|
#define NS_FORWARD_SAFE_NSIFILEOUTPUTSTREAM(_to) \
|
||||||
|
NS_IMETHOD Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags) { return !_to ? NS_ERROR_NULL_POINTER : _to->Init(file, ioFlags, perm, behaviorFlags); }
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Use the code below as a template for the implementation class for this interface. */
|
||||||
|
|
||||||
|
/* Header file */
|
||||||
|
class nsFileOutputStream : public nsIFileOutputStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIFILEOUTPUTSTREAM
|
||||||
|
|
||||||
|
nsFileOutputStream();
|
||||||
|
|
||||||
|
private:
|
||||||
|
~nsFileOutputStream();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* additional members */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Implementation file */
|
||||||
|
NS_IMPL_ISUPPORTS1(nsFileOutputStream, nsIFileOutputStream)
|
||||||
|
|
||||||
|
nsFileOutputStream::nsFileOutputStream()
|
||||||
|
{
|
||||||
|
/* member initializers and constructor code */
|
||||||
|
}
|
||||||
|
|
||||||
|
nsFileOutputStream::~nsFileOutputStream()
|
||||||
|
{
|
||||||
|
/* destructor code */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* void init (in nsIFile file, in long ioFlags, in long perm, in long behaviorFlags); */
|
||||||
|
NS_IMETHODIMP nsFileOutputStream::Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm, PRInt32 behaviorFlags)
|
||||||
|
{
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of implementation class template. */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __gen_nsIFileStreams_h__ */
|
557
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaInterfaces.cpp
Executable file
557
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaInterfaces.cpp
Executable file
|
@ -0,0 +1,557 @@
|
||||||
|
/* ***** 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) 2007
|
||||||
|
* 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 "nsJavaInterfaces.h"
|
||||||
|
#include "nsJavaWrapper.h"
|
||||||
|
#include "nsJavaXPCOMBindingUtils.h"
|
||||||
|
#include "nsJavaXPTCStub.h"
|
||||||
|
#include "nsIComponentRegistrar.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsISimpleEnumerator.h"
|
||||||
|
#include "nsIInterfaceInfoManager.h"
|
||||||
|
#include "nsIInputStream.h"
|
||||||
|
#include "nsEnumeratorUtils.h"
|
||||||
|
#include "nsAppFileLocProviderProxy.h"
|
||||||
|
#ifndef VBOX
|
||||||
|
#include "nsXULAppAPI.h"
|
||||||
|
#endif
|
||||||
|
#include "nsILocalFile.h"
|
||||||
|
|
||||||
|
#ifdef XP_MACOSX
|
||||||
|
#include "jawt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
#if 0
|
||||||
|
#include "org_mozilla_xpcom_internal_GREImpl.h"
|
||||||
|
#include "org_mozilla_xpcom_internal_JavaXPCOMMethods.h"
|
||||||
|
#include "org_mozilla_xpcom_internal_MozillaImpl.h"
|
||||||
|
#include "org_mozilla_xpcom_internal_XPCOMImpl.h"
|
||||||
|
#include "org_mozilla_xpcom_internal_XPCOMJavaProxy.h"
|
||||||
|
#include "org_mozilla_xpcom_ProfileLock.h"
|
||||||
|
#endif
|
||||||
|
#include <VBox/com/com.h>
|
||||||
|
using namespace com;
|
||||||
|
#include <iprt/initterm.h>
|
||||||
|
#include <iprt/string.h>
|
||||||
|
#include <alloca.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
MOZILLA_NATIVE(initialize) (JNIEnv* env, jobject)
|
||||||
|
{
|
||||||
|
if (!InitializeJavaGlobals(env)) {
|
||||||
|
jclass clazz =
|
||||||
|
env->FindClass("org/mozilla/xpcom/XPCOMInitializationException");
|
||||||
|
if (clazz) {
|
||||||
|
env->ThrowNew(clazz, "Failed to initialize JavaXPCOM");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
InitEmbedding_Impl(JNIEnv* env, jobject aLibXULDirectory,
|
||||||
|
jobject aAppDirectory, jobject aAppDirProvider)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
// create an nsILocalFile from given java.io.File
|
||||||
|
nsCOMPtr<nsILocalFile> libXULDir;
|
||||||
|
if (aLibXULDirectory) {
|
||||||
|
rv = File_to_nsILocalFile(env, aLibXULDirectory, getter_AddRefs(libXULDir));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
nsCOMPtr<nsILocalFile> appDir;
|
||||||
|
if (aAppDirectory) {
|
||||||
|
rv = File_to_nsILocalFile(env, aAppDirectory, getter_AddRefs(appDir));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create nsAppFileLocProviderProxy from given Java object
|
||||||
|
nsCOMPtr<nsIDirectoryServiceProvider> provider;
|
||||||
|
if (aAppDirProvider) {
|
||||||
|
rv = NS_NewAppFileLocProviderProxy(aAppDirProvider,
|
||||||
|
getter_AddRefs(provider));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
// init libXUL
|
||||||
|
#ifdef VBOX
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
return XRE_InitEmbedding(libXULDir, appDir, provider, nsnull, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
GRE_NATIVE(initEmbedding) (JNIEnv* env, jobject, jobject aLibXULDirectory,
|
||||||
|
jobject aAppDirectory, jobject aAppDirProvider)
|
||||||
|
{
|
||||||
|
nsresult rv = InitEmbedding_Impl(env, aLibXULDirectory, aAppDirectory,
|
||||||
|
aAppDirProvider);
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
ThrowException(env, rv, "Failure in initEmbedding");
|
||||||
|
FreeJavaGlobals(env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
GRE_NATIVE(termEmbedding) (JNIEnv *env, jobject)
|
||||||
|
{
|
||||||
|
// Free globals before calling XRE_TermEmbedding(), since we need some
|
||||||
|
// XPCOM services.
|
||||||
|
FreeJavaGlobals(env);
|
||||||
|
|
||||||
|
#ifndef VBOX
|
||||||
|
XRE_TermEmbedding();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifdef VBOX
|
||||||
|
nsresult
|
||||||
|
InitXPCOMVBox_Impl(JNIEnv* env, jobject aVBoxBinDirectory)
|
||||||
|
{
|
||||||
|
#if defined(VBOX_PATH_APP_PRIVATE_ARCH) && defined(VBOX_PATH_SHARED_LIBS)
|
||||||
|
rv = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
|
||||||
|
#else
|
||||||
|
const char *pszHome = nsnull;
|
||||||
|
const char *jhome = nsnull;
|
||||||
|
jstring path = nsnull;
|
||||||
|
|
||||||
|
int rv;
|
||||||
|
jclass clazz;
|
||||||
|
jmethodID getPathMID;
|
||||||
|
|
||||||
|
if (aVBoxBinDirectory &&
|
||||||
|
(clazz = env->FindClass("java/io/File")) &&
|
||||||
|
(getPathMID = env->GetMethodID(clazz, "getAbsolutePath",
|
||||||
|
"()Ljava/lang/String;"))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
path = (jstring)env->CallObjectMethod(aVBoxBinDirectory, getPathMID);
|
||||||
|
pszHome = jhome = env->GetStringUTFChars(path, nsnull);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pszHome == nsnull)
|
||||||
|
pszHome = getenv("VBOX_PROGRAM_PATH");
|
||||||
|
|
||||||
|
if (pszHome) {
|
||||||
|
size_t cchHome = strlen(pszHome);
|
||||||
|
char *pszExePath = (char *)alloca(cchHome + 32);
|
||||||
|
memcpy(pszExePath, pszHome, cchHome);
|
||||||
|
memcpy(pszExePath + cchHome, "/javafake", sizeof("/javafake"));
|
||||||
|
rv = RTR3InitEx(RTR3INIT_VER_CUR, RTR3INIT_FLAGS_DLL | RTR3INIT_FLAGS_UNOBTRUSIVE, 0, NULL, pszExePath);
|
||||||
|
} else {
|
||||||
|
rv = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jhome)
|
||||||
|
env->ReleaseStringUTFChars(path, jhome);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return com::Initialize();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
InitXPCOM_Impl(JNIEnv* env, jobject aMozBinDirectory,
|
||||||
|
jobject aAppFileLocProvider, jobject* aResult)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
// create an nsILocalFile from given java.io.File
|
||||||
|
nsCOMPtr<nsILocalFile> directory;
|
||||||
|
if (aMozBinDirectory) {
|
||||||
|
rv = File_to_nsILocalFile(env, aMozBinDirectory, getter_AddRefs(directory));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create nsAppFileLocProviderProxy from given Java object
|
||||||
|
nsCOMPtr<nsIDirectoryServiceProvider> provider;
|
||||||
|
if (aAppFileLocProvider) {
|
||||||
|
rv = NS_NewAppFileLocProviderProxy(aAppFileLocProvider,
|
||||||
|
getter_AddRefs(provider));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
// init XPCOM
|
||||||
|
nsCOMPtr<nsIServiceManager> servMan;
|
||||||
|
rv = NS_InitXPCOM2(getter_AddRefs(servMan), directory, provider);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// create Java proxy for service manager returned by NS_InitXPCOM2
|
||||||
|
return NativeInterfaceToJavaObject(env, servMan, NS_GET_IID(nsIServiceManager),
|
||||||
|
nsnull, aResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(initXPCOM) (JNIEnv* env, jobject, jobject aMozBinDirectory,
|
||||||
|
jobject aAppFileLocProvider)
|
||||||
|
{
|
||||||
|
#ifdef VBOX
|
||||||
|
nsresult rv = InitXPCOMVBox_Impl(env, aMozBinDirectory);
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
return nsnull;
|
||||||
|
#else
|
||||||
|
jobject servMan;
|
||||||
|
nsresult rv = InitXPCOM_Impl(env, aMozBinDirectory, aAppFileLocProvider,
|
||||||
|
&servMan);
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
return servMan;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ThrowException(env, rv, "Failure in initXPCOM");
|
||||||
|
FreeJavaGlobals(env);
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
#ifdef VBOX
|
||||||
|
XPCOM_NATIVE2(shutdownXPCOM) (JNIEnv *env, jobject, jobject aServMgr)
|
||||||
|
#else
|
||||||
|
XPCOM_NATIVE(shutdownXPCOM) (JNIEnv *env, jobject, jobject aServMgr)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef VBOX
|
||||||
|
// Free globals before calling NS_ShutdownXPCOM(), since we need some
|
||||||
|
// XPCOM services.
|
||||||
|
//FreeJavaGlobals(env);
|
||||||
|
//com::Shutdown();
|
||||||
|
#else
|
||||||
|
nsresult rv;
|
||||||
|
nsIServiceManager* servMgr = nsnull;
|
||||||
|
if (aServMgr) {
|
||||||
|
// Get native XPCOM instance
|
||||||
|
nsISupports* instancePtr = nsnull;
|
||||||
|
rv = JavaObjectToNativeInterface(env, aServMgr,
|
||||||
|
NS_GET_IID(nsIServiceManager), (void**) &instancePtr);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv) && instancePtr != nsnull,
|
||||||
|
"Failed to get XPCOM obj for ServiceMgr.");
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
rv = instancePtr->QueryInterface(NS_GET_IID(nsIServiceManager),
|
||||||
|
(void**) &servMgr);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv), "QI for nsIServiceManager failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Even if we failed to get the matching xpcom object, we don't abort this
|
||||||
|
// function. Just call NS_ShutdownXPCOM with a null service manager.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free globals before calling NS_ShutdownXPCOM(), since we need some
|
||||||
|
// XPCOM services.
|
||||||
|
FreeJavaGlobals(env);
|
||||||
|
|
||||||
|
rv = NS_ShutdownXPCOM(servMgr);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
ThrowException(env, rv, "NS_ShutdownXPCOM failed");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(newLocalFile) (JNIEnv *env, jobject, jstring aPath,
|
||||||
|
jboolean aFollowLinks)
|
||||||
|
{
|
||||||
|
// Create a Mozilla string from the jstring
|
||||||
|
const PRUnichar* buf = nsnull;
|
||||||
|
if (aPath) {
|
||||||
|
buf = env->GetStringChars(aPath, nsnull);
|
||||||
|
if (!buf)
|
||||||
|
return nsnull; // exception already thrown
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoString path_str(buf);
|
||||||
|
env->ReleaseStringChars(aPath, buf);
|
||||||
|
|
||||||
|
// Make call to given function
|
||||||
|
nsCOMPtr<nsILocalFile> file;
|
||||||
|
nsresult rv = NS_NewLocalFile(path_str, aFollowLinks, getter_AddRefs(file));
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
jobject javaProxy;
|
||||||
|
rv = NativeInterfaceToJavaObject(env, file, NS_GET_IID(nsILocalFile),
|
||||||
|
nsnull, &javaProxy);
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
return javaProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowException(env, rv, "Failure in newLocalFile");
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
#ifdef VBOX
|
||||||
|
XPCOM_NATIVE2(getComponentManager) (JNIEnv *env, jobject)
|
||||||
|
#else
|
||||||
|
XPCOM_NATIVE(getComponentManager) (JNIEnv *env, jobject)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// Call XPCOM method
|
||||||
|
nsCOMPtr<nsIComponentManager> cm;
|
||||||
|
nsresult rv = NS_GetComponentManager(getter_AddRefs(cm));
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
jobject javaProxy;
|
||||||
|
rv = NativeInterfaceToJavaObject(env, cm, NS_GET_IID(nsIComponentManager),
|
||||||
|
nsnull, &javaProxy);
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
return javaProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowException(env, rv, "Failure in getComponentManager");
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(getComponentRegistrar) (JNIEnv *env, jobject)
|
||||||
|
{
|
||||||
|
// Call XPCOM method
|
||||||
|
nsCOMPtr<nsIComponentRegistrar> cr;
|
||||||
|
nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
jobject javaProxy;
|
||||||
|
rv = NativeInterfaceToJavaObject(env, cr, NS_GET_IID(nsIComponentRegistrar),
|
||||||
|
nsnull, &javaProxy);
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
return javaProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowException(env, rv, "Failure in getComponentRegistrar");
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
# include <VBox/com/NativeEventQueue.h>
|
||||||
|
# include <iprt/err.h>
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jint JNICALL
|
||||||
|
XPCOM_NATIVE2(waitForEvents) (JNIEnv *env, jobject, jlong aTimeout)
|
||||||
|
{
|
||||||
|
com::NativeEventQueue* aEventQ = com::NativeEventQueue::getMainEventQueue();
|
||||||
|
NS_WARN_IF_FALSE(aEventQ != nsnull, "Null main event queue");
|
||||||
|
if (!aEventQ)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int rc = aEventQ->processEventQueue(aTimeout < 0 ? RT_INDEFINITE_WAIT : (uint32_t)aTimeout);
|
||||||
|
|
||||||
|
if (RT_SUCCESS(rc))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ( rc == VERR_TIMEOUT
|
||||||
|
|| rc == VERR_INTERRUPTED)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
#ifdef VBOX
|
||||||
|
XPCOM_NATIVE2(getServiceManager) (JNIEnv *env, jobject)
|
||||||
|
#else
|
||||||
|
XPCOM_NATIVE(getServiceManager) (JNIEnv *env, jobject)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// Call XPCOM method
|
||||||
|
nsCOMPtr<nsIServiceManager> sm;
|
||||||
|
nsresult rv = NS_GetServiceManager(getter_AddRefs(sm));
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
jobject javaProxy;
|
||||||
|
rv = NativeInterfaceToJavaObject(env, sm, NS_GET_IID(nsIServiceManager),
|
||||||
|
nsnull, &javaProxy);
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
return javaProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowException(env, rv, "Failure in getServiceManager");
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
GRE_NATIVE(lockProfileDirectory) (JNIEnv* env, jobject, jobject aDirectory)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
if (aDirectory) {
|
||||||
|
nsCOMPtr<nsILocalFile> profileDir;
|
||||||
|
rv = File_to_nsILocalFile(env, aDirectory, getter_AddRefs(profileDir));
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
nsISupports* lock;
|
||||||
|
#ifdef VBOX
|
||||||
|
rv = 0;
|
||||||
|
lock = 0;
|
||||||
|
#else
|
||||||
|
rv = XRE_LockProfileDirectory(profileDir, &lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
jclass clazz =
|
||||||
|
env->FindClass("org/mozilla/xpcom/ProfileLock");
|
||||||
|
if (clazz) {
|
||||||
|
jmethodID mid = env->GetMethodID(clazz, "<init>", "(J)V");
|
||||||
|
if (mid) {
|
||||||
|
return env->NewObject(clazz, mid, reinterpret_cast<jlong>(lock));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we get here, then something failed
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ThrowException(env, rv, "Failure in lockProfileDirectory");
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
GRE_NATIVE(notifyProfile) (JNIEnv *env, jobject)
|
||||||
|
{
|
||||||
|
#ifndef VBOX
|
||||||
|
XRE_NotifyProfile();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef XP_MACOSX
|
||||||
|
extern PRUint64 GetPlatformHandle(JAWT_DrawingSurfaceInfo* dsi);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jlong JNICALL
|
||||||
|
MOZILLA_NATIVE(getNativeHandleFromAWT) (JNIEnv* env, jobject clazz,
|
||||||
|
jobject widget)
|
||||||
|
{
|
||||||
|
PRUint64 handle = 0;
|
||||||
|
|
||||||
|
#if defined(XP_MACOSX) && !defined(VBOX)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jlong JNICALL
|
||||||
|
JXUTILS_NATIVE(wrapJavaObject) (JNIEnv* env, jobject, jobject aJavaObject,
|
||||||
|
jstring aIID)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
void* xpcomObject = nsnull;
|
||||||
|
|
||||||
|
if (!aJavaObject || !aIID) {
|
||||||
|
rv = NS_ERROR_NULL_POINTER;
|
||||||
|
} else {
|
||||||
|
const char* str = env->GetStringUTFChars(aIID, nsnull);
|
||||||
|
if (!str) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
nsID iid;
|
||||||
|
if (iid.Parse(str)) {
|
||||||
|
rv = JavaObjectToNativeInterface(env, aJavaObject, iid, &xpcomObject);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
nsISupports *xpcom_nat_obj = (nsISupports*) xpcomObject;
|
||||||
|
rv = xpcom_nat_obj->QueryInterface(iid, &xpcomObject);
|
||||||
|
NS_IF_RELEASE(xpcom_nat_obj);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rv = NS_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
env->ReleaseStringUTFChars(aIID, str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
ThrowException(env, rv, "Failed to create XPCOM proxy for Java object");
|
||||||
|
}
|
||||||
|
return reinterpret_cast<jlong>(xpcomObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
JXUTILS_NATIVE(wrapXPCOMObject) (JNIEnv* env, jobject, jlong aXPCOMObject,
|
||||||
|
jstring aIID)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
jobject javaObject = nsnull;
|
||||||
|
nsISupports* xpcomObject = reinterpret_cast<nsISupports*>(aXPCOMObject);
|
||||||
|
|
||||||
|
if (!xpcomObject || !aIID) {
|
||||||
|
rv = NS_ERROR_NULL_POINTER;
|
||||||
|
} else {
|
||||||
|
const char* str = env->GetStringUTFChars(aIID, nsnull);
|
||||||
|
if (!str) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
nsID iid;
|
||||||
|
if (iid.Parse(str)) {
|
||||||
|
// XXX Should we be passing something other than NULL for aObjectLoader?
|
||||||
|
rv = NativeInterfaceToJavaObject(env, xpcomObject, iid, nsnull,
|
||||||
|
&javaObject);
|
||||||
|
} else {
|
||||||
|
rv = NS_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
env->ReleaseStringUTFChars(aIID, str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
ThrowException(env, rv, "Failed to create XPCOM proxy for Java object");
|
||||||
|
}
|
||||||
|
return javaObject;
|
||||||
|
}
|
121
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaInterfaces.h
Executable file
121
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaInterfaces.h
Executable file
|
@ -0,0 +1,121 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
#ifndef _nsJavaInterfaces_h_
|
||||||
|
#define _nsJavaInterfaces_h_
|
||||||
|
|
||||||
|
#include "jni.h"
|
||||||
|
#include "nscore.h"
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
#define MOZILLA_NATIVE(func) Java_org_mozilla_xpcom_internal_MozillaImpl_##func##Native
|
||||||
|
#define GRE_NATIVE(func) Java_org_mozilla_xpcom_internal_GREImpl_##func##Native
|
||||||
|
#define XPCOM_NATIVE(func) Java_org_mozilla_xpcom_internal_XPCOMImpl_##func##Native
|
||||||
|
#define XPCOM_NATIVE2(func) Java_org_mozilla_xpcom_internal_XPCOMImpl_##func
|
||||||
|
#else
|
||||||
|
#define MOZILLA_NATIVE(func) Java_org_mozilla_xpcom_internal_MozillaImpl_##func
|
||||||
|
#define GRE_NATIVE(func) Java_org_mozilla_xpcom_internal_GREImpl_##func
|
||||||
|
#define XPCOM_NATIVE(func) Java_org_mozilla_xpcom_internal_XPCOMImpl_##func
|
||||||
|
#endif
|
||||||
|
#define JAVAPROXY_NATIVE(func) \
|
||||||
|
Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_##func
|
||||||
|
#define LOCKPROXY_NATIVE(func) Java_org_mozilla_xpcom_ProfileLock_##func
|
||||||
|
#define JXUTILS_NATIVE(func) \
|
||||||
|
Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_##func
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
MOZILLA_NATIVE(initialize) (JNIEnv* env, jobject);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
GRE_NATIVE(initEmbedding) (JNIEnv* env, jobject, jobject aLibXULDirectory,
|
||||||
|
jobject aAppDirectory, jobject aAppDirProvider);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
GRE_NATIVE(termEmbedding) (JNIEnv *env, jobject);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
GRE_NATIVE(lockProfileDirectory) (JNIEnv *, jobject, jobject aDirectory);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
GRE_NATIVE(notifyProfile) (JNIEnv *env, jobject);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(initXPCOM) (JNIEnv* env, jobject, jobject aMozBinDirectory,
|
||||||
|
jobject aAppFileLocProvider);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
XPCOM_NATIVE(shutdownXPCOM) (JNIEnv *env, jobject, jobject aServMgr);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(newLocalFile) (JNIEnv *env, jobject, jstring aPath,
|
||||||
|
jboolean aFollowLinks);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(getComponentManager) (JNIEnv *env, jobject);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(getComponentRegistrar) (JNIEnv *env, jobject);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
XPCOM_NATIVE(getServiceManager) (JNIEnv *env, jobject);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
JAVAPROXY_NATIVE(callXPCOMMethod) (JNIEnv *env, jclass that, jobject aJavaProxy,
|
||||||
|
jstring aMethodName, jobjectArray aParams);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
JAVAPROXY_NATIVE(finalizeProxy) (JNIEnv *env, jclass that, jobject aJavaProxy);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jboolean JNICALL
|
||||||
|
JAVAPROXY_NATIVE(isSameXPCOMObject) (JNIEnv *env, jclass that, jobject aProxy1,
|
||||||
|
jobject aProxy2);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT void JNICALL
|
||||||
|
LOCKPROXY_NATIVE(release) (JNIEnv *env, jclass that, jlong aLockObject);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jlong JNICALL
|
||||||
|
MOZILLA_NATIVE(getNativeHandleFromAWT) (JNIEnv* env, jobject, jobject widget);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jlong JNICALL
|
||||||
|
JXUTILS_NATIVE(wrapJavaObject) (JNIEnv* env, jobject, jobject aJavaObject,
|
||||||
|
jstring aIID);
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT jobject JNICALL
|
||||||
|
JXUTILS_NATIVE(wrapXPCOMObject) (JNIEnv* env, jobject, jlong aXPCOMObject,
|
||||||
|
jstring aIID);
|
||||||
|
|
||||||
|
#endif // _nsJavaInterfaces_h_
|
2020
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaWrapper.cpp
Executable file
2020
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaWrapper.cpp
Executable file
File diff suppressed because it is too large
Load diff
75
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaWrapper.h
Executable file
75
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaWrapper.h
Executable file
|
@ -0,0 +1,75 @@
|
||||||
|
/* ***** 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) 2004
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef _nsJavaWrapper_h_
|
||||||
|
#define _nsJavaWrapper_h_
|
||||||
|
|
||||||
|
#include "jni.h"
|
||||||
|
#include "nsISupports.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the associated Java wraper for the given XPCOM object and IID. If no
|
||||||
|
* such Java wrapper exists, then a new one is created.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aXPCOMObject XPCOM object for which to find/create Java wrapper
|
||||||
|
* @param aIID desired interface IID for Java wrapper
|
||||||
|
* @param aObjectLoader Java wrapper whose class loader we use for finding
|
||||||
|
* classes; can be null
|
||||||
|
* @param aResult on success, holds reference to Java wrapper
|
||||||
|
*
|
||||||
|
* @return NS_OK if succeeded; all other return values are error codes.
|
||||||
|
*/
|
||||||
|
nsresult GetNewOrUsedJavaWrapper(JNIEnv* env, nsISupports* aXPCOMObject,
|
||||||
|
const nsIID& aIID, jobject aObjectLoader,
|
||||||
|
jobject* aResult);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the XPCOM object for which the given Java proxy was created.
|
||||||
|
*
|
||||||
|
* @param env pointer to Java context
|
||||||
|
* @param aJavaObject a Java proxy created by CreateJavaProxy()
|
||||||
|
* @param aResult on exit, holds pointer to XPCOM instance
|
||||||
|
*
|
||||||
|
* @return NS_OK if the XPCOM object was successfully retrieved;
|
||||||
|
* any other value denotes an error condition.
|
||||||
|
*/
|
||||||
|
nsresult GetXPCOMInstFromProxy(JNIEnv* env, jobject aJavaObject,
|
||||||
|
void** aResult);
|
||||||
|
|
||||||
|
#endif // _nsJavaWrapper_h_
|
1084
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPCOMBindingUtils.cpp
Executable file
1084
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPCOMBindingUtils.cpp
Executable file
File diff suppressed because it is too large
Load diff
392
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPCOMBindingUtils.h
Executable file
392
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPCOMBindingUtils.h
Executable file
|
@ -0,0 +1,392 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef _nsJavaXPCOMBindingUtils_h_
|
||||||
|
#define _nsJavaXPCOMBindingUtils_h_
|
||||||
|
|
||||||
|
#include "jni.h"
|
||||||
|
#include "xptcall.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "pldhash.h"
|
||||||
|
#include "nsJavaXPTCStub.h"
|
||||||
|
#include "nsAutoLock.h"
|
||||||
|
#include "nsTHashtable.h"
|
||||||
|
#include "nsHashKeys.h"
|
||||||
|
#include "nsILocalFile.h"
|
||||||
|
|
||||||
|
//#define DEBUG_JAVAXPCOM
|
||||||
|
//#define DEBUG_JAVAXPCOM_REFCNT
|
||||||
|
|
||||||
|
#ifdef DEBUG_JAVAXPCOM
|
||||||
|
#define LOG(x) printf x
|
||||||
|
#else
|
||||||
|
#define LOG(x) /* nothing */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* Java JNI globals
|
||||||
|
*********************/
|
||||||
|
|
||||||
|
extern jclass systemClass;
|
||||||
|
extern jclass booleanClass;
|
||||||
|
extern jclass charClass;
|
||||||
|
extern jclass byteClass;
|
||||||
|
extern jclass shortClass;
|
||||||
|
extern jclass intClass;
|
||||||
|
extern jclass longClass;
|
||||||
|
extern jclass floatClass;
|
||||||
|
extern jclass doubleClass;
|
||||||
|
extern jclass stringClass;
|
||||||
|
extern jclass nsISupportsClass;
|
||||||
|
extern jclass xpcomExceptionClass;
|
||||||
|
extern jclass xpcomJavaProxyClass;
|
||||||
|
extern jclass weakReferenceClass;
|
||||||
|
extern jclass javaXPCOMUtilsClass;
|
||||||
|
|
||||||
|
extern jmethodID hashCodeMID;
|
||||||
|
extern jmethodID booleanValueMID;
|
||||||
|
extern jmethodID booleanInitMID;
|
||||||
|
extern jmethodID charValueMID;
|
||||||
|
extern jmethodID charInitMID;
|
||||||
|
extern jmethodID byteValueMID;
|
||||||
|
extern jmethodID byteInitMID;
|
||||||
|
extern jmethodID shortValueMID;
|
||||||
|
extern jmethodID shortInitMID;
|
||||||
|
extern jmethodID intValueMID;
|
||||||
|
extern jmethodID intInitMID;
|
||||||
|
extern jmethodID longValueMID;
|
||||||
|
extern jmethodID longInitMID;
|
||||||
|
extern jmethodID floatValueMID;
|
||||||
|
extern jmethodID floatInitMID;
|
||||||
|
extern jmethodID doubleValueMID;
|
||||||
|
extern jmethodID doubleInitMID;
|
||||||
|
extern jmethodID createProxyMID;
|
||||||
|
extern jmethodID isXPCOMJavaProxyMID;
|
||||||
|
extern jmethodID getNativeXPCOMInstMID;
|
||||||
|
extern jmethodID weakReferenceConstructorMID;
|
||||||
|
extern jmethodID getReferentMID;
|
||||||
|
extern jmethodID clearReferentMID;
|
||||||
|
extern jmethodID findClassInLoaderMID;
|
||||||
|
|
||||||
|
#ifdef DEBUG_JAVAXPCOM
|
||||||
|
extern jmethodID getNameMID;
|
||||||
|
extern jmethodID proxyToStringMID;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class NativeToJavaProxyMap;
|
||||||
|
extern NativeToJavaProxyMap* gNativeToJavaProxyMap;
|
||||||
|
class JavaToXPTCStubMap;
|
||||||
|
extern JavaToXPTCStubMap* gJavaToXPTCStubMap;
|
||||||
|
|
||||||
|
extern nsTHashtable<nsDepCharHashKey>* gJavaKeywords;
|
||||||
|
|
||||||
|
// The Java garbage collector runs in a separate thread. Since it calls the
|
||||||
|
// finalizeProxy() function in nsJavaWrapper.cpp, we need to make sure that
|
||||||
|
// all the structures touched by finalizeProxy() are multithread aware.
|
||||||
|
extern PRLock* gJavaXPCOMLock;
|
||||||
|
|
||||||
|
extern PRBool gJavaXPCOMInitialized;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize global structures used by JavaXPCOM.
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @return PR_TRUE if JavaXPCOM is initialized; PR_FALSE if an error occurred
|
||||||
|
*/
|
||||||
|
PRBool InitializeJavaGlobals(JNIEnv *env);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees global structures that were allocated by InitializeJavaGlobals().
|
||||||
|
* @param env Java environment pointer
|
||||||
|
*/
|
||||||
|
void FreeJavaGlobals(JNIEnv* env);
|
||||||
|
|
||||||
|
|
||||||
|
/*************************
|
||||||
|
* JavaXPCOMInstance
|
||||||
|
*************************/
|
||||||
|
|
||||||
|
class JavaXPCOMInstance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JavaXPCOMInstance(nsISupports* aInstance, nsIInterfaceInfo* aIInfo);
|
||||||
|
~JavaXPCOMInstance();
|
||||||
|
|
||||||
|
nsISupports* GetInstance() { return mInstance; }
|
||||||
|
nsIInterfaceInfo* InterfaceInfo() { return mIInfo; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsISupports* mInstance;
|
||||||
|
nsIInterfaceInfo* mIInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************
|
||||||
|
* Java<->XPCOM object mappings
|
||||||
|
**************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps native XPCOM objects to their associated Java proxy object.
|
||||||
|
*/
|
||||||
|
class NativeToJavaProxyMap
|
||||||
|
{
|
||||||
|
friend PLDHashOperator DestroyJavaProxyMappingEnum(PLDHashTable* aTable,
|
||||||
|
PLDHashEntryHdr* aHeader,
|
||||||
|
PRUint32 aNumber,
|
||||||
|
void* aData);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
struct ProxyList
|
||||||
|
{
|
||||||
|
ProxyList(const jobject aRef, const nsIID& aIID, ProxyList* aList)
|
||||||
|
: javaObject(aRef)
|
||||||
|
, iid(aIID)
|
||||||
|
, next(aList)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
const jobject javaObject;
|
||||||
|
const nsIID iid;
|
||||||
|
ProxyList* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Entry : public PLDHashEntryHdr
|
||||||
|
{
|
||||||
|
nsISupports* key;
|
||||||
|
ProxyList* list;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
NativeToJavaProxyMap()
|
||||||
|
: mHashTable(nsnull)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
~NativeToJavaProxyMap()
|
||||||
|
{
|
||||||
|
NS_ASSERTION(mHashTable == nsnull,
|
||||||
|
"MUST call Destroy() before deleting object");
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult Init();
|
||||||
|
|
||||||
|
nsresult Destroy(JNIEnv* env);
|
||||||
|
|
||||||
|
nsresult Add(JNIEnv* env, nsISupports* aXPCOMObject, const nsIID& aIID,
|
||||||
|
jobject aProxy);
|
||||||
|
|
||||||
|
nsresult Find(JNIEnv* env, nsISupports* aNativeObject, const nsIID& aIID,
|
||||||
|
jobject* aResult);
|
||||||
|
|
||||||
|
nsresult Remove(JNIEnv* env, nsISupports* aNativeObject, const nsIID& aIID);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PLDHashTable* mHashTable;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps Java objects to their associated nsJavaXPTCStub.
|
||||||
|
*/
|
||||||
|
class JavaToXPTCStubMap
|
||||||
|
{
|
||||||
|
friend PLDHashOperator DestroyXPTCMappingEnum(PLDHashTable* aTable,
|
||||||
|
PLDHashEntryHdr* aHeader,
|
||||||
|
PRUint32 aNumber, void* aData);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
struct Entry : public PLDHashEntryHdr
|
||||||
|
{
|
||||||
|
jint key;
|
||||||
|
nsJavaXPTCStub* xptcstub;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
JavaToXPTCStubMap()
|
||||||
|
: mHashTable(nsnull)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
~JavaToXPTCStubMap()
|
||||||
|
{
|
||||||
|
NS_ASSERTION(mHashTable == nsnull,
|
||||||
|
"MUST call Destroy() before deleting object");
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult Init();
|
||||||
|
|
||||||
|
nsresult Destroy();
|
||||||
|
|
||||||
|
nsresult Add(jint aJavaObjectHashCode, nsJavaXPTCStub* aProxy);
|
||||||
|
|
||||||
|
nsresult Find(jint aJavaObjectHashCode, const nsIID& aIID,
|
||||||
|
nsJavaXPTCStub** aResult);
|
||||||
|
|
||||||
|
nsresult Remove(jint aJavaObjectHashCode);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PLDHashTable* mHashTable;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************
|
||||||
|
* Helper functions
|
||||||
|
*******************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a native nsISupports to a Java object.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aXPCOMObject XPCOM object for which to find/create Java object
|
||||||
|
* @param aIID desired interface IID for Java object
|
||||||
|
* @param aObjectLoader Java object whose class loader we use for finding
|
||||||
|
* classes; can be null
|
||||||
|
* @param aResult on success, holds reference to Java object
|
||||||
|
*
|
||||||
|
* @return NS_OK if succeeded; all other return values are error codes.
|
||||||
|
*/
|
||||||
|
nsresult NativeInterfaceToJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
|
||||||
|
const nsIID& aIID, jobject aObjectLoader,
|
||||||
|
jobject* aResult);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a Java object to a native nsISupports object.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aJavaObject Java object for which to find/create XPCOM object
|
||||||
|
* @param aIID desired interface IID for XPCOM object
|
||||||
|
* @param aResult on success, holds AddRef'd reference to XPCOM object
|
||||||
|
*
|
||||||
|
* @return NS_OK if succeeded; all other return values are error codes.
|
||||||
|
*/
|
||||||
|
nsresult JavaObjectToNativeInterface(JNIEnv* env, jobject aJavaObject,
|
||||||
|
const nsIID& aIID, void** aResult);
|
||||||
|
|
||||||
|
nsresult GetIIDForMethodParam(nsIInterfaceInfo *iinfo,
|
||||||
|
const XPTMethodDescriptor *methodInfo,
|
||||||
|
const nsXPTParamInfo ¶mInfo,
|
||||||
|
PRUint8 paramType, PRUint16 methodIndex,
|
||||||
|
nsXPTCMiniVariant *dispatchParams,
|
||||||
|
PRBool isFullVariantArray,
|
||||||
|
nsID &result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Class object associated with the class or interface with the
|
||||||
|
* given string name, using the class loader of the given object.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aObjectLoader Java object whose class loader is used to load class
|
||||||
|
* @param aClassName fully qualified name of class to load
|
||||||
|
*
|
||||||
|
* @return java.lang.Class object of requested Class; NULL if the class
|
||||||
|
* wasn't found
|
||||||
|
*
|
||||||
|
* @see http://java.sun.com/j2se/1.3/docs/guide/jni/jni-12.html#classops
|
||||||
|
*/
|
||||||
|
inline jclass
|
||||||
|
FindClassInLoader(JNIEnv* env, jobject aObjectLoader, const char* aClassName)
|
||||||
|
{
|
||||||
|
jclass clazz = nsnull;
|
||||||
|
jstring name = env->NewStringUTF(aClassName);
|
||||||
|
if (name)
|
||||||
|
clazz = (jclass) env->CallStaticObjectMethod(javaXPCOMUtilsClass,
|
||||||
|
findClassInLoaderMID, aObjectLoader, name);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (!clazz)
|
||||||
|
fprintf(stderr, "WARNING: failed to find class [%s]\n", aClassName);
|
||||||
|
#endif
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************
|
||||||
|
* JNI helper functions
|
||||||
|
*******************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pointer to the appropriate JNIEnv structure. This function is
|
||||||
|
* useful in callbacks or other functions that are not called directly from
|
||||||
|
* Java and therefore do not have the JNIEnv structure passed in.
|
||||||
|
*
|
||||||
|
* @return pointer to JNIEnv structure for current thread
|
||||||
|
*/
|
||||||
|
JNIEnv* GetJNIEnv();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs and throws an exception. Some error codes (such as
|
||||||
|
* NS_ERROR_OUT_OF_MEMORY) are handled by the appropriate Java exception/error.
|
||||||
|
* Otherwise, an instance of XPCOMException is created with the given error
|
||||||
|
* code and message.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aErrorCode The error code returned by an XPCOM/Gecko function. Pass
|
||||||
|
* zero for the default behaviour.
|
||||||
|
* @param aMessage A string that provides details for throwing this
|
||||||
|
* exception. Pass in <code>nsnull</code> for the default
|
||||||
|
* behaviour.
|
||||||
|
*
|
||||||
|
* @throws OutOfMemoryError if aErrorCode == NS_ERROR_OUT_OF_MEMORY
|
||||||
|
* XPCOMException for all other error codes
|
||||||
|
*/
|
||||||
|
void ThrowException(JNIEnv* env, const nsresult aErrorCode,
|
||||||
|
const char* aMessage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper functions for converting from java.lang.String to
|
||||||
|
* nsAString/nsACstring. Caller must delete nsAString/nsACString.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aString Java string to convert
|
||||||
|
*
|
||||||
|
* @return nsAString/nsACString with same content as given Java string;
|
||||||
|
* a 'void' nsAString/nsACString object if aString is
|
||||||
|
* <code>null</code>; or <code>nsnull</code> if out of memory
|
||||||
|
*/
|
||||||
|
nsAString* jstring_to_nsAString(JNIEnv* env, jstring aString);
|
||||||
|
nsACString* jstring_to_nsACString(JNIEnv* env, jstring aString);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for converting from java.io.File to nsILocalFile.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aFile Java File to convert
|
||||||
|
* @param aLocalFile returns the converted nsILocalFile
|
||||||
|
*
|
||||||
|
* @return NS_OK for success; other values indicate error in conversion
|
||||||
|
*/
|
||||||
|
nsresult File_to_nsILocalFile(JNIEnv* env, jobject aFile,
|
||||||
|
nsILocalFile** aLocalFile);
|
||||||
|
|
||||||
|
#endif // _nsJavaXPCOMBindingUtils_h_
|
535
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPCOMGlue.cpp
Executable file
535
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPCOMGlue.cpp
Executable file
|
@ -0,0 +1,535 @@
|
||||||
|
/* ***** 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"
|
||||||
|
#include "nsXPCOMPrivate.h" // for XPCOM_DLL defines.
|
||||||
|
#include "nsXPCOMGlue.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
#include <string.h>
|
||||||
|
#include "nsDebug.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(XP_WIN) || defined(XP_OS2)
|
||||||
|
#define JX_EXPORT JNIEXPORT
|
||||||
|
#else
|
||||||
|
#define JX_EXPORT JNIEXPORT NS_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/***********************
|
||||||
|
* JNI Load & Unload
|
||||||
|
***********************/
|
||||||
|
|
||||||
|
extern "C" JX_EXPORT jint JNICALL
|
||||||
|
JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||||
|
{
|
||||||
|
// Let the JVM know that we are using JDK 1.2 JNI features.
|
||||||
|
return JNI_VERSION_1_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JX_EXPORT void JNICALL
|
||||||
|
JNI_OnUnload(JavaVM* vm, void* reserved)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************
|
||||||
|
* JavaXPCOM JNI interfaces
|
||||||
|
********************************/
|
||||||
|
|
||||||
|
#define JXM_NATIVE(func) Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_##func
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kFunc_Initialize,
|
||||||
|
kFunc_InitEmbedding,
|
||||||
|
kFunc_TermEmbedding,
|
||||||
|
kFunc_LockProfileDirectory,
|
||||||
|
kFunc_NotifyProfile,
|
||||||
|
kFunc_InitXPCOM,
|
||||||
|
kFunc_ShutdownXPCOM,
|
||||||
|
kFunc_GetComponentManager,
|
||||||
|
kFunc_GetComponentRegistrar,
|
||||||
|
kFunc_GetServiceManager,
|
||||||
|
kFunc_NewLocalFile,
|
||||||
|
kFunc_CallXPCOMMethod,
|
||||||
|
kFunc_FinalizeProxy,
|
||||||
|
kFunc_IsSameXPCOMObject,
|
||||||
|
kFunc_ReleaseProfileLock,
|
||||||
|
kFunc_GetNativeHandleFromAWT,
|
||||||
|
kFunc_WrapJavaObject,
|
||||||
|
kFunc_WrapXPCOMObject
|
||||||
|
};
|
||||||
|
|
||||||
|
#define JX_NUM_FUNCS 18
|
||||||
|
|
||||||
|
|
||||||
|
// Get path string from java.io.File object.
|
||||||
|
jstring
|
||||||
|
GetJavaFilePath(JNIEnv* env, jobject aFile)
|
||||||
|
{
|
||||||
|
jclass clazz = env->FindClass("java/io/File");
|
||||||
|
if (clazz) {
|
||||||
|
jmethodID pathMID = env->GetMethodID(clazz, "getCanonicalPath",
|
||||||
|
"()Ljava/lang/String;");
|
||||||
|
if (pathMID) {
|
||||||
|
return (jstring) env->CallObjectMethod(aFile, pathMID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
#ifdef VBOX
|
||||||
|
|
||||||
|
#include "nsXPTCUtils.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsIInterfaceInfoManager.h"
|
||||||
|
#include "nsJavaInterfaces.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage);
|
||||||
|
|
||||||
|
class nsXPTCJStub : public nsXPTCStubBase
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIInterfaceInfo> mII;
|
||||||
|
nsIXPTCProxy* mOuter;
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
|
||||||
|
nsXPTCJStub(REFNSIID aIID, nsIXPTCProxy* aOuter, nsIInterfaceInfo* ii)
|
||||||
|
{
|
||||||
|
mOuter = aOuter;
|
||||||
|
mII = ii;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~nsXPTCJStub()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info)
|
||||||
|
{
|
||||||
|
*info = mII;
|
||||||
|
(*info)->AddRef();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
// call this method and return result
|
||||||
|
NS_IMETHOD CallMethod(PRUint16 methodIndex,
|
||||||
|
const nsXPTMethodInfo* info,
|
||||||
|
nsXPTCMiniVariant* params)
|
||||||
|
{
|
||||||
|
return mOuter->CallMethod(methodIndex, info, params);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_IMETHODIMP_(nsrefcnt)
|
||||||
|
nsXPTCJStub::AddRef()
|
||||||
|
{
|
||||||
|
return mOuter->AddRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP_(nsrefcnt)
|
||||||
|
nsXPTCJStub::Release()
|
||||||
|
{
|
||||||
|
return mOuter->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsXPTCJStub::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsIID* mIID;
|
||||||
|
mII->GetInterfaceIID(&mIID);
|
||||||
|
|
||||||
|
if (mIID->Equals(aIID)) {
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
*aInstancePtr = static_cast<nsISupports*>(this);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mOuter->QueryInterface(aIID, aInstancePtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
|
||||||
|
nsISomeInterface* *aResult)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG(aOuter && aResult);
|
||||||
|
#if 0
|
||||||
|
xptiInterfaceInfoManager *iim =
|
||||||
|
xptiInterfaceInfoManager::GetInterfaceInfoManagerNoAddRef();
|
||||||
|
NS_ENSURE_TRUE(iim, NS_ERROR_NOT_INITIALIZED);
|
||||||
|
|
||||||
|
xptiInterfaceEntry *iie = iim->GetInterfaceEntryForIID(&aIID);
|
||||||
|
if (!iie || !iie->EnsureResolved())
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
nsXPTCStubBase* newbase = new nsXPTCStubBase(aOuter, iie);
|
||||||
|
if (!newbase)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
*aResult = newbase;
|
||||||
|
#else
|
||||||
|
nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager();
|
||||||
|
nsCOMPtr<nsIInterfaceInfo> ii;
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
rv = iim->GetInfoForIID(&aIID, getter_AddRefs(ii));
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
nsXPTCStubBase* newbase = new nsXPTCJStub(aIID, aOuter, ii);
|
||||||
|
if (!newbase)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
*aResult = newbase;
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NS_DestroyXPTCallStub(nsISomeInterface* aStub)
|
||||||
|
{
|
||||||
|
nsXPTCStubBase* stub = static_cast<nsXPTCStubBase*>(aStub);
|
||||||
|
delete(stub);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void JAVAPROXY_NATIVE(finalizeProxy)(JNIEnv *env, jclass that, jobject aJavaProxy);
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
FindVBoxMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
|
||||||
|
{
|
||||||
|
nsresult rv = 0;
|
||||||
|
|
||||||
|
// We only need to care about this function because the C function we offer
|
||||||
|
// is different from what the Java side expects
|
||||||
|
aFunctions[kFunc_FinalizeProxy] = (void*)JAVAPROXY_NATIVE(finalizeProxy);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// Calls XPCOMGlueStartup using the given java.io.File object, and loads
|
||||||
|
// the JavaXPCOM methods from the XUL shared library.
|
||||||
|
nsresult
|
||||||
|
LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
|
||||||
|
{
|
||||||
|
jstring pathString = GetJavaFilePath(env, aXPCOMPath);
|
||||||
|
if (!pathString)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
const char* path = env->GetStringUTFChars(pathString, nsnull);
|
||||||
|
if (!path)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
int len = strlen(path);
|
||||||
|
char* xpcomPath = (char*) malloc(len + sizeof(XPCOM_DLL) +
|
||||||
|
sizeof(XPCOM_FILE_PATH_SEPARATOR) + 1);
|
||||||
|
if (!xpcomPath)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
sprintf(xpcomPath, "%s" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, path);
|
||||||
|
|
||||||
|
nsresult rv = XPCOMGlueStartup(xpcomPath);
|
||||||
|
free(xpcomPath);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
#ifdef XP_WIN32
|
||||||
|
// The JNICALL calling convention defines to "__stdcall" on Win32, which
|
||||||
|
// mangles the name.
|
||||||
|
nsDynamicFunctionLoad funcs[] = {
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_MozillaImpl_initialize@8",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_Initialize] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_GREImpl_initEmbedding@20",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_InitEmbedding] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_GREImpl_termEmbedding@8",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_TermEmbedding] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_GREImpl_lockProfileDirectory@12",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_LockProfileDirectory] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_GREImpl_notifyProfile@8",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_NotifyProfile] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMImpl_initXPCOM@16",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_InitXPCOM] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMImpl_shutdownXPCOM@12",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_ShutdownXPCOM] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentManager@8",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_GetComponentManager] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentRegistrar@8",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_GetComponentRegistrar] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getServiceManager@8",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_GetServiceManager] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMImpl_newLocalFile@16",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_NewLocalFile] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_callXPCOMMethod@20",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_CallXPCOMMethod] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_finalizeProxy@12",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_FinalizeProxy] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_isSameXPCOMObject@16",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_IsSameXPCOMObject] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_ProfileLock_release@16",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_ReleaseProfileLock] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT@12",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject@16",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
|
||||||
|
{ "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject@20",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
|
||||||
|
{ nsnull, nsnull }
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
nsDynamicFunctionLoad funcs[] = {
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_MozillaImpl_initialize",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_Initialize] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_initEmbedding",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_InitEmbedding] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_termEmbedding",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_TermEmbedding] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_lockProfileDirectory",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_LockProfileDirectory] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_notifyProfile",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_NotifyProfile] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMImpl_initXPCOM",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_InitXPCOM] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMImpl_shutdownXPCOM",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_ShutdownXPCOM] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentManager",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_GetComponentManager] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentRegistrar",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_GetComponentRegistrar] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMImpl_getServiceManager",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_GetServiceManager] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMImpl_newLocalFile",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_NewLocalFile] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_callXPCOMMethod",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_CallXPCOMMethod] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_finalizeProxy",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_FinalizeProxy] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_isSameXPCOMObject",
|
||||||
|
(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] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
|
||||||
|
{ "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject",
|
||||||
|
(NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
|
||||||
|
{ nsnull, nsnull }
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rv = XPCOMGlueLoadXULFunctions(funcs);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage)
|
||||||
|
{
|
||||||
|
// Only throw this exception if one hasn't already been thrown, so we don't
|
||||||
|
// mask a previous exception/error.
|
||||||
|
if (env->ExceptionCheck())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// If the error code we get is for an Out Of Memory error, try to throw an
|
||||||
|
// OutOfMemoryError. The JVM may have enough memory to create this error.
|
||||||
|
if (aErrorCode == NS_ERROR_OUT_OF_MEMORY) {
|
||||||
|
jclass clazz = env->FindClass("java/lang/OutOfMemoryError");
|
||||||
|
if (clazz) {
|
||||||
|
env->ThrowNew(clazz, aMessage);
|
||||||
|
}
|
||||||
|
env->DeleteLocalRef(clazz);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the error was not handled above, then create an XPCOMException with the
|
||||||
|
// given error code.
|
||||||
|
jthrowable throwObj = nsnull;
|
||||||
|
jclass exceptionClass = env->FindClass("org/mozilla/xpcom/XPCOMException");
|
||||||
|
if (exceptionClass) {
|
||||||
|
jmethodID mid = env->GetMethodID(exceptionClass, "<init>",
|
||||||
|
"(JLjava/lang/String;)V");
|
||||||
|
if (mid) {
|
||||||
|
throwObj = (jthrowable) env->NewObject(exceptionClass, mid,
|
||||||
|
(PRInt64) aErrorCode,
|
||||||
|
env->NewStringUTF(aMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NS_ASSERTION(throwObj, "Failed to create XPCOMException object");
|
||||||
|
|
||||||
|
// throw exception
|
||||||
|
if (throwObj) {
|
||||||
|
env->Throw(throwObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // VBOX
|
||||||
|
|
||||||
|
// Register the JavaXPCOM native methods. This associates a native Java
|
||||||
|
// method with its C implementation.
|
||||||
|
nsresult
|
||||||
|
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[] = {
|
||||||
|
{ "initEmbeddingNative",
|
||||||
|
"(Ljava/io/File;Ljava/io/File;Lorg/mozilla/xpcom/IAppFileLocProvider;)V",
|
||||||
|
(void*) aFunctions[kFunc_InitEmbedding] },
|
||||||
|
{ "termEmbedding", "()V",
|
||||||
|
(void*) aFunctions[kFunc_TermEmbedding] },
|
||||||
|
{ "lockProfileDirectory", "(Ljava/io/File;)Lorg/mozilla/xpcom/ProfileLock;",
|
||||||
|
(void*) aFunctions[kFunc_LockProfileDirectory] },
|
||||||
|
{ "notifyProfile", "()V",
|
||||||
|
(void*) aFunctions[kFunc_NotifyProfile] },
|
||||||
|
};
|
||||||
|
|
||||||
|
JNINativeMethod xpcom_methods[] = {
|
||||||
|
{ "initXPCOMNative",
|
||||||
|
"(Ljava/io/File;Lorg/mozilla/xpcom/IAppFileLocProvider;)Lorg/mozilla/interfaces/nsIServiceManager;",
|
||||||
|
(void*) aFunctions[kFunc_InitXPCOM] },
|
||||||
|
{ "shutdownXPCOM", "(Lorg/mozilla/interfaces/nsIServiceManager;)V",
|
||||||
|
(void*) aFunctions[kFunc_ShutdownXPCOM] },
|
||||||
|
{ "getComponentManager", "()Lorg/mozilla/interfaces/nsIComponentManager;",
|
||||||
|
(void*) aFunctions[kFunc_GetComponentManager] },
|
||||||
|
{ "getComponentRegistrar", "()Lorg/mozilla/interfaces/nsIComponentRegistrar;",
|
||||||
|
(void*) aFunctions[kFunc_GetComponentRegistrar] },
|
||||||
|
{ "getServiceManager", "()Lorg/mozilla/interfaces/nsIServiceManager;",
|
||||||
|
(void*) aFunctions[kFunc_GetServiceManager] },
|
||||||
|
{ "newLocalFile", "(Ljava/lang/String;Z)Lorg/mozilla/interfaces/nsILocalFile;",
|
||||||
|
(void*) aFunctions[kFunc_NewLocalFile] }
|
||||||
|
};
|
||||||
|
|
||||||
|
JNINativeMethod proxy_methods[] = {
|
||||||
|
{ "callXPCOMMethod",
|
||||||
|
"(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;",
|
||||||
|
(void*) aFunctions[kFunc_CallXPCOMMethod] },
|
||||||
|
{ "finalizeProxyNative", "(Ljava/lang/Object;)V",
|
||||||
|
(void*) aFunctions[kFunc_FinalizeProxy] },
|
||||||
|
{ "isSameXPCOMObject", "(Ljava/lang/Object;Ljava/lang/Object;)Z",
|
||||||
|
(void*) aFunctions[kFunc_IsSameXPCOMObject] }
|
||||||
|
};
|
||||||
|
|
||||||
|
JNINativeMethod lockProxy_methods[] = {
|
||||||
|
{ "releaseNative", "(J)V",
|
||||||
|
(void*) aFunctions[kFunc_ReleaseProfileLock] }
|
||||||
|
};
|
||||||
|
|
||||||
|
JNINativeMethod util_methods[] = {
|
||||||
|
{ "wrapJavaObject", "(Ljava/lang/Object;Ljava/lang/String;)J",
|
||||||
|
(void*) aFunctions[kFunc_WrapJavaObject] },
|
||||||
|
{ "wrapXPCOMObject", "(JLjava/lang/String;)Ljava/lang/Object;",
|
||||||
|
(void*) aFunctions[kFunc_WrapXPCOMObject] }
|
||||||
|
};
|
||||||
|
|
||||||
|
jint rc = -1;
|
||||||
|
jclass clazz = env->FindClass("org/mozilla/xpcom/internal/MozillaImpl");
|
||||||
|
if (clazz) {
|
||||||
|
rc = env->RegisterNatives(clazz, mozilla_methods,
|
||||||
|
sizeof(mozilla_methods) / sizeof(mozilla_methods[0]));
|
||||||
|
}
|
||||||
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
rc = -1;
|
||||||
|
clazz = env->FindClass("org/mozilla/xpcom/internal/GREImpl");
|
||||||
|
if (clazz) {
|
||||||
|
rc = env->RegisterNatives(clazz, gre_methods,
|
||||||
|
sizeof(gre_methods) / sizeof(gre_methods[0]));
|
||||||
|
}
|
||||||
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
rc = -1;
|
||||||
|
clazz = env->FindClass("org/mozilla/xpcom/internal/XPCOMImpl");
|
||||||
|
if (clazz) {
|
||||||
|
rc = env->RegisterNatives(clazz, xpcom_methods,
|
||||||
|
sizeof(xpcom_methods) / sizeof(xpcom_methods[0]));
|
||||||
|
}
|
||||||
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
rc = -1;
|
||||||
|
clazz = env->FindClass("org/mozilla/xpcom/internal/XPCOMJavaProxy");
|
||||||
|
if (clazz) {
|
||||||
|
rc = env->RegisterNatives(clazz, proxy_methods,
|
||||||
|
sizeof(proxy_methods) / sizeof(proxy_methods[0]));
|
||||||
|
}
|
||||||
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
rc = -1;
|
||||||
|
clazz = env->FindClass("org/mozilla/xpcom/ProfileLock");
|
||||||
|
if (clazz) {
|
||||||
|
rc = env->RegisterNatives(clazz, lockProxy_methods,
|
||||||
|
sizeof(lockProxy_methods) / sizeof(lockProxy_methods[0]));
|
||||||
|
}
|
||||||
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
rc = -1;
|
||||||
|
clazz = env->FindClass("org/mozilla/xpcom/internal/JavaXPCOMMethods");
|
||||||
|
if (clazz) {
|
||||||
|
rc = env->RegisterNatives(clazz, util_methods,
|
||||||
|
sizeof(util_methods) / sizeof(util_methods[0]));
|
||||||
|
}
|
||||||
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the JavaXPCOM methods from the XUL shared library, and registers them
|
||||||
|
// as Java native methods.
|
||||||
|
extern "C" JX_EXPORT void JNICALL
|
||||||
|
JXM_NATIVE(registerJavaXPCOMMethodsNative) (JNIEnv *env, jclass that,
|
||||||
|
jobject aXPCOMPath)
|
||||||
|
{
|
||||||
|
void* functions[JX_NUM_FUNCS];
|
||||||
|
memset(functions, 0, JX_NUM_FUNCS * sizeof(void*));
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
nsresult rv = FindVBoxMethods(env, aXPCOMPath, functions);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
rv = RegisterNativeMethods(env, functions);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
nsresult rv = LoadXULMethods(env, aXPCOMPath, functions);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
rv = RegisterNativeMethods(env, functions);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
ThrowException(env, rv, "Failed to register JavaXPCOM methods");
|
||||||
|
}
|
||||||
|
}
|
1711
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStub.cpp
Executable file
1711
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStub.cpp
Executable file
File diff suppressed because it is too large
Load diff
153
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStub.h
Executable file
153
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStub.h
Executable file
|
@ -0,0 +1,153 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef _nsJavaXPTCStub_h_
|
||||||
|
#define _nsJavaXPTCStub_h_
|
||||||
|
|
||||||
|
#include "nsXPTCUtils.h"
|
||||||
|
#include "jni.h"
|
||||||
|
#include "nsVoidArray.h"
|
||||||
|
#include "nsIInterfaceInfo.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsWeakReference.h"
|
||||||
|
#include "nsJavaXPTCStubWeakRef.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define NS_JAVAXPTCSTUB_IID \
|
||||||
|
{0x88dd8130, 0xebe6, 0x4431, {0x9d, 0xa7, 0xe6, 0xb7, 0x54, 0x74, 0xfb, 0x21}}
|
||||||
|
|
||||||
|
class nsJavaXPTCStub : protected nsAutoXPTCStub,
|
||||||
|
public nsSupportsWeakReference
|
||||||
|
{
|
||||||
|
friend class nsJavaXPTCStubWeakRef;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSISUPPORTSWEAKREFERENCE
|
||||||
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_JAVAXPTCSTUB_IID)
|
||||||
|
|
||||||
|
nsJavaXPTCStub(jobject aJavaObject, nsIInterfaceInfo *aIInfo,
|
||||||
|
nsresult *rv);
|
||||||
|
|
||||||
|
virtual ~nsJavaXPTCStub();
|
||||||
|
|
||||||
|
// call this method and return result
|
||||||
|
NS_IMETHOD CallMethod(PRUint16 aMethodIndex,
|
||||||
|
const XPTMethodDescriptor *aInfo,
|
||||||
|
nsXPTCMiniVariant *aParams);
|
||||||
|
|
||||||
|
nsISomeInterface* GetStub() { return mXPTCStub; }
|
||||||
|
|
||||||
|
// getter for mJavaObject
|
||||||
|
jobject GetJavaObject();
|
||||||
|
|
||||||
|
// Deletes the strong global ref for the Java object, so it can be garbage
|
||||||
|
// collected if necessary. See DestroyXPTCMappingEnum().
|
||||||
|
void DeleteStrongRef();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the associated nsJavaXPTCStub for the given Java object and IID.
|
||||||
|
* If no such stub exists, then a new one is created.
|
||||||
|
*
|
||||||
|
* @param env Java environment pointer
|
||||||
|
* @param aJavaObject Java object for which to find/create nsJavaXPTCStub
|
||||||
|
* @param aIID desired interface IID for nsJavaXPTCStub
|
||||||
|
* @param aResult on success, holds AddRef'd reference to nsJavaXPTCStub
|
||||||
|
*
|
||||||
|
* @return NS_OK if succeeded; all other return values are error codes.
|
||||||
|
*/
|
||||||
|
static nsresult GetNewOrUsed(JNIEnv* env, jobject aJavaObject,
|
||||||
|
const nsIID& aIID, void** aResult);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRefInternal();
|
||||||
|
NS_IMETHOD_(nsrefcnt) ReleaseInternal();
|
||||||
|
|
||||||
|
// Deletes this object and its members. Called by ReleaseInternal() and
|
||||||
|
// ReleaseWeakRef().
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
|
// When a nsJavaXPTCStubWeakRef associated with this object is released, it
|
||||||
|
// calls this function to let this object know that there is one less weak
|
||||||
|
// ref. If there are no more weakrefs referencing this object, and no one
|
||||||
|
// holds a strong ref, then this function takes care of deleting the object.
|
||||||
|
void ReleaseWeakRef();
|
||||||
|
|
||||||
|
// returns a weak reference to a child supporting the specified interface
|
||||||
|
nsJavaXPTCStub * FindStubSupportingIID(const nsID &aIID);
|
||||||
|
|
||||||
|
// returns true if this stub supports the specified interface
|
||||||
|
PRBool SupportsIID(const nsID &aIID);
|
||||||
|
|
||||||
|
nsresult SetupJavaParams(const nsXPTParamInfo &aParamInfo,
|
||||||
|
const XPTMethodDescriptor* aMethodInfo,
|
||||||
|
PRUint16 aMethodIndex,
|
||||||
|
nsXPTCMiniVariant* aDispatchParams,
|
||||||
|
nsXPTCMiniVariant &aVariant,
|
||||||
|
jvalue &aJValue, nsACString &aMethodSig);
|
||||||
|
nsresult GetRetvalSig(const nsXPTParamInfo* aParamInfo,
|
||||||
|
const XPTMethodDescriptor* aMethodInfo,
|
||||||
|
PRUint16 aMethodIndex,
|
||||||
|
nsXPTCMiniVariant* aDispatchParams,
|
||||||
|
nsACString &aRetvalSig);
|
||||||
|
nsresult FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
|
||||||
|
const XPTMethodDescriptor* aMethodInfo,
|
||||||
|
PRUint16 aMethodIndex,
|
||||||
|
nsXPTCMiniVariant* aDispatchParams,
|
||||||
|
nsXPTCMiniVariant &aVariant,
|
||||||
|
jvalue &aJValue);
|
||||||
|
nsresult SetXPCOMRetval();
|
||||||
|
|
||||||
|
jobject mJavaWeakRef;
|
||||||
|
jobject mJavaStrongRef;
|
||||||
|
jint mJavaRefHashCode;
|
||||||
|
nsCOMPtr<nsIInterfaceInfo> mIInfo;
|
||||||
|
|
||||||
|
nsVoidArray mChildren; // weak references (cleared by the children)
|
||||||
|
nsJavaXPTCStub *mMaster; // strong reference
|
||||||
|
|
||||||
|
nsAutoRefCnt mWeakRefCnt; // count for number of associated weak refs
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
NS_DEFINE_STATIC_IID_ACCESSOR2(nsJavaXPTCStub, NS_JAVAXPTCSTUB_IID)
|
||||||
|
#else
|
||||||
|
NS_DEFINE_STATIC_IID_ACCESSOR2(nsJavaXPTCStub, NS_JAVAXPTCSTUB_IID)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _nsJavaXPTCStub_h_
|
98
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStubWeakRef.cpp
Executable file
98
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStubWeakRef.cpp
Executable file
|
@ -0,0 +1,98 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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"
|
||||||
|
#include "nsJavaXPTCStubWeakRef.h"
|
||||||
|
#include "nsJavaXPTCStub.h"
|
||||||
|
#include "nsJavaXPCOMBindingUtils.h"
|
||||||
|
#include "nsIInterfaceInfoManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How we handle XPCOM weak references to a Java object:
|
||||||
|
*
|
||||||
|
* If XPCOM requires or asks for a weak reference of a Java object, we first
|
||||||
|
* find (or create) an nsJavaXPTCStub for that Java object. That way, there is
|
||||||
|
* always an nsJavaXPTCStub for any nsJavaXPTCStubWeakRef. However, the
|
||||||
|
* XPTCStub may not always be 'valid'; that is, its refcount may be zero if
|
||||||
|
* is not currently referenced by any XPCOM class.
|
||||||
|
* When an XPCOM method queries the referent from the weak reference, the
|
||||||
|
* weak ref checks first whether the Java object is still valid. If so, we can
|
||||||
|
* immediately return an addref'd nsJavaXPTCStub. The XPTCStub takes care of
|
||||||
|
* finding an XPTCStub for the required IID.
|
||||||
|
*/
|
||||||
|
|
||||||
|
nsJavaXPTCStubWeakRef::nsJavaXPTCStubWeakRef(jobject aJavaObject,
|
||||||
|
nsJavaXPTCStub* aXPTCStub)
|
||||||
|
: mXPTCStub(aXPTCStub)
|
||||||
|
{
|
||||||
|
JNIEnv* env = GetJNIEnv();
|
||||||
|
jobject weakref = env->NewObject(weakReferenceClass,
|
||||||
|
weakReferenceConstructorMID, aJavaObject);
|
||||||
|
mWeakRef = env->NewGlobalRef(weakref);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsJavaXPTCStubWeakRef::~nsJavaXPTCStubWeakRef()
|
||||||
|
{
|
||||||
|
JNIEnv* env = GetJNIEnv();
|
||||||
|
env->CallVoidMethod(mWeakRef, clearReferentMID);
|
||||||
|
env->DeleteGlobalRef(mWeakRef);
|
||||||
|
mXPTCStub->ReleaseWeakRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsJavaXPTCStubWeakRef)
|
||||||
|
NS_IMPL_RELEASE(nsJavaXPTCStubWeakRef)
|
||||||
|
|
||||||
|
NS_IMPL_QUERY_INTERFACE1(nsJavaXPTCStubWeakRef, nsIWeakReference)
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsJavaXPTCStubWeakRef::QueryReferent(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
LOG(("nsJavaXPTCStubWeakRef::QueryReferent()\n"));
|
||||||
|
|
||||||
|
// Is weak ref still valid?
|
||||||
|
// We create a strong local ref to make sure Java object isn't garbage
|
||||||
|
// collected during this call.
|
||||||
|
JNIEnv* env = GetJNIEnv();
|
||||||
|
jobject javaObject = env->CallObjectMethod(mWeakRef, getReferentMID);
|
||||||
|
if (env->IsSameObject(javaObject, NULL))
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
// Java object has not been garbage collected, so return QI from XPTCStub.
|
||||||
|
return mXPTCStub->QueryInterface(aIID, aInstancePtr);
|
||||||
|
}
|
||||||
|
|
63
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStubWeakRef.h
Executable file
63
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsJavaXPTCStubWeakRef.h
Executable file
|
@ -0,0 +1,63 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef _nsJavaXPTCStubWeakRef_h_
|
||||||
|
#define _nsJavaXPTCStubWeakRef_h_
|
||||||
|
|
||||||
|
#include "jni.h"
|
||||||
|
#include "nsIWeakReference.h"
|
||||||
|
|
||||||
|
|
||||||
|
class nsJavaXPTCStub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents an XPCOM weak reference to a Java object.
|
||||||
|
*/
|
||||||
|
class nsJavaXPTCStubWeakRef : public nsIWeakReference
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsJavaXPTCStubWeakRef(jobject aJavaObject, nsJavaXPTCStub* aXPTCStub);
|
||||||
|
virtual ~nsJavaXPTCStubWeakRef();
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIWEAKREFERENCE
|
||||||
|
|
||||||
|
protected:
|
||||||
|
jobject mWeakRef;
|
||||||
|
nsJavaXPTCStub* mXPTCStub;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _nsJavaXPTCStubWeakRef_h_
|
399
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsThreadUtils.h
Executable file
399
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsThreadUtils.h
Executable file
|
@ -0,0 +1,399 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||||
|
/* ***** 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 Mozilla code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Google Inc.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Darin Fisher <darin@meer.net>
|
||||||
|
*
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef nsThreadUtils_h__
|
||||||
|
#define nsThreadUtils_h__
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
#include "nsIThread.h"
|
||||||
|
|
||||||
|
inline already_AddRefed<nsIThread>
|
||||||
|
do_GetMainThread() {
|
||||||
|
nsIThread *thread = nsnull;
|
||||||
|
nsIThread::GetMainThread(&thread);
|
||||||
|
return already_AddRefed<nsIThread>(thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "VBox/com/NativeEventQueue.h"
|
||||||
|
|
||||||
|
inline already_AddRefed<nsIEventQueue> do_GetMainThreadQueue()
|
||||||
|
{
|
||||||
|
com::NativeEventQueue* eq = com::NativeEventQueue::getMainEventQueue();
|
||||||
|
NS_ASSERTION(eq != nsnull, "Must be valid");
|
||||||
|
return eq->getIEventQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#include "prthread.h"
|
||||||
|
#include "prinrval.h"
|
||||||
|
#include "nsIThreadManager.h"
|
||||||
|
#include "nsIThread.h"
|
||||||
|
#include "nsIRunnable.h"
|
||||||
|
#include "nsStringGlue.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
|
||||||
|
// This is needed on some systems to prevent collisions between the symbols
|
||||||
|
// appearing in xpcom_core and xpcomglue. It may be unnecessary in the future
|
||||||
|
// with better toolchain support.
|
||||||
|
#ifdef MOZILLA_INTERNAL_API
|
||||||
|
# define NS_NewThread NS_NewThread_P
|
||||||
|
# define NS_GetCurrentThread NS_GetCurrentThread_P
|
||||||
|
# define NS_GetMainThread NS_GetMainThread_P
|
||||||
|
# define NS_IsMainThread NS_IsMainThread_P
|
||||||
|
# define NS_DispatchToCurrentThread NS_DispatchToCurrentThread_P
|
||||||
|
# define NS_DispatchToMainThread NS_DispatchToMainThread_P
|
||||||
|
# define NS_ProcessPendingEvents NS_ProcessPendingEvents_P
|
||||||
|
# define NS_HasPendingEvents NS_HasPendingEvents_P
|
||||||
|
# define NS_ProcessNextEvent NS_ProcessNextEvent_P
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// These methods are alternatives to the methods on nsIThreadManager, provided
|
||||||
|
// for convenience.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new thread, and optionally provide an initial event for the thread.
|
||||||
|
*
|
||||||
|
* @param result
|
||||||
|
* The resulting nsIThread object.
|
||||||
|
* @param initialEvent
|
||||||
|
* The initial event to run on this thread. This parameter may be null.
|
||||||
|
*
|
||||||
|
* @returns NS_ERROR_INVALID_ARG
|
||||||
|
* Indicates that the given name is not unique.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE NS_METHOD
|
||||||
|
NS_NewThread(nsIThread **result, nsIRunnable *initialEvent = nsnull);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a reference to the current thread.
|
||||||
|
*
|
||||||
|
* @param result
|
||||||
|
* The resulting nsIThread object.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE NS_METHOD
|
||||||
|
NS_GetCurrentThread(nsIThread **result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a reference to the main thread.
|
||||||
|
*
|
||||||
|
* @param result
|
||||||
|
* The resulting nsIThread object.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE NS_METHOD
|
||||||
|
NS_GetMainThread(nsIThread **result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to see if the current thread is the main thread.
|
||||||
|
*
|
||||||
|
* @returns PR_TRUE if the current thread is the main thread, and PR_FALSE
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE NS_METHOD_(PRBool)
|
||||||
|
NS_IsMainThread();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch the given event to the current thread.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
* The event to dispatch.
|
||||||
|
*
|
||||||
|
* @returns NS_ERROR_INVALID_ARG
|
||||||
|
* If event is null.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE NS_METHOD
|
||||||
|
NS_DispatchToCurrentThread(nsIRunnable *event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch the given event to the main thread.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
* The event to dispatch.
|
||||||
|
* @param dispatchFlags
|
||||||
|
* The flags to pass to the main thread's dispatch method.
|
||||||
|
*
|
||||||
|
* @returns NS_ERROR_INVALID_ARG
|
||||||
|
* If event is null.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE NS_METHOD
|
||||||
|
NS_DispatchToMainThread(nsIRunnable *event,
|
||||||
|
PRUint32 dispatchFlags = NS_DISPATCH_NORMAL);
|
||||||
|
|
||||||
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
||||||
|
/**
|
||||||
|
* Process all pending events for the given thread before returning. This
|
||||||
|
* method simply calls ProcessNextEvent on the thread while HasPendingEvents
|
||||||
|
* continues to return true and the time spent in NS_ProcessPendingEvents
|
||||||
|
* does not exceed the given timeout value.
|
||||||
|
*
|
||||||
|
* @param thread
|
||||||
|
* The thread object for which to process pending events. If null, then
|
||||||
|
* events will be processed for the current thread.
|
||||||
|
* @param timeout
|
||||||
|
* The maximum number of milliseconds to spend processing pending events.
|
||||||
|
* Events are not pre-empted to honor this timeout. Rather, the timeout
|
||||||
|
* value is simply used to determine whether or not to process another event.
|
||||||
|
* Pass PR_INTERVAL_NO_TIMEOUT to specify no timeout.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE NS_METHOD
|
||||||
|
NS_ProcessPendingEvents(nsIThread *thread,
|
||||||
|
PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for nsIThread::HasPendingEvents.
|
||||||
|
*
|
||||||
|
* It is an error to call this function when the given thread is not the
|
||||||
|
* current thread. This function will return PR_FALSE if called from some
|
||||||
|
* other thread.
|
||||||
|
*
|
||||||
|
* @param thread
|
||||||
|
* The current thread or null.
|
||||||
|
*
|
||||||
|
* @returns
|
||||||
|
* A boolean value that if "true" indicates that there are pending events
|
||||||
|
* in the current thread's event queue.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE PRBool
|
||||||
|
NS_HasPendingEvents(nsIThread *thread = nsnull);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for nsIThread::ProcessNextEvent.
|
||||||
|
*
|
||||||
|
* It is an error to call this function when the given thread is not the
|
||||||
|
* current thread. This function will simply return PR_FALSE if called
|
||||||
|
* from some other thread.
|
||||||
|
*
|
||||||
|
* @param thread
|
||||||
|
* The current thread or null.
|
||||||
|
* @param mayWait
|
||||||
|
* A boolean parameter that if "true" indicates that the method may block
|
||||||
|
* the calling thread to wait for a pending event.
|
||||||
|
*
|
||||||
|
* @returns
|
||||||
|
* A boolean value that if "true" indicates that an event from the current
|
||||||
|
* thread's event queue was processed.
|
||||||
|
*/
|
||||||
|
extern NS_COM_GLUE PRBool
|
||||||
|
NS_ProcessNextEvent(nsIThread *thread = nsnull, PRBool mayWait = PR_TRUE);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Helpers that work with nsCOMPtr:
|
||||||
|
|
||||||
|
inline already_AddRefed<nsIThread>
|
||||||
|
do_GetCurrentThread() {
|
||||||
|
nsIThread *thread = nsnull;
|
||||||
|
NS_GetCurrentThread(&thread);
|
||||||
|
return already_AddRefed<nsIThread>(thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline already_AddRefed<nsIThread>
|
||||||
|
do_GetMainThread() {
|
||||||
|
nsIThread *thread = nsnull;
|
||||||
|
NS_GetMainThread(&thread);
|
||||||
|
return already_AddRefed<nsIThread>(thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef MOZILLA_INTERNAL_API
|
||||||
|
// Fast access to the current thread. Do not release the returned pointer! If
|
||||||
|
// you want to use this pointer from some other thread, then you will need to
|
||||||
|
// AddRef it. Otherwise, you should only consider this pointer valid from code
|
||||||
|
// running on the current thread.
|
||||||
|
extern NS_COM_GLUE nsIThread *NS_GetCurrentThread();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
||||||
|
|
||||||
|
#undef IMETHOD_VISIBILITY
|
||||||
|
#define IMETHOD_VISIBILITY NS_COM_GLUE
|
||||||
|
|
||||||
|
// This class is designed to be subclassed.
|
||||||
|
class NS_COM_GLUE nsRunnable : public nsIRunnable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIRUNNABLE
|
||||||
|
|
||||||
|
nsRunnable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual ~nsRunnable() {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef IMETHOD_VISIBILITY
|
||||||
|
#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
|
||||||
|
|
||||||
|
// An event that can be used to call a method on a class. The class type must
|
||||||
|
// support reference counting.
|
||||||
|
template <class T>
|
||||||
|
class nsRunnableMethod : public nsRunnable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void (T::*Method)();
|
||||||
|
|
||||||
|
nsRunnableMethod(T *obj, Method method)
|
||||||
|
: mObj(obj), mMethod(method) {
|
||||||
|
NS_ADDREF(mObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHOD Run() {
|
||||||
|
(mObj->*mMethod)();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual ~nsRunnableMethod() {
|
||||||
|
NS_RELEASE(mObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
T *mObj;
|
||||||
|
Method mMethod;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use this helper macro like so:
|
||||||
|
//
|
||||||
|
// nsCOMPtr<nsIRunnable> event =
|
||||||
|
// NS_NEW_RUNNABLE_METHOD(MyClass, myObject, HandleEvent);
|
||||||
|
// NS_DispatchToCurrentThread(event);
|
||||||
|
//
|
||||||
|
// Constraints:
|
||||||
|
// - myObject must be of type MyClass
|
||||||
|
// - MyClass must defined AddRef and Release methods
|
||||||
|
//
|
||||||
|
// NOTE: Attempts to make this a template function caused VC6 to barf :-(
|
||||||
|
//
|
||||||
|
#define NS_NEW_RUNNABLE_METHOD(class_, obj_, method_) \
|
||||||
|
new nsRunnableMethod<class_>(obj_, &class_::method_)
|
||||||
|
|
||||||
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
||||||
|
|
||||||
|
// This class is designed to be used when you have an event class E that has a
|
||||||
|
// pointer back to resource class R. If R goes away while E is still pending,
|
||||||
|
// then it is important to "revoke" E so that it does not try use R after R has
|
||||||
|
// been destroyed. nsRevocableEventPtr makes it easy for R to manage such
|
||||||
|
// situations:
|
||||||
|
//
|
||||||
|
// class R;
|
||||||
|
//
|
||||||
|
// class E : public nsRunnable {
|
||||||
|
// public:
|
||||||
|
// void Revoke() {
|
||||||
|
// mResource = nsnull;
|
||||||
|
// }
|
||||||
|
// private:
|
||||||
|
// R *mResource;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// class R {
|
||||||
|
// public:
|
||||||
|
// void EventHandled() {
|
||||||
|
// mEvent.Forget();
|
||||||
|
// }
|
||||||
|
// private:
|
||||||
|
// nsRevocableEventPtr<E> mEvent;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// void R::PostEvent() {
|
||||||
|
// // Make sure any pending event is revoked.
|
||||||
|
// mEvent->Revoke();
|
||||||
|
//
|
||||||
|
// nsCOMPtr<nsIRunnable> event = new E();
|
||||||
|
// if (NS_SUCCEEDED(NS_DispatchToCurrentThread(event))) {
|
||||||
|
// // Keep pointer to event so we can revoke it.
|
||||||
|
// mEvent = event;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// NS_IMETHODIMP E::Run() {
|
||||||
|
// if (!mResource)
|
||||||
|
// return NS_OK;
|
||||||
|
// ...
|
||||||
|
// mResource->EventHandled();
|
||||||
|
// return NS_OK;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
template <class T>
|
||||||
|
class nsRevocableEventPtr {
|
||||||
|
public:
|
||||||
|
nsRevocableEventPtr()
|
||||||
|
: mEvent(nsnull) {
|
||||||
|
}
|
||||||
|
|
||||||
|
~nsRevocableEventPtr() {
|
||||||
|
Revoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
const nsRevocableEventPtr& operator=(T *event) {
|
||||||
|
Revoke();
|
||||||
|
mEvent = event;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Revoke() {
|
||||||
|
if (mEvent) {
|
||||||
|
mEvent->Revoke();
|
||||||
|
mEvent = nsnull;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Forget() {
|
||||||
|
mEvent = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool IsPending() {
|
||||||
|
return mEvent != nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Not implemented
|
||||||
|
nsRevocableEventPtr(const nsRevocableEventPtr&);
|
||||||
|
nsRevocableEventPtr& operator=(const nsRevocableEventPtr&);
|
||||||
|
|
||||||
|
T *mEvent;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // nsThreadUtils_h__
|
128
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsXPTCUtils.h
Executable file
128
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/nsXPTCUtils.h
Executable file
|
@ -0,0 +1,128 @@
|
||||||
|
/* ***** 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 Mozilla XPCOM.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* the Mozilla Foundation <http://www.mozilla.org/>.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Benjamin Smedberg <benjamin@smedbergs.us> - New code
|
||||||
|
*
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
#ifndef nsXPTCUtils_h__
|
||||||
|
#define nsXPTCUtils_h__
|
||||||
|
|
||||||
|
#include "xptcall.h"
|
||||||
|
|
||||||
|
#ifdef VBOX
|
||||||
|
|
||||||
|
#define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \
|
||||||
|
template <class Dummy> \
|
||||||
|
struct COMTypeInfo \
|
||||||
|
{ \
|
||||||
|
static const nsIID kIID NS_HIDDEN; \
|
||||||
|
}; \
|
||||||
|
static const nsIID& GetIID() {return COMTypeInfo<int>::kIID;}
|
||||||
|
|
||||||
|
|
||||||
|
#define NS_DEFINE_STATIC_IID_ACCESSOR2(the_interface, the_iid) \
|
||||||
|
template <class Dummy> \
|
||||||
|
const nsIID the_interface::COMTypeInfo<Dummy>::kIID NS_HIDDEN = the_iid;
|
||||||
|
|
||||||
|
|
||||||
|
class nsIXPTCProxy : public nsISupports
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_IMETHOD CallMethod(PRUint16 aMethodIndex,
|
||||||
|
const XPTMethodDescriptor *aInfo,
|
||||||
|
nsXPTCMiniVariant *aParams) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a typedef to avoid confusion between the canonical
|
||||||
|
* nsISupports* that provides object identity and an interface pointer
|
||||||
|
* for inheriting interfaces that aren't known at compile-time.
|
||||||
|
*/
|
||||||
|
typedef nsISupports nsISomeInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a proxy object to implement the specified interface.
|
||||||
|
*
|
||||||
|
* @param aIID The IID of the interface to implement.
|
||||||
|
* @param aOuter An object to receive method calls from the proxy object.
|
||||||
|
* The stub forwards QueryInterface/AddRef/Release to the
|
||||||
|
* outer object. The proxy object does not hold a reference to
|
||||||
|
* the outer object; it is the caller's responsibility to
|
||||||
|
* ensure that this pointer remains valid until the stub has
|
||||||
|
* been destroyed.
|
||||||
|
* @param aStub Out parameter for the new proxy object. The object is
|
||||||
|
* not addrefed. The object never destroys itself. It must be
|
||||||
|
* explicitly destroyed by calling
|
||||||
|
* NS_DestroyXPTCallStub when it is no longer needed.
|
||||||
|
*/
|
||||||
|
XPTC_PUBLIC_API(nsresult)
|
||||||
|
NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
|
||||||
|
nsISomeInterface* *aStub);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys an XPTCall stub previously created with NS_GetXPTCallStub.
|
||||||
|
*/
|
||||||
|
XPTC_PUBLIC_API(void)
|
||||||
|
NS_DestroyXPTCallStub(nsISomeInterface* aStub);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper class that initializes an xptcall helper at construction
|
||||||
|
* and releases it at destruction.
|
||||||
|
*/
|
||||||
|
class nsAutoXPTCStub : protected nsIXPTCProxy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsISomeInterface* mXPTCStub;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsAutoXPTCStub() : mXPTCStub(nsnull) { }
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
InitStub(const nsIID& aIID)
|
||||||
|
{
|
||||||
|
return NS_GetXPTCallStub(aIID, this, &mXPTCStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
~nsAutoXPTCStub()
|
||||||
|
{
|
||||||
|
if (mXPTCStub)
|
||||||
|
NS_DestroyXPTCallStub(mXPTCStub);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsXPTCUtils_h__
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
|
||||||
|
public class GREVersionRange {
|
||||||
|
|
||||||
|
private String lower;
|
||||||
|
private boolean lowerInclusive;
|
||||||
|
private String upper;
|
||||||
|
private boolean upperInclusive;
|
||||||
|
|
||||||
|
public GREVersionRange(String aLower, boolean aLowerInclusive,
|
||||||
|
String aUpper, boolean aUpperInclusive) {
|
||||||
|
lower = aLower;
|
||||||
|
lowerInclusive = aLowerInclusive;
|
||||||
|
upper = aUpper;
|
||||||
|
upperInclusive = aUpperInclusive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check(String aVersion) {
|
||||||
|
VersionComparator comparator = new VersionComparator();
|
||||||
|
int c = comparator.compare(aVersion, lower);
|
||||||
|
if (c < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 0 && !lowerInclusive) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = comparator.compare(aVersion, upper);
|
||||||
|
if (c > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 0 && !upperInclusive) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
/* ***** 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) 2004
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by XPCOM's Directory Service to get file locations.
|
||||||
|
* <p>
|
||||||
|
* This interface is similar to <code>nsIDirectoryServiceProvider</code> and
|
||||||
|
* <code>nsIDirectoryServiceProvider2</code>, except that its methods use
|
||||||
|
* <code>java.io.File</code> instead of <code>nsIFile</code>.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see Mozilla#initEmbedding
|
||||||
|
* @see Mozilla#initXPCOM
|
||||||
|
* @see <a href=
|
||||||
|
* "http://lxr.mozilla.org/mozilla/source/xpcom/io/nsIDirectoryService.idl">
|
||||||
|
* nsIDirectoryServiceProvider </a>
|
||||||
|
* @see <a href=
|
||||||
|
* "http://lxr.mozilla.org/mozilla/source/xpcom/io/nsDirectoryServiceDefs.h">
|
||||||
|
* Directory Service property names </a>
|
||||||
|
*/
|
||||||
|
public interface IAppFileLocProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directory Service calls this when it gets the first request for
|
||||||
|
* a property or on every request if the property is not persistent.
|
||||||
|
*
|
||||||
|
* @param prop the symbolic name of the file
|
||||||
|
* @param persistent an array of length one used to supply the output value:
|
||||||
|
* <ul>
|
||||||
|
* <li><code>true</code> - The returned file will be
|
||||||
|
* cached by Directory Service. Subsequent requests for
|
||||||
|
* this prop will bypass the provider and use the cache.
|
||||||
|
* </li>
|
||||||
|
* <li><code>false</code> - The provider will be asked
|
||||||
|
* for this prop each time it is requested. </li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @return the file represented by the property
|
||||||
|
*/
|
||||||
|
File getFile(String prop, boolean[] persistent);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directory Service calls this when it gets a request for
|
||||||
|
* a property and the requested type is nsISimpleEnumerator.
|
||||||
|
*
|
||||||
|
* @param prop the symbolic name of the file list
|
||||||
|
*
|
||||||
|
* @return an array of file locations
|
||||||
|
*/
|
||||||
|
File[] getFiles(String prop);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
127
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/IGRE.java
Executable file
127
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/IGRE.java
Executable file
|
@ -0,0 +1,127 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
|
||||||
|
public interface IGRE {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes libXUL for embedding purposes.
|
||||||
|
* <p>
|
||||||
|
* NOTE: This function must be called from the "main" thread.
|
||||||
|
* <p>
|
||||||
|
* NOTE: At the present time, this function may only be called once in
|
||||||
|
* a given process. Use <code>termEmbedding</code> to clean up and free
|
||||||
|
* resources allocated by <code>initEmbedding</code>.
|
||||||
|
*
|
||||||
|
* @param aLibXULDirectory The directory in which the libXUL shared library
|
||||||
|
* was found.
|
||||||
|
* @param aAppDirectory The directory in which the application components
|
||||||
|
* and resources can be found. This will map to
|
||||||
|
* the "resource:app" directory service key.
|
||||||
|
* @param aAppDirProvider A directory provider for the application. This
|
||||||
|
* provider will be aggregated by a libXUL provider
|
||||||
|
* which will provide the base required GRE keys.
|
||||||
|
*
|
||||||
|
* @throws XPCOMException if a failure occurred during initialization
|
||||||
|
*/
|
||||||
|
void initEmbedding(File aLibXULDirectory, File aAppDirectory,
|
||||||
|
IAppFileLocProvider aAppDirProvider) throws XPCOMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminates libXUL embedding.
|
||||||
|
* <p>
|
||||||
|
* NOTE: Release any references to XPCOM objects that you may be holding
|
||||||
|
* before calling this function.
|
||||||
|
*/
|
||||||
|
void termEmbedding();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lock a profile directory using platform-specific semantics.
|
||||||
|
*
|
||||||
|
* @param aDirectory The profile directory to lock.
|
||||||
|
*
|
||||||
|
* @return A lock object. The directory will remain locked until the lock is
|
||||||
|
* released by invoking the <code>release</code> method, or by the
|
||||||
|
* termination of the JVM, whichever comes first.
|
||||||
|
*
|
||||||
|
* @throws XPCOMException if a failure occurred
|
||||||
|
*/
|
||||||
|
ProfileLock lockProfileDirectory(File aDirectory) throws XPCOMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fire notifications to inform the toolkit about a new profile. This
|
||||||
|
* method should be called after <code>initEmbedding</code> if the
|
||||||
|
* embedder wishes to run with a profile.
|
||||||
|
* <p>
|
||||||
|
* Normally the embedder should call <code>lockProfileDirectory</code>
|
||||||
|
* to lock the directory before calling this method.
|
||||||
|
* <p>
|
||||||
|
* NOTE: There are two possibilities for selecting a profile:
|
||||||
|
* <ul>
|
||||||
|
* <li>
|
||||||
|
* Select the profile before calling <code>initEmbedding</code>.
|
||||||
|
* The aAppDirProvider object passed to <code>initEmbedding</code>
|
||||||
|
* should provide the NS_APP_USER_PROFILE_50_DIR key, and
|
||||||
|
* may also provide the following keys:
|
||||||
|
* <ul>
|
||||||
|
* <li>NS_APP_USER_PROFILE_LOCAL_50_DIR
|
||||||
|
* <li>NS_APP_PROFILE_DIR_STARTUP
|
||||||
|
* <li>NS_APP_PROFILE_LOCAL_DIR_STARTUP
|
||||||
|
* </ul>
|
||||||
|
* In this scenario <code>notifyProfile</code> should be called
|
||||||
|
* immediately after <code>initEmbedding</code>. Component
|
||||||
|
* registration information will be stored in the profile and
|
||||||
|
* JS components may be stored in the fastload cache.
|
||||||
|
* </li>
|
||||||
|
* <li>
|
||||||
|
* Select a profile some time after calling <code>initEmbedding</code>.
|
||||||
|
* In this case the embedder must install a directory service
|
||||||
|
* provider which provides NS_APP_USER_PROFILE_50_DIR and optionally
|
||||||
|
* NS_APP_USER_PROFILE_LOCAL_50_DIR. Component registration information
|
||||||
|
* will be stored in the application directory and JS components will not
|
||||||
|
* fastload.
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
void notifyProfile();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* ***** 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) 2007
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
public interface IJavaXPCOMUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pointer to a C++ proxy object for the given Java object.
|
||||||
|
*
|
||||||
|
* @param aJavaObject Java object to encapsulate in C++ proxy
|
||||||
|
* @param aIID interface ID for requested proxy
|
||||||
|
* @return C pointer (as long) of new proxy
|
||||||
|
*/
|
||||||
|
long wrapJavaObject(Object aJavaObject, String aIID);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a Java proxy for the given C++ XPCOM object
|
||||||
|
*
|
||||||
|
* @param aXPCOMObject C++ XPCOM object to encapsulate in Java proxy
|
||||||
|
* @param aIID interface ID for requested proxy
|
||||||
|
* @return new Proxy
|
||||||
|
*/
|
||||||
|
Object wrapXPCOMObject(long aXPCOMObject, String aIID);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
243
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/INIParser.java
Executable file
243
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/INIParser.java
Executable file
|
@ -0,0 +1,243 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple parser for INI files.
|
||||||
|
*/
|
||||||
|
public class INIParser {
|
||||||
|
|
||||||
|
private HashMap<String, Properties> mSections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new <code>INIParser</code> instance from the INI file at the
|
||||||
|
* given path. <code>aCharset</code> specifies the character encoding of
|
||||||
|
* the file.
|
||||||
|
*
|
||||||
|
* @param aFilename path of INI file to parse
|
||||||
|
* @param aCharset character encoding of file
|
||||||
|
* @throws FileNotFoundException if <code>aFilename</code> does not exist.
|
||||||
|
* @throws IOException if there is a problem reading the given file.
|
||||||
|
*/
|
||||||
|
public INIParser(String aFilename, Charset aCharset)
|
||||||
|
throws FileNotFoundException, IOException {
|
||||||
|
initFromFile(new File(aFilename), aCharset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new <code>INIParser</code> instance from the INI file at the
|
||||||
|
* given path, which is assumed to be in the <code>UTF-8</code> charset.
|
||||||
|
*
|
||||||
|
* @param aFilename path of INI file to parse
|
||||||
|
* @throws FileNotFoundException if <code>aFilename</code> does not exist.
|
||||||
|
* @throws IOException if there is a problem reading the given file.
|
||||||
|
*/
|
||||||
|
public INIParser(String aFilename) throws FileNotFoundException, IOException {
|
||||||
|
initFromFile(new File(aFilename), Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new <code>INIParser</code> instance from the given file.
|
||||||
|
* <code>aCharset</code> specifies the character encoding of the file.
|
||||||
|
*
|
||||||
|
* @param aFile INI file to parse
|
||||||
|
* @param aCharset character encoding of file
|
||||||
|
* @throws FileNotFoundException if <code>aFile</code> does not exist.
|
||||||
|
* @throws IOException if there is a problem reading the given file.
|
||||||
|
*/
|
||||||
|
public INIParser(File aFile, Charset aCharset)
|
||||||
|
throws FileNotFoundException, IOException {
|
||||||
|
initFromFile(aFile, aCharset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new <code>INIParser</code> instance from the given file,
|
||||||
|
* which is assumed to be in the <code>UTF-8</code> charset.
|
||||||
|
*
|
||||||
|
* @param aFile INI file to parse
|
||||||
|
* @throws FileNotFoundException if <code>aFile</code> does not exist.
|
||||||
|
* @throws IOException if there is a problem reading the given file.
|
||||||
|
*/
|
||||||
|
public INIParser(File aFile) throws FileNotFoundException, IOException {
|
||||||
|
initFromFile(aFile, Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses given INI file.
|
||||||
|
*
|
||||||
|
* @param aFile INI file to parse
|
||||||
|
* @param aCharset character encoding of file
|
||||||
|
* @throws FileNotFoundException if <code>aFile</code> does not exist.
|
||||||
|
* @throws IOException if there is a problem reading the given file.
|
||||||
|
*/
|
||||||
|
private void initFromFile(File aFile, Charset aCharset)
|
||||||
|
throws FileNotFoundException, IOException {
|
||||||
|
FileInputStream fileStream = new FileInputStream(aFile);
|
||||||
|
InputStreamReader inStream = new InputStreamReader(fileStream, aCharset);
|
||||||
|
BufferedReader reader = new BufferedReader(inStream);
|
||||||
|
|
||||||
|
mSections = new HashMap<String, Properties>();
|
||||||
|
String currSection = null;
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
// skip empty lines and comment lines
|
||||||
|
String trimmedLine = line.trim();
|
||||||
|
if (trimmedLine.length() == 0 || trimmedLine.startsWith("#")
|
||||||
|
|| trimmedLine.startsWith(";")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for section headers (i.e. "[Section]").
|
||||||
|
if (line.startsWith("[")) {
|
||||||
|
/*
|
||||||
|
* We are looking for a well-formed "[Section]". If this header is
|
||||||
|
* malformed (i.e. "[Section" or "[Section]Moretext"), just skip it
|
||||||
|
* and go on to next well-formed section header.
|
||||||
|
*/
|
||||||
|
if (!trimmedLine.endsWith("]") ||
|
||||||
|
trimmedLine.indexOf("]") != (trimmedLine.length() - 1)) {
|
||||||
|
currSection = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove enclosing brackets
|
||||||
|
currSection = trimmedLine.substring(1, trimmedLine.length() - 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we haven't found a valid section header, continue to next line
|
||||||
|
if (currSection == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringTokenizer tok = new StringTokenizer(line, "=");
|
||||||
|
if (tok.countTokens() != 2) { // looking for value pairs
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties props = mSections.get(currSection);
|
||||||
|
if (props == null) {
|
||||||
|
props = new Properties();
|
||||||
|
mSections.put(currSection, props);
|
||||||
|
}
|
||||||
|
props.setProperty(tok.nextToken(), tok.nextToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an iterator over the section names available in the INI file.
|
||||||
|
*
|
||||||
|
* @return an iterator over the section names
|
||||||
|
*/
|
||||||
|
public Iterator getSections() {
|
||||||
|
return mSections.keySet().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an iterator over the keys available within a section.
|
||||||
|
*
|
||||||
|
* @param aSection section name whose keys are to be returned
|
||||||
|
* @return an iterator over section keys, or <code>null</code> if no
|
||||||
|
* such section exists
|
||||||
|
*/
|
||||||
|
public Iterator getKeys(String aSection) {
|
||||||
|
/*
|
||||||
|
* Simple wrapper class to convert Enumeration to Iterator
|
||||||
|
*/
|
||||||
|
class PropertiesIterator implements Iterator {
|
||||||
|
private Enumeration e;
|
||||||
|
|
||||||
|
public PropertiesIterator(Enumeration aEnum) {
|
||||||
|
e = aEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
return e.hasMoreElements();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object next() {
|
||||||
|
return e.nextElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties props = mSections.get(aSection);
|
||||||
|
if (props == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PropertiesIterator(props.propertyNames());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the string value for a particular section and key.
|
||||||
|
*
|
||||||
|
* @param aSection a section name
|
||||||
|
* @param aKey the key whose value is to be returned.
|
||||||
|
* @return string value of particular section and key
|
||||||
|
*/
|
||||||
|
public String getString(String aSection, String aKey) {
|
||||||
|
Properties props = mSections.get(aSection);
|
||||||
|
if (props == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return props.getProperty(aKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
137
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/IXPCOM.java
Executable file
137
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/IXPCOM.java
Executable file
|
@ -0,0 +1,137 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.mozilla.interfaces.nsIComponentManager;
|
||||||
|
import org.mozilla.interfaces.nsIComponentRegistrar;
|
||||||
|
import org.mozilla.interfaces.nsILocalFile;
|
||||||
|
import org.mozilla.interfaces.nsIServiceManager;
|
||||||
|
|
||||||
|
|
||||||
|
public interface IXPCOM {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes XPCOM. You must call this method before proceeding
|
||||||
|
* to use XPCOM.
|
||||||
|
*
|
||||||
|
* @param aMozBinDirectory The directory containing the component
|
||||||
|
* registry and runtime libraries;
|
||||||
|
* or use <code>null</code> to use the working
|
||||||
|
* directory.
|
||||||
|
*
|
||||||
|
* @param aAppFileLocProvider The object to be used by Gecko that specifies
|
||||||
|
* to Gecko where to find profiles, the component
|
||||||
|
* registry preferences and so on; or use
|
||||||
|
* <code>null</code> for the default behaviour.
|
||||||
|
*
|
||||||
|
* @return the service manager
|
||||||
|
*
|
||||||
|
* @throws XPCOMException <ul>
|
||||||
|
* <li> NS_ERROR_NOT_INITIALIZED - if static globals were not initialied,
|
||||||
|
* which can happen if XPCOM is reloaded, but did not completly
|
||||||
|
* shutdown. </li>
|
||||||
|
* <li> Other error codes indicate a failure during initialisation. </li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
nsIServiceManager initXPCOM(File aMozBinDirectory,
|
||||||
|
IAppFileLocProvider aAppFileLocProvider) throws XPCOMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown XPCOM. You must call this method after you are finished
|
||||||
|
* using xpcom.
|
||||||
|
*
|
||||||
|
* @param aServMgr The service manager which was returned by initXPCOM.
|
||||||
|
* This will release servMgr.
|
||||||
|
*
|
||||||
|
* @throws XPCOMException if a failure occurred during termination
|
||||||
|
*/
|
||||||
|
void shutdownXPCOM(nsIServiceManager aServMgr) throws XPCOMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public Method to access to the service manager.
|
||||||
|
*
|
||||||
|
* @return the service manager
|
||||||
|
*
|
||||||
|
* @throws XPCOMException
|
||||||
|
*/
|
||||||
|
nsIServiceManager getServiceManager() throws XPCOMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public Method to access to the component manager.
|
||||||
|
*
|
||||||
|
* @return the component manager
|
||||||
|
*
|
||||||
|
* @throws XPCOMException
|
||||||
|
*/
|
||||||
|
nsIComponentManager getComponentManager() throws XPCOMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public Method to access to the component registration manager.
|
||||||
|
*
|
||||||
|
* @return the component registration manager
|
||||||
|
*
|
||||||
|
* @throws XPCOMException
|
||||||
|
*/
|
||||||
|
nsIComponentRegistrar getComponentRegistrar() throws XPCOMException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public Method to create an instance of a nsILocalFile.
|
||||||
|
*
|
||||||
|
* @param aPath A string which specifies a full file path to a
|
||||||
|
* location. Relative paths will be treated as an
|
||||||
|
* error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
|
||||||
|
* @param aFollowLinks This attribute will determine if the nsLocalFile will
|
||||||
|
* auto resolve symbolic links. By default, this value
|
||||||
|
* will be false on all non unix systems. On unix, this
|
||||||
|
* attribute is effectively a noop.
|
||||||
|
*
|
||||||
|
* @return an instance of an nsILocalFile that points to given path
|
||||||
|
*
|
||||||
|
* @throws XPCOMException <ul>
|
||||||
|
* <li> NS_ERROR_FILE_UNRECOGNIZED_PATH - raised for unrecognized paths
|
||||||
|
* or relative paths (must supply full file path) </li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
nsILocalFile newLocalFile(String aPath, boolean aFollowLinks)
|
||||||
|
throws XPCOMException;
|
||||||
|
|
||||||
|
// #ifdef VBOX
|
||||||
|
int waitForEvents(long timeout);
|
||||||
|
// #endif VBOX
|
||||||
|
}
|
1079
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/Mozilla.java
Executable file
1079
VirtualBox-5.2.14/src/libs/xpcom18a4/java/src/org/mozilla/xpcom/Mozilla.java
Executable file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,63 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
public class ProfileLock {
|
||||||
|
|
||||||
|
private long lock = 0;
|
||||||
|
|
||||||
|
public ProfileLock(long aLockObject) {
|
||||||
|
lock = aLockObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
releaseNative(lock);
|
||||||
|
lock = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private native void releaseNative(long aLockObject);
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return lock != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
release();
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,272 @@
|
||||||
|
/* ***** 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) 2005
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
import org.mozilla.interfaces.nsISupports;
|
||||||
|
/* import org.mozilla.interfaces.nsIVersionComparator; */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version strings are dot-separated sequences of version-parts.
|
||||||
|
* <p>
|
||||||
|
* A version-part consists of up to four parts, all of which are optional:
|
||||||
|
* <br><code>
|
||||||
|
* <number-a><string-b><number-c>
|
||||||
|
* <string-d (everything else)>
|
||||||
|
* </code> <p>
|
||||||
|
* A version-part may also consist of a single asterisk "*" which indicates
|
||||||
|
* "infinity".
|
||||||
|
* <p>
|
||||||
|
* Numbers are base-10, and are zero if left out.
|
||||||
|
* Strings are compared bytewise.
|
||||||
|
* <p>
|
||||||
|
* For additional backwards compatibility, if "string-b" is "+" then
|
||||||
|
* "number-a" is incremented by 1 and "string-b" becomes "pre".
|
||||||
|
* <p> <pre>
|
||||||
|
* 1.0pre1
|
||||||
|
* < 1.0pre2
|
||||||
|
* < 1.0 == 1.0.0 == 1.0.0.0
|
||||||
|
* < 1.1pre == 1.1pre0 == 1.0+
|
||||||
|
* < 1.1pre1a
|
||||||
|
* < 1.1pre1
|
||||||
|
* < 1.1pre10a
|
||||||
|
* < 1.1pre10
|
||||||
|
* </pre>
|
||||||
|
* Although not required by this interface, it is recommended that
|
||||||
|
* numbers remain within the limits of a signed char, i.e. -127 to 128.
|
||||||
|
*/
|
||||||
|
public class VersionComparator implements nsISupports /* implements nsIVersionComparator */ {
|
||||||
|
|
||||||
|
public nsISupports queryInterface(String aIID) {
|
||||||
|
return Mozilla.queryInterface(this, aIID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two version strings
|
||||||
|
* @param A a version string
|
||||||
|
* @param B a version string
|
||||||
|
* @return a value less than 0 if A < B;
|
||||||
|
* the value 0 if A == B;
|
||||||
|
* or a value greater than 0 if A > B
|
||||||
|
*/
|
||||||
|
public int compare(String A, String B) {
|
||||||
|
int result;
|
||||||
|
String a = A, b = B;
|
||||||
|
|
||||||
|
do {
|
||||||
|
VersionPart va = new VersionPart();
|
||||||
|
VersionPart vb = new VersionPart();
|
||||||
|
a = parseVersionPart(a, va);
|
||||||
|
b = parseVersionPart(b, vb);
|
||||||
|
|
||||||
|
result = compareVersionPart(va, vb);
|
||||||
|
if (result != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (a != null || b != null);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class VersionPart {
|
||||||
|
int numA = 0;
|
||||||
|
String strB;
|
||||||
|
int numC = 0;
|
||||||
|
String extraD;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String parseVersionPart(String aVersion, VersionPart result) {
|
||||||
|
if (aVersion == null || aVersion.length() == 0) {
|
||||||
|
return aVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringTokenizer tok = new StringTokenizer(aVersion.trim(), ".");
|
||||||
|
String part = tok.nextToken();
|
||||||
|
|
||||||
|
if (part.equals("*")) {
|
||||||
|
result.numA = Integer.MAX_VALUE;
|
||||||
|
result.strB = "";
|
||||||
|
} else {
|
||||||
|
VersionPartTokenizer vertok = new VersionPartTokenizer(part);
|
||||||
|
try {
|
||||||
|
result.numA = Integer.parseInt(vertok.nextToken());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// parsing error; default to zero like 'strtol' C function
|
||||||
|
result.numA = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vertok.hasMoreElements()) {
|
||||||
|
String str = vertok.nextToken();
|
||||||
|
|
||||||
|
// if part is of type "<num>+"
|
||||||
|
if (str.charAt(0) == '+') {
|
||||||
|
result.numA++;
|
||||||
|
result.strB = "pre";
|
||||||
|
} else {
|
||||||
|
// else if part is of type "<num><alpha>..."
|
||||||
|
result.strB = str;
|
||||||
|
|
||||||
|
if (vertok.hasMoreTokens()) {
|
||||||
|
try {
|
||||||
|
result.numC = Integer.parseInt(vertok.nextToken());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// parsing error; default to zero like 'strtol' C function
|
||||||
|
result.numC = 0;
|
||||||
|
}
|
||||||
|
if (vertok.hasMoreTokens()) {
|
||||||
|
result.extraD = vertok.getRemainder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tok.hasMoreTokens()) {
|
||||||
|
// return everything after "."
|
||||||
|
return aVersion.substring(part.length() + 1);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int compareVersionPart(VersionPart va, VersionPart vb) {
|
||||||
|
int res = compareInt(va.numA, vb.numA);
|
||||||
|
if (res != 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = compareString(va.strB, vb.strB);
|
||||||
|
if (res != 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = compareInt(va.numC, vb.numC);
|
||||||
|
if (res != 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return compareString(va.extraD, vb.extraD);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int compareInt(int n1, int n2) {
|
||||||
|
return n1 - n2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int compareString(String str1, String str2) {
|
||||||
|
// any string is *before* no string
|
||||||
|
if (str1 == null) {
|
||||||
|
return (str2 != null) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str2 == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str1.compareTo(str2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specialized tokenizer for Mozilla version strings. A token can
|
||||||
|
* consist of one of the four sections of a version string: <code>
|
||||||
|
* <number-a><string-b><number-c>
|
||||||
|
* <string-d (everything else)></code>.
|
||||||
|
*/
|
||||||
|
class VersionPartTokenizer implements Enumeration {
|
||||||
|
|
||||||
|
String part;
|
||||||
|
|
||||||
|
public VersionPartTokenizer(String aPart) {
|
||||||
|
part = aPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasMoreElements() {
|
||||||
|
return part.length() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasMoreTokens() {
|
||||||
|
return part.length() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object nextElement() {
|
||||||
|
if (part.matches("[\\+\\-]?[0-9].*")) {
|
||||||
|
// if string starts with a number...
|
||||||
|
int index = 0;
|
||||||
|
if (part.charAt(0) == '+' || part.charAt(0) == '-') {
|
||||||
|
index = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (index < part.length() && Character.isDigit(part.charAt(index))) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
String numPart = part.substring(0, index);
|
||||||
|
part = part.substring(index);
|
||||||
|
return numPart;
|
||||||
|
} else {
|
||||||
|
// ... or if this is the non-numeric part of version string
|
||||||
|
int index = 0;
|
||||||
|
while (index < part.length() && !Character.isDigit(part.charAt(index))) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
String alphaPart = part.substring(0, index);
|
||||||
|
part = part.substring(index);
|
||||||
|
return alphaPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String nextToken() {
|
||||||
|
return (String) nextElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns what remains of the original string, without tokenization. This
|
||||||
|
* method is useful for getting the <code><string-d (everything else)>
|
||||||
|
* </code> section of a version string.
|
||||||
|
*
|
||||||
|
* @return remaining version string
|
||||||
|
*/
|
||||||
|
public String getRemainder() {
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
/* ***** 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) 2004
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This exception is thrown whenever an internal XPCOM/Gecko error occurs.
|
||||||
|
* You can query the error ID returned by XPCOM by checking
|
||||||
|
* <code>errorcode</code> field.
|
||||||
|
*/
|
||||||
|
public class XPCOMException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The XPCOM error value.
|
||||||
|
*/
|
||||||
|
public long errorcode;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 198521829884000593L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new XPCOMException instance, with a default error
|
||||||
|
* (NS_ERROR_FAILURE) and message.
|
||||||
|
*/
|
||||||
|
public XPCOMException() {
|
||||||
|
this(0x80004005L, "Unspecified internal XPCOM error");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new XPCOMException instance with the given message, passing
|
||||||
|
* NS_ERROR_FAILURE as the error code.
|
||||||
|
*
|
||||||
|
* @param message detailed message of exception
|
||||||
|
*/
|
||||||
|
public XPCOMException(String message) {
|
||||||
|
this(0x80004005L, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new XPCOMException instance with the given code, passing
|
||||||
|
* a default message.
|
||||||
|
*
|
||||||
|
* @param code internal XPCOM error ID
|
||||||
|
*/
|
||||||
|
public XPCOMException(long code) {
|
||||||
|
this(code, "Internal XPCOM error");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new XPCOMException instance with an error code and message.
|
||||||
|
*
|
||||||
|
* @param code internal XPCOM error ID
|
||||||
|
* @param message detailed message of exception
|
||||||
|
*/
|
||||||
|
public XPCOMException(long code, String message) {
|
||||||
|
super(message + " (0x" + Long.toHexString(code) + ")");
|
||||||
|
this.errorcode = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom;
|
||||||
|
|
||||||
|
|
||||||
|
public class XPCOMInitializationException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7067350325909231055L;
|
||||||
|
|
||||||
|
public XPCOMInitializationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XPCOMInitializationException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XPCOMInitializationException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom.internal;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.mozilla.xpcom.IAppFileLocProvider;
|
||||||
|
import org.mozilla.xpcom.IGRE;
|
||||||
|
import org.mozilla.xpcom.ProfileLock;
|
||||||
|
|
||||||
|
|
||||||
|
public class GREImpl implements IGRE {
|
||||||
|
|
||||||
|
public void initEmbedding(File aLibXULDirectory, File aAppDirectory,
|
||||||
|
IAppFileLocProvider aAppDirProvider) {
|
||||||
|
initEmbeddingNative(aLibXULDirectory, aAppDirectory, aAppDirProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public native void initEmbeddingNative(File aLibXULDirectory,
|
||||||
|
File aAppDirectory, IAppFileLocProvider aAppDirProvider);
|
||||||
|
|
||||||
|
public native void termEmbedding();
|
||||||
|
|
||||||
|
public native ProfileLock lockProfileDirectory(File aDirectory);
|
||||||
|
|
||||||
|
public native void notifyProfile();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom.internal;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.mozilla.xpcom.IJavaXPCOMUtils;
|
||||||
|
|
||||||
|
|
||||||
|
public class JavaXPCOMMethods implements IJavaXPCOMUtils {
|
||||||
|
|
||||||
|
public static void registerJavaXPCOMMethods(File aLibXULDirectory) {
|
||||||
|
// load JNI library
|
||||||
|
String path = "";
|
||||||
|
if (aLibXULDirectory != null) {
|
||||||
|
path = aLibXULDirectory + File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false)
|
||||||
|
{
|
||||||
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
|
if (osName.startsWith("os/2")) {
|
||||||
|
System.load(path + System.mapLibraryName("jxpcmglu"));
|
||||||
|
} else {
|
||||||
|
System.load(path + System.mapLibraryName("javaxpcomglue"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// #ifdef VBOX
|
||||||
|
try {
|
||||||
|
System.load(path + System.mapLibraryName("vboxjxpcom"));
|
||||||
|
} catch (java.lang.UnsatisfiedLinkError ule) {
|
||||||
|
System.loadLibrary("vboxjxpcom");
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
registerJavaXPCOMMethodsNative(aLibXULDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static native void
|
||||||
|
registerJavaXPCOMMethodsNative(File aLibXULDirectory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Class object associated with the class or interface with the
|
||||||
|
* given string name, using the class loader of the given object.
|
||||||
|
*
|
||||||
|
* @param aObject the Java object whose class loader is used to load class
|
||||||
|
* @param aClassName the fully qualified name of desired class
|
||||||
|
* @return the Class object of requested Class; <code>null</code> if the
|
||||||
|
* class was not found
|
||||||
|
*
|
||||||
|
* @see http://java.sun.com/j2se/1.3/docs/guide/jni/jni-12.html#classops
|
||||||
|
*/
|
||||||
|
public static Class findClassInLoader(Object aObject, String aClassName) {
|
||||||
|
try {
|
||||||
|
if (aObject == null) {
|
||||||
|
return Class.forName(aClassName);
|
||||||
|
} else {
|
||||||
|
return Class.forName(aClassName, true,
|
||||||
|
aObject.getClass().getClassLoader());
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public native long wrapJavaObject(Object aJavaObject, String aIID);
|
||||||
|
|
||||||
|
public native Object wrapXPCOMObject(long aXPCOMObject, String aIID);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom.internal;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.mozilla.xpcom.IMozilla;
|
||||||
|
import org.mozilla.xpcom.XPCOMInitializationException;
|
||||||
|
|
||||||
|
public class MozillaImpl implements IMozilla {
|
||||||
|
|
||||||
|
public void initialize(File aLibXULDirectory)
|
||||||
|
throws XPCOMInitializationException {
|
||||||
|
JavaXPCOMMethods.registerJavaXPCOMMethods(aLibXULDirectory);
|
||||||
|
initializeNative();
|
||||||
|
}
|
||||||
|
|
||||||
|
private native void initializeNative();
|
||||||
|
|
||||||
|
public native long getNativeHandleFromAWT(Object widget);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/* ***** 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom.internal;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.mozilla.xpcom.IAppFileLocProvider;
|
||||||
|
import org.mozilla.xpcom.IXPCOM;
|
||||||
|
|
||||||
|
import org.mozilla.interfaces.nsIComponentManager;
|
||||||
|
import org.mozilla.interfaces.nsIComponentRegistrar;
|
||||||
|
import org.mozilla.interfaces.nsILocalFile;
|
||||||
|
import org.mozilla.interfaces.nsIServiceManager;
|
||||||
|
|
||||||
|
|
||||||
|
public class XPCOMImpl implements IXPCOM {
|
||||||
|
|
||||||
|
public nsIServiceManager initXPCOM(File aMozBinDirectory,
|
||||||
|
IAppFileLocProvider aAppFileLocProvider) {
|
||||||
|
return initXPCOMNative(aMozBinDirectory, aAppFileLocProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public native nsIServiceManager initXPCOMNative(File aMozBinDirectory,
|
||||||
|
IAppFileLocProvider aAppFileLocProvider);
|
||||||
|
|
||||||
|
public native void shutdownXPCOM(nsIServiceManager aServMgr);
|
||||||
|
|
||||||
|
public native nsIComponentManager getComponentManager();
|
||||||
|
|
||||||
|
public native nsIComponentRegistrar getComponentRegistrar();
|
||||||
|
|
||||||
|
public native nsIServiceManager getServiceManager();
|
||||||
|
|
||||||
|
public native nsILocalFile newLocalFile(String aPath, boolean aFollowLinks);
|
||||||
|
|
||||||
|
// #ifdef VBOX
|
||||||
|
public native int waitForEvents(long timeout);
|
||||||
|
// #endif VBOX
|
||||||
|
}
|
|
@ -0,0 +1,257 @@
|
||||||
|
/* ***** 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) 2004
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom.internal;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
|
import org.mozilla.xpcom.XPCOMException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used to pass XPCOM objects to Java functions. A
|
||||||
|
* <code>java.lang.reflect.Proxy</code> instance is created using the expected
|
||||||
|
* interface, and all calls to the proxy are forwarded to the XPCOM object.
|
||||||
|
*/
|
||||||
|
public class XPCOMJavaProxy implements InvocationHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pointer to the XPCOM object for which we are a proxy.
|
||||||
|
*/
|
||||||
|
protected long nativeXPCOMPtr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*
|
||||||
|
* @param aXPCOMInstance address of XPCOM object as a long
|
||||||
|
*/
|
||||||
|
public XPCOMJavaProxy(long aXPCOMInstance) {
|
||||||
|
nativeXPCOMPtr = aXPCOMInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the XPCOM object that the given proxy references.
|
||||||
|
*
|
||||||
|
* @param aProxy Proxy created by <code>createProxy</code>
|
||||||
|
*
|
||||||
|
* @return address of XPCOM object as a long
|
||||||
|
*/
|
||||||
|
protected static long getNativeXPCOMInstance(Object aProxy) {
|
||||||
|
XPCOMJavaProxy proxy = (XPCOMJavaProxy) Proxy.getInvocationHandler(aProxy);
|
||||||
|
return proxy.nativeXPCOMPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Proxy for the given XPCOM object.
|
||||||
|
*
|
||||||
|
* @param aInterface interface from which to create Proxy
|
||||||
|
* @param aXPCOMInstance address of XPCOM object as a long
|
||||||
|
*
|
||||||
|
* @return Proxy of given XPCOM object
|
||||||
|
*/
|
||||||
|
protected static Object createProxy(Class aInterface, long aXPCOMInstance) {
|
||||||
|
// XXX We should really get the class loader from |aInterface|. However,
|
||||||
|
// that class loader doesn't know about |XPCOMJavaProxyBase|. So for
|
||||||
|
// now, we get the class loader that loaded |XPCOMJavaProxy|. When
|
||||||
|
// we get rid of the "XPCOMJavaProxyBase.java" class, we can revert
|
||||||
|
// to the old method below.
|
||||||
|
// return Proxy.newProxyInstance(aInterface.getClassLoader(),
|
||||||
|
return Proxy.newProxyInstance(XPCOMJavaProxy.class.getClassLoader(),
|
||||||
|
new Class[] { aInterface, XPCOMJavaProxyBase.class },
|
||||||
|
new XPCOMJavaProxy(aXPCOMInstance));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All calls to the Java proxy are forwarded to this method. This method
|
||||||
|
* takes care of a few of the <code>Object</code> method calls; all other
|
||||||
|
* calls are forwarded to the XPCOM object.
|
||||||
|
*
|
||||||
|
* @param aProxy Proxy created by <code>createProxy</code>
|
||||||
|
* @param aMethod object that describes the called method
|
||||||
|
* @param aParams array of the arguments passed to the method
|
||||||
|
*
|
||||||
|
* @return return value as defined by given <code>aMethod</code>
|
||||||
|
*/
|
||||||
|
public Object invoke(Object aProxy, Method aMethod, Object[] aParams)
|
||||||
|
throws Throwable {
|
||||||
|
String methodName = aMethod.getName();
|
||||||
|
|
||||||
|
// Handle the three java.lang.Object methods that are passed to us.
|
||||||
|
if (aMethod.getDeclaringClass() == Object.class) {
|
||||||
|
if (methodName.equals("hashCode")) {
|
||||||
|
return proxyHashCode(aProxy);
|
||||||
|
}
|
||||||
|
if (methodName.equals("equals")) {
|
||||||
|
return proxyEquals(aProxy, aParams[0]);
|
||||||
|
}
|
||||||
|
if (methodName.equals("toString")) {
|
||||||
|
return proxyToString(aProxy);
|
||||||
|
}
|
||||||
|
System.err.println("WARNING: Unhandled Object method [" +
|
||||||
|
methodName + "]");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the 'finalize' method called during garbage collection
|
||||||
|
if (aMethod.getDeclaringClass() == XPCOMJavaProxyBase.class) {
|
||||||
|
if (methodName.equals("finalize")) {
|
||||||
|
finalizeProxy(aProxy);
|
||||||
|
} else {
|
||||||
|
System.err.println("WARNING: Unhandled XPCOMJavaProxyBase method [" +
|
||||||
|
methodName + "]");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not already handled, pass method calls to XPCOM object.
|
||||||
|
return callXPCOMMethod(aProxy, methodName, aParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles method calls of <code>java.lang.Object.hashCode</code>
|
||||||
|
*
|
||||||
|
* @param aProxy Proxy created by <code>createProxy</code>
|
||||||
|
*
|
||||||
|
* @return Integer object representing hash code of given object
|
||||||
|
*
|
||||||
|
* @see Object#hashCode()
|
||||||
|
*/
|
||||||
|
protected static Integer proxyHashCode(Object aProxy) {
|
||||||
|
return new Integer(System.identityHashCode(aProxy));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles method calls of <code>java.lang.Object.equals</code>
|
||||||
|
*
|
||||||
|
* @param aProxy Proxy created by <code>createProxy</code>
|
||||||
|
* @param aOther another object
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if the given objects are the same;
|
||||||
|
* <code>false</code> otherwise
|
||||||
|
*
|
||||||
|
* @see Object#equals(Object)
|
||||||
|
*/
|
||||||
|
protected static Boolean proxyEquals(Object aProxy, Object aOther) {
|
||||||
|
// See if the two are the same Java object
|
||||||
|
if (aProxy == aOther) {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
} else {
|
||||||
|
// If not, then see if they represent the same XPCOM object. But first,
|
||||||
|
// we need to check if |aOther| is an XPCOMJavaProxy.
|
||||||
|
if (isXPCOMJavaProxy(aOther) && isSameXPCOMObject(aProxy, aOther)) {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the given object is an XPCOMJavaProxy.
|
||||||
|
*
|
||||||
|
* @param aObject object to check
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if the given object is an XPCOMJavaProxy;
|
||||||
|
* <code>false</code> otherwise
|
||||||
|
*/
|
||||||
|
protected static boolean isXPCOMJavaProxy(Object aObject) {
|
||||||
|
if (aObject != null && Proxy.isProxyClass(aObject.getClass())) {
|
||||||
|
InvocationHandler h = Proxy.getInvocationHandler(aObject);
|
||||||
|
if (h instanceof XPCOMJavaProxy) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the two given XPCOMJavaProxy objects are proxies for
|
||||||
|
* the same XPCOM object.
|
||||||
|
*
|
||||||
|
* @param aProxy1 XPCOMJavaProxy created by <code>createProxy</code>
|
||||||
|
* @param aProxy2 XPCOMJavaProxy created by <code>createProxy</code>
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if both proxies represent the same XPCOM object;
|
||||||
|
* <code>false</code> otherwise
|
||||||
|
*/
|
||||||
|
protected static native boolean isSameXPCOMObject(Object aProxy1,
|
||||||
|
Object aProxy2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles method calls of <code>java.lang.Object.toString</code>
|
||||||
|
*
|
||||||
|
* @param aProxy Proxy created by <code>createProxy</code>
|
||||||
|
*
|
||||||
|
* @return String representation of given object
|
||||||
|
*
|
||||||
|
* @see Object#toString()
|
||||||
|
*/
|
||||||
|
protected static String proxyToString(Object aProxy) {
|
||||||
|
return aProxy.getClass().getInterfaces()[0].getName() + '@' +
|
||||||
|
Integer.toHexString(aProxy.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the proxy is garbage collected by the JVM. Allows us to clean
|
||||||
|
* up any references to the XPCOM object.
|
||||||
|
*
|
||||||
|
* @param aProxy reference to Proxy that is being garbage collected
|
||||||
|
*/
|
||||||
|
protected void finalizeProxy(Object aProxy) throws Throwable {
|
||||||
|
finalizeProxyNative(aProxy);
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static native void finalizeProxyNative(Object aProxy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the XPCOM object referenced by the proxy with the given method.
|
||||||
|
*
|
||||||
|
* @param aProxy Proxy created by <code>createProxy</code>
|
||||||
|
* @param aMethodName name of method that we want to call
|
||||||
|
* @param aParams array of params passed to method
|
||||||
|
*
|
||||||
|
* @return return value as defined by given method
|
||||||
|
*
|
||||||
|
* @exception XPCOMException if XPCOM method failed. Values of XPCOMException
|
||||||
|
* are defined by the method called.
|
||||||
|
*/
|
||||||
|
protected static native Object callXPCOMMethod(Object aProxy,
|
||||||
|
String aMethodName, Object[] aParams);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* ***** 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) 2004
|
||||||
|
* 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 ***** */
|
||||||
|
|
||||||
|
package org.mozilla.xpcom.internal;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface forms the foundation of any XPCOMJavaProxy that is created.
|
||||||
|
* It allows us to handle any JVM calls to <code>finalize</code> when the Proxy
|
||||||
|
* is garbage collected.
|
||||||
|
*/
|
||||||
|
public interface XPCOMJavaProxyBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.lang.Object#finalize()
|
||||||
|
*/
|
||||||
|
void finalize() throws Throwable;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* $Id: VBoxObjectBase.java $ */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Oracle Corporation
|
||||||
|
*
|
||||||
|
* This file is part of VirtualBox Open Source Edition (OSE), as
|
||||||
|
* available from http://www.virtualbox.org. This file is free software;
|
||||||
|
* you can redistribute it and/or modify it under the terms of the GNU
|
||||||
|
* General Public License (GPL) as published by the Free Software
|
||||||
|
* Foundation, in version 2 as it comes in the "COPYING" file of the
|
||||||
|
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
||||||
|
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
||||||
|
*/
|
||||||
|
import org.mozilla.interfaces.nsISupports;
|
||||||
|
|
||||||
|
public abstract class VBoxObjectBase implements nsISupports
|
||||||
|
{
|
||||||
|
public nsISupports queryInterface(String iid)
|
||||||
|
{
|
||||||
|
return org.mozilla.xpcom.Mozilla.queryInterface(this, iid);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,10 +6,9 @@ import org.mozilla.interfaces.IFramebuffer;
|
||||||
import org.mozilla.interfaces.IFramebufferOverlay;
|
import org.mozilla.interfaces.IFramebufferOverlay;
|
||||||
import org.mozilla.interfaces.nsISupports;
|
import org.mozilla.interfaces.nsISupports;
|
||||||
import org.mozilla.xpcom.Mozilla;
|
import org.mozilla.xpcom.Mozilla;
|
||||||
import org.virtualbox_5_2.BitmapFormat;
|
import org.virtualbox_5_2.*;
|
||||||
import org.virtualbox_5_2.Holder;
|
|
||||||
import org.virtualbox_5_2.IDisplay;
|
import java.util.Arrays;
|
||||||
import org.virtualbox_5_2.IDisplaySourceBitmap;
|
|
||||||
|
|
||||||
public class MCFrameBuffer implements IFramebuffer {
|
public class MCFrameBuffer implements IFramebuffer {
|
||||||
private IDisplay display;
|
private IDisplay display;
|
||||||
|
@ -36,8 +35,15 @@ public class MCFrameBuffer implements IFramebuffer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long[] getCapabilities(long[] arg0) {
|
public long[] getCapabilities(long[] arg0) {
|
||||||
|
try {
|
||||||
|
System.out.println("Capabilities: " + Arrays.toString(arg0));
|
||||||
|
return new long[]{FramebufferCapabilities.UpdateImage.value()};
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
return new long[]{};
|
return new long[]{};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getHeight() {
|
public long getHeight() {
|
||||||
|
@ -114,11 +120,13 @@ public class MCFrameBuffer implements IFramebuffer {
|
||||||
public void notifyUpdate(long x, long y, long width, long height) {
|
public void notifyUpdate(long x, long y, long width, long height) {
|
||||||
if(tttt != null)
|
if(tttt != null)
|
||||||
tttt.cancel(); //We are getting updates, but the pixel array isn't updated - VB reacts slowly
|
tttt.cancel(); //We are getting updates, but the pixel array isn't updated - VB reacts slowly
|
||||||
tttt = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
/*tttt = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
||||||
for (IRenderer r : PluginMain.renderers)
|
for (IRenderer r : PluginMain.renderers)
|
||||||
if (r instanceof DirectRenderer)
|
if (r instanceof DirectRenderer)
|
||||||
((DirectRenderer) r).render(PluginMain.allpixels, x, y, width, height);
|
((DirectRenderer) r).render(PluginMain.allpixels, x, y, width, height);
|
||||||
}, 5);
|
System.out.println("Update!");
|
||||||
|
}, 5);*/
|
||||||
|
throw new UnsupportedOperationException("Use UpdateImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package sznp.virtualcomputer;
|
package sznp.virtualcomputer;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.sun.jna.Memory;
|
||||||
|
import com.sun.jna.Pointer;
|
||||||
import jnr.ffi.LibraryLoader;
|
import jnr.ffi.LibraryLoader;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -8,6 +10,7 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.virtualbox_5_2.*;
|
import org.virtualbox_5_2.*;
|
||||||
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -51,6 +54,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
||||||
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom");
|
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom");
|
||||||
vbl.RTR3InitExe(0, "", 0);
|
vbl.RTR3InitExe(0, "", 0);
|
||||||
|
Pointer addr = new Pointer(10);
|
||||||
vbox = manager.getVBox();
|
vbox = manager.getVBox();
|
||||||
session = manager.getSessionObject(); // TODO: Events
|
session = manager.getSessionObject(); // TODO: Events
|
||||||
ccs.sendMessage("§bLoading Screen...");
|
ccs.sendMessage("§bLoading Screen...");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
@ -77,10 +77,6 @@
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="DllExport, Version=1.5.2.30304, Culture=neutral, PublicKeyToken=8337224c9ad9e356, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\DllExport.1.5.2\lib\net20\DllExport.dll</HintPath>
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.ComponentModel.Composition" />
|
<Reference Include="System.ComponentModel.Composition" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="DllExport" version="1.5.2" targetFramework="net462" />
|
|
||||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />
|
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in a new issue