From 9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 22:18:47 +0200 Subject: moebius#140: Fix: Fetch - headers should sort and combine https://github.com/MoonchildProductions/moebius/pull/140 --- dom/fetch/InternalHeaders.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ dom/fetch/InternalHeaders.h | 31 +++++++++++++++++------ 2 files changed, 81 insertions(+), 8 deletions(-) (limited to 'dom/fetch') diff --git a/dom/fetch/InternalHeaders.cpp b/dom/fetch/InternalHeaders.cpp index e81863173..11585615e 100644 --- a/dom/fetch/InternalHeaders.cpp +++ b/dom/fetch/InternalHeaders.cpp @@ -21,12 +21,14 @@ InternalHeaders::InternalHeaders(const nsTArray&& aHeaders, HeadersGuardEnum aGuard) : mGuard(aGuard) , mList(aHeaders) + , mListDirty(true) { } InternalHeaders::InternalHeaders(const nsTArray& aHeadersEntryList, HeadersGuardEnum aGuard) : mGuard(aGuard) + , mListDirty(true) { for (const HeadersEntry& headersEntry : aHeadersEntryList) { mList.AppendElement(Entry(headersEntry.name(), headersEntry.value())); @@ -56,6 +58,8 @@ InternalHeaders::Append(const nsACString& aName, const nsACString& aValue, return; } + SetListDirty(); + mList.AppendElement(Entry(lowerName, aValue)); } @@ -69,6 +73,8 @@ InternalHeaders::Delete(const nsACString& aName, ErrorResult& aRv) return; } + SetListDirty(); + // remove in reverse order to minimize copying for (int32_t i = mList.Length() - 1; i >= 0; --i) { if (lowerName == mList[i].mName) { @@ -155,6 +161,8 @@ InternalHeaders::Set(const nsACString& aName, const nsACString& aValue, ErrorRes return; } + SetListDirty(); + int32_t firstIndex = INT32_MAX; // remove in reverse order to minimize copying @@ -177,6 +185,7 @@ InternalHeaders::Set(const nsACString& aName, const nsACString& aValue, ErrorRes void InternalHeaders::Clear() { + SetListDirty(); mList.Clear(); } @@ -419,5 +428,54 @@ InternalHeaders::GetUnsafeHeaders(nsTArray& aNames) const } } +void +InternalHeaders::MaybeSortList() +{ + class Comparator { + public: + bool Equals(const Entry& aA, const Entry& aB) const + { + return aA.mName == aB.mName; + } + + bool LessThan(const Entry& aA, const Entry& aB) const + { + return aA.mName < aB.mName; + } + }; + + if (!mListDirty) { + return; + } + + mListDirty = false; + + Comparator comparator; + + mSortedList.Clear(); + for (const Entry& entry : mList) { + bool found = false; + for (Entry& sortedEntry : mSortedList) { + if (sortedEntry.mName == entry.mName) { + sortedEntry.mValue += ", "; + sortedEntry.mValue += entry.mValue; + found = true; + break; + } + } + + if (!found) { + mSortedList.InsertElementSorted(entry, comparator); + } + } +} + +void +InternalHeaders::SetListDirty() +{ + mSortedList.Clear(); + mListDirty = true; +} + } // namespace dom } // namespace mozilla diff --git a/dom/fetch/InternalHeaders.h b/dom/fetch/InternalHeaders.h index e47066669..9a6d6dae7 100644 --- a/dom/fetch/InternalHeaders.h +++ b/dom/fetch/InternalHeaders.h @@ -45,14 +45,23 @@ private: HeadersGuardEnum mGuard; nsTArray mList; + nsTArray mSortedList; + + // This boolean is set to true at any writing operation to mList. It's set to + // false when mSortedList is regenerated. This happens when the header is + // iterated. + bool mListDirty; + public: explicit InternalHeaders(HeadersGuardEnum aGuard = HeadersGuardEnum::None) : mGuard(aGuard) + , mListDirty(false) { } explicit InternalHeaders(const InternalHeaders& aOther) : mGuard(HeadersGuardEnum::None) + , mListDirty(true) { ErrorResult result; Fill(aOther, result); @@ -79,19 +88,22 @@ public: bool Has(const nsACString& aName, ErrorResult& aRv) const; void Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv); - uint32_t GetIterableLength() const + uint32_t GetIterableLength() { - return mList.Length(); + MaybeSortList(); + return mSortedList.Length(); } - const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex) const + const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex) { - MOZ_ASSERT(aIndex < mList.Length()); - return NS_ConvertASCIItoUTF16(mList[aIndex].mName); + MaybeSortList(); + MOZ_ASSERT(aIndex < mSortedList.Length()); + return NS_ConvertASCIItoUTF16(mSortedList[aIndex].mName); } - const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex) const + const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex) { - MOZ_ASSERT(aIndex < mList.Length()); - return NS_ConvertASCIItoUTF16(mList[aIndex].mValue); + MaybeSortList(); + MOZ_ASSERT(aIndex < mSortedList.Length()); + return NS_ConvertASCIItoUTF16(mSortedList[aIndex].mValue); } void Clear(); @@ -152,6 +164,9 @@ private: const nsACString& aValue); static bool IsRevalidationHeader(const nsACString& aName); + + void MaybeSortList(); + void SetListDirty(); }; } // namespace dom -- cgit v1.2.3 From 27e021136b6e58143f95ff3df37b58ed699e8b06 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Tue, 24 Apr 2018 11:47:08 +0200 Subject: moebius#312: DOM - Fix incorrect TypeError: Response body is given with a null body status https://github.com/MoonchildProductions/moebius/issues/312 --- dom/fetch/Response.cpp | 8 ++++---- dom/fetch/Response.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'dom/fetch') diff --git a/dom/fetch/Response.cpp b/dom/fetch/Response.cpp index a76071bf8..3b3ada6d3 100644 --- a/dom/fetch/Response.cpp +++ b/dom/fetch/Response.cpp @@ -104,7 +104,7 @@ Response::Redirect(const GlobalObject& aGlobal, const nsAString& aUrl, return nullptr; } - Optional body; + Optional> body; ResponseInit init; init.mStatus = aStatus; RefPtr r = Response::Constructor(aGlobal, body, init, aRv); @@ -125,7 +125,7 @@ Response::Redirect(const GlobalObject& aGlobal, const nsAString& aUrl, /*static*/ already_AddRefed Response::Constructor(const GlobalObject& aGlobal, - const Optional& aBody, + const Optional>& aBody, const ResponseInit& aInit, ErrorResult& aRv) { nsCOMPtr global = do_QueryInterface(aGlobal.GetAsSupports()); @@ -191,7 +191,7 @@ Response::Constructor(const GlobalObject& aGlobal, } } - if (aBody.WasPassed()) { + if (aBody.WasPassed() && !aBody.Value().IsNull()) { if (aInit.mStatus == 204 || aInit.mStatus == 205 || aInit.mStatus == 304) { aRv.ThrowTypeError(); return nullptr; @@ -200,7 +200,7 @@ Response::Constructor(const GlobalObject& aGlobal, nsCOMPtr bodyStream; nsCString contentType; uint64_t bodySize = 0; - aRv = ExtractByteStreamFromBody(aBody.Value(), + aRv = ExtractByteStreamFromBody(aBody.Value().Value(), getter_AddRefs(bodyStream), contentType, bodySize); diff --git a/dom/fetch/Response.h b/dom/fetch/Response.h index 64b3c5f45..de367bef6 100644 --- a/dom/fetch/Response.h +++ b/dom/fetch/Response.h @@ -114,7 +114,7 @@ public: static already_AddRefed Constructor(const GlobalObject& aGlobal, - const Optional& aBody, + const Optional>& aBody, const ResponseInit& aInit, ErrorResult& rv); nsIGlobalObject* GetParentObject() const -- cgit v1.2.3 From e03ae4be5c032f45e15908834444a6753e5e6441 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 26 May 2018 17:32:31 +0200 Subject: Bug 1394399 - Default Request.credentials to "same-origin" instead of "omit" Issue #389 --- dom/fetch/Request.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dom/fetch') diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index bc17afae3..c119a503e 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -327,7 +327,7 @@ Request::Constructor(const GlobalObject& aGlobal, RequestCache fallbackCache = RequestCache::EndGuard_; if (aInput.IsUSVString()) { fallbackMode = RequestMode::Cors; - fallbackCredentials = RequestCredentials::Omit; + fallbackCredentials = RequestCredentials::Same_origin; fallbackCache = RequestCache::Default; } -- cgit v1.2.3 From 07ee0792c9664d649fae8ae530b27462ee45f530 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 17 Jun 2018 09:35:48 +0200 Subject: Bug 1398229 - Save-link-as feature should use the loading principal - implementation of nsIContentPolicy.TYPE_SAVE_AS_DOWNLOAD --- dom/fetch/InternalRequest.cpp | 3 +++ dom/fetch/InternalRequest.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'dom/fetch') diff --git a/dom/fetch/InternalRequest.cpp b/dom/fetch/InternalRequest.cpp index 85feabde3..b2631da6a 100644 --- a/dom/fetch/InternalRequest.cpp +++ b/dom/fetch/InternalRequest.cpp @@ -320,6 +320,9 @@ InternalRequest::MapContentPolicyTypeToRequestContext(nsContentPolicyType aConte case nsIContentPolicy::TYPE_WEB_MANIFEST: context = RequestContext::Manifest; break; + case nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD: + context = RequestContext::Internal; + break; default: MOZ_ASSERT(false, "Unhandled nsContentPolicyType value"); break; diff --git a/dom/fetch/InternalRequest.h b/dom/fetch/InternalRequest.h index 84ee0bf69..966490675 100644 --- a/dom/fetch/InternalRequest.h +++ b/dom/fetch/InternalRequest.h @@ -53,7 +53,7 @@ namespace dom { * image | TYPE_INTERNAL_IMAGE, TYPE_INTERNAL_IMAGE_PRELOAD, TYPE_INTERNAL_IMAGE_FAVICON * imageset | TYPE_IMAGESET * import | Not supported by Gecko - * internal | TYPE_DOCUMENT, TYPE_XBL, TYPE_OTHER + * internal | TYPE_DOCUMENT, TYPE_XBL, TYPE_OTHER, TYPE_SAVEAS_DOWNLOAD * location | * manifest | TYPE_WEB_MANIFEST * object | TYPE_INTERNAL_OBJECT -- cgit v1.2.3 From a80267e9e88b3dcebf7f8f1f6f10931a99ddf2ca Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 5 Jul 2018 13:04:44 +0200 Subject: Bug 604026 - Sync event loops in workers should be created only if compatible with the worker shutdown status --- dom/fetch/Request.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dom/fetch') diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index c119a503e..d3836cda1 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -403,7 +403,7 @@ Request::Constructor(const GlobalObject& aGlobal, // this work in a single sync loop. RefPtr checker = new ReferrerSameOriginChecker(worker, referrerURL, rv); - checker->Dispatch(aRv); + checker->Dispatch(Terminating, aRv); if (aRv.Failed() || NS_FAILED(rv)) { aRv.ThrowTypeError(referrer, worker->GetLocationInfo().mOrigin); -- cgit v1.2.3 From bfeac5c28ddb60531f25d7d99d0299a5161b9a8e Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 5 Jul 2018 13:08:32 +0200 Subject: Bug 1298823 - Fix Request constructor - with "mode: navigate" --- dom/fetch/Request.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'dom/fetch') diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index d3836cda1..7ca5b43c4 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -338,8 +338,7 @@ Request::Constructor(const GlobalObject& aGlobal, if (mode == RequestMode::Navigate || (aInit.IsAnyMemberPresent() && request->Mode() == RequestMode::Navigate)) { - aRv.ThrowTypeError(NS_LITERAL_STRING("navigate")); - return nullptr; + mode = RequestMode::Same_origin; } if (aInit.IsAnyMemberPresent()) { @@ -374,11 +373,7 @@ Request::Constructor(const GlobalObject& aGlobal, nsresult rv = principal->CheckMayLoad(uri, /* report */ false, /* allowIfInheritsPrincipal */ false); if (NS_FAILED(rv)) { - nsAutoCString globalOrigin; - principal->GetOrigin(globalOrigin); - aRv.ThrowTypeError(referrer, - NS_ConvertUTF8toUTF16(globalOrigin)); - return nullptr; + referrerURL.AssignLiteral(kFETCH_CLIENT_REFERRER_STR); } } } @@ -403,11 +398,10 @@ Request::Constructor(const GlobalObject& aGlobal, // this work in a single sync loop. RefPtr checker = new ReferrerSameOriginChecker(worker, referrerURL, rv); - checker->Dispatch(Terminating, aRv); - if (aRv.Failed() || NS_FAILED(rv)) { - aRv.ThrowTypeError(referrer, - worker->GetLocationInfo().mOrigin); - return nullptr; + IgnoredErrorResult error; + checker->Dispatch(Terminating, error); + if (error.Failed() || NS_FAILED(rv)) { + referrerURL.AssignLiteral(kFETCH_CLIENT_REFERRER_STR); } } } -- cgit v1.2.3