1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
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/. */
8 #include "NeckoCommon.h"
10 #include "nsIInputStream.h"
11 #include "nsIMultiPartChannel.h"
12 #include "nsIParentChannel.h"
13 #include "nsStringStream.h"
15 namespace mozilla::net
{
17 nsresult
ForwardStreamListenerFunctions(nsTArray
<StreamListenerFunction
> aCalls
,
18 nsIStreamListener
* aParent
) {
20 for (auto& variant
: aCalls
) {
22 [&](OnStartRequestParams
& aParams
) {
23 rv
= aParent
->OnStartRequest(aParams
.request
);
25 aParams
.request
->Cancel(rv
);
28 [&](OnDataAvailableParams
& aParams
) {
29 // Don't deliver OnDataAvailable if we've
34 nsCOMPtr
<nsIInputStream
> stringStream
;
35 rv
= NS_NewCStringInputStream(getter_AddRefs(stringStream
),
36 std::move(aParams
.data
));
37 if (NS_SUCCEEDED(rv
)) {
38 rv
= aParent
->OnDataAvailable(aParams
.request
, stringStream
,
39 aParams
.offset
, aParams
.count
);
42 aParams
.request
->Cancel(rv
);
45 [&](OnStopRequestParams
& aParams
) {
46 if (NS_SUCCEEDED(rv
)) {
47 aParent
->OnStopRequest(aParams
.request
, aParams
.status
);
49 aParent
->OnStopRequest(aParams
.request
, rv
);
53 [&](OnAfterLastPartParams
& aParams
) {
54 nsCOMPtr
<nsIMultiPartChannelListener
> multiListener
=
55 do_QueryInterface(aParent
);
57 if (NS_SUCCEEDED(rv
)) {
58 multiListener
->OnAfterLastPart(aParams
.status
);
60 multiListener
->OnAfterLastPart(rv
);
68 } // namespace mozilla::net