Source code

Revision control

Other Tools

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/. */
5
6
#include "nsInputStreamChannel.h"
7
8
//-----------------------------------------------------------------------------
9
// nsInputStreamChannel
10
11
namespace mozilla {
12
namespace net {
13
14
nsresult nsInputStreamChannel::OpenContentStream(bool async,
15
nsIInputStream** result,
16
nsIChannel** channel) {
17
NS_ENSURE_TRUE(mContentStream, NS_ERROR_NOT_INITIALIZED);
18
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.
21
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;
30
}
31
mContentLength = avail;
32
}
33
34
EnableSynthesizedProgressEvents(true);
35
36
NS_ADDREF(*result = mContentStream);
37
return NS_OK;
38
}
39
40
//-----------------------------------------------------------------------------
41
// nsInputStreamChannel::nsISupports
42
43
NS_IMPL_ISUPPORTS_INHERITED(nsInputStreamChannel, nsBaseChannel,
44
nsIInputStreamChannel)
45
46
//-----------------------------------------------------------------------------
47
// nsInputStreamChannel::nsIInputStreamChannel
48
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;
54
}
55
56
NS_IMETHODIMP
57
nsInputStreamChannel::GetContentStream(nsIInputStream** stream) {
58
NS_IF_ADDREF(*stream = mContentStream);
59
return NS_OK;
60
}
61
62
NS_IMETHODIMP
63
nsInputStreamChannel::SetContentStream(nsIInputStream* stream) {
64
NS_ENSURE_TRUE(!mContentStream, NS_ERROR_ALREADY_INITIALIZED);
65
mContentStream = stream;
66
return NS_OK;
67
}
68
69
NS_IMETHODIMP
70
nsInputStreamChannel::GetSrcdocData(nsAString& aSrcdocData) {
71
aSrcdocData = mSrcdocData;
72
return NS_OK;
73
}
74
75
NS_IMETHODIMP
76
nsInputStreamChannel::SetSrcdocData(const nsAString& aSrcdocData) {
77
mSrcdocData = aSrcdocData;
78
mIsSrcdocChannel = true;
79
return NS_OK;
80
}
81
82
NS_IMETHODIMP
83
nsInputStreamChannel::GetIsSrcdocChannel(bool* aIsSrcdocChannel) {
84
*aIsSrcdocChannel = mIsSrcdocChannel;
85
return NS_OK;
86
}
87
88
NS_IMETHODIMP
89
nsInputStreamChannel::GetBaseURI(nsIURI** aBaseURI) {
90
*aBaseURI = mBaseURI;
91
NS_IF_ADDREF(*aBaseURI);
92
return NS_OK;
93
}
94
95
NS_IMETHODIMP
96
nsInputStreamChannel::SetBaseURI(nsIURI* aBaseURI) {
97
mBaseURI = aBaseURI;
98
return NS_OK;
99
}
100
101
} // namespace net
102
} // namespace mozilla