diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-21 01:17:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-21 11:51:18 +0200 |
commit | 6c33dea6a6ee0a417d85ccef07a49b9bbdf1d734 (patch) | |
tree | 4ab1f7965a5ad9ed07b91a3ca7c920f21bf7c581 | |
parent | 0c7ab663c1ea592dc9f38cb6cf6c6e9d57c87ecd (diff) | |
download | serenity-6c33dea6a6ee0a417d85ccef07a49b9bbdf1d734.zip |
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.
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/BrowsingContext.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Page/Page.h | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 038f6dbdbd..95464fa6b5 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -1322,4 +1322,22 @@ void BrowsingContext::discard() 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(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h index f0db2a5f59..29a8f1edb6 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h @@ -168,6 +168,9 @@ public: // https://html.spec.whatwg.org/multipage/window-object.html#a-browsing-context-is-discarded void discard(); + // https://html.spec.whatwg.org/multipage/window-object.html#close-a-browsing-context + void close(); + private: explicit BrowsingContext(Page&, HTML::BrowsingContextContainer*); diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 3a232077c4..e9f8b29c39 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -110,6 +110,7 @@ public: 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_update_resource_count(i32) { } + virtual void page_did_close_browsing_context(HTML::BrowsingContext const&) { } virtual void request_file(NonnullRefPtr<FileRequest>&) = 0; |