2020-03-13 17:00:50 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jeremy Apthorp <nornagon@nornagon.net>
|
|
|
|
Date: Wed, 4 Mar 2020 11:18:03 -0800
|
|
|
|
Subject: feat: add onclose to MessagePort
|
|
|
|
|
|
|
|
This adds the 'onclose' event to MessagePort. This is
|
|
|
|
[proposed](https://github.com/w3ctag/design-reviews/issues/269#issuecomment-407584290)
|
|
|
|
in w3c and has been discussed for years without conclusion. I'd like to
|
|
|
|
get this standardised, but in lieu of that, this makes MessagePort a
|
|
|
|
whole bunch more useful!
|
|
|
|
|
|
|
|
diff --git a/third_party/blink/renderer/core/messaging/message_port.cc b/third_party/blink/renderer/core/messaging/message_port.cc
|
2021-05-19 23:15:47 +00:00
|
|
|
index 002ee34ce9a1bbcbdeb5c54967a2f22b1444cc85..c22870137449bf55a62f74d702e25fa6547baca3 100644
|
2020-03-13 17:00:50 +00:00
|
|
|
--- a/third_party/blink/renderer/core/messaging/message_port.cc
|
|
|
|
+++ b/third_party/blink/renderer/core/messaging/message_port.cc
|
2020-05-26 20:06:26 +00:00
|
|
|
@@ -158,6 +158,7 @@ void MessagePort::close() {
|
|
|
|
Entangle(pipe.TakePort0());
|
2020-03-13 17:00:50 +00:00
|
|
|
}
|
|
|
|
closed_ = true;
|
|
|
|
+ DispatchEvent(*Event::Create(event_type_names::kClose));
|
|
|
|
}
|
|
|
|
|
2020-05-26 20:06:26 +00:00
|
|
|
void MessagePort::Entangle(MessagePortDescriptor port) {
|
2020-03-13 17:00:50 +00:00
|
|
|
diff --git a/third_party/blink/renderer/core/messaging/message_port.h b/third_party/blink/renderer/core/messaging/message_port.h
|
2020-08-12 18:33:58 +00:00
|
|
|
index 7a83dce5113dc77d3654997db09ff9bc4cfeb3e2..85987f99ee144060cee11719726eb823bf58c645 100644
|
2020-03-13 17:00:50 +00:00
|
|
|
--- a/third_party/blink/renderer/core/messaging/message_port.h
|
|
|
|
+++ b/third_party/blink/renderer/core/messaging/message_port.h
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -120,6 +120,13 @@ class CORE_EXPORT MessagePort : public EventTargetWithInlineData,
|
2020-03-13 17:00:50 +00:00
|
|
|
return GetAttributeEventListener(event_type_names::kMessageerror);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ void setOnclose(EventListener* listener) {
|
|
|
|
+ SetAttributeEventListener(event_type_names::kClose, listener);
|
|
|
|
+ }
|
|
|
|
+ EventListener* onclose() {
|
|
|
|
+ return GetAttributeEventListener(event_type_names::kClose);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
// A port starts out its life entangled, and remains entangled until it is
|
|
|
|
// closed or is cloned.
|
|
|
|
bool IsEntangled() const { return !closed_ && !IsNeutered(); }
|
|
|
|
diff --git a/third_party/blink/renderer/core/messaging/message_port.idl b/third_party/blink/renderer/core/messaging/message_port.idl
|
|
|
|
index 6fab27fcdf1c333739b6ffe88b3cc4eed3301ee4..3f1f181d9b8a66997136f870f55c97c08294b6eb 100644
|
|
|
|
--- a/third_party/blink/renderer/core/messaging/message_port.idl
|
|
|
|
+++ b/third_party/blink/renderer/core/messaging/message_port.idl
|
|
|
|
@@ -40,4 +40,5 @@
|
|
|
|
// event handlers
|
|
|
|
attribute EventHandler onmessage;
|
|
|
|
attribute EventHandler onmessageerror;
|
|
|
|
+ attribute EventHandler onclose;
|
|
|
|
};
|