Commit 6937e5d5 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Remove FrameTreeNodeIdRegistry which is no longer needed now that networking...

Remove FrameTreeNodeIdRegistry which is no longer needed now that networking callbacks are on the UI thread.

Change-Id: Ic66af3c207262aac8b955cb15a2f4a4922e0d898
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2524281
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825432}
parent bcd4e3b8
......@@ -1779,8 +1779,6 @@ source_set("browser") {
"web_contents/aura/types.h",
"web_contents/file_chooser_impl.cc",
"web_contents/file_chooser_impl.h",
"web_contents/frame_tree_node_id_registry.cc",
"web_contents/frame_tree_node_id_registry.h",
"web_contents/javascript_dialog_navigation_deferrer.cc",
"web_contents/javascript_dialog_navigation_deferrer.h",
"web_contents/web_contents_impl.cc",
......
......@@ -16,7 +16,6 @@
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_object_host.h"
#include "content/browser/service_worker/service_worker_registration_object_host.h"
#include "content/browser/web_contents/frame_tree_node_id_registry.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/content_navigation_policy.h"
#include "content/common/service_worker/service_worker_utils.h"
......@@ -139,9 +138,6 @@ ServiceWorkerContainerHost::~ServiceWorkerContainerHost() {
rfh->RemoveServiceWorkerContainerHost(client_uuid());
}
if (fetch_request_window_id_)
FrameTreeNodeIdRegistry::GetInstance()->Remove(fetch_request_window_id_);
if (IsContainerForClient() && controller_)
controller_->OnControlleeDestroyed(client_uuid());
......@@ -853,13 +849,8 @@ void ServiceWorkerContainerHost::UpdateUrls(
// Revoke the token on URL change since any service worker holding the token
// may no longer be the potential controller of this frame and shouldn't
// have the power to display SSL dialogs for it.
if (IsContainerForWindowClient()) {
auto* registry = FrameTreeNodeIdRegistry::GetInstance();
registry->Remove(fetch_request_window_id_);
if (IsContainerForWindowClient())
fetch_request_window_id_ = base::UnguessableToken::Create();
registry->Add(fetch_request_window_id_,
client_info_->GetFrameTreeNodeId());
}
}
auto previous_origin = url::Origin::Create(previous_url);
......
......@@ -475,6 +475,17 @@ ServiceWorkerContextCore::GetContainerHostByClientID(
return it->second.get();
}
ServiceWorkerContainerHost*
ServiceWorkerContextCore::GetContainerHostByWindowId(
const base::UnguessableToken& window_id) {
for (auto& it : container_host_by_uuid_) {
if (it.second->fetch_request_window_id() == window_id)
return it.second.get();
}
return nullptr;
}
void ServiceWorkerContextCore::OnContainerHostReceiverDisconnected() {
ServiceWorkerContainerHost* container_host =
container_host_receivers_->current_context();
......
......@@ -234,6 +234,10 @@ class CONTENT_EXPORT ServiceWorkerContextCore
ServiceWorkerContainerHost* GetContainerHostByClientID(
const std::string& client_uuid);
// Retrieves a container host given its window ID.
ServiceWorkerContainerHost* GetContainerHostByWindowId(
const base::UnguessableToken& window_id);
void OnContainerHostReceiverDisconnected();
void RegisterServiceWorker(
......
......@@ -60,12 +60,13 @@
#include "content/browser/network_context_client_base_impl.h"
#include "content/browser/notifications/platform_notification_context_impl.h"
#include "content/browser/quota/quota_context.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/service_sandbox_type.h"
#include "content/browser/service_worker/service_worker_container_host.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/ssl/ssl_client_auth_handler.h"
#include "content/browser/ssl/ssl_error_handler.h"
#include "content/browser/ssl_private_key_impl.h"
#include "content/browser/web_contents/frame_tree_node_id_registry.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/navigation_params.mojom.h"
#include "content/common/service_worker/service_worker_utils.h"
......@@ -547,11 +548,7 @@ void OnAuthRequiredContinuation(
mojo::PendingRemote<network::mojom::AuthChallengeResponder>
auth_challenge_responder,
base::RepeatingCallback<WebContents*(void)> web_contents_getter) {
if (!web_contents_getter) {
web_contents_getter =
base::BindRepeating(GetWebContents, process_id, routing_id);
}
if (!web_contents_getter.Run()) {
if (!web_contents_getter || !web_contents_getter.Run()) {
mojo::Remote<network::mojom::AuthChallengeResponder>
auth_challenge_responder_remote(std::move(auth_challenge_responder));
auth_challenge_responder_remote->OnAuthCredentials(base::nullopt);
......@@ -564,63 +561,6 @@ void OnAuthRequiredContinuation(
first_auth_attempt); // deletes self
}
FrameTreeNodeIdRegistry::IsMainFrameGetter GetIsMainFrameFromRegistry(
const base::UnguessableToken& window_id) {
return FrameTreeNodeIdRegistry::GetInstance()->GetIsMainFrameGetter(
window_id);
}
base::RepeatingCallback<WebContents*(void)> GetWebContentsFromRegistry(
const base::UnguessableToken& window_id) {
return FrameTreeNodeIdRegistry::GetInstance()->GetWebContentsGetter(
window_id);
}
void OnAuthRequiredContinuationForWindowId(
const base::UnguessableToken& window_id,
uint32_t process_id,
uint32_t routing_id,
uint32_t request_id,
const GURL& url,
bool first_auth_attempt,
const net::AuthChallengeInfo& auth_info,
network::mojom::URLResponseHeadPtr head,
mojo::PendingRemote<network::mojom::AuthChallengeResponder>
auth_challenge_responder,
FrameTreeNodeIdRegistry::IsMainFrameGetter is_main_frame_getter) {
if (!is_main_frame_getter) {
// FrameTreeNode id may already be removed from FrameTreeNodeIdRegistry
// due to thread hopping.
mojo::Remote<network::mojom::AuthChallengeResponder>
auth_challenge_responder_remote(std::move(auth_challenge_responder));
auth_challenge_responder_remote->OnAuthCredentials(base::nullopt);
return;
}
base::Optional<bool> is_main_frame_opt = is_main_frame_getter.Run();
// The frame may already be gone due to thread hopping.
if (!is_main_frame_opt) {
mojo::Remote<network::mojom::AuthChallengeResponder>
auth_challenge_responder_remote(std::move(auth_challenge_responder));
auth_challenge_responder_remote->OnAuthCredentials(base::nullopt);
return;
}
if (ServiceWorkerContext::IsServiceWorkerOnUIEnabled()) {
OnAuthRequiredContinuation(process_id, routing_id, request_id, url,
*is_main_frame_opt, first_auth_attempt,
auth_info, std::move(head),
std::move(auth_challenge_responder),
GetWebContentsFromRegistry(window_id));
} else {
GetIOThreadTaskRunner({})->PostTaskAndReplyWithResult(
FROM_HERE, base::BindOnce(&GetWebContentsFromRegistry, window_id),
base::BindOnce(&OnAuthRequiredContinuation, process_id, routing_id,
request_id, url, *is_main_frame_opt, first_auth_attempt,
auth_info, std::move(head),
std::move(auth_challenge_responder)));
}
}
bool IsMainFrameRequest(int process_id, int routing_id) {
if (process_id != network::mojom::kBrowserProcessId)
return false;
......@@ -703,11 +643,10 @@ void OnCertificateRequestedContinuation(
mojo::PendingRemote<network::mojom::ClientCertificateResponder>
client_cert_responder_remote,
base::RepeatingCallback<WebContents*(void)> web_contents_getter) {
if (!web_contents_getter) {
web_contents_getter =
base::BindRepeating(GetWebContents, process_id, routing_id);
}
WebContents* web_contents = web_contents_getter.Run();
WebContents* web_contents = nullptr;
if (web_contents_getter)
web_contents = web_contents_getter.Run();
if (!web_contents) {
DCHECK(client_cert_responder_remote);
mojo::Remote<network::mojom::ClientCertificateResponder>
......@@ -1729,26 +1668,33 @@ void StoragePartitionImpl::OnAuthRequired(
mojo::PendingRemote<network::mojom::AuthChallengeResponder>
auth_challenge_responder) {
if (window_id) {
if (ServiceWorkerContext::IsServiceWorkerOnUIEnabled()) {
OnAuthRequiredContinuationForWindowId(
*window_id, process_id, routing_id, request_id, url,
first_auth_attempt, auth_info, std::move(head),
std::move(auth_challenge_responder),
GetIsMainFrameFromRegistry(*window_id));
} else {
GetIOThreadTaskRunner({})->PostTaskAndReplyWithResult(
FROM_HERE, base::BindOnce(&GetIsMainFrameFromRegistry, *window_id),
base::BindOnce(&OnAuthRequiredContinuationForWindowId, *window_id,
process_id, routing_id, request_id, url,
first_auth_attempt, auth_info, std::move(head),
std::move(auth_challenge_responder)));
bool is_main_frame = false;
base::RepeatingCallback<WebContents*(void)> web_contents_getter;
if (service_worker_context_->context()) {
auto* container_host =
service_worker_context_->context()->GetContainerHostByWindowId(
*window_id);
if (container_host) {
int frame_tree_node_id = container_host->frame_tree_node_id();
if (FrameTreeNode* frame_tree_node =
FrameTreeNode::GloballyFindByID(frame_tree_node_id)) {
is_main_frame = frame_tree_node->IsMainFrame();
web_contents_getter = base::BindRepeating(
&WebContents::FromFrameTreeNodeId, frame_tree_node_id);
}
}
}
OnAuthRequiredContinuation(
process_id, routing_id, request_id, url, is_main_frame,
first_auth_attempt, auth_info, std::move(head),
std::move(auth_challenge_responder), web_contents_getter);
return;
}
OnAuthRequiredContinuation(process_id, routing_id, request_id, url,
IsMainFrameRequest(process_id, routing_id),
first_auth_attempt, auth_info, std::move(head),
std::move(auth_challenge_responder), {});
OnAuthRequiredContinuation(
process_id, routing_id, request_id, url,
IsMainFrameRequest(process_id, routing_id), first_auth_attempt, auth_info,
std::move(head), std::move(auth_challenge_responder),
base::BindRepeating(GetWebContents, process_id, routing_id));
}
void StoragePartitionImpl::OnCertificateRequested(
......@@ -1761,22 +1707,26 @@ void StoragePartitionImpl::OnCertificateRequested(
cert_responder) {
// Use |window_id| if it's provided.
if (window_id) {
if (ServiceWorkerContext::IsServiceWorkerOnUIEnabled()) {
OnCertificateRequestedContinuation(
process_id, routing_id, request_id, cert_info,
std::move(cert_responder), GetWebContentsFromRegistry(*window_id));
} else {
GetIOThreadTaskRunner({})->PostTaskAndReplyWithResult(
FROM_HERE, base::BindOnce(&GetWebContentsFromRegistry, *window_id),
base::BindOnce(&OnCertificateRequestedContinuation, process_id,
routing_id, request_id, cert_info,
std::move(cert_responder)));
base::RepeatingCallback<WebContents*(void)> web_contents_getter;
if (service_worker_context_->context()) {
auto* container_host =
service_worker_context_->context()->GetContainerHostByWindowId(
*window_id);
if (container_host) {
int frame_tree_node_id = container_host->frame_tree_node_id();
web_contents_getter = base::BindRepeating(
&WebContents::FromFrameTreeNodeId, frame_tree_node_id);
}
}
OnCertificateRequestedContinuation(process_id, routing_id, request_id,
cert_info, std::move(cert_responder),
web_contents_getter);
return;
}
OnCertificateRequestedContinuation(process_id, routing_id, request_id,
cert_info, std::move(cert_responder), {});
OnCertificateRequestedContinuation(
process_id, routing_id, request_id, cert_info, std::move(cert_responder),
base::BindRepeating(GetWebContents, process_id, routing_id));
}
void StoragePartitionImpl::OnSSLCertificateError(
......
// 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.
#include "content/browser/web_contents/frame_tree_node_id_registry.h"
#include "base/bind_helpers.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/public/browser/web_contents.h"
namespace content {
using WebContentsGetter = FrameTreeNodeIdRegistry::WebContentsGetter;
using IsMainFrameGetter = FrameTreeNodeIdRegistry::IsMainFrameGetter;
namespace {
base::Optional<bool> IsMainFrameFromFrameTreeNodeId(int frame_tree_node_id) {
if (FrameTreeNode* frame_tree_node =
FrameTreeNode::GloballyFindByID(frame_tree_node_id)) {
return frame_tree_node->IsMainFrame();
}
return base::nullopt;
}
} // namespace
// static
FrameTreeNodeIdRegistry* FrameTreeNodeIdRegistry::GetInstance() {
static base::NoDestructor<FrameTreeNodeIdRegistry> instance;
return instance.get();
}
void FrameTreeNodeIdRegistry::Add(const base::UnguessableToken& id,
const int frame_tree_node_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool inserted = (map_.emplace(id, frame_tree_node_id)).second;
CHECK(inserted);
}
void FrameTreeNodeIdRegistry::Remove(const base::UnguessableToken& id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
map_.erase(id);
}
WebContentsGetter FrameTreeNodeIdRegistry::GetWebContentsGetter(
const base::UnguessableToken& id) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto iter = map_.find(id);
if (iter == map_.end())
return base::NullCallback();
return base::BindRepeating(&WebContents::FromFrameTreeNodeId, iter->second);
}
IsMainFrameGetter FrameTreeNodeIdRegistry::GetIsMainFrameGetter(
const base::UnguessableToken& id) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto iter = map_.find(id);
if (iter == map_.end()) {
return base::NullCallback();
}
return base::BindRepeating(&IsMainFrameFromFrameTreeNodeId, iter->second);
}
FrameTreeNodeIdRegistry::FrameTreeNodeIdRegistry() = default;
FrameTreeNodeIdRegistry::~FrameTreeNodeIdRegistry() = default;
} // 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_WEB_CONTENTS_FRAME_TREE_NODE_ID_REGISTRY_H_
#define CONTENT_BROWSER_WEB_CONTENTS_FRAME_TREE_NODE_ID_REGISTRY_H_
#include <map>
#include "base/callback.h"
#include "base/no_destructor.h"
#include "base/optional.h"
#include "base/sequence_checker.h"
#include "base/unguessable_token.h"
namespace content {
class WebContents;
// A global map of UnguessableToken to FrameTreeNode id. This registry lives and
// is used only on the thread identified by
// ServiceWorkerContext::GetCoreThreadId(), as that's the thread the class that
// adds/removes from this registry is on (ServiceWorkerContainerHost).
// TODO(crbug.com/824858): Make this live on the UI thread once the service
// worker core thread moves to the UI thread.
//
// 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.
// To prevent a potential risk, the registry doesn't provide
// |static int /* FrameTreeNode id */ Get(const base::UnguessableToken& id)|.
class FrameTreeNodeIdRegistry {
public:
using WebContentsGetter = base::RepeatingCallback<WebContents*()>;
using IsMainFrameGetter = base::RepeatingCallback<base::Optional<bool>()>;
static FrameTreeNodeIdRegistry* GetInstance();
void Add(const base::UnguessableToken& id, const int frame_tree_node_id);
void Remove(const base::UnguessableToken&);
// Returns a null callback if not found.
WebContentsGetter GetWebContentsGetter(
const base::UnguessableToken& id) const;
// Returns a null callback if not found. The returned callback will return
// nullopt if a corresponding FrameTreeNode is not found.
IsMainFrameGetter GetIsMainFrameGetter(
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_WEB_CONTENTS_FRAME_TREE_NODE_ID_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