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