1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include "mozilla/net/BackgroundDataBridgeChild.h"
6 #include "mozilla/net/HttpBackgroundChannelChild.h"
7
8 namespace mozilla {
9 namespace net {
10
BackgroundDataBridgeChild(HttpBackgroundChannelChild * aBgChild)11 BackgroundDataBridgeChild::BackgroundDataBridgeChild(
12 HttpBackgroundChannelChild* aBgChild)
13 : mBgChild(aBgChild) {
14 MOZ_ASSERT(aBgChild);
15 }
16
17 BackgroundDataBridgeChild::~BackgroundDataBridgeChild() = default;
18
ActorDestroy(ActorDestroyReason aWhy)19 void BackgroundDataBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
20 mBgChild = nullptr;
21 }
22
RecvOnTransportAndData(const uint64_t & offset,const uint32_t & count,const nsDependentCSubstring & data)23 mozilla::ipc::IPCResult BackgroundDataBridgeChild::RecvOnTransportAndData(
24 const uint64_t& offset, const uint32_t& count,
25 const nsDependentCSubstring& data) {
26 if (!mBgChild) {
27 return IPC_OK();
28 }
29
30 if (mBgChild->ChannelClosed()) {
31 Unused << Send__delete__(this);
32 return IPC_OK();
33 }
34
35 return mBgChild->RecvOnTransportAndData(NS_OK, NS_NET_STATUS_RECEIVING_FROM,
36 offset, count, data, true);
37 }
38
RecvOnStopRequest(nsresult aStatus,const ResourceTimingStructArgs & aTiming,const TimeStamp & aLastActiveTabOptHit,const nsHttpHeaderArray & aResponseTrailers)39 mozilla::ipc::IPCResult BackgroundDataBridgeChild::RecvOnStopRequest(
40 nsresult aStatus, const ResourceTimingStructArgs& aTiming,
41 const TimeStamp& aLastActiveTabOptHit,
42 const nsHttpHeaderArray& aResponseTrailers) {
43 if (!mBgChild) {
44 return IPC_OK();
45 }
46
47 if (mBgChild->ChannelClosed()) {
48 Unused << Send__delete__(this);
49 return IPC_OK();
50 }
51
52 return mBgChild->RecvOnStopRequest(aStatus, aTiming, aLastActiveTabOptHit,
53 aResponseTrailers,
54 nsTArray<ConsoleReportCollected>(), true);
55 }
56
57 } // namespace net
58 } // namespace mozilla
59