michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _RemoteOpenFileChild_h michael@0: #define _RemoteOpenFileChild_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/dom/TabChild.h" michael@0: #include "mozilla/net/PRemoteOpenFileChild.h" michael@0: #include "nsICachedFileDescriptorListener.h" michael@0: #include "nsILocalFile.h" michael@0: #include "nsIRemoteOpenFileListener.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace ipc { michael@0: class FileDescriptor; michael@0: } michael@0: michael@0: namespace net { michael@0: michael@0: /** michael@0: * RemoteOpenFileChild: a thin wrapper around regular nsIFile classes that does michael@0: * IPC to open a file handle on parent instead of child. Used when we can't michael@0: * open file handle on child (don't have permission), but we don't want the michael@0: * overhead of shipping all I/O traffic across IPDL. Example: JAR files. michael@0: * michael@0: * To open a file handle with this class, AsyncRemoteFileOpen() must be called michael@0: * first. After the listener's OnRemoteFileOpenComplete() is called, if the michael@0: * result is NS_OK, nsIFile.OpenNSPRFileDesc() may be called--once--to get the michael@0: * file handle. michael@0: * michael@0: * Note that calling Clone() on this class results in the filehandle ownership michael@0: * being passed on to the new RemoteOpenFileChild. I.e. if michael@0: * OnRemoteFileOpenComplete is called and then Clone(), OpenNSPRFileDesc() will michael@0: * work in the cloned object, but not in the original. michael@0: * michael@0: * This class should only be instantiated in a child process. michael@0: * michael@0: */ michael@0: class RemoteOpenFileChild MOZ_FINAL michael@0: : public PRemoteOpenFileChild michael@0: , public nsIFile michael@0: , public nsIHashable michael@0: , public nsICachedFileDescriptorListener michael@0: { michael@0: typedef mozilla::dom::TabChild TabChild; michael@0: typedef mozilla::ipc::FileDescriptor FileDescriptor; michael@0: michael@0: public: michael@0: RemoteOpenFileChild() michael@0: : mNSPRFileDesc(nullptr) michael@0: , mAsyncOpenCalled(false) michael@0: , mNSPROpenCalled(false) michael@0: {} michael@0: michael@0: virtual ~RemoteOpenFileChild(); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIFILE michael@0: NS_DECL_NSIHASHABLE michael@0: michael@0: // aRemoteOpenUri must be scheme 'remoteopenfile://': otherwise looks like michael@0: // a file:// uri. michael@0: nsresult Init(nsIURI* aRemoteOpenUri, nsIURI* aAppUri); michael@0: michael@0: // Send message to parent to tell it to open file handle for file. michael@0: // TabChild is required, for IPC security. michael@0: // Note: currently only PR_RDONLY is supported for 'flags' michael@0: nsresult AsyncRemoteFileOpen(int32_t aFlags, michael@0: nsIRemoteOpenFileListener* aListener, michael@0: nsITabChild* aTabChild); michael@0: michael@0: void ReleaseIPDLReference() michael@0: { michael@0: Release(); michael@0: } michael@0: michael@0: private: michael@0: RemoteOpenFileChild(const RemoteOpenFileChild& other); michael@0: michael@0: protected: michael@0: void AddIPDLReference() michael@0: { michael@0: AddRef(); michael@0: } michael@0: michael@0: virtual bool Recv__delete__(const FileDescriptor&) MOZ_OVERRIDE; michael@0: michael@0: virtual void OnCachedFileDescriptor(const nsAString& aPath, michael@0: const FileDescriptor& aFD) MOZ_OVERRIDE; michael@0: michael@0: void HandleFileDescriptorAndNotifyListener(const FileDescriptor&, michael@0: bool aFromRecvDelete); michael@0: michael@0: void NotifyListener(nsresult aResult); michael@0: michael@0: // regular nsIFile object, that we forward most calls to. michael@0: nsCOMPtr mFile; michael@0: nsCOMPtr mURI; michael@0: nsCOMPtr mAppURI; michael@0: nsCOMPtr mListener; michael@0: nsRefPtr mTabChild; michael@0: PRFileDesc* mNSPRFileDesc; michael@0: bool mAsyncOpenCalled; michael@0: bool mNSPROpenCalled; michael@0: }; michael@0: michael@0: } // namespace net michael@0: } // namespace mozilla michael@0: michael@0: #endif // _RemoteOpenFileChild_h