Bug 1371699 part 3. Make nsIStringInputStream not inherit from nsIInputStream anymore. r=bkelly

This will prevent ambiguous nsIInputStream inheritance once we also inherit from nsIAsyncInputStream.
This commit is contained in:
Boris Zbarsky 2017-06-13 16:16:23 -04:00
Родитель 4c7424ec25
Коммит 3d884086c3
21 изменённых файлов: 75 добавлений и 85 удалений

Просмотреть файл

@ -73,18 +73,17 @@ nsFeedSniffer::ConvertEncodedData(nsIRequest* request,
converter->OnStartRequest(request, nullptr);
nsCOMPtr<nsIStringInputStream> rawStream =
do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID);
if (!rawStream)
return NS_ERROR_FAILURE;
if (data) {
nsCOMPtr<nsIInputStream> rawStream;
rv = NS_NewCStringInputStream(
getter_AddRefs(rawStream),
nsDependentCSubstring(reinterpret_cast<const char*>(data), length));
if (NS_SUCCEEDED(rv)) {
rv = converter->OnDataAvailable(request, nullptr, rawStream, 0, length);
}
}
rv = rawStream->SetData((const char*)data, length);
NS_ENSURE_SUCCESS(rv, rv);
rv = converter->OnDataAvailable(request, nullptr, rawStream, 0, length);
NS_ENSURE_SUCCESS(rv, rv);
converter->OnStopRequest(request, nullptr, NS_OK);
converter->OnStopRequest(request, nullptr, rv);
}
}
return rv;

Просмотреть файл

@ -372,7 +372,7 @@ UDPSocket::Send(const StringOrBlobOrArrayBufferOrArrayBufferView& aData,
return false;
}
stream = strStream;
stream = do_QueryInterface(strStream);
}
if (mSocket) {

Просмотреть файл

@ -580,7 +580,7 @@ nsresult nsPluginHost::PostURL(nsISupports* pluginInst,
// freed by the string stream.
postDataLen = newDataToPostLen;
sis->AdoptData(dataToPost, postDataLen);
postStream = sis;
postStream = do_QueryInterface(sis);
if (target) {
RefPtr<nsPluginInstanceOwner> owner = instance->GetOwner();

Просмотреть файл

@ -25,7 +25,7 @@ using mozilla::DefaultXDisplay;
#include "GLImages.h"
#include "nsPluginFrame.h"
#include "nsIPluginDocument.h"
#include "nsIStringStream.h"
#include "nsStringStream.h"
#include "nsNetUtil.h"
#include "mozilla/Preferences.h"
#include "nsILinkHandler.h"
@ -540,13 +540,11 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,
if (!aHeadersDataLen)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIStringInputStream> sis = do_CreateInstance("@mozilla.org/io/string-input-stream;1");
if (!sis)
return NS_ERROR_OUT_OF_MEMORY;
rv = sis->SetData((char *)aHeadersData, aHeadersDataLen);
rv = NS_NewCStringInputStream(
getter_AddRefs(headersDataStream),
nsDependentCSubstring(reinterpret_cast<const char*>(aHeadersData),
aHeadersDataLen));
NS_ENSURE_SUCCESS(rv, rv);
headersDataStream = do_QueryInterface(sis);
}
int32_t blockPopups =

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsThreadUtils.h"
#include "PresentationLog.h"
#include "PresentationTCPSessionTransport.h"
#include "nsStringStream.h"
#define BUFFER_SIZE 65536
@ -393,16 +394,10 @@ PresentationTCPSessionTransport::Send(const nsAString& aData)
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream =
do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
if(NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
NS_ConvertUTF16toUTF8 msgString(aData);
rv = stream->SetData(msgString.BeginReading(), msgString.Length());
if(NS_WARN_IF(NS_FAILED(rv))) {
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream),
NS_ConvertUTF16toUTF8(aData));
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}

Просмотреть файл

@ -1015,13 +1015,6 @@ nsCSPContext::SendReports(nsISupports* aBlockedContentSource,
rv = reportChannel->SetLoadGroup(mCallingChannelLoadGroup);
NS_ENSURE_SUCCESS(rv, rv);
// wire in the string input stream to send the report
nsCOMPtr<nsIStringInputStream> sis(do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID));
NS_ASSERTION(sis, "nsIStringInputStream is needed but not available to send CSP violation reports");
nsAutoCString utf8CSPReport = NS_ConvertUTF16toUTF8(csp_report);
rv = sis->SetData(utf8CSPReport.get(), utf8CSPReport.Length());
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(reportChannel));
if (!uploadChannel) {
// It's possible the URI provided can't be uploaded to, in which case
@ -1029,7 +1022,14 @@ nsCSPContext::SendReports(nsISupports* aBlockedContentSource,
continue;
}
rv = uploadChannel->SetUploadStream(sis, NS_LITERAL_CSTRING("application/csp-report"), -1);
// wire in the string input stream to send the report
nsCOMPtr<nsIInputStream> stream;
rv = NS_NewCStringInputStream(getter_AddRefs(stream),
NS_ConvertUTF16toUTF8(csp_report));
NS_ENSURE_SUCCESS(rv, rv);
rv = uploadChannel->SetUploadStream(
stream, NS_LITERAL_CSTRING("application/csp-report"), -1);
NS_ENSURE_SUCCESS(rv, rv);
// if this is an HTTP channel, set the request method to post

Просмотреть файл

@ -11,6 +11,7 @@
#include "AndroidBridge.h"
#include "nsIconChannel.h"
#include "nsIStringStream.h"
#include "nsIInputStream.h"
#include "nsNetUtil.h"
#include "nsComponentManagerUtils.h"
#include "NullPrincipal.h"
@ -105,13 +106,15 @@ moz_icon_to_channel(nsIURI* aURI, const nsACString& aFileExt,
}
}
nsCOMPtr<nsIStringInputStream> stream =
nsCOMPtr<nsIStringInputStream> sis =
do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = stream->AdoptData((char*)buf, buf_size);
rv = sis->AdoptData((char*)buf, buf_size);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> stream = do_QueryInterface(sis);
// nsIconProtocolHandler::NewChannel2 will provide the correct loadInfo for
// this iconChannel. Use the most restrictive security settings for the
// temporary loadInfo to make sure the channel can not be openend.

Просмотреть файл

@ -24,6 +24,7 @@
#include "nsNetUtil.h"
#include "nsComponentManagerUtils.h"
#include "nsIStringStream.h"
#include "nsIInputStream.h"
#include "nsServiceManagerUtils.h"
#include "NullPrincipal.h"
#include "nsIURL.h"
@ -86,7 +87,7 @@ moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI* aURI,
NS_ASSERTION(out == buf + buf_size, "size miscalculation");
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream =
nsCOMPtr<nsIStringInputStream> sis =
do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
// Prevent the leaking of buf
@ -97,12 +98,14 @@ moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI* aURI,
// stream takes ownership of buf and will free it on destruction.
// This function cannot fail.
rv = stream->AdoptData((char*)buf, buf_size);
rv = sis->AdoptData((char*)buf, buf_size);
// If this no longer holds then re-examine buf's lifetime.
MOZ_ASSERT(NS_SUCCEEDED(rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> stream(do_QueryInterface(sis));
// nsIconProtocolHandler::NewChannel2 will provide the correct loadInfo for
// this iconChannel. Use the most restrictive security settings for the
// temporary loadInfo to make sure the channel can not be openend.

Просмотреть файл

@ -14,7 +14,7 @@
#include "nsXPIDLString.h"
#include "nsMimeTypes.h"
#include "nsMemory.h"
#include "nsIStringStream.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsNetCID.h"
#include "nsIPipe.h"

Просмотреть файл

@ -15,7 +15,7 @@
#include "nsReadableUtils.h"
#include "nsMimeTypes.h"
#include "nsMemory.h"
#include "nsIStringStream.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsIOutputStream.h"
#include "nsIPipe.h"

Просмотреть файл

@ -8,6 +8,7 @@
#include "nsIScriptableUConv.h"
#include "nsScriptableUConv.h"
#include "nsIStringStream.h"
#include "nsIInputStream.h"
#include "nsComponentManagerUtils.h"
using namespace mozilla;
@ -233,8 +234,7 @@ nsScriptableUnicodeConverter::ConvertToInputStream(const nsAString& aString,
return rv;
}
NS_ADDREF(*_retval = inputStream);
return rv;
return CallQueryInterface(inputStream, _retval);
}
NS_IMETHODIMP

Просмотреть файл

@ -622,15 +622,11 @@ NS_NewInputStreamChannelInternal(nsIChannel **outChannel,
nsILoadInfo *aLoadInfo,
bool aIsSrcdocChannel /* = false */)
{
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream;
stream = do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream),
NS_ConvertUTF16toUTF8(aData));
NS_ENSURE_SUCCESS(rv, rv);
uint32_t len;
char* utf8Bytes = ToNewUTF8String(aData, &len);
rv = stream->AdoptData(utf8Bytes, len);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewInputStreamChannelInternal(getter_AddRefs(channel),
aUri,
@ -1454,12 +1450,8 @@ NS_NewPostDataStream(nsIInputStream **result,
}
// 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());
nsCOMPtr<nsIInputStream> stream;
rv = NS_NewCStringInputStream(getter_AddRefs(stream), data);
if (NS_FAILED(rv))
return rv;

Просмотреть файл

@ -517,7 +517,8 @@ nsHTTPCompressConv::do_OnDataAvailable(nsIRequest* request,
MutexAutoLock lock(mMutex);
listener = mListener;
}
nsresult rv = listener->OnDataAvailable(request, context, mStream,
nsCOMPtr<nsIInputStream> stream(do_QueryInterface(mStream));
nsresult rv = listener->OnDataAvailable(request, context, stream,
offset, count);
// Make sure the stream no longer references |buffer| in case our listener

Просмотреть файл

@ -765,19 +765,15 @@ nsUnknownDecoder::ConvertEncodedData(nsIRequest* request,
if (listener) {
listener->OnStartRequest(request, nullptr);
nsCOMPtr<nsIStringInputStream> rawStream =
do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID);
if (!rawStream)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIInputStream> rawStream;
rv = NS_NewCStringInputStream(getter_AddRefs(rawStream),
nsDependentCSubstring(data, length));
if (NS_SUCCEEDED(rv)) {
rv = listener->OnDataAvailable(request, nullptr, rawStream, 0,
length);
}
rv = rawStream->SetData((const char*)data, length);
NS_ENSURE_SUCCESS(rv, rv);
rv = listener->OnDataAvailable(request, nullptr, rawStream, 0,
length);
NS_ENSURE_SUCCESS(rv, rv);
listener->OnStopRequest(request, nullptr, NS_OK);
listener->OnStopRequest(request, nullptr, rv);
}
}
return rv;

Просмотреть файл

@ -375,10 +375,10 @@ CacheCloseHelper(const nsACString& key, const CacheEntry* data,
MOZ_ASSERT(data); // assert key was found in mTable.
nsresult rv;
nsIStringInputStream* stream = holder->stream;
nsIStringInputStream* sis = holder->stream;
nsIZipWriter* writer = holder->writer;
stream->ShareData(data->data.get(), data->size);
sis->ShareData(data->data.get(), data->size);
#ifdef DEBUG
bool hasEntry;
@ -386,6 +386,7 @@ CacheCloseHelper(const nsACString& key, const CacheEntry* data,
NS_ASSERTION(NS_SUCCEEDED(rv) && hasEntry == false,
"Existing entry in disk StartupCache.");
#endif
nsCOMPtr<nsIInputStream> stream(do_QueryInterface(sis));
rv = writer->AddEntryStream(key, holder->time, true, stream, false);
if (NS_FAILED(rv)) {

Просмотреть файл

@ -31,7 +31,8 @@ NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
NS_ENSURE_TRUE(objectInput, NS_ERROR_FAILURE);
stringStream->AdoptData(buffer.release(), len);
objectInput->SetInputStream(stringStream);
nsCOMPtr<nsIInputStream> baseStream(do_QueryInterface(stringStream));
objectInput->SetInputStream(baseStream);
objectInput.forget(stream);
return NS_OK;

Просмотреть файл

@ -1363,6 +1363,9 @@ PendingLookup::SendRemoteQueryInternal()
rv = sstream->SetData(serialized.c_str(), serialized.length());
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> stream(do_QueryInterface(sstream));
// Set up the channel to transmit the request to the service.
nsCOMPtr<nsIIOService> ios = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
rv = ios->NewChannel2(serviceUrl,
@ -1391,7 +1394,7 @@ PendingLookup::SendRemoteQueryInternal()
nsCOMPtr<nsIUploadChannel2> uploadChannel = do_QueryInterface(mChannel, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = uploadChannel->ExplicitSetUploadStream(sstream,
rv = uploadChannel->ExplicitSetUploadStream(stream,
NS_LITERAL_CSTRING("application/octet-stream"), serialized.size(),
NS_LITERAL_CSTRING("POST"), false);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -546,13 +546,9 @@ nsUrlClassifierStreamUpdater::UpdateError(nsresult result)
nsresult
nsUrlClassifierStreamUpdater::AddRequestBody(const nsACString &aRequestBody)
{
nsresult rv;
nsCOMPtr<nsIStringInputStream> strStream =
do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = strStream->SetData(aRequestBody.BeginReading(),
aRequestBody.Length());
nsCOMPtr<nsIInputStream> strStream;
nsresult rv = NS_NewCStringInputStream(getter_AddRefs(strStream),
aRequestBody);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIUploadChannel> uploadChannel = do_QueryInterface(mChannel, &rv);

Просмотреть файл

@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIInputStream.idl"
#include "nsISupports.idl"
%{C++
#include "mozilla/MemoryReporting.h"
@ -18,7 +18,7 @@ native MallocSizeOf(mozilla::MallocSizeOf);
* nsIInputStream implementation with a simple character array.
*/
[scriptable, builtinclass, uuid(450cd2d4-f0fd-424d-b365-b1251f80fd53)]
interface nsIStringInputStream : nsIInputStream
interface nsIStringInputStream : nsISupports
{
/**
* SetData - assign data to the input stream (copied on assignment).

Просмотреть файл

@ -34,6 +34,7 @@ using mozilla::Some;
class nsStringInputStream final
: public nsIStringInputStream
, public nsIInputStream
, public nsISeekableStream
, public nsISupportsCString
, public nsIIPCSerializableInputStream

Просмотреть файл

@ -8,6 +8,7 @@
#define nsStringStream_h__
#include "nsIStringStream.h"
#include "nsIInputStream.h"
#include "nsStringGlue.h"
#include "nsMemory.h"