Bug 867089 - Validate the playbackRate before using it. r=ehsan
[gecko.git] / netwerk / ipc / RemoteOpenFileChild.h
blob70fc6ccbfcde87ec94835818e42e26737d3526ab
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;
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.
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.
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.
41 * This class should only be instantiated in a child process.
44 class RemoteOpenFileChild MOZ_FINAL
45 : public PRemoteOpenFileChild
46 , public nsIFile
47 , public nsIHashable
48 , public nsICachedFileDescriptorListener
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)
60 virtual ~RemoteOpenFileChild();
62 NS_DECL_ISUPPORTS
63 NS_DECL_NSIFILE
64 NS_DECL_NSIHASHABLE
66 // URI must be scheme 'remoteopenfile://': otherwise looks like a file:// uri.
67 nsresult Init(nsIURI* aRemoteOpenUri);
69 // Send message to parent to tell it to open file handle for file.
70 // TabChild is required, for IPC security.
71 // Note: currently only PR_RDONLY is supported for 'flags'
72 nsresult AsyncRemoteFileOpen(int32_t aFlags,
73 nsIRemoteOpenFileListener* aListener,
74 nsITabChild* aTabChild);
76 void ReleaseIPDLReference()
78 Release();
81 private:
82 RemoteOpenFileChild(const RemoteOpenFileChild& other);
84 protected:
85 void AddIPDLReference()
87 AddRef();
90 virtual bool Recv__delete__(const FileDescriptor&) MOZ_OVERRIDE;
92 virtual void OnCachedFileDescriptor(const nsAString& aPath,
93 const FileDescriptor& aFD) MOZ_OVERRIDE;
95 void HandleFileDescriptorAndNotifyListener(const FileDescriptor&,
96 bool aFromRecvDelete);
98 void NotifyListener(nsresult aResult);
100 // regular nsIFile object, that we forward most calls to.
101 nsCOMPtr<nsIFile> mFile;
102 nsCOMPtr<nsIURI> mURI;
103 nsCOMPtr<nsIRemoteOpenFileListener> mListener;
104 nsRefPtr<TabChild> mTabChild;
105 PRFileDesc* mNSPRFileDesc;
106 bool mAsyncOpenCalled;
107 bool mNSPROpenCalled;
110 } // namespace net
111 } // namespace mozilla
113 #endif // _RemoteOpenFileChild_h