2015-03-02 16:20:00 +03:00
|
|
|
/* -*- 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
|
|
|
|
|
2020-07-22 18:12:10 +03:00
|
|
|
#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
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
class nsIGlobalObject;
|
2015-03-22 09:52:12 +03:00
|
|
|
class nsIAsyncInputStream;
|
2015-03-02 16:20:00 +03:00
|
|
|
class nsIInputStream;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2016-05-15 20:32:09 +03:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PBackgroundChild;
|
|
|
|
class AutoIPCStream;
|
|
|
|
} // namespace ipc
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct CacheQueryOptions;
|
2020-09-17 16:02:46 +03:00
|
|
|
struct MultiCacheQueryOptions;
|
2020-07-22 18:12:10 +03:00
|
|
|
class InternalHeaders;
|
2015-03-02 16:20:00 +03:00
|
|
|
class InternalRequest;
|
|
|
|
class InternalResponse;
|
|
|
|
class OwningRequestOrUSVString;
|
|
|
|
class Request;
|
|
|
|
class RequestOrUSVString;
|
|
|
|
class Response;
|
|
|
|
|
|
|
|
namespace cache {
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
class CacheQueryParams;
|
|
|
|
class CacheReadStream;
|
|
|
|
class CacheRequest;
|
|
|
|
class CacheResponse;
|
2015-04-16 22:00:15 +03:00
|
|
|
class HeadersEntry;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
class TypeUtils {
|
|
|
|
public:
|
|
|
|
enum BodyAction { IgnoreBody, ReadBody };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-29 18:59:43 +03:00
|
|
|
enum SchemeAction { IgnoreInvalidScheme, TypeErrorOnInvalidScheme };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-02-20 18:49:27 +03:00
|
|
|
~TypeUtils() = default;
|
2015-03-02 16:20:00 +03:00
|
|
|
virtual nsIGlobalObject* GetGlobalObject() const = 0;
|
|
|
|
#ifdef DEBUG
|
|
|
|
virtual void AssertOwningThread() const = 0;
|
|
|
|
#else
|
|
|
|
inline void AssertOwningThread() const {}
|
|
|
|
#endif
|
|
|
|
|
2016-05-15 20:32:09 +03:00
|
|
|
// 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;
|
2015-03-22 09:52:12 +03:00
|
|
|
|
2020-05-11 15:10:53 +03:00
|
|
|
SafeRefPtr<InternalRequest> ToInternalRequest(JSContext* aCx,
|
|
|
|
const RequestOrUSVString& aIn,
|
|
|
|
BodyAction aBodyAction,
|
|
|
|
ErrorResult& aRv);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2020-05-11 15:10:53 +03:00
|
|
|
SafeRefPtr<InternalRequest> ToInternalRequest(
|
2017-08-11 04:04:55 +03:00
|
|
|
JSContext* aCx, const OwningRequestOrUSVString& aIn,
|
|
|
|
BodyAction aBodyAction, ErrorResult& aRv);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void ToCacheRequest(
|
2020-05-11 15:10:53 +03:00
|
|
|
CacheRequest& aOut, const InternalRequest& aIn, BodyAction aBodyAction,
|
2015-04-29 18:59:43 +03:00
|
|
|
SchemeAction aSchemeAction,
|
2016-05-15 20:32:09 +03:00
|
|
|
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
|
2015-04-29 18:59:43 +03:00
|
|
|
ErrorResult& aRv);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void ToCacheResponseWithoutBody(CacheResponse& aOut, InternalResponse& aIn,
|
|
|
|
ErrorResult& aRv);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2017-08-11 04:04:55 +03:00
|
|
|
void ToCacheResponse(
|
|
|
|
JSContext* aCx, CacheResponse& aOut, Response& aIn,
|
2016-05-15 20:32:09 +03:00
|
|
|
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
|
|
|
|
ErrorResult& aRv);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void ToCacheQueryParams(CacheQueryParams& aOut, const CacheQueryOptions& aIn);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2020-09-17 16:02:46 +03:00
|
|
|
void ToCacheQueryParams(CacheQueryParams& aOut,
|
|
|
|
const MultiCacheQueryOptions& aIn);
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
already_AddRefed<Response> ToResponse(const CacheResponse& aIn);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2020-05-11 15:10:53 +03:00
|
|
|
SafeRefPtr<InternalRequest> ToInternalRequest(const CacheRequest& aIn);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2020-05-11 15:13:48 +03:00
|
|
|
SafeRefPtr<Request> ToRequest(const CacheRequest& aIn);
|
2015-04-14 00:05:57 +03:00
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
// static methods
|
|
|
|
static already_AddRefed<InternalHeaders> ToInternalHeaders(
|
|
|
|
const nsTArray<HeadersEntry>& aHeadersEntryList,
|
|
|
|
HeadersGuardEnum aGuard = HeadersGuardEnum::None);
|
|
|
|
|
2015-06-17 03:39:05 +03:00
|
|
|
// 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.
|
2015-06-17 03:39:05 +03:00
|
|
|
// 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.
|
2015-06-17 03:39:05 +03:00
|
|
|
//
|
|
|
|
// Any errors are thrown on ErrorResult.
|
|
|
|
static void ProcessURL(nsACString& aUrl, bool* aSchemeValidOut,
|
2015-06-17 03:39:05 +03:00
|
|
|
nsACString* aUrlWithoutQueryOut,
|
|
|
|
nsACString* aUrlQueryOut, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
private:
|
2020-05-11 15:13:48 +03:00
|
|
|
void CheckAndSetBodyUsed(JSContext* aCx, Request& aRequest,
|
2017-08-11 04:04:55 +03:00
|
|
|
BodyAction aBodyAction, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-05-11 15:10:53 +03:00
|
|
|
SafeRefPtr<InternalRequest> ToInternalRequest(const nsAString& aIn,
|
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void SerializeCacheStream(
|
2019-03-21 14:09:44 +03:00
|
|
|
nsIInputStream* aStream, Maybe<CacheReadStream>* aStreamOut,
|
2016-05-15 20:32:09 +03:00
|
|
|
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
|
2015-03-02 16:20:00 +03:00
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-15 20:32:09 +03:00
|
|
|
void SerializeSendStream(nsIInputStream* aStream,
|
|
|
|
CacheReadStream& aReadStreamOut, ErrorResult& aRv);
|
2015-03-02 16:20:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_cache_TypesUtils_h
|