DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_net_ParentChannelListener_h
#define mozilla_net_ParentChannelListener_h

#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "nsIAuthPromptProvider.h"
#include "nsIInterfaceRequestor.h"
#include "nsIMultiPartChannel.h"
#include "nsINetworkInterceptController.h"
#include "nsIStreamListener.h"
#include "nsIThreadRetargetableStreamListener.h"

namespace mozilla {
namespace net {

#define PARENT_CHANNEL_LISTENER                      \
  {                                                  \
    0xa4e2c10c, 0xceba, 0x457f, {                    \
      0xa8, 0x0d, 0x78, 0x2b, 0x23, 0xba, 0xbd, 0x16 \
    }                                                \
  }

// Note: nsIInterfaceRequestor must be the first base so that do_QueryObject()
// works correctly on this object, as it's needed to compute a void* pointing to
// the beginning of this object.

class ParentChannelListener final : public nsIInterfaceRequestor,
                                    public nsIStreamListener,
                                    public nsIMultiPartChannelListener,
                                    public nsINetworkInterceptController,
                                    public nsIThreadRetargetableStreamListener,
                                    private nsIAuthPromptProvider {
 public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIINTERFACEREQUESTOR
  NS_DECL_NSIREQUESTOBSERVER
  NS_DECL_NSISTREAMLISTENER
  NS_DECL_NSIMULTIPARTCHANNELLISTENER
  NS_DECL_NSINETWORKINTERCEPTCONTROLLER
  NS_DECL_NSIAUTHPROMPTPROVIDER
  NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER

  NS_DECLARE_STATIC_IID_ACCESSOR(PARENT_CHANNEL_LISTENER)

  explicit ParentChannelListener(
      nsIStreamListener* aListener,
      dom::CanonicalBrowsingContext* aBrowsingContext,
      bool aUsePrivateBrowsing);

  // For channel diversion from child to parent.
  void DivertTo(nsIStreamListener* aListener);
  [[nodiscard]] nsresult SuspendForDiversion();

  void SetupInterception(const nsHttpResponseHead& aResponseHead);
  void SetupInterceptionAfterRedirect(bool aShouldIntercept);
  void ClearInterceptedChannel(nsIStreamListener* aListener);

  // Called to set a new listener which replaces the old one after a redirect.
  void SetListenerAfterRedirect(nsIStreamListener* aListener);

  dom::CanonicalBrowsingContext* GetBrowsingContext() {
    return mBrowsingContext;
  }

 private:
  virtual ~ParentChannelListener();

  // Private partner function to SuspendForDiversion.
  void ResumeForDiversion();

  // Can be the original HttpChannelParent that created this object (normal
  // case), a different {HTTP|FTP}ChannelParent that we've been redirected to,
  // or some other listener that we have been diverted to via
  // nsIDivertableChannel.
  nsCOMPtr<nsIStreamListener> mNextListener;
  // When set, no OnStart/OnData/OnStop calls should be received.
  bool mSuspendedForDiversion;

  // Set if this channel should be intercepted before it sets up the HTTP
  // transaction.
  bool mShouldIntercept;
  // Set if this channel should suspend on interception.
  bool mShouldSuspendIntercept;
  // Set if the channel interception has been canceled.  Can be set before
  // interception first occurs.  In this case cancelation is deferred until
  // the interception takes place.
  bool mInterceptCanceled;

  UniquePtr<nsHttpResponseHead> mSynthesizedResponseHead;

  // Handle to the channel wrapper if this channel has been intercepted.
  nsCOMPtr<nsIInterceptedChannel> mInterceptedChannel;

  // This will be populated with a real network controller if parent-side
  // interception is enabled.
  nsCOMPtr<nsINetworkInterceptController> mInterceptController;

  RefPtr<dom::CanonicalBrowsingContext> mBrowsingContext;

  // True if we received OnStartRequest for a nsIMultiPartChannel, and are
  // expected AllPartsStopped to be called when complete.
  bool mIsMultiPart = false;
};

NS_DEFINE_STATIC_IID_ACCESSOR(ParentChannelListener, PARENT_CHANNEL_LISTENER)

inline nsISupports* ToSupports(ParentChannelListener* aDoc) {
  return static_cast<nsIInterfaceRequestor*>(aDoc);
}

}  // namespace net
}  // namespace mozilla

#endif  // mozilla_net_ParentChannelListener_h