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
Register(uint64_t aRegistrarId)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
SetParentListener(mozilla::net::ParentChannelListener * listener)46 ParentChannelWrapper::SetParentListener(
47 mozilla::net::ParentChannelListener* listener) {
48 return NS_OK;
49 }
50
51 NS_IMETHODIMP
NotifyFlashPluginStateChanged(nsIHttpChannel::FlashPluginState aState)52 ParentChannelWrapper::NotifyFlashPluginStateChanged(
53 nsIHttpChannel::FlashPluginState aState) {
54 // For now, only HttpChannel use this attribute.
55 RefPtr<HttpBaseChannel> httpChannel = do_QueryObject(mChannel);
56 if (httpChannel) {
57 httpChannel->SetFlashPluginState(aState);
58 }
59 return NS_OK;
60 }
61
62 NS_IMETHODIMP
SetClassifierMatchedInfo(const nsACString & aList,const nsACString & aProvider,const nsACString & aFullHash)63 ParentChannelWrapper::SetClassifierMatchedInfo(const nsACString& aList,
64 const nsACString& aProvider,
65 const nsACString& aFullHash) {
66 nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
67 do_QueryInterface(mChannel);
68 if (classifiedChannel) {
69 classifiedChannel->SetMatchedInfo(aList, aProvider, aFullHash);
70 }
71 return NS_OK;
72 }
73
74 NS_IMETHODIMP
SetClassifierMatchedTrackingInfo(const nsACString & aLists,const nsACString & aFullHash)75 ParentChannelWrapper::SetClassifierMatchedTrackingInfo(
76 const nsACString& aLists, const nsACString& aFullHash) {
77 nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
78 do_QueryInterface(mChannel);
79 if (classifiedChannel) {
80 nsTArray<nsCString> lists, fullhashes;
81 for (const nsACString& token : aLists.Split(',')) {
82 lists.AppendElement(token);
83 }
84 for (const nsACString& token : aFullHash.Split(',')) {
85 fullhashes.AppendElement(token);
86 }
87 classifiedChannel->SetMatchedTrackingInfo(lists, fullhashes);
88 }
89 return NS_OK;
90 }
91
92 NS_IMETHODIMP
NotifyClassificationFlags(uint32_t aClassificationFlags,bool aIsThirdParty)93 ParentChannelWrapper::NotifyClassificationFlags(uint32_t aClassificationFlags,
94 bool aIsThirdParty) {
95 UrlClassifierCommon::SetClassificationFlagsHelper(
96 mChannel, aClassificationFlags, aIsThirdParty);
97 return NS_OK;
98 }
99
100 NS_IMETHODIMP
Delete()101 ParentChannelWrapper::Delete() { return NS_OK; }
102
103 NS_IMETHODIMP
GetRemoteType(nsACString & aRemoteType)104 ParentChannelWrapper::GetRemoteType(nsACString& aRemoteType) {
105 aRemoteType = NOT_REMOTE_TYPE;
106 return NS_OK;
107 }
108
109 } // namespace net
110 } // namespace mozilla
111
112 #undef LOG
113