Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set sw=2 ts=8 et tw=80 : */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef _RemoteOpenFileChild_h |
michael@0 | 8 | #define _RemoteOpenFileChild_h |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/Attributes.h" |
michael@0 | 11 | #include "mozilla/dom/TabChild.h" |
michael@0 | 12 | #include "mozilla/net/PRemoteOpenFileChild.h" |
michael@0 | 13 | #include "nsICachedFileDescriptorListener.h" |
michael@0 | 14 | #include "nsILocalFile.h" |
michael@0 | 15 | #include "nsIRemoteOpenFileListener.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | namespace ipc { |
michael@0 | 20 | class FileDescriptor; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | namespace net { |
michael@0 | 24 | |
michael@0 | 25 | /** |
michael@0 | 26 | * RemoteOpenFileChild: a thin wrapper around regular nsIFile classes that does |
michael@0 | 27 | * IPC to open a file handle on parent instead of child. Used when we can't |
michael@0 | 28 | * open file handle on child (don't have permission), but we don't want the |
michael@0 | 29 | * overhead of shipping all I/O traffic across IPDL. Example: JAR files. |
michael@0 | 30 | * |
michael@0 | 31 | * To open a file handle with this class, AsyncRemoteFileOpen() must be called |
michael@0 | 32 | * first. After the listener's OnRemoteFileOpenComplete() is called, if the |
michael@0 | 33 | * result is NS_OK, nsIFile.OpenNSPRFileDesc() may be called--once--to get the |
michael@0 | 34 | * file handle. |
michael@0 | 35 | * |
michael@0 | 36 | * Note that calling Clone() on this class results in the filehandle ownership |
michael@0 | 37 | * being passed on to the new RemoteOpenFileChild. I.e. if |
michael@0 | 38 | * OnRemoteFileOpenComplete is called and then Clone(), OpenNSPRFileDesc() will |
michael@0 | 39 | * work in the cloned object, but not in the original. |
michael@0 | 40 | * |
michael@0 | 41 | * This class should only be instantiated in a child process. |
michael@0 | 42 | * |
michael@0 | 43 | */ |
michael@0 | 44 | class RemoteOpenFileChild MOZ_FINAL |
michael@0 | 45 | : public PRemoteOpenFileChild |
michael@0 | 46 | , public nsIFile |
michael@0 | 47 | , public nsIHashable |
michael@0 | 48 | , public nsICachedFileDescriptorListener |
michael@0 | 49 | { |
michael@0 | 50 | typedef mozilla::dom::TabChild TabChild; |
michael@0 | 51 | typedef mozilla::ipc::FileDescriptor FileDescriptor; |
michael@0 | 52 | |
michael@0 | 53 | public: |
michael@0 | 54 | RemoteOpenFileChild() |
michael@0 | 55 | : mNSPRFileDesc(nullptr) |
michael@0 | 56 | , mAsyncOpenCalled(false) |
michael@0 | 57 | , mNSPROpenCalled(false) |
michael@0 | 58 | {} |
michael@0 | 59 | |
michael@0 | 60 | virtual ~RemoteOpenFileChild(); |
michael@0 | 61 | |
michael@0 | 62 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 63 | NS_DECL_NSIFILE |
michael@0 | 64 | NS_DECL_NSIHASHABLE |
michael@0 | 65 | |
michael@0 | 66 | // aRemoteOpenUri must be scheme 'remoteopenfile://': otherwise looks like |
michael@0 | 67 | // a file:// uri. |
michael@0 | 68 | nsresult Init(nsIURI* aRemoteOpenUri, nsIURI* aAppUri); |
michael@0 | 69 | |
michael@0 | 70 | // Send message to parent to tell it to open file handle for file. |
michael@0 | 71 | // TabChild is required, for IPC security. |
michael@0 | 72 | // Note: currently only PR_RDONLY is supported for 'flags' |
michael@0 | 73 | nsresult AsyncRemoteFileOpen(int32_t aFlags, |
michael@0 | 74 | nsIRemoteOpenFileListener* aListener, |
michael@0 | 75 | nsITabChild* aTabChild); |
michael@0 | 76 | |
michael@0 | 77 | void ReleaseIPDLReference() |
michael@0 | 78 | { |
michael@0 | 79 | Release(); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | private: |
michael@0 | 83 | RemoteOpenFileChild(const RemoteOpenFileChild& other); |
michael@0 | 84 | |
michael@0 | 85 | protected: |
michael@0 | 86 | void AddIPDLReference() |
michael@0 | 87 | { |
michael@0 | 88 | AddRef(); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | virtual bool Recv__delete__(const FileDescriptor&) MOZ_OVERRIDE; |
michael@0 | 92 | |
michael@0 | 93 | virtual void OnCachedFileDescriptor(const nsAString& aPath, |
michael@0 | 94 | const FileDescriptor& aFD) MOZ_OVERRIDE; |
michael@0 | 95 | |
michael@0 | 96 | void HandleFileDescriptorAndNotifyListener(const FileDescriptor&, |
michael@0 | 97 | bool aFromRecvDelete); |
michael@0 | 98 | |
michael@0 | 99 | void NotifyListener(nsresult aResult); |
michael@0 | 100 | |
michael@0 | 101 | // regular nsIFile object, that we forward most calls to. |
michael@0 | 102 | nsCOMPtr<nsIFile> mFile; |
michael@0 | 103 | nsCOMPtr<nsIURI> mURI; |
michael@0 | 104 | nsCOMPtr<nsIURI> mAppURI; |
michael@0 | 105 | nsCOMPtr<nsIRemoteOpenFileListener> mListener; |
michael@0 | 106 | nsRefPtr<TabChild> mTabChild; |
michael@0 | 107 | PRFileDesc* mNSPRFileDesc; |
michael@0 | 108 | bool mAsyncOpenCalled; |
michael@0 | 109 | bool mNSPROpenCalled; |
michael@0 | 110 | }; |
michael@0 | 111 | |
michael@0 | 112 | } // namespace net |
michael@0 | 113 | } // namespace mozilla |
michael@0 | 114 | |
michael@0 | 115 | #endif // _RemoteOpenFileChild_h |