Add VBoxJXPCOM source

Successfully compiled VirtualBox
This commit is contained in:
Norbi Peti 2018-07-06 23:20:14 +02:00
parent b95109a591
commit 5dd5546dc1
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
43 changed files with 11633 additions and 14 deletions

View 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);
}

View 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);
}

View 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;
}

View 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_

View 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;
}

View 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__

View 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__ */

View 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(