Bug 1876541 - Remove an assert that doesn't hold for svg roots.
[gecko.git] / netwerk / ipc / NeckoCommon.cpp
blob9ad4483d3226bae30ac902c783946fc67d879c1e
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) {
19 nsresult rv = NS_OK;
20 for (auto& variant : aCalls) {
21 variant.match(
22 [&](OnStartRequestParams& aParams) {
23 rv = aParent->OnStartRequest(aParams.request);
24 if (NS_FAILED(rv)) {
25 aParams.request->Cancel(rv);
28 [&](OnDataAvailableParams& aParams) {
29 // Don't deliver OnDataAvailable if we've
30 // already failed.
31 if (NS_FAILED(rv)) {
32 return;
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);
41 if (NS_FAILED(rv)) {
42 aParams.request->Cancel(rv);
45 [&](OnStopRequestParams& aParams) {
46 if (NS_SUCCEEDED(rv)) {
47 aParent->OnStopRequest(aParams.request, aParams.status);
48 } else {
49 aParent->OnStopRequest(aParams.request, rv);
51 rv = NS_OK;
53 [&](OnAfterLastPartParams& aParams) {
54 nsCOMPtr<nsIMultiPartChannelListener> multiListener =
55 do_QueryInterface(aParent);
56 if (multiListener) {
57 if (NS_SUCCEEDED(rv)) {
58 multiListener->OnAfterLastPart(aParams.status);
59 } else {
60 multiListener->OnAfterLastPart(rv);
63 });
65 return rv;
68 } // namespace mozilla::net