[wpe-webkit] Web Extension Support In WPE

Carlos Garcia Campos cgarcia at igalia.com
Fri Jun 21 02:55:05 PDT 2019


El vie, 21-06-2019 a las 12:55 +0530, Munez Bn escribió:
> Hello Again,
> 
> I was trying to use jsc_class_add_constructor() like it was used
> in TestJSC.cpp. Earlier I tried only registering JSC class and adding
> method/properties to JSC class which worked fine for me.
> With constructor  approach, when I call  getPath(), it
> says G_IS_FILE(file) check failed. Not sure who is freeing this GFile
> object. I tried this in both javascript
> and jsc_context_evaluate() but same issue.  Instead of returning
> GFile object, if I return ref of GFile object  in constructor
> callback, then it works fine. But in TestJSC.cpp. we do not return
> ref the GFile in constructor callback.  

What version of WebKit are you using? That was a known bug that
recently fixed in 2.24.1. See:

https://bugs.webkit.org/show_bug.cgi?id=195206

>     JSCClass* gFileClass = jsc_context_register_class(js_context,
> "GFile", nullptr, nullptr, nullptr);
>     jsc_class_add_method (gFileClass, "getPath", G_CALLBACK
> (js_get_gfile_path), NULL, NULL, G_TYPE_STRING, 0);
> 
>     JSCValue *constructor = jsc_class_add_constructor(gFileClass,
> nullptr, G_CALLBACK(createGFile), nullptr, nullptr, G_TYPE_OBJECT, 1,
> G_TYPE_STRING);
>     jsc_context_set_value(js_context, jsc_class_get_name(gFileClass),
> constructor);
> 
>   static GFile* createGFile(const char* path, gpointer user_data)
>  {
>     GFile* file = g_file_new_for_path(path);
>     return file;
>     //return G_FILE(g_object_ref(file));    ---> If i return like
> this then it works as expected.
>  }
> 
> static char* js_get_gfile_path (GFile* file, gpointer usr_data)
> {
>     char *path = nullptr;
>     if(G_IS_FILE(file))                      ------> this is false if
> I don't ref and return in  createGFile  
>         path = g_file_get_path (file);
>      return path;
> }
> 
> Thanks & Regards
> Munez
> 
> On Thu, Jun 20, 2019 at 11:29 PM Munez Bn <munezbn.dev at gmail.com>
> wrote:
> > Thanks Michael & Carlos for all your suggestions. It was very
> > helpful. I am able to return native objects and have better
> > understanding of JSC APi now :)
> > I will update my stack-overflow post.
> > 
> > Please note that when I tried initially, my sample extension was
> > stored in Tools/MiniBrowser/gtk/TestExtension/CMakeLists.txt and in
> > Extension's CMakeLists.txt I had exported all the internal include
> > paths. Also Some function I declaration locally in extension file.
> > I will do all the cleanup and do it in a clean way now.
> > 
> > Cheers..
> > Munez
> > 
> > On Thu, Jun 20, 2019 at 12:55 PM Carlos Garcia Campos <
> > cgarcia at igalia.com> wrote:
> > > 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/20190621/1fe25e4d/attachment.bin>


More information about the webkit-wpe mailing list