summaryrefslogtreecommitdiffstats
path: root/src/core/renderer
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2018-06-26 13:40:24 +0200
committerMichal Klocek <michal.klocek@qt.io>2018-07-19 07:40:53 +0000
commitdf3681dc6c401f3cebb6e767ef8b8ca4e1a8260b (patch)
treeac6f08476923c5426853b50bf981e6e019535965 /src/core/renderer
parentd82ef0ce217e967ac91f067377ef82803e0eeb5d (diff)
Migrate WebChannel IPC to mojo
Mojoifies: * WebChannelIPCTransport_SetWorldId * WebChannelIPCTransport_Message * WebChannelIPCTransportHost_SendMessage This change is just the simple rewrite of IPC in web channel transport, however ultimate goal here is to use mojo directly in javascript land. Change-Id: Ifcf84659b1d48d99cc4e87849b8a258303e8fedc Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/core/renderer')
-rw-r--r--src/core/renderer/web_channel_ipc_transport.cpp62
-rw-r--r--src/core/renderer/web_channel_ipc_transport.h19
2 files changed, 52 insertions, 29 deletions
diff --git a/src/core/renderer/web_channel_ipc_transport.cpp b/src/core/renderer/web_channel_ipc_transport.cpp
index 70aeabdcf..1f496e810 100644
--- a/src/core/renderer/web_channel_ipc_transport.cpp
+++ b/src/core/renderer/web_channel_ipc_transport.cpp
@@ -51,7 +51,11 @@
#include "gin/wrappable.h"
#include "third_party/blink/public/web/blink.h"
#include "third_party/blink/public/web/web_local_frame.h"
+#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
+#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "v8/include/v8.h"
+#include "services/service_manager/public/cpp/interface_provider.h"
+#include "qtwebengine/browser/qtwebchannel.mojom.h"
#include <QJsonDocument>
@@ -154,9 +158,9 @@ void WebChannelTransport::NativeQtSendMessage(gin::Arguments *args)
int size = 0;
const char *rawData = doc.rawData(&size);
- renderFrame->Send(new WebChannelIPCTransportHost_SendMessage(
- renderFrame->GetRoutingID(),
- std::vector<char>(rawData, rawData + size)));
+ qtwebchannel::mojom::WebChannelTransportHostAssociatedPtr webChannelTransport;
+ renderFrame->GetRemoteAssociatedInterfaces()->GetInterface(&webChannelTransport);
+ webChannelTransport->DispatchWebChannelMessage(std::vector<uint8_t>(rawData, rawData + size));
}
gin::ObjectTemplateBuilder WebChannelTransport::GetObjectTemplateBuilder(v8::Isolate *isolate)
@@ -167,29 +171,50 @@ gin::ObjectTemplateBuilder WebChannelTransport::GetObjectTemplateBuilder(v8::Iso
WebChannelIPCTransport::WebChannelIPCTransport(content::RenderFrame *renderFrame)
: content::RenderFrameObserver(renderFrame)
+ , m_worldId(0)
+ , m_worldInitialized(false)
{
+ renderFrame->GetAssociatedInterfaceRegistry()->AddInterface(
+ base::Bind(&WebChannelIPCTransport::BindRequest, base::Unretained(this)));
}
-void WebChannelIPCTransport::setWorldId(base::Optional<uint> worldId)
+void WebChannelIPCTransport::BindRequest(
+ qtwebchannel::mojom::WebChannelTransportRenderAssociatedRequest request) {
+
+ m_binding.AddBinding(this, std::move(request));
+}
+
+void WebChannelIPCTransport::SetWorldId(uint32_t worldId)
{
- if (m_worldId == worldId)
+ if (m_worldInitialized && m_worldId == worldId)
return;
- if (m_worldId && m_canUseContext)
- WebChannelTransport::Uninstall(render_frame()->GetWebFrame(), *m_worldId);
+ if (m_worldInitialized && m_canUseContext)
+ WebChannelTransport::Uninstall(render_frame()->GetWebFrame(), m_worldId);
+ m_worldInitialized = true;
m_worldId = worldId;
- if (m_worldId && m_canUseContext)
- WebChannelTransport::Install(render_frame()->GetWebFrame(), *m_worldId);
+ if (m_canUseContext)
+ WebChannelTransport::Install(render_frame()->GetWebFrame(), m_worldId);
+}
+
+void WebChannelIPCTransport::ResetWorldId()
+{
+ if (m_worldInitialized && m_canUseContext)
+ WebChannelTransport::Uninstall(render_frame()->GetWebFrame(), m_worldId);
+
+ m_worldInitialized = false;
+ m_worldId = 0;
}
-void WebChannelIPCTransport::dispatchWebChannelMessage(const std::vector<char> &binaryJson, uint worldId)
+void WebChannelIPCTransport::DispatchWebChannelMessage(const std::vector<uint8_t> &binaryJson, uint32_t worldId)
{
DCHECK(m_canUseContext);
DCHECK(m_worldId == worldId);
- QJsonDocument doc = QJsonDocument::fromRawData(binaryJson.data(), binaryJson.size(), QJsonDocument::BypassValidation);
+ QJsonDocument doc = QJsonDocument::fromRawData(reinterpret_cast<const char *>(binaryJson.data()),
+ binaryJson.size(), QJsonDocument::BypassValidation);
DCHECK(doc.isObject());
QByteArray json = doc.toJson(QJsonDocument::Compact);
@@ -241,22 +266,11 @@ void WebChannelIPCTransport::DidClearWindowObject()
{
if (!m_canUseContext) {
m_canUseContext = true;
- if (m_worldId)
- WebChannelTransport::Install(render_frame()->GetWebFrame(), *m_worldId);
+ if (m_worldInitialized)
+ WebChannelTransport::Install(render_frame()->GetWebFrame(), m_worldId);
}
}
-bool WebChannelIPCTransport::OnMessageReceived(const IPC::Message &message)
-{
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(WebChannelIPCTransport, message)
- IPC_MESSAGE_HANDLER(WebChannelIPCTransport_SetWorldId, setWorldId)
- IPC_MESSAGE_HANDLER(WebChannelIPCTransport_Message, dispatchWebChannelMessage)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
void WebChannelIPCTransport::OnDestruct()
{
delete this;
diff --git a/src/core/renderer/web_channel_ipc_transport.h b/src/core/renderer/web_channel_ipc_transport.h
index 19494360a..178c20ed1 100644
--- a/src/core/renderer/web_channel_ipc_transport.h
+++ b/src/core/renderer/web_channel_ipc_transport.h
@@ -41,30 +41,39 @@
#define WEB_CHANNEL_IPC_TRANSPORT_H
#include "content/public/renderer/render_frame_observer.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
+#include "mojo/public/cpp/bindings/associated_binding_set.h"
+#include "qtwebengine/browser/qtwebchannel.mojom.h"
#include <QtCore/qglobal.h>
namespace QtWebEngineCore {
-class WebChannelIPCTransport : private content::RenderFrameObserver {
+class WebChannelIPCTransport: private content::RenderFrameObserver,
+ public qtwebchannel::mojom::WebChannelTransportRender {
public:
WebChannelIPCTransport(content::RenderFrame *);
private:
- void setWorldId(base::Optional<uint> worldId);
- void dispatchWebChannelMessage(const std::vector<char> &binaryJson, uint worldId);
+ // qtwebchannel::mojom::WebChannelTransportRender
+ void SetWorldId(uint32_t worldId) override;
+ void ResetWorldId() override;
+ void DispatchWebChannelMessage(const std::vector<uint8_t>& binaryJson, uint32_t worldId) override;
// RenderFrameObserver
void WillReleaseScriptContext(v8::Local<v8::Context> context, int worldId) override;
void DidClearWindowObject() override;
- bool OnMessageReceived(const IPC::Message &message) override;
void OnDestruct() override;
+ void BindRequest(qtwebchannel::mojom::WebChannelTransportRenderAssociatedRequest request);
+private:
// The worldId from our WebChannelIPCTransportHost or empty when there is no
// WebChannelIPCTransportHost.
- base::Optional<uint> m_worldId;
+ uint32_t m_worldId;
+ bool m_worldInitialized;
// True means it's currently OK to manipulate the frame's script context.
bool m_canUseContext = false;
+ mojo::AssociatedBindingSet<qtwebchannel::mojom::WebChannelTransportRender> m_binding;
};
} // namespace