mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
LibWeb: Move url_origin() to URL/URL.{cpp,h}
This commit is contained in:
parent
93405b4aff
commit
c380d2cfdc
3 changed files with 37 additions and 25 deletions
|
@ -25,6 +25,7 @@
|
|||
#include <LibWeb/Layout/InitialContainingBlock.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/URL/URL.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -39,30 +40,6 @@ static bool url_matches_about_blank(AK::URL const& url)
|
|||
&& url.host().is_null();
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#concept-url-origin
|
||||
static HTML::Origin url_origin(AK::URL const& url)
|
||||
{
|
||||
// FIXME: Move this whole function somewhere better.
|
||||
|
||||
if (url.scheme() == "blob"sv) {
|
||||
// FIXME: Implement
|
||||
return HTML::Origin {};
|
||||
}
|
||||
|
||||
if (url.scheme().is_one_of("ftp"sv, "http"sv, "https"sv, "ws"sv, "wss"sv)) {
|
||||
// Return the tuple origin (url’s scheme, url’s host, url’s port, null).
|
||||
return HTML::Origin(url.scheme(), url.host(), url.port().value_or(0));
|
||||
}
|
||||
|
||||
if (url.scheme() == "file"sv) {
|
||||
// Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
|
||||
// Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
|
||||
return HTML::Origin(url.scheme(), String(), 0);
|
||||
}
|
||||
|
||||
return HTML::Origin {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsers.html#determining-the-origin
|
||||
HTML::Origin determine_the_origin(BrowsingContext const& browsing_context, Optional<AK::URL> url, SandboxingFlagSet sandbox_flags, Optional<HTML::Origin> invocation_origin)
|
||||
{
|
||||
|
@ -88,7 +65,7 @@ HTML::Origin determine_the_origin(BrowsingContext const& browsing_context, Optio
|
|||
}
|
||||
|
||||
// 5. Return url's origin.
|
||||
return url_origin(*url);
|
||||
return URL::url_origin(*url);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-top-level-browsing-context
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue