[wpe-webkit] Web Extension Support In WPE

Carlos Garcia Campos cgarcia at igalia.com
Thu Jun 20 00:25:26 PDT 2019


El mié, 19-06-2019 a las 15:33 -0500, Michael Catanzaro escribió:
> Hi Munez,
> 
> On Wed, Jun 19, 2019 at 2:10 PM, Munez Bn <munezbn.dev at gmail.com>
> wrote:
> > I didn't do any changes in webkit or makefiles to install internal 
> > headers.
> 
> I'm really confused then. You are using multiple internal APIs that
> are 
> not defined in any public headers, so you must have somehow made
> some 
> major changes to WebKit to gain access to these APIs.
> 
> On Wed, Jun 19, 2019 at 2:10 PM, Munez Bn <munezbn.dev at gmail.com>
> wrote:
> > 1. The API description of jsc_value_new_function() says that, If
> > we 
> > really want to return a new copy of the boxed type in the callback 
> > function passed as argument to jsc_value_new_function(), then use 
> > #JSC_TYPE_VALUE and return a #JSCValue created with 
> > jsc_value_new_object() that receives the copy as instance
> > parameter. 
> > But jsc_value_new_object() also needs a context so when I tried to 
> > passed jsc_context as user data to callback function, the callback 
> > function threw following error.
> > 
> > JSCValue* jsc_value_new_undefined(JSCContext*): assertion 
> > 'JSC_IS_CONTEXT(context)' failed
> > 
> > Please let me know if i am missing anything. I was planing to 
> > register class in callback function getTestExtObjec().
> 
> OK, this at least looks straightforward. You correctly noticed that
> the 
> JSCContext returned by
> webkit_frame_get_js_context_for_script_world() 
> is returned transfer full, so your code is responsible for taking 
> ownership. You used g_autoptr to hold that ownership, which is good. 
> But you're failing to transfer the ownership from your 
> windowObjectCleared function to the getTestExtObject callback. The
> fix 
> would be to use g_steal_pointer():
> 
> g_autoptr(JSCValue) function = jsc_value_new_function(jsContext, 
> "getTestExtObject", G_CALLBACK(getTestExtObject), 
> g_steal_pointer(&jsContext), NULL, JSC_TYPE_VALUE, 1, G_TYPE_STRING);
> 
> Otherwise, it's deleted before your getTestExtObject() is called.
> Using 
> g_steal_pointer() makes the ownership clear. You could also just not 
> use g_autoptr at all, but then the ownership will not be obvious in
> the 
> code. Either way, once that is fixed you will need to unref it in 
> getTestExtObject() to avoid leaking it.

Right, you are passing the context as callback data, but it's freed at
the time the callback is called. I don't think it's a good idea to pass
the context, though. You can simply use jsc_context_get_current(). That
always work inside function callbacks. The JSCContext won't be the same
as the one you got in window_object_cleared, but the wrapped
JSGlobalObjectRef is.

You have an example of that in the unit tests too, in the function to
get the parent of a GFile (we need to create a new wrapped GFile in the
callback, see:

https://trac.webkit.org/browser/webkit/trunk/Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp#L1640

> Hope that helps,
> 
> Michael
> 
> 
> 
-- 
Carlos Garcia Campos
http://pgp.rediris.es:11371/pks/lookup?op=get&search=0xF3D322D0EC4582C3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://lists.webkit.org/pipermail/webkit-wpe/attachments/20190620/d0e9bfe1/attachment.bin>


More information about the webkit-wpe mailing list