HTML5 Desktop/Investigation: Difference between revisions
imported>Evilissimo |
imported>Rmarko (syntax highlight) |
||
(2 intermediate revisions by one other user not shown) | |||
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 | |||
<syntaxhighlight lang="cpp">virtual void didCreateScriptContext( WebKit::WebFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId);</syntaxhighlight> | |||
Callback which is derived from WebKit::WebFrameClient where in CEF OnContextCreated is called which calls the function below. | |||
<syntaxhighlight lang="cpp">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); | |||
}</syntaxhighlight> |
Latest revision as of 18:56, 28 March 2012
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 <syntaxhighlight lang="cpp">virtual void didCreateScriptContext( WebKit::WebFrame*, v8::Handle<v8::Context>, int extensionGroup, int worldId);</syntaxhighlight> Callback which is derived from WebKit::WebFrameClient where in CEF OnContextCreated is called which calls the function below.
<syntaxhighlight lang="cpp">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); }</syntaxhighlight>