Commit a9ac9036 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Consolidate http and non-http WillCreateURLLoaderFactory calls.

This CL deduplicates ContentBrowserClient::WillCreateURLLoaderFactory
and devtools_instrumentation::WillCreateURLLoaderFactory calls made by
RenderFrameHostImpl from RenderFrameHostImpl::CommitNavigation (for
|non_network_url_loader_factories_|) and from
RenderFrameHostImpl::CreateNetworkServiceDefaultFactoryInternal.

This deduplication will help in a follow-up CL that changes the lifetime
of FileURLLoaderFactory and needs to add one more call to
WillCreateURLLoaderFactory - see https://crrev.com/c/2305213/11.

This CL ignores RFHI callers of
ContentBrowserClient::WillCreateURLLoaderFactory that don't call into
devtools_instrumentation (AppCache and WebUI).  Omitting
devtools_instrumentation from these callers is intentional (as discussed
in the code review).

Bug: 1106995
Change-Id: I9888a39f3a7169399e535b3c68eae6fc53610b18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2321538
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792365}
parent b1a9f297
......@@ -5991,17 +5991,8 @@ void RenderFrameHostImpl::CommitNavigation(
pending_factory_proxy;
mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver =
pending_factory_proxy.InitWithNewPipeAndPassReceiver();
GetContentClient()->browser()->WillCreateURLLoaderFactory(
browser_context, this, GetProcess()->GetID(),
ContentBrowserClient::URLLoaderFactoryType::kDocumentSubResource,
main_world_origin_for_url_loader_factory,
base::nullopt /* navigation_id */, &factory_receiver,
nullptr /* header_client */, nullptr /* bypass_redirect_checks */,
nullptr /* disable_secure_dns */, nullptr /* factory_override */);
// Keep DevTools proxy last, i.e. closest to the network.
devtools_instrumentation::WillCreateURLLoaderFactory(
this, false /* is_navigation */, false /* is_download */,
&factory_receiver, nullptr /* factory_override */);
WillCreateURLLoaderFactory(main_world_origin_for_url_loader_factory,
&factory_receiver);
factory.second->Clone(std::move(factory_receiver));
subresource_loader_factories->pending_scheme_specific_factories().emplace(
factory.first, std::move(pending_factory_proxy));
......@@ -6839,23 +6830,15 @@ bool RenderFrameHostImpl::CreateNetworkServiceDefaultFactoryInternal(
network::mojom::URLLoaderFactoryParamsPtr params,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>
default_factory_receiver) {
auto* context = GetSiteInstance()->GetBrowserContext();
DCHECK(params->request_initiator_site_lock.has_value());
const url::Origin& origin = params->request_initiator_site_lock.value();
const url::Origin& request_initiator =
params->request_initiator_site_lock.value();
bool bypass_redirect_checks = false;
GetContentClient()->browser()->WillCreateURLLoaderFactory(
context, this, GetProcess()->GetID(),
ContentBrowserClient::URLLoaderFactoryType::kDocumentSubResource, origin,
base::nullopt /* navigation_id */, &default_factory_receiver,
&params->header_client, &bypass_redirect_checks,
&params->disable_secure_dns, &params->factory_override);
// Keep DevTools proxy last, i.e. closest to the network.
devtools_instrumentation::WillCreateURLLoaderFactory(
this, false /* is_navigation */, false /* is_download */,
&default_factory_receiver, &params->factory_override);
WillCreateURLLoaderFactory(request_initiator, &default_factory_receiver,
&params->header_client, &bypass_redirect_checks,
&params->disable_secure_dns,
&params->factory_override);
GetProcess()->CreateURLLoaderFactory(std::move(default_factory_receiver),
std::move(params));
......@@ -6863,6 +6846,27 @@ bool RenderFrameHostImpl::CreateNetworkServiceDefaultFactoryInternal(
return bypass_redirect_checks;
}
void RenderFrameHostImpl::WillCreateURLLoaderFactory(
const url::Origin& request_initiator,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
header_client,
bool* bypass_redirect_checks,
bool* disable_secure_dns,
network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
GetContentClient()->browser()->WillCreateURLLoaderFactory(
GetBrowserContext(), this, GetProcess()->GetID(),
ContentBrowserClient::URLLoaderFactoryType::kDocumentSubResource,
request_initiator, base::nullopt /* navigation_id */, factory_receiver,
header_client, bypass_redirect_checks, disable_secure_dns,
factory_override);
// Keep DevTools proxy last, i.e. closest to the network.
devtools_instrumentation::WillCreateURLLoaderFactory(
this, false /* is_navigation */, false /* is_download */,
factory_receiver, factory_override);
}
bool RenderFrameHostImpl::CanExecuteJavaScript() {
if (g_allow_injecting_javascript)
return true;
......
......@@ -2063,6 +2063,17 @@ class CONTENT_EXPORT RenderFrameHostImpl
mojo::PendingReceiver<network::mojom::URLLoaderFactory>
default_factory_receiver);
// Lets ContentBrowserClient and devtools_instrumentation wrap the subresource
// factories before they are sent to a renderer process.
void WillCreateURLLoaderFactory(
const url::Origin& request_initiator,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
header_client = nullptr,
bool* bypass_redirect_checks = nullptr,
bool* disable_secure_dns = nullptr,
network::mojom::URLLoaderFactoryOverridePtr* factory_override = nullptr);
// Returns true if the ExecuteJavaScript() API can be used on this host.
bool CanExecuteJavaScript();
......
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