Skip to content

Commit

Permalink
fixup! refactor: remove routing_id from CreateLoaderAndStart
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 authored and MarshallOfSound committed Apr 12, 2021
1 parent 4a4da7a commit a1f0bbb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
11 changes: 7 additions & 4 deletions shell/browser/electron_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1573,10 +1573,13 @@ bool ElectronBrowserClient::WillCreateURLLoaderFactory(
ProtocolRegistry::FromBrowserContext(browser_context);
new ProxyingURLLoaderFactory(
web_request.get(), protocol_registry->intercept_handlers(),
render_process_id, &next_id_, std::move(navigation_ui_data),
std::move(navigation_id), std::move(proxied_receiver),
std::move(target_factory_remote), std::move(header_client_receiver),
type);
render_process_id,
frame_host ? frame_host->GetRoutingID() : MSG_ROUTING_NONE,
frame_host ? frame_host->GetRenderViewHost()->GetRoutingID()
: MSG_ROUTING_NONE,
&next_id_, std::move(navigation_ui_data), std::move(navigation_id),
std::move(proxied_receiver), std::move(target_factory_remote),
std::move(header_client_receiver), type);

if (bypass_redirect_checks)
*bypass_redirect_checks = true;
Expand Down
16 changes: 7 additions & 9 deletions shell/browser/net/electron_url_loader_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,18 @@ ElectronURLLoaderFactory::~ElectronURLLoaderFactory() = default;

void ElectronURLLoaderFactory::CreateLoaderAndStart(
mojo::PendingReceiver<network::mojom::URLLoader> loader,
int32_t routing_id,
int32_t request_id,
uint32_t options,
const network::ResourceRequest& request,
mojo::PendingRemote<network::mojom::URLLoaderClient> client,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
mojo::PendingRemote<network::mojom::URLLoaderFactory> proxy_factory;
handler_.Run(request, base::BindOnce(&ElectronURLLoaderFactory::StartLoading,
std::move(loader), routing_id,
request_id, options, request,
std::move(client), traffic_annotation,
std::move(proxy_factory), type_));
handler_.Run(
request,
base::BindOnce(&ElectronURLLoaderFactory::StartLoading, std::move(loader),
request_id, options, request, std::move(client),
traffic_annotation, std::move(proxy_factory), type_));
}

// static
Expand All @@ -222,7 +221,6 @@ void ElectronURLLoaderFactory::OnComplete(
// static
void ElectronURLLoaderFactory::StartLoading(
mojo::PendingReceiver<network::mojom::URLLoader> loader,
int32_t routing_id,
int32_t request_id,
uint32_t options,
const network::ResourceRequest& request,
Expand Down Expand Up @@ -312,7 +310,7 @@ void ElectronURLLoaderFactory::StartLoading(
std::move(proxy_factory));

proxy_factory_remote->CreateLoaderAndStart(
std::move(loader), routing_id, request_id, options, new_request,
std::move(loader), request_id, options, new_request,
std::move(client), traffic_annotation);
} else {
StartLoadingHttp(std::move(loader), new_request, std::move(client),
Expand Down Expand Up @@ -356,7 +354,7 @@ void ElectronURLLoaderFactory::StartLoading(
network::URLLoaderCompletionStatus(net::ERR_FAILED));
return;
}
StartLoading(std::move(loader), routing_id, request_id, options, request,
StartLoading(std::move(loader), request_id, options, request,
std::move(client), traffic_annotation,
std::move(proxy_factory), type, args);
break;
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/net/electron_url_loader_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ElectronURLLoaderFactory : public network::SelfDeletingURLLoaderFactory {
// network::mojom::URLLoaderFactory:
void CreateLoaderAndStart(
mojo::PendingReceiver<network::mojom::URLLoader> loader,
int32_t routing_id,
int32_t request_id,
uint32_t options,
const network::ResourceRequest& request,
Expand All @@ -59,7 +58,6 @@ class ElectronURLLoaderFactory : public network::SelfDeletingURLLoaderFactory {

static void StartLoading(
mojo::PendingReceiver<network::mojom::URLLoader> loader,
int32_t routing_id,
int32_t request_id,
uint32_t options,
const network::ResourceRequest& request,
Expand Down
46 changes: 26 additions & 20 deletions shell/browser/net/proxying_url_loader_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ ProxyingURLLoaderFactory::InProgressRequest::FollowRedirectParams::
ProxyingURLLoaderFactory::InProgressRequest::InProgressRequest(
ProxyingURLLoaderFactory* factory,
int64_t web_request_id,
int32_t routing_id,
int32_t view_routing_id,
int32_t frame_routing_id,
int32_t network_service_request_id,
uint32_t options,
const network::ResourceRequest& request,
Expand All @@ -40,7 +41,8 @@ ProxyingURLLoaderFactory::InProgressRequest::InProgressRequest(
request_(request),
original_initiator_(request.request_initiator),
request_id_(web_request_id),
routing_id_(routing_id),
view_routing_id_(view_routing_id),
frame_routing_id_(frame_routing_id),
network_service_request_id_(network_service_request_id),
options_(options),
traffic_annotation_(traffic_annotation),
Expand All @@ -65,11 +67,13 @@ ProxyingURLLoaderFactory::InProgressRequest::InProgressRequest(
ProxyingURLLoaderFactory::InProgressRequest::InProgressRequest(
ProxyingURLLoaderFactory* factory,
uint64_t request_id,
int32_t frame_routing_id,
const network::ResourceRequest& request)
: factory_(factory),
request_(request),
original_initiator_(request.request_initiator),
request_id_(request_id),
frame_routing_id_(frame_routing_id),
proxied_loader_receiver_(this),
for_cors_preflight_(true),
has_any_extra_headers_listeners_(true) {}
Expand Down Expand Up @@ -104,10 +108,10 @@ void ProxyingURLLoaderFactory::InProgressRequest::UpdateRequestInfo() {
network::ResourceRequest request_for_info = request_;
request_for_info.request_initiator = original_initiator_;
info_.emplace(extensions::WebRequestInfoInitParams(
request_id_, factory_->render_process_id_, request_.render_frame_id,
request_id_, factory_->render_process_id_, frame_routing_id_,
factory_->navigation_ui_data_ ? factory_->navigation_ui_data_->DeepCopy()
: nullptr,
routing_id_, request_for_info, false,
view_routing_id_, request_for_info, false,
!(options_ & network::mojom::kURLLoadOptionSynchronous),
factory_->IsForServiceWorkerScript(), factory_->navigation_id_,
ukm::kInvalidSourceIdObj));
Expand Down Expand Up @@ -373,8 +377,8 @@ void ProxyingURLLoaderFactory::OnLoaderForCorsPreflightCreated(
const uint64_t web_request_id = ++(*request_id_generator_);

auto result = requests_.insert(std::make_pair(
web_request_id,
std::make_unique<InProgressRequest>(this, web_request_id, request)));
web_request_id, std::make_unique<InProgressRequest>(
this, web_request_id, frame_routing_id_, request)));

result.first->second->OnLoaderCreated(std::move(receiver));
result.first->second->Restart();
Expand Down Expand Up @@ -513,9 +517,8 @@ void ProxyingURLLoaderFactory::InProgressRequest::ContinueToStartRequest(
if (has_any_extra_headers_listeners_)
options |= network::mojom::kURLLoadOptionUseHeaderClient;
factory_->target_factory_->CreateLoaderAndStart(
mojo::MakeRequest(&target_loader_), routing_id_,
network_service_request_id_, options, request_,
proxied_client_receiver_.BindNewPipeAndPassRemote(),
mojo::MakeRequest(&target_loader_), network_service_request_id_,
options, request_, proxied_client_receiver_.BindNewPipeAndPassRemote(),
traffic_annotation_);
}

Expand Down Expand Up @@ -745,6 +748,8 @@ ProxyingURLLoaderFactory::ProxyingURLLoaderFactory(
WebRequestAPI* web_request_api,
const HandlersMap& intercepted_handlers,
int render_process_id,
int frame_routing_id,
int view_routing_id,
uint64_t* request_id_generator,
std::unique_ptr<extensions::ExtensionNavigationUIData> navigation_ui_data,
base::Optional<int64_t> navigation_id,
Expand All @@ -756,6 +761,8 @@ ProxyingURLLoaderFactory::ProxyingURLLoaderFactory(
: web_request_api_(web_request_api),
intercepted_handlers_(intercepted_handlers),
render_process_id_(render_process_id),
frame_routing_id_(frame_routing_id),
view_routing_id_(view_routing_id),
request_id_generator_(request_id_generator),
navigation_ui_data_(std::move(navigation_ui_data)),
navigation_id_(std::move(navigation_id)),
Expand Down Expand Up @@ -790,7 +797,6 @@ bool ProxyingURLLoaderFactory::ShouldIgnoreConnectionsLimit(

void ProxyingURLLoaderFactory::CreateLoaderAndStart(
mojo::PendingReceiver<network::mojom::URLLoader> loader,
int32_t routing_id,
int32_t request_id,
uint32_t options,
const network::ResourceRequest& original_request,
Expand All @@ -812,11 +818,10 @@ void ProxyingURLLoaderFactory::CreateLoaderAndStart(

// <scheme, <type, handler>>
it->second.second.Run(
request,
base::BindOnce(&ElectronURLLoaderFactory::StartLoading,
std::move(loader), routing_id, request_id, options,
request, std::move(client), traffic_annotation,
std::move(loader_remote), it->second.first));
request, base::BindOnce(&ElectronURLLoaderFactory::StartLoading,
std::move(loader), request_id, options, request,
std::move(client), traffic_annotation,
std::move(loader_remote), it->second.first));
return;
}

Expand All @@ -832,9 +837,9 @@ void ProxyingURLLoaderFactory::CreateLoaderAndStart(

if (!web_request_api()->HasListener()) {
// Pass-through to the original factory.
target_factory_->CreateLoaderAndStart(
std::move(loader), routing_id, request_id, options, request,
std::move(client), traffic_annotation);
target_factory_->CreateLoaderAndStart(std::move(loader), request_id,
options, request, std::move(client),
traffic_annotation);
return;
}

Expand All @@ -854,8 +859,9 @@ void ProxyingURLLoaderFactory::CreateLoaderAndStart(
auto result = requests_.emplace(
web_request_id,
std::make_unique<InProgressRequest>(
this, web_request_id, routing_id, request_id, options, request,
traffic_annotation, std::move(loader), std::move(client)));
this, web_request_id, view_routing_id_, frame_routing_id_, request_id,
options, request, traffic_annotation, std::move(loader),
std::move(client)));
result.first->second->Restart();
}

Expand Down
13 changes: 10 additions & 3 deletions shell/browser/net/proxying_url_loader_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "base/optional.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_frame_host.h"
#include "extensions/browser/api/web_request/web_request_info.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
Expand Down Expand Up @@ -46,7 +47,8 @@ class ProxyingURLLoaderFactory
InProgressRequest(
ProxyingURLLoaderFactory* factory,
int64_t web_request_id,
int32_t routing_id,
int32_t view_routing_id,
int32_t frame_routing_id,
int32_t network_service_request_id,
uint32_t options,
const network::ResourceRequest& request,
Expand All @@ -56,6 +58,7 @@ class ProxyingURLLoaderFactory
// For CORS preflights.
InProgressRequest(ProxyingURLLoaderFactory* factory,
uint64_t request_id,
int32_t frame_routing_id,
const network::ResourceRequest& request);
~InProgressRequest() override;

Expand Down Expand Up @@ -120,7 +123,8 @@ class ProxyingURLLoaderFactory
network::ResourceRequest request_;
const base::Optional<url::Origin> original_initiator_;
const uint64_t request_id_ = 0;
const int32_t routing_id_ = 0;
const int32_t view_routing_id_ = MSG_ROUTING_NONE;
const int32_t frame_routing_id_ = MSG_ROUTING_NONE;
const int32_t network_service_request_id_ = 0;
const uint32_t options_ = 0;
const net::MutableNetworkTrafficAnnotationTag traffic_annotation_;
Expand Down Expand Up @@ -177,6 +181,8 @@ class ProxyingURLLoaderFactory
WebRequestAPI* web_request_api,
const HandlersMap& intercepted_handlers,
int render_process_id,
int frame_routing_id,
int view_routing_id,
uint64_t* request_id_generator,
std::unique_ptr<extensions::ExtensionNavigationUIData> navigation_ui_data,
base::Optional<int64_t> navigation_id,
Expand All @@ -191,7 +197,6 @@ class ProxyingURLLoaderFactory
// network::mojom::URLLoaderFactory:
void CreateLoaderAndStart(
mojo::PendingReceiver<network::mojom::URLLoader> loader,
int32_t routing_id,
int32_t request_id,
uint32_t options,
const network::ResourceRequest& request,
Expand Down Expand Up @@ -236,6 +241,8 @@ class ProxyingURLLoaderFactory
const HandlersMap& intercepted_handlers_;

const int render_process_id_;
const int frame_routing_id_;
const int view_routing_id_;
uint64_t* request_id_generator_; // managed by ElectronBrowserClient
std::unique_ptr<extensions::ExtensionNavigationUIData> navigation_ui_data_;
base::Optional<int64_t> navigation_id_;
Expand Down

0 comments on commit a1f0bbb

Please sign in to comment.