Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsIDOMEventTarget.idl" |
michael@0 | 7 | |
michael@0 | 8 | interface nsIChannel; |
michael@0 | 9 | interface nsIDOMDocument; |
michael@0 | 10 | interface nsIDOMEventListener; |
michael@0 | 11 | interface nsIPrincipal; |
michael@0 | 12 | interface nsIScriptContext; |
michael@0 | 13 | interface nsIURI; |
michael@0 | 14 | interface nsIVariant; |
michael@0 | 15 | interface nsIGlobalObject; |
michael@0 | 16 | interface nsIInputStream; |
michael@0 | 17 | interface nsIDOMBlob; |
michael@0 | 18 | |
michael@0 | 19 | [scriptable, builtinclass, uuid(5ced7e7a-e2c3-4563-a57d-31b97ce64dc5)] |
michael@0 | 20 | interface nsIXMLHttpRequestEventTarget : nsIDOMEventTarget { |
michael@0 | 21 | // event handler attributes |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | [scriptable, builtinclass, uuid(df3796fa-d98a-4185-9dda-d2f2b56a5d38)] |
michael@0 | 25 | interface nsIXMLHttpRequestUpload : nsIXMLHttpRequestEventTarget { |
michael@0 | 26 | // for future use |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * Mozilla's XMLHttpRequest is modelled after Microsoft's IXMLHttpRequest |
michael@0 | 31 | * object. The goal has been to make Mozilla's version match Microsoft's |
michael@0 | 32 | * version as closely as possible, but there are bound to be some differences. |
michael@0 | 33 | * |
michael@0 | 34 | * In general, Microsoft's documentation for IXMLHttpRequest can be used. |
michael@0 | 35 | * Mozilla's interface definitions provide some additional documentation. The |
michael@0 | 36 | * web page to look at is http://www.mozilla.org/xmlextras/ |
michael@0 | 37 | * |
michael@0 | 38 | * Mozilla's XMLHttpRequest object can be created in JavaScript like this: |
michael@0 | 39 | * new XMLHttpRequest() |
michael@0 | 40 | * compare to Internet Explorer: |
michael@0 | 41 | * new ActiveXObject("Msxml2.XMLHTTP") |
michael@0 | 42 | * |
michael@0 | 43 | * From JavaScript, the methods and properties visible in the XMLHttpRequest |
michael@0 | 44 | * object are a combination of nsIXMLHttpRequest and nsIJSXMLHttpRequest; |
michael@0 | 45 | * there is no need to differentiate between those interfaces. |
michael@0 | 46 | * |
michael@0 | 47 | * From native code, the way to set up onload and onerror handlers is a bit |
michael@0 | 48 | * different. Here is a comment from Johnny Stenback <jst@netscape.com>: |
michael@0 | 49 | * |
michael@0 | 50 | * The mozilla implementation of nsIXMLHttpRequest implements the interface |
michael@0 | 51 | * nsIDOMEventTarget and that's how you're supported to add event listeners. |
michael@0 | 52 | * Try something like this: |
michael@0 | 53 | * |
michael@0 | 54 | * nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(myxmlhttpreq)); |
michael@0 | 55 | * |
michael@0 | 56 | * target->AddEventListener(NS_LITERAL_STRING("load"), mylistener, |
michael@0 | 57 | * PR_FALSE) |
michael@0 | 58 | * |
michael@0 | 59 | * where mylistener is your event listener object that implements the |
michael@0 | 60 | * interface nsIDOMEventListener. |
michael@0 | 61 | * |
michael@0 | 62 | * The 'onload', 'onerror', and 'onreadystatechange' attributes moved to |
michael@0 | 63 | * nsIJSXMLHttpRequest, but if you're coding in C++ you should avoid using |
michael@0 | 64 | * those. |
michael@0 | 65 | * |
michael@0 | 66 | * Conclusion: Do not use event listeners on XMLHttpRequest from C++, unless |
michael@0 | 67 | * you're aware of all the security implications. And then think twice about |
michael@0 | 68 | * it. |
michael@0 | 69 | */ |
michael@0 | 70 | [scriptable, uuid(2e91e088-e9fa-4ba4-9887-2a0b7cf27a3e)] |
michael@0 | 71 | interface nsIXMLHttpRequest : nsISupports |
michael@0 | 72 | { |
michael@0 | 73 | /** |
michael@0 | 74 | * The request uses a channel in order to perform the |
michael@0 | 75 | * request. This attribute represents the channel used |
michael@0 | 76 | * for the request. NULL if the channel has not yet been |
michael@0 | 77 | * created. |
michael@0 | 78 | * |
michael@0 | 79 | * Mozilla only. Requires elevated privileges to access. |
michael@0 | 80 | */ |
michael@0 | 81 | readonly attribute nsIChannel channel; |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * The response to the request is parsed as if it were a |
michael@0 | 85 | * text/xml stream. This attributes represents the response as |
michael@0 | 86 | * a DOM Document object. NULL if the request is unsuccessful or |
michael@0 | 87 | * has not yet been sent. |
michael@0 | 88 | */ |
michael@0 | 89 | readonly attribute nsIDOMDocument responseXML; |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * The response to the request as text. |
michael@0 | 93 | * NULL if the request is unsuccessful or |
michael@0 | 94 | * has not yet been sent. |
michael@0 | 95 | */ |
michael@0 | 96 | readonly attribute AString responseText; |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Determine a response format which response attribute returns. |
michael@0 | 100 | * empty string (initial value) or "text": as text. |
michael@0 | 101 | * "arraybuffer": as a typed array ArrayBuffer. |
michael@0 | 102 | * "blob": as a File API Blob. |
michael@0 | 103 | * "document": as a DOM Document object. |
michael@0 | 104 | */ |
michael@0 | 105 | attribute AString responseType; |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * The response to the request as a specified format by responseType. |
michael@0 | 109 | * NULL if the request is unsuccessful or |
michael@0 | 110 | * has not yet been sent. |
michael@0 | 111 | */ |
michael@0 | 112 | [implicit_jscontext] readonly attribute jsval /* any */ response; |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * The status of the response to the request for HTTP requests. |
michael@0 | 116 | */ |
michael@0 | 117 | // XXX spec says unsigned short |
michael@0 | 118 | readonly attribute unsigned long status; |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * The string representing the status of the response for |
michael@0 | 122 | * HTTP requests. |
michael@0 | 123 | */ |
michael@0 | 124 | readonly attribute ACString statusText; |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * If the request has been sent already, this method will |
michael@0 | 128 | * abort the request. |
michael@0 | 129 | */ |
michael@0 | 130 | [binaryname(SlowAbort)] void abort(); |
michael@0 | 131 | |
michael@0 | 132 | /** |
michael@0 | 133 | * Returns all of the response headers as a string for HTTP |
michael@0 | 134 | * requests. |
michael@0 | 135 | * |
michael@0 | 136 | * @returns A string containing all of the response headers. |
michael@0 | 137 | * The empty string if the response has not yet been received. |
michael@0 | 138 | */ |
michael@0 | 139 | ACString getAllResponseHeaders(); |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * Returns the text of the header with the specified name for |
michael@0 | 143 | * HTTP requests. |
michael@0 | 144 | * |
michael@0 | 145 | * @param header The name of the header to retrieve |
michael@0 | 146 | * @returns A string containing the text of the header specified. |
michael@0 | 147 | * NULL if the response has not yet been received or the |
michael@0 | 148 | * header does not exist in the response. |
michael@0 | 149 | */ |
michael@0 | 150 | ACString getResponseHeader(in ACString header); |
michael@0 | 151 | |
michael@0 | 152 | %{C++ |
michael@0 | 153 | // note this is NOT virtual so this won't muck with the vtable! |
michael@0 | 154 | inline nsresult Open(const nsACString& method, const nsACString& url, |
michael@0 | 155 | bool async, const nsAString& user, |
michael@0 | 156 | const nsAString& password) { |
michael@0 | 157 | return Open(method, url, async, user, password, 3); |
michael@0 | 158 | } |
michael@0 | 159 | %} |
michael@0 | 160 | /** |
michael@0 | 161 | * Meant to be a script-only method for initializing a request. |
michael@0 | 162 | * |
michael@0 | 163 | * If there is an "active" request (that is, if open() has been called |
michael@0 | 164 | * already), this is equivalent to calling abort() and then open(). |
michael@0 | 165 | * |
michael@0 | 166 | * @param method The HTTP method - either "POST" or "GET". Ignored |
michael@0 | 167 | * if the URL is not a HTTP URL. |
michael@0 | 168 | * @param url The URL to which to send the request. |
michael@0 | 169 | * @param async (optional) Whether the request is synchronous or |
michael@0 | 170 | * asynchronous i.e. whether send returns only after |
michael@0 | 171 | * the response is received or if it returns immediately after |
michael@0 | 172 | * sending the request. In the latter case, notification |
michael@0 | 173 | * of completion is sent through the event listeners. |
michael@0 | 174 | * The default value is true. |
michael@0 | 175 | * @param user (optional) A username for authentication if necessary. |
michael@0 | 176 | * The default value is the empty string |
michael@0 | 177 | * @param password (optional) A password for authentication if necessary. |
michael@0 | 178 | * The default value is the empty string |
michael@0 | 179 | */ |
michael@0 | 180 | [optional_argc] void open(in ACString method, in AUTF8String url, |
michael@0 | 181 | [optional] in boolean async, |
michael@0 | 182 | [optional,Undefined(Empty)] in DOMString user, |
michael@0 | 183 | [optional,Undefined(Empty)] in DOMString password); |
michael@0 | 184 | |
michael@0 | 185 | /** |
michael@0 | 186 | * Sends the request. If the request is asynchronous, returns |
michael@0 | 187 | * immediately after sending the request. If it is synchronous |
michael@0 | 188 | * returns only after the response has been received. |
michael@0 | 189 | * |
michael@0 | 190 | * All event listeners must be set before calling send(). |
michael@0 | 191 | * |
michael@0 | 192 | * After the initial response, all event listeners will be cleared. |
michael@0 | 193 | * // XXXbz what does that mean, exactly? |
michael@0 | 194 | * |
michael@0 | 195 | * @param body Either an instance of nsIDOMDocument, nsIInputStream |
michael@0 | 196 | * or a string (nsISupportsString in the native calling |
michael@0 | 197 | * case). This is used to populate the body of the |
michael@0 | 198 | * HTTP request if the HTTP request method is "POST". |
michael@0 | 199 | * If the parameter is a nsIDOMDocument, it is serialized. |
michael@0 | 200 | * If the parameter is a nsIInputStream, then it must be |
michael@0 | 201 | * compatible with nsIUploadChannel.setUploadStream, and a |
michael@0 | 202 | * Content-Length header will be added to the HTTP request |
michael@0 | 203 | * with a value given by nsIInputStream.available. Any |
michael@0 | 204 | * headers included at the top of the stream will be |
michael@0 | 205 | * treated as part of the message body. The MIME type of |
michael@0 | 206 | * the stream should be specified by setting the Content- |
michael@0 | 207 | * Type header via the setRequestHeader method before |
michael@0 | 208 | * calling send. |
michael@0 | 209 | */ |
michael@0 | 210 | void send([optional] in nsIVariant body); |
michael@0 | 211 | |
michael@0 | 212 | /** |
michael@0 | 213 | * A variant of the send() method used to send binary data. |
michael@0 | 214 | * |
michael@0 | 215 | * @param body The request body as a DOM string. The string data will be |
michael@0 | 216 | * converted to a single-byte string by truncation (i.e., the |
michael@0 | 217 | * high-order byte of each character will be discarded). |
michael@0 | 218 | */ |
michael@0 | 219 | void sendAsBinary(in DOMString body); |
michael@0 | 220 | |
michael@0 | 221 | /** |
michael@0 | 222 | * Sets a HTTP request header for HTTP requests. You must call open |
michael@0 | 223 | * before setting the request headers. |
michael@0 | 224 | * |
michael@0 | 225 | * @param header The name of the header to set in the request. |
michael@0 | 226 | * @param value The body of the header. |
michael@0 | 227 | */ |
michael@0 | 228 | void setRequestHeader(in ACString header, in ACString value); |
michael@0 | 229 | |
michael@0 | 230 | /** |
michael@0 | 231 | * The amount of milliseconds a request can take before being terminated. |
michael@0 | 232 | * Initially zero. Zero means there is no timeout. |
michael@0 | 233 | */ |
michael@0 | 234 | attribute unsigned long timeout; |
michael@0 | 235 | |
michael@0 | 236 | /** |
michael@0 | 237 | * The state of the request. |
michael@0 | 238 | * |
michael@0 | 239 | * Possible values: |
michael@0 | 240 | * 0 UNSENT open() has not been called yet. |
michael@0 | 241 | * 1 OPENED send() has not been called yet. |
michael@0 | 242 | * 2 HEADERS_RECEIVED |
michael@0 | 243 | * send() has been called, headers and status are available. |
michael@0 | 244 | * 3 LOADING Downloading, responseText holds the partial data. |
michael@0 | 245 | * 4 DONE Finished with all operations. |
michael@0 | 246 | */ |
michael@0 | 247 | const unsigned short UNSENT = 0; |
michael@0 | 248 | const unsigned short OPENED = 1; |
michael@0 | 249 | const unsigned short HEADERS_RECEIVED = 2; |
michael@0 | 250 | const unsigned short LOADING = 3; |
michael@0 | 251 | const unsigned short DONE = 4; |
michael@0 | 252 | readonly attribute unsigned short readyState; |
michael@0 | 253 | |
michael@0 | 254 | /** |
michael@0 | 255 | * Override the mime type returned by the server (if any). This may |
michael@0 | 256 | * be used, for example, to force a stream to be treated and parsed |
michael@0 | 257 | * as text/xml, even if the server does not report it as such. This |
michael@0 | 258 | * must be done before the <code>send</code> method is invoked. |
michael@0 | 259 | * |
michael@0 | 260 | * @param mimetype The type used to override that returned by the server |
michael@0 | 261 | * (if any). |
michael@0 | 262 | */ |
michael@0 | 263 | [binaryname(SlowOverrideMimeType)] void overrideMimeType(in DOMString mimetype); |
michael@0 | 264 | |
michael@0 | 265 | /** |
michael@0 | 266 | * Set to true if this is a background service request. This will |
michael@0 | 267 | * prevent a load group being associated with the request, and |
michael@0 | 268 | * suppress any security dialogs from being shown * to the user. |
michael@0 | 269 | * In the cases where one of those dialogs would be shown, the request |
michael@0 | 270 | * will simply fail instead. |
michael@0 | 271 | */ |
michael@0 | 272 | attribute boolean mozBackgroundRequest; |
michael@0 | 273 | |
michael@0 | 274 | /** |
michael@0 | 275 | * When set to true attempts to make cross-site Access-Control requests |
michael@0 | 276 | * with credentials such as cookies and authorization headers. |
michael@0 | 277 | * |
michael@0 | 278 | * Never affects same-site requests. |
michael@0 | 279 | * |
michael@0 | 280 | * Defaults to false. |
michael@0 | 281 | */ |
michael@0 | 282 | attribute boolean withCredentials; |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Initialize the object for use from C++ code with the principal, script |
michael@0 | 286 | * context, and owner window that should be used. |
michael@0 | 287 | * |
michael@0 | 288 | * @param principal The principal to use for the request. This must not be |
michael@0 | 289 | * null. |
michael@0 | 290 | * @param scriptContext The script context to use for the request. May be |
michael@0 | 291 | * null. |
michael@0 | 292 | * @param globalObject The associated global for the request. Can be the |
michael@0 | 293 | * outer window, a sandbox, or a backstage pass. |
michael@0 | 294 | * May be null, but then the request cannot create a |
michael@0 | 295 | * document. |
michael@0 | 296 | * @param baseURI The base URI to use when resolving relative URIs. May be |
michael@0 | 297 | * null. |
michael@0 | 298 | */ |
michael@0 | 299 | [noscript] void init(in nsIPrincipal principal, |
michael@0 | 300 | in nsIScriptContext scriptContext, |
michael@0 | 301 | in nsIGlobalObject globalObject, |
michael@0 | 302 | in nsIURI baseURI); |
michael@0 | 303 | |
michael@0 | 304 | /** |
michael@0 | 305 | * Upload process can be tracked by adding event listener to |upload|. |
michael@0 | 306 | */ |
michael@0 | 307 | readonly attribute nsIXMLHttpRequestUpload upload; |
michael@0 | 308 | |
michael@0 | 309 | /** |
michael@0 | 310 | * Meant to be a script-only mechanism for setting a callback function. |
michael@0 | 311 | * The attribute is expected to be JavaScript function object. When the |
michael@0 | 312 | * readyState changes, the callback function will be called. |
michael@0 | 313 | * This attribute should not be used from native code!! |
michael@0 | 314 | * |
michael@0 | 315 | * After the initial response, all event listeners will be cleared. |
michael@0 | 316 | * // XXXbz what does that mean, exactly? |
michael@0 | 317 | * |
michael@0 | 318 | * Call open() before setting an onreadystatechange listener. |
michael@0 | 319 | */ |
michael@0 | 320 | [implicit_jscontext] attribute jsval onreadystatechange; |
michael@0 | 321 | |
michael@0 | 322 | /** |
michael@0 | 323 | * If true, the request will be sent without cookie and authentication |
michael@0 | 324 | * headers. |
michael@0 | 325 | */ |
michael@0 | 326 | readonly attribute boolean mozAnon; |
michael@0 | 327 | |
michael@0 | 328 | /** |
michael@0 | 329 | * If true, the same origin policy will not be enforced on the request. |
michael@0 | 330 | */ |
michael@0 | 331 | readonly attribute boolean mozSystem; |
michael@0 | 332 | }; |
michael@0 | 333 | |
michael@0 | 334 | [uuid(840d0d00-e83e-4a29-b3c7-67e96e90a499)] |
michael@0 | 335 | interface nsIXHRSendable : nsISupports { |
michael@0 | 336 | void getSendInfo(out nsIInputStream body, |
michael@0 | 337 | out uint64_t contentLength, |
michael@0 | 338 | out ACString contentType, |
michael@0 | 339 | out ACString charset); |
michael@0 | 340 | }; |
michael@0 | 341 | |
michael@0 | 342 | /** |
michael@0 | 343 | * @deprecated |
michael@0 | 344 | */ |
michael@0 | 345 | [scriptable, uuid(8ae70a39-edf1-40b4-a992-472d23421c25)] |
michael@0 | 346 | interface nsIJSXMLHttpRequest : nsISupports { |
michael@0 | 347 | }; |
michael@0 | 348 | |
michael@0 | 349 | %{ C++ |
michael@0 | 350 | #define NS_XMLHTTPREQUEST_CID \ |
michael@0 | 351 | { /* d164e770-4157-11d4-9a42-000064657374 */ \ |
michael@0 | 352 | 0xd164e770, 0x4157, 0x11d4, \ |
michael@0 | 353 | {0x9a, 0x42, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} } |
michael@0 | 354 | #define NS_XMLHTTPREQUEST_CONTRACTID \ |
michael@0 | 355 | "@mozilla.org/xmlextras/xmlhttprequest;1" |
michael@0 | 356 | %} |