mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Use task! to announce event source connections
This commit is contained in:
parent
7a5d7e2e90
commit
ad41ce7a6f
1 changed files with 14 additions and 20 deletions
|
@ -33,7 +33,6 @@ use std::cell::Cell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::str::{Chars, FromStr};
|
use std::str::{Chars, FromStr};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use task::Task;
|
|
||||||
use task_source::TaskSource;
|
use task_source::TaskSource;
|
||||||
use timers::OneshotTimerCallback;
|
use timers::OneshotTimerCallback;
|
||||||
use utf8;
|
use utf8;
|
||||||
|
@ -91,15 +90,25 @@ struct EventSourceContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventSourceContext {
|
impl EventSourceContext {
|
||||||
|
/// https://html.spec.whatwg.org/multipage/#announce-the-connection
|
||||||
fn announce_the_connection(&self) {
|
fn announce_the_connection(&self) {
|
||||||
let event_source = self.event_source.root();
|
let event_source = self.event_source.root();
|
||||||
if self.gen_id != event_source.generation_id.get() {
|
if self.gen_id != event_source.generation_id.get() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let task = box AnnounceConnectionTask {
|
let global = event_source.global();
|
||||||
event_source: self.event_source.clone()
|
let event_source = self.event_source.clone();
|
||||||
};
|
// FIXME(nox): Why are errors silenced here?
|
||||||
let _ = event_source.global().networking_task_source().queue(task, &*event_source.global());
|
let _ = global.networking_task_source().queue(
|
||||||
|
box task!(announce_the_event_source_connection: move || {
|
||||||
|
let event_source = event_source.root();
|
||||||
|
if event_source.ready_state.get() != ReadyState::Closed {
|
||||||
|
event_source.ready_state.set(ReadyState::Open);
|
||||||
|
event_source.upcast::<EventTarget>().fire_event(atom!("open"));
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
&global,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#fail-the-connection
|
/// https://html.spec.whatwg.org/multipage/#fail-the-connection
|
||||||
|
@ -519,21 +528,6 @@ impl EventSourceMethods for EventSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AnnounceConnectionTask {
|
|
||||||
event_source: Trusted<EventSource>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Task for AnnounceConnectionTask {
|
|
||||||
// https://html.spec.whatwg.org/multipage/#announce-the-connection
|
|
||||||
fn run(self: Box<Self>) {
|
|
||||||
let event_source = self.event_source.root();
|
|
||||||
if event_source.ready_state.get() != ReadyState::Closed {
|
|
||||||
event_source.ready_state.set(ReadyState::Open);
|
|
||||||
event_source.upcast::<EventTarget>().fire_event(atom!("open"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(HeapSizeOf, JSTraceable)]
|
#[derive(HeapSizeOf, JSTraceable)]
|
||||||
pub struct EventSourceTimeoutCallback {
|
pub struct EventSourceTimeoutCallback {
|
||||||
#[ignore_heap_size_of = "Because it is non-owning"]
|
#[ignore_heap_size_of = "Because it is non-owning"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue