diff options
Diffstat (limited to 'src/core/renderer_host/web_channel_ipc_transport_host.cpp')
-rw-r--r-- | src/core/renderer_host/web_channel_ipc_transport_host.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/core/renderer_host/web_channel_ipc_transport_host.cpp b/src/core/renderer_host/web_channel_ipc_transport_host.cpp index 9ed3749ad..087e0e83b 100644 --- a/src/core/renderer_host/web_channel_ipc_transport_host.cpp +++ b/src/core/renderer_host/web_channel_ipc_transport_host.cpp @@ -96,10 +96,9 @@ void WebChannelIPCTransportHost::sendMessage(const QJsonObject &message) int size = 0; const char *rawData = doc.rawData(&size); content::RenderFrameHost *frame = web_contents()->GetMainFrame(); - mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> webChannelTransport; - frame->GetRemoteAssociatedInterfaces()->GetInterface(&webChannelTransport); qCDebug(log).nospace() << "sending webchannel message to " << frame << ": " << doc; - webChannelTransport->DispatchWebChannelMessage(std::vector<uint8_t>(rawData, rawData + size), m_worldId); + GetWebChannelIPCTransportRemote(frame)->DispatchWebChannelMessage( + std::vector<uint8_t>(rawData, rawData + size), m_worldId); } void WebChannelIPCTransportHost::setWorldId(uint32_t worldId) @@ -116,9 +115,7 @@ void WebChannelIPCTransportHost::setWorldId(content::RenderFrameHost *frame, uin if (!frame->IsRenderFrameLive()) return; qCDebug(log).nospace() << "sending setWorldId(" << worldId << ") message to " << frame; - mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> webChannelTransport; - frame->GetRemoteAssociatedInterfaces()->GetInterface(&webChannelTransport); - webChannelTransport->SetWorldId(worldId); + GetWebChannelIPCTransportRemote(frame)->SetWorldId(worldId); } void WebChannelIPCTransportHost::resetWorldId() @@ -126,9 +123,7 @@ void WebChannelIPCTransportHost::resetWorldId() for (content::RenderFrameHost *frame : web_contents()->GetAllFrames()) { if (!frame->IsRenderFrameLive()) return; - mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> webChannelTransport; - frame->GetRemoteAssociatedInterfaces()->GetInterface(&webChannelTransport); - webChannelTransport->ResetWorldId(); + GetWebChannelIPCTransportRemote(frame)->ResetWorldId(); } } @@ -156,4 +151,25 @@ void WebChannelIPCTransportHost::RenderFrameCreated(content::RenderFrameHost *fr setWorldId(frame, m_worldId); } +void WebChannelIPCTransportHost::RenderFrameDeleted(content::RenderFrameHost *rfh) +{ + m_renderFrames.erase(rfh); +} + +const mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> & +WebChannelIPCTransportHost::GetWebChannelIPCTransportRemote(content::RenderFrameHost *rfh) +{ + auto it = m_renderFrames.find(rfh); + if (it == m_renderFrames.end()) { + mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> remote; + rfh->GetRemoteAssociatedInterfaces()->GetInterface(remote.BindNewEndpointAndPassReceiver()); + it = m_renderFrames.insert(std::make_pair(rfh, std::move(remote))).first; + } else if (it->second.is_bound() && !it->second.is_connected()) { + it->second.reset(); + rfh->GetRemoteAssociatedInterfaces()->GetInterface(&it->second); + } + + return it->second; +} + } // namespace QtWebEngineCore |