[webkit-help] Extending JavascriptCore
Christian Frost
cf at cfrost.dk
Thu Feb 21 23:32:14 PST 2013
Hi
I have a question on how to extent the JavascriptCore. My example is
similar to the one found at the bottom at the following site:
http://rvr.typepad.com/wind/2011/10/webkit-extending-javascript-1.html
However, I use WebKit2 which may cause that my WebKitWebView does not
have the "window-object-cleared" signal. Therefore it cannot be
connected. I have tried to "hook" it to the "resource-load-started"
with the following callback function:
static void resource_load_started_cb(WebKitWebView *web_view,
WebKitWebResource *resource, WebKitURIRequest *request, gpointer
user_data)
{
JSGlobalContextRef * context
=webkit_web_view_get_javascript_global_context(web_view);
JSClassRef classDef = JSClassCreate(&class_def);
JSObjectRef classObj = JSObjectMake(context, classDef, context);
JSObjectRef globalObj = JSContextGetGlobalObject(context);
JSStringRef str = JSStringCreateWithUTF8CString("CustomClass");
JSObjectSetProperty(context, globalObj, str, classObj,
kJSPropertyAttributeNone, NULL);
}
However, when I use my CustomClass in Javascript, WebKit cannot find the class.
Can someone guide me how to do this? Currently I use the Minibrowser
as a sample program to implement it.
Regards,
Christian
More information about the webkit-help
mailing list