You definitely can ... you just need to create an extra layer on top of WebView :: setObjectCallback and WebViewListener :: onCallback using delegates / function pointers.
I wrote a quick class JSDelegate.h ( see it here ), which can be used to connect "onCallback" events directly to C ++ member members.
The basic idea is to support matching callback names to delegates:
typedef std::map<std::wstring, Awesomium::JSDelegate> DelegateMap; DelegateMap _delegateMap;
And call the appropriate function from your WebViewListener :: onCallback:
void MyListener::onCallback(Awesomium::WebView* caller, const std::wstring& objectName, const std::wstring& callbackName, const Awesomium::JSArguments& args) { DelegateMap::iterator i = _delegateMap.find(callbackName); if(i != _delegateMap.end()) i->second(caller, args); }
And then, every time you want to associate a specific C ++ function, you would do it like this:
// Member function we wish to bind, must have this signature for JSDelegate void MyClass::myFunction(Awesomium::WebView* caller, const Awesomium::JSArguments& args) { // handle args here } // Instantiate MyClass instance in C++ MyClass* myClass = new MyClass(); // Create corresponding 'MyClass' object in Javascript webView->createObject(L"MyClass"); // Do the following for each member function: // Bind MyClass::myFunction delegate to MyClass.myFunction in JS _delegateMap[L"myFunction"] = Awesomium::JSDelegate(myClass, &MyClass::myFunction); webView->setObjectCallback(L"MyClass", L"myFunction");
Then you should be able to call MyClass :: myFunction directly from Javascript as follows:
MyClass.myFunction("foo", 1, 2 3)
Hope this helps! I have not tested any code, but I wrote it using the Awesomium v1.6 RC4 SDK .