Xilium CefGlue 利用XHR实现JS调用C#方法

http://www.wa.com/26359.htmlhtml

 

引言:Xilium CefGlue是个不错的cef扩展工程,托管地址在这里 https://bitbucket.org/xilium/xilium.cefglue/wiki/Homeweb

固然它还有不少工做要作,这里介绍一下怎样利用XHR实现Js调用c#方法。代码已经在官方Demo里,只是没有中文资料,英文资料也几乎没有,这里只是把它挖出来说一下,本人毫无技术含量。ps:感谢热心的@dmitry.azaraev邮件耐心回复。c#

本文参考自 http://www.cnblogs.com/liulun/archive/2013/03/18/2874276.html,建议先阅读该系列教程。浏览器

什么是XHRdom

XMLHttpRequest (XHR) is an API available to web browser scripting languages such as JavaScript. It is used to send HTTP or HTTPSrequests to a web server and load the server response data back into the script.[1] Development versions of all major browsers support URI schemes beyond http: and https:, in particular, blob: URLs are supported.[2]函数

在这里,XHR能够向CefGlue浏览器发送请求,并接收回复,简单的字符串便可经过Post传递,若是是复杂对象,能够使用Json转换后传递。spa

CefGlue提供的APIserver

RegisterSchemeHandlerFactory(string schemeName, string domainName, CefSchemeHandlerFactory factory)htm

该方法位于CefRuntime,在启动Initialize后使用。其向浏览器注册一个Scheme处理工厂。对象

三个参数:

schemeName:scheme名;

domainName:使用域 的名称,这一个参数比较重要,在js中咱们须要向这个地址发送Post请求,能够随便填,好比 “testdomain”,那么在js中请求的地址是 “http://testdomain/”;

factory:处理工厂,须要来装配一个处理handle。

C#端须要作的两项工做

1.新建一个类DumpRequestResourceHandler,继承自CefResourceHandler,有六个函数须要咱们继承,这里只用到前面三个。

相关文章
相关标签/搜索