HTML5 Desktop/Investigation: Difference between revisions

From base48
imported>Evilissimo
imported>Evilissimo
Line 2: Line 2:


= Javascript Bindings =
= Javascript Bindings =
== Chromium Embedded Framework ==
With the chromium embedded framework it would work like in the example as in the snippet below. The registration of it is performed by calling InitMyJavascriptAPI from the <pre>virtual void didCreateScriptContext( WebKit::WebFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId);</pre>
Callback which is derived from WebKit::WebFrameClient where in CEF OnContextCreated is called which calls the function below.
<pre>class MyV8Handler : public CefV8Handler {
<pre>class MyV8Handler : public CefV8Handler {
public:
public:

Revision as of 06:10, 27 March 2012

Back to Project page

Javascript Bindings

Chromium Embedded Framework

With the chromium embedded framework it would work like in the example as in the snippet below. The registration of it is performed by calling InitMyJavascriptAPI from the

virtual void didCreateScriptContext( WebKit::WebFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId);

Callback which is derived from WebKit::WebFrameClient where in CEF OnContextCreated is called which calls the function below.

class MyV8Handler : public CefV8Handler {
public:
	MyV8Handler(){}
	~MyV8Handler(){}

	 virtual bool Execute(const CefString& name,
                       CefRefPtr<CefV8Value> object,
                       const CefV8ValueList& arguments,
                       CefRefPtr<CefV8Value>& retval,
                       CefString& exception) OVERRIDE {
		if( name == "getOSInfo" ) {
			retval = CefV8Value::CreateString(getOSInfo());
			return true;	
		}
		return false;
	}

	IMPLEMENT_REFCOUNTING(MyV8Handler);
};

void InitMyJavascriptAPI(CefRefPtr<CefBrowser> browser,
                         CefRefPtr<CefFrame> frame,
                         CefRefPtr<CefV8Value> object) {

	// Create a new javascript object
	CefRefPtr<CefV8Value> myAPI = CefV8Value::CreateObject(NULL,NULL);

	// Make my new object accessible via window.myAPI
	object->SetValue("myAPI", myAPI, V8_PROPERTY_ATTRIBUTE_NONE);

	// Add stuff to myAPI

	// Readonly string property
	myAPI->SetValue("version", CefV8Value::CreateString("base48.cefclient 0.1"), V8_PROPERTY_ATTRIBUTE_READONLY );

	// Binding a function
	CefRefPtr<CefV8Handler> handler = new MyV8Handler();
	myAPI->SetValue("getOSInfo", CefV8Value::CreateFunction("getOSInfo", handler), V8_PROPERTY_ATTRIBUTE_NONE);
}