mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Fix rooting issues with data channels callbacks
This commit is contained in:
parent
f5c930087e
commit
ace0d7795e
1 changed files with 72 additions and 65 deletions
|
@ -45,7 +45,6 @@ pub struct RTCDataChannel {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RTCDataChannel {
|
impl RTCDataChannel {
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
pub fn new_inherited(
|
pub fn new_inherited(
|
||||||
webrtc_controller: &DomRefCell<Option<WebRtcController>>,
|
webrtc_controller: &DomRefCell<Option<WebRtcController>>,
|
||||||
label: USVString,
|
label: USVString,
|
||||||
|
@ -67,7 +66,7 @@ impl RTCDataChannel {
|
||||||
channel.unwrap()
|
channel.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let rtc_data_channel = RTCDataChannel {
|
RTCDataChannel {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
channel,
|
channel,
|
||||||
label,
|
label,
|
||||||
|
@ -77,67 +76,7 @@ impl RTCDataChannel {
|
||||||
protocol: options.protocol.clone(),
|
protocol: options.protocol.clone(),
|
||||||
negotiated: options.negotiated,
|
negotiated: options.negotiated,
|
||||||
id: options.id,
|
id: options.id,
|
||||||
};
|
}
|
||||||
|
|
||||||
let trusted = Trusted::new(&rtc_data_channel);
|
|
||||||
|
|
||||||
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(
|
|
||||||
task!(on_open: move || {
|
|
||||||
this_.root().on_open();
|
|
||||||
}),
|
|
||||||
global.upcast(),
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
|
|
||||||
let this = trusted.clone();
|
|
||||||
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(
|
|
||||||
task!(on_close: move || {
|
|
||||||
this_.root().on_close();
|
|
||||||
}),
|
|
||||||
global.upcast(),
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
|
|
||||||
let this = trusted.clone();
|
|
||||||
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(
|
|
||||||
task!(on_error: move || {
|
|
||||||
this_.root().on_error(error);
|
|
||||||
}),
|
|
||||||
global.upcast(),
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
|
|
||||||
let this = trusted.clone();
|
|
||||||
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(
|
|
||||||
task!(on_message: move || {
|
|
||||||
this_.root().on_message(message);
|
|
||||||
}),
|
|
||||||
global.upcast(),
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
|
|
||||||
rtc_data_channel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
@ -147,7 +86,7 @@ impl RTCDataChannel {
|
||||||
options: &RTCDataChannelInit,
|
options: &RTCDataChannelInit,
|
||||||
channel: Option<Box<dyn WebRtcDataChannelBackend>>,
|
channel: Option<Box<dyn WebRtcDataChannelBackend>>,
|
||||||
) -> DomRoot<RTCDataChannel> {
|
) -> DomRoot<RTCDataChannel> {
|
||||||
reflect_dom_object(
|
let rtc_data_channel = reflect_dom_object(
|
||||||
Box::new(RTCDataChannel::new_inherited(
|
Box::new(RTCDataChannel::new_inherited(
|
||||||
webrtc_controller,
|
webrtc_controller,
|
||||||
label,
|
label,
|
||||||
|
@ -155,7 +94,75 @@ impl RTCDataChannel {
|
||||||
channel,
|
channel,
|
||||||
)),
|
)),
|
||||||
global,
|
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 _ = task_source.queue_with_canceller(
|
||||||
|
task!(on_open: move || {
|
||||||
|
this.root().on_open();
|
||||||
|
}),
|
||||||
|
&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 _ = task_source.queue_with_canceller(
|
||||||
|
task!(on_close: move || {
|
||||||
|
this.root().on_close();
|
||||||
|
}),
|
||||||
|
&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 _ = task_source.queue_with_canceller(
|
||||||
|
task!(on_error: move || {
|
||||||
|
this.root().on_error(error);
|
||||||
|
}),
|
||||||
|
&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 _ = task_source.queue_with_canceller(
|
||||||
|
task!(on_message: move || {
|
||||||
|
this.root().on_message(message);
|
||||||
|
}),
|
||||||
|
&canceller,
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
rtc_data_channel
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_open(&self) {
|
fn on_open(&self) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue