Bug 1486445 - P1 - Propagate the sw internally redirected URL to fetching request; r=asuth

Bug 1222008 didn't propagate a sw redirected URL to outer response properly. To
fix that this patch mainly make a redirecting request be overwritten while it's
redirected by a service worker. This patch also add a private setter function
for InternalRequest and a public checking function to avoid that function from
being used widely.

Differential Revision: https://phabricator.services.mozilla.com/D4762

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Tung 2018-09-12 12:44:30 +00:00
Родитель 6f847f695a
Коммит b98b2f6c82
2 изменённых файлов: 49 добавлений и 19 удалений

Просмотреть файл

@ -1296,7 +1296,6 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
// However, ignore internal redirects here. We don't want to flip
// Response.redirected to true if an internal redirect occurs. These
// should be transparent to script.
if (!(aFlags & nsIChannelEventSink::REDIRECT_INTERNAL)) {
nsCOMPtr<nsIURI> uri;
MOZ_ALWAYS_SUCCEEDS(aNewChannel->GetURI(getter_AddRefs(uri)));
@ -1316,7 +1315,12 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
return rv;
}
if (!(aFlags & nsIChannelEventSink::REDIRECT_INTERNAL)) {
mRequest->AddURL(spec, fragment);
} else {
// Overwrite the URL only when the request is redirected by a service
// worker.
mRequest->SetURLForInternalRedirect(aFlags, spec, fragment);
}
NS_ConvertUTF8toUTF16 tRPHeaderValue(tRPHeaderCValue);

Просмотреть файл

@ -133,6 +133,20 @@ public:
return mURLList.LastElement();
}
// A safe guard for ensuring that request's URL is only allowed to be set in a
// sw internal redirect.
void
SetURLForInternalRedirect(const uint32_t aFlag,
const nsACString& aURL,
const nsACString& aFragment)
{
// Only check in debug build to prevent it from being used unexpectedly.
MOZ_ASSERT(aFlag & nsIChannelEventSink::REDIRECT_INTERNAL);
return SetURL(aURL, aFragment);
}
// AddURL should append the url into url list.
// Normally we strip the fragment from the URL in Request::Constructor and
// pass the fragment as the second argument into it.
@ -578,6 +592,18 @@ private:
static bool
IsWorkerContentPolicy(nsContentPolicyType aContentPolicyType);
// It should only be called while there is a service-worker-internal-redirect.
void
SetURL(const nsACString& aURL, const nsACString& aFragment)
{
MOZ_ASSERT(!aURL.IsEmpty());
MOZ_ASSERT(!aURL.Contains('#'));
MOZ_ASSERT(mURLList.Length() > 0);
mURLList.LastElement() = aURL;
mFragment.Assign(aFragment);
}
nsCString mMethod;
// mURLList: a list of one or more fetch URLs
nsTArray<nsCString> mURLList;