Commit e720158a authored by Hayato Ito's avatar Hayato Ito Committed by Commit Bot

Create ServiceWorkerProviderHost::web_contents_getter_ in ctor.

This is a follow-up CL for https://crrev.com/c/1623611.

|ServiceWorkerProviderHost::web_contents_getter_| can be created from
|frame_tree_node_id| in ctor. |web_contents_getter_| can be const.

This makes code a bit clean.

Bug: 623464
Change-Id: I8e8258a2e2579de2ef2e8e29a4da289d39b0346f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1623664
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664661}
parent 0e48f997
...@@ -640,7 +640,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -640,7 +640,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
ServiceWorkerRequestHandler::CreateForNavigation( ServiceWorkerRequestHandler::CreateForNavigation(
resource_request_->url, resource_context_, resource_request_->url, resource_context_,
service_worker_navigation_handle_core, *request_info, service_worker_navigation_handle_core, *request_info,
web_contents_getter_, &service_worker_provider_host_); &service_worker_provider_host_);
// The interceptor for service worker may not be created for some reasons // The interceptor for service worker may not be created for some reasons
// (e.g. the origin is not secure). // (e.g. the origin is not secure).
if (service_worker_interceptor) if (service_worker_interceptor)
......
...@@ -1856,8 +1856,7 @@ TEST_F(ServiceWorkerJobTest, AddRegistrationToMatchingProviderHosts) { ...@@ -1856,8 +1856,7 @@ TEST_F(ServiceWorkerJobTest, AddRegistrationToMatchingProviderHosts) {
base::WeakPtr<ServiceWorkerProviderHost> reserved_client = base::WeakPtr<ServiceWorkerProviderHost> reserved_client =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
helper_->context()->AsWeakPtr(), true /* are_ancestors_secure */, helper_->context()->AsWeakPtr(), true /* are_ancestors_secure */,
FrameTreeNode::kFrameTreeNodeInvalidId, {} /* web_contents_getter */, FrameTreeNode::kFrameTreeNodeInvalidId, &provider_info);
&provider_info);
reserved_client->UpdateUrls(in_scope, in_scope); reserved_client->UpdateUrls(in_scope, in_scope);
// Make an out-scope client. // Make an out-scope client.
......
...@@ -163,7 +163,6 @@ ServiceWorkerProviderHost::PreCreateNavigationHost( ...@@ -163,7 +163,6 @@ ServiceWorkerProviderHost::PreCreateNavigationHost(
base::WeakPtr<ServiceWorkerContextCore> context, base::WeakPtr<ServiceWorkerContextCore> context,
bool are_ancestors_secure, bool are_ancestors_secure,
int frame_tree_node_id, int frame_tree_node_id,
WebContentsGetter web_contents_getter,
blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info) { blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info) {
DCHECK(context); DCHECK(context);
blink::mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info; blink::mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info;
...@@ -173,8 +172,6 @@ ServiceWorkerProviderHost::PreCreateNavigationHost( ...@@ -173,8 +172,6 @@ ServiceWorkerProviderHost::PreCreateNavigationHost(
frame_tree_node_id, frame_tree_node_id,
mojo::MakeRequest(&((*out_provider_info)->host_ptr_info)), mojo::MakeRequest(&((*out_provider_info)->host_ptr_info)),
std::move(client_ptr_info), context)); std::move(client_ptr_info), context));
host->web_contents_getter_ = std::move(web_contents_getter);
auto weak_ptr = host->AsWeakPtr(); auto weak_ptr = host->AsWeakPtr();
RegisterToContextCore(context, std::move(host)); RegisterToContextCore(context, std::move(host));
return weak_ptr; return weak_ptr;
...@@ -248,6 +245,11 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost( ...@@ -248,6 +245,11 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost(
frame_id_(MSG_ROUTING_NONE), frame_id_(MSG_ROUTING_NONE),
is_parent_frame_secure_(is_parent_frame_secure), is_parent_frame_secure_(is_parent_frame_secure),
frame_tree_node_id_(frame_tree_node_id), frame_tree_node_id_(frame_tree_node_id),
web_contents_getter_(
frame_tree_node_id == FrameTreeNode::kFrameTreeNodeInvalidId
? base::NullCallback()
: base::BindRepeating(&WebContents::FromFrameTreeNodeId,
frame_tree_node_id_)),
context_(context), context_(context),
binding_(this), binding_(this),
interface_provider_binding_(this) { interface_provider_binding_(this) {
......
...@@ -126,7 +126,6 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -126,7 +126,6 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
base::WeakPtr<ServiceWorkerContextCore> context, base::WeakPtr<ServiceWorkerContextCore> context,
bool are_ancestors_secure, bool are_ancestors_secure,
int frame_tree_node_id, int frame_tree_node_id,
WebContentsGetter web_contents_getter,
blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info); blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info);
// Used for starting a service worker. Returns a provider host for the service // Used for starting a service worker. Returns a provider host for the service
...@@ -633,10 +632,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -633,10 +632,8 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
const int frame_tree_node_id_; const int frame_tree_node_id_;
// Only set when this object is pre-created for a navigation. It indicates the // Only set when this object is pre-created for a navigation. It indicates the
// tab where the navigation occurs. // tab where the navigation occurs. Otherwise, a null callback.
// TODO(hayato): Remove |web_contents_getter_| since we can create const WebContentsGetter web_contents_getter_;
// WebContentsGetter from |frame_tree_node_id_|.
WebContentsGetter web_contents_getter_;
// For service worker clients. See comments for the getter functions. // For service worker clients. See comments for the getter functions.
GURL url_; GURL url_;
......
...@@ -458,8 +458,7 @@ TEST_F(ServiceWorkerProviderHostTest, Controller) { ...@@ -458,8 +458,7 @@ TEST_F(ServiceWorkerProviderHostTest, Controller) {
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
helper_->context()->AsWeakPtr(), true /* are_ancestors_secure */, helper_->context()->AsWeakPtr(), true /* are_ancestors_secure */,
FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(), FrameTreeNode::kFrameTreeNodeInvalidId, &provider_info);
&provider_info);
remote_endpoints_.emplace_back(); remote_endpoints_.emplace_back();
remote_endpoints_.back().BindForWindow(std::move(provider_info)); remote_endpoints_.back().BindForWindow(std::move(provider_info));
auto container = std::make_unique<MockServiceWorkerContainer>( auto container = std::make_unique<MockServiceWorkerContainer>(
...@@ -495,8 +494,7 @@ TEST_F(ServiceWorkerProviderHostTest, UncontrolledWithMatchingRegistration) { ...@@ -495,8 +494,7 @@ TEST_F(ServiceWorkerProviderHostTest, UncontrolledWithMatchingRegistration) {
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
helper_->context()->AsWeakPtr(), true /* are_ancestors_secure */, helper_->context()->AsWeakPtr(), true /* are_ancestors_secure */,
FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(), FrameTreeNode::kFrameTreeNodeInvalidId, &provider_info);
&provider_info);
remote_endpoints_.emplace_back(); remote_endpoints_.emplace_back();
remote_endpoints_.back().BindForWindow(std::move(provider_info)); remote_endpoints_.back().BindForWindow(std::move(provider_info));
auto container = std::make_unique<MockServiceWorkerContainer>( auto container = std::make_unique<MockServiceWorkerContainer>(
...@@ -873,8 +871,7 @@ TEST_F(ServiceWorkerProviderHostTest, ...@@ -873,8 +871,7 @@ TEST_F(ServiceWorkerProviderHostTest,
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
helper_->context()->AsWeakPtr(), true, helper_->context()->AsWeakPtr(), true,
FrameTreeNode::kFrameTreeNodeInvalidId, FrameTreeNode::kFrameTreeNodeInvalidId, &provider_info);
base::RepeatingCallback<WebContents*(void)>(), &provider_info);
ServiceWorkerRemoteProviderEndpoint remote_endpoint; ServiceWorkerRemoteProviderEndpoint remote_endpoint;
remote_endpoint.BindForWindow(std::move(provider_info)); remote_endpoint.BindForWindow(std::move(provider_info));
FinishNavigation(host.get()); FinishNavigation(host.get());
...@@ -894,8 +891,7 @@ TEST_F(ServiceWorkerProviderHostTest, ClientPhaseForWindow) { ...@@ -894,8 +891,7 @@ TEST_F(ServiceWorkerProviderHostTest, ClientPhaseForWindow) {
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
helper_->context()->AsWeakPtr(), true, helper_->context()->AsWeakPtr(), true,
FrameTreeNode::kFrameTreeNodeInvalidId, FrameTreeNode::kFrameTreeNodeInvalidId, &provider_info);
base::RepeatingCallback<WebContents*(void)>(), &provider_info);
EXPECT_FALSE(host->is_response_committed()); EXPECT_FALSE(host->is_response_committed());
EXPECT_FALSE(host->is_execution_ready()); EXPECT_FALSE(host->is_execution_ready());
......
...@@ -43,7 +43,6 @@ ServiceWorkerRequestHandler::CreateForNavigation( ...@@ -43,7 +43,6 @@ ServiceWorkerRequestHandler::CreateForNavigation(
ResourceContext* resource_context, ResourceContext* resource_context,
ServiceWorkerNavigationHandleCore* navigation_handle_core, ServiceWorkerNavigationHandleCore* navigation_handle_core,
const NavigationRequestInfo& request_info, const NavigationRequestInfo& request_info,
base::RepeatingCallback<WebContents*()> web_contents_getter,
base::WeakPtr<ServiceWorkerProviderHost>* out_provider_host) { base::WeakPtr<ServiceWorkerProviderHost>* out_provider_host) {
DCHECK(navigation_handle_core); DCHECK(navigation_handle_core);
...@@ -65,8 +64,7 @@ ServiceWorkerRequestHandler::CreateForNavigation( ...@@ -65,8 +64,7 @@ ServiceWorkerRequestHandler::CreateForNavigation(
// Initialize the SWProviderHost. // Initialize the SWProviderHost.
*out_provider_host = ServiceWorkerProviderHost::PreCreateNavigationHost( *out_provider_host = ServiceWorkerProviderHost::PreCreateNavigationHost(
context->AsWeakPtr(), request_info.are_ancestors_secure, context->AsWeakPtr(), request_info.are_ancestors_secure,
request_info.frame_tree_node_id, std::move(web_contents_getter), request_info.frame_tree_node_id, &provider_info);
&provider_info);
navigation_handle_core->OnCreatedProviderHost(*out_provider_host, navigation_handle_core->OnCreatedProviderHost(*out_provider_host,
std::move(provider_info)); std::move(provider_info));
......
...@@ -20,7 +20,6 @@ namespace content { ...@@ -20,7 +20,6 @@ namespace content {
class ResourceContext; class ResourceContext;
class ServiceWorkerNavigationHandleCore; class ServiceWorkerNavigationHandleCore;
class ServiceWorkerProviderHost; class ServiceWorkerProviderHost;
class WebContents;
struct NavigationRequestInfo; struct NavigationRequestInfo;
// Contains factory methods for creating the NavigationLoaderInterceptors for // Contains factory methods for creating the NavigationLoaderInterceptors for
...@@ -36,7 +35,6 @@ class CONTENT_EXPORT ServiceWorkerRequestHandler { ...@@ -36,7 +35,6 @@ class CONTENT_EXPORT ServiceWorkerRequestHandler {
ResourceContext* resource_context, ResourceContext* resource_context,
ServiceWorkerNavigationHandleCore* navigation_handle_core, ServiceWorkerNavigationHandleCore* navigation_handle_core,
const NavigationRequestInfo& request_info, const NavigationRequestInfo& request_info,
base::RepeatingCallback<WebContents*()> web_contents_getter,
base::WeakPtr<ServiceWorkerProviderHost>* out_provider_host); base::WeakPtr<ServiceWorkerProviderHost>* out_provider_host);
// Same as above but for a dedicated worker or shared worker. // Same as above but for a dedicated worker or shared worker.
......
...@@ -96,7 +96,6 @@ class ServiceWorkerRequestHandlerTest : public testing::Test { ...@@ -96,7 +96,6 @@ class ServiceWorkerRequestHandlerTest : public testing::Test {
ServiceWorkerRequestHandler::CreateForNavigation( ServiceWorkerRequestHandler::CreateForNavigation(
GURL(url), nullptr /* resource_context */, GURL(url), nullptr /* resource_context */,
navigation_handle_core.get(), request_info, navigation_handle_core.get(), request_info,
base::RepeatingCallback<WebContents*(void)>(),
&service_worker_provider_host); &service_worker_provider_host);
EXPECT_EQ(expected_handler_created, !!interceptor.get()); EXPECT_EQ(expected_handler_created, !!interceptor.get());
} }
......
...@@ -242,8 +242,7 @@ base::WeakPtr<ServiceWorkerProviderHost> CreateProviderHostForWindow( ...@@ -242,8 +242,7 @@ base::WeakPtr<ServiceWorkerProviderHost> CreateProviderHostForWindow(
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
context, is_parent_frame_secure, context, is_parent_frame_secure,
FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(), FrameTreeNode::kFrameTreeNodeInvalidId, &provider_info);
&provider_info);
output_endpoint->BindForWindow(std::move(provider_info)); output_endpoint->BindForWindow(std::move(provider_info));
// In production code this is called from NavigationRequest in the browser // In production code this is called from NavigationRequest in the browser
......
...@@ -1273,8 +1273,7 @@ TEST_F(ServiceWorkerVersionTest, ...@@ -1273,8 +1273,7 @@ TEST_F(ServiceWorkerVersionTest,
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
helper_->context()->AsWeakPtr(), true /* is_parent_frame_secure */, helper_->context()->AsWeakPtr(), true /* is_parent_frame_secure */,
FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(), FrameTreeNode::kFrameTreeNodeInvalidId, &provider_info);
&provider_info);
remote_endpoint.BindForWindow(std::move(provider_info)); remote_endpoint.BindForWindow(std::move(provider_info));
host->UpdateUrls(registration_->scope(), registration_->scope()); host->UpdateUrls(registration_->scope(), registration_->scope());
host->SetControllerRegistration(registration_, host->SetControllerRegistration(registration_,
......
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