tor-browser

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

ParentChannelWrapper.cpp (3269B)


      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 #include "ParentChannelWrapper.h"
      9 #include "mozilla/net/HttpBaseChannel.h"
     10 #include "mozilla/net/UrlClassifierCommon.h"
     11 #include "mozilla/net/RedirectChannelRegistrar.h"
     12 #include "nsIViewSourceChannel.h"
     13 #include "nsNetUtil.h"
     14 #include "nsQueryObject.h"
     15 #include "mozilla/dom/RemoteType.h"
     16 
     17 namespace mozilla {
     18 namespace net {
     19 
     20 NS_IMPL_ISUPPORTS(ParentChannelWrapper, nsIParentChannel, nsIStreamListener,
     21                  nsIRequestObserver);
     22 
     23 void ParentChannelWrapper::Register(uint64_t aRegistrarId) {
     24  nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
     25      RedirectChannelRegistrar::GetOrCreate();
     26  nsCOMPtr<nsIChannel> dummy;
     27  MOZ_ALWAYS_SUCCEEDS(
     28      NS_LinkRedirectChannels(aRegistrarId, this, getter_AddRefs(dummy)));
     29 
     30 #ifdef DEBUG
     31  // The channel registered with the RedirectChannelRegistrar will be the inner
     32  // channel when dealing with view-source loads.
     33  if (nsCOMPtr<nsIViewSourceChannel> viewSource = do_QueryInterface(mChannel)) {
     34    MOZ_ASSERT(dummy == viewSource->GetInnerChannel());
     35  } else {
     36    MOZ_ASSERT(dummy == mChannel);
     37  }
     38 #endif
     39 }
     40 
     41 ////////////////////////////////////////////////////////////////////////////////
     42 // nsIParentChannel
     43 ////////////////////////////////////////////////////////////////////////////////
     44 
     45 NS_IMETHODIMP
     46 ParentChannelWrapper::SetParentListener(
     47    mozilla::net::ParentChannelListener* listener) {
     48  return NS_OK;
     49 }
     50 
     51 NS_IMETHODIMP
     52 ParentChannelWrapper::SetClassifierMatchedInfo(const nsACString& aList,
     53                                               const nsACString& aProvider,
     54                                               const nsACString& aFullHash) {
     55  nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
     56      do_QueryInterface(mChannel);
     57  if (classifiedChannel) {
     58    classifiedChannel->SetMatchedInfo(aList, aProvider, aFullHash);
     59  }
     60  return NS_OK;
     61 }
     62 
     63 NS_IMETHODIMP
     64 ParentChannelWrapper::SetClassifierMatchedTrackingInfo(
     65    const nsACString& aLists, const nsACString& aFullHash) {
     66  nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
     67      do_QueryInterface(mChannel);
     68  if (classifiedChannel) {
     69    nsTArray<nsCString> lists, fullhashes;
     70    for (const nsACString& token : aLists.Split(',')) {
     71      lists.AppendElement(token);
     72    }
     73    for (const nsACString& token : aFullHash.Split(',')) {
     74      fullhashes.AppendElement(token);
     75    }
     76    classifiedChannel->SetMatchedTrackingInfo(lists, fullhashes);
     77  }
     78  return NS_OK;
     79 }
     80 
     81 NS_IMETHODIMP
     82 ParentChannelWrapper::NotifyClassificationFlags(uint32_t aClassificationFlags,
     83                                                bool aIsThirdParty) {
     84  UrlClassifierCommon::SetClassificationFlagsHelper(
     85      mChannel, aClassificationFlags, aIsThirdParty);
     86  return NS_OK;
     87 }
     88 
     89 NS_IMETHODIMP
     90 ParentChannelWrapper::Delete() { return NS_OK; }
     91 
     92 NS_IMETHODIMP
     93 ParentChannelWrapper::GetRemoteType(nsACString& aRemoteType) {
     94  aRemoteType = NOT_REMOTE_TYPE;
     95  return NS_OK;
     96 }
     97 
     98 }  // namespace net
     99 }  // namespace mozilla
    100 
    101 #undef LOG