mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
b400a34984
When parsing relative URLs, we have to check the first <base href> in tree order (if one is available). This was getting *very* costly on large DOMs with many relative urls. This patch avoids all that repeated traversal by letting Document cache the first <base href> and invalidating the cache whenever a <base> element is added/removed/edited in the DOM. The browser was stuck doing this for a *very* long time when loading the ECMA-262 spec, and this removes that problem entirely.
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
class HTMLBaseElement final : public HTMLElement {
|
|
WEB_PLATFORM_OBJECT(HTMLBaseElement, HTMLElement);
|
|
|
|
public:
|
|
virtual ~HTMLBaseElement() override;
|
|
|
|
String href() const;
|
|
void set_href(String const& href);
|
|
|
|
AK::URL const& frozen_base_url() const { return m_frozen_base_url; }
|
|
|
|
virtual void inserted() override;
|
|
virtual void removed_from(Node*) override;
|
|
virtual void parse_attribute(FlyString const& name, String const& value) override;
|
|
|
|
private:
|
|
HTMLBaseElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
virtual bool is_html_base_element() const override { return true; }
|
|
|
|
// https://html.spec.whatwg.org/multipage/semantics.html#frozen-base-url
|
|
// A base element that is the first base element with an href content attribute in a document tree has a frozen base URL.
|
|
AK::URL m_frozen_base_url;
|
|
|
|
void set_the_frozen_base_url();
|
|
};
|
|
|
|
}
|
|
|
|
namespace Web::DOM {
|
|
template<>
|
|
inline bool Node::fast_is<HTML::HTMLBaseElement>() const { return is_html_base_element(); }
|
|
}
|