XMLHttpRequest.webidl (4338B)
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. 5 * 6 * The origin of this IDL file is 7 * https://xhr.spec.whatwg.org/#interface-xmlhttprequest 8 * 9 * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C 10 * liability, trademark and document use rules apply. 11 */ 12 13 interface InputStream; 14 interface MozChannel; 15 16 enum XMLHttpRequestResponseType { 17 "", 18 "arraybuffer", 19 "blob", 20 "document", 21 "json", 22 "text", 23 }; 24 25 /** 26 * Parameters for instantiating an XMLHttpRequest. They are passed as an 27 * optional argument to the constructor: 28 * 29 * new XMLHttpRequest({anon: true, system: true}); 30 */ 31 dictionary MozXMLHttpRequestParameters 32 { 33 /** 34 * If true, the request will be sent without cookie and authentication 35 * headers. Defaults to true for system/privileged/chrome requests, 36 * and to false otherwise. 37 * Note that even if set to true, for system/privileged/chrome requests, 38 * manually-set 'Cookie' headers are not removed. 39 */ 40 boolean mozAnon; 41 42 /** 43 * If true, the same origin policy will not be enforced on the request. 44 */ 45 boolean mozSystem = false; 46 }; 47 48 [Exposed=(Window,DedicatedWorker,SharedWorker)] 49 interface XMLHttpRequest : XMLHttpRequestEventTarget { 50 [Throws] 51 constructor(optional MozXMLHttpRequestParameters params = {}); 52 // There are apparently callers, specifically CoffeeScript, who do 53 // things like this: 54 // c = new(window.ActiveXObject || XMLHttpRequest)("Microsoft.XMLHTTP") 55 // To handle that, we need a constructor that takes a string. 56 [Throws] 57 constructor(DOMString ignored); 58 59 // event handler 60 attribute EventHandler onreadystatechange; 61 62 // states 63 const unsigned short UNSENT = 0; 64 const unsigned short OPENED = 1; 65 const unsigned short HEADERS_RECEIVED = 2; 66 const unsigned short LOADING = 3; 67 const unsigned short DONE = 4; 68 69 readonly attribute unsigned short readyState; 70 71 // request 72 [Throws] 73 undefined open(ByteString method, UTF8String url); 74 [Throws] 75 undefined open(ByteString method, UTF8String url, boolean async, 76 optional UTF8String? user=null, optional UTF8String? password=null); 77 [Throws] 78 undefined setRequestHeader(ByteString header, ByteString value); 79 80 [SetterThrows] 81 attribute unsigned long timeout; 82 83 [SetterThrows] 84 attribute boolean withCredentials; 85 86 [Throws] 87 readonly attribute XMLHttpRequestUpload upload; 88 89 [Throws] 90 undefined send(optional (Document or XMLHttpRequestBodyInit)? body = null); 91 92 [Throws] 93 undefined abort(); 94 95 // response 96 readonly attribute UTF8String responseURL; 97 98 [Throws] 99 readonly attribute unsigned short status; 100 101 [Throws] 102 readonly attribute ByteString statusText; 103 104 [Throws] 105 ByteString? getResponseHeader(ByteString header); 106 107 [Throws] 108 ByteString getAllResponseHeaders(); 109 110 // Not UTF8String, because CMimeType::Parse 111 // has Latin1 rather than UTF-8 semantics. 112 [Throws] 113 undefined overrideMimeType(DOMString mime); 114 115 [SetterThrows] 116 attribute XMLHttpRequestResponseType responseType; 117 [Throws] 118 readonly attribute any response; 119 120 // This is really USVString, but this string is potentially large, 121 // and we already know that it's valid UTF-16, since it came out of 122 // an encoding converter, so let's not have the binding layer 123 // do UTF-16 validation on a known-valid value. 124 [Cached, Pure, Throws] 125 readonly attribute DOMString? responseText; 126 127 [Throws, Exposed=Window] 128 readonly attribute Document? responseXML; 129 130 // Mozilla-specific stuff 131 132 [ChromeOnly, SetterThrows] 133 attribute boolean mozBackgroundRequest; 134 135 [ChromeOnly, Exposed=Window] 136 readonly attribute MozChannel? channel; 137 138 [Throws, ChromeOnly, Exposed=Window] 139 any getInterface(any iid); 140 141 [ChromeOnly, Exposed=Window] 142 undefined setOriginAttributes(optional OriginAttributesDictionary originAttributes = {}); 143 144 [ChromeOnly, Throws] 145 undefined sendInputStream(InputStream body); 146 147 // Only works on MainThread. 148 // Its permanence is to be evaluated in bug 1368540 for Firefox 60. 149 [ChromeOnly] 150 readonly attribute unsigned short errorCode; 151 152 readonly attribute boolean mozAnon; 153 readonly attribute boolean mozSystem; 154 };