Make ElectronBrowser mojo interface frame associated. (#32734)

This commit is contained in:
marekharanczyk 2022-02-08 17:33:21 +01:00 committed by GitHub
parent 58af7d2a9a
commit e119da8ce2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 32 deletions

View file

@ -1450,6 +1450,12 @@ bool ElectronBrowserClient::PreSpawnChild(sandbox::TargetPolicy* policy,
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
void BindElectronBrowser(
mojo::PendingAssociatedReceiver<electron::mojom::ElectronBrowser> receiver,
content::RenderFrameHost* frame_host) {
ElectronBrowserHandlerImpl::Create(frame_host, std::move(receiver));
}
bool ElectronBrowserClient::BindAssociatedReceiverFromFrame( bool ElectronBrowserClient::BindAssociatedReceiverFromFrame(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const std::string& interface_name, const std::string& interface_name,
@ -1461,6 +1467,13 @@ bool ElectronBrowserClient::BindAssociatedReceiverFromFrame(
render_frame_host); render_frame_host);
return true; return true;
} }
if (interface_name == electron::mojom::ElectronBrowser::Name_) {
BindElectronBrowser(
mojo::PendingAssociatedReceiver<electron::mojom::ElectronBrowser>(
std::move(*handle)),
render_frame_host);
return true;
}
#if BUILDFLAG(ENABLE_PRINTING) #if BUILDFLAG(ENABLE_PRINTING)
if (interface_name == printing::mojom::PrintManagerHost::Name_) { if (interface_name == printing::mojom::PrintManagerHost::Name_) {
mojo::PendingAssociatedReceiver<printing::mojom::PrintManagerHost> receiver( mojo::PendingAssociatedReceiver<printing::mojom::PrintManagerHost> receiver(
@ -1522,12 +1535,6 @@ void ElectronBrowserClient::BindHostReceiverForRenderer(
#endif #endif
} }
void BindElectronBrowser(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<electron::mojom::ElectronBrowser> receiver) {
ElectronBrowserHandlerImpl::Create(frame_host, std::move(receiver));
}
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
void BindMimeHandlerService( void BindMimeHandlerService(
content::RenderFrameHost* frame_host, content::RenderFrameHost* frame_host,
@ -1576,8 +1583,6 @@ void ElectronBrowserClient::RegisterBrowserInterfaceBindersForFrame(
base::BindRepeating(&BindNetworkHintsHandler)); base::BindRepeating(&BindNetworkHintsHandler));
map->Add<blink::mojom::BadgeService>( map->Add<blink::mojom::BadgeService>(
base::BindRepeating(&badging::BadgeManager::BindFrameReceiver)); base::BindRepeating(&badging::BadgeManager::BindFrameReceiver));
map->Add<electron::mojom::ElectronBrowser>(
base::BindRepeating(&BindElectronBrowser));
map->Add<blink::mojom::KeyboardLockService>(base::BindRepeating( map->Add<blink::mojom::KeyboardLockService>(base::BindRepeating(
&content::KeyboardLockServiceImpl::CreateMojoService)); &content::KeyboardLockServiceImpl::CreateMojoService));
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)

View file

@ -15,7 +15,7 @@
namespace electron { namespace electron {
ElectronBrowserHandlerImpl::ElectronBrowserHandlerImpl( ElectronBrowserHandlerImpl::ElectronBrowserHandlerImpl(
content::RenderFrameHost* frame_host, content::RenderFrameHost* frame_host,
mojo::PendingReceiver<mojom::ElectronBrowser> receiver) mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver)
: render_process_id_(frame_host->GetProcess()->GetID()), : render_process_id_(frame_host->GetProcess()->GetID()),
render_frame_id_(frame_host->GetRoutingID()) { render_frame_id_(frame_host->GetRoutingID()) {
content::WebContents* web_contents = content::WebContents* web_contents =
@ -135,7 +135,7 @@ content::RenderFrameHost* ElectronBrowserHandlerImpl::GetRenderFrameHost() {
// static // static
void ElectronBrowserHandlerImpl::Create( void ElectronBrowserHandlerImpl::Create(
content::RenderFrameHost* frame_host, content::RenderFrameHost* frame_host,
mojo::PendingReceiver<mojom::ElectronBrowser> receiver) { mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver) {
new ElectronBrowserHandlerImpl(frame_host, std::move(receiver)); new ElectronBrowserHandlerImpl(frame_host, std::move(receiver));
} }
} // namespace electron } // namespace electron

View file

@ -23,10 +23,11 @@ class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
public: public:
explicit ElectronBrowserHandlerImpl( explicit ElectronBrowserHandlerImpl(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<mojom::ElectronBrowser> receiver); mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver);
static void Create(content::RenderFrameHost* frame_host, static void Create(
mojo::PendingReceiver<mojom::ElectronBrowser> receiver); content::RenderFrameHost* frame_host,
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver);
// disable copy // disable copy
ElectronBrowserHandlerImpl(const ElectronBrowserHandlerImpl&) = delete; ElectronBrowserHandlerImpl(const ElectronBrowserHandlerImpl&) = delete;
@ -75,7 +76,7 @@ class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
const int render_process_id_; const int render_process_id_;
const int render_frame_id_; const int render_frame_id_;
mojo::Receiver<mojom::ElectronBrowser> receiver_{this}; mojo::AssociatedReceiver<mojom::ElectronBrowser> receiver_{this};
base::WeakPtrFactory<ElectronBrowserHandlerImpl> weak_factory_{this}; base::WeakPtrFactory<ElectronBrowserHandlerImpl> weak_factory_{this};
}; };

View file

@ -22,7 +22,7 @@
#include "shell/common/node_bindings.h" #include "shell/common/node_bindings.h"
#include "shell/common/node_includes.h" #include "shell/common/node_includes.h"
#include "shell/common/v8_value_serializer.h" #include "shell/common/v8_value_serializer.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_message_port_converter.h" #include "third_party/blink/public/web/web_message_port_converter.h"
@ -59,8 +59,8 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
v8::Global<v8::Context>(isolate, isolate->GetCurrentContext()); v8::Global<v8::Context>(isolate, isolate->GetCurrentContext());
weak_context_.SetWeak(); weak_context_.SetWeak();
render_frame->GetBrowserInterfaceBroker()->GetInterface( render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
electron_browser_remote_.BindNewPipeAndPassReceiver()); &electron_browser_remote_);
} }
void OnDestruct() override { electron_browser_remote_.reset(); } void OnDestruct() override { electron_browser_remote_.reset(); }
@ -223,7 +223,8 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
} }
v8::Global<v8::Context> weak_context_; v8::Global<v8::Context> weak_context_;
mojo::Remote<electron::mojom::ElectronBrowser> electron_browser_remote_; mojo::AssociatedRemote<electron::mojom::ElectronBrowser>
electron_browser_remote_;
}; };
gin::WrapperInfo IPCRenderer::kWrapperInfo = {gin::kEmbedderNativeGin}; gin::WrapperInfo IPCRenderer::kWrapperInfo = {gin::kEmbedderNativeGin};

View file

@ -34,7 +34,7 @@
#include "shell/renderer/api/electron_api_context_bridge.h" #include "shell/renderer/api/electron_api_context_bridge.h"
#include "shell/renderer/api/electron_api_spell_check_client.h" #include "shell/renderer/api/electron_api_spell_check_client.h"
#include "shell/renderer/renderer_client_base.h" #include "shell/renderer/renderer_client_base.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/page/page_zoom.h" #include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/common/web_cache/web_cache_resource_type_stats.h" #include "third_party/blink/public/common/web_cache/web_cache_resource_type_stats.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h" #include "third_party/blink/public/common/web_preferences/web_preferences.h"
@ -453,9 +453,9 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
if (!MaybeGetRenderFrame(isolate, "setZoomLevel", &render_frame)) if (!MaybeGetRenderFrame(isolate, "setZoomLevel", &render_frame))
return; return;
mojo::Remote<mojom::ElectronBrowser> browser_remote; mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
render_frame->GetBrowserInterfaceBroker()->GetInterface( render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
browser_remote.BindNewPipeAndPassReceiver()); &browser_remote);
browser_remote->SetTemporaryZoomLevel(level); browser_remote->SetTemporaryZoomLevel(level);
} }
@ -465,9 +465,9 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
if (!MaybeGetRenderFrame(isolate, "getZoomLevel", &render_frame)) if (!MaybeGetRenderFrame(isolate, "getZoomLevel", &render_frame))
return result; return result;
mojo::Remote<mojom::ElectronBrowser> browser_remote; mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
render_frame->GetBrowserInterfaceBroker()->GetInterface( render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
browser_remote.BindNewPipeAndPassReceiver()); &browser_remote);
browser_remote->DoGetZoomLevel(&result); browser_remote->DoGetZoomLevel(&result);
return result; return result;
} }

View file

@ -22,7 +22,7 @@
#include "shell/common/options_switches.h" #include "shell/common/options_switches.h"
#include "shell/common/world_ids.h" #include "shell/common/world_ids.h"
#include "shell/renderer/renderer_client_base.h" #include "shell/renderer/renderer_client_base.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h" #include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/platform/web_isolated_world_info.h" #include "third_party/blink/public/platform/web_isolated_world_info.h"
#include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/blink.h"
@ -149,9 +149,8 @@ void ElectronRenderFrameObserver::DraggableRegionsChanged() {
regions.push_back(std::move(region)); regions.push_back(std::move(region));
} }
mojo::Remote<mojom::ElectronBrowser> browser_remote; mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
render_frame_->GetBrowserInterfaceBroker()->GetInterface( render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(&browser_remote);
browser_remote.BindNewPipeAndPassReceiver());
browser_remote->UpdateDraggableRegions(std::move(regions)); browser_remote->UpdateDraggableRegions(std::move(regions));
} }
@ -169,9 +168,9 @@ void ElectronRenderFrameObserver::OnDestruct() {
void ElectronRenderFrameObserver::DidMeaningfulLayout( void ElectronRenderFrameObserver::DidMeaningfulLayout(
blink::WebMeaningfulLayout layout_type) { blink::WebMeaningfulLayout layout_type) {
if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) { if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
mojo::Remote<mojom::ElectronBrowser> browser_remote; mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
render_frame_->GetBrowserInterfaceBroker()->GetInterface( render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(
browser_remote.BindNewPipeAndPassReceiver()); &browser_remote);
browser_remote->OnFirstNonEmptyLayout(); browser_remote->OnFirstNonEmptyLayout();
} }
} }