I am trying to implement window JSBinding by referring to http://code.google.com/p/chromiumembedded/wiki/JavaScriptIntegration#Extensions However function is not being invoked at all. Would you please have a look at the following codes and tell where I am doing wrong ?
CefV8Handler implementation
- Code: Select all
public class HelloV8Handler : CefV8Handler
{
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
{
if (name == "world")
{
returnValue = CefV8Value.CreateString("test();");
exception = "";
return true;
}
returnValue = CefV8Value.CreateUndefined();
exception = "undefined method";
return false;
}
}
RenderProcessHandler implementation
- Code: Select all
public class RenderProcessHandler : CefRenderProcessHandler
{
protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
{
// Retrieve the 'window' object.
var window = context.GetGlobal();
CefV8Handler handler = new HelloV8Handler();
CefV8Value obj = CefV8Value.CreateObject(null);
obj.SetValue("world", CefV8Value.CreateFunction("world", handler), CefV8PropertyAttribute.None);
obj.SetValue("str", CefV8Value.CreateString("hello world!"), CefV8PropertyAttribute.None);
window.SetValue("hello", obj, CefV8PropertyAttribute.None);
base.OnContextCreated(browser, frame, context);
}
}
HTML test page. Results are commented in code.
- Code: Select all
<html>
<body>
<script>
window.hello.world(); // successfull binding but invocation didn't occur.
alert(window.hello.world()); // displays "undefined"
alert(window.hello.str); // displays "hello world!" as expected.
function test()
{
alert('js invocation from v8handler!');
}
</script>
</body>
</html>
Thanks in advance,
albay