Commit 7a9db510 authored by yhirano's avatar yhirano Committed by Commit bot

Provide route ID via URLLoaderFactory

BUG=603396

Review-Url: https://codereview.chromium.org/2390983002
Cr-Commit-Position: refs/heads/master@{#423011}
parent 50face11
...@@ -326,6 +326,7 @@ specific_include_rules = { ...@@ -326,6 +326,7 @@ specific_include_rules = {
"+content/browser/loader/test_url_loader_client.h", "+content/browser/loader/test_url_loader_client.h",
"+content/browser/loader/resource_dispatcher_host_impl.h", "+content/browser/loader/resource_dispatcher_host_impl.h",
"+content/browser/loader/resource_message_filter.h", "+content/browser/loader/resource_message_filter.h",
"+content/browser/loader/resource_request_info_impl.h",
"+content/browser/loader/url_loader_factory_impl.h", "+content/browser/loader/url_loader_factory_impl.h",
"+content/browser/loader_delegate_impl.h", "+content/browser/loader_delegate_impl.h",
"+content/common/resource_request.h", "+content/common/resource_request.h",
......
...@@ -26,13 +26,12 @@ URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { ...@@ -26,13 +26,12 @@ URLLoaderFactoryImpl::~URLLoaderFactoryImpl() {
void URLLoaderFactoryImpl::CreateLoaderAndStart( void URLLoaderFactoryImpl::CreateLoaderAndStart(
mojom::URLLoaderRequest request, mojom::URLLoaderRequest request,
int32_t routing_id,
int32_t request_id, int32_t request_id,
const ResourceRequest& url_request, const ResourceRequest& url_request,
mojom::URLLoaderClientPtr client) { mojom::URLLoaderClientPtr client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(yhirano): Provide the right routing ID.
const int routing_id = 0;
ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request,
std::move(request), std::move(client), std::move(request), std::move(client),
......
...@@ -22,6 +22,7 @@ class URLLoaderFactoryImpl final : public mojom::URLLoaderFactory { ...@@ -22,6 +22,7 @@ class URLLoaderFactoryImpl final : public mojom::URLLoaderFactory {
~URLLoaderFactoryImpl() override; ~URLLoaderFactoryImpl() override;
void CreateLoaderAndStart(mojom::URLLoaderRequest request, void CreateLoaderAndStart(mojom::URLLoaderRequest request,
int32_t routing_id,
int32_t request_id, int32_t request_id,
const ResourceRequest& url_request, const ResourceRequest& url_request,
mojom::URLLoaderClientPtr client) override; mojom::URLLoaderClientPtr client) override;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "content/browser/loader/navigation_resource_throttle.h" #include "content/browser/loader/navigation_resource_throttle.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h" #include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/loader/resource_message_filter.h" #include "content/browser/loader/resource_message_filter.h"
#include "content/browser/loader/resource_request_info_impl.h"
#include "content/browser/loader/test_url_loader_client.h" #include "content/browser/loader/test_url_loader_client.h"
#include "content/browser/loader_delegate_impl.h" #include "content/browser/loader_delegate_impl.h"
#include "content/common/resource_request.h" #include "content/common/resource_request.h"
...@@ -53,6 +54,8 @@ namespace content { ...@@ -53,6 +54,8 @@ namespace content {
namespace { namespace {
constexpr int kChildId = 99;
class RejectingResourceDispatcherHostDelegate final class RejectingResourceDispatcherHostDelegate final
: public ResourceDispatcherHostDelegate { : public ResourceDispatcherHostDelegate {
public: public:
...@@ -76,7 +79,7 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> { ...@@ -76,7 +79,7 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> {
: thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
browser_context_(new TestBrowserContext()), browser_context_(new TestBrowserContext()),
resource_message_filter_(new ResourceMessageFilter( resource_message_filter_(new ResourceMessageFilter(
0, kChildId,
// If browser side navigation is enabled then // If browser side navigation is enabled then
// ResourceDispatcherHostImpl prevents main frame URL requests from // ResourceDispatcherHostImpl prevents main frame URL requests from
// the renderer. Ensure that these checks don't trip us up by // the renderer. Ensure that these checks don't trip us up by
...@@ -130,6 +133,8 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> { ...@@ -130,6 +133,8 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> {
}; };
TEST_P(URLLoaderFactoryImplTest, GetResponse) { TEST_P(URLLoaderFactoryImplTest, GetResponse) {
constexpr int32_t kRoutingId = 81;
constexpr int32_t kRequestId = 28;
NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
mojom::URLLoaderPtr loader; mojom::URLLoaderPtr loader;
base::FilePath root; base::FilePath root;
...@@ -142,7 +147,8 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) { ...@@ -142,7 +147,8 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) {
request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html"); request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html");
request.method = "GET"; request.method = "GET";
request.is_main_frame = true; request.is_main_frame = true;
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request, factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), kRoutingId,
kRequestId, request,
client.CreateInterfacePtrAndBind()); client.CreateInterfacePtrAndBind());
ASSERT_FALSE(client.has_received_response()); ASSERT_FALSE(client.has_received_response());
...@@ -150,6 +156,17 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) { ...@@ -150,6 +156,17 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) {
ASSERT_FALSE(client.has_received_completion()); ASSERT_FALSE(client.has_received_completion());
client.RunUntilResponseReceived(); client.RunUntilResponseReceived();
net::URLRequest* url_request =
rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId));
ASSERT_TRUE(url_request);
ResourceRequestInfoImpl* request_info =
ResourceRequestInfoImpl::ForRequest(url_request);
ASSERT_TRUE(request_info);
EXPECT_EQ(kChildId, request_info->GetChildID());
EXPECT_EQ(kRoutingId, request_info->GetRouteID());
EXPECT_EQ(kRequestId, request_info->GetRequestID());
ASSERT_FALSE(client.has_received_completion()); ASSERT_FALSE(client.has_received_completion());
ASSERT_FALSE(client.has_received_completion()); ASSERT_FALSE(client.has_received_completion());
...@@ -194,7 +211,7 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) { ...@@ -194,7 +211,7 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) {
request.url = net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase( request.url = net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
net::URLRequestFailedJob::START, net::ERR_TIMED_OUT); net::URLRequestFailedJob::START, net::ERR_TIMED_OUT);
request.method = "GET"; request.method = "GET";
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request, factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request,
client.CreateInterfacePtrAndBind()); client.CreateInterfacePtrAndBind());
client.RunUntilComplete(); client.RunUntilComplete();
...@@ -212,7 +229,7 @@ TEST_P(URLLoaderFactoryImplTest, InvalidURL) { ...@@ -212,7 +229,7 @@ TEST_P(URLLoaderFactoryImplTest, InvalidURL) {
request.url = GURL(); request.url = GURL();
request.method = "GET"; request.method = "GET";
ASSERT_FALSE(request.url.is_valid()); ASSERT_FALSE(request.url.is_valid());
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request, factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request,
client.CreateInterfacePtrAndBind()); client.CreateInterfacePtrAndBind());
client.RunUntilComplete(); client.RunUntilComplete();
...@@ -231,7 +248,7 @@ TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) { ...@@ -231,7 +248,7 @@ TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) {
TestURLLoaderClient client; TestURLLoaderClient client;
request.url = GURL("http://localhost/"); request.url = GURL("http://localhost/");
request.method = "GET"; request.method = "GET";
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request, factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request,
client.CreateInterfacePtrAndBind()); client.CreateInterfacePtrAndBind());
client.RunUntilComplete(); client.RunUntilComplete();
......
...@@ -664,7 +664,7 @@ int ResourceDispatcher::StartAsync( ...@@ -664,7 +664,7 @@ int ResourceDispatcher::StartAsync(
new URLLoaderClientImpl(request_id, this, main_thread_task_runner_)); new URLLoaderClientImpl(request_id, this, main_thread_task_runner_));
mojom::URLLoaderPtr url_loader; mojom::URLLoaderPtr url_loader;
url_loader_factory->CreateLoaderAndStart( url_loader_factory->CreateLoaderAndStart(
GetProxy(&url_loader), request_id, *request, GetProxy(&url_loader), routing_id, request_id, *request,
client->CreateInterfacePtrAndBind()); client->CreateInterfacePtrAndBind());
pending_requests_[request_id]->url_loader = std::move(url_loader); pending_requests_[request_id]->url_loader = std::move(url_loader);
pending_requests_[request_id]->url_loader_client = std::move(client); pending_requests_[request_id]->url_loader_client = std::move(client);
......
...@@ -12,6 +12,7 @@ interface URLLoaderFactory { ...@@ -12,6 +12,7 @@ interface URLLoaderFactory {
// (e.g., response arrival) happen. |request_id| is for compatibility with // (e.g., response arrival) happen. |request_id| is for compatibility with
// the existing Chrome IPC. // the existing Chrome IPC.
CreateLoaderAndStart(URLLoader& loader, CreateLoaderAndStart(URLLoader& loader,
int32 routing_id,
int32 request_id, int32 request_id,
URLRequest request, URLRequest request,
URLLoaderClient client); URLLoaderClient client);
......
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