Make ElectronBrowser mojo interface frame associated. (#32734)
This commit is contained in:
parent
58af7d2a9a
commit
e119da8ce2
6 changed files with 38 additions and 32 deletions
|
@ -1450,6 +1450,12 @@ bool ElectronBrowserClient::PreSpawnChild(sandbox::TargetPolicy* policy,
|
|||
}
|
||||
#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(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
const std::string& interface_name,
|
||||
|
@ -1461,6 +1467,13 @@ bool ElectronBrowserClient::BindAssociatedReceiverFromFrame(
|
|||
render_frame_host);
|
||||
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 (interface_name == printing::mojom::PrintManagerHost::Name_) {
|
||||
mojo::PendingAssociatedReceiver<printing::mojom::PrintManagerHost> receiver(
|
||||
|
@ -1522,12 +1535,6 @@ void ElectronBrowserClient::BindHostReceiverForRenderer(
|
|||
#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)
|
||||
void BindMimeHandlerService(
|
||||
content::RenderFrameHost* frame_host,
|
||||
|
@ -1576,8 +1583,6 @@ void ElectronBrowserClient::RegisterBrowserInterfaceBindersForFrame(
|
|||
base::BindRepeating(&BindNetworkHintsHandler));
|
||||
map->Add<blink::mojom::BadgeService>(
|
||||
base::BindRepeating(&badging::BadgeManager::BindFrameReceiver));
|
||||
map->Add<electron::mojom::ElectronBrowser>(
|
||||
base::BindRepeating(&BindElectronBrowser));
|
||||
map->Add<blink::mojom::KeyboardLockService>(base::BindRepeating(
|
||||
&content::KeyboardLockServiceImpl::CreateMojoService));
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace electron {
|
||||
ElectronBrowserHandlerImpl::ElectronBrowserHandlerImpl(
|
||||
content::RenderFrameHost* frame_host,
|
||||
mojo::PendingReceiver<mojom::ElectronBrowser> receiver)
|
||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver)
|
||||
: render_process_id_(frame_host->GetProcess()->GetID()),
|
||||
render_frame_id_(frame_host->GetRoutingID()) {
|
||||
content::WebContents* web_contents =
|
||||
|
@ -135,7 +135,7 @@ content::RenderFrameHost* ElectronBrowserHandlerImpl::GetRenderFrameHost() {
|
|||
// static
|
||||
void ElectronBrowserHandlerImpl::Create(
|
||||
content::RenderFrameHost* frame_host,
|
||||
mojo::PendingReceiver<mojom::ElectronBrowser> receiver) {
|
||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver) {
|
||||
new ElectronBrowserHandlerImpl(frame_host, std::move(receiver));
|
||||
}
|
||||
} // namespace electron
|
||||
|
|
|
@ -23,10 +23,11 @@ class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
|
|||
public:
|
||||
explicit ElectronBrowserHandlerImpl(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
mojo::PendingReceiver<mojom::ElectronBrowser> receiver);
|
||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver);
|
||||
|
||||
static void Create(content::RenderFrameHost* frame_host,
|
||||
mojo::PendingReceiver<mojom::ElectronBrowser> receiver);
|
||||
static void Create(
|
||||
content::RenderFrameHost* frame_host,
|
||||
mojo::PendingAssociatedReceiver<mojom::ElectronBrowser> receiver);
|
||||
|
||||
// disable copy
|
||||
ElectronBrowserHandlerImpl(const ElectronBrowserHandlerImpl&) = delete;
|
||||
|
@ -75,7 +76,7 @@ class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
|
|||
const int render_process_id_;
|
||||
const int render_frame_id_;
|
||||
|
||||
mojo::Receiver<mojom::ElectronBrowser> receiver_{this};
|
||||
mojo::AssociatedReceiver<mojom::ElectronBrowser> receiver_{this};
|
||||
|
||||
base::WeakPtrFactory<ElectronBrowserHandlerImpl> weak_factory_{this};
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "shell/common/node_bindings.h"
|
||||
#include "shell/common/node_includes.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_message_port_converter.h"
|
||||
|
||||
|
@ -59,8 +59,8 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
|||
v8::Global<v8::Context>(isolate, isolate->GetCurrentContext());
|
||||
weak_context_.SetWeak();
|
||||
|
||||
render_frame->GetBrowserInterfaceBroker()->GetInterface(
|
||||
electron_browser_remote_.BindNewPipeAndPassReceiver());
|
||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
&electron_browser_remote_);
|
||||
}
|
||||
|
||||
void OnDestruct() override { electron_browser_remote_.reset(); }
|
||||
|
@ -223,7 +223,8 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer>,
|
|||
}
|
||||
|
||||
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};
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "shell/renderer/api/electron_api_context_bridge.h"
|
||||
#include "shell/renderer/api/electron_api_spell_check_client.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/web_cache/web_cache_resource_type_stats.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))
|
||||
return;
|
||||
|
||||
mojo::Remote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame->GetBrowserInterfaceBroker()->GetInterface(
|
||||
browser_remote.BindNewPipeAndPassReceiver());
|
||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
&browser_remote);
|
||||
browser_remote->SetTemporaryZoomLevel(level);
|
||||
}
|
||||
|
||||
|
@ -465,9 +465,9 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
|||
if (!MaybeGetRenderFrame(isolate, "getZoomLevel", &render_frame))
|
||||
return result;
|
||||
|
||||
mojo::Remote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame->GetBrowserInterfaceBroker()->GetInterface(
|
||||
browser_remote.BindNewPipeAndPassReceiver());
|
||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
&browser_remote);
|
||||
browser_remote->DoGetZoomLevel(&result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "shell/common/options_switches.h"
|
||||
#include "shell/common/world_ids.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/platform/web_isolated_world_info.h"
|
||||
#include "third_party/blink/public/web/blink.h"
|
||||
|
@ -149,9 +149,8 @@ void ElectronRenderFrameObserver::DraggableRegionsChanged() {
|
|||
regions.push_back(std::move(region));
|
||||
}
|
||||
|
||||
mojo::Remote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame_->GetBrowserInterfaceBroker()->GetInterface(
|
||||
browser_remote.BindNewPipeAndPassReceiver());
|
||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(&browser_remote);
|
||||
browser_remote->UpdateDraggableRegions(std::move(regions));
|
||||
}
|
||||
|
||||
|
@ -169,9 +168,9 @@ void ElectronRenderFrameObserver::OnDestruct() {
|
|||
void ElectronRenderFrameObserver::DidMeaningfulLayout(
|
||||
blink::WebMeaningfulLayout layout_type) {
|
||||
if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
|
||||
mojo::Remote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame_->GetBrowserInterfaceBroker()->GetInterface(
|
||||
browser_remote.BindNewPipeAndPassReceiver());
|
||||
mojo::AssociatedRemote<mojom::ElectronBrowser> browser_remote;
|
||||
render_frame_->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
&browser_remote);
|
||||
browser_remote->OnFirstNonEmptyLayout();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue