refactor: ginify protocol (#22812)

This commit is contained in:
Jeremy Apthorp 2020-03-26 10:34:32 -07:00 committed by GitHub
parent b3d3ac4e0f
commit e73d5e3db5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 192 additions and 112 deletions

View file

@ -81,6 +81,7 @@
#include "shell/browser/network_hints_handler_impl.h"
#include "shell/browser/notifications/notification_presenter.h"
#include "shell/browser/notifications/platform_notification_service.h"
#include "shell/browser/protocol_registry.h"
#include "shell/browser/session_preferences.h"
#include "shell/browser/ui/devtools_manager_delegate.h"
#include "shell/browser/web_contents_permission_helper.h"
@ -1162,17 +1163,15 @@ void ElectronBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
NonNetworkURLLoaderFactoryMap* factories) {
content::WebContents* web_contents =
content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
api::Protocol* protocol = api::Protocol::FromWrappedClass(
v8::Isolate::GetCurrent(), web_contents->GetBrowserContext());
content::BrowserContext* context = web_contents->GetBrowserContext();
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
factories->emplace(
extensions::kExtensionScheme,
extensions::CreateExtensionNavigationURLLoaderFactory(
web_contents->GetBrowserContext(),
false /* we don't support extensions::WebViewGuest */));
context, false /* we don't support extensions::WebViewGuest */));
#endif
if (protocol)
protocol->RegisterURLLoaderFactories(factories);
auto* protocol_registry = ProtocolRegistry::FromBrowserContext(context);
protocol_registry->RegisterURLLoaderFactories(factories);
}
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
@ -1231,10 +1230,8 @@ void ElectronBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
content::WebContents::FromRenderFrameHost(frame_host);
if (web_contents) {
api::Protocol* protocol = api::Protocol::FromWrappedClass(
v8::Isolate::GetCurrent(), web_contents->GetBrowserContext());
if (protocol)
protocol->RegisterURLLoaderFactories(factories);
ProtocolRegistry::FromBrowserContext(web_contents->GetBrowserContext())
->RegisterURLLoaderFactories(factories);
}
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
@ -1348,9 +1345,6 @@ bool ElectronBrowserClient::WillCreateURLLoaderFactory(
network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
api::Protocol* protocol =
api::Protocol::FromWrappedClass(isolate, browser_context);
DCHECK(protocol);
auto web_request = api::WebRequest::FromOrCreate(isolate, browser_context);
DCHECK(web_request.get());
@ -1374,12 +1368,14 @@ bool ElectronBrowserClient::WillCreateURLLoaderFactory(
if (header_client)
header_client_receiver = header_client->InitWithNewPipeAndPassReceiver();
auto* protocol_registry =
ProtocolRegistry::FromBrowserContext(browser_context);
new ProxyingURLLoaderFactory(
web_request.get(), protocol->intercept_handlers(), browser_context,
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);
web_request.get(), protocol_registry->intercept_handlers(),
browser_context, 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);
if (bypass_redirect_checks)
*bypass_redirect_checks = true;