1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:58:13 +00:00

LibHTML+AK: Move URL completion from Document to AK::URL

Completing a relative URL based on a base URL seems like generally
useful functionality.
This commit is contained in:
Andreas Kling 2019-11-18 22:04:39 +01:00
parent 47326042c5
commit 0405ab91aa
3 changed files with 31 additions and 23 deletions

View file

@ -156,29 +156,7 @@ RefPtr<GraphicsBitmap> Document::background_image() const
URL Document::complete_url(const String& string) const
{
URL url(string);
if (url.is_valid())
return url;
FileSystemPath fspath(m_url.path());
StringBuilder builder;
builder.append('/');
bool document_url_ends_in_slash = m_url.path()[m_url.path().length() - 1] == '/';
for (int i = 0; i < fspath.parts().size(); ++i) {
if (i == fspath.parts().size() - 1 && !document_url_ends_in_slash)
break;
builder.append(fspath.parts()[i]);
builder.append('/');
}
builder.append(string);
auto built = builder.to_string();
fspath = FileSystemPath(built);
url = m_url;
url.set_path(fspath.string());
return url;
return m_url.complete_url(string);
}
void Document::force_layout()