From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- dom/cache/Cache.cpp | 43 ++++++++++++++++++++----------------------- dom/cache/Cache.h | 18 +++++++++--------- dom/cache/CacheStorage.cpp | 2 +- dom/cache/CacheStorage.h | 2 +- dom/cache/CacheTypes.ipdlh | 2 +- dom/cache/DBSchema.cpp | 9 +++++---- dom/cache/FileUtils.cpp | 2 +- dom/cache/StreamList.cpp | 11 +++++++++++ dom/cache/TypeUtils.cpp | 16 ++++++++-------- dom/cache/TypeUtils.h | 10 +++++----- 10 files changed, 62 insertions(+), 53 deletions(-) (limited to 'dom/cache') diff --git a/dom/cache/Cache.cpp b/dom/cache/Cache.cpp index 3f84e08e66..78480022c1 100644 --- a/dom/cache/Cache.cpp +++ b/dom/cache/Cache.cpp @@ -34,12 +34,11 @@ namespace { enum class PutStatusPolicy { Default, RequireOK }; -bool IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv) { +bool IsValidPutRequestURL(const nsACString& aUrl, ErrorResult& aRv) { bool validScheme = false; // make a copy because ProcessURL strips the fragmet - NS_ConvertUTF16toUTF8 url(aUrl); - + nsAutoCString url(aUrl); TypeUtils::ProcessURL(url, &validScheme, nullptr, nullptr, aRv); if (aRv.Failed()) { return false; @@ -47,8 +46,7 @@ bool IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv) { if (!validScheme) { // `url` has been modified, so don't use it here. - aRv.ThrowTypeError("Request", - NS_ConvertUTF16toUTF8(aUrl)); + aRv.ThrowTypeError("Request", aUrl); return false; } @@ -66,7 +64,7 @@ static bool IsValidPutRequestMethod(const Request& aRequest, ErrorResult& aRv) { return true; } -static bool IsValidPutRequestMethod(const RequestOrUSVString& aRequest, +static bool IsValidPutRequestMethod(const RequestOrUTF8String& aRequest, ErrorResult& aRv) { // If the provided request is a string URL, then it will default to // a valid http method automatically. @@ -81,12 +79,10 @@ static bool IsValidPutResponseStatus(Response& aResponse, ErrorResult& aRv) { if ((aPolicy == PutStatusPolicy::RequireOK && !aResponse.Ok()) || aResponse.Status() == 206) { - nsAutoString url; + nsAutoCString url; aResponse.GetUrl(url); - aRv.ThrowTypeError( - GetEnumString(aResponse.Type()), IntToCString(aResponse.Status()), - NS_ConvertUTF16toUTF8(url)); + GetEnumString(aResponse.Type()), IntToCString(aResponse.Status()), url); return false; } @@ -228,7 +224,7 @@ Cache::Cache(nsIGlobalObject* aGlobal, CacheChild* aActor, Namespace aNamespace) } already_AddRefed Cache::Match(JSContext* aCx, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv) { if (NS_WARN_IF(!mActor)) { @@ -259,7 +255,7 @@ already_AddRefed Cache::Match(JSContext* aCx, } already_AddRefed Cache::MatchAll( - JSContext* aCx, const Optional& aRequest, + JSContext* aCx, const Optional& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv) { if (NS_WARN_IF(!mActor)) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -291,7 +287,7 @@ already_AddRefed Cache::MatchAll( } already_AddRefed Cache::Add(JSContext* aContext, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, CallerType aCallerType, ErrorResult& aRv) { if (NS_WARN_IF(!mActor)) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -315,7 +311,7 @@ already_AddRefed Cache::Add(JSContext* aContext, return nullptr; } - nsAutoString url; + nsAutoCString url; request->GetUrl(url); if (NS_WARN_IF(!IsValidPutRequestURL(url, aRv))) { return nullptr; @@ -326,7 +322,8 @@ already_AddRefed Cache::Add(JSContext* aContext, } already_AddRefed Cache::AddAll( - JSContext* aContext, const Sequence& aRequestList, + JSContext* aContext, + const Sequence& aRequestList, CallerType aCallerType, ErrorResult& aRv) { if (NS_WARN_IF(!mActor)) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -340,7 +337,7 @@ already_AddRefed Cache::AddAll( nsTArray> requestList(aRequestList.Length()); for (uint32_t i = 0; i < aRequestList.Length(); ++i) { - RequestOrUSVString requestOrString; + RequestOrUTF8String requestOrString; if (aRequestList[i].IsRequest()) { requestOrString.SetAsRequest() = aRequestList[i].GetAsRequest(); @@ -349,8 +346,8 @@ already_AddRefed Cache::AddAll( return nullptr; } } else { - requestOrString.SetAsUSVString().ShareOrDependUpon( - aRequestList[i].GetAsUSVString()); + requestOrString.SetAsUTF8String().ShareOrDependUpon( + aRequestList[i].GetAsUTF8String()); } RootedDictionary requestInit(aContext); @@ -360,7 +357,7 @@ already_AddRefed Cache::AddAll( return nullptr; } - nsAutoString url; + nsAutoCString url; request->GetUrl(url); if (NS_WARN_IF(!IsValidPutRequestURL(url, aRv))) { return nullptr; @@ -373,7 +370,7 @@ already_AddRefed Cache::AddAll( } already_AddRefed Cache::Put(JSContext* aCx, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, Response& aResponse, ErrorResult& aRv) { if (NS_WARN_IF(!mActor)) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -418,7 +415,7 @@ already_AddRefed Cache::Put(JSContext* aCx, } already_AddRefed Cache::Delete(JSContext* aCx, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv) { if (NS_WARN_IF(!mActor)) { @@ -448,7 +445,7 @@ already_AddRefed Cache::Delete(JSContext* aCx, } already_AddRefed Cache::Keys( - JSContext* aCx, const Optional& aRequest, + JSContext* aCx, const Optional& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv) { if (NS_WARN_IF(!mActor)) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -552,7 +549,7 @@ already_AddRefed Cache::AddAll( // future once fetch supports it. for (uint32_t i = 0; i < aRequestList.Length(); ++i) { - RequestOrUSVString requestOrString; + RequestOrUTF8String requestOrString; requestOrString.SetAsRequest() = aRequestList[i].unsafeGetRawPtr(); RootedDictionary requestInit(aGlobal.Context()); RefPtr fetch = diff --git a/dom/cache/Cache.h b/dom/cache/Cache.h index 02ccb557f7..35b133357b 100644 --- a/dom/cache/Cache.h +++ b/dom/cache/Cache.h @@ -22,10 +22,10 @@ class ErrorResult; namespace dom { -class OwningRequestOrUSVString; +class OwningRequestOrUTF8String; class Promise; struct CacheQueryOptions; -class RequestOrUSVString; +class RequestOrUTF8String; class Response; template class Optional; @@ -46,27 +46,27 @@ class Cache final : public nsISupports, // webidl interface methods already_AddRefed Match(JSContext* aCx, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv); already_AddRefed MatchAll( - JSContext* aCx, const Optional& aRequest, + JSContext* aCx, const Optional& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv); already_AddRefed Add(JSContext* aContext, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, CallerType aCallerType, ErrorResult& aRv); already_AddRefed AddAll( - JSContext* aContext, const Sequence& aRequests, + JSContext* aContext, const Sequence& aRequests, CallerType aCallerType, ErrorResult& aRv); already_AddRefed Put(JSContext* aCx, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, Response& aResponse, ErrorResult& aRv); already_AddRefed Delete(JSContext* aCx, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, const CacheQueryOptions& aOptions, ErrorResult& aRv); already_AddRefed Keys(JSContext* aCx, - const Optional& aRequest, + const Optional& aRequest, const CacheQueryOptions& aParams, ErrorResult& aRv); diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index b5647ba791..f41966a5e3 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -298,7 +298,7 @@ CacheStorage::CacheStorage(nsresult aFailureResult) } already_AddRefed CacheStorage::Match( - JSContext* aCx, const RequestOrUSVString& aRequest, + JSContext* aCx, const RequestOrUTF8String& aRequest, const MultiCacheQueryOptions& aOptions, ErrorResult& aRv) { NS_ASSERT_OWNINGTHREAD(CacheStorage); diff --git a/dom/cache/CacheStorage.h b/dom/cache/CacheStorage.h index 306c7cccd4..3bfbece08b 100644 --- a/dom/cache/CacheStorage.h +++ b/dom/cache/CacheStorage.h @@ -56,7 +56,7 @@ class CacheStorage final : public nsISupports, // webidl interface methods already_AddRefed Match(JSContext* aCx, - const RequestOrUSVString& aRequest, + const RequestOrUTF8String& aRequest, const MultiCacheQueryOptions& aOptions, ErrorResult& aRv); already_AddRefed Has(const nsAString& aKey, ErrorResult& aRv); diff --git a/dom/cache/CacheTypes.ipdlh b/dom/cache/CacheTypes.ipdlh index 67131ed86a..5a0bafc737 100644 --- a/dom/cache/CacheTypes.ipdlh +++ b/dom/cache/CacheTypes.ipdlh @@ -59,7 +59,7 @@ struct CacheRequest nsCString urlFragment; HeadersEntry[] headers; HeadersGuardEnum headersGuard; - nsString referrer; + nsCString referrer; ReferrerPolicy referrerPolicy; RequestMode mode; RequestCredentials credentials; diff --git a/dom/cache/DBSchema.cpp b/dom/cache/DBSchema.cpp index 0c2c9cd4fb..390c1a9fd6 100644 --- a/dom/cache/DBSchema.cpp +++ b/dom/cache/DBSchema.cpp @@ -1646,7 +1646,7 @@ nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId, QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0)); }())); - MOZ_DIAGNOSTIC_ASSERT(refcount >= aCount); + MOZ_ASSERT_DEBUG_OR_FUZZING(refcount >= aCount); // Next, calculate the new refcount int32_t newCount = refcount - aCount; @@ -1794,8 +1794,8 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId, QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("request_url_fragment"_ns, aRequest.urlFragment()))); - QM_TRY(MOZ_TO_RESULT( - state->BindStringByName("request_referrer"_ns, aRequest.referrer()))); + QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("request_referrer"_ns, + aRequest.referrer()))); QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName( "request_referrer_policy"_ns, @@ -2208,7 +2208,8 @@ Result ReadRequest(mozIStorageConnection& aConn, MOZ_TO_RESULT(state->GetUTF8String(2, savedRequest.mValue.urlQuery()))); QM_TRY(MOZ_TO_RESULT( state->GetUTF8String(3, savedRequest.mValue.urlFragment()))); - QM_TRY(MOZ_TO_RESULT(state->GetString(4, savedRequest.mValue.referrer()))); + QM_TRY( + MOZ_TO_RESULT(state->GetUTF8String(4, savedRequest.mValue.referrer()))); QM_TRY_INSPECT(const int32_t& referrerPolicy, MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 5)); diff --git a/dom/cache/FileUtils.cpp b/dom/cache/FileUtils.cpp index cd99591c91..4e84455d73 100644 --- a/dom/cache/FileUtils.cpp +++ b/dom/cache/FileUtils.cpp @@ -34,7 +34,7 @@ namespace mozilla::dom::cache { -static_assert(SNAPPY_VERSION == 0x010109); +static_assert(SNAPPY_VERSION == 0x010200); using mozilla::dom::quota::Client; using mozilla::dom::quota::CloneFileAndAppend; diff --git a/dom/cache/StreamList.cpp b/dom/cache/StreamList.cpp index b72b7f95d5..cbce695b60 100644 --- a/dom/cache/StreamList.cpp +++ b/dom/cache/StreamList.cpp @@ -85,6 +85,12 @@ void StreamList::Add(const nsID& aId, nsCOMPtr&& aStream) { // All streams should be added on IO thread before we set the stream // control on the owning IPC thread. MOZ_DIAGNOSTIC_ASSERT(!mStreamControl); + + // Removal of the stream will be triggered when the stream is closed, + // which happens only once, so let's ensure nobody adds us twice. + MOZ_ASSERT_DEBUG_OR_FUZZING( + std::find_if(mList.begin(), mList.end(), MatchById(aId)) == mList.end()); + mList.EmplaceBack(aId, std::move(aStream)); } @@ -93,6 +99,9 @@ already_AddRefed StreamList::Extract(const nsID& aId) { const auto it = std::find_if(mList.begin(), mList.end(), MatchById(aId)); + // Note that if the stream has not been opened with OpenMode::Eager we will + // find it nullptr here and it will have to be opened by the consumer. + return it != mList.end() ? it->mStream.forget() : nullptr; } @@ -101,6 +110,7 @@ void StreamList::NoteClosed(const nsID& aId) { const auto it = std::find_if(mList.begin(), mList.end(), MatchById(aId)); if (it != mList.end()) { + MOZ_ASSERT(!it->mStream, "We expect to find mStream already extracted."); mList.RemoveElementAt(it); mManager->ReleaseBodyId(aId); } @@ -124,6 +134,7 @@ void StreamList::NoteClosedAll() { void StreamList::CloseAll() { NS_ASSERT_OWNINGTHREAD(StreamList); + if (mStreamControl && mStreamControl->CanSend()) { auto* streamControl = std::exchange(mStreamControl, nullptr); diff --git a/dom/cache/TypeUtils.cpp b/dom/cache/TypeUtils.cpp index 5e42f0a079..818b1cf93b 100644 --- a/dom/cache/TypeUtils.cpp +++ b/dom/cache/TypeUtils.cpp @@ -74,7 +74,7 @@ nsTArray ToHeadersEntryList(InternalHeaders* aHeaders) { } // namespace SafeRefPtr TypeUtils::ToInternalRequest( - JSContext* aCx, const RequestOrUSVString& aIn, BodyAction aBodyAction, + JSContext* aCx, const RequestOrUTF8String& aIn, BodyAction aBodyAction, ErrorResult& aRv) { if (aIn.IsRequest()) { Request& request = aIn.GetAsRequest(); @@ -89,12 +89,12 @@ SafeRefPtr TypeUtils::ToInternalRequest( return request.GetInternalRequest(); } - return ToInternalRequest(aIn.GetAsUSVString(), aRv); + return ToInternalRequest(aIn.GetAsUTF8String(), aRv); } SafeRefPtr TypeUtils::ToInternalRequest( - JSContext* aCx, const OwningRequestOrUSVString& aIn, BodyAction aBodyAction, - ErrorResult& aRv) { + JSContext* aCx, const OwningRequestOrUTF8String& aIn, + BodyAction aBodyAction, ErrorResult& aRv) { if (aIn.IsRequest()) { Request& request = aIn.GetAsRequest(); @@ -108,7 +108,7 @@ SafeRefPtr TypeUtils::ToInternalRequest( return request.GetInternalRequest(); } - return ToInternalRequest(aIn.GetAsUSVString(), aRv); + return ToInternalRequest(aIn.GetAsUTF8String(), aRv); } void TypeUtils::ToCacheRequest(CacheRequest& aOut, const InternalRequest& aIn, @@ -447,10 +447,10 @@ void TypeUtils::CheckAndSetBodyUsed(JSContext* aCx, Request& aRequest, } } -SafeRefPtr TypeUtils::ToInternalRequest(const nsAString& aIn, +SafeRefPtr TypeUtils::ToInternalRequest(const nsACString& aIn, ErrorResult& aRv) { - RequestOrUSVString requestOrString; - requestOrString.SetAsUSVString().ShareOrDependUpon(aIn); + RequestOrUTF8String requestOrString; + requestOrString.SetAsUTF8String().ShareOrDependUpon(aIn); // Re-create a GlobalObject stack object so we can use webidl Constructors. AutoJSAPI jsapi; diff --git a/dom/cache/TypeUtils.h b/dom/cache/TypeUtils.h index 5342ea3d7e..051b12cbbf 100644 --- a/dom/cache/TypeUtils.h +++ b/dom/cache/TypeUtils.h @@ -30,9 +30,9 @@ struct MultiCacheQueryOptions; class InternalHeaders; class InternalRequest; class InternalResponse; -class OwningRequestOrUSVString; +class OwningRequestOrUTF8String; class Request; -class RequestOrUSVString; +class RequestOrUTF8String; class Response; namespace cache { @@ -64,12 +64,12 @@ class TypeUtils { virtual mozilla::ipc::PBackgroundChild* GetIPCManager() = 0; SafeRefPtr ToInternalRequest(JSContext* aCx, - const RequestOrUSVString& aIn, + const RequestOrUTF8String& aIn, BodyAction aBodyAction, ErrorResult& aRv); SafeRefPtr ToInternalRequest( - JSContext* aCx, const OwningRequestOrUSVString& aIn, + JSContext* aCx, const OwningRequestOrUTF8String& aIn, BodyAction aBodyAction, ErrorResult& aRv); void ToCacheRequest(CacheRequest& aOut, const InternalRequest& aIn, @@ -120,7 +120,7 @@ class TypeUtils { void CheckAndSetBodyUsed(JSContext* aCx, Request& aRequest, BodyAction aBodyAction, ErrorResult& aRv); - SafeRefPtr ToInternalRequest(const nsAString& aIn, + SafeRefPtr ToInternalRequest(const nsACString& aIn, ErrorResult& aRv); void SerializeCacheStream(nsIInputStream* aStream, -- cgit v1.2.3