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