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
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) {
24 nsresult rv
= mContentStream
->Available(&avail
);
25 if (rv
== NS_BASE_STREAM_CLOSED
) {
26 // This just means there's nothing in the stream
28 } else if (NS_FAILED(rv
)) {
31 mContentLength
= avail
;
34 EnableSynthesizedProgressEvents(true);
36 *result
= do_AddRef(mContentStream
).take();
40 //-----------------------------------------------------------------------------
41 // nsInputStreamChannel::nsISupports
43 NS_IMPL_ISUPPORTS_INHERITED(nsInputStreamChannel
, nsBaseChannel
,
44 nsIInputStreamChannel
)
46 //-----------------------------------------------------------------------------
47 // nsInputStreamChannel::nsIInputStreamChannel
50 nsInputStreamChannel::SetURI(nsIURI
* uri
) {
51 NS_ENSURE_TRUE(!URI(), NS_ERROR_ALREADY_INITIALIZED
);
52 nsBaseChannel::SetURI(uri
);
57 nsInputStreamChannel::GetContentStream(nsIInputStream
** stream
) {
58 NS_IF_ADDREF(*stream
= mContentStream
);
63 nsInputStreamChannel::SetContentStream(nsIInputStream
* stream
) {
64 NS_ENSURE_TRUE(!mContentStream
, NS_ERROR_ALREADY_INITIALIZED
);
65 mContentStream
= stream
;
70 nsInputStreamChannel::GetSrcdocData(nsAString
& aSrcdocData
) {
71 aSrcdocData
= mSrcdocData
;
76 nsInputStreamChannel::SetSrcdocData(const nsAString
& aSrcdocData
) {
77 mSrcdocData
= aSrcdocData
;
78 mIsSrcdocChannel
= true;
83 nsInputStreamChannel::GetIsSrcdocChannel(bool* aIsSrcdocChannel
) {
84 *aIsSrcdocChannel
= mIsSrcdocChannel
;
89 nsInputStreamChannel::GetBaseURI(nsIURI
** aBaseURI
) {
91 NS_IF_ADDREF(*aBaseURI
);
96 nsInputStreamChannel::SetBaseURI(nsIURI
* aBaseURI
) {
102 } // namespace mozilla