Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 3876d40

Browse files
committed
Bug 1404198: Part 1 - Add non-virtual constructor for nsIObject(Input|Output)Stream and update existing callers. r=njn
MozReview-Commit-ID: 3eoh6AwDJyz --HG-- extra : rebase_source : 92b18b6ef07d276cac79ce735ca0b592cffbf87e
1 parent d52de87 commit 3876d40

10 files changed

Lines changed: 69 additions & 64 deletions

File tree

dom/cache/FileUtils.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "mozilla/dom/quota/QuotaManager.h"
1212
#include "mozilla/SnappyCompressOutputStream.h"
1313
#include "mozilla/Unused.h"
14-
#include "nsIBinaryInputStream.h"
15-
#include "nsIBinaryOutputStream.h"
14+
#include "nsIObjectInputStream.h"
15+
#include "nsIObjectOutputStream.h"
1616
#include "nsIFile.h"
1717
#include "nsIUUIDGenerator.h"
1818
#include "nsNetCID.h"
@@ -420,14 +420,10 @@ LockedDirectoryPaddingWrite(nsIFile* aBaseDir, DirPaddingFile aPaddingFileType,
420420
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), file);
421421
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
422422

423-
nsCOMPtr<nsIBinaryOutputStream> binaryStream =
424-
do_CreateInstance("@mozilla.org/binaryoutputstream;1");
425-
if (NS_WARN_IF(!binaryStream)) { return NS_ERROR_FAILURE; }
423+
nsCOMPtr<nsIObjectOutputStream> objectStream =
424+
NS_NewObjectOutputStream(outputStream);
426425

427-
rv = binaryStream->SetOutputStream(outputStream);
428-
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
429-
430-
rv = binaryStream->Write64(aPaddingSize);
426+
rv = objectStream->Write64(aPaddingSize);
431427
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
432428

433429
return rv;
@@ -744,15 +740,11 @@ LockedDirectoryPaddingGet(nsIFile* aBaseDir, int64_t* aPaddingSizeOut)
744740
rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream), stream, 512);
745741
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
746742

747-
nsCOMPtr<nsIBinaryInputStream> binaryStream =
748-
do_CreateInstance("@mozilla.org/binaryinputstream;1");
749-
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
750-
751-
rv = binaryStream->SetInputStream(bufferedStream);
752-
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
743+
nsCOMPtr<nsIObjectInputStream> objectStream =
744+
NS_NewObjectInputStream(bufferedStream);
753745

754746
uint64_t paddingSize = 0;
755-
rv = binaryStream->Read64(&paddingSize);
747+
rv = objectStream->Read64(&paddingSize);
756748
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
757749

758750
*aPaddingSizeOut = paddingSize;

dom/events/DataTransfer.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "nsIClipboard.h"
2020
#include "nsContentUtils.h"
2121
#include "nsIContent.h"
22-
#include "nsIBinaryInputStream.h"
23-
#include "nsIBinaryOutputStream.h"
22+
#include "nsIObjectInputStream.h"
23+
#include "nsIObjectOutputStream.h"
2424
#include "nsIStorageStream.h"
2525
#include "nsStringStream.h"
2626
#include "nsCRT.h"
@@ -996,7 +996,7 @@ DataTransfer::GetTransferable(uint32_t aIndex, nsILoadContext* aLoadContext)
996996
transferable->Init(aLoadContext);
997997

998998
nsCOMPtr<nsIStorageStream> storageStream;
999-
nsCOMPtr<nsIBinaryOutputStream> stream;
999+
nsCOMPtr<nsIObjectOutputStream> stream;
10001000

10011001
bool added = false;
10021002
bool handlingCustomFormats = true;
@@ -1087,8 +1087,7 @@ DataTransfer::GetTransferable(uint32_t aIndex, nsILoadContext* aLoadContext)
10871087
nsCOMPtr<nsIOutputStream> outputStream;
10881088
storageStream->GetOutputStream(0, getter_AddRefs(outputStream));
10891089

1090-
stream = do_CreateInstance("@mozilla.org/binaryoutputstream;1");
1091-
stream->SetOutputStream(outputStream);
1090+
stream = NS_NewObjectOutputStream(outputStream);
10921091
}
10931092

10941093
CheckedInt<uint32_t> formatLength =
@@ -1593,14 +1592,8 @@ DataTransfer::FillInExternalCustomTypes(nsIVariant* aData, uint32_t aIndex,
15931592
nsCOMPtr<nsIInputStream> stringStream;
15941593
NS_NewCStringInputStream(getter_AddRefs(stringStream), str);
15951594

1596-
nsCOMPtr<nsIBinaryInputStream> stream =
1597-
do_CreateInstance("@mozilla.org/binaryinputstream;1");
1598-
if (!stream) {
1599-
return;
1600-
}
1601-
1602-
rv = stream->SetInputStream(stringStream);
1603-
NS_ENSURE_SUCCESS_VOID(rv);
1595+
nsCOMPtr<nsIObjectInputStream> stream =
1596+
NS_NewObjectInputStream(stringStream);
16041597

16051598
uint32_t type;
16061599
do {

dom/quota/ActorsParent.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "mozIStorageConnection.h"
1010
#include "mozIStorageService.h"
11-
#include "nsIBinaryInputStream.h"
12-
#include "nsIBinaryOutputStream.h"
11+
#include "nsIObjectInputStream.h"
12+
#include "nsIObjectOutputStream.h"
1313
#include "nsIFile.h"
1414
#include "nsIFileStreams.h"
1515
#include "nsIObserverService.h"
@@ -2140,18 +2140,14 @@ GetBinaryOutputStream(nsIFile* aFile,
21402140
return rv;
21412141
}
21422142

2143-
nsCOMPtr<nsIBinaryOutputStream> binaryStream =
2144-
do_CreateInstance("@mozilla.org/binaryoutputstream;1");
2145-
if (NS_WARN_IF(!binaryStream)) {
2146-
return NS_ERROR_FAILURE;
2143+
if (NS_WARN_IF(!outputStream)) {
2144+
return NS_ERROR_UNEXPECTED;
21472145
}
21482146

2149-
rv = binaryStream->SetOutputStream(outputStream);
2150-
if (NS_WARN_IF(NS_FAILED(rv))) {
2151-
return rv;
2152-
}
2147+
nsCOMPtr<nsIObjectOutputStream> objectOutputStream =
2148+
NS_NewObjectOutputStream(outputStream);
21532149

2154-
binaryStream.forget(aStream);
2150+
objectOutputStream.forget(aStream);
21552151
return NS_OK;
21562152
}
21572153

dom/xul/nsXULPrototypeCache.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,15 @@ nsXULPrototypeCache::GetOutputStream(nsIURI* uri, nsIObjectOutputStream** stream
399399
nsCOMPtr<nsIStorageStream> storageStream;
400400
bool found = mOutputStreamTable.Get(uri, getter_AddRefs(storageStream));
401401
if (found) {
402-
objectOutput = do_CreateInstance("mozilla.org/binaryoutputstream;1");
403-
if (!objectOutput) return NS_ERROR_OUT_OF_MEMORY;
402+
// Setting an output stream here causes crashes on Windows. The previous
403+
// version of this code always returned NS_ERROR_OUT_OF_MEMORY here,
404+
// because it used a mistyped contract ID to create its object stream.
405+
return NS_ERROR_NOT_IMPLEMENTED;
406+
#if 0
404407
nsCOMPtr<nsIOutputStream> outputStream
405408
= do_QueryInterface(storageStream);
406-
objectOutput->SetOutputStream(outputStream);
409+
objectOutput = NS_NewObjectOutputStream(outputStream);
410+
#endif
407411
} else {
408412
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
409413
getter_AddRefs(storageStream),

netwerk/base/nsSerializationHelper.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ NS_SerializeToString(nsISerializable* obj, nsACString& str)
2525
return NS_ERROR_OUT_OF_MEMORY;
2626

2727
nsCOMPtr<nsIObjectOutputStream> objstream =
28-
do_CreateInstance("@mozilla.org/binaryoutputstream;1");
29-
if (!objstream)
30-
return NS_ERROR_OUT_OF_MEMORY;
31-
32-
objstream->SetOutputStream(stream);
28+
NS_NewObjectOutputStream(stream);
3329
nsresult rv =
3430
objstream->WriteCompoundObject(obj, NS_GET_IID(nsISupports), true);
3531
NS_ENSURE_SUCCESS(rv, rv);
@@ -48,11 +44,7 @@ NS_DeserializeObject(const nsACString& str, nsISupports** obj)
4844
NS_ENSURE_SUCCESS(rv, rv);
4945

5046
nsCOMPtr<nsIObjectInputStream> objstream =
51-
do_CreateInstance("@mozilla.org/binaryinputstream;1");
52-
if (!objstream)
53-
return NS_ERROR_OUT_OF_MEMORY;
54-
55-
objstream->SetInputStream(stream);
47+
NS_NewObjectInputStream(stream);
5648
return objstream->ReadObject(true, obj);
5749
}
5850

startupcache/StartupCacheUtils.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "nsIResProtocolHandler.h"
1212
#include "nsIChromeRegistry.h"
1313
#include "nsAutoPtr.h"
14+
#include "nsStringStream.h"
1415
#include "StartupCacheUtils.h"
1516
#include "mozilla/scache/StartupCache.h"
1617
#include "mozilla/Omnijar.h"
@@ -22,16 +23,14 @@ nsresult
2223
NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
2324
nsIObjectInputStream** stream)
2425
{
25-
nsCOMPtr<nsIStringInputStream> stringStream =
26-
do_CreateInstance("@mozilla.org/io/string-input-stream;1");
27-
NS_ENSURE_TRUE(stringStream, NS_ERROR_FAILURE);
26+
nsCOMPtr<nsIInputStream> stringStream;
27+
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream),
28+
buffer.release(), len,
29+
NS_ASSIGNMENT_ADOPT);
30+
MOZ_ALWAYS_SUCCEEDS(rv);
2831

2932
nsCOMPtr<nsIObjectInputStream> objectInput =
30-
do_CreateInstance("@mozilla.org/binaryinputstream;1");
31-
NS_ENSURE_TRUE(objectInput, NS_ERROR_FAILURE);
32-
33-
stringStream->AdoptData(buffer.release(), len);
34-
objectInput->SetInputStream(stringStream);
33+
NS_NewObjectInputStream(stringStream);
3534

3635
objectInput.forget(stream);
3736
return NS_OK;
@@ -47,12 +46,11 @@ NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
4746
nsresult rv = NS_NewStorageStream(256, UINT32_MAX, getter_AddRefs(storageStream));
4847
NS_ENSURE_SUCCESS(rv, rv);
4948

50-
nsCOMPtr<nsIObjectOutputStream> objectOutput
51-
= do_CreateInstance("@mozilla.org/binaryoutputstream;1");
5249
nsCOMPtr<nsIOutputStream> outputStream
5350
= do_QueryInterface(storageStream);
5451

55-
objectOutput->SetOutputStream(outputStream);
52+
nsCOMPtr<nsIObjectOutputStream> objectOutput
53+
= NS_NewObjectOutputStream(outputStream);
5654

5755
#ifdef DEBUG
5856
if (wantDebugStream) {

xpcom/io/nsBinaryStream.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "mozilla/EndianUtils.h"
2727
#include "mozilla/PodOperations.h"
28+
#include "mozilla/RefPtr.h"
2829
#include "mozilla/UniquePtr.h"
2930

3031
#include "nsCRT.h"
@@ -41,6 +42,26 @@ using mozilla::MakeUnique;
4142
using mozilla::PodCopy;
4243
using mozilla::UniquePtr;
4344

45+
already_AddRefed<nsIObjectOutputStream>
46+
NS_NewObjectOutputStream(nsIOutputStream* aOutputStream)
47+
{
48+
MOZ_ASSERT(aOutputStream);
49+
auto stream = mozilla::MakeRefPtr<nsBinaryOutputStream>();
50+
51+
MOZ_ALWAYS_SUCCEEDS(stream->SetOutputStream(aOutputStream));
52+
return stream.forget();
53+
}
54+
55+
already_AddRefed<nsIObjectInputStream>
56+
NS_NewObjectInputStream(nsIInputStream* aInputStream)
57+
{
58+
MOZ_ASSERT(aInputStream);
59+
auto stream = mozilla::MakeRefPtr<nsBinaryInputStream>();
60+
61+
MOZ_ALWAYS_SUCCEEDS(stream->SetInputStream(aInputStream));
62+
return stream.forget();
63+
}
64+
4465
NS_IMPL_ISUPPORTS(nsBinaryOutputStream,
4566
nsIObjectOutputStream,
4667
nsIBinaryOutputStream,

xpcom/io/nsBinaryStream.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class nsBinaryOutputStream final : public nsIObjectOutputStream
3333
}
3434

3535
protected:
36+
friend already_AddRefed<nsIObjectOutputStream> NS_NewObjectOutputStream(nsIOutputStream*);
37+
3638
// nsISupports methods
3739
NS_DECL_ISUPPORTS
3840

@@ -76,6 +78,8 @@ class nsBinaryInputStream final : public nsIObjectInputStream
7678
}
7779

7880
protected:
81+
friend already_AddRefed<nsIObjectInputStream> NS_NewObjectInputStream(nsIInputStream*);
82+
7983
// nsISupports methods
8084
NS_DECL_ISUPPORTS
8185

xpcom/io/nsIObjectInputStream.idl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ interface nsIObjectInputStream : nsIBinaryInputStream
3535

3636
%{C++
3737

38+
already_AddRefed<nsIObjectInputStream>
39+
NS_NewObjectInputStream(nsIInputStream* aOutputStream);
40+
3841
inline nsresult
3942
NS_ReadOptionalObject(nsIObjectInputStream* aStream, bool aIsStrongRef,
4043
nsISupports* *aResult)

xpcom/io/nsIObjectOutputStream.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ interface nsIObjectOutputStream : nsIBinaryOutputStream
5858
};
5959

6060
%{C++
61+
already_AddRefed<nsIObjectOutputStream>
62+
NS_NewObjectOutputStream(nsIOutputStream* aOutputStream);
6163

6264
inline nsresult
6365
NS_WriteOptionalObject(nsIObjectOutputStream* aStream, nsISupports* aObject,

0 commit comments

Comments
 (0)