2006-04-20 07:37:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
2006-04-20 07:36:50 +04:00
|
|
|
*
|
2006-04-20 07:37:39 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
2006-04-20 07:36:50 +04:00
|
|
|
*
|
2006-04-20 07:37:39 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2006-04-20 07:36:50 +04:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2006-04-20 07:37:39 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2006-04-20 07:36:50 +04:00
|
|
|
*
|
2006-04-20 07:37:39 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-04-20 07:36:50 +04:00
|
|
|
|
|
|
|
#include "nsISupports.idl"
|
|
|
|
|
|
|
|
interface nsIDOMDocument;
|
|
|
|
interface nsIDOMEventListener;
|
2006-04-20 07:37:29 +04:00
|
|
|
interface nsIChannel;
|
2006-04-20 07:37:45 +04:00
|
|
|
interface nsIVariant;
|
2006-04-20 07:36:50 +04:00
|
|
|
|
2006-04-20 07:37:31 +04:00
|
|
|
/**
|
|
|
|
* Mozilla's XMLHttpRequest is modelled after Microsoft's IXMLHttpRequest
|
|
|
|
* object. The goal has been to make Mozilla's version match Microsoft's
|
|
|
|
* version as closely as possible, but there are bound to be some differences.
|
|
|
|
*
|
|
|
|
* In general, Microsoft's documentation for IXMLHttpRequest can be used.
|
|
|
|
* Mozilla's interface definitions provide some additional documentation. The
|
|
|
|
* web page to look at is http://www.mozilla.org/xmlextras/
|
|
|
|
*
|
|
|
|
* Mozilla's XMLHttpRequest object can be created in JavaScript like this:
|
|
|
|
* new XMLHttpRequest()
|
|
|
|
* compare to Internet Explorer:
|
|
|
|
* new ActiveXObject("Msxml2.XMLHTTP")
|
|
|
|
*
|
|
|
|
* From JavaScript, the methods and properties visible in the XMLHttpRequest
|
|
|
|
* object are a combination of nsIXMLHttpRequest and nsIJSXMLHttpRequest;
|
|
|
|
* there is no need to differentiate between those interfaces.
|
|
|
|
*
|
|
|
|
* From native code, the way to set up onload and onerror handlers is a bit
|
|
|
|
* different. Here is a comment from Johnny Stenback <jst@netscape.com>:
|
|
|
|
*
|
|
|
|
* The mozilla implementation of nsIXMLHttpRequest implements the interface
|
|
|
|
* nsIDOMEventTarget and that's how you're supported to add event listeners.
|
|
|
|
* Try something like this:
|
|
|
|
*
|
2006-04-20 07:38:31 +04:00
|
|
|
* nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(myxmlhttpreq));
|
2006-04-20 07:37:31 +04:00
|
|
|
*
|
|
|
|
* target->AddEventListener(NS_LITERAL_STRING("load"), mylistener,
|
|
|
|
* PR_FALSE)
|
|
|
|
*
|
2006-04-20 07:38:51 +04:00
|
|
|
* where mylistener is your event listener object that implements the
|
2006-04-20 07:37:31 +04:00
|
|
|
* interface nsIDOMEventListener.
|
|
|
|
*
|
|
|
|
* The 'onload' and 'onerror' attributes moved to nsIJSXMLHttRequest,
|
|
|
|
* but if you're coding in C++ you should avoid using those.
|
|
|
|
*/
|
2006-04-20 07:38:53 +04:00
|
|
|
[scriptable, uuid(7b3b3c62-9d53-4abc-bc89-c33ce78f439f)]
|
2006-04-20 07:38:51 +04:00
|
|
|
interface nsIXMLHttpRequest : nsISupports
|
|
|
|
{
|
2006-04-20 07:37:01 +04:00
|
|
|
/**
|
2006-04-20 07:37:29 +04:00
|
|
|
* The request uses a channel in order to perform the
|
|
|
|
* request. This attribute represents the channel used
|
|
|
|
* for the request. NULL if the channel has not yet been
|
2006-04-20 07:37:01 +04:00
|
|
|
* created.
|
2006-04-20 07:37:31 +04:00
|
|
|
*
|
2006-04-20 07:38:52 +04:00
|
|
|
* In a multipart request case, this is the initial channel, not the
|
|
|
|
* different parts in the multipart request.
|
|
|
|
*
|
2006-04-20 07:38:26 +04:00
|
|
|
* Mozilla only. Requires elevated privileges to access.
|
2006-04-20 07:37:01 +04:00
|
|
|
*/
|
2006-04-20 07:37:29 +04:00
|
|
|
readonly attribute nsIChannel channel;
|
2006-04-20 07:37:01 +04:00
|
|
|
|
2006-04-20 07:36:55 +04:00
|
|
|
/**
|
2006-04-20 07:37:29 +04:00
|
|
|
* The response to the request is parsed as if it were a
|
2006-04-20 07:38:51 +04:00
|
|
|
* text/xml stream. This attributes represents the response as
|
2006-04-20 07:36:55 +04:00
|
|
|
* a DOM Document object. NULL if the request is unsuccessful or
|
|
|
|
* has not yet been sent.
|
|
|
|
*/
|
2006-04-20 07:36:50 +04:00
|
|
|
readonly attribute nsIDOMDocument responseXML;
|
2006-04-20 07:36:55 +04:00
|
|
|
|
2006-04-20 07:37:08 +04:00
|
|
|
/**
|
2006-04-20 07:38:51 +04:00
|
|
|
* The response to the request as text.
|
2006-04-20 07:37:08 +04:00
|
|
|
* NULL if the request is unsuccessful or
|
|
|
|
* has not yet been sent.
|
|
|
|
*/
|
2006-04-20 07:38:51 +04:00
|
|
|
readonly attribute AString responseText;
|
2006-04-20 07:37:08 +04:00
|
|
|
|
|
|
|
|
2006-04-20 07:36:55 +04:00
|
|
|
/**
|
2006-04-20 07:38:51 +04:00
|
|
|
* The status of the response to the request for HTTP requests.
|
2006-04-20 07:36:55 +04:00
|
|
|
*/
|
2006-04-20 07:36:50 +04:00
|
|
|
readonly attribute unsigned long status;
|
2006-04-20 07:36:55 +04:00
|
|
|
|
|
|
|
/**
|
2006-04-20 07:37:29 +04:00
|
|
|
* The string representing the status of the response for
|
|
|
|
* HTTP requests.
|
2006-04-20 07:36:55 +04:00
|
|
|
*/
|
2006-04-20 07:38:51 +04:00
|
|
|
readonly attribute AUTF8String statusText;
|
2006-04-20 07:36:50 +04:00
|
|
|
|
2006-04-20 07:36:55 +04:00
|
|
|
/**
|
2006-04-20 07:37:29 +04:00
|
|
|
* If the request has been sent already, this method will
|
2006-04-20 07:36:55 +04:00
|
|
|
* abort the request.
|
|
|
|
*/
|
2006-04-20 07:36:50 +04:00
|
|
|
void abort();
|
2006-04-20 07:36:55 +04:00
|
|
|
|
|
|
|
/**
|
2006-04-20 07:37:29 +04:00
|
|
|
* Returns all of the response headers as a string for HTTP
|
|
|
|
* requests.
|
2006-04-20 07:38:51 +04:00
|
|
|
*
|
2006-04-20 07:38:52 +04:00
|
|
|
* Note that this will return all the headers from the *current*
|
|
|
|
* part of a multipart request, not from the original channel.
|
|
|
|
*
|
2006-04-20 07:38:51 +04:00
|
|
|
* @returns A string containing all of the response headers.
|
2006-04-20 07:36:55 +04:00
|
|
|
* NULL if the response has not yet been received.
|
|
|
|
*/
|
2006-04-20 07:38:51 +04:00
|
|
|
string getAllResponseHeaders();
|
2006-04-20 07:36:55 +04:00
|
|
|
|
|
|
|
/**
|
2006-04-20 07:37:29 +04:00
|
|
|
* Returns the text of the header with the specified name for
|
|
|
|
* HTTP requests.
|
2006-04-20 07:36:55 +04:00
|
|
|
*
|
|
|
|
* @param header The name of the header to retrieve
|
|
|
|
* @returns A string containing the text of the header specified.
|
|
|
|
* NULL if the response has not yet been received or the
|
|
|
|
* header does not exist in the response.
|
|
|
|
*/
|
2006-04-20 07:38:51 +04:00
|
|
|
ACString getResponseHeader(in AUTF8String header);
|
2006-04-20 07:36:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Native (non-script) method to initialize a request. Note that
|
2006-04-20 07:38:51 +04:00
|
|
|
* the request is not sent until the <code>send</code> method
|
2006-04-20 07:36:55 +04:00
|
|
|
* is invoked.
|
|
|
|
*
|
2006-04-20 07:38:26 +04:00
|
|
|
* Will abort currently active loads.
|
|
|
|
*
|
|
|
|
* After the initial response, all event listeners will be cleared.
|
|
|
|
* Call open() before setting new event listeners.
|
|
|
|
*
|
2006-04-20 07:37:49 +04:00
|
|
|
* @param method The HTTP method, for example "POST" or "GET". Ignored
|
|
|
|
* if the URL is not a HTTP(S) URL.
|
2006-04-20 07:36:55 +04:00
|
|
|
* @param url The URL to which to send the request.
|
|
|
|
* @param async Whether the request is synchronous or asynchronous
|
|
|
|
* i.e. whether send returns only after the response
|
|
|
|
* is received or if it returns immediately after
|
|
|
|
* sending the request. In the latter case, notification
|
|
|
|
* of completion is sent through the event listeners.
|
2006-04-20 07:38:52 +04:00
|
|
|
* This argument must be true if the multipart
|
|
|
|
* attribute has been set to true, or an exception will
|
|
|
|
* be thrown.
|
2006-04-20 07:36:55 +04:00
|
|
|
* @param user A username for authentication if necessary.
|
|
|
|
* @param password A password for authentication if necessary.
|
|
|
|
*/
|
2006-04-20 07:38:51 +04:00
|
|
|
[noscript] void openRequest(in AUTF8String method,
|
|
|
|
in AUTF8String url,
|
2006-04-20 07:36:55 +04:00
|
|
|
in boolean async,
|
2006-04-20 07:38:51 +04:00
|
|
|
in AString user,
|
|
|
|
in AString password);
|
2006-04-20 07:36:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Meant to be a script-only method for initializing a request.
|
|
|
|
* The parameters are similar to the ones detailed in the
|
|
|
|
* description of <code>openRequest</code>, but the last
|
|
|
|
* 3 are optional.
|
|
|
|
*
|
2006-04-20 07:38:26 +04:00
|
|
|
* Will abort currently active loads.
|
|
|
|
*
|
|
|
|
* After the initial response, all event listeners will be cleared.
|
|
|
|
* Call open() before setting new event listeners.
|
|
|
|
*
|
2006-04-20 07:37:29 +04:00
|
|
|
* @param method The HTTP method - either "POST" or "GET". Ignored
|
|
|
|
* if the URL is not a HTTP URL.
|
2006-04-20 07:36:55 +04:00
|
|
|
* @param url The URL to which to send the request.
|
2006-04-20 07:38:51 +04:00
|
|
|
* @param async (optional) Whether the request is synchronous or
|
|
|
|
* asynchronous i.e. whether send returns only after
|
2006-04-20 07:36:55 +04:00
|
|
|
* the response is received or if it returns immediately after
|
|
|
|
* sending the request. In the latter case, notification
|
|
|
|
* of completion is sent through the event listeners.
|
|
|
|
* The default value is true.
|
2006-04-20 07:38:52 +04:00
|
|
|
* This argument must be true if the multipart
|
|
|
|
* attribute has been set to true, or an exception will
|
|
|
|
* be thrown.
|
2006-04-20 07:38:51 +04:00
|
|
|
* @param user (optional) A username for authentication if necessary.
|
2006-04-20 07:36:55 +04:00
|
|
|
* The default value is the empty string
|
|
|
|
* @param password (optional) A password for authentication if necessary.
|
|
|
|
* The default value is the empty string
|
|
|
|
*/
|
2006-04-20 07:38:51 +04:00
|
|
|
void open(in AUTF8String method, in AUTF8String url);
|
2006-04-20 07:36:55 +04:00
|
|
|
|
|
|
|
/**
|
2006-04-20 07:37:29 +04:00
|
|
|
* Sends the request. If the request is asynchronous, returns
|
2006-04-20 07:36:55 +04:00
|
|
|
* immediately after sending the request. If it is synchronous
|
|
|
|
* returns only after the response has been received.
|
|
|
|
*
|
2006-04-20 07:38:26 +04:00
|
|
|
* After the initial response, all event listeners will be cleared.
|
|
|
|
* Call open() before setting new event listeners.
|
|
|
|
*
|
2006-04-20 07:36:55 +04:00
|
|
|
* @param body Either an instance of nsIDOMDocument, nsIInputStream
|
2006-04-20 07:38:05 +04:00
|
|
|
* or a string (nsISupportsString in the native calling
|
2006-04-20 07:36:55 +04:00
|
|
|
* case). This is used to populate the body of the
|
|
|
|
* HTTP request if the HTTP request method is "POST".
|
|
|
|
* If the parameter is a nsIDOMDocument, it is serialized.
|
|
|
|
* If the parameter is a nsIInputStream, it is expected
|
|
|
|
* to contain the ContentType: and ContentLength: headers
|
|
|
|
* and trailing carriage-return/line-feed pairs.
|
|
|
|
*/
|
2006-04-20 07:37:45 +04:00
|
|
|
void send(in nsIVariant body);
|
2006-04-20 07:36:55 +04:00
|
|
|
|
|
|
|
/**
|
2006-04-20 07:37:31 +04:00
|
|
|
* Sets a HTTP request header for HTTP requests. You must call open
|
|
|
|
* before setting the request headers.
|
2006-04-20 07:36:55 +04:00
|
|
|
*
|
|
|
|
* @param header The name of the header to set in the request.
|
|
|
|
* @param value The body of the header.
|
|
|
|
*/
|
2006-04-20 07:38:51 +04:00
|
|
|
void setRequestHeader(in AUTF8String header, in AUTF8String value);
|
2006-04-20 07:37:31 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The state of the request.
|
|
|
|
*
|
|
|
|
* Possible values:
|
|
|
|
* 0 UNINITIALIZED open() has not been called yet.
|
|
|
|
* 1 LOADING send() has not been called yet.
|
|
|
|
* 2 LOADED send() has been called, headers and status are available.
|
|
|
|
* 3 INTERACTIVE Downloading, responseText holds the partial data.
|
|
|
|
* 4 COMPLETED Finished with all operations.
|
|
|
|
*/
|
2006-04-20 07:38:52 +04:00
|
|
|
readonly attribute long readyState;
|
2006-04-20 07:37:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the mime type returned by the server (if any). This may
|
|
|
|
* be used, for example, to force a stream to be treated and parsed
|
|
|
|
* as text/xml, even if the server does not report it as such. This
|
|
|
|
* must be done before the <code>send</code> method is invoked.
|
|
|
|
*
|
|
|
|
* @param mimetype The type used to override that returned by the server
|
|
|
|
* (if any).
|
|
|
|
*/
|
2006-04-20 07:38:52 +04:00
|
|
|
void overrideMimeType(in AUTF8String mimetype);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to true if the response is expected to be a stream of
|
|
|
|
* possibly multiple (XML) documents. If set to true, the content
|
|
|
|
* type of the initial response must be multipart/x-mixed-replace or
|
|
|
|
* an error will be triggerd. All requests must be asynchronous.
|
|
|
|
*
|
|
|
|
* This enables server push. For each XML document that's written to
|
|
|
|
* this request, a new XML DOM document is created and the onload
|
|
|
|
* handler is called inbetween documents. Note that when this is
|
|
|
|
* set, the onload handler and other event handlers are not reset
|
|
|
|
* after the first XML document is loaded, and the onload handler
|
|
|
|
* will be called as each part of the response is received.
|
|
|
|
*/
|
|
|
|
attribute boolean multipart;
|
2006-04-20 07:36:50 +04:00
|
|
|
};
|
|
|
|
|
2006-04-20 07:37:23 +04:00
|
|
|
|
2006-04-20 07:37:31 +04:00
|
|
|
[scriptable, function, uuid(6459B7CE-6B57-4934-A0AF-0133BA6F9085)]
|
|
|
|
interface nsIOnReadystatechangeHandler : nsISupports {
|
|
|
|
/**
|
|
|
|
* Helper to implement the onreadystatechange callback member.
|
|
|
|
* You should not need to use this.
|
|
|
|
*/
|
|
|
|
void handleEvent();
|
|
|
|
};
|
|
|
|
|
2006-04-20 07:37:23 +04:00
|
|
|
[scriptable, uuid(9deabc90-28d5-41d3-a660-474f2254f4ba)]
|
|
|
|
interface nsIJSXMLHttpRequest : nsISupports {
|
|
|
|
/**
|
|
|
|
* Meant to be a script-only mechanism for setting a load event listener.
|
|
|
|
* The attribute is expected to be JavaScript function object. When
|
2006-04-20 07:38:51 +04:00
|
|
|
* the load event occurs, the function is invoked.
|
2006-04-20 07:37:23 +04:00
|
|
|
* This attribute should not be used from native code!!
|
2006-04-20 07:37:31 +04:00
|
|
|
*
|
2006-04-20 07:38:26 +04:00
|
|
|
* After the initial response, all event listeners will be cleared.
|
|
|
|
* Call open() before setting new event listeners.
|
|
|
|
*
|
2006-04-20 07:37:31 +04:00
|
|
|
* Mozilla only.
|
2006-04-20 07:37:23 +04:00
|
|
|
*/
|
|
|
|
attribute nsIDOMEventListener onload;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Meant to be a script-only mechanism for setting an error event listener.
|
|
|
|
* The attribute is expected to be JavaScript function object. When
|
2006-04-20 07:38:51 +04:00
|
|
|
* the error event occurs, the function is invoked.
|
2006-04-20 07:37:23 +04:00
|
|
|
* This attribute should not be used from native code!!
|
2006-04-20 07:37:31 +04:00
|
|
|
*
|
2006-04-20 07:38:26 +04:00
|
|
|
* After the initial response, all event listeners will be cleared.
|
|
|
|
* Call open() before setting new event listeners.
|
|
|
|
*
|
2006-04-20 07:37:31 +04:00
|
|
|
* Mozilla only.
|
2006-04-20 07:37:23 +04:00
|
|
|
*/
|
|
|
|
attribute nsIDOMEventListener onerror;
|
2006-04-20 07:37:31 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Meant to be a script-only mechanism for setting a callback function.
|
|
|
|
* The attribute is expected to be JavaScript function object. When the
|
|
|
|
* readyState changes, the callback function will be called.
|
|
|
|
* This attribute should not be used from native code!!
|
2006-04-20 07:38:26 +04:00
|
|
|
*
|
|
|
|
* After the initial response, all event listeners will be cleared.
|
|
|
|
* Call open() before setting new event listeners.
|
2006-04-20 07:37:31 +04:00
|
|
|
*/
|
|
|
|
attribute nsIOnReadystatechangeHandler onreadystatechange;
|
2006-04-20 07:37:23 +04:00
|
|
|
};
|
|
|
|
|
2006-04-20 07:36:50 +04:00
|
|
|
%{ C++
|
|
|
|
#define NS_XMLHTTPREQUEST_CID \
|
|
|
|
{ /* d164e770-4157-11d4-9a42-000064657374 */ \
|
|
|
|
0xd164e770, 0x4157, 0x11d4, \
|
|
|
|
{0x9a, 0x42, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
|
2006-04-20 07:37:00 +04:00
|
|
|
#define NS_XMLHTTPREQUEST_CONTRACTID \
|
|
|
|
"@mozilla.org/xmlextras/xmlhttprequest;1"
|
2006-04-20 07:36:50 +04:00
|
|
|
%}
|