tor-browser

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

RemoteStreamGetter.h (2089B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef RemoteStreamGetter_h___
      8 #define RemoteStreamGetter_h___
      9 
     10 #include "nsIChannel.h"
     11 #include "nsIInputStreamPump.h"
     12 #include "nsIStreamListener.h"
     13 #include "nsIInputStream.h"
     14 #include "nsICancelable.h"
     15 #include "SimpleChannel.h"
     16 #include "mozilla/net/NeckoChannelParams.h"
     17 #include "mozilla/net/NeckoChild.h"
     18 #include "mozilla/Maybe.h"
     19 
     20 class nsILoadInfo;
     21 
     22 namespace mozilla {
     23 namespace net {
     24 
     25 using RemoteStreamPromise =
     26    mozilla::MozPromise<RemoteStreamInfo, nsresult, false>;
     27 using Method = RefPtr<
     28    MozPromise<Maybe<RemoteStreamInfo>, ipc::ResponseRejectReason, true>> (
     29    PNeckoChild::*)(nsIURI*, const LoadInfoArgs&);
     30 
     31 /**
     32 * Helper class used with SimpleChannel to asynchronously obtain an input
     33 * stream and metadata from the parent for a remote protocol load from the
     34 * child.
     35 */
     36 class RemoteStreamGetter final : public nsICancelable {
     37  NS_DECL_ISUPPORTS
     38  NS_DECL_NSICANCELABLE
     39 
     40 public:
     41  RemoteStreamGetter(nsIURI* aURI, nsILoadInfo* aLoadInfo);
     42 
     43  // Get an input stream from the parent asynchronously.
     44  RequestOrReason GetAsync(nsIStreamListener* aListener, nsIChannel* aChannel,
     45                           Method aMethod);
     46 
     47  // Handle an input stream being returned from the parent
     48  void OnStream(const Maybe<RemoteStreamInfo>& aStreamInfo);
     49 
     50  static void CancelRequest(nsIStreamListener* aListener, nsIChannel* aChannel,
     51                            nsresult aResult);
     52 
     53 private:
     54  ~RemoteStreamGetter() = default;
     55 
     56  nsCOMPtr<nsIURI> mURI;
     57  nsCOMPtr<nsILoadInfo> mLoadInfo;
     58  nsCOMPtr<nsIStreamListener> mListener;
     59  nsCOMPtr<nsIChannel> mChannel;
     60  nsCOMPtr<nsIInputStreamPump> mPump;
     61  bool mCanceled{false};
     62  nsresult mStatus{NS_OK};
     63 };
     64 
     65 }  // namespace net
     66 }  // namespace mozilla
     67 
     68 #endif /* RemoteStreamGetter_h___ */