content/base/public/nsIXMLHttpRequest.idl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial