Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NS_NewURI is now thread-safe

96 views
Skip to first unread message

Valentin Gosu

unread,
Jun 10, 2019, 4:08:39 PM6/10/19
to dev-platform
Hello everyone,

nsIURI has been immutable for a few releases now, meaning once you had one
it was safe to use it on any thread (even change it using nsIURIMutator).
But until recently you couldn't create a new URI off the main thread
(unless you already knew the type of the URI).
A few days ago I closed bug 922464
<https://bugzilla.mozilla.org/show_bug.cgi?id=922464>, which means nsIURI
can now be safely used and created on any thread via NS_NewURI. It also
means nsIProtocolHandler.newURI no longer exists, and if you want to add
any other special scheme to Gecko you should do so in NS_NewURI in
nsNetUtil.cpp

Most of the work happened in bug 1536744
<https://bugzilla.mozilla.org/show_bug.cgi?id=1536744>. This unblocks work
to make make nsIPrincipal thread safe in bug 1443925
<https://bugzilla.mozilla.org/show_bug.cgi?id=1443925>.
I've noticed there are some places that keep URIs around as strings. If
those strings are regularly used to create nsIURIs, I strongly encourage
you to do so from the beginning.

There is still work to be done in order to reduce the number of
implementations we have for nsIURI and resolve our incompatibilities with
the URL spec. Stay tuned.

Let me know if you uncover any issues, or if you have any questions.

Cheers!
--
Valentin

Boris Zbarsky

unread,
Jun 10, 2019, 4:20:49 PM6/10/19
to
On 6/10/19 4:07 PM, Valentin Gosu wrote:
> which means nsIURI
> can now be safely used and created on any thread via NS_NewURI.

That's awesome news!

> and if you want to add any other special scheme to Gecko you should do so in NS_NewURI in
> nsNetUtil.cpp

Here "special" is in the sense of "Parsed as anything other than a basic
nsSimpleURI"?

-Boris

Valentin Gosu

unread,
Jun 10, 2019, 4:43:03 PM6/10/19
to Boris Zbarsky, dev-platform
That's absolutely correct.

nsSimpleURI is the default parser for unknown schemes, and at the moment it
has the downside of not having a hostname. So if need URIs of a certain
scheme to have a hostname, you probably need to add code to create the
correct type - probably an nsStandardURL.

Bobby Holley

unread,
Jun 10, 2019, 5:48:28 PM6/10/19
to Valentin Gosu, Boris Zbarsky, dev-platform
This is awesome work and has been years in the making. Thanks to everyone
involved for getting it over the line!

On Mon, Jun 10, 2019 at 1:42 PM Valentin Gosu <valent...@gmail.com>
wrote:

> On Mon, 10 Jun 2019 at 22:25, Boris Zbarsky <bzba...@mit.edu> wrote:
>
> That's absolutely correct.
>
> nsSimpleURI is the default parser for unknown schemes, and at the moment it
> has the downside of not having a hostname. So if need URIs of a certain
> scheme to have a hostname, you probably need to add code to create the
> correct type - probably an nsStandardURL.
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>

Cameron McCormack

unread,
Jun 10, 2019, 6:49:25 PM6/10/19
to Valentin Gosu, dev-platform
This is going to let us simplify a whole lot of URL handling code in the style system, where we otherwise have to store strings and lazily creating nsIURIs when we're back on the main thread. Thanks so much!

On Mon, Jun 10, 2019, at 1:08 PM, Valentin Gosu wrote:
> Hello everyone,
>
> nsIURI has been immutable for a few releases now, meaning once you had one
> it was safe to use it on any thread (even change it using nsIURIMutator).
> But until recently you couldn't create a new URI off the main thread
> (unless you already knew the type of the URI).
> A few days ago I closed bug 922464
> <https://bugzilla.mozilla.org/show_bug.cgi?id=922464>, which means nsIURI
> can now be safely used and created on any thread via NS_NewURI. It also
> means nsIProtocolHandler.newURI no longer exists, and if you want to add
> any other special scheme to Gecko you should do so in NS_NewURI in
> nsNetUtil.cpp
>
> Most of the work happened in bug 1536744
> <https://bugzilla.mozilla.org/show_bug.cgi?id=1536744>. This unblocks work
> to make make nsIPrincipal thread safe in bug 1443925
> <https://bugzilla.mozilla.org/show_bug.cgi?id=1443925>.
> I've noticed there are some places that keep URIs around as strings. If
> those strings are regularly used to create nsIURIs, I strongly encourage
> you to do so from the beginning.
>
> There is still work to be done in order to reduce the number of
> implementations we have for nsIURI and resolve our incompatibilities with
> the URL spec. Stay tuned.
>
> Let me know if you uncover any issues, or if you have any questions.
>
> Cheers!
> --
> Valentin
0 new messages