mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Implement the overrideMimeType method for XMLHttpRequest
This commit is contained in:
parent
4067960ba5
commit
ed809a60bf
11 changed files with 32 additions and 26 deletions
|
@ -45,6 +45,7 @@ use euclid::size::Size2D;
|
||||||
use html5ever::tree_builder::QuirksMode;
|
use html5ever::tree_builder::QuirksMode;
|
||||||
use hyper::header::Headers;
|
use hyper::header::Headers;
|
||||||
use hyper::method::Method;
|
use hyper::method::Method;
|
||||||
|
use hyper::mime::Mime;
|
||||||
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||||
use js::jsapi::JS_CallUnbarrieredObjectTracer;
|
use js::jsapi::JS_CallUnbarrieredObjectTracer;
|
||||||
use js::jsapi::{GCTraceKindToAscii, Heap, JSGCTraceKind, JSObject, JSTracer, JS_CallObjectTracer, JS_CallValueTracer};
|
use js::jsapi::{GCTraceKindToAscii, Heap, JSGCTraceKind, JSObject, JSTracer, JS_CallObjectTracer, JS_CallValueTracer};
|
||||||
|
@ -286,6 +287,7 @@ no_jsmanaged_fields!(PseudoElement);
|
||||||
no_jsmanaged_fields!(Length);
|
no_jsmanaged_fields!(Length);
|
||||||
no_jsmanaged_fields!(ElementState);
|
no_jsmanaged_fields!(ElementState);
|
||||||
no_jsmanaged_fields!(DOMString);
|
no_jsmanaged_fields!(DOMString);
|
||||||
|
no_jsmanaged_fields!(Mime);
|
||||||
|
|
||||||
impl JSTraceable for Box<ScriptChan + Send> {
|
impl JSTraceable for Box<ScriptChan + Send> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -65,7 +65,8 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget {
|
||||||
readonly attribute ByteString statusText;
|
readonly attribute ByteString statusText;
|
||||||
ByteString? getResponseHeader(ByteString name);
|
ByteString? getResponseHeader(ByteString name);
|
||||||
ByteString getAllResponseHeaders();
|
ByteString getAllResponseHeaders();
|
||||||
// void overrideMimeType(DOMString mime);
|
[Throws]
|
||||||
|
void overrideMimeType(DOMString mime);
|
||||||
[SetterThrows]
|
[SetterThrows]
|
||||||
attribute XMLHttpRequestResponseType responseType;
|
attribute XMLHttpRequestResponseType responseType;
|
||||||
readonly attribute any response;
|
readonly attribute any response;
|
||||||
|
|
|
@ -121,6 +121,9 @@ pub struct XMLHttpRequest {
|
||||||
response_xml: MutNullableHeap<JS<Document>>,
|
response_xml: MutNullableHeap<JS<Document>>,
|
||||||
#[ignore_heap_size_of = "Defined in hyper"]
|
#[ignore_heap_size_of = "Defined in hyper"]
|
||||||
response_headers: DOMRefCell<Headers>,
|
response_headers: DOMRefCell<Headers>,
|
||||||
|
override_mime_type: DOMRefCell<Option<Mime>>,
|
||||||
|
#[ignore_heap_size_of = "Defined in rust-encoding"]
|
||||||
|
override_charset: DOMRefCell<Option<EncodingRef>>,
|
||||||
|
|
||||||
// Associated concepts
|
// Associated concepts
|
||||||
request_method: DOMRefCell<Method>,
|
request_method: DOMRefCell<Method>,
|
||||||
|
@ -158,6 +161,8 @@ impl XMLHttpRequest {
|
||||||
response_type: Cell::new(_empty),
|
response_type: Cell::new(_empty),
|
||||||
response_xml: Default::default(),
|
response_xml: Default::default(),
|
||||||
response_headers: DOMRefCell::new(Headers::new()),
|
response_headers: DOMRefCell::new(Headers::new()),
|
||||||
|
override_mime_type: DOMRefCell::new(None),
|
||||||
|
override_charset: DOMRefCell::new(None),
|
||||||
|
|
||||||
request_method: DOMRefCell::new(Method::Get),
|
request_method: DOMRefCell::new(Method::Get),
|
||||||
request_url: DOMRefCell::new(None),
|
request_url: DOMRefCell::new(None),
|
||||||
|
@ -644,6 +649,21 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
ByteString::new(self.filter_response_headers().to_string().into_bytes())
|
ByteString::new(self.filter_response_headers().to_string().into_bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://xhr.spec.whatwg.org/#the-overridemimetype()-method
|
||||||
|
fn OverrideMimeType(&self, mime: DOMString) -> ErrorResult {
|
||||||
|
match self.ready_state.get() {
|
||||||
|
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => return Err(Error::InvalidState),
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
let override_mime = try!(mime.parse::<Mime>().map_err(|_| Error::Syntax));
|
||||||
|
*self.override_mime_type.borrow_mut() = Some(override_mime.clone());
|
||||||
|
let value = override_mime.get_param(mime::Attr::Charset);
|
||||||
|
*self.override_charset.borrow_mut() = value.and_then(|value| {
|
||||||
|
encoding_from_whatwg_label(value)
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// https://xhr.spec.whatwg.org/#the-responsetype-attribute
|
// https://xhr.spec.whatwg.org/#the-responsetype-attribute
|
||||||
fn ResponseType(&self) -> XMLHttpRequestResponseType {
|
fn ResponseType(&self) -> XMLHttpRequestResponseType {
|
||||||
self.response_type.get()
|
self.response_type.get()
|
||||||
|
@ -987,6 +1007,7 @@ impl XMLHttpRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FIXME: add support for override_mime_type and override_charset
|
||||||
fn text_response(&self) -> String {
|
fn text_response(&self) -> String {
|
||||||
let mut encoding = UTF_8 as EncodingRef;
|
let mut encoding = UTF_8 as EncodingRef;
|
||||||
match self.response_headers.borrow().get() {
|
match self.response_headers.borrow().get() {
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
[interfaces.html]
|
[interfaces.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
[XMLHttpRequest interface: operation overrideMimeType(DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XMLHttpRequest interface: calling overrideMimeType(DOMString) on new XMLHttpRequest() with too few arguments must throw TypeError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[FormData interface: new FormData() must inherit property "getAll" with the proper type (4)]
|
[FormData interface: new FormData() must inherit property "getAll" with the proper type (4)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[FormData interface: new FormData(form) must inherit property "getAll" with the proper type (4)]
|
[FormData interface: new FormData(form) must inherit property "getAll" with the proper type (4)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[XMLHttpRequest interface: new XMLHttpRequest() must inherit property "overrideMimeType" with the proper type (20)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[FormData interface: operation getAll(USVString)]
|
[FormData interface: operation getAll(USVString)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[overridemimetype-done-state.htm]
|
|
||||||
type: testharness
|
|
||||||
[XMLHttpRequest: overrideMimeType() in DONE state]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[overridemimetype-invalid-mime-type.htm]
|
|
||||||
type: testharness
|
|
||||||
[XMLHttpRequest: overrideMimeType() in unsent state, invalid MIME types]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[overridemimetype-loading-state.htm]
|
|
||||||
type: testharness
|
|
||||||
[XMLHttpRequest: overrideMimeType() in LOADING state]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[overridemimetype-open-state-force-utf-8.htm]
|
[overridemimetype-open-state-force-utf-8.htm]
|
||||||
type: testharness
|
type: testharness
|
||||||
|
expected: CRASH
|
||||||
[XMLHttpRequest: overrideMimeType() in open state, enforcing UTF-8 encoding]
|
[XMLHttpRequest: overrideMimeType() in open state, enforcing UTF-8 encoding]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[overridemimetype-open-state-force-xml.htm]
|
[overridemimetype-open-state-force-xml.htm]
|
||||||
type: testharness
|
type: testharness
|
||||||
|
expected: TIMEOUT
|
||||||
[XMLHttpRequest: overrideMimeType() in open state, XML MIME type with UTF-8 charset]
|
[XMLHttpRequest: overrideMimeType() in open state, XML MIME type with UTF-8 charset]
|
||||||
expected: FAIL
|
expected: TIMEOUT
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[overridemimetype-unsent-state-force-shiftjis.htm]
|
[overridemimetype-unsent-state-force-shiftjis.htm]
|
||||||
type: testharness
|
type: testharness
|
||||||
|
expected: CRASH
|
||||||
[XMLHttpRequest: overrideMimeType() in unsent state, enforcing Shift-JIS encoding]
|
[XMLHttpRequest: overrideMimeType() in unsent state, enforcing Shift-JIS encoding]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,6 @@
|
||||||
[XML document, windows-1252]
|
[XML document, windows-1252]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
[HTML document, invalid UTF-8]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue