mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Replace WebSocketTask::Open by ConnectionEstablished.
This commit is contained in:
parent
17bd7e5ec3
commit
f93f49490f
1 changed files with 22 additions and 14 deletions
|
@ -151,7 +151,6 @@ impl WebSocket {
|
||||||
};
|
};
|
||||||
let response = request.send().unwrap();
|
let response = request.send().unwrap();
|
||||||
response.validate().unwrap();
|
response.validate().unwrap();
|
||||||
ws.r().ready_state.set(WebSocketRequestState::Open);
|
|
||||||
|
|
||||||
let (temp_sender, temp_receiver) = response.begin().split();
|
let (temp_sender, temp_receiver) = response.begin().split();
|
||||||
*ws.r().sender.borrow_mut() = Some(temp_sender);
|
*ws.r().sender.borrow_mut() = Some(temp_sender);
|
||||||
|
@ -161,7 +160,7 @@ impl WebSocket {
|
||||||
let global_root = ws.r().global.root();
|
let global_root = ws.r().global.root();
|
||||||
let addr: Trusted<WebSocket> =
|
let addr: Trusted<WebSocket> =
|
||||||
Trusted::new(global_root.r().get_cx(), ws.r(), global_root.r().script_chan().clone());
|
Trusted::new(global_root.r().get_cx(), ws.r(), global_root.r().script_chan().clone());
|
||||||
let open_task = box WebSocketTaskHandler::new(addr.clone(), WebSocketTask::Open);
|
let open_task = box WebSocketTaskHandler::new(addr, WebSocketTask::ConnectionEstablished);
|
||||||
global_root.r().script_chan().send(ScriptMsg::RunnableMsg(open_task)).unwrap();
|
global_root.r().script_chan().send(ScriptMsg::RunnableMsg(open_task)).unwrap();
|
||||||
//TODO: Spawn thread here for receive loop
|
//TODO: Spawn thread here for receive loop
|
||||||
/*TODO: Add receive loop here and make new thread run this
|
/*TODO: Add receive loop here and make new thread run this
|
||||||
|
@ -268,7 +267,8 @@ impl<'a> WebSocketMethods for &'a WebSocket {
|
||||||
|
|
||||||
|
|
||||||
pub enum WebSocketTask {
|
pub enum WebSocketTask {
|
||||||
Open,
|
/// Task queued when *the WebSocket connection is established*.
|
||||||
|
ConnectionEstablished,
|
||||||
Close,
|
Close,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,19 +285,27 @@ impl WebSocketTaskHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_open(&self) {
|
fn connection_established(&self) {
|
||||||
/*TODO: Items 1, 3, 4, & 5 under "WebSocket connection is established" as specified here:
|
/*TODO: Items 1, 3, 4, & 5 under "WebSocket connection is established" as specified here:
|
||||||
https://html.spec.whatwg.org/multipage/#feedback-from-the-protocol
|
https://html.spec.whatwg.org/multipage/#feedback-from-the-protocol
|
||||||
*/
|
*/
|
||||||
let ws = self.addr.root(); //Get root
|
let ws = self.addr.root();
|
||||||
let ws = ws.r(); //Get websocket reference
|
|
||||||
|
// Step 1: Protocols.
|
||||||
|
|
||||||
|
// Step 2.
|
||||||
|
ws.ready_state.set(WebSocketRequestState::Open);
|
||||||
|
|
||||||
|
// Step 3: Extensions.
|
||||||
|
// Step 4: Protocols.
|
||||||
|
// Step 5: Cookies.
|
||||||
|
|
||||||
|
// Step 6.
|
||||||
let global = ws.global.root();
|
let global = ws.global.root();
|
||||||
let event = Event::new(global.r(),
|
let event = Event::new(global.r(), "open".to_owned(),
|
||||||
"open".to_owned(),
|
EventBubbles::DoesNotBubble,
|
||||||
EventBubbles::DoesNotBubble,
|
EventCancelable::NotCancelable);
|
||||||
EventCancelable::NotCancelable);
|
event.fire(EventTargetCast::from_ref(ws.r()));
|
||||||
let target = EventTargetCast::from_ref(ws);
|
|
||||||
event.r().fire(target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_close(&self) {
|
fn dispatch_close(&self) {
|
||||||
|
@ -339,8 +347,8 @@ impl WebSocketTaskHandler {
|
||||||
impl Runnable for WebSocketTaskHandler {
|
impl Runnable for WebSocketTaskHandler {
|
||||||
fn handler(self: Box<WebSocketTaskHandler>) {
|
fn handler(self: Box<WebSocketTaskHandler>) {
|
||||||
match self.task {
|
match self.task {
|
||||||
WebSocketTask::Open => {
|
WebSocketTask::ConnectionEstablished => {
|
||||||
self.dispatch_open();
|
self.connection_established();
|
||||||
}
|
}
|
||||||
WebSocketTask::Close => {
|
WebSocketTask::Close => {
|
||||||
self.dispatch_close();
|
self.dispatch_close();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue