Commit 08e99954 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Fix URLLoaderInterceptor not intercepting non-network schemes for navigations...

Fix URLLoaderInterceptor not intercepting non-network schemes for navigations when the network service is enabled.

Bug: b/120908346
Change-Id: Ib1cbc7be93a417e662c9dafcd337637fab1483e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1566021
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650496}
parent 417d8be6
...@@ -916,6 +916,15 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -916,6 +916,15 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
non_network_factory.get()); non_network_factory.get());
} }
if (g_loader_factory_interceptor.Get()) {
network::mojom::URLLoaderFactoryPtr factory_ptr;
auto request = mojo::MakeRequest(&factory_ptr);
g_loader_factory_interceptor.Get().Run(&request);
factory->Clone(std::move(request));
factory = base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
std::move(factory_ptr));
}
} else { } else {
default_loader_used_ = true; default_loader_used_ = true;
......
...@@ -83,9 +83,10 @@ class CONTENT_EXPORT NavigationURLLoaderImpl : public NavigationURLLoader { ...@@ -83,9 +83,10 @@ class CONTENT_EXPORT NavigationURLLoaderImpl : public NavigationURLLoader {
static void SetBeginNavigationInterceptorForTesting( static void SetBeginNavigationInterceptorForTesting(
const BeginNavigationInterceptor& interceptor); const BeginNavigationInterceptor& interceptor);
// Intercepts loading of frame requests when network service is enabled and a // Intercepts loading of frame requests when network service is enabled and
// network::mojom::TrustedURLLoaderHeaderClient is being used. This must be // either a network::mojom::TrustedURLLoaderHeaderClient is being used or for
// called on the UI thread or before threads start. // schemes not handled by network service (e.g. files). This must be called on
// the UI thread or before threads start.
using URLLoaderFactoryInterceptor = base::RepeatingCallback<void( using URLLoaderFactoryInterceptor = base::RepeatingCallback<void(
network::mojom::URLLoaderFactoryRequest* request)>; network::mojom::URLLoaderFactoryRequest* request)>;
static void SetURLLoaderFactoryInterceptorForTesting( static void SetURLLoaderFactoryInterceptorForTesting(
......
...@@ -140,7 +140,8 @@ class URLLoaderInterceptor::IOState ...@@ -140,7 +140,8 @@ class URLLoaderInterceptor::IOState
} }
// Callback on IO thread whenever NavigationURLLoaderImpl needs a // Callback on IO thread whenever NavigationURLLoaderImpl needs a
// URLLoaderFactory with a network::mojom::TrustedURLLoaderHeaderClient. // URLLoaderFactory with a network::mojom::TrustedURLLoaderHeaderClient or
// for a non-network-service scheme.
void InterceptNavigationRequestCallback( void InterceptNavigationRequestCallback(
network::mojom::URLLoaderFactoryRequest* request) { network::mojom::URLLoaderFactoryRequest* request) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/data_pipe_utils.h" #include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/base/filename_util.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/test/test_url_loader_client.h" #include "services/network/test/test_url_loader_client.h"
...@@ -68,21 +69,43 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, MonitorFrame) { ...@@ -68,21 +69,43 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, MonitorFrame) {
} }
IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptFrame) { IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptFrame) {
bool seen = false;
GURL url = GetPageURL(); GURL url = GetPageURL();
URLLoaderInterceptor interceptor(base::BindLambdaForTesting( URLLoaderInterceptor interceptor(base::BindLambdaForTesting(
[&](URLLoaderInterceptor::RequestParams* params) { [&](URLLoaderInterceptor::RequestParams* params) {
EXPECT_EQ(params->url_request.url, url); EXPECT_EQ(params->url_request.url, url);
EXPECT_EQ(params->process_id, 0); EXPECT_EQ(params->process_id, 0);
seen = true;
network::URLLoaderCompletionStatus status; network::URLLoaderCompletionStatus status;
status.error_code = net::ERR_FAILED; status.error_code = net::ERR_FAILED;
params->client->OnComplete(status); params->client->OnComplete(status);
return true; return true;
})); }));
EXPECT_FALSE(NavigateToURL(shell(), GetPageURL())); EXPECT_FALSE(NavigateToURL(shell(), GetPageURL()));
EXPECT_TRUE(seen);
}
IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptFrameWithFileScheme) {
bool seen = false;
base::FilePath path = GetTestFilePath(nullptr, "empty.html");
GURL url = net::FilePathToFileURL(path);
URLLoaderInterceptor interceptor(base::BindLambdaForTesting(
[&](URLLoaderInterceptor::RequestParams* params) {
EXPECT_EQ(params->url_request.url, url);
EXPECT_EQ(params->process_id, 0);
seen = true;
network::URLLoaderCompletionStatus status;
status.error_code = net::ERR_FAILED;
params->client->OnComplete(status);
return true;
}));
EXPECT_FALSE(NavigateToURL(shell(), url));
EXPECT_TRUE(seen);
} }
IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest,
AsynchronousInitializationInterceptFrame) { AsynchronousInitializationInterceptFrame) {
bool seen = false;
GURL url = GetPageURL(); GURL url = GetPageURL();
base::RunLoop run_loop; base::RunLoop run_loop;
URLLoaderInterceptor interceptor( URLLoaderInterceptor interceptor(
...@@ -90,6 +113,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, ...@@ -90,6 +113,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest,
[&](URLLoaderInterceptor::RequestParams* params) { [&](URLLoaderInterceptor::RequestParams* params) {
EXPECT_EQ(params->url_request.url, url); EXPECT_EQ(params->url_request.url, url);
EXPECT_EQ(params->process_id, 0); EXPECT_EQ(params->process_id, 0);
seen = true;
network::URLLoaderCompletionStatus status; network::URLLoaderCompletionStatus status;
status.error_code = net::ERR_FAILED; status.error_code = net::ERR_FAILED;
params->client->OnComplete(status); params->client->OnComplete(status);
...@@ -98,18 +122,21 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, ...@@ -98,18 +122,21 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest,
run_loop.QuitClosure()); run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
EXPECT_FALSE(NavigateToURL(shell(), GetPageURL())); EXPECT_FALSE(NavigateToURL(shell(), GetPageURL()));
EXPECT_TRUE(seen);
} }
IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest,
AsynchronousDestructionIsAppliedImmediately) { AsynchronousDestructionIsAppliedImmediately) {
const GURL url = GetPageURL(); const GURL url = GetPageURL();
{ {
bool seen = false;
base::RunLoop run_loop; base::RunLoop run_loop;
URLLoaderInterceptor interceptor( URLLoaderInterceptor interceptor(
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&](URLLoaderInterceptor::RequestParams* params) { [&](URLLoaderInterceptor::RequestParams* params) {
EXPECT_EQ(params->url_request.url, url); EXPECT_EQ(params->url_request.url, url);
EXPECT_EQ(params->process_id, 0); EXPECT_EQ(params->process_id, 0);
seen = true;
network::URLLoaderCompletionStatus status; network::URLLoaderCompletionStatus status;
status.error_code = net::ERR_FAILED; status.error_code = net::ERR_FAILED;
params->client->OnComplete(status); params->client->OnComplete(status);
...@@ -119,6 +146,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, ...@@ -119,6 +146,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest,
run_loop.Run(); run_loop.Run();
ASSERT_FALSE(NavigateToURL(shell(), url)); ASSERT_FALSE(NavigateToURL(shell(), url));
EXPECT_TRUE(seen);
} }
EXPECT_TRUE(NavigateToURL(shell(), url)); EXPECT_TRUE(NavigateToURL(shell(), url));
} }
...@@ -157,17 +185,20 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, ...@@ -157,17 +185,20 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest,
content::ContentBrowserClient* old_browser_client = content::ContentBrowserClient* old_browser_client =
content::SetBrowserClientForTesting(&browser_client); content::SetBrowserClientForTesting(&browser_client);
bool seen = false;
GURL url = GetPageURL(); GURL url = GetPageURL();
URLLoaderInterceptor interceptor(base::BindLambdaForTesting( URLLoaderInterceptor interceptor(base::BindLambdaForTesting(
[&](URLLoaderInterceptor::RequestParams* params) { [&](URLLoaderInterceptor::RequestParams* params) {
EXPECT_EQ(params->url_request.url, url); EXPECT_EQ(params->url_request.url, url);
EXPECT_EQ(params->process_id, 0); EXPECT_EQ(params->process_id, 0);
seen = true;
network::URLLoaderCompletionStatus status; network::URLLoaderCompletionStatus status;
status.error_code = net::ERR_FAILED; status.error_code = net::ERR_FAILED;
params->client->OnComplete(status); params->client->OnComplete(status);
return true; return true;
})); }));
EXPECT_FALSE(NavigateToURL(shell(), GetPageURL())); EXPECT_FALSE(NavigateToURL(shell(), GetPageURL()));
EXPECT_TRUE(seen);
SetBrowserClientForTesting(old_browser_client); SetBrowserClientForTesting(old_browser_client);
} }
...@@ -190,10 +221,12 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, MonitorSubresource) { ...@@ -190,10 +221,12 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, MonitorSubresource) {
} }
IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptSubresource) { IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptSubresource) {
bool seen = false;
GURL url = GetImageURL(); GURL url = GetImageURL();
URLLoaderInterceptor interceptor(base::BindLambdaForTesting( URLLoaderInterceptor interceptor(base::BindLambdaForTesting(
[&](URLLoaderInterceptor::RequestParams* params) { [&](URLLoaderInterceptor::RequestParams* params) {
if (params->url_request.url == url) { if (params->url_request.url == url) {
seen = true;
network::URLLoaderCompletionStatus status; network::URLLoaderCompletionStatus status;
status.error_code = net::ERR_FAILED; status.error_code = net::ERR_FAILED;
params->client->OnComplete(status); params->client->OnComplete(status);
...@@ -203,9 +236,11 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptSubresource) { ...@@ -203,9 +236,11 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptSubresource) {
})); }));
Test(); Test();
EXPECT_FALSE(DidImageLoad()); EXPECT_FALSE(DidImageLoad());
EXPECT_TRUE(seen);
} }
IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptBrowser) { IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptBrowser) {
bool seen = false;
GURL url = GetImageURL(); GURL url = GetImageURL();
network::mojom::URLLoaderPtr loader; network::mojom::URLLoaderPtr loader;
network::TestURLLoaderClient client; network::TestURLLoaderClient client;
...@@ -214,6 +249,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptBrowser) { ...@@ -214,6 +249,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptBrowser) {
URLLoaderInterceptor interceptor(base::BindLambdaForTesting( URLLoaderInterceptor interceptor(base::BindLambdaForTesting(
[&](URLLoaderInterceptor::RequestParams* params) { [&](URLLoaderInterceptor::RequestParams* params) {
seen = true;
EXPECT_EQ(params->url_request.url, url); EXPECT_EQ(params->url_request.url, url);
network::URLLoaderCompletionStatus status; network::URLLoaderCompletionStatus status;
status.error_code = net::ERR_FAILED; status.error_code = net::ERR_FAILED;
...@@ -229,6 +265,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptBrowser) { ...@@ -229,6 +265,7 @@ IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, InterceptBrowser) {
net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
client.RunUntilComplete(); client.RunUntilComplete();
EXPECT_EQ(net::ERR_FAILED, client.completion_status().error_code); EXPECT_EQ(net::ERR_FAILED, client.completion_status().error_code);
EXPECT_TRUE(seen);
} }
IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, WriteResponse) { IN_PROC_BROWSER_TEST_F(URLLoaderInterceptorTest, WriteResponse) {
......
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