mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibWeb: Update HTMLHyperlinkElementUtils to use navigables
This commit is contained in:
parent
857537f90c
commit
c7a6d418d7
1 changed files with 23 additions and 42 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <AK/URLParser.h>
|
#include <AK/URLParser.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/HTML/HTMLHyperlinkElementUtils.h>
|
#include <LibWeb/HTML/HTMLHyperlinkElementUtils.h>
|
||||||
|
#include <LibWeb/HTML/Navigable.h>
|
||||||
#include <LibWeb/Loader/FrameLoader.h>
|
#include <LibWeb/Loader/FrameLoader.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -472,50 +473,41 @@ bool HTMLHyperlinkElementUtils::cannot_navigate() const
|
||||||
// https://html.spec.whatwg.org/multipage/links.html#following-hyperlinks-2
|
// https://html.spec.whatwg.org/multipage/links.html#following-hyperlinks-2
|
||||||
void HTMLHyperlinkElementUtils::follow_the_hyperlink(Optional<DeprecatedString> hyperlink_suffix)
|
void HTMLHyperlinkElementUtils::follow_the_hyperlink(Optional<DeprecatedString> hyperlink_suffix)
|
||||||
{
|
{
|
||||||
// To follow the hyperlink created by an element subject, given an optional hyperlinkSuffix (default null):
|
|
||||||
|
|
||||||
// 1. If subject cannot navigate, then return.
|
// 1. If subject cannot navigate, then return.
|
||||||
if (cannot_navigate())
|
if (cannot_navigate())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// FIXME: 2. Let replace be false.
|
// 2. Let replace be false.
|
||||||
|
[[maybe_unused]] auto replace = false;
|
||||||
|
|
||||||
// 3. Let source be subject's node document's browsing context.
|
// 3. Let targetAttributeValue be the empty string.
|
||||||
auto* source = hyperlink_element_utils_document().browsing_context();
|
DeprecatedString target_attribute_value;
|
||||||
if (!source)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 4. Let targetAttributeValue be the empty string.
|
// 4. If subject is an a or area element, then set targetAttributeValue to the result of getting an element's target given subject.
|
||||||
// 5. If subject is an a or area element, then set targetAttributeValue to
|
target_attribute_value = hyperlink_element_utils_get_an_elements_target();
|
||||||
// the result of getting an element's target given subject.
|
|
||||||
DeprecatedString target_attribute_value = hyperlink_element_utils_get_an_elements_target();
|
|
||||||
|
|
||||||
// 6. Let noopener be the result of getting an element's noopener with subject and targetAttributeValue.
|
// 5. Let noopener be the result of getting an element's noopener with subject and targetAttributeValue.
|
||||||
auto noopener = hyperlink_element_utils_get_an_elements_noopener(target_attribute_value);
|
auto noopener = hyperlink_element_utils_get_an_elements_noopener(target_attribute_value);
|
||||||
|
|
||||||
// 7. Let target be the first return value of applying the rules for
|
// 6. Let targetNavigable be the first return value of applying the rules for choosing a navigable given
|
||||||
// choosing a browsing context given targetAttributeValue, source, and
|
// targetAttributeValue, subject's node navigable, and noopener.
|
||||||
// noopener.
|
auto target_navigable = hyperlink_element_utils_document().navigable()->choose_a_navigable(target_attribute_value, noopener).navigable;
|
||||||
auto target = source->choose_a_browsing_context(target_attribute_value, noopener).browsing_context;
|
|
||||||
|
|
||||||
// 8. If target is null, then return.
|
// 7. If targetNavigable is null, then return.
|
||||||
if (!target)
|
if (!target_navigable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 9. Parse a URL given subject's href attribute, relative to subject's node
|
// 8. Parse a URL given subject's href attribute, relative to subject's node document.
|
||||||
// document.
|
auto url = hyperlink_element_utils_document().parse_url(href());
|
||||||
auto url = source->active_document()->parse_url(href());
|
|
||||||
|
// 9. If that is successful, let url be the resulting URL string.
|
||||||
|
// Otherwise, if parsing the URL failed, then return.
|
||||||
|
if (!url.is_valid())
|
||||||
|
return;
|
||||||
|
|
||||||
// 10. If that is successful, let URL be the resulting URL string.
|
// 10. If that is successful, let URL be the resulting URL string.
|
||||||
auto url_string = url.to_deprecated_string();
|
auto url_string = url.to_deprecated_string();
|
||||||
|
|
||||||
// 11. Otherwise, if parsing the URL failed, the user agent may report the
|
|
||||||
// error to the user in a user-agent-specific manner, may queue an element
|
|
||||||
// task on the DOM manipulation task source given subject to navigate the
|
|
||||||
// target browsing context to an error page to report the error, or may
|
|
||||||
// ignore the error and do nothing. In any case, the user agent must then
|
|
||||||
// return.
|
|
||||||
|
|
||||||
// 12. If hyperlinkSuffix is non-null, then append it to URL.
|
// 12. If hyperlinkSuffix is non-null, then append it to URL.
|
||||||
if (hyperlink_suffix.has_value()) {
|
if (hyperlink_suffix.has_value()) {
|
||||||
StringBuilder url_builder;
|
StringBuilder url_builder;
|
||||||
|
@ -525,21 +517,10 @@ void HTMLHyperlinkElementUtils::follow_the_hyperlink(Optional<DeprecatedString>
|
||||||
url_string = url_builder.to_deprecated_string();
|
url_string = url_builder.to_deprecated_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: 13. Let request be a new request whose URL is URL and whose
|
// FIXME: 12. If subject's link types includes the noreferrer keyword, then set referrerPolicy to "no-referrer".
|
||||||
// referrer policy is the current state of subject's referrerpolicy content
|
|
||||||
// attribute.
|
|
||||||
|
|
||||||
// FIXME: 14. If subject's link types includes the noreferrer keyword, then
|
// 13. Navigate targetNavigable to url using subject's node document, with referrerPolicy set to referrerPolicy.
|
||||||
// set request's referrer to "no-referrer".
|
MUST(target_navigable->navigate(url, hyperlink_element_utils_document()));
|
||||||
|
|
||||||
// 15. Queue an element task on the DOM manipulation task source given
|
|
||||||
// subject to navigate target to request with the source browsing context
|
|
||||||
// set to source.
|
|
||||||
// FIXME: "navigate" means implementing the navigation algorithm here:
|
|
||||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
|
|
||||||
hyperlink_element_utils_queue_an_element_task(Task::Source::DOMManipulation, [url_string, target] {
|
|
||||||
verify_cast<BrowsingContext>(*target).loader().load(url_string, FrameLoader::Type::Navigation);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue