tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

IPCStreamUtils.h (1770B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 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/. */
      6 
      7 #ifndef mozilla_ipc_IPCStreamUtils_h
      8 #define mozilla_ipc_IPCStreamUtils_h
      9 
     10 #include "mozilla/ipc/IPCStream.h"
     11 #include "nsCOMPtr.h"
     12 #include "nsIInputStream.h"
     13 
     14 namespace mozilla::ipc {
     15 
     16 // Serialize an IPCStream to be sent over IPC fallibly.
     17 //
     18 // If |aAllowLazy| is true the stream may be serialized as a
     19 // RemoteLazyInputStream when being sent from child to parent.
     20 //
     21 // ParamTraits<nsIInputStream> may be used instead if serialization cannot be
     22 // fallible.
     23 [[nodiscard]] bool SerializeIPCStream(
     24    already_AddRefed<nsIInputStream> aInputStream, IPCStream& aValue,
     25    bool aAllowLazy);
     26 
     27 // If serialization fails, `aValue` will be initialized to `Nothing()`, so this
     28 // return value is safe to ignore.
     29 bool SerializeIPCStream(already_AddRefed<nsIInputStream> aInputStream,
     30                        Maybe<IPCStream>& aValue, bool aAllowLazy);
     31 
     32 // Deserialize an IPCStream received from an actor call.  These methods
     33 // work in both the child and parent.
     34 already_AddRefed<nsIInputStream> DeserializeIPCStream(const IPCStream& aValue);
     35 
     36 already_AddRefed<nsIInputStream> DeserializeIPCStream(
     37    const Maybe<IPCStream>& aValue);
     38 
     39 }  // namespace mozilla::ipc
     40 
     41 namespace IPC {
     42 
     43 template <>
     44 struct ParamTraits<nsIInputStream*> {
     45  static void Write(MessageWriter* aWriter, nsIInputStream* aParam);
     46  static bool Read(MessageReader* aReader, RefPtr<nsIInputStream>* aResult);
     47 };
     48 
     49 }  // namespace IPC
     50 
     51 #endif  // mozilla_ipc_IPCStreamUtils_h