netwerk/ipc/RemoteOpenFileChild.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial