mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Introduce GlobalScope::networking_task_source
This commit is contained in:
parent
a7305b7fc4
commit
1fd470889d
5 changed files with 19 additions and 16 deletions
|
@ -67,15 +67,6 @@ impl<'a> GlobalRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `ScriptChan` used to send messages to the event loop of this global's
|
|
||||||
/// thread.
|
|
||||||
pub fn networking_task_source(&self) -> Box<ScriptChan + Send> {
|
|
||||||
match *self {
|
|
||||||
GlobalRef::Window(ref window) => window.networking_task_source(),
|
|
||||||
GlobalRef::Worker(ref worker) => worker.script_chan(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `ScriptChan` used to send messages to the event loop of this global's
|
/// `ScriptChan` used to send messages to the event loop of this global's
|
||||||
/// thread.
|
/// thread.
|
||||||
pub fn file_reading_task_source(&self) -> FileReadingTaskSource {
|
pub fn file_reading_task_source(&self) -> FileReadingTaskSource {
|
||||||
|
|
|
@ -270,6 +270,18 @@ impl GlobalScope {
|
||||||
}
|
}
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `ScriptChan` to send messages to the networking task source of
|
||||||
|
/// this of this global scope.
|
||||||
|
pub fn networking_task_source(&self) -> Box<ScriptChan + Send> {
|
||||||
|
if let Some(window) = self.downcast::<Window>() {
|
||||||
|
return window.networking_task_source();
|
||||||
|
}
|
||||||
|
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
|
||||||
|
return worker.script_chan();
|
||||||
|
}
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||||
|
|
|
@ -270,7 +270,7 @@ impl WebSocket {
|
||||||
*ws.sender.borrow_mut() = Some(dom_action_sender);
|
*ws.sender.borrow_mut() = Some(dom_action_sender);
|
||||||
|
|
||||||
let moved_address = address.clone();
|
let moved_address = address.clone();
|
||||||
let sender = global.networking_task_source();
|
let sender = global_scope.networking_task_source();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
while let Ok(event) = dom_event_receiver.recv() {
|
while let Ok(event) = dom_event_receiver.recv() {
|
||||||
match event {
|
match event {
|
||||||
|
@ -438,7 +438,7 @@ impl WebSocketMethods for WebSocket {
|
||||||
self.ready_state.set(WebSocketRequestState::Closing);
|
self.ready_state.set(WebSocketRequestState::Closing);
|
||||||
|
|
||||||
let address = Trusted::new(self);
|
let address = Trusted::new(self);
|
||||||
let sender = self.global().r().networking_task_source();
|
let sender = self.global_scope().networking_task_source();
|
||||||
fail_the_websocket_connection(address, sender);
|
fail_the_websocket_connection(address, sender);
|
||||||
}
|
}
|
||||||
WebSocketRequestState::Open => {
|
WebSocketRequestState::Open => {
|
||||||
|
@ -469,11 +469,10 @@ impl Runnable for ConnectionEstablishedTask {
|
||||||
|
|
||||||
fn handler(self: Box<Self>) {
|
fn handler(self: Box<Self>) {
|
||||||
let ws = self.address.root();
|
let ws = self.address.root();
|
||||||
let global = ws.r().global();
|
|
||||||
|
|
||||||
// Step 1: Protocols.
|
// Step 1: Protocols.
|
||||||
if !self.protocols.is_empty() && self.headers.get::<WebSocketProtocol>().is_none() {
|
if !self.protocols.is_empty() && self.headers.get::<WebSocketProtocol>().is_none() {
|
||||||
let sender = global.r().networking_task_source();
|
let sender = ws.global_scope().networking_task_source();
|
||||||
fail_the_websocket_connection(self.address, sender);
|
fail_the_websocket_connection(self.address, sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1296,14 +1296,15 @@ impl XMLHttpRequest {
|
||||||
sync_status: DOMRefCell::new(None),
|
sync_status: DOMRefCell::new(None),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let global_scope = global.as_global_scope();
|
||||||
let (script_chan, script_port) = if self.sync.get() {
|
let (script_chan, script_port) = if self.sync.get() {
|
||||||
let (tx, rx) = global.new_script_pair();
|
let (tx, rx) = global.new_script_pair();
|
||||||
(tx, Some(rx))
|
(tx, Some(rx))
|
||||||
} else {
|
} else {
|
||||||
(global.networking_task_source(), None)
|
(global_scope.networking_task_source(), None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let core_resource_thread = global.as_global_scope().core_resource_thread();
|
let core_resource_thread = global_scope.core_resource_thread();
|
||||||
XMLHttpRequest::initiate_async_xhr(context.clone(), script_chan,
|
XMLHttpRequest::initiate_async_xhr(context.clone(), script_chan,
|
||||||
core_resource_thread, init);
|
core_resource_thread, init);
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ pub fn Fetch(global: GlobalRef, input: RequestOrUSVString, init: &RequestInit) -
|
||||||
}));
|
}));
|
||||||
let listener = NetworkListener {
|
let listener = NetworkListener {
|
||||||
context: fetch_context,
|
context: fetch_context,
|
||||||
script_chan: global.networking_task_source(),
|
script_chan: global_scope.networking_task_source(),
|
||||||
wrapper: None,
|
wrapper: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue