Commit 8c7c00a6 authored by Asami Doi's avatar Asami Doi Committed by Chromium LUCI CQ

PlzDedicatedWorker: Fix origin comparison for a blob url worker

This CL fixes origin comparison on IsSameOriginClientContainerHost() for
blob url workers. This fixes WPTs for clients.claim() when
PlzDedicatedWorker is enabled.

Before this CL, IsSameOriginClientContainerHost() took an origin from
ServiceWorkerContainerHost::url() that returns GURL. However, this
didn't work when the function returns a blob url (e.g., when the
container host is for a blob url worker) because GURL::GetOrigin()
cannot retrieve an origin from blob URLs
(see https://crbug.com/1144717).

After this CL, the function takes the origin from
ServiceWorkerContainerHost::GetUrlForScopeMatch(). Even for blob url
workers, this returns a non-blob URL inherited from their parent. It
should be valid to take the origin from the alternative URL because
it's guaranteed that they are in the same origin.

This might not align with the spec based on the discussion in the
issues, but we implement this to keep compatibilities:
- https://github.com/w3c/ServiceWorker/issues/1265
- https://github.com/w3c/ServiceWorker/issues/1554

Bug: 1017034
Change-Id: Ia167c1acaa665ac08e433d37f78d4c5b22383ab2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2600420
Commit-Queue: Asami Doi <asamidoi@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842892}
parent ac61ca2b
......@@ -1585,6 +1585,13 @@ bool ServiceWorkerContainerHost::CanServeContainerHostMethods(
return true;
}
const GURL ServiceWorkerContainerHost::GetOrigin() const {
// Ideally, the origins of GetUrlForScopeMatch() and url() should be the same
// but GURL::GetOrigin() doesn't work with blob URL.
// See https://crbug.com/1144717
return GetUrlForScopeMatch().GetOrigin();
}
const GURL& ServiceWorkerContainerHost::GetUrlForScopeMatch() const {
DCHECK(IsContainerForClient());
if (!scope_match_url_for_blob_client_.is_empty())
......
......@@ -448,6 +448,12 @@ class CONTENT_EXPORT ServiceWorkerContainerHost final
void EnterBackForwardCacheForTesting() { is_in_back_forward_cache_ = true; }
void LeaveBackForwardCacheForTesting() { is_in_back_forward_cache_ = false; }
// Returns the origin of this container host.
// Note that you must use this function instead of retrieving the origin from
// url(). That can be invalid when this container host is created for a blob
// URL context. See comments on GetUrlForScopeMatch() for details.
const GURL GetOrigin() const;
// For service worker clients. Returns the URL that is used for scope matching
// algorithm. This can be different from url() in the case of blob URL
// workers. In that case, url() may be like "blob://https://a.test" and the
......
......@@ -137,7 +137,7 @@ bool IsSameOriginClientContainerHost(
container_host->IsInBackForwardCache()) {
return false;
}
return container_host->url().GetOrigin() == origin &&
return container_host->GetOrigin() == origin &&
(allow_reserved_client || container_host->is_execution_ready());
}
......
This is a testharness.js-based test.
PASS fetch() in Worker should be intercepted after the client is claimed.
PASS fetch() in nested Worker should be intercepted after the client is claimed.
FAIL fetch() in blob URL Worker should be intercepted after the client is claimed. assert_equals: fetch() in the worker should be intercepted. expected "Intercepted!" but got "a simple text file\n"
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment