diff options
author | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2020-06-02 10:28:33 +0200 |
---|---|---|
committer | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2020-06-29 16:53:48 +0200 |
commit | ace0d7795ec3e9ad1bdadfd1894aacbd0d3676d8 (patch) | |
tree | 3a49360200d2fa63d881d1a5b5aa638087958cf3 /components/script/dom/rtcdatachannel.rs | |
parent | f5c930087e51df882a65d47950d79954bdf24e50 (diff) | |
download | servo-ace0d7795ec3e9ad1bdadfd1894aacbd0d3676d8.tar.gz servo-ace0d7795ec3e9ad1bdadfd1894aacbd0d3676d8.zip |
Fix rooting issues with data channels callbacks
Diffstat (limited to 'components/script/dom/rtcdatachannel.rs')
-rw-r--r-- | components/script/dom/rtcdatachannel.rs | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/components/script/dom/rtcdatachannel.rs b/components/script/dom/rtcdatachannel.rs index 3daa4b0fd85..2b26bf4f8b9 100644 --- a/components/script/dom/rtcdatachannel.rs +++ b/components/script/dom/rtcdatachannel.rs @@ -45,7 +45,6 @@ pub struct RTCDataChannel { } impl RTCDataChannel { - #[allow(unrooted_must_root)] pub fn new_inherited( webrtc_controller: &DomRefCell<Option<WebRtcController>>, label: USVString, @@ -67,7 +66,7 @@ impl RTCDataChannel { channel.unwrap() }; - let rtc_data_channel = RTCDataChannel { + RTCDataChannel { eventtarget: EventTarget::new_inherited(), channel, label, @@ -77,87 +76,95 @@ impl RTCDataChannel { protocol: options.protocol.clone(), negotiated: options.negotiated, id: options.id, - }; + } + } - let trusted = Trusted::new(&rtc_data_channel); + pub fn new( + global: &GlobalScope, + webrtc_controller: &DomRefCell<Option<WebRtcController>>, + label: USVString, + options: &RTCDataChannelInit, + channel: Option<Box<dyn WebRtcDataChannelBackend>>, + ) -> DomRoot<RTCDataChannel> { + let rtc_data_channel = reflect_dom_object( + Box::new(RTCDataChannel::new_inherited( + webrtc_controller, + label, + options, + channel, + )), + global, + ); + + let trusted = Trusted::new(&*rtc_data_channel); + let (task_source, canceller) = global + .as_window() + .task_manager() + .networking_task_source_with_canceller(); let this = trusted.clone(); rtc_data_channel.channel.set_on_open(Box::new(move || { - let this_ = this.clone(); - let global = this.root().global(); - let task_source = global.networking_task_source(); - let _ = task_source.queue( + let this = this.clone(); + let _ = task_source.queue_with_canceller( task!(on_open: move || { - this_.root().on_open(); + this.root().on_open(); }), - global.upcast(), + &canceller, ); })); let this = trusted.clone(); + let (task_source, canceller) = global + .as_window() + .task_manager() + .networking_task_source_with_canceller(); rtc_data_channel.channel.set_on_close(Box::new(move || { - let this_ = this.clone(); - let global = this.root().global(); - let task_source = global.networking_task_source(); - let _ = task_source.queue( + let this = this.clone(); + let _ = task_source.queue_with_canceller( task!(on_close: move || { - this_.root().on_close(); + this.root().on_close(); }), - global.upcast(), + &canceller, ); })); let this = trusted.clone(); + let (task_source, canceller) = global + .as_window() + .task_manager() + .networking_task_source_with_canceller(); rtc_data_channel .channel .set_on_error(Box::new(move |error| { - let this_ = this.clone(); - let global = this.root().global(); - let task_source = global.networking_task_source(); - let _ = task_source.queue( + let this = this.clone(); + let _ = task_source.queue_with_canceller( task!(on_error: move || { - this_.root().on_error(error); + this.root().on_error(error); }), - global.upcast(), + &canceller, ); })); let this = trusted.clone(); + let (task_source, canceller) = global + .as_window() + .task_manager() + .networking_task_source_with_canceller(); rtc_data_channel .channel .set_on_message(Box::new(move |message| { - let this_ = this.clone(); - let global = this.root().global(); - let task_source = global.networking_task_source(); - let _ = task_source.queue( + let this = this.clone(); + let _ = task_source.queue_with_canceller( task!(on_message: move || { - this_.root().on_message(message); + this.root().on_message(message); }), - global.upcast(), + &canceller, ); })); rtc_data_channel } - pub fn new( - global: &GlobalScope, - webrtc_controller: &DomRefCell<Option<WebRtcController>>, - label: USVString, - options: &RTCDataChannelInit, - channel: Option<Box<dyn WebRtcDataChannelBackend>>, - ) -> DomRoot<RTCDataChannel> { - reflect_dom_object( - Box::new(RTCDataChannel::new_inherited( - webrtc_controller, - label, - options, - channel, - )), - global, - ) - } - fn on_open(&self) { let event = Event::new( &self.global(), |