Commit 54544c53 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Rename topmost_frame_url to site_for_cookies.

This aligns with ResourceRequest's naming, which is where the value
comes from anyway. Note that ResourceRequest documentation states
site_for_cookies is "usually" the topmost frame URL.

This also allows the getter function to be called for service worker
execution contexts. This simplifies some code at the callsite.

Bug: 908311
Change-Id: Ief92f49d439e1219a6a33a7bafb03371d514b6e6
Reviewed-on: https://chromium-review.googlesource.com/c/1350415Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610775}
parent b732de6b
......@@ -407,7 +407,7 @@ void ServiceWorkerControlleeRequestHandler::
}
if (!GetContentClient()->browser()->AllowServiceWorker(
registration->scope(), provider_host_->topmost_frame_url(),
registration->scope(), provider_host_->site_for_cookies(),
resource_context_, provider_host_->web_contents_getter())) {
url_job_->FallbackToNetwork();
TRACE_EVENT_ASYNC_END1(
......
......@@ -90,7 +90,7 @@ class ServiceWorkerURLTrackingRequestHandler
return nullptr;
const GURL stripped_url = net::SimplifyUrlForRequest(request->url());
provider_host_->SetDocumentUrl(stripped_url);
provider_host_->SetTopmostFrameUrl(request->site_for_cookies());
provider_host_->SetSiteForCookies(request->site_for_cookies());
return nullptr;
}
......@@ -105,7 +105,7 @@ class ServiceWorkerURLTrackingRequestHandler
const GURL stripped_url =
net::SimplifyUrlForRequest(tentative_resource_request.url);
provider_host_->SetDocumentUrl(stripped_url);
provider_host_->SetTopmostFrameUrl(
provider_host_->SetSiteForCookies(
tentative_resource_request.site_for_cookies);
// Fall back to network.
std::move(callback).Run({});
......@@ -459,10 +459,10 @@ ServiceWorkerProviderHost::GetControllerServiceWorkerPtr() {
}
void ServiceWorkerProviderHost::UpdateURLs(const GURL& document_url,
const GURL& topmost_frame_url) {
const GURL& site_for_cookies) {
GURL previous_url = document_url_;
SetDocumentUrl(document_url);
SetTopmostFrameUrl(topmost_frame_url);
SetSiteForCookies(site_for_cookies);
auto current_origin = url::Origin::Create(previous_url);
auto new_origin = url::Origin::Create(document_url_);
// Update client id on cross origin redirects. This corresponds to the HTML
......@@ -507,14 +507,15 @@ void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) {
SyncMatchingRegistrations();
}
void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) {
void ServiceWorkerProviderHost::SetSiteForCookies(const GURL& url) {
DCHECK(IsProviderForClient());
topmost_frame_url_ = url;
site_for_cookies_ = url;
}
const GURL& ServiceWorkerProviderHost::topmost_frame_url() const {
DCHECK(IsProviderForClient());
return topmost_frame_url_;
const GURL& ServiceWorkerProviderHost::site_for_cookies() const {
if (IsProviderForClient())
return site_for_cookies_;
return running_hosted_version_->script_url();
}
void ServiceWorkerProviderHost::UpdateController(bool notify_controllerchange) {
......@@ -668,8 +669,7 @@ void ServiceWorkerProviderHost::RemoveServiceWorkerObjectHost(
bool ServiceWorkerProviderHost::AllowServiceWorker(const GURL& scope) {
DCHECK(IsContextAlive());
return GetContentClient()->browser()->AllowServiceWorker(
scope, IsProviderForClient() ? topmost_frame_url() : document_url(),
context_->wrapper()->resource_context(),
scope, site_for_cookies(), context_->wrapper()->resource_context(),
base::BindRepeating(&WebContentsImpl::FromRenderFrameHostID,
render_process_id_, frame_id()));
}
......
......@@ -271,9 +271,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// for posting messages.
mojom::ControllerServiceWorkerPtr GetControllerServiceWorkerPtr();
// Sets the |document_url_|, |topmost_frame_url_| and updates the uuid if it's
// Sets the |document_url_|, |site_for_cookies_| and updates the uuid if it's
// cross origin transition. This is for service worker clients.
void UpdateURLs(const GURL& document_url, const GURL& topmost_frame_url);
void UpdateURLs(const GURL& document_url, const GURL& site_for_cookies);
// Sets the |document_url_|. When this object is for a client,
// |matching_registrations_| gets also updated to ensure that |document_url_|
......@@ -288,11 +288,13 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
void SetDocumentUrl(const GURL& url);
const GURL& document_url() const { return document_url_; }
// For service worker clients. Sets the |topmost_frame_url|.
void SetTopmostFrameUrl(const GURL& url);
// For service worker clients, used for permission checks. Use document_url()
// instead if |this| is for a service worker execution context.
const GURL& topmost_frame_url() const;
// The URL representing the first-party site for this context. See
// |network::ResourceRequest::site_for_cookies| for details.
// SetSiteForCookies() can only be called if |this| is for a service worker
// client. For service worker execution contexts, site_for_cookies() always
// returns the service worker script URL.
void SetSiteForCookies(const GURL& url);
const GURL& site_for_cookies() const;
blink::mojom::ServiceWorkerProviderType provider_type() const {
return info_->type;
......@@ -640,7 +642,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
WebContentsGetter web_contents_getter_;
GURL document_url_;
GURL topmost_frame_url_;
GURL site_for_cookies_;
// Keyed by registration scope URL length.
using ServiceWorkerRegistrationMap =
......
......@@ -133,26 +133,26 @@ class ServiceWorkerProviderHostTest : public testing::TestWithParam<bool> {
ServiceWorkerRemoteProviderEndpoint PrepareServiceWorkerProviderHost(
const GURL& document_url) {
ServiceWorkerRemoteProviderEndpoint remote_endpoint;
GURL topmost_frame_url = document_url;
CreateProviderHostInternal(document_url, topmost_frame_url,
GURL site_for_cookies = document_url;
CreateProviderHostInternal(document_url, site_for_cookies,
&remote_endpoint);
return remote_endpoint;
}
ServiceWorkerRemoteProviderEndpoint
PrepareServiceWorkerProviderHostWithTopmostFrameUrl(
PrepareServiceWorkerProviderHostWithSiteForCookies(
const GURL& document_url,
const GURL& topmost_frame_url) {
const GURL& site_for_cookies) {
ServiceWorkerRemoteProviderEndpoint remote_endpoint;
CreateProviderHostInternal(document_url, topmost_frame_url,
CreateProviderHostInternal(document_url, site_for_cookies,
&remote_endpoint);
return remote_endpoint;
}
ServiceWorkerProviderHost* CreateProviderHost(const GURL& document_url) {
GURL topmost_frame_url = document_url;
GURL site_for_cookies = document_url;
remote_endpoints_.emplace_back();
return CreateProviderHostInternal(document_url, document_url,
return CreateProviderHostInternal(document_url, site_for_cookies,
&remote_endpoints_.back());
}
......@@ -174,7 +174,7 @@ class ServiceWorkerProviderHostTest : public testing::TestWithParam<bool> {
mojom::ServiceWorkerProviderHostInfoPtr info) {
// In production code, the loader/request handler does this.
host->SetDocumentUrl(GURL("https://www.example.com/page"));
host->SetTopmostFrameUrl(GURL("https://www.example.com/page"));
host->SetSiteForCookies(GURL("https://www.example.com/page"));
// In production code, the OnProviderCreated IPC is received which
// does this.
......@@ -297,7 +297,7 @@ class ServiceWorkerProviderHostTest : public testing::TestWithParam<bool> {
private:
ServiceWorkerProviderHost* CreateProviderHostInternal(
const GURL& document_url,
const GURL& topmost_frame_url,
const GURL& site_for_cookies,
ServiceWorkerRemoteProviderEndpoint* remote_endpoint) {
base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost(
......@@ -309,7 +309,7 @@ class ServiceWorkerProviderHostTest : public testing::TestWithParam<bool> {
host->CompleteNavigationInitialized(helper_->mock_render_process_id(),
std::move(info));
host->SetDocumentUrl(document_url);
host->SetTopmostFrameUrl(topmost_frame_url);
host->SetSiteForCookies(site_for_cookies);
return host.get();
}
......@@ -383,11 +383,11 @@ TEST_P(ServiceWorkerProviderHostTest, UpdateURLs_SameOriginRedirect) {
ServiceWorkerProviderHost* host = CreateProviderHost(url1);
const std::string uuid1 = host->client_uuid();
EXPECT_EQ(url1, host->document_url());
EXPECT_EQ(url1, host->topmost_frame_url());
EXPECT_EQ(url1, host->site_for_cookies());
host->UpdateURLs(url2, url2);
EXPECT_EQ(url2, host->document_url());
EXPECT_EQ(url2, host->topmost_frame_url());
EXPECT_EQ(url2, host->site_for_cookies());
EXPECT_EQ(uuid1, host->client_uuid());
EXPECT_EQ(host, context_->GetProviderHostByClientID(host->client_uuid()));
......@@ -400,11 +400,11 @@ TEST_P(ServiceWorkerProviderHostTest, UpdateURLs_CrossOriginRedirect) {
ServiceWorkerProviderHost* host = CreateProviderHost(url1);
const std::string uuid1 = host->client_uuid();
EXPECT_EQ(url1, host->document_url());
EXPECT_EQ(url1, host->topmost_frame_url());
EXPECT_EQ(url1, host->site_for_cookies());
host->UpdateURLs(url2, url2);
EXPECT_EQ(url2, host->document_url());
EXPECT_EQ(url2, host->topmost_frame_url());
EXPECT_EQ(url2, host->site_for_cookies());
EXPECT_NE(uuid1, host->client_uuid());
EXPECT_FALSE(context_->GetProviderHostByClientID(uuid1));
......@@ -556,7 +556,7 @@ TEST_P(ServiceWorkerProviderHostTest,
SetBrowserClientForTesting(&test_browser_client);
ServiceWorkerRemoteProviderEndpoint remote_endpoint =
PrepareServiceWorkerProviderHostWithTopmostFrameUrl(
PrepareServiceWorkerProviderHostWithSiteForCookies(
GURL("https://www.example.com/foo"),
GURL("https://www.example.com/top"));
......@@ -884,7 +884,7 @@ TEST_P(ServiceWorkerProviderHostTest,
context_->AsWeakPtr(), helper_->mock_render_process_id(),
&provider_info);
const GURL url("https://www.example.com/shared_worker.js");
host->SetTopmostFrameUrl(url);
host->SetSiteForCookies(url);
EXPECT_FALSE(CanFindClientProviderHost(host.get()));
host->CompleteSharedWorkerPreparation();
EXPECT_TRUE(CanFindClientProviderHost(host.get()));
......
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