tor-browser

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

DocumentChannel.h (4095B)


      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 
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 #ifndef mozilla_net_DocumentChannel_h
      9 #define mozilla_net_DocumentChannel_h
     10 
     11 #include "mozilla/dom/ClientInfo.h"
     12 #include "mozilla/net/NeckoChannelParams.h"
     13 #include "nsDOMNavigationTiming.h"
     14 #include "nsIChannel.h"
     15 #include "nsIChildChannel.h"
     16 
     17 class nsDocShell;
     18 
     19 #define DOCUMENT_CHANNEL_IID \
     20  {0x6977bc44, 0xb1db, 0x41b7, {0xb5, 0xc5, 0xe2, 0x13, 0x68, 0x22, 0xc9, 0x8f}}
     21 
     22 namespace mozilla {
     23 namespace net {
     24 
     25 uint64_t InnerWindowIDForExtantDoc(nsDocShell* docShell);
     26 
     27 /**
     28 * DocumentChannel is a protocol agnostic placeholder nsIChannel implementation
     29 * that we use so that nsDocShell knows about a connecting load. It transfers
     30 * all data into a DocumentLoadListener (running in the parent process), which
     31 * will create the real channel for the connection, and decide which process to
     32 * load the resulting document in. If the document is to be loaded in the
     33 * current process, then we'll synthesize a redirect replacing this placeholder
     34 * channel with the real one, otherwise the originating docshell will be removed
     35 * during the process switch.
     36 */
     37 class DocumentChannel : public nsIIdentChannel {
     38 public:
     39  NS_DECL_ISUPPORTS
     40  NS_DECL_NSIREQUEST
     41  NS_DECL_NSICHANNEL
     42  NS_DECL_NSIIDENTCHANNEL
     43 
     44  NS_INLINE_DECL_STATIC_IID(DOCUMENT_CHANNEL_IID)
     45 
     46  void SetNavigationTiming(nsDOMNavigationTiming* aTiming) {
     47    mTiming = aTiming;
     48  }
     49 
     50  void SetInitialClientInfo(const Maybe<dom::ClientInfo>& aInfo) {
     51    mInitialClientInfo = aInfo;
     52  }
     53 
     54  void DisconnectChildListeners(const nsresult& aStatus,
     55                                const nsresult& aLoadGroupStatus);
     56 
     57  /**
     58   * Will create the appropriate document channel:
     59   * Either a DocumentChannelChild if called from the content process or
     60   * a ParentProcessDocumentChannel if called from the parent process.
     61   * This operation is infallible.
     62   */
     63  static already_AddRefed<DocumentChannel> CreateForDocument(
     64      nsDocShellLoadState* aLoadState, class LoadInfo* aLoadInfo,
     65      nsLoadFlags aLoadFlags, nsIInterfaceRequestor* aNotificationCallbacks,
     66      uint32_t aCacheKey, bool aUriModified, bool aIsEmbeddingBlockedError);
     67  static already_AddRefed<DocumentChannel> CreateForObject(
     68      nsDocShellLoadState* aLoadState, class LoadInfo* aLoadInfo,
     69      nsLoadFlags aLoadFlags, nsIInterfaceRequestor* aNotificationCallbacks);
     70 
     71  static bool CanUseDocumentChannel(nsIURI* aURI);
     72 
     73 protected:
     74  DocumentChannel(nsDocShellLoadState* aLoadState, class LoadInfo* aLoadInfo,
     75                  nsLoadFlags aLoadFlags, uint32_t aCacheKey, bool aUriModified,
     76                  bool aIsEmbeddingBlockedError);
     77 
     78  void ShutdownListeners(nsresult aStatusCode);
     79  virtual void DeleteIPDL() {}
     80 
     81  nsDocShell* GetDocShell();
     82 
     83  virtual ~DocumentChannel() = default;
     84 
     85  const RefPtr<nsDocShellLoadState> mLoadState;
     86  const uint32_t mCacheKey;
     87 
     88  nsresult mStatus = NS_OK;
     89  bool mCanceled = false;
     90  bool mIsPending = false;
     91  bool mWasOpened = false;
     92  uint64_t mChannelId;
     93  uint32_t mLoadFlags = LOAD_NORMAL;
     94  const nsCOMPtr<nsIURI> mURI;
     95  nsCOMPtr<nsILoadGroup> mLoadGroup;
     96  nsCOMPtr<nsILoadInfo> mLoadInfo;
     97  nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
     98  nsCOMPtr<nsIStreamListener> mListener;
     99  nsCOMPtr<nsISupports> mOwner;
    100  RefPtr<nsDOMNavigationTiming> mTiming;
    101  Maybe<dom::ClientInfo> mInitialClientInfo;
    102  // mUriModified is true if we're doing a history load and the URI of the
    103  // session history had been modified by pushState/replaceState.
    104  bool mUriModified = false;
    105  // mIsEmbeddingBlockedError is true if we're handling a load error and the
    106  // status of the failed channel is NS_ERROR_XFO_VIOLATION or
    107  // NS_ERROR_CSP_FRAME_ANCESTOR_VIOLATION.
    108  bool mIsEmbeddingBlockedError = false;
    109 };
    110 
    111 }  // namespace net
    112 }  // namespace mozilla
    113 
    114 #endif  // mozilla_net_DocumentChannel_h