gecko-dev/netwerk/ipc/RemoteOpenFileChild.cpp

808 строки
19 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RemoteOpenFileChild.h"
#include "mozilla/unused.h"
#include "mozilla/ipc/FileDescriptor.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/ipc/URIUtils.h"
#include "mozilla/net/NeckoChild.h"
#include "nsThreadUtils.h"
#include "nsJARProtocolHandler.h"
#include "nsIRemoteOpenFileListener.h"
#include "nsProxyRelease.h"
#include "SerializedLoadContext.h"
#include "nsNetUtil.h"
Bug 1238290 - fix bad necko deps on unified_sources r=valentin.gosu --- netwerk/base/ARefBase.h | 2 ++ netwerk/base/CaptivePortalService.cpp | 1 + netwerk/base/CaptivePortalService.h | 1 + netwerk/base/EventTokenBucket.cpp | 4 +++- netwerk/base/LoadContextInfo.cpp | 3 +++ netwerk/base/LoadInfo.cpp | 3 +++ netwerk/base/MemoryDownloader.cpp | 1 + netwerk/base/Predictor.cpp | 1 + netwerk/base/RedirectChannelRegistrar.h | 1 + netwerk/base/nsBaseChannel.cpp | 1 + netwerk/base/nsChannelClassifier.cpp | 1 + netwerk/base/nsDirectoryIndexStream.cpp | 3 ++- netwerk/base/nsDownloader.cpp | 1 + netwerk/base/nsIOService.cpp | 1 + netwerk/base/nsIncrementalDownload.cpp | 3 +++ netwerk/base/nsNetUtil.cpp | 4 ++++ netwerk/base/nsNetUtil.h | 1 + netwerk/base/nsProtocolProxyService.cpp | 1 + netwerk/base/nsSecCheckWrapChannel.cpp | 2 ++ netwerk/base/nsUDPSocket.cpp | 4 +++- netwerk/cache/nsDiskCacheBinding.cpp | 2 +- netwerk/cache/nsDiskCacheDeviceSQL.cpp | 2 ++ netwerk/cache/nsMemoryCacheDevice.cpp | 2 +- netwerk/cache2/CacheFileUtils.cpp | 2 ++ netwerk/cache2/CacheStorageService.h | 1 + netwerk/ipc/NeckoParent.cpp | 1 + netwerk/ipc/RemoteOpenFileChild.cpp | 1 + netwerk/protocol/about/nsAboutBloat.cpp | 1 + netwerk/protocol/about/nsAboutCacheEntry.cpp | 1 + netwerk/protocol/about/nsAboutProtocolHandler.cpp | 1 + netwerk/protocol/data/DataChannelParent.cpp | 1 + netwerk/protocol/file/nsFileProtocolHandler.cpp | 1 + netwerk/protocol/ftp/FTPChannelParent.cpp | 2 ++ netwerk/protocol/ftp/FTPChannelParent.h | 1 + netwerk/protocol/ftp/nsFtpConnectionThread.cpp | 1 + netwerk/protocol/ftp/nsFtpProtocolHandler.h | 1 + netwerk/protocol/http/Http2Compression.cpp | 1 + netwerk/protocol/http/Http2Session.cpp | 1 + netwerk/protocol/http/Http2Stream.h | 2 ++ netwerk/protocol/http/HttpBaseChannel.cpp | 4 ++++ netwerk/protocol/http/HttpBaseChannel.h | 1 + netwerk/protocol/http/HttpChannelChild.cpp | 25 ++-------------------- netwerk/protocol/http/HttpChannelChild.h | 24 +++++++++++++++++++++ netwerk/protocol/http/HttpChannelParent.cpp | 1 + netwerk/protocol/http/HttpChannelParent.h | 1 + .../protocol/http/HttpChannelParentListener.cpp | 1 + netwerk/protocol/http/HttpChannelParentListener.h | 1 + netwerk/protocol/http/InterceptedChannel.cpp | 1 + netwerk/protocol/http/NullHttpChannel.cpp | 1 + netwerk/protocol/http/NullHttpTransaction.cpp | 1 + netwerk/protocol/http/PackagedAppService.cpp | 14 ++++++++++-- netwerk/protocol/http/PackagedAppService.h | 4 +++- netwerk/protocol/http/PackagedAppVerifier.cpp | 1 + netwerk/protocol/http/nsCORSListenerProxy.cpp | 2 +- netwerk/protocol/http/nsHttpBasicAuth.cpp | 1 + netwerk/protocol/http/nsHttpChannel.cpp | 2 ++ netwerk/protocol/http/nsHttpChunkedDecoder.cpp | 1 + netwerk/protocol/http/nsHttpConnectionInfo.cpp | 2 ++ netwerk/protocol/http/nsHttpConnectionMgr.cpp | 1 + netwerk/protocol/http/nsHttpDigestAuth.cpp | 1 + netwerk/protocol/viewsource/nsViewSourceHandler.h | 4 ++++ .../protocol/websocket/BaseWebSocketChannel.cpp | 1 + .../websocket/WebSocketEventListenerParent.cpp | 1 + .../protocol/websocket/WebSocketEventService.cpp | 3 +++ netwerk/protocol/websocket/WebSocketFrame.cpp | 2 ++ netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp | 1 + .../protocol/wyciwyg/nsWyciwygProtocolHandler.cpp | 1 + netwerk/streamconv/converters/mozTXTToHTMLConv.cpp | 1 + .../streamconv/converters/nsFTPDirListingConv.cpp | 1 + .../streamconv/converters/nsHTTPCompressConv.cpp | 2 ++ netwerk/streamconv/converters/nsHTTPCompressConv.h | 1 + netwerk/streamconv/converters/nsIndexedToHTML.cpp | 1 + netwerk/streamconv/converters/nsMultiMixedConv.cpp | 2 ++ netwerk/streamconv/converters/nsTXTToHTMLConv.cpp | 2 ++ netwerk/streamconv/converters/nsUnknownDecoder.cpp | 2 ++ 75 files changed, 147 insertions(+), 32 deletions(-)
2016-01-09 04:20:50 +03:00
#include "nsIFileURL.h"
// needed to alloc/free NSPR file descriptors
#include "private/pprio.h"
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA)
#include <unistd.h>
#endif
using namespace mozilla::ipc;
namespace mozilla {
namespace net {
//-----------------------------------------------------------------------------
// Helper class to dispatch events async on windows/OSX
//-----------------------------------------------------------------------------
class CallsListenerInNewEvent : public nsRunnable
{
public:
CallsListenerInNewEvent(nsIRemoteOpenFileListener *aListener, nsresult aRv)
: mListener(aListener), mRV(aRv)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aListener);
}
void Dispatch()
{
MOZ_ASSERT(NS_IsMainThread());
nsresult rv = NS_DispatchToCurrentThread(this);
NS_ENSURE_SUCCESS_VOID(rv);
}
private:
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mListener);
mListener->OnRemoteFileOpenComplete(mRV);
return NS_OK;
}
nsCOMPtr<nsIRemoteOpenFileListener> mListener;
nsresult mRV;
};
//-----------------------------------------------------------------------------
// RemoteOpenFileChild
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS(RemoteOpenFileChild,
nsIFile,
nsIHashable,
nsICachedFileDescriptorListener)
RemoteOpenFileChild::RemoteOpenFileChild(const RemoteOpenFileChild& other)
: mTabChild(other.mTabChild)
, mNSPRFileDesc(nullptr)
, mAsyncOpenCalled(other.mAsyncOpenCalled)
{
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
// Windows/OSX desktop builds skip remoting, so the file descriptor should
// be nullptr here.
MOZ_ASSERT(!other.mNSPRFileDesc);
#else
if (other.mNSPRFileDesc) {
PROsfd osfd = dup(PR_FileDesc2NativeHandle(other.mNSPRFileDesc));
mNSPRFileDesc = PR_ImportFile(osfd);
}
#endif
// Note: don't clone mListener or we'll have a refcount leak.
other.mURI->Clone(getter_AddRefs(mURI));
if (other.mAppURI) {
other.mAppURI->Clone(getter_AddRefs(mAppURI));
}
other.mFile->Clone(getter_AddRefs(mFile));
}
RemoteOpenFileChild::~RemoteOpenFileChild()
{
if (NS_IsMainThread()) {
if (mListener) {
NotifyListener(NS_ERROR_UNEXPECTED);
}
} else {
NS_ReleaseOnMainThread(mURI.forget(), true);
NS_ReleaseOnMainThread(mAppURI.forget(), true);
NS_ReleaseOnMainThread(mListener.forget(), true);
NS_ReleaseOnMainThread(mTabChild.forget(), true);
}
if (mNSPRFileDesc) {
// PR_Close both closes the file and deallocates the PRFileDesc
PR_Close(mNSPRFileDesc);
}
}
nsresult
RemoteOpenFileChild::Init(nsIURI* aRemoteOpenUri, nsIURI* aAppUri)
{
if (!aRemoteOpenUri) {
return NS_ERROR_INVALID_ARG;
}
if (aAppUri) {
aAppUri->Clone(getter_AddRefs(mAppURI));
}
nsAutoCString scheme;
nsresult rv = aRemoteOpenUri->GetScheme(scheme);
NS_ENSURE_SUCCESS(rv, rv);
if (!scheme.EqualsLiteral("remoteopenfile")) {
return NS_ERROR_INVALID_ARG;
}
// scheme of URI is not file:// so this is not a nsIFileURL. Convert to one.
nsCOMPtr<nsIURI> clonedURI;
rv = aRemoteOpenUri->Clone(getter_AddRefs(clonedURI));
NS_ENSURE_SUCCESS(rv, rv);
clonedURI->SetScheme(NS_LITERAL_CSTRING("file"));
nsAutoCString spec;
clonedURI->GetSpec(spec);
rv = NS_NewURI(getter_AddRefs(mURI), spec);
NS_ENSURE_SUCCESS(rv, rv);
// Get nsIFile
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mURI);
if (!fileURL) {
return NS_ERROR_UNEXPECTED;
}
rv = fileURL->GetFile(getter_AddRefs(mFile));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
nsresult
RemoteOpenFileChild::AsyncRemoteFileOpen(int32_t aFlags,
nsIRemoteOpenFileListener* aListener,
nsITabChild* aTabChild,
nsILoadContext *aLoadContext)
{
if (!mFile) {
return NS_ERROR_NOT_INITIALIZED;
}
if (!aListener) {
return NS_ERROR_INVALID_ARG;
}
if (mAsyncOpenCalled) {
return NS_ERROR_ALREADY_OPENED;
}
if (aFlags != PR_RDONLY) {
return NS_ERROR_NOT_AVAILABLE;
}
mTabChild = static_cast<TabChild*>(aTabChild);
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
// Windows/OSX desktop builds skip remoting, and just open file in child
// process when asked for NSPR handle
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<CallsListenerInNewEvent> runnable =
new CallsListenerInNewEvent(aListener, NS_OK);
runnable->Dispatch();
mAsyncOpenCalled = true;
return NS_OK;
#else
nsString path;
if (NS_FAILED(mFile->GetPath(path))) {
MOZ_CRASH("Couldn't get path from file!");
}
mListener = aListener;
if (mTabChild) {
if (mTabChild->GetCachedFileDescriptor(path, this)) {
// The file descriptor was found in the cache and OnCachedFileDescriptor()
// will be called with it.
return NS_OK;
}
}
URIParams uri;
SerializeURI(mURI, uri);
OptionalURIParams appUri;
SerializeURI(mAppURI, appUri);
IPC::SerializedLoadContext loadContext(aLoadContext);
gNeckoChild->SendPRemoteOpenFileConstructor(this, loadContext, uri, appUri);
// The chrome process now has a logical ref to us until it calls Send__delete.
AddIPDLReference();
mAsyncOpenCalled = true;
return NS_OK;
#endif
}
nsresult
RemoteOpenFileChild::SetNSPRFileDesc(PRFileDesc* aNSPRFileDesc)
{
MOZ_ASSERT(!mNSPRFileDesc);
if (mNSPRFileDesc) {
return NS_ERROR_ALREADY_OPENED;
}
mNSPRFileDesc = aNSPRFileDesc;
return NS_OK;
}
void
RemoteOpenFileChild::OnCachedFileDescriptor(const nsAString& aPath,
const FileDescriptor& aFD)
{
#ifdef DEBUG
if (!aPath.IsEmpty()) {
MOZ_ASSERT(mFile);
nsString path;
MOZ_ASSERT(NS_SUCCEEDED(mFile->GetPath(path)));
MOZ_ASSERT(path == aPath, "Paths don't match!");
}
#endif
HandleFileDescriptorAndNotifyListener(aFD, /* aFromRecvDelete */ false);
}
void
RemoteOpenFileChild::HandleFileDescriptorAndNotifyListener(
const FileDescriptor& aFD,
bool aFromRecvDelete)
{
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
MOZ_CRASH("OS X and Windows shouldn't be doing IPDL here");
#else
if (!mListener) {
// We already notified our listener (either in response to a cached file
// descriptor callback or through the normal messaging mechanism). Close the
// file descriptor if it is valid.
if (aFD.IsValid()) {
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<CloseFileRunnable> runnable = new CloseFileRunnable(aFD);
runnable->Dispatch();
}
return;
}
MOZ_ASSERT(!mNSPRFileDesc);
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<TabChild> tabChild;
mTabChild.swap(tabChild);
// If RemoteOpenFile reply (Recv__delete__) for app's application.zip comes
// back sooner than the parent-pushed fd (TabChild::RecvCacheFileDescriptor())
// have TabChild cancel running callbacks, since we'll call them in
// NotifyListener.
if (tabChild && aFromRecvDelete) {
nsString path;
if (NS_FAILED(mFile->GetPath(path))) {
MOZ_CRASH("Couldn't get path from file!");
}
tabChild->CancelCachedFileDescriptorCallback(path, this);
}
if (aFD.IsValid()) {
mNSPRFileDesc = PR_ImportFile(aFD.PlatformHandle());
if (!mNSPRFileDesc) {
NS_WARNING("Failed to import file handle!");
}
}
NotifyListener(mNSPRFileDesc ? NS_OK : NS_ERROR_FILE_NOT_FOUND);
#endif
}
void
RemoteOpenFileChild::NotifyListener(nsresult aResult)
{
MOZ_ASSERT(mListener);
mListener->OnRemoteFileOpenComplete(aResult);
mListener = nullptr; // release ref to listener
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<nsJARProtocolHandler> handler(gJarHandler);
NS_WARN_IF_FALSE(handler, "nsJARProtocolHandler is already gone!");
if (handler) {
handler->RemoteOpenFileComplete(this, aResult);
}
}
//-----------------------------------------------------------------------------
// RemoteOpenFileChild::PRemoteOpenFileChild
//-----------------------------------------------------------------------------
bool
RemoteOpenFileChild::Recv__delete__(const FileDescriptor& aFD)
{
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
NS_NOTREACHED("OS X and Windows shouldn't be doing IPDL here");
#else
HandleFileDescriptorAndNotifyListener(aFD, /* aFromRecvDelete */ true);
#endif
return true;
}
//-----------------------------------------------------------------------------
// RemoteOpenFileChild::nsIFile functions that we override logic for
//-----------------------------------------------------------------------------
NS_IMETHODIMP
RemoteOpenFileChild::Clone(nsIFile **file)
{
*file = new RemoteOpenFileChild(*this);
NS_ADDREF(*file);
return NS_OK;
}
/* The main event: get file descriptor from parent process
*/
NS_IMETHODIMP
RemoteOpenFileChild::OpenNSPRFileDesc(int32_t aFlags, int32_t aMode,
PRFileDesc **aRetval)
{
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
// Windows and OSX builds: just open nsIFile locally.
return mFile->OpenNSPRFileDesc(aFlags, aMode, aRetval);
#else
if (aFlags != PR_RDONLY) {
return NS_ERROR_NOT_AVAILABLE;
}
if (!mNSPRFileDesc) {
// Client skipped AsyncRemoteFileOpen() or didn't wait for result.
return NS_ERROR_NOT_AVAILABLE;
}
PROsfd osfd = dup(PR_FileDesc2NativeHandle(mNSPRFileDesc));
*aRetval = PR_ImportFile(osfd);
return NS_OK;
#endif
}
//-----------------------------------------------------------------------------
// RemoteOpenFileChild::nsIFile functions that we delegate to underlying nsIFile
//-----------------------------------------------------------------------------
nsresult
RemoteOpenFileChild::GetLeafName(nsAString &aLeafName)
{
return mFile->GetLeafName(aLeafName);
}
NS_IMETHODIMP
RemoteOpenFileChild::GetNativeLeafName(nsACString &aLeafName)
{
return mFile->GetNativeLeafName(aLeafName);
}
nsresult
RemoteOpenFileChild::GetTarget(nsAString &_retval)
{
return mFile->GetTarget(_retval);
}
NS_IMETHODIMP
RemoteOpenFileChild::GetNativeTarget(nsACString &_retval)
{
return mFile->GetNativeTarget(_retval);
}
nsresult
RemoteOpenFileChild::GetPath(nsAString &_retval)
{
return mFile->GetPath(_retval);
}
NS_IMETHODIMP
RemoteOpenFileChild::GetNativePath(nsACString &_retval)
{
return mFile->GetNativePath(_retval);
}
NS_IMETHODIMP
RemoteOpenFileChild::Equals(nsIFile *inFile, bool *_retval)
{
return mFile->Equals(inFile, _retval);
}
NS_IMETHODIMP
RemoteOpenFileChild::Contains(nsIFile *inFile, bool *_retval)
{
return mFile->Contains(inFile, _retval);
}
NS_IMETHODIMP
RemoteOpenFileChild::GetParent(nsIFile **aParent)
{
return mFile->GetParent(aParent);
}
NS_IMETHODIMP
RemoteOpenFileChild::GetFollowLinks(bool *aFollowLinks)
{
return mFile->GetFollowLinks(aFollowLinks);
}
//-----------------------------------------------------------------------------
// RemoteOpenFileChild::nsIFile functions that are not currently supported
//-----------------------------------------------------------------------------
nsresult
RemoteOpenFileChild::Append(const nsAString &node)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::AppendNative(const nsACString &fragment)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::Normalize()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::Create(uint32_t type, uint32_t permissions)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
RemoteOpenFileChild::SetLeafName(const nsAString &aLeafName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetNativeLeafName(const nsACString &aLeafName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
RemoteOpenFileChild::InitWithPath(const nsAString &filePath)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::InitWithNativePath(const nsACString &filePath)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::InitWithFile(nsIFile *aFile)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetFollowLinks(bool aFollowLinks)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
RemoteOpenFileChild::AppendRelativePath(const nsAString &node)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::AppendRelativeNativePath(const nsACString &fragment)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetPersistentDescriptor(nsACString &aPersistentDescriptor)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetPersistentDescriptor(const nsACString &aPersistentDescriptor)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetRelativeDescriptor(nsIFile *fromFile, nsACString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetRelativeDescriptor(nsIFile *fromFile,
const nsACString& relativeDesc)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetRelativePath(nsIFile *fromFile, nsACString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetRelativePath(nsIFile *fromFile,
const nsACString& relativePath)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
RemoteOpenFileChild::CopyTo(nsIFile *newParentDir, const nsAString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::CopyToNative(nsIFile *newParent, const nsACString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
RemoteOpenFileChild::CopyToFollowingLinks(nsIFile *newParentDir,
const nsAString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::CopyToFollowingLinksNative(nsIFile *newParent,
const nsACString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
RemoteOpenFileChild::MoveTo(nsIFile *newParentDir, const nsAString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::MoveToNative(nsIFile *newParent, const nsACString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::RenameTo(nsIFile *newParentDir, const nsAString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::RenameToNative(nsIFile *newParentDir, const nsACString &newName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::Remove(bool recursive)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetPermissions(uint32_t *aPermissions)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetPermissions(uint32_t aPermissions)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetPermissionsOfLink(uint32_t *aPermissionsOfLink)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetPermissionsOfLink(uint32_t aPermissions)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetLastModifiedTime(PRTime *aLastModTime)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetLastModifiedTime(PRTime aLastModTime)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetLastModifiedTimeOfLink(PRTime *aLastModTimeOfLink)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetLastModifiedTimeOfLink(PRTime aLastModTimeOfLink)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetFileSize(int64_t *aFileSize)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::SetFileSize(int64_t aFileSize)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetFileSizeOfLink(int64_t *aFileSize)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::Exists(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsWritable(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsReadable(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsExecutable(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsHidden(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsDirectory(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsFile(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsSymlink(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::IsSpecial(bool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::CreateUnique(uint32_t type, uint32_t attributes)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetDirectoryEntries(nsISimpleEnumerator **entries)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::OpenANSIFileDesc(const char *mode, FILE **_retval)
{
// TODO: can implement using fdopen()?
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::Load(PRLibrary **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetDiskSpaceAvailable(int64_t *aDiskSpaceAvailable)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::Reveal()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::Launch()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//-----------------------------------------------------------------------------
// RemoteOpenFileChild::nsIHashable functions that we delegate to underlying nsIFile
//-----------------------------------------------------------------------------
NS_IMETHODIMP
RemoteOpenFileChild::Equals(nsIHashable* aOther, bool *aResult)
{
nsCOMPtr<nsIHashable> hashable = do_QueryInterface(mFile);
MOZ_ASSERT(hashable);
if (hashable) {
return hashable->Equals(aOther, aResult);
}
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
RemoteOpenFileChild::GetHashCode(uint32_t *aResult)
{
nsCOMPtr<nsIHashable> hashable = do_QueryInterface(mFile);
MOZ_ASSERT(hashable);
if (hashable) {
return hashable->GetHashCode(aResult);
}
return NS_ERROR_UNEXPECTED;
}
} // namespace net
} // namespace mozilla