summaryrefslogtreecommitdiffstats
path: root/dom/cache/TypeUtils.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/cache/TypeUtils.h
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/cache/TypeUtils.h')
-rw-r--r--dom/cache/TypeUtils.h138
1 files changed, 138 insertions, 0 deletions
diff --git a/dom/cache/TypeUtils.h b/dom/cache/TypeUtils.h
new file mode 100644
index 0000000000..5342ea3d7e
--- /dev/null
+++ b/dom/cache/TypeUtils.h
@@ -0,0 +1,138 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#ifndef mozilla_dom_cache_TypesUtils_h
+#define mozilla_dom_cache_TypesUtils_h
+
+#include "mozilla/AlreadyAddRefed.h" // for already_AddRefed
+#include "mozilla/UniquePtr.h" // for UniquePtr
+#include "mozilla/dom/HeadersBinding.h" // for HeadersGuardEnum, HeadersGua...
+#include "mozilla/dom/SafeRefPtr.h" // for SafeRefPtr
+#include "nsStringFwd.h" // for nsACString, nsAString
+
+class nsIGlobalObject;
+class nsIAsyncInputStream;
+class nsIInputStream;
+
+namespace mozilla {
+
+namespace ipc {
+class PBackgroundChild;
+} // namespace ipc
+
+namespace dom {
+
+struct CacheQueryOptions;
+struct MultiCacheQueryOptions;
+class InternalHeaders;
+class InternalRequest;
+class InternalResponse;
+class OwningRequestOrUSVString;
+class Request;
+class RequestOrUSVString;
+class Response;
+
+namespace cache {
+
+class CacheQueryParams;
+class CacheReadStream;
+class CacheRequest;
+class CacheResponse;
+class HeadersEntry;
+
+class TypeUtils {
+ public:
+ enum BodyAction { IgnoreBody, ReadBody };
+
+ enum SchemeAction { IgnoreInvalidScheme, TypeErrorOnInvalidScheme };
+
+ ~TypeUtils() = default;
+ virtual nsIGlobalObject* GetGlobalObject() const = 0;
+#ifdef DEBUG
+ virtual void AssertOwningThread() const = 0;
+#else
+ inline void AssertOwningThread() const {}
+#endif
+
+ // This is mainly declared to support serializing body streams. Some
+ // TypeUtils implementations do not expect to be used for this kind of
+ // serialization. These classes will MOZ_CRASH() if you try to call
+ // GetIPCManager().
+ virtual mozilla::ipc::PBackgroundChild* GetIPCManager() = 0;
+
+ SafeRefPtr<InternalRequest> ToInternalRequest(JSContext* aCx,
+ const RequestOrUSVString& aIn,
+ BodyAction aBodyAction,
+ ErrorResult& aRv);
+
+ SafeRefPtr<InternalRequest> ToInternalRequest(
+ JSContext* aCx, const OwningRequestOrUSVString& aIn,
+ BodyAction aBodyAction, ErrorResult& aRv);
+
+ void ToCacheRequest(CacheRequest& aOut, const InternalRequest& aIn,
+ BodyAction aBodyAction, SchemeAction aSchemeAction,
+ ErrorResult& aRv);
+
+ void ToCacheResponseWithoutBody(CacheResponse& aOut, InternalResponse& aIn,
+ ErrorResult& aRv);
+
+ void ToCacheResponse(JSContext* aCx, CacheResponse& aOut, Response& aIn,
+ ErrorResult& aRv);
+
+ void ToCacheQueryParams(CacheQueryParams& aOut, const CacheQueryOptions& aIn);
+
+ void ToCacheQueryParams(CacheQueryParams& aOut,
+ const MultiCacheQueryOptions& aIn);
+
+ already_AddRefed<Response> ToResponse(const CacheResponse& aIn);
+
+ SafeRefPtr<InternalRequest> ToInternalRequest(const CacheRequest& aIn);
+
+ SafeRefPtr<Request> ToRequest(const CacheRequest& aIn);
+
+ // static methods
+ static already_AddRefed<InternalHeaders> ToInternalHeaders(
+ const nsTArray<HeadersEntry>& aHeadersEntryList,
+ HeadersGuardEnum aGuard = HeadersGuardEnum::None);
+
+ // Utility method for parsing a URL and doing associated operations. A mix
+ // of things are done in this one method to avoid duplicated parsing:
+ //
+ // 1) The aUrl argument is modified to strip the fragment
+ // 2) If aSchemaValidOut is set, then a boolean value is set indicating
+ // if the aUrl's scheme is valid or not for storing in the cache.
+ // 3) If aUrlWithoutQueryOut is set, then a url string is provided without
+ // the search section.
+ // 4) If aUrlQueryOut is set then its populated with the search section
+ // of the URL. Note, this parameter must be set if aUrlWithoutQueryOut
+ // is set. They must either both be nullptr or set to valid string
+ // pointers.
+ //
+ // Any errors are thrown on ErrorResult.
+ static void ProcessURL(nsACString& aUrl, bool* aSchemeValidOut,
+ nsACString* aUrlWithoutQueryOut,
+ nsACString* aUrlQueryOut, ErrorResult& aRv);
+
+ private:
+ void CheckAndSetBodyUsed(JSContext* aCx, Request& aRequest,
+ BodyAction aBodyAction, ErrorResult& aRv);
+
+ SafeRefPtr<InternalRequest> ToInternalRequest(const nsAString& aIn,
+ ErrorResult& aRv);
+
+ void SerializeCacheStream(nsIInputStream* aStream,
+ Maybe<CacheReadStream>* aStreamOut,
+ ErrorResult& aRv);
+
+ void SerializeSendStream(nsIInputStream* aStream,
+ CacheReadStream& aReadStreamOut, ErrorResult& aRv);
+};
+
+} // namespace cache
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_cache_TypesUtils_h