diff options
author | bors-servo <release+servo@mozilla.com> | 2014-05-03 04:37:11 -0400 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2014-05-03 04:37:11 -0400 |
commit | 53777807f96e64c64f1ef995f54e630122856366 (patch) | |
tree | a25a9e923534a71c5ce58f68336bab7f9c0235ca /src | |
parent | a6f235e285034f8e1f9dd96f143a55056aef0029 (diff) | |
parent | 619da07a4f2b5c303a6b23318f0c249b00adf3fa (diff) | |
download | servo-53777807f96e64c64f1ef995f54e630122856366.tar.gz servo-53777807f96e64c64f1ef995f54e630122856366.zip |
auto merge of #2292 : Manishearth/servo/xhr-webidl, r=Ms2ger
This just gets a working interface with dummy methods in place that can be built on. I'll implement stuff as we go along.
Blocks #2282
Diffstat (limited to 'src')
10 files changed, 364 insertions, 17 deletions
diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index b80cda36b59..053fabae1b2 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -125,6 +125,9 @@ DOMInterfaces = { 'window', ], }, +'XMLHttpRequest': {}, +'XMLHttpRequestEventTarget': {}, +'XMLHttpRequestUpload': {}, 'TestBinding': {}, diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index ab1bd83ea5e..4833b1ab632 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -193,22 +193,11 @@ class CGMethodCall(CGThing): # easy case! signature = possibleSignatures[0] - # (possibly) important optimization: if signature[1] has > - # argCount arguments and signature[1][argCount] is optional and - # there is only one signature for argCount+1, then the - # signature for argCount+1 is just ourselves and we can fall - # through. - if (len(signature[1]) > argCount and - signature[1][argCount].optional and - (argCount+1) in allowedArgCounts and - len(method.signaturesForArgCount(argCount+1)) == 1): - argCountCases.append( - CGCase(str(argCount), None, True)) - else: - sigIndex = signatures.index(signature) - argCountCases.append( - CGCase(str(argCount), getPerSignatureCall(signature, - signatureIndex=sigIndex))) + + sigIndex = signatures.index(signature) + argCountCases.append( + CGCase(str(argCount), getPerSignatureCall(signature, + signatureIndex=sigIndex))) continue distinguishingIndex = method.distinguishingIndexForArgCount(argCount) @@ -2677,6 +2666,7 @@ use js::jsapi::JSContext; use js::jsval::JSVal; #[repr(uint)] +#[deriving(Encodable)] pub enum valuelist { %s } diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index b22af2a9da0..5214aa0aa69 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -10,6 +10,7 @@ use self::EventListenerBinding::EventListener; use dom::event::Event; use dom::eventdispatcher::dispatch_event; use dom::node::NodeTypeId; +use dom::xmlhttprequest::XMLHttpRequestId; use dom::virtualmethods::VirtualMethods; use servo_util::str::DOMString; @@ -23,8 +24,9 @@ pub enum ListenerPhase { #[deriving(Eq,Encodable)] pub enum EventTargetTypeId { + NodeTargetTypeId(NodeTypeId), WindowTypeId, - NodeTargetTypeId(NodeTypeId) + XMLHttpRequestTargetTypeId(XMLHttpRequestId) } #[deriving(Eq,Encodable)] diff --git a/src/components/script/dom/webidls/XMLHttpRequest.webidl b/src/components/script/dom/webidls/XMLHttpRequest.webidl new file mode 100644 index 00000000000..dd3023a05ca --- /dev/null +++ b/src/components/script/dom/webidls/XMLHttpRequest.webidl @@ -0,0 +1,63 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * http://xhr.spec.whatwg.org/#interface-xmlhttprequest + * + * To the extent possible under law, the editor has waived all copyright + * and related or neighboring rights to this work. In addition, as of 1 May 2014, + * the editor has made this specification available under the Open Web Foundation + * Agreement Version 1.0, which is available at + * http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. + */ + +enum XMLHttpRequestResponseType { + "", + "arraybuffer", + "blob", + "document", + "json", + "text" +}; + +[Constructor, + Exposed=Window,Worker] +interface XMLHttpRequest : XMLHttpRequestEventTarget { + // event handler + // attribute EventHandler onreadystatechange; + + // states + const unsigned short UNSENT = 0; + const unsigned short OPENED = 1; + const unsigned short HEADERS_RECEIVED = 2; + const unsigned short LOADING = 3; + const unsigned short DONE = 4; + + readonly attribute unsigned short readyState; + + // request + // void open(/* ByteString */ DOMString method, /* [EnsureUTF16] */ DOMString url); + + // void open(/* ByteString */ DOMString method, /* [EnsureUTF16] */ DOMString url, boolean async, optional /* [EnsureUTF16] */ DOMString? username = null, optional /* [EnsureUTF16] */ DOMString? password = null); + + // void setRequestHeader(/* ByteString */ DOMString name, /* ByteString */ DOMString value); + attribute unsigned long timeout; + attribute boolean withCredentials; + readonly attribute XMLHttpRequestUpload upload; + // void send(optional /*(ArrayBufferView or Blob or Document or [EnsureUTF16] */ DOMString/* or FormData or URLSearchParams)*/? data = null); + // void abort(); + + // response + readonly attribute DOMString responseURL; + readonly attribute unsigned short status; + readonly attribute /* ByteString*/ DOMString statusText; + // DOMString? /*ByteString?*/ getResponseHeader(/*ByteString*/ DOMString name); + // DOMString /*ByteString*/ getAllResponseHeaders(); + // void overrideMimeType(DOMString mime); + attribute XMLHttpRequestResponseType responseType; + // readonly attribute any response; + readonly attribute DOMString responseText; + [Exposed=Window] readonly attribute Document? responseXML; +}; diff --git a/src/components/script/dom/webidls/XMLHttpRequestEventTarget.webidl b/src/components/script/dom/webidls/XMLHttpRequestEventTarget.webidl new file mode 100644 index 00000000000..5a7bbc652b4 --- /dev/null +++ b/src/components/script/dom/webidls/XMLHttpRequestEventTarget.webidl @@ -0,0 +1,28 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * http://xhr.spec.whatwg.org/#interface-xmlhttprequest + * + * To the extent possible under law, the editor has waived all copyright + * and related or neighboring rights to this work. In addition, as of 1 May 2014, + * the editor has made this specification available under the Open Web Foundation + * Agreement Version 1.0, which is available at + * http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. + */ + +/* https://github.com/mozilla/servo/issues/1223: [NoInterfaceObject] */ +interface XMLHttpRequestEventTarget : EventTarget { + // event handlers + /* Needs EventHandler: https://github.com/mozilla/servo/issues/1238 + attribute EventHandler onloadstart; + attribute EventHandler onprogress; + attribute EventHandler onabort; + attribute EventHandler onerror; + attribute EventHandler onload; + attribute EventHandler ontimeout; + attribute EventHandler onloadend; + */ +};
\ No newline at end of file diff --git a/src/components/script/dom/webidls/XMLHttpRequestUpload.webidl b/src/components/script/dom/webidls/XMLHttpRequestUpload.webidl new file mode 100644 index 00000000000..dfb5ffd8255 --- /dev/null +++ b/src/components/script/dom/webidls/XMLHttpRequestUpload.webidl @@ -0,0 +1,18 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * http://xhr.spec.whatwg.org/#interface-xmlhttprequest + * + * To the extent possible under law, the editor has waived all copyright + * and related or neighboring rights to this work. In addition, as of 1 May 2014, + * the editor has made this specification available under the Open Web Foundation + * Agreement Version 1.0, which is available at + * http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. + */ + +[Exposed=Window,Worker] +interface XMLHttpRequestUpload : XMLHttpRequestEventTarget { +}; diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs new file mode 100644 index 00000000000..86b87f33d7c --- /dev/null +++ b/src/components/script/dom/xmlhttprequest.rs @@ -0,0 +1,152 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::BindingDeclarations::XMLHttpRequestBinding; +use self::XMLHttpRequestBinding::XMLHttpRequestResponseType; +use self::XMLHttpRequestBinding::XMLHttpRequestResponseTypeValues::_empty; +use dom::bindings::codegen::InheritTypes::XMLHttpRequestDerived; +use dom::document::Document; +use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; +use dom::bindings::error::Fallible; +use dom::bindings::js::JS; +use js::jsapi::JSContext; +use js::jsval::{JSVal, NullValue}; +use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; +use dom::window::Window; +use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget; +use dom::xmlhttprequestupload::XMLHttpRequestUpload; +use servo_util::str::DOMString; + +#[deriving(Eq,Encodable)] +pub enum XMLHttpRequestId { + XMLHttpRequestTypeId, + XMLHttpRequestUploadTypeId +} + +#[deriving(Encodable)] +pub struct XMLHttpRequest { + eventtarget: XMLHttpRequestEventTarget, + ready_state: u16, + timeout: u32, + with_credentials: bool, + upload: JS<XMLHttpRequestUpload>, + response_url: DOMString, + status: u16, + status_text: DOMString, + response_type: XMLHttpRequestResponseType, + response_text: DOMString, + response_xml: Option<JS<Document>> +} + +impl XMLHttpRequest { + pub fn new_inherited(owner: &JS<Window>) -> XMLHttpRequest { + XMLHttpRequest { + eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId), + ready_state: 0, + timeout: 0u32, + with_credentials: false, + upload: XMLHttpRequestUpload::new(owner), + response_url: ~"", + status: 0, + status_text: ~"", + response_type: _empty, + response_text: ~"", + response_xml: None + } + } + pub fn new(window: &JS<Window>) -> JS<XMLHttpRequest> { + reflect_dom_object(~XMLHttpRequest::new_inherited(window), + window, + XMLHttpRequestBinding::Wrap) + } + pub fn Constructor(owner: &JS<Window>) -> Fallible<JS<XMLHttpRequest>> { + Ok(XMLHttpRequest::new(owner)) + } + pub fn ReadyState(&self) -> u16 { + self.ready_state + } + pub fn Open(&self, _method: DOMString, _url: DOMString) { + + } + pub fn Open_(&self, _method: DOMString, _url: DOMString, _async: bool, + _username: Option<DOMString>, _password: Option<DOMString>) { + + } + pub fn SetRequestHeader(&self, _name: DOMString, _value: DOMString) { + + } + pub fn Timeout(&self) -> u32 { + self.timeout + } + pub fn SetTimeout(&mut self, timeout: u32) { + self.timeout = timeout + } + pub fn WithCredentials(&self) -> bool { + self.with_credentials + } + pub fn SetWithCredentials(&mut self, with_credentials: bool) { + self.with_credentials = with_credentials + } + pub fn Upload(&self) -> JS<XMLHttpRequestUpload> { + self.upload.clone() + } + pub fn Send(&self, _data: Option<DOMString>) { + + } + pub fn Abort(&self) { + + } + pub fn ResponseURL(&self) -> DOMString { + self.response_url.clone() + } + pub fn Status(&self) -> u16 { + self.status + } + pub fn StatusText(&self) -> DOMString { + self.status_text.clone() + } + pub fn GetResponseHeader(&self, _name: DOMString) -> Option<DOMString> { + None + } + pub fn GetAllResponseHeaders(&self) -> DOMString { + ~"" + } + pub fn OverrideMimeType(&self, _mime: DOMString) { + + } + pub fn ResponseType(&self) -> XMLHttpRequestResponseType { + self.response_type + } + pub fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) { + self.response_type = response_type + } + pub fn Response(&self, _cx: *JSContext) -> JSVal { + NullValue() + } + pub fn ResponseText(&self) -> DOMString { + self.response_text.clone() + } + pub fn GetResponseXML(&self) -> Option<JS<Document>> { + self.response_xml.clone() + } +} + +impl Reflectable for XMLHttpRequest { + fn reflector<'a>(&'a self) -> &'a Reflector { + self.eventtarget.reflector() + } + + fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { + self.eventtarget.mut_reflector() + } +} + +impl XMLHttpRequestDerived for EventTarget { + fn is_xmlhttprequest(&self) -> bool { + match self.type_id { + XMLHttpRequestTargetTypeId(XMLHttpRequestTypeId) => true, + _ => false + } + } +}
\ No newline at end of file diff --git a/src/components/script/dom/xmlhttprequesteventtarget.rs b/src/components/script/dom/xmlhttprequesteventtarget.rs new file mode 100644 index 00000000000..55708581a1d --- /dev/null +++ b/src/components/script/dom/xmlhttprequesteventtarget.rs @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::InheritTypes::XMLHttpRequestEventTargetDerived; +use dom::bindings::utils::{Reflectable, Reflector}; +use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; +use dom::xmlhttprequest::XMLHttpRequestId; + +#[deriving(Encodable)] +pub struct XMLHttpRequestEventTarget { + pub eventtarget: EventTarget, +} + +impl XMLHttpRequestEventTarget { + pub fn new_inherited(type_id: XMLHttpRequestId) -> XMLHttpRequestEventTarget { + XMLHttpRequestEventTarget { + eventtarget: EventTarget::new_inherited(XMLHttpRequestTargetTypeId(type_id)) + } + } +} +impl XMLHttpRequestEventTargetDerived for EventTarget { + fn is_xmlhttprequesteventtarget(&self) -> bool { + match self.type_id { + XMLHttpRequestTargetTypeId(_) => true, + _ => false + } + } + +} + +impl Reflectable for XMLHttpRequestEventTarget { + fn reflector<'a>(&'a self) -> &'a Reflector { + self.eventtarget.reflector() + } + + fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { + self.eventtarget.mut_reflector() + } +}
\ No newline at end of file diff --git a/src/components/script/dom/xmlhttprequestupload.rs b/src/components/script/dom/xmlhttprequestupload.rs new file mode 100644 index 00000000000..bcfb2d02c47 --- /dev/null +++ b/src/components/script/dom/xmlhttprequestupload.rs @@ -0,0 +1,48 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::InheritTypes::XMLHttpRequestUploadDerived; +use dom::bindings::codegen::BindingDeclarations::XMLHttpRequestUploadBinding; +use dom::bindings::js::JS; +use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; +use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId}; +use dom::window::Window; +use dom::xmlhttprequest::{XMLHttpRequestUploadTypeId}; +use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget; + +#[deriving(Encodable)] +pub struct XMLHttpRequestUpload { + eventtarget: XMLHttpRequestEventTarget +} + +impl XMLHttpRequestUpload { + pub fn new_inherited() -> XMLHttpRequestUpload { + XMLHttpRequestUpload { + eventtarget:XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestUploadTypeId) + } + } + pub fn new(window: &JS<Window>) -> JS<XMLHttpRequestUpload> { + reflect_dom_object(~XMLHttpRequestUpload::new_inherited(), + window, + XMLHttpRequestUploadBinding::Wrap) + } +} +impl Reflectable for XMLHttpRequestUpload { + fn reflector<'a>(&'a self) -> &'a Reflector { + self.eventtarget.reflector() + } + + fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { + self.eventtarget.mut_reflector() + } +} + +impl XMLHttpRequestUploadDerived for EventTarget { + fn is_xmlhttprequestupload(&self) -> bool { + match self.type_id { + XMLHttpRequestTargetTypeId(XMLHttpRequestUploadTypeId) => true, + _ => false + } + } +}
\ No newline at end of file diff --git a/src/components/script/script.rs b/src/components/script/script.rs index 9536a4f20ca..158416771cc 100644 --- a/src/components/script/script.rs +++ b/src/components/script/script.rs @@ -159,6 +159,9 @@ pub mod dom { pub mod validitystate; pub mod virtualmethods; pub mod window; + pub mod xmlhttprequest; + pub mod xmlhttprequesteventtarget; + pub mod xmlhttprequestupload; pub mod testbinding; } |