1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "mozilla/net/ChannelDiverterParent.h"
8 #include "mozilla/net/NeckoChannelParams.h"
9 #include "mozilla/net/HttpChannelParent.h"
10 #include "mozilla/net/FTPChannelParent.h"
11 #include "mozilla/net/PHttpChannelParent.h"
12 #include "mozilla/net/PFTPChannelParent.h"
13 #include "ADivertableParentChannel.h"
14 
15 namespace mozilla {
16 namespace net {
17 
ChannelDiverterParent()18 ChannelDiverterParent::ChannelDiverterParent()
19 {
20 }
21 
~ChannelDiverterParent()22 ChannelDiverterParent::~ChannelDiverterParent()
23 {
24 }
25 
26 bool
Init(const ChannelDiverterArgs & aArgs)27 ChannelDiverterParent::Init(const ChannelDiverterArgs& aArgs)
28 {
29   switch (aArgs.type()) {
30   case ChannelDiverterArgs::THttpChannelDiverterArgs:
31   {
32     auto httpParent = static_cast<HttpChannelParent*>(
33       aArgs.get_HttpChannelDiverterArgs().mChannelParent());
34     httpParent->SetApplyConversion(aArgs.get_HttpChannelDiverterArgs().mApplyConversion());
35 
36     mDivertableChannelParent =
37       static_cast<ADivertableParentChannel*>(httpParent);
38     break;
39   }
40   case ChannelDiverterArgs::TPFTPChannelParent:
41   {
42     mDivertableChannelParent = static_cast<ADivertableParentChannel*>(
43       static_cast<FTPChannelParent*>(aArgs.get_PFTPChannelParent()));
44     break;
45   }
46   default:
47     NS_NOTREACHED("unknown ChannelDiverterArgs type");
48     return false;
49   }
50   MOZ_ASSERT(mDivertableChannelParent);
51 
52   nsresult rv = mDivertableChannelParent->SuspendForDiversion();
53   if (NS_WARN_IF(NS_FAILED(rv))) {
54     return false;
55   }
56   return true;
57 }
58 
59 void
DivertTo(nsIStreamListener * newListener)60 ChannelDiverterParent::DivertTo(nsIStreamListener* newListener)
61 {
62   MOZ_ASSERT(newListener);
63   MOZ_ASSERT(mDivertableChannelParent);
64 
65   mDivertableChannelParent->DivertTo(newListener);
66 }
67 
68 void
ActorDestroy(ActorDestroyReason aWhy)69 ChannelDiverterParent::ActorDestroy(ActorDestroyReason aWhy)
70 {
71   // Implement me! Bug 1005179
72 }
73 
74 } // namespace net
75 } // namespace mozilla
76