On Thu, Jul 11, 2019 at 10:57:05PM -0700, mcace...@mozilla.com wrote:
Was looking at how WebKit implements the WebShare API, and they have this nice 
method `completeURL(str)` [1] that resolved URLs relative to, I guess, the 
`Document` object (or whatever context is). So they can basically do this c++:
...
Right now, in Gecko, I'm having to do this:

Most of the overhead in this has nothing to do with resolving the URIs, so much as error checking. That said, there are a few ways to make it simpler. If you really need a UTF-16 string, you can do something like:

 nsAutoCString utf8URI;
 MOZ_TRY(doc->GetDocumentURI()->Resolve(aData.mUrl.Value()));

 NS_ConvertUTF8toUTF16 uri(utf8URI);

Though the general preference should be to keep URIs stored as nsIURIs rather than strings wherever possible, which means just:

 nsCOMPtr<nsIURI> uri;
MOZ_TRY(NS_NewURI(getter_AddRefs(uri), aData.mUrl.Value(), doc->GetDocumentURI()));

There really isn't a need to pass a reference to the IO service to NS_NewURI anymore. Even if you happened to have a handy copy, the argument isn't even used anymore.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to