netwerk/ipc/RemoteOpenFileChild.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/ipc/RemoteOpenFileChild.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=8 et tw=80 : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef _RemoteOpenFileChild_h
    1.11 +#define _RemoteOpenFileChild_h
    1.12 +
    1.13 +#include "mozilla/Attributes.h"
    1.14 +#include "mozilla/dom/TabChild.h"
    1.15 +#include "mozilla/net/PRemoteOpenFileChild.h"
    1.16 +#include "nsICachedFileDescriptorListener.h"
    1.17 +#include "nsILocalFile.h"
    1.18 +#include "nsIRemoteOpenFileListener.h"
    1.19 +
    1.20 +namespace mozilla {
    1.21 +
    1.22 +namespace ipc {
    1.23 +class FileDescriptor;
    1.24 +}
    1.25 +
    1.26 +namespace net {
    1.27 +
    1.28 +/**
    1.29 + * RemoteOpenFileChild: a thin wrapper around regular nsIFile classes that does
    1.30 + * IPC to open a file handle on parent instead of child.  Used when we can't
    1.31 + * open file handle on child (don't have permission), but we don't want the
    1.32 + * overhead of shipping all I/O traffic across IPDL.  Example: JAR files.
    1.33 + *
    1.34 + * To open a file handle with this class, AsyncRemoteFileOpen() must be called
    1.35 + * first.  After the listener's OnRemoteFileOpenComplete() is called, if the
    1.36 + * result is NS_OK, nsIFile.OpenNSPRFileDesc() may be called--once--to get the
    1.37 + * file handle.
    1.38 + *
    1.39 + * Note that calling Clone() on this class results in the filehandle ownership
    1.40 + * being passed on to the new RemoteOpenFileChild. I.e. if
    1.41 + * OnRemoteFileOpenComplete is called and then Clone(), OpenNSPRFileDesc() will
    1.42 + * work in the cloned object, but not in the original.
    1.43 + *
    1.44 + * This class should only be instantiated in a child process.
    1.45 + *
    1.46 + */
    1.47 +class RemoteOpenFileChild MOZ_FINAL
    1.48 +  : public PRemoteOpenFileChild
    1.49 +  , public nsIFile
    1.50 +  , public nsIHashable
    1.51 +  , public nsICachedFileDescriptorListener
    1.52 +{
    1.53 +  typedef mozilla::dom::TabChild TabChild;
    1.54 +  typedef mozilla::ipc::FileDescriptor FileDescriptor;
    1.55 +
    1.56 +public:
    1.57 +  RemoteOpenFileChild()
    1.58 +    : mNSPRFileDesc(nullptr)
    1.59 +    , mAsyncOpenCalled(false)
    1.60 +    , mNSPROpenCalled(false)
    1.61 +  {}
    1.62 +
    1.63 +  virtual ~RemoteOpenFileChild();
    1.64 +
    1.65 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.66 +  NS_DECL_NSIFILE
    1.67 +  NS_DECL_NSIHASHABLE
    1.68 +
    1.69 +  // aRemoteOpenUri must be scheme 'remoteopenfile://': otherwise looks like
    1.70 +  // a file:// uri.
    1.71 +  nsresult Init(nsIURI* aRemoteOpenUri, nsIURI* aAppUri);
    1.72 +
    1.73 +  // Send message to parent to tell it to open file handle for file.
    1.74 +  // TabChild is required, for IPC security.
    1.75 +  // Note: currently only PR_RDONLY is supported for 'flags'
    1.76 +  nsresult AsyncRemoteFileOpen(int32_t aFlags,
    1.77 +                               nsIRemoteOpenFileListener* aListener,
    1.78 +                               nsITabChild* aTabChild);
    1.79 +
    1.80 +  void ReleaseIPDLReference()
    1.81 +  {
    1.82 +    Release();
    1.83 +  }
    1.84 +
    1.85 +private:
    1.86 +  RemoteOpenFileChild(const RemoteOpenFileChild& other);
    1.87 +
    1.88 +protected:
    1.89 +  void AddIPDLReference()
    1.90 +  {
    1.91 +    AddRef();
    1.92 +  }
    1.93 +
    1.94 +  virtual bool Recv__delete__(const FileDescriptor&) MOZ_OVERRIDE;
    1.95 +
    1.96 +  virtual void OnCachedFileDescriptor(const nsAString& aPath,
    1.97 +                                      const FileDescriptor& aFD) MOZ_OVERRIDE;
    1.98 +
    1.99 +  void HandleFileDescriptorAndNotifyListener(const FileDescriptor&,
   1.100 +                                             bool aFromRecvDelete);
   1.101 +
   1.102 +  void NotifyListener(nsresult aResult);
   1.103 +
   1.104 +  // regular nsIFile object, that we forward most calls to.
   1.105 +  nsCOMPtr<nsIFile> mFile;
   1.106 +  nsCOMPtr<nsIURI> mURI;
   1.107 +  nsCOMPtr<nsIURI> mAppURI;
   1.108 +  nsCOMPtr<nsIRemoteOpenFileListener> mListener;
   1.109 +  nsRefPtr<TabChild> mTabChild;
   1.110 +  PRFileDesc* mNSPRFileDesc;
   1.111 +  bool mAsyncOpenCalled;
   1.112 +  bool mNSPROpenCalled;
   1.113 +};
   1.114 +
   1.115 +} // namespace net
   1.116 +} // namespace mozilla
   1.117 +
   1.118 +#endif // _RemoteOpenFileChild_h

mercurial