Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsInputStreamChannel.h" |
michael@0 | 7 | |
michael@0 | 8 | //----------------------------------------------------------------------------- |
michael@0 | 9 | // nsInputStreamChannel |
michael@0 | 10 | |
michael@0 | 11 | nsresult |
michael@0 | 12 | nsInputStreamChannel::OpenContentStream(bool async, nsIInputStream **result, |
michael@0 | 13 | nsIChannel** channel) |
michael@0 | 14 | { |
michael@0 | 15 | NS_ENSURE_TRUE(mContentStream, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 16 | |
michael@0 | 17 | // If content length is unknown, then we must guess. In this case, we assume |
michael@0 | 18 | // the stream can tell us. If the stream is a pipe, then this will not work. |
michael@0 | 19 | |
michael@0 | 20 | if (mContentLength < 0) { |
michael@0 | 21 | uint64_t avail; |
michael@0 | 22 | nsresult rv = mContentStream->Available(&avail); |
michael@0 | 23 | if (rv == NS_BASE_STREAM_CLOSED) { |
michael@0 | 24 | // This just means there's nothing in the stream |
michael@0 | 25 | avail = 0; |
michael@0 | 26 | } else if (NS_FAILED(rv)) { |
michael@0 | 27 | return rv; |
michael@0 | 28 | } |
michael@0 | 29 | mContentLength = avail; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | EnableSynthesizedProgressEvents(true); |
michael@0 | 33 | |
michael@0 | 34 | NS_ADDREF(*result = mContentStream); |
michael@0 | 35 | return NS_OK; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | //----------------------------------------------------------------------------- |
michael@0 | 39 | // nsInputStreamChannel::nsISupports |
michael@0 | 40 | |
michael@0 | 41 | NS_IMPL_ISUPPORTS_INHERITED(nsInputStreamChannel, |
michael@0 | 42 | nsBaseChannel, |
michael@0 | 43 | nsIInputStreamChannel) |
michael@0 | 44 | |
michael@0 | 45 | //----------------------------------------------------------------------------- |
michael@0 | 46 | // nsInputStreamChannel::nsIInputStreamChannel |
michael@0 | 47 | |
michael@0 | 48 | NS_IMETHODIMP |
michael@0 | 49 | nsInputStreamChannel::SetURI(nsIURI *uri) |
michael@0 | 50 | { |
michael@0 | 51 | NS_ENSURE_TRUE(!URI(), NS_ERROR_ALREADY_INITIALIZED); |
michael@0 | 52 | nsBaseChannel::SetURI(uri); |
michael@0 | 53 | return NS_OK; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | NS_IMETHODIMP |
michael@0 | 57 | nsInputStreamChannel::GetContentStream(nsIInputStream **stream) |
michael@0 | 58 | { |
michael@0 | 59 | NS_IF_ADDREF(*stream = mContentStream); |
michael@0 | 60 | return NS_OK; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | NS_IMETHODIMP |
michael@0 | 64 | nsInputStreamChannel::SetContentStream(nsIInputStream *stream) |
michael@0 | 65 | { |
michael@0 | 66 | NS_ENSURE_TRUE(!mContentStream, NS_ERROR_ALREADY_INITIALIZED); |
michael@0 | 67 | mContentStream = stream; |
michael@0 | 68 | return NS_OK; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | NS_IMETHODIMP |
michael@0 | 72 | nsInputStreamChannel::GetSrcdocData(nsAString& aSrcdocData) |
michael@0 | 73 | { |
michael@0 | 74 | aSrcdocData = mSrcdocData; |
michael@0 | 75 | return NS_OK; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | NS_IMETHODIMP |
michael@0 | 79 | nsInputStreamChannel::SetSrcdocData(const nsAString& aSrcdocData) |
michael@0 | 80 | { |
michael@0 | 81 | mSrcdocData = aSrcdocData; |
michael@0 | 82 | mIsSrcdocChannel = true; |
michael@0 | 83 | return NS_OK; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | NS_IMETHODIMP |
michael@0 | 87 | nsInputStreamChannel::GetIsSrcdocChannel(bool *aIsSrcdocChannel) |
michael@0 | 88 | { |
michael@0 | 89 | *aIsSrcdocChannel = mIsSrcdocChannel; |
michael@0 | 90 | return NS_OK; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | NS_IMETHODIMP |
michael@0 | 94 | nsInputStreamChannel::GetBaseURI(nsIURI** aBaseURI) |
michael@0 | 95 | { |
michael@0 | 96 | *aBaseURI = mBaseURI; |
michael@0 | 97 | NS_IF_ADDREF(*aBaseURI); |
michael@0 | 98 | return NS_OK; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | NS_IMETHODIMP |
michael@0 | 102 | nsInputStreamChannel::SetBaseURI(nsIURI* aBaseURI) |
michael@0 | 103 | { |
michael@0 | 104 | mBaseURI = aBaseURI; |
michael@0 | 105 | return NS_OK; |
michael@0 | 106 | } |