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++:
```
Optional<URL> url;
if (!data.url.isEmpty()) {
url = context.completeURL(data.url);
}
```
Do we have an equivalent in Gecko?
Right now, in Gecko, I'm having to do this:
```
nsAutoString url;
if (aData.mUrl.WasPassed()) {
auto doc = mWindow->GetExtantDoc();
if (!doc) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsresult rv;
nsCOMPtr<nsIURI> resolvedUri;
rv = NS_NewURI(getter_AddRefs(resolvedUri), aData.mUrl.Value(), nullptr,
doc->GetDocumentURI(), nsContentUtils::GetIOService());
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aData.mUrl.Value());
return nullptr;
}
nsAutoCString utf8href;
nsresult resolveURLRv = resolvedUri->GetSpec(utf8href);
if (NS_FAILED(resolveURLRv)) {
aRv.Throw(NS_ERROR_DOM_BAD_URI);
return nullptr;
}
CopyUTF8toUTF16(utf8href, url);
}
```
Which could maybe be wrapped into a nice utility function and placed somewhere?
Or maybe something like that already exists?
Also, having to use `nsIURI` feels kinda sad when we implement the URL
Standard.... Can we use URL somehow be used as a drop in replacement for
nsIURI?
https://github.com/WebKit/webkit/blob/master/Source/WebCore/page/Navigator.cpp#L123
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform