mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 10:27:36 +00:00
LibWeb: Implement Document/BrowsingContext hookup according to spec
We now implement the browsing context's "set active document" algorithm from the spec, as well as the "discard" algorithm for browsing contexts and documents.
This commit is contained in:
parent
ab8432783e
commit
92deba7197
9 changed files with 189 additions and 70 deletions
|
@ -651,20 +651,6 @@ void Document::set_title(String const& title)
|
|||
}
|
||||
}
|
||||
|
||||
void Document::attach_to_browsing_context(Badge<HTML::BrowsingContext>, HTML::BrowsingContext& browsing_context)
|
||||
{
|
||||
m_browsing_context = browsing_context;
|
||||
|
||||
update_the_visibility_state(browsing_context.system_visibility_state());
|
||||
}
|
||||
|
||||
void Document::detach_from_browsing_context(Badge<HTML::BrowsingContext>, HTML::BrowsingContext& browsing_context)
|
||||
{
|
||||
VERIFY(&browsing_context == m_browsing_context);
|
||||
tear_down_layout_tree();
|
||||
m_browsing_context = nullptr;
|
||||
}
|
||||
|
||||
void Document::tear_down_layout_tree()
|
||||
{
|
||||
if (!m_layout_root)
|
||||
|
@ -1605,6 +1591,11 @@ String Document::visibility_state() const
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
void Document::set_visibility_state(Badge<HTML::BrowsingContext>, HTML::VisibilityState visibility_state)
|
||||
{
|
||||
m_visibility_state = visibility_state;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
|
||||
void Document::update_the_visibility_state(HTML::VisibilityState visibility_state)
|
||||
{
|
||||
|
@ -2021,4 +2012,100 @@ Vector<NonnullRefPtr<HTML::BrowsingContext>> Document::list_of_descendant_browsi
|
|||
return list;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document
|
||||
void Document::discard()
|
||||
{
|
||||
// 1. Set document's salvageable state to false.
|
||||
m_salvageable = false;
|
||||
|
||||
// FIXME: 2. Run any unloading document cleanup steps for document that are defined by this specification and other applicable specifications.
|
||||
|
||||
// 3. Abort document.
|
||||
abort();
|
||||
|
||||
// 4. Remove any tasks associated with document in any task source, without running those tasks.
|
||||
HTML::main_thread_event_loop().task_queue().remove_tasks_matching([this](auto& task) {
|
||||
return task.document() == this;
|
||||
});
|
||||
|
||||
// 5. Discard all the child browsing contexts of document.
|
||||
if (browsing_context()) {
|
||||
browsing_context()->for_each_child([](HTML::BrowsingContext& child_browsing_context) {
|
||||
child_browsing_context.discard();
|
||||
});
|
||||
}
|
||||
|
||||
// FIXME: 6. For each session history entry entry whose document is equal to document, set entry's document to null.
|
||||
|
||||
// 7. Set document's browsing context to null.
|
||||
tear_down_layout_tree();
|
||||
m_browsing_context = nullptr;
|
||||
|
||||
// FIXME: 8. Remove document from the owner set of each WorkerGlobalScope object whose set contains document.
|
||||
|
||||
// FIXME: 9. For each workletGlobalScope in document's worklet global scopes, terminate workletGlobalScope.
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#abort-a-document
|
||||
void Document::abort()
|
||||
{
|
||||
// 1. Abort the active documents of every child browsing context.
|
||||
// If this results in any of those Document objects having their salvageable state set to false,
|
||||
// then set document's salvageable state to false also.
|
||||
if (browsing_context()) {
|
||||
browsing_context()->for_each_child([this](HTML::BrowsingContext& child_browsing_context) {
|
||||
if (auto* child_document = child_browsing_context.active_document()) {
|
||||
child_document->abort();
|
||||
if (!child_document->m_salvageable)
|
||||
m_salvageable = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// FIXME: 2. Cancel any instances of the fetch algorithm in the context of document,
|
||||
// discarding any tasks queued for them, and discarding any further data received from the network for them.
|
||||
// If this resulted in any instances of the fetch algorithm being canceled
|
||||
// or any queued tasks or any network data getting discarded,
|
||||
// then set document's salvageable state to false.
|
||||
|
||||
// 3. If document's navigation id is non-null, then:
|
||||
if (m_navigation_id.has_value()) {
|
||||
// 1. FIXME: Invoke WebDriver BiDi navigation aborted with document's browsing context,
|
||||
// and new WebDriver BiDi navigation status whose whose id is document's navigation id,
|
||||
// status is "canceled", and url is document's URL.
|
||||
|
||||
// 2. Set document's navigation id to null.
|
||||
m_navigation_id = {};
|
||||
}
|
||||
|
||||
// 4. If document has an active parser, then:
|
||||
if (auto parser = active_parser()) {
|
||||
// 1. Set document's active parser was aborted to true.
|
||||
m_active_parser_was_aborted = true;
|
||||
|
||||
// 2. Abort that parser.
|
||||
parser->abort();
|
||||
|
||||
// 3. Set document's salvageable state to false.
|
||||
m_salvageable = false;
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#active-parser
|
||||
RefPtr<HTML::HTMLParser> Document::active_parser()
|
||||
{
|
||||
if (!m_parser)
|
||||
return nullptr;
|
||||
|
||||
if (m_parser->aborted() || m_parser->stopped())
|
||||
return nullptr;
|
||||
|
||||
return m_parser;
|
||||
}
|
||||
|
||||
void Document::set_browsing_context(HTML::BrowsingContext* browsing_context)
|
||||
{
|
||||
m_browsing_context = browsing_context;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -135,12 +135,11 @@ public:
|
|||
String title() const;
|
||||
void set_title(String const&);
|
||||
|
||||
void attach_to_browsing_context(Badge<HTML::BrowsingContext>, HTML::BrowsingContext&);
|
||||
void detach_from_browsing_context(Badge<HTML::BrowsingContext>, HTML::BrowsingContext&);
|
||||
|
||||
HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); }
|
||||
HTML::BrowsingContext const* browsing_context() const { return m_browsing_context.ptr(); }
|
||||
|
||||
void set_browsing_context(HTML::BrowsingContext*);
|
||||
|
||||
Page* page();
|
||||
Page const* page() const;
|
||||
|
||||
|
@ -322,6 +321,9 @@ public:
|
|||
// https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
|
||||
void update_the_visibility_state(HTML::VisibilityState);
|
||||
|
||||
// NOTE: This does not fire any events, unlike update_the_visibility_state().
|
||||
void set_visibility_state(Badge<HTML::BrowsingContext>, HTML::VisibilityState);
|
||||
|
||||
void run_the_resize_steps();
|
||||
void run_the_scroll_steps();
|
||||
|
||||
|
@ -386,6 +388,15 @@ public:
|
|||
// https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts
|
||||
Vector<NonnullRefPtr<HTML::BrowsingContext>> list_of_descendant_browsing_contexts() const;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document
|
||||
void discard();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#abort-a-document
|
||||
void abort();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#active-parser
|
||||
RefPtr<HTML::HTMLParser> active_parser();
|
||||
|
||||
protected:
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
|
@ -476,6 +487,9 @@ private:
|
|||
|
||||
size_t m_number_of_things_delaying_the_load_event { 0 };
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#concept-document-salvageable
|
||||
bool m_salvageable { true };
|
||||
|
||||
// https://html.spec.whatwg.org/#page-showing
|
||||
bool m_page_showing { false };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue