Bug 1729952 [wpt PR 30477] - Fix timeout in grid-positioned-item-dynamic-change-006...
[gecko.git] / netwerk / base / nsInputStreamChannel.cpp
blob53e003948b34e60789f4b3e6c1aec53e748670e5
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsInputStreamChannel.h"
8 //-----------------------------------------------------------------------------
9 // nsInputStreamChannel
11 namespace mozilla {
12 namespace net {
14 nsresult nsInputStreamChannel::OpenContentStream(bool async,
15 nsIInputStream** result,
16 nsIChannel** channel) {
17 NS_ENSURE_TRUE(mContentStream, NS_ERROR_NOT_INITIALIZED);
19 // If content length is unknown, then we must guess. In this case, we assume
20 // the stream can tell us. If the stream is a pipe, then this will not work.
22 if (mContentLength < 0) {
23 uint64_t avail;
24 nsresult rv = mContentStream->Available(&avail);
25 if (rv == NS_BASE_STREAM_CLOSED) {
26 // This just means there's nothing in the stream
27 avail = 0;
28 } else if (NS_FAILED(rv)) {
29 return rv;
31 mContentLength = avail;
34 EnableSynthesizedProgressEvents(true);
36 *result = do_AddRef(mContentStream).take();
37 return NS_OK;
40 //-----------------------------------------------------------------------------
41 // nsInputStreamChannel::nsISupports
43 NS_IMPL_ISUPPORTS_INHERITED(nsInputStreamChannel, nsBaseChannel,
44 nsIInputStreamChannel)
46 //-----------------------------------------------------------------------------
47 // nsInputStreamChannel::nsIInputStreamChannel
49 NS_IMETHODIMP
50 nsInputStreamChannel::SetURI(nsIURI* uri) {
51 NS_ENSURE_TRUE(!URI(), NS_ERROR_ALREADY_INITIALIZED);
52 nsBaseChannel::SetURI(uri);
53 return NS_OK;
56 NS_IMETHODIMP
57 nsInputStreamChannel::GetContentStream(nsIInputStream** stream) {
58 NS_IF_ADDREF(*stream = mContentStream);
59 return NS_OK;
62 NS_IMETHODIMP
63 nsInputStreamChannel::SetContentStream(nsIInputStream* stream) {
64 NS_ENSURE_TRUE(!mContentStream, NS_ERROR_ALREADY_INITIALIZED);
65 mContentStream = stream;
66 return NS_OK;
69 NS_IMETHODIMP
70 nsInputStreamChannel::GetSrcdocData(nsAString& aSrcdocData) {
71 aSrcdocData = mSrcdocData;
72 return NS_OK;
75 NS_IMETHODIMP
76 nsInputStreamChannel::SetSrcdocData(const nsAString& aSrcdocData) {
77 mSrcdocData = aSrcdocData;
78 mIsSrcdocChannel = true;
79 return NS_OK;
82 NS_IMETHODIMP
83 nsInputStreamChannel::GetIsSrcdocChannel(bool* aIsSrcdocChannel) {
84 *aIsSrcdocChannel = mIsSrcdocChannel;
85 return NS_OK;
88 NS_IMETHODIMP
89 nsInputStreamChannel::GetBaseURI(nsIURI** aBaseURI) {
90 *aBaseURI = mBaseURI;
91 NS_IF_ADDREF(*aBaseURI);
92 return NS_OK;
95 NS_IMETHODIMP
96 nsInputStreamChannel::SetBaseURI(nsIURI* aBaseURI) {
97 mBaseURI = aBaseURI;
98 return NS_OK;
101 } // namespace net
102 } // namespace mozilla