diff options
-rw-r--r-- | components/script/dom/bindings/global.rs | 9 | ||||
-rw-r--r-- | components/script/dom/globalscope.rs | 12 | ||||
-rw-r--r-- | components/script/dom/websocket.rs | 7 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 5 | ||||
-rw-r--r-- | components/script/fetch.rs | 2 |
5 files changed, 19 insertions, 16 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 67ed8766932..35541148fda 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -69,15 +69,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 - /// thread. pub fn file_reading_task_source(&self) -> FileReadingTaskSource { match *self { GlobalRef::Window(ref window) => window.file_reading_task_source(), diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 7e5f0407e36..29c918d28f0 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -270,6 +270,18 @@ impl GlobalScope { } 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 { diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index ac1cf53b2ae..242f8124721 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -270,7 +270,7 @@ impl WebSocket { *ws.sender.borrow_mut() = Some(dom_action_sender); let moved_address = address.clone(); - let sender = global.networking_task_source(); + let sender = global_scope.networking_task_source(); thread::spawn(move || { while let Ok(event) = dom_event_receiver.recv() { match event { @@ -438,7 +438,7 @@ impl WebSocketMethods for WebSocket { self.ready_state.set(WebSocketRequestState::Closing); 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); } WebSocketRequestState::Open => { @@ -469,11 +469,10 @@ impl Runnable for ConnectionEstablishedTask { fn handler(self: Box<Self>) { let ws = self.address.root(); - let global = ws.r().global(); // Step 1: Protocols. 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); return; } diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 907f8ba2653..5e7f156931e 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -1296,14 +1296,15 @@ impl XMLHttpRequest { sync_status: DOMRefCell::new(None), })); + let global_scope = global.as_global_scope(); let (script_chan, script_port) = if self.sync.get() { let (tx, rx) = global.new_script_pair(); (tx, Some(rx)) } 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, core_resource_thread, init); diff --git a/components/script/fetch.rs b/components/script/fetch.rs index a50f781d0b0..b23f8f8f8dd 100644 --- a/components/script/fetch.rs +++ b/components/script/fetch.rs @@ -96,7 +96,7 @@ pub fn Fetch(global: GlobalRef, input: RequestOrUSVString, init: &RequestInit) - })); let listener = NetworkListener { context: fetch_context, - script_chan: global.networking_task_source(), + script_chan: global_scope.networking_task_source(), wrapper: None, }; |