summaryrefslogtreecommitdiffstats
path: root/dom/fetch/FetchStreamUtils.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /dom/fetch/FetchStreamUtils.cpp
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/fetch/FetchStreamUtils.cpp')
-rw-r--r--dom/fetch/FetchStreamUtils.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/dom/fetch/FetchStreamUtils.cpp b/dom/fetch/FetchStreamUtils.cpp
new file mode 100644
index 0000000000..96f4dc346e
--- /dev/null
+++ b/dom/fetch/FetchStreamUtils.cpp
@@ -0,0 +1,68 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 "FetchStreamUtils.h"
+
+#include "mozilla/NotNull.h"
+#include "mozilla/RemoteLazyInputStreamChild.h"
+#include "mozilla/RemoteLazyInputStreamStorage.h"
+#include "mozilla/dom/FetchTypes.h"
+#include "mozilla/dom/IPCBlob.h"
+#include "nsContentUtils.h"
+#include "nsXULAppAPI.h"
+
+namespace mozilla::dom {
+
+namespace {
+
+RefPtr<RemoteLazyInputStreamStorage> GetRemoteLazyInputStreamStorage() {
+ auto storageOrErr = RemoteLazyInputStreamStorage::Get();
+ MOZ_ASSERT(storageOrErr.isOk());
+ return storageOrErr.unwrap();
+}
+
+} // namespace
+
+NotNull<nsCOMPtr<nsIInputStream>> ToInputStream(
+ const ParentToParentStream& aStream) {
+ MOZ_ASSERT(XRE_IsParentProcess());
+ return WrapNotNull(
+ GetRemoteLazyInputStreamStorage()->ForgetStream(aStream.uuid()));
+}
+
+NotNull<nsCOMPtr<nsIInputStream>> ToInputStream(
+ const ParentToChildStream& aStream) {
+ MOZ_ASSERT(XRE_IsContentProcess());
+ nsCOMPtr<nsIInputStream> result = aStream.stream();
+ return WrapNotNull(result);
+}
+
+ParentToParentStream ToParentToParentStream(
+ const NotNull<nsCOMPtr<nsIInputStream>>& aStream, int64_t aStreamSize) {
+ MOZ_ASSERT(XRE_IsParentProcess());
+
+ ParentToParentStream stream;
+ stream.uuid() = nsID::GenerateUUID();
+ GetRemoteLazyInputStreamStorage()->AddStream(aStream.get(), stream.uuid());
+ return stream;
+}
+
+ParentToChildStream ToParentToChildStream(
+ const NotNull<nsCOMPtr<nsIInputStream>>& aStream, int64_t aStreamSize,
+ NotNull<mozilla::ipc::PBackgroundParent*> aBackgroundParent) {
+ MOZ_ASSERT(XRE_IsParentProcess());
+
+ ParentToChildStream result;
+ result.stream() = RemoteLazyInputStream::WrapStream(aStream.get());
+ return result;
+}
+
+ParentToChildStream ToParentToChildStream(
+ const ParentToParentStream& aStream, int64_t aStreamSize,
+ NotNull<mozilla::ipc::PBackgroundParent*> aBackgroundParent) {
+ return ToParentToChildStream(ToInputStream(aStream), aStreamSize,
+ aBackgroundParent);
+}
+
+} // namespace mozilla::dom