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

Use FrameTreeNode id, instead of WebContentsGetter, in WebContentsGetterRegistry

This is a preparation CL for https://crrev.com/c/1614723.

As per the review comment [1], we can use FrameTreeNode id, instead of
WebContentsGetter, in WebContentsGetterRegistry because we can get
WebContentsGetter from FrameTreeNode id, as well as to know whether the frame
is mainframe or not from the id.

WebContentsGetterRegistry is now renamed to FrameTreeNodeIdRegistry.

[1] https://crrev.com/c/chromium/src/+/1614723/12/content/browser/web_contents/web_contents_getter_registry.h#16

Bug: 623464
Change-Id: Ifab7727f6a6b74408f815e5b853d75d39c515f9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1623611
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662992}
parent f47f6c88
...@@ -893,6 +893,8 @@ jumbo_source_set("browser") { ...@@ -893,6 +893,8 @@ jumbo_source_set("browser") {
"frame_host/frame_tree_node.h", "frame_host/frame_tree_node.h",
"frame_host/frame_tree_node_blame_context.cc", "frame_host/frame_tree_node_blame_context.cc",
"frame_host/frame_tree_node_blame_context.h", "frame_host/frame_tree_node_blame_context.h",
"frame_host/frame_tree_node_id_registry.cc",
"frame_host/frame_tree_node_id_registry.h",
"frame_host/history_navigation_ablation_study_navigation_throttle.cc", "frame_host/history_navigation_ablation_study_navigation_throttle.cc",
"frame_host/history_navigation_ablation_study_navigation_throttle.h", "frame_host/history_navigation_ablation_study_navigation_throttle.h",
"frame_host/input/input_injector_impl.cc", "frame_host/input/input_injector_impl.cc",
...@@ -1880,8 +1882,6 @@ jumbo_source_set("browser") { ...@@ -1880,8 +1882,6 @@ jumbo_source_set("browser") {
"web_contents/aura/gesture_nav_simple.h", "web_contents/aura/gesture_nav_simple.h",
"web_contents/aura/types.cc", "web_contents/aura/types.cc",
"web_contents/aura/types.h", "web_contents/aura/types.h",
"web_contents/web_contents_getter_registry.cc",
"web_contents/web_contents_getter_registry.h",
"web_contents/web_contents_impl.cc", "web_contents/web_contents_impl.cc",
"web_contents/web_contents_impl.h", "web_contents/web_contents_impl.h",
"web_contents/web_contents_view.h", "web_contents/web_contents_view.h",
......
...@@ -2,50 +2,40 @@ ...@@ -2,50 +2,40 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/web_contents/web_contents_getter_registry.h" #include "content/browser/frame_host/frame_tree_node_id_registry.h"
#include "base/no_destructor.h" #include "content/browser/frame_host/frame_tree_node.h"
namespace content { namespace content {
using WebContentsGetter = WebContentsGetterRegistry::WebContentsGetter;
// static // static
WebContentsGetterRegistry* WebContentsGetterRegistry::GetInstance() { FrameTreeNodeIdRegistry* FrameTreeNodeIdRegistry::GetInstance() {
static base::NoDestructor<WebContentsGetterRegistry> instance; static base::NoDestructor<FrameTreeNodeIdRegistry> instance;
return instance.get(); return instance.get();
} }
void WebContentsGetterRegistry::Add( void FrameTreeNodeIdRegistry::Add(const base::UnguessableToken& id,
const base::UnguessableToken& id, const int frame_tree_node_id) {
const WebContentsGetter& web_contents_getter) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool inserted = (map_.emplace(id, web_contents_getter)).second; bool inserted = (map_.emplace(id, frame_tree_node_id)).second;
CHECK(inserted); CHECK(inserted);
} }
void WebContentsGetterRegistry::Remove(const base::UnguessableToken& id) { void FrameTreeNodeIdRegistry::Remove(const base::UnguessableToken& id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
map_.erase(id); map_.erase(id);
} }
const WebContentsGetter& WebContentsGetterRegistry::Get( int FrameTreeNodeIdRegistry::Get(const base::UnguessableToken& id) const {
const base::UnguessableToken& id) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto iter = map_.find(id); auto iter = map_.find(id);
if (iter == map_.end()) if (iter == map_.end())
return GetNullGetter(); return FrameTreeNode::kFrameTreeNodeInvalidId;
return iter->second; return iter->second;
} }
WebContentsGetterRegistry::WebContentsGetterRegistry() = default; FrameTreeNodeIdRegistry::FrameTreeNodeIdRegistry() = default;
WebContentsGetterRegistry::~WebContentsGetterRegistry() = default;
// static FrameTreeNodeIdRegistry::~FrameTreeNodeIdRegistry() = default;
const WebContentsGetter& WebContentsGetterRegistry::GetNullGetter() {
static const base::NoDestructor<WebContentsGetter> null_getter;
return *null_getter;
}
} // namespace content } // namespace content
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_ID_REGISTRY_H_
#define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_ID_REGISTRY_H_
#include <map>
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
#include "base/unguessable_token.h"
namespace content {
// A global map of UnguessableToken to FrameTreeNode id. This registry lives
// and is used only on the IO thread, as it's convenient for the current user
// of the class (ServiceWorkerProviderHost, which should move to the UI thread
// eventually). This is currently used to map a network request to a frame so
// that the network service can tell the browser to display tab-level UI
// required for the request in certain cases, including client certificates and
// basic HTTP authentication.
//
// It uses FrameTreeNode rather than RenderFrameHost because the lookup can
// happen for browser-initiated navigation requests, where a RenderFrameHost
// might not have been created yet.
//
// Warning: A corresponding frame may have changed security contexts since it
// was added. It's useful for looking up a WebContents or determining if it's a
// main frame or not, but callers should not make assumptions that it's in the
// same renderer process or origin as when it was added to the registry.
class FrameTreeNodeIdRegistry {
public:
static FrameTreeNodeIdRegistry* GetInstance();
void Add(const base::UnguessableToken& id, const int frame_tree_node_id);
void Remove(const base::UnguessableToken&);
// Returns FrameTreeNodeId::kFrameTreeNodeIdInvalid if not found.
int Get(const base::UnguessableToken& id) const;
private:
friend class base::NoDestructor<FrameTreeNodeIdRegistry>;
FrameTreeNodeIdRegistry();
~FrameTreeNodeIdRegistry();
std::map<base::UnguessableToken, int> map_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(FrameTreeNodeIdRegistry);
};
} // namespace content
#endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_ID_REGISTRY_H_
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "content/browser/frame_host/frame_tree_node.h" #include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/frame_tree_node_id_registry.h"
#include "content/browser/loader/resource_message_filter.h" #include "content/browser/loader/resource_message_filter.h"
#include "content/browser/service_worker/service_worker_provider_host.h" #include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/browser/web_contents/web_contents_getter_registry.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/net/url_request_service_worker_data.h" #include "content/common/net/url_request_service_worker_data.h"
#include "content/common/net/url_request_user_data.h" #include "content/common/net/url_request_user_data.h"
...@@ -194,10 +194,12 @@ ResourceRequestInfo::WebContentsGetter ...@@ -194,10 +194,12 @@ ResourceRequestInfo::WebContentsGetter
ResourceRequestInfoImpl::GetWebContentsGetterForRequest() { ResourceRequestInfoImpl::GetWebContentsGetterForRequest() {
// If we have a window id, try to use that. // If we have a window id, try to use that.
if (fetch_window_id_) { if (fetch_window_id_) {
ResourceRequestInfo::WebContentsGetter getter = int frame_tree_node_id =
WebContentsGetterRegistry::GetInstance()->Get(fetch_window_id_); FrameTreeNodeIdRegistry::GetInstance()->Get(fetch_window_id_);
if (getter) if (frame_tree_node_id != FrameTreeNode::kFrameTreeNodeInvalidId) {
return getter; return base::BindRepeating(&WebContents::FromFrameTreeNodeId,
frame_tree_node_id);
}
} }
// Navigation requests are created with a valid FrameTreeNode ID and invalid // Navigation requests are created with a valid FrameTreeNode ID and invalid
......
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
#include "content/browser/browsing_data/clear_site_data_handler.h" #include "content/browser/browsing_data/clear_site_data_handler.h"
#include "content/browser/devtools/devtools_url_loader_interceptor.h" #include "content/browser/devtools/devtools_url_loader_interceptor.h"
#include "content/browser/frame_host/frame_tree_node.h" #include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/frame_tree_node_id_registry.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h" #include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/ssl/ssl_client_auth_handler.h" #include "content/browser/ssl/ssl_client_auth_handler.h"
#include "content/browser/ssl/ssl_error_handler.h" #include "content/browser/ssl/ssl_error_handler.h"
#include "content/browser/ssl/ssl_manager.h" #include "content/browser/ssl/ssl_manager.h"
#include "content/browser/ssl_private_key_impl.h" #include "content/browser/ssl_private_key_impl.h"
#include "content/browser/web_contents/web_contents_getter_registry.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
...@@ -325,7 +325,13 @@ void HandleFileUploadRequest( ...@@ -325,7 +325,13 @@ void HandleFileUploadRequest(
base::RepeatingCallback<WebContents*(void)> GetWebContentsFromRegistry( base::RepeatingCallback<WebContents*(void)> GetWebContentsFromRegistry(
const base::UnguessableToken& window_id) { const base::UnguessableToken& window_id) {
return WebContentsGetterRegistry::GetInstance()->Get(window_id); int frame_tree_node_id =
FrameTreeNodeIdRegistry::GetInstance()->Get(window_id);
if (frame_tree_node_id == FrameTreeNode::kFrameTreeNodeInvalidId) {
return base::NullCallback();
}
return base::BindRepeating(&WebContents::FromFrameTreeNodeId,
frame_tree_node_id);
} }
WebContents* GetWebContents(int process_id, int routing_id) { WebContents* GetWebContents(int process_id, int routing_id) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/test/test_simple_task_runner.h" #include "base/test/test_simple_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/service_worker/embedded_worker_status.h" #include "content/browser/service_worker/embedded_worker_status.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h" #include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/fake_embedded_worker_instance_client.h" #include "content/browser/service_worker/fake_embedded_worker_instance_client.h"
...@@ -1855,7 +1856,8 @@ TEST_F(ServiceWorkerJobTest, AddRegistrationToMatchingProviderHosts) { ...@@ -1855,7 +1856,8 @@ 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 */,
{} /* web_contents_getter */, &provider_info); FrameTreeNode::kFrameTreeNodeInvalidId, {} /* web_contents_getter */,
&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.
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/bad_message.h" #include "content/browser/bad_message.h"
#include "content/browser/frame_host/frame_tree_node_id_registry.h"
#include "content/browser/interface_provider_filtering.h" #include "content/browser/interface_provider_filtering.h"
#include "content/browser/loader/navigation_loader_interceptor.h" #include "content/browser/loader/navigation_loader_interceptor.h"
#include "content/browser/renderer_interface_binders.h" #include "content/browser/renderer_interface_binders.h"
...@@ -29,7 +30,6 @@ ...@@ -29,7 +30,6 @@
#include "content/browser/service_worker/service_worker_type_converters.h" #include "content/browser/service_worker/service_worker_type_converters.h"
#include "content/browser/service_worker/service_worker_version.h" #include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/url_loader_factory_getter.h" #include "content/browser/url_loader_factory_getter.h"
#include "content/browser/web_contents/web_contents_getter_registry.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/service_worker/service_worker_types.h" #include "content/common/service_worker/service_worker_types.h"
#include "content/common/service_worker/service_worker_utils.h" #include "content/common/service_worker/service_worker_utils.h"
...@@ -163,6 +163,7 @@ base::WeakPtr<ServiceWorkerProviderHost> ...@@ -163,6 +163,7 @@ base::WeakPtr<ServiceWorkerProviderHost>
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
base::WeakPtr<ServiceWorkerContextCore> context, base::WeakPtr<ServiceWorkerContextCore> context,
bool are_ancestors_secure, bool are_ancestors_secure,
int frame_tree_node_id,
WebContentsGetter web_contents_getter, WebContentsGetter web_contents_getter,
blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info) { blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info) {
DCHECK(context); DCHECK(context);
...@@ -170,6 +171,7 @@ ServiceWorkerProviderHost::PreCreateNavigationHost( ...@@ -170,6 +171,7 @@ ServiceWorkerProviderHost::PreCreateNavigationHost(
(*out_provider_info)->client_request = mojo::MakeRequest(&client_ptr_info); (*out_provider_info)->client_request = mojo::MakeRequest(&client_ptr_info);
auto host = base::WrapUnique(new ServiceWorkerProviderHost( auto host = base::WrapUnique(new ServiceWorkerProviderHost(
blink::mojom::ServiceWorkerProviderType::kForWindow, are_ancestors_secure, blink::mojom::ServiceWorkerProviderType::kForWindow, are_ancestors_secure,
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); host->web_contents_getter_ = std::move(web_contents_getter);
...@@ -190,7 +192,7 @@ ServiceWorkerProviderHost::PreCreateForController( ...@@ -190,7 +192,7 @@ ServiceWorkerProviderHost::PreCreateForController(
(*out_provider_info)->client_request = mojo::MakeRequest(&client_ptr_info); (*out_provider_info)->client_request = mojo::MakeRequest(&client_ptr_info);
auto host = base::WrapUnique(new ServiceWorkerProviderHost( auto host = base::WrapUnique(new ServiceWorkerProviderHost(
blink::mojom::ServiceWorkerProviderType::kForServiceWorker, blink::mojom::ServiceWorkerProviderType::kForServiceWorker,
true /* is_parent_frame_secure */, true /* is_parent_frame_secure */, FrameTreeNode::kFrameTreeNodeInvalidId,
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->running_hosted_version_ = std::move(version); host->running_hosted_version_ = std::move(version);
...@@ -210,7 +212,7 @@ ServiceWorkerProviderHost::PreCreateForSharedWorker( ...@@ -210,7 +212,7 @@ ServiceWorkerProviderHost::PreCreateForSharedWorker(
(*out_provider_info)->client_request = mojo::MakeRequest(&client_ptr_info); (*out_provider_info)->client_request = mojo::MakeRequest(&client_ptr_info);
auto host = base::WrapUnique(new ServiceWorkerProviderHost( auto host = base::WrapUnique(new ServiceWorkerProviderHost(
blink::mojom::ServiceWorkerProviderType::kForSharedWorker, blink::mojom::ServiceWorkerProviderType::kForSharedWorker,
true /* is_parent_frame_secure */, true /* is_parent_frame_secure */, FrameTreeNode::kFrameTreeNodeInvalidId,
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->SetRenderProcessId(process_id); host->SetRenderProcessId(process_id);
...@@ -234,6 +236,7 @@ void ServiceWorkerProviderHost::RegisterToContextCore( ...@@ -234,6 +236,7 @@ void ServiceWorkerProviderHost::RegisterToContextCore(
ServiceWorkerProviderHost::ServiceWorkerProviderHost( ServiceWorkerProviderHost::ServiceWorkerProviderHost(
blink::mojom::ServiceWorkerProviderType type, blink::mojom::ServiceWorkerProviderType type,
bool is_parent_frame_secure, bool is_parent_frame_secure,
int frame_tree_node_id,
blink::mojom::ServiceWorkerContainerHostAssociatedRequest host_request, blink::mojom::ServiceWorkerContainerHostAssociatedRequest host_request,
blink::mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info, blink::mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info,
base::WeakPtr<ServiceWorkerContextCore> context) base::WeakPtr<ServiceWorkerContextCore> context)
...@@ -245,6 +248,7 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost( ...@@ -245,6 +248,7 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost(
render_thread_id_(kDocumentMainThreadId), render_thread_id_(kDocumentMainThreadId),
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),
context_(context), context_(context),
binding_(this), binding_(this),
interface_provider_binding_(this) { interface_provider_binding_(this) {
...@@ -272,7 +276,7 @@ ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { ...@@ -272,7 +276,7 @@ ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
if (controller_) if (controller_)
controller_->RemoveControllee(client_uuid_); controller_->RemoveControllee(client_uuid_);
if (fetch_request_window_id_) if (fetch_request_window_id_)
WebContentsGetterRegistry::GetInstance()->Remove(fetch_request_window_id_); FrameTreeNodeIdRegistry::GetInstance()->Remove(fetch_request_window_id_);
// Remove |this| as an observer of ServiceWorkerRegistrations. // Remove |this| as an observer of ServiceWorkerRegistrations.
// TODO(falken): Use ScopedObserver instead of this explicit call. // TODO(falken): Use ScopedObserver instead of this explicit call.
...@@ -401,10 +405,10 @@ void ServiceWorkerProviderHost::UpdateUrls(const GURL& url, ...@@ -401,10 +405,10 @@ void ServiceWorkerProviderHost::UpdateUrls(const GURL& url,
// may no longer be the potential controller of this frame and shouldn't // may no longer be the potential controller of this frame and shouldn't
// have the power to display SSL dialogs for it. // have the power to display SSL dialogs for it.
if (type_ == blink::mojom::ServiceWorkerProviderType::kForWindow) { if (type_ == blink::mojom::ServiceWorkerProviderType::kForWindow) {
auto* registry = WebContentsGetterRegistry::GetInstance(); auto* registry = FrameTreeNodeIdRegistry::GetInstance();
registry->Remove(fetch_request_window_id_); registry->Remove(fetch_request_window_id_);
fetch_request_window_id_ = base::UnguessableToken::Create(); fetch_request_window_id_ = base::UnguessableToken::Create();
registry->Add(fetch_request_window_id_, web_contents_getter()); registry->Add(fetch_request_window_id_, frame_tree_node_id_);
} }
} }
......
...@@ -114,8 +114,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -114,8 +114,9 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// ServiceWorkerProviderContext will later be created in the renderer, should // ServiceWorkerProviderContext will later be created in the renderer, should
// the navigation succeed. |are_ancestors_secure| should be true for main // the navigation succeed. |are_ancestors_secure| should be true for main
// frames. Otherwise it is true iff all ancestor frames of this frame have a // frames. Otherwise it is true iff all ancestor frames of this frame have a
// secure origin. |web_contents_getter| indicates the tab where the navigation // secure origin. |frame_tree_node_id| is FrameTreeNode
// is occurring. // id. |web_contents_getter| indicates the tab where the navigation is
// occurring.
// //
// The returned host stays alive as long as the filled |out_provider_info| // The returned host stays alive as long as the filled |out_provider_info|
// stays alive (namely, as long as |out_provider_info->host_ptr_info| stays // stays alive (namely, as long as |out_provider_info->host_ptr_info| stays
...@@ -124,6 +125,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -124,6 +125,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
static base::WeakPtr<ServiceWorkerProviderHost> PreCreateNavigationHost( static base::WeakPtr<ServiceWorkerProviderHost> PreCreateNavigationHost(
base::WeakPtr<ServiceWorkerContextCore> context, base::WeakPtr<ServiceWorkerContextCore> context,
bool are_ancestors_secure, bool are_ancestors_secure,
int frame_tree_node_id,
WebContentsGetter web_contents_getter, WebContentsGetter web_contents_getter,
blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info); blink::mojom::ServiceWorkerProviderInfoForWindowPtr* out_provider_info);
...@@ -462,6 +464,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -462,6 +464,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
ServiceWorkerProviderHost( ServiceWorkerProviderHost(
blink::mojom::ServiceWorkerProviderType type, blink::mojom::ServiceWorkerProviderType type,
bool is_parent_frame_secure, bool is_parent_frame_secure,
int frame_tree_node_id,
blink::mojom::ServiceWorkerContainerHostAssociatedRequest host_request, blink::mojom::ServiceWorkerContainerHostAssociatedRequest host_request,
blink::mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info, blink::mojom::ServiceWorkerContainerAssociatedPtrInfo client_ptr_info,
base::WeakPtr<ServiceWorkerContextCore> context); base::WeakPtr<ServiceWorkerContextCore> context);
...@@ -625,8 +628,14 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -625,8 +628,14 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// change its value. // change its value.
bool is_parent_frame_secure_; bool is_parent_frame_secure_;
// FrameTreeNode id if this is a service worker window client.
// Otherwise, |FrameTreeNode::kFrameTreeNodeInvalidId|.
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.
// TODO(hayato): Remove |web_contents_getter_| since we can create
// WebContentsGetter from |frame_tree_node_id_|.
WebContentsGetter web_contents_getter_; WebContentsGetter web_contents_getter_;
// For service worker clients. See comments for the getter functions. // For service worker clients. See comments for the getter functions.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h" #include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/service_worker_context_core.h" #include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_register_job.h" #include "content/browser/service_worker/service_worker_register_job.h"
...@@ -457,7 +458,8 @@ TEST_F(ServiceWorkerProviderHostTest, Controller) { ...@@ -457,7 +458,8 @@ 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 */,
base::NullCallback(), &provider_info); FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(),
&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>(
...@@ -493,7 +495,8 @@ TEST_F(ServiceWorkerProviderHostTest, UncontrolledWithMatchingRegistration) { ...@@ -493,7 +495,8 @@ 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 */,
base::NullCallback(), &provider_info); FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(),
&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>(
...@@ -870,6 +873,7 @@ TEST_F(ServiceWorkerProviderHostTest, ...@@ -870,6 +873,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,
base::RepeatingCallback<WebContents*(void)>(), &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));
...@@ -890,6 +894,7 @@ TEST_F(ServiceWorkerProviderHostTest, ClientPhaseForWindow) { ...@@ -890,6 +894,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,
base::RepeatingCallback<WebContents*(void)>(), &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());
......
...@@ -65,7 +65,8 @@ ServiceWorkerRequestHandler::CreateForNavigation( ...@@ -65,7 +65,8 @@ 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,
std::move(web_contents_getter), &provider_info); request_info.frame_tree_node_id, std::move(web_contents_getter),
&provider_info);
navigation_handle_core->OnCreatedProviderHost(*out_provider_host, navigation_handle_core->OnCreatedProviderHost(*out_provider_host,
std::move(provider_info)); std::move(provider_info));
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/barrier_closure.h" #include "base/barrier_closure.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h" #include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/service_worker_context_core.h" #include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_database.h" #include "content/browser/service_worker/service_worker_database.h"
...@@ -240,7 +241,8 @@ base::WeakPtr<ServiceWorkerProviderHost> CreateProviderHostForWindow( ...@@ -240,7 +241,8 @@ base::WeakPtr<ServiceWorkerProviderHost> CreateProviderHostForWindow(
auto provider_info = blink::mojom::ServiceWorkerProviderInfoForWindow::New(); auto provider_info = blink::mojom::ServiceWorkerProviderInfoForWindow::New();
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
ServiceWorkerProviderHost::PreCreateNavigationHost( ServiceWorkerProviderHost::PreCreateNavigationHost(
context, is_parent_frame_secure, base::NullCallback(), context, is_parent_frame_secure,
FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(),
&provider_info); &provider_info);
output_endpoint->BindForWindow(std::move(provider_info)); output_endpoint->BindForWindow(std::move(provider_info));
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h" #include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/service_worker/embedded_worker_status.h" #include "content/browser/service_worker/embedded_worker_status.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h" #include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/fake_embedded_worker_instance_client.h" #include "content/browser/service_worker/fake_embedded_worker_instance_client.h"
...@@ -1282,7 +1283,8 @@ TEST_F(ServiceWorkerVersionTest, ...@@ -1282,7 +1283,8 @@ 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 */,
base::NullCallback(), &provider_info); FrameTreeNode::kFrameTreeNodeInvalidId, base::NullCallback(),
&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_,
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_GETTER_REGISTRY_H_
#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_GETTER_REGISTRY_H_
#include "base/callback_forward.h"
#include "base/containers/flat_map.h"
#include "base/sequence_checker.h"
#include "base/unguessable_token.h"
#include "content/public/browser/web_contents.h"
namespace content {
// A global map of UnguessableToken to WebContentsGetter. Unlike most other
// WebContents related objects, this registry lives and is used only on the IO
// thread, as it's convenient for the current user of the class
// (ServiceWorkerProviderHost, which should move to the UI thread eventually).
// However, the WebContentsGetter callbacks must only be run on the UI thread.
class WebContentsGetterRegistry {
public:
using WebContentsGetter = base::RepeatingCallback<WebContents*()>;
static WebContentsGetterRegistry* GetInstance();
void Add(const base::UnguessableToken& id,
const WebContentsGetter& web_contents_getter);
void Remove(const base::UnguessableToken&);
// Returns null getter if not found.
const WebContentsGetter& Get(const base::UnguessableToken& id) const;
private:
friend class base::NoDestructor<WebContentsGetterRegistry>;
WebContentsGetterRegistry();
~WebContentsGetterRegistry();
static const WebContentsGetter& GetNullGetter();
base::flat_map<base::UnguessableToken, WebContentsGetter> map_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(WebContentsGetterRegistry);
};
} // namespace content
#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_GETTER_REGISTRY_H_
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