1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "WebBrowserPersistSerializeChild.h"
11 #include "nsThreadUtils.h"
15 NS_IMPL_ISUPPORTS(WebBrowserPersistSerializeChild
,
16 nsIWebBrowserPersistWriteCompletion
,
17 nsIWebBrowserPersistURIMap
, nsIOutputStream
)
19 WebBrowserPersistSerializeChild::WebBrowserPersistSerializeChild(
20 const WebBrowserPersistURIMap
& aMap
)
23 WebBrowserPersistSerializeChild::~WebBrowserPersistSerializeChild() = default;
26 WebBrowserPersistSerializeChild::OnFinish(
27 nsIWebBrowserPersistDocument
* aDocument
, nsIOutputStream
* aStream
,
28 const nsACString
& aContentType
, nsresult aStatus
) {
29 MOZ_ASSERT(aStream
== this);
30 nsCString
contentType(aContentType
);
31 Send__delete__(this, contentType
, aStatus
);
36 WebBrowserPersistSerializeChild::GetNumMappedURIs(uint32_t* aNum
) {
37 *aNum
= static_cast<uint32_t>(mMap
.mapURIs().Length());
42 WebBrowserPersistSerializeChild::GetURIMapping(uint32_t aIndex
,
45 if (aIndex
>= mMap
.mapURIs().Length()) {
46 return NS_ERROR_INVALID_ARG
;
48 aMapFrom
= mMap
.mapURIs()[aIndex
].mapFrom();
49 aMapTo
= mMap
.mapURIs()[aIndex
].mapTo();
54 WebBrowserPersistSerializeChild::GetTargetBaseURI(nsACString
& aURI
) {
55 aURI
= mMap
.targetBaseURI();
60 WebBrowserPersistSerializeChild::Close() {
61 NS_WARNING("WebBrowserPersistSerializeChild::Close()");
62 return NS_ERROR_NOT_IMPLEMENTED
;
66 WebBrowserPersistSerializeChild::Flush() {
67 NS_WARNING("WebBrowserPersistSerializeChild::Flush()");
68 return NS_ERROR_NOT_IMPLEMENTED
;
72 WebBrowserPersistSerializeChild::StreamStatus() {
73 // XXX: This stream doesn't appear to have a closed state.
78 WebBrowserPersistSerializeChild::Write(const char* aBuf
, uint32_t aCount
,
80 // Normally an nsIOutputStream would have to be thread-safe, but
81 // nsDocumentEncoder currently doesn't call this off the main
82 // thread (which also means it's difficult to test the
83 // thread-safety code this class doesn't yet have).
85 // This is *not* an NS_ERROR_NOT_IMPLEMENTED, because at this
86 // point we've probably already misused the non-thread-safe
88 MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Fix this class to be thread-safe.");
90 // Limit the message size to 64k because large messages are
91 // potentially bad for the latency of other messages on the same channel.
92 static const uint32_t kMaxWrite
= 65536;
94 // Work around bug 1181433 by sending multiple messages if
95 // necessary to write the entire aCount bytes, even though
96 // nsIOutputStream.idl says we're allowed to do a short write.
97 const char* buf
= aBuf
;
98 uint32_t count
= aCount
;
101 uint32_t toWrite
= std::min(kMaxWrite
, count
);
102 nsTArray
<uint8_t> arrayBuf
;
103 // It would be nice if this extra copy could be avoided.
104 arrayBuf
.AppendElements(buf
, toWrite
);
105 SendWriteData(std::move(arrayBuf
));
106 *aWritten
+= toWrite
;
114 WebBrowserPersistSerializeChild::WriteFrom(nsIInputStream
* aFrom
,
116 uint32_t* aWritten
) {
117 NS_WARNING("WebBrowserPersistSerializeChild::WriteFrom()");
118 return NS_ERROR_NOT_IMPLEMENTED
;
122 WebBrowserPersistSerializeChild::WriteSegments(nsReadSegmentFun aFun
,
123 void* aCtx
, uint32_t aCount
,
124 uint32_t* aWritten
) {
125 NS_WARNING("WebBrowserPersistSerializeChild::WriteSegments()");
126 return NS_ERROR_NOT_IMPLEMENTED
;
130 WebBrowserPersistSerializeChild::IsNonBlocking(bool* aNonBlocking
) {
131 // Writes will never fail with NS_BASE_STREAM_WOULD_BLOCK, so:
132 *aNonBlocking
= false;
136 } // namespace mozilla