Bug 1424809 - Get rid of NS_NewPostDataStream, r=valentin

This commit is contained in:
Andrea Marchesini 2017-12-12 06:01:17 -06:00
parent 3373df795c
commit b32bea6044
4 changed files with 6 additions and 47 deletions

View File

@ -101,6 +101,7 @@
#include "nsICookieService.h"
#include "nsIConsoleReportCollector.h"
#include "nsObjectLoadingContent.h"
#include "nsStringStream.h"
// we want to explore making the document own the load group
// so we can associate the document URI with the load group.
@ -622,8 +623,8 @@ SendPing(void* aClosure, nsIContent* aContent, nsIURI* aURI,
NS_NAMED_LITERAL_CSTRING(uploadData, "PING");
nsCOMPtr<nsIInputStream> uploadStream;
NS_NewPostDataStream(getter_AddRefs(uploadStream), false, uploadData);
if (!uploadStream) {
rv = NS_NewCStringInputStream(getter_AddRefs(uploadStream), uploadData);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}

View File

@ -1359,43 +1359,6 @@ NS_NewBufferedInputStream(nsIInputStream** aResult,
return rv;
}
nsresult
NS_NewPostDataStream(nsIInputStream **result,
bool isFile,
const nsACString &data)
{
nsresult rv;
if (isFile) {
nsCOMPtr<nsIFile> file;
nsCOMPtr<nsIInputStream> fileStream;
rv = NS_NewNativeLocalFile(data, false, getter_AddRefs(file));
if (NS_SUCCEEDED(rv)) {
rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file);
if (NS_SUCCEEDED(rv)) {
// wrap the file stream with a buffered input stream
rv = NS_NewBufferedInputStream(result, fileStream.forget(),
8192);
}
}
return rv;
}
// otherwise, create a string stream for the data (copies)
nsCOMPtr<nsIStringInputStream> stream
(do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
if (NS_FAILED(rv))
return rv;
rv = stream->SetData(data.BeginReading(), data.Length());
if (NS_FAILED(rv))
return rv;
stream.forget(result);
return NS_OK;
}
namespace {
#define BUFFER_SIZE 4096

View File

@ -510,11 +510,6 @@ nsresult NS_NewBufferedOutputStream(nsIOutputStream** aResult,
already_AddRefed<nsIOutputStream> aOutputStream,
uint32_t aBufferSize);
// returns an input stream compatible with nsIUploadChannel::SetUploadStream()
nsresult NS_NewPostDataStream(nsIInputStream **result,
bool isFile,
const nsACString &data);
/**
* This function reads an inputStream and stores its content into a buffer. In
* general, you should avoid using this function because, it blocks the current

View File

@ -30,6 +30,7 @@
#include "nsNetUtil.h"
#include "nsProtectedAuthThread.h"
#include "nsProxyRelease.h"
#include "nsStringStream.h"
#include "pkix/pkixtypes.h"
#include "ssl.h"
#include "sslproto.h"
@ -140,8 +141,7 @@ nsHTTPDownloadEvent::Run()
if (mRequestSession->mHasPostData)
{
nsCOMPtr<nsIInputStream> uploadStream;
rv = NS_NewPostDataStream(getter_AddRefs(uploadStream),
false,
rv = NS_NewCStringInputStream(getter_AddRefs(uploadStream),
mRequestSession->mPostData);
NS_ENSURE_SUCCESS(rv, rv);