summaryrefslogtreecommitdiffstats
path: root/netwerk/ipc/ParentChannelWrapper.cpp
blob: 57b9fe37c1cccb95fd8209924a9ee3255559be5a (plain)
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
/* -*- 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/. */

#include "ParentChannelWrapper.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "nsIRedirectChannelRegistrar.h"

namespace mozilla {
namespace net {

NS_IMPL_ISUPPORTS(ParentChannelWrapper, nsIParentChannel, nsIStreamListener,
                  nsIRequestObserver);

void ParentChannelWrapper::Register(uint64_t aRegistrarId) {
  nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
      RedirectChannelRegistrar::GetOrCreate();
  nsCOMPtr<nsIChannel> dummy;
  MOZ_ALWAYS_SUCCEEDS(
      NS_LinkRedirectChannels(aRegistrarId, this, getter_AddRefs(dummy)));

#ifdef DEBUG
  // The channel registered with the RedirectChannelRegistrar will be the inner
  // channel when dealing with view-source loads.
  if (nsCOMPtr<nsIViewSourceChannel> viewSource = do_QueryInterface(mChannel)) {
    MOZ_ASSERT(dummy == viewSource->GetInnerChannel());
  } else {
    MOZ_ASSERT(dummy == mChannel);
  }
#endif
}

////////////////////////////////////////////////////////////////////////////////
// nsIParentChannel
////////////////////////////////////////////////////////////////////////////////

NS_IMETHODIMP
ParentChannelWrapper::SetParentListener(
    mozilla::net::ParentChannelListener* listener) {
  return NS_OK;
}

NS_IMETHODIMP
ParentChannelWrapper::NotifyFlashPluginStateChanged(
    nsIHttpChannel::FlashPluginState aState) {
  // For now, only HttpChannel use this attribute.
  RefPtr<HttpBaseChannel> httpChannel = do_QueryObject(mChannel);
  if (httpChannel) {
    httpChannel->SetFlashPluginState(aState);
  }
  return NS_OK;
}

NS_IMETHODIMP
ParentChannelWrapper::SetClassifierMatchedInfo(const nsACString& aList,
                                               const nsACString& aProvider,
                                               const nsACString& aFullHash) {
  nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
      do_QueryInterface(mChannel);
  if (classifiedChannel) {
    classifiedChannel->SetMatchedInfo(aList, aProvider, aFullHash);
  }
  return NS_OK;
}

NS_IMETHODIMP
ParentChannelWrapper::SetClassifierMatchedTrackingInfo(
    const nsACString& aLists, const nsACString& aFullHash) {
  nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
      do_QueryInterface(mChannel);
  if (classifiedChannel) {
    nsTArray<nsCString> lists, fullhashes;
    for (const nsACString& token : aLists.Split(',')) {
      lists.AppendElement(token);
    }
    for (const nsACString& token : aFullHash.Split(',')) {
      fullhashes.AppendElement(token);
    }
    classifiedChannel->SetMatchedTrackingInfo(lists, fullhashes);
  }
  return NS_OK;
}

NS_IMETHODIMP
ParentChannelWrapper::NotifyClassificationFlags(uint32_t aClassificationFlags,
                                                bool aIsThirdParty) {
  UrlClassifierCommon::SetClassificationFlagsHelper(
      mChannel, aClassificationFlags, aIsThirdParty);
  return NS_OK;
}

NS_IMETHODIMP
ParentChannelWrapper::Delete() { return NS_OK; }

NS_IMETHODIMP
ParentChannelWrapper::GetRemoteType(nsACString& aRemoteType) {
  aRemoteType = NOT_REMOTE_TYPE;
  return NS_OK;
}

}  // namespace net
}  // namespace mozilla

#undef LOG