summaryrefslogtreecommitdiffstats
path: root/dom/cache
diff options
context:
space:
mode:
Diffstat (limited to 'dom/cache')
-rw-r--r--dom/cache/Cache.cpp43
-rw-r--r--dom/cache/Cache.h18
-rw-r--r--dom/cache/CacheStorage.cpp2
-rw-r--r--dom/cache/CacheStorage.h2
-rw-r--r--dom/cache/CacheTypes.ipdlh2
-rw-r--r--dom/cache/DBSchema.cpp9
-rw-r--r--dom/cache/FileUtils.cpp2
-rw-r--r--dom/cache/StreamList.cpp11
-rw-r--r--dom/cache/TypeUtils.cpp16
-rw-r--r--dom/cache/TypeUtils.h10
10 files changed, 62 insertions, 53 deletions
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<MSG_INVALID_URL_SCHEME>("Request",
- NS_ConvertUTF16toUTF8(aUrl));
+ aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("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<MSG_CACHE_ADD_FAILED_RESPONSE>(
- 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<Promise> 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<Promise> Cache::Match(JSContext* aCx,
}
already_AddRefed<Promise> Cache::MatchAll(
- JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
+ JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
const CacheQueryOptions& aOptions, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@@ -291,7 +287,7 @@ already_AddRefed<Promise> Cache::MatchAll(
}
already_AddRefed<Promise> 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<Promise> 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<Promise> Cache::Add(JSContext* aContext,
}
already_AddRefed<Promise> Cache::AddAll(
- JSContext* aContext, const Sequence<OwningRequestOrUSVString>& aRequestList,
+ JSContext* aContext,
+ const Sequence<OwningRequestOrUTF8String>& aRequestList,
CallerType aCallerType, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@@ -340,7 +337,7 @@ already_AddRefed<Promise> Cache::AddAll(
nsTArray<SafeRefPtr<Request>> 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<Promise> Cache::AddAll(
return nullptr;
}
} else {
- requestOrString.SetAsUSVString().ShareOrDependUpon(
- aRequestList[i].GetAsUSVString());
+ requestOrString.SetAsUTF8String().ShareOrDependUpon(
+ aRequestList[i].GetAsUTF8String());
}
RootedDictionary<RequestInit> requestInit(aContext);
@@ -360,7 +357,7 @@ already_AddRefed<Promise> 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<Promise> Cache::AddAll(
}
already_AddRefed<Promise> 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<Promise> Cache::Put(JSContext* aCx,
}
already_AddRefed<Promise> 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<Promise> Cache::Delete(JSContext* aCx,
}
already_AddRefed<Promise> Cache::Keys(
- JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
+ JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
const CacheQueryOptions& aOptions, ErrorResult& aRv) {
if (NS_WARN_IF(!mActor)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@@ -552,7 +549,7 @@ already_AddRefed<Promise> 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> requestInit(aGlobal.Context());
RefPtr<Promise> 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 <typename T>
class Optional;
@@ -46,27 +46,27 @@ class Cache final : public nsISupports,
// webidl interface methods
already_AddRefed<Promise> Match(JSContext* aCx,
- const RequestOrUSVString& aRequest,
+ const RequestOrUTF8String& aRequest,
const CacheQueryOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> MatchAll(
- JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
+ JSContext* aCx, const Optional<RequestOrUTF8String>& aRequest,
const CacheQueryOptions& aOptions, ErrorResult& aRv);
already_AddRefed<Promise> Add(JSContext* aContext,
- const RequestOrUSVString& aRequest,
+ const RequestOrUTF8String& aRequest,
CallerType aCallerType, ErrorResult& aRv);
already_AddRefed<Promise> AddAll(
- JSContext* aContext, const Sequence<OwningRequestOrUSVString>& aRequests,
+ JSContext* aContext, const Sequence<OwningRequestOrUTF8String>& aRequests,
CallerType aCallerType, ErrorResult& aRv);
already_AddRefed<Promise> Put(JSContext* aCx,
- const RequestOrUSVString& aRequest,
+ const RequestOrUTF8String& aRequest,
Response& aResponse, ErrorResult& aRv);
already_AddRefed<Promise> Delete(JSContext* aCx,
- const RequestOrUSVString& aRequest,
+ const RequestOrUTF8String& aRequest,
const CacheQueryOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> Keys(JSContext* aCx,
- const Optional<RequestOrUSVString>& aRequest,
+ const Optional<RequestOrUTF8String>& 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<Promise> 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<Promise> Match(JSContext* aCx,
- const RequestOrUSVString& aRequest,
+ const RequestOrUTF8String& aRequest,
const MultiCacheQueryOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> 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<SavedRequest, nsresult> 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<nsIInputStream>&& 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<nsIInputStream> 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<HeadersEntry> ToHeadersEntryList(InternalHeaders* aHeaders) {
} // namespace
SafeRefPtr<InternalRequest> 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<InternalRequest> TypeUtils::ToInternalRequest(
return request.GetInternalRequest();
}
- return ToInternalRequest(aIn.GetAsUSVString(), aRv);
+ return ToInternalRequest(aIn.GetAsUTF8String(), aRv);
}
SafeRefPtr<InternalRequest> 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<InternalRequest> 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<InternalRequest> TypeUtils::ToInternalRequest(const nsAString& aIn,
+SafeRefPtr<InternalRequest> 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<InternalRequest> ToInternalRequest(JSContext* aCx,
- const RequestOrUSVString& aIn,
+ const RequestOrUTF8String& aIn,
BodyAction aBodyAction,
ErrorResult& aRv);
SafeRefPtr<InternalRequest> 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<InternalRequest> ToInternalRequest(const nsAString& aIn,
+ SafeRefPtr<InternalRequest> ToInternalRequest(const nsACString& aIn,
ErrorResult& aRv);
void SerializeCacheStream(nsIInputStream* aStream,