Skip to content

Commit

Permalink
Implement XHR progress event changes
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesvdv committed Feb 18, 2017
1 parent 05623b3 commit f938c95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
21 changes: 10 additions & 11 deletions components/script/dom/xmlhttprequest.rs
Expand Up @@ -42,7 +42,7 @@ use encoding::types::{DecoderTrap, EncoderTrap, Encoding, EncodingRef};
use euclid::length::Length;
use html5ever::serialize;
use html5ever::serialize::SerializeOpts;
use hyper::header::{ContentLength, ContentType};
use hyper::header::{ContentLength, ContentType, ContentEncoding};
use hyper::header::Headers;
use hyper::method::Method;
use hyper::mime::{self, Attr as MimeAttr, Mime, Value as MimeValue};
Expand Down Expand Up @@ -979,14 +979,12 @@ impl XMLHttpRequest {
// Part of step 11, send() (processing response end of file)
// XXXManishearth handle errors, if any (substep 2)

// Subsubsteps 5-7
// Subsubsteps 6-8
self.send_flag.set(false);

self.change_ready_state(XMLHttpRequestState::Done);
return_if_fetch_was_terminated!();
// Subsubsteps 10-12
self.dispatch_response_progress_event(atom!("progress"));
return_if_fetch_was_terminated!();
// Subsubsteps 11-12
self.dispatch_response_progress_event(atom!("load"));
return_if_fetch_was_terminated!();
self.dispatch_response_progress_event(atom!("loadend"));
Expand All @@ -1009,15 +1007,11 @@ impl XMLHttpRequest {
let upload_complete = &self.upload_complete;
if !upload_complete.get() {
upload_complete.set(true);
self.dispatch_upload_progress_event(atom!("progress"), None);
return_if_fetch_was_terminated!();
self.dispatch_upload_progress_event(Atom::from(errormsg), None);
return_if_fetch_was_terminated!();
self.dispatch_upload_progress_event(atom!("loadend"), None);
return_if_fetch_was_terminated!();
}
self.dispatch_response_progress_event(atom!("progress"));
return_if_fetch_was_terminated!();
self.dispatch_response_progress_event(Atom::from(errormsg));
return_if_fetch_was_terminated!();
self.dispatch_response_progress_event(atom!("loadend"));
Expand All @@ -1032,12 +1026,17 @@ impl XMLHttpRequest {
}

fn dispatch_progress_event(&self, upload: bool, type_: Atom, loaded: u64, total: Option<u64>) {
let (total_length, length_computable) = if self.response_headers.borrow().has::<ContentEncoding>() {
(0, false)
} else {
(total.unwrap_or(0), total.is_some())
};
let progressevent = ProgressEvent::new(&self.global(),
type_,
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
total.is_some(), loaded,
total.unwrap_or(0));
length_computable, loaded,
total_length);
let target = if upload {
self.upload.upcast()
} else {
Expand Down

This file was deleted.

0 comments on commit f938c95

Please sign in to comment.