将信息从Chromium Embedded(Javascript)发送到包含C ++的应用程序 [英] Sending information from Chromium Embedded (Javascript) to a containing C++ application

查看:84
本文介绍了将信息从Chromium Embedded(Javascript)发送到包含C ++的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查看Chromium Embedded Framework示例后,我有一个问题。我需要与窗口的嵌入部分进行本机交互。但是,在CEF示例中,我看到的只是c ++向浏览器发送消息,而不是相反。我想知道是否有任何方法可以从c ++发送来自JavaScript的消息,就像函数一样。

After checking out the Chromium Embedded Framework example I have a question. I need native interaction with the embedded part of my window. However, in the CEF example, all I saw was the c++ sending messages to the browser, not the other way around. I was wondering if there is any way to send a message from JavaScript from c++, like in the way of a function.

我要找的是这样的。点击后,我的网页上有一个按钮。我想尽量减少窗口。有没有办法在CEF中用JavaScript调用一些c ++?

What I am looking for is something like this. I have a button in my webpage that when clicked. I would like to minimize the window. Is there any way to call some c++ from JavaScript in CEF?

推荐答案

最简单的方法:
1.在主流程中(UI进程) - 您可以创建自己的自定义方案处理程序(它也可以绑定到http协议,并通过域绑定不同的处理程序)。
2.从JS方面,您可以使用XMLHttpRequest来调用方案处理程序。它是JS<> Main进程之间IPC的标准机制。

Easiest way: 1. In main process (UI process) - you can create own custom scheme handler (it can be bounded to http protocol too, and distinct handlers by domain). 2. From JS side, you can use XMLHttpRequest to call you scheme handler. It is standard mechanism to IPC between JS<>Main process.

其他方式:
使用V8绑定,但在这种情况下,您需要在两者之间建立自己的IPC渲染器和主要过程。或者使用内置IPC,但请注意它只是以异步方式发送消息。

Other way: Use V8 bindings, but in this case you will need make own IPC between renderer and main process. Or use built-in IPC, but note that it is sends messages only in async way.

这篇关于将信息从Chromium Embedded(Javascript)发送到包含C ++的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆