I am currently trying to get JavaScript window binding to work. Therefore I derived my ClientApp from CefRenderProcessHandler and implemented my custom OnContextCreatedmethod in the ClientApp.
Sadly the variable is undefined in JavaScript. Whats also strange, is that OnContextCreated is never called. (Or at least the breakpoint never triggers there. Even though I use "--renderer-startup-dialog" and attached the debugger to the render process. As described here: http://www.chromium.org/developers/how-tos/debugging)
Any ideas what I could have done wrong?
Here is the full source-code:
- Code: Select all
// ClientApp.h
class ClientApp : public CView, public CefApp, public CefBrowserProcessHandler, public CefRenderProcessHandler {
public:
ClientApp();
// CefApp methods:
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE { return this; }
// CefBrowserProcessHandler methods:
virtual void OnContextInitialized() OVERRIDE;
// CefRenderProcessHandler methods
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientApp);
};
// ClientApp.cpp
// [...]
void ClientApp::OnContextCreated( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context )
{
// Retrieve the context's window object.
CefRefPtr<CefV8Value> object = context->GetGlobal();
// Create a new V8 string value. See the "Basic JS Types" section below.
CefRefPtr<CefV8Value> str = CefV8Value::CreateString("My Value!");
// Add the string to the window object as "window.myval". See the "JS Objects" section below.
object->SetValue("myval", str, V8_PROPERTY_ATTRIBUTE_NONE);
}
In my HTML-File I simply added:
- Code: Select all
<script language="JavaScript">
alert(window.myval); // Shows an alert box with "My Value!"
</script>
Which always prints "undefined".
Any help would be appreciated.