Fix for bug 324865 (Move XMLHttpRequest to gklayout). r/sr=jst.

This commit is contained in:
peterv%propagandism.org 2006-04-26 11:37:55 +00:00
parent bf758988d6
commit 4dd046de15
15 changed files with 0 additions and 4040 deletions

View File

@ -1 +0,0 @@
Makefile

View File

@ -1,54 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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.
#
# The Original Code is mozilla.org code.
#
# 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.
#
# 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 MPL, 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 MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xmlextras
GRE_MODULE = 1
XPIDLSRCS = \
nsIDOMSerializer.idl \
nsIXMLHttpRequest.idl \
nsIDOMParser.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -1,111 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIInputStream;
interface nsIDOMDocument;
interface nsIURI;
/**
* The nsIDOMParser interface is a non-SAX interface that can be used
* to parse a string or byte stream containing XML or HTML content
* to a DOM document. Parsing is always synchronous - a document is always
* returned from the parsing methods. This is as opposed to loading and
* parsing with the XMLHttpRequest interface, which can be used for
* asynchronous (callback-based) loading.
*/
[scriptable, uuid(4f45513e-55e5-411c-a844-e899057026c1)]
interface nsIDOMParser : nsISupports {
/**
* The string passed in is parsed into a DOM document.
*
* @param str The UTF16 string to be parsed
* @param contentType The content type of the string (see parseFromStream)
* @returns The DOM document created as a result of parsing the
* string
*/
nsIDOMDocument parseFromString(in wstring str, in string contentType);
/**
* The buffer is parsed into a DOM document.
* The charset is determined from the xml entity decl.
*
* @param buf The octet array data to be parsed
* @param bufLen Length (in bytes) of the data
* @param contentType The content type of the data (see parseFromStream)
* @returns The DOM document created as a result of parsing the
* string
*/
nsIDOMDocument parseFromBuffer([const,array,size_is(bufLen)] in octet buf, in PRUint32 bufLen, in string contentType);
/**
* The byte stream passed in is parsed into a DOM document.
*
* Not accessible from web content.
*
* @param stream The byte stream whose contents are parsed
* @param charset The character set that was used to encode the byte
* stream. NULL if not specified.
* @param contentLength The number of bytes in the input stream.
* @param contentType The content type of the string - either text/xml,
* application/xml, or application/xhtml+xml.
* Must not be NULL.
* @returns The DOM document created as a result of parsing the
* stream
*/
nsIDOMDocument parseFromStream(in nsIInputStream stream,
in string charset,
in long contentLength,
in string contentType);
/**
* Set/Get the baseURI, may be needed when called from native code.
*/
[noscript] attribute nsIURI baseURI;
};
%{ C++
#define NS_DOMPARSER_CID \
{ /* 3a8a3a50-512c-11d4-9a54-000064657374 */ \
0x3a8a3a50, 0x512c, 0x11d4, \
{0x9a, 0x54, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
#define NS_DOMPARSER_CONTRACTID \
"@mozilla.org/xmlextras/domparser;1"
%}

View File

@ -1,84 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIOutputStream;
interface nsIDOMNode;
/**
* The nsIDOMSerializer interface is really a placeholder till the W3C
* DOM Working Group defines a mechanism for serializing DOM nodes.
* An instance of this interface can be used to serialize a DOM document
* or any DOM subtree.
*/
[scriptable, uuid(9fd4ba15-e67c-4c98-b52c-7715f62c9196)]
interface nsIDOMSerializer : nsISupports
{
/**
* The subtree rooted by the specified element is serialized to
* a string.
*
* @param root The root of the subtree to be serialized. This could
* be any node, including a Document.
* @returns The serialized subtree in the form of a Unicode string
*/
AString serializeToString(in nsIDOMNode root);
/**
* The subtree rooted by the specified element is serialized to
* a byte stream using the character set specified.
* @param root The root of the subtree to be serialized. This could
* be any node, including a Document.
* @param stream The byte stream to which the subtree is serialized.
* @param charset The name of the character set to use for the encoding
* to a byte stream.
*/
void serializeToStream(in nsIDOMNode root, in nsIOutputStream stream,
in AUTF8String charset);
};
%{ C++
#define NS_XMLSERIALIZER_CID \
{ /* a6cf9124-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9124, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
#define NS_XMLSERIALIZER_CONTRACTID \
"@mozilla.org/xmlextras/xmlserializer;1"
%}

View File

@ -1,357 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIDOMDocument;
interface nsIDOMEventListener;
interface nsIChannel;
interface nsIVariant;
/**
* 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:
*
* nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(myxmlhttpreq));
*
* target->AddEventListener(NS_LITERAL_STRING("load"), mylistener,
* PR_FALSE)
*
* where mylistener is your event listener object that implements the
* interface nsIDOMEventListener.
*
* The 'onload' and 'onerror' attributes moved to nsIJSXMLHttRequest,
* but if you're coding in C++ you should avoid using those.
*/
[scriptable, uuid(7b3b3c62-9d53-4abc-bc89-c33ce78f439f)]
interface nsIXMLHttpRequest : nsISupports
{
/**
* 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
* created.
*
* In a multipart request case, this is the initial channel, not the
* different parts in the multipart request.
*
* Mozilla only. Requires elevated privileges to access.
*/
readonly attribute nsIChannel channel;
/**
* The response to the request is parsed as if it were a
* text/xml stream. This attributes represents the response as
* a DOM Document object. NULL if the request is unsuccessful or
* has not yet been sent.
*/
readonly attribute nsIDOMDocument responseXML;
/**
* The response to the request as text.
* NULL if the request is unsuccessful or
* has not yet been sent.
*/
readonly attribute AString responseText;
/**
* The status of the response to the request for HTTP requests.
*/
readonly attribute unsigned long status;
/**
* The string representing the status of the response for
* HTTP requests.
*/
readonly attribute AUTF8String statusText;
/**
* If the request has been sent already, this method will
* abort the request.
*/
void abort();
/**
* Returns all of the response headers as a string for HTTP
* requests.
*
* Note that this will return all the headers from the *current*
* part of a multipart request, not from the original channel.
*
* @returns A string containing all of the response headers.
* NULL if the response has not yet been received.
*/
string getAllResponseHeaders();
/**
* Returns the text of the header with the specified name for
* HTTP requests.
*
* @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.
*/
ACString getResponseHeader(in AUTF8String header);
/**
* Native (non-script) method to initialize a request. Note that
* the request is not sent until the <code>send</code> method
* is invoked.
*
* Will abort currently active loads.
*
* After the initial response, all event listeners will be cleared.
* Call open() before setting new event listeners.
*
* @param method The HTTP method, for example "POST" or "GET". Ignored
* if the URL is not a HTTP(S) URL.
* @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.
* This argument must be true if the multipart
* attribute has been set to true, or an exception will
* be thrown.
* @param user A username for authentication if necessary.
* @param password A password for authentication if necessary.
*/
[noscript] void openRequest(in AUTF8String method,
in AUTF8String url,
in boolean async,
in AString user,
in AString password);
/**
* 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.
*
* Will abort currently active loads.
*
* After the initial response, all event listeners will be cleared.
* Call open() before setting new event listeners.
*
* @param method The HTTP method - either "POST" or "GET". Ignored
* if the URL is not a HTTP URL.
* @param url The URL to which to send the request.
* @param async (optional) 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.
* The default value is true.
* This argument must be true if the multipart
* attribute has been set to true, or an exception will
* be thrown.
* @param user (optional) A username for authentication if necessary.
* The default value is the empty string
* @param password (optional) A password for authentication if necessary.
* The default value is the empty string
*/
void open(in AUTF8String method, in AUTF8String url);
/**
* Sends the request. If the request is asynchronous, returns
* immediately after sending the request. If it is synchronous
* returns only after the response has been received.
*
* After the initial response, all event listeners will be cleared.
* Call open() before setting new event listeners.
*
* @param body Either an instance of nsIDOMDocument, nsIInputStream
* or a string (nsISupportsString in the native calling
* 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, then it must be
* compatible with nsIUploadChannel.setUploadStream, and a
* Content-Length header will be added to the HTTP request
* with a value given by nsIInputStream.available. Any
* headers included at the top of the stream will be
* treated as part of the message body. The MIME type of
* the stream should be specified by setting the Content-
* Type header via the setRequestHeader method before
* calling send.
*/
void send(in nsIVariant body);
/**
* Sets a HTTP request header for HTTP requests. You must call open
* before setting the request headers.
*
* @param header The name of the header to set in the request.
* @param value The body of the header.
*/
void setRequestHeader(in AUTF8String header, in AUTF8String value);
/**
* 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.
*/
readonly attribute long readyState;
/**
* 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).
*/
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;
};
[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();
};
[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
* the load event occurs, the function is invoked.
* This attribute should not be used from native code!!
*
* After the initial response, all event listeners will be cleared.
* Call open() before setting new event listeners.
*
* Mozilla only.
*/
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
* the error event occurs, the function is invoked.
* This attribute should not be used from native code!!
*
* After the initial response, all event listeners will be cleared.
* Call open() before setting new event listeners.
*
* Mozilla only.
*/
attribute nsIDOMEventListener onerror;
/**
* Meant to be a script-only mechanism for setting a progress event listener.
* The attribute is expected to be JavaScript function object. When
* the error event occurs, the function is invoked.
* This attribute should not be used from native code!!
* This event listener may be called multiple times during the open request.
*
* After the initial response, all event listeners will be cleared.
* Call open() before setting new event listeners.
*
* Mozilla only.
*/
attribute nsIDOMEventListener onprogress;
/**
* 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!!
*
* After the initial response, all event listeners will be cleared.
* Call open() before setting new event listeners.
*/
attribute nsIOnReadyStateChangeHandler onreadystatechange;
};
%{ C++
#define NS_XMLHTTPREQUEST_CID \
{ /* d164e770-4157-11d4-9a42-000064657374 */ \
0xd164e770, 0x4157, 0x11d4, \
{0x9a, 0x42, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
#define NS_XMLHTTPREQUEST_CONTRACTID \
"@mozilla.org/xmlextras/xmlhttprequest;1"
%}

View File

@ -1 +0,0 @@
Makefile

View File

@ -1,93 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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.
#
# The Original Code is mozilla.org code.
#
# 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.
#
# 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 MPL, 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 MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xmlextras
LIBRARY_NAME = xmlextrasbase_s
LIBXUL_LIBRARY = 1
REQUIRES = xpcom \
string \
dom \
js \
gfx \
layout \
content \
widget \
caps \
uconv \
necko \
xpconnect \
htmlparser \
windowwatcher \
$(NULL)
CPPSRCS = \
nsDOMSerializer.cpp \
nsXMLHttpRequest.cpp \
nsDOMParser.cpp \
nsLoadListenerProxy.cpp \
$(NULL)
ifndef MOZ_ENABLE_LIBXUL
# See bug 295659
DEFINES += -D_IMPL_NS_GFX
CPPSRCS += nsRect.cpp
endif
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk
ifndef MOZ_ENABLE_LIBXUL
# Make sure that we have nsRect built in, because some compilers like to
# aggressively expand some inlines we get via nsGUIEvent.h, and then we
# lose when linking during a (transitive) XPI_PKGNAME build driven by a
# static-app master build.
#
# See bug 295659.
export::
$(NSINSTALL) $(topsrcdir)/gfx/src/nsRect.cpp .
endif

View File

@ -1,416 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsapi.h"
#include "nsDOMParser.h"
#include "nsIURI.h"
#include "nsIChannel.h"
#include "nsILoadGroup.h"
#include "nsIInputStream.h"
#include "nsNetUtil.h"
#include "nsStringStream.h"
#include "nsIXPConnect.h"
#include "nsIServiceManager.h"
#include "nsLayoutCID.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMWindow.h"
#include "nsIPrivateDOMImplementation.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMClassInfo.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsIDOMEventReceiver.h"
#include "nsLoadListenerProxy.h"
#include "nsStreamUtils.h"
#include "nsNetCID.h"
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static const char* kLoadAsData = "loadAsData";
static NS_DEFINE_CID(kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID);
/////////////////////////////////////////////
//
//
/////////////////////////////////////////////
// nsIDOMEventListener
nsresult
nsDOMParser::HandleEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
// nsIDOMLoadListener
nsresult
nsDOMParser::Load(nsIDOMEvent* aEvent)
{
mLoopingForSyncLoad = PR_FALSE;
return NS_OK;
}
nsresult
nsDOMParser::BeforeUnload(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult
nsDOMParser::Unload(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult
nsDOMParser::Abort(nsIDOMEvent* aEvent)
{
mLoopingForSyncLoad = PR_FALSE;
return NS_OK;
}
nsresult
nsDOMParser::Error(nsIDOMEvent* aEvent)
{
mLoopingForSyncLoad = PR_FALSE;
return NS_OK;
}
nsDOMParser::nsDOMParser()
: mLoopingForSyncLoad(PR_FALSE)
{
mEventQService = do_GetService(kEventQueueServiceCID);
}
nsDOMParser::~nsDOMParser()
{
NS_ABORT_IF_FALSE(!mLoopingForSyncLoad, "we rather crash than hang");
mLoopingForSyncLoad = PR_FALSE;
}
// QueryInterface implementation for nsDOMParser
NS_INTERFACE_MAP_BEGIN(nsDOMParser)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMParser)
NS_INTERFACE_MAP_ENTRY(nsIDOMParser)
NS_INTERFACE_MAP_ENTRY(nsIDOMLoadListener)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(DOMParser)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMParser)
NS_IMPL_RELEASE(nsDOMParser)
/* nsIDOMDocument parseFromString (in wstring str, in string contentType); */
NS_IMETHODIMP
nsDOMParser::ParseFromString(const PRUnichar *str,
const char *contentType,
nsIDOMDocument **_retval)
{
NS_ENSURE_ARG(str);
NS_ENSURE_ARG_POINTER(_retval);
NS_ConvertUTF16toUTF8 data(str);
// The new stream holds a reference to the buffer
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
data.get(), data.Length(),
NS_ASSIGNMENT_DEPEND);
if (NS_FAILED(rv))
return rv;
return ParseFromStream(stream, "UTF-8", data.Length(), contentType, _retval);
}
/* nsIDOMDocument parseFromBuffer([const,array,size_is(bufLen)] in octet buf, in PRUint32 bufLen, in string contentType); */
NS_IMETHODIMP
nsDOMParser::ParseFromBuffer(const PRUint8 *buf,
PRUint32 bufLen,
const char *contentType,
nsIDOMDocument **_retval)
{
NS_ENSURE_ARG_POINTER(buf);
NS_ENSURE_ARG_POINTER(_retval);
// The new stream holds a reference to the buffer
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
NS_REINTERPRET_CAST(const char *, buf),
bufLen, NS_ASSIGNMENT_DEPEND);
if (NS_FAILED(rv))
return rv;
return ParseFromStream(stream, nsnull, bufLen, contentType, _retval);
}
/* nsIDOMDocument parseFromStream (in nsIInputStream stream, in string charset, in string contentType); */
NS_IMETHODIMP
nsDOMParser::ParseFromStream(nsIInputStream *stream,
const char *charset,
PRInt32 contentLength,
const char *contentType,
nsIDOMDocument **_retval)
{
NS_ENSURE_ARG(stream);
NS_ENSURE_ARG(contentType);
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
// For now, we can only create XML documents.
if ((nsCRT::strcmp(contentType, "text/xml") != 0) &&
(nsCRT::strcmp(contentType, "application/xml") != 0) &&
(nsCRT::strcmp(contentType, "application/xhtml+xml") != 0))
return NS_ERROR_NOT_IMPLEMENTED;
// Put the nsCOMPtr out here so we hold a ref to the stream as needed
nsresult rv;
nsCOMPtr<nsIBufferedInputStream> bufferedStream;
if (!NS_InputStreamIsBuffered(stream)) {
bufferedStream = do_CreateInstance(NS_BUFFEREDINPUTSTREAM_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = bufferedStream->Init(stream, 4096);
NS_ENSURE_SUCCESS(rv, rv);
stream = bufferedStream;
}
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
secMan->GetSubjectPrincipal(getter_AddRefs(principal));
}
// Try to find a base URI for the document we're creating.
nsCOMPtr<nsIURI> baseURI;
nsCOMPtr<nsIXPCNativeCallContext> cc;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
if(NS_SUCCEEDED(rv)) {
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
}
if (NS_SUCCEEDED(rv) && cc) {
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext) {
nsCOMPtr<nsIDOMWindow> window =
do_QueryInterface(scriptContext->GetGlobalObject());
if (window) {
nsCOMPtr<nsIDOMDocument> domdoc;
window->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
if (doc) {
baseURI = doc->GetBaseURI();
}
}
}
}
if (!baseURI) {
// No URI from script environment (we are running from command line, for example).
// Create a dummy one.
// XXX Is this safe? Could we get the URI from stream or something?
if (!mBaseURI) {
rv = NS_NewURI(getter_AddRefs(baseURI),
"about:blank" );
if (NS_FAILED(rv)) return rv;
} else {
baseURI = mBaseURI;
}
}
// Get and initialize a DOMImplementation
nsCOMPtr<nsIDOMDOMImplementation> implementation(do_CreateInstance(kIDOMDOMImplementationCID, &rv));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (baseURI) {
nsCOMPtr<nsIPrivateDOMImplementation> privImpl(do_QueryInterface(implementation));
if (privImpl) {
// XXXbz Is this really right? Why are we setting the documentURI to
// baseURI? But note that's what the StartDocumentLoad() below would do
// if we let it reset. In any case, this is odd, since the caller can
// set baseURI to anything it feels like, pretty much.
privImpl->Init(baseURI, baseURI, principal);
}
}
// Create an empty document from it
nsCOMPtr<nsIDOMDocument> domDocument;
rv = implementation->CreateDocument(EmptyString(),
EmptyString(),
nsnull,
getter_AddRefs(domDocument));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// Register as a load listener on the document
nsCOMPtr<nsIDOMEventReceiver> target(do_QueryInterface(domDocument));
if (target) {
nsWeakPtr requestWeak(do_GetWeakReference(NS_STATIC_CAST(nsIDOMParser*, this)));
nsLoadListenerProxy* proxy = new nsLoadListenerProxy(requestWeak);
if (!proxy) return NS_ERROR_OUT_OF_MEMORY;
// This will addref the proxy
rv = target->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*,
proxy),
NS_GET_IID(nsIDOMLoadListener));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
}
// Create a fake channel
nsCOMPtr<nsIChannel> parserChannel;
NS_NewInputStreamChannel(getter_AddRefs(parserChannel), baseURI, nsnull,
nsDependentCString(contentType), nsnull);
NS_ENSURE_STATE(parserChannel);
// Hold a reference to it in this method
if (principal) {
parserChannel->SetOwner(principal);
}
if (charset) {
parserChannel->SetContentCharset(nsDependentCString(charset));
}
// Tell the document to start loading
nsCOMPtr<nsIStreamListener> listener;
nsCOMPtr<nsIDocument> document(do_QueryInterface(domDocument));
if (!document) return NS_ERROR_FAILURE;
nsCOMPtr<nsIEventQueue> modalEventQueue;
if(!mEventQService) {
return NS_ERROR_FAILURE;
}
mLoopingForSyncLoad = PR_TRUE;
rv = mEventQService->PushThreadEventQueue(getter_AddRefs(modalEventQueue));
if (NS_FAILED(rv)) {
return rv;
}
// Have to pass PR_FALSE for reset here, else the reset will remove
// our event listener. Should that listener addition move to later
// than this call?
rv = document->StartDocumentLoad(kLoadAsData, parserChannel,
nsnull, nsnull,
getter_AddRefs(listener),
PR_FALSE);
if (principal) {
// Make sure to give this document the right principal
document->SetPrincipal(principal);
}
if (NS_FAILED(rv) || !listener) {
if (modalEventQueue) {
mEventQService->PopThreadEventQueue(modalEventQueue);
}
return NS_ERROR_FAILURE;
}
// Now start pumping data to the listener
nsresult status;
rv = listener->OnStartRequest(parserChannel, nsnull);
if (NS_FAILED(rv))
parserChannel->Cancel(rv);
parserChannel->GetStatus(&status);
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(status)) {
rv = listener->OnDataAvailable(parserChannel, nsnull, stream, 0,
contentLength);
if (NS_FAILED(rv))
parserChannel->Cancel(rv);
parserChannel->GetStatus(&status);
}
rv = listener->OnStopRequest(parserChannel, nsnull, status);
// Failure returned from OnStopRequest does not affect the final status of
// the channel, so we do not need to call Cancel(rv) as we do above.
if (NS_FAILED(rv)) {
if (modalEventQueue) {
mEventQService->PopThreadEventQueue(modalEventQueue);
}
return NS_ERROR_FAILURE;
}
while (mLoopingForSyncLoad) {
modalEventQueue->ProcessPendingEvents();
}
mEventQService->PopThreadEventQueue(modalEventQueue);
*_retval = domDocument;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP
nsDOMParser::GetBaseURI(nsIURI **aBaseURI)
{
NS_ENSURE_ARG_POINTER(aBaseURI);
*aBaseURI = mBaseURI;
NS_IF_ADDREF(*aBaseURI);
return NS_OK;
}
NS_IMETHODIMP
nsDOMParser::SetBaseURI(nsIURI *aBaseURI)
{
mBaseURI = aBaseURI;
return NS_OK;
}

View File

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDOMParser_h__
#define nsDOMParser_h__
#include "nsIDOMParser.h"
#include "nsCOMPtr.h"
#include "nsIURI.h"
#include "nsIEventQueueService.h"
#include "nsIDOMLoadListener.h"
#include "nsWeakReference.h"
class nsDOMParser : public nsIDOMParser,
public nsIDOMLoadListener,
public nsSupportsWeakReference
{
public:
nsDOMParser();
virtual ~nsDOMParser();
NS_DECL_ISUPPORTS
// nsIDOMParser
NS_DECL_NSIDOMPARSER
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIDOMLoadListener
NS_IMETHOD Load(nsIDOMEvent* aEvent);
NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
NS_IMETHOD Error(nsIDOMEvent* aEvent);
private:
nsCOMPtr<nsIURI> mBaseURI;
nsCOMPtr<nsIEventQueueService> mEventQService;
PRBool mLoopingForSyncLoad;
};
#endif

View File

@ -1,219 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDOMSerializer.h"
#include "nsIDOMNode.h"
#include "nsIDOMClassInfo.h"
#include "nsIOutputStream.h"
#include "nsINode.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDocumentEncoder.h"
#include "nsIComponentManager.h"
#include "nsIContentSerializer.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsContentCID.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsIURI.h"
nsDOMSerializer::nsDOMSerializer()
{
}
nsDOMSerializer::~nsDOMSerializer()
{
}
// QueryInterface implementation for nsDOMSerializer
NS_INTERFACE_MAP_BEGIN(nsDOMSerializer)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMSerializer)
NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XMLSerializer)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMSerializer)
NS_IMPL_RELEASE(nsDOMSerializer)
static nsresult
SetUpEncoder(nsIDOMNode *aRoot, const nsACString& aCharset,
nsIDocumentEncoder **aEncoder)
{
*aEncoder = nsnull;
nsresult rv;
nsCOMPtr<nsIDocumentEncoder> encoder =
do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &rv);
if (NS_FAILED(rv))
return rv;
PRBool entireDocument = PR_TRUE;
nsCOMPtr<nsIDocument> document(do_QueryInterface(aRoot));
if (!document) {
entireDocument = PR_FALSE;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = aRoot->GetOwnerDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv))
return rv;
document = do_QueryInterface(domDoc);
}
// This method will fail if no document
rv = encoder->Init(document, NS_LITERAL_STRING("text/xml"),
nsIDocumentEncoder::OutputEncodeBasicEntities);
if (NS_FAILED(rv))
return rv;
nsCAutoString charset(aCharset);
if (charset.IsEmpty()) {
charset = document->GetDocumentCharacterSet();
}
rv = encoder->SetCharset(charset);
if (NS_FAILED(rv))
return rv;
// If we are working on the entire document we do not need to
// specify which part to serialize
if (!entireDocument) {
rv = encoder->SetNode(aRoot);
}
if (NS_SUCCEEDED(rv)) {
*aEncoder = encoder.get();
NS_ADDREF(*aEncoder);
}
return rv;
}
static nsresult
CheckSameOrigin(nsIDOMNode *aRoot)
{
// Make sure that the caller has permission to access the root
// Be sure to QI to nsINode to make sure we're passed a native
// object.
nsCOMPtr<nsINode> node(do_QueryInterface(aRoot));
if (NS_UNLIKELY(!node)) {
// We got a non-native object.
return NS_ERROR_INVALID_POINTER;
}
nsIPrincipal *principal = node->GetNodePrincipal();
if (principal) {
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRBool ubrEnabled = PR_FALSE;
rv = secMan->IsCapabilityEnabled("UniversalBrowserRead", &ubrEnabled);
NS_ENSURE_SUCCESS(rv, rv);
if (ubrEnabled) {
// UniversalBrowserRead is enabled (or we're not called from
// script), permit access.
return NS_OK;
}
nsCOMPtr<nsIPrincipal> subject;
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
NS_ENSURE_SUCCESS(rv, rv);
// XXXbz can we happen to not have a subject principal here?
// nsScriptSecurityManager::IsCapabilityEnabled doesn't actually use
// GetSubjectPrincipal, so not sure...
// In any case, no subject principal means access is allowed.
if (subject) {
// Check if the caller is from the same origin that the root is from.
return secMan->CheckSameOriginPrincipal(subject, principal);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMSerializer::SerializeToString(nsIDOMNode *aRoot, nsAString& _retval)
{
NS_ENSURE_ARG_POINTER(aRoot);
_retval.Truncate();
nsresult rv = CheckSameOrigin(aRoot);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDocumentEncoder> encoder;
rv = SetUpEncoder(aRoot, EmptyCString(), getter_AddRefs(encoder));
if (NS_FAILED(rv))
return rv;
return encoder->EncodeToString(_retval);
}
NS_IMETHODIMP
nsDOMSerializer::SerializeToStream(nsIDOMNode *aRoot,
nsIOutputStream *aStream,
const nsACString& aCharset)
{
NS_ENSURE_ARG_POINTER(aRoot);
NS_ENSURE_ARG_POINTER(aStream);
// The charset arg can be null, in which case we get the document's
// charset and use that when serializing.
nsresult rv = CheckSameOrigin(aRoot);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDocumentEncoder> encoder;
rv = SetUpEncoder(aRoot, aCharset, getter_AddRefs(encoder));
if (NS_FAILED(rv))
return rv;
return encoder->EncodeToStream(aStream);
}

View File

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDOMSerializer_h__
#define nsDOMSerializer_h__
#include "nsIDOMSerializer.h"
class nsDOMSerializer : public nsIDOMSerializer
{
public:
nsDOMSerializer();
virtual ~nsDOMSerializer();
NS_DECL_ISUPPORTS
// nsIDOMSerializer
NS_DECL_NSIDOMSERIALIZER
};
#endif

View File

@ -1,123 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsLoadListenerProxy.h"
#include "nsIDOMEvent.h"
nsLoadListenerProxy::nsLoadListenerProxy(nsWeakPtr aParent)
{
mParent = aParent;
}
nsLoadListenerProxy::~nsLoadListenerProxy()
{
}
NS_IMPL_ISUPPORTS2(nsLoadListenerProxy, nsIDOMEventListener,
nsIDOMLoadListener)
NS_IMETHODIMP
nsLoadListenerProxy::HandleEvent(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
if (listener) {
return listener->HandleEvent(aEvent);
}
return NS_OK;
}
NS_IMETHODIMP
nsLoadListenerProxy::Load(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
if (listener) {
return listener->Load(aEvent);
}
return NS_OK;
}
NS_IMETHODIMP
nsLoadListenerProxy::BeforeUnload(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
if (listener) {
return listener->BeforeUnload(aEvent);
}
return NS_OK;
}
NS_IMETHODIMP
nsLoadListenerProxy::Unload(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
if (listener) {
return listener->Unload(aEvent);
}
return NS_OK;
}
NS_IMETHODIMP
nsLoadListenerProxy::Abort(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
if (listener) {
return listener->Abort(aEvent);
}
return NS_OK;
}
NS_IMETHODIMP
nsLoadListenerProxy::Error(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
if (listener) {
return listener->Error(aEvent);
}
return NS_OK;
}

View File

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLoadListenerProxy_h
#define nsLoadListenerProxy_h
#include "nsIDOMLoadListener.h"
#include "nsWeakReference.h"
/////////////////////////////////////////////
//
// This class exists to prevent a circular reference between
// the loaded document and the actual loader instance request. The
// request owns the document. While the document is loading,
// the request is a load listener, held onto by the document.
// The proxy class breaks the circularity by filling in as the
// load listener and holding a weak reference to the request
// object.
//
/////////////////////////////////////////////
class nsLoadListenerProxy : public nsIDOMLoadListener {
public:
nsLoadListenerProxy(nsWeakPtr aParent);
virtual ~nsLoadListenerProxy();
NS_DECL_ISUPPORTS
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIDOMLoadListener
NS_IMETHOD Load(nsIDOMEvent* aEvent);
NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
NS_IMETHOD Error(nsIDOMEvent* aEvent);
protected:
nsWeakPtr mParent;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,213 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* 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.
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXMLHttpRequest_h__
#define nsXMLHttpRequest_h__
#include "nsIXMLHttpRequest.h"
#include "nsISupportsUtils.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMDocument.h"
#include "nsIURI.h"
#include "nsIHttpChannel.h"
#include "nsIDocument.h"
#include "nsIStreamListener.h"
#include "nsIEventQueueService.h"
#include "nsWeakReference.h"
#include "nsISupportsArray.h"
#include "jsapi.h"
#include "nsIScriptContext.h"
#include "nsIChannelEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsIHttpHeaderVisitor.h"
#include "nsIProgressEventSink.h"
#include "nsIDOMLSProgressEvent.h"
class nsILoadGroup;
class nsXMLHttpRequest : public nsIXMLHttpRequest,
public nsIJSXMLHttpRequest,
public nsIDOMLoadListener,
public nsIDOMEventTarget,
public nsIStreamListener,
public nsIChannelEventSink,
public nsIInterfaceRequestor,
public nsIProgressEventSink,
public nsSupportsWeakReference
{
public:
nsXMLHttpRequest();
virtual ~nsXMLHttpRequest();
NS_DECL_ISUPPORTS
// nsIXMLHttpRequest
NS_DECL_NSIXMLHTTPREQUEST
// nsIJSXMLHttpRequest
NS_DECL_NSIJSXMLHTTPREQUEST
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIDOMLoadListener
NS_IMETHOD Load(nsIDOMEvent* aEvent);
NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
NS_IMETHOD Error(nsIDOMEvent* aEvent);
// nsIStreamListener
NS_DECL_NSISTREAMLISTENER
// nsIRequestObserver
NS_DECL_NSIREQUESTOBSERVER
// nsIChannelEventSink
NS_DECL_NSICHANNELEVENTSINK
// nsIProgressEventSink
NS_DECL_NSIPROGRESSEVENTSINK
// nsIInterfaceRequestor
NS_DECL_NSIINTERFACEREQUESTOR
protected:
nsresult GetStreamForWString(const PRUnichar* aStr,
PRInt32 aLength,
nsIInputStream** aStream);
nsresult DetectCharset(nsACString& aCharset);
nsresult ConvertBodyToText(nsAString& aOutBuffer);
static NS_METHOD StreamReaderFunc(nsIInputStream* in,
void* closure,
const char* fromRawSegment,
PRUint32 toOffset,
PRUint32 count,
PRUint32 *writeCount);
// Change the state of the object with this. The broadcast argument
// determines if the onreadystatechange listener should be called.
// If aClearEventListeners is true, ChangeState will take refs to
// any event listeners it needs and call ClearEventListeners before
// making any HandleEvent() calls that could change the listener
// values.
nsresult ChangeState(PRUint32 aState, PRBool aBroadcast = PR_TRUE,
PRBool aClearEventListeners = PR_FALSE);
nsresult RequestCompleted();
nsresult GetLoadGroup(nsILoadGroup **aLoadGroup);
nsIURI *GetBaseURI();
nsresult CreateEvent(nsEvent* event, nsIDOMEvent** domevent);
void NotifyEventListeners(nsIDOMEventListener* aHandler,
nsISupportsArray* aListeners, nsIDOMEvent* aEvent);
void ClearEventListeners();
already_AddRefed<nsIHttpChannel> GetCurrentHttpChannel();
nsCOMPtr<nsISupports> mContext;
nsCOMPtr<nsIChannel> mChannel;
nsCOMPtr<nsIRequest> mReadRequest;
nsCOMPtr<nsIDOMDocument> mDocument;
nsCOMPtr<nsISupportsArray> mLoadEventListeners;
nsCOMPtr<nsISupportsArray> mErrorEventListeners;
nsCOMPtr<nsIScriptContext> mScriptContext;
nsCOMPtr<nsIDOMEventListener> mOnLoadListener;
nsCOMPtr<nsIDOMEventListener> mOnErrorListener;
nsCOMPtr<nsIDOMEventListener> mOnProgressListener;
nsCOMPtr<nsIOnReadyStateChangeHandler> mOnReadystatechangeListener;
nsCOMPtr<nsIStreamListener> mXMLParserStreamListener;
nsCOMPtr<nsIEventQueueService> mEventQService;
// used to implement getAllResponseHeaders()
class nsHeaderVisitor : public nsIHttpHeaderVisitor {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIHTTPHEADERVISITOR
nsHeaderVisitor() { }
virtual ~nsHeaderVisitor() {}
const nsACString &Headers() { return mHeaders; }
private:
nsCString mHeaders;
};
nsCString mResponseBody;
nsCString mOverrideMimeType;
/**
* The notification callbacks the channel had when Send() was
* called. We want to forward things here as needed.
*/
nsCOMPtr<nsIInterfaceRequestor> mNotificationCallbacks;
/**
* Sink interfaces that we implement that mNotificationCallbacks may
* want to also be notified for. These are inited lazily if we're
* asked for the relevant interface.
*/
nsCOMPtr<nsIChannelEventSink> mChannelEventSink;
nsCOMPtr<nsIProgressEventSink> mProgressEventSink;
PRUint32 mState;
};
// helper class to expose a progress DOM Event
class nsXMLHttpProgressEvent : public nsIDOMLSProgressEvent
{
public:
nsXMLHttpProgressEvent(nsIDOMEvent * aInner, PRUint64 aCurrentProgress, PRUint64 aMaxProgress);
virtual ~nsXMLHttpProgressEvent();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMLSPROGRESSEVENT
NS_DECL_NSIDOMEVENT
protected:
nsCOMPtr<nsIDOMEvent> mInner;
PRUint64 mCurProgress;
PRUint64 mMaxProgress;
};
#endif