1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 17:48:12 +00:00

LibWeb: Implement the "close" algorithm for browsing contexts

This is used by window.close() programmatically, but of course the user
can also decide to close a top-level browsing context at any time by
closing the tab.
This commit is contained in:
Andreas Kling 2022-09-21 01:17:01 +02:00
parent 0c7ab663c1
commit 6c33dea6a6
3 changed files with 22 additions and 0 deletions

View file

@ -1322,4 +1322,22 @@ void BrowsingContext::discard()
parent()->remove_child(*this); parent()->remove_child(*this);
} }
// https://html.spec.whatwg.org/multipage/window-object.html#close-a-browsing-context
void BrowsingContext::close()
{
VERIFY(active_document());
// FIXME: 1. If the result of calling prompt to unload with browsingContext's active document is "refuse", then return.
// 2. Unload browsingContext's active document.
active_document()->unload();
// 3. Remove browsingContext from the user interface (e.g., close or hide its tab in a tabbed browser).
if (m_page)
m_page->client().page_did_close_browsing_context(*this);
// 4. Discard browsingContext.
discard();
}
} }

View file

@ -168,6 +168,9 @@ public:
// https://html.spec.whatwg.org/multipage/window-object.html#a-browsing-context-is-discarded // https://html.spec.whatwg.org/multipage/window-object.html#a-browsing-context-is-discarded
void discard(); void discard();
// https://html.spec.whatwg.org/multipage/window-object.html#close-a-browsing-context
void close();
private: private:
explicit BrowsingContext(Page&, HTML::BrowsingContextContainer*); explicit BrowsingContext(Page&, HTML::BrowsingContextContainer*);

View file

@ -110,6 +110,7 @@ public:
virtual String page_did_request_cookie(const AK::URL&, Cookie::Source) { return {}; } virtual String page_did_request_cookie(const AK::URL&, Cookie::Source) { return {}; }
virtual void page_did_set_cookie(const AK::URL&, Cookie::ParsedCookie const&, Cookie::Source) { } virtual void page_did_set_cookie(const AK::URL&, Cookie::ParsedCookie const&, Cookie::Source) { }
virtual void page_did_update_resource_count(i32) { } virtual void page_did_update_resource_count(i32) { }
virtual void page_did_close_browsing_context(HTML::BrowsingContext const&) { }
virtual void request_file(NonnullRefPtr<FileRequest>&) = 0; virtual void request_file(NonnullRefPtr<FileRequest>&) = 0;