mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWeb: Close WebSockets when document is unloaded
Previously, they would stay open for the entire WebContent lifetime, or until the server closed the connection. This was particularly noticeable on collaborative websites/games such as https://jigsawpuzzles.io/, where the user using Ladybird would stick around even after they had navigated away.
This commit is contained in:
parent
3224f8acb5
commit
12a07b4fad
Notes:
github-actions[bot]
2025-02-26 10:48:29 +00:00
Author: https://github.com/Lubrsi
Commit: 12a07b4fad
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3694
5 changed files with 66 additions and 3 deletions
|
@ -44,6 +44,7 @@
|
|||
#include <LibWeb/WebIDL/DOMException.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
#include <LibWeb/WebSockets/WebSocket.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -638,6 +639,28 @@ void WindowOrWorkerGlobalScopeMixin::forcibly_close_all_event_sources()
|
|||
event_source->forcibly_close();
|
||||
}
|
||||
|
||||
void WindowOrWorkerGlobalScopeMixin::register_web_socket(Badge<WebSockets::WebSocket>, GC::Ref<WebSockets::WebSocket> web_socket)
|
||||
{
|
||||
m_registered_web_sockets.append(web_socket);
|
||||
}
|
||||
|
||||
void WindowOrWorkerGlobalScopeMixin::unregister_web_socket(Badge<WebSockets::WebSocket>, GC::Ref<WebSockets::WebSocket> web_socket)
|
||||
{
|
||||
m_registered_web_sockets.remove(web_socket);
|
||||
}
|
||||
|
||||
WindowOrWorkerGlobalScopeMixin::AffectedAnyWebSockets WindowOrWorkerGlobalScopeMixin::make_disappear_all_web_sockets()
|
||||
{
|
||||
auto affected_any_web_sockets = AffectedAnyWebSockets::No;
|
||||
|
||||
for (auto& web_socket : m_registered_web_sockets) {
|
||||
web_socket.make_disappear();
|
||||
affected_any_web_sockets = AffectedAnyWebSockets::Yes;
|
||||
}
|
||||
|
||||
return affected_any_web_sockets;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#run-steps-after-a-timeout
|
||||
void WindowOrWorkerGlobalScopeMixin::run_steps_after_a_timeout(i32 timeout, Function<void()> completion_step)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue