[webkit-gtk] Sockets/file descriptors and the web extension

Adrian Perez de Castro aperez at igalia.com
Wed Dec 5 11:51:59 PST 2018

Hello Eric,

On Wed, 05 Dec 2018 14:26:56 -0500, Eric Williams <ericwill at redhat.com> wrote:
> On 12/5/18 1:14 PM, Michael Catanzaro wrote:
> > On Wed, Dec 5, 2018 at 11:11 AM, Eric Williams <ericwill at redhat.com> wrote:
> >> Some preliminary debugging shows that the web extension still holds 
> >> onto the socket/file descriptor used when opening the port in step 1 
> >> -- even though the port has been closed. This causes the error in step 
> >> 4. If no web extension is created (i.e. step 2 is skipped), then no 
> >> error from step 4 happens.
> > 
> > I'm confused and suspect I've misunderstood the scenario. But: why does 
> > WebKit have anything to do with a socket that you create in your own code?
> This is kind of what I'm trying to get at: is it possible that WebKit 
> gets a copy of all open sockets somehow when creating an extension? If 
> this is completely outside the realm of possibility then I'll 
> investigate further.

Are you setting the close-on-exec flag [1] on the file descriptor? If not,
it may be as well that the file descriptor for the socket is being inherited
by the child processes (WebKitNetworProcess, WebKitWebProcess, etc).

On a different note, from the brief description if the use case you gave on
your first e-mail, I think you can probably get things done without using
a WebKitWebExtension at all. Instead of an extension you could:

 - Use WebKitUserContentManager [2] to inject JS scripts that are loaded in
   the context of the Web pages loaded (that is: in the WebKitWebProcess).

 - Use webkit_web_view_run_javascript() [3] to make calls into functionality
   provided by the injected JS code.

 - If you need to communicate back from the Web process, you can use a
   script message handler (also in WebKitUserContentManager) to allow sending
   JS objects to the UI process. Every time one of this is received, it will
   trigger the WebKitUserContentManager::script-message-received signal.

While there are certain things which cannot be easily done with JS injected
code, for many things it does a perfectly fine job, and usually with much
less effort.



[1] https://stackoverflow.com/questions/6125068/what-does-the-fd-cloexec-fcntl-flag-do
[2] https://webkitgtk.org/reference/webkit2gtk/stable/WebKitUserContentManager.html
[3] https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-run-javascript
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.webkit.org/pipermail/webkit-gtk/attachments/20181205/328e7cd7/attachment.bin>

More information about the webkit-gtk mailing list