зеркало из https://github.com/mozilla/gecko-dev.git
Not part of Netscape 6.0 package. Checking in patches from toml@us.ibm.com. These fix bug 55508 (DOMParser does not work without script environment) and bug 55599 (add GetChannel method to nsIXMLHTTPRequest), as well as add a test program. r=heikki, a=vidur.
This commit is contained in:
Родитель
4d4ab5b138
Коммит
78807d92fd
|
@ -902,6 +902,7 @@ for extension in $MOZ_EXTENSIONS; do
|
|||
extensions/xmlextras/build/Makefile
|
||||
extensions/xmlextras/build/src/Makefile
|
||||
extensions/xmlextras/soap/public/Makefile
|
||||
extensions/xmlextras/tests/Makefile
|
||||
" ;;
|
||||
xmlterm ) MAKEFILES_extensions="$MAKEFILES_extensions
|
||||
extensions/xmlterm/Makefile
|
||||
|
|
|
@ -28,4 +28,8 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
DIRS = base soap build
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
interface nsIInputStream;
|
||||
interface nsIDOMDocument;
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* The nsIDOMParser interface is a non-SAX interface that can be used
|
||||
|
@ -63,6 +64,14 @@ interface nsIDOMParser : nsISupports {
|
|||
in string charset,
|
||||
in long contentLength,
|
||||
in string contentType);
|
||||
|
||||
/**
|
||||
* Set/Get the baseURI. You will probably not need this if you
|
||||
* have a script environment. This is mostly intended for cases
|
||||
* without a script environment, for example calling from native
|
||||
* code.
|
||||
*/
|
||||
attribute nsIURI baseURI;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
interface nsIDOMDocument;
|
||||
interface nsIDOMEventListener;
|
||||
interface nsIHTTPChannel;
|
||||
|
||||
[scriptable, uuid(b7215e70-4157-11d4-9a42-000064657374)]
|
||||
interface nsIXMLHttpRequest : nsISupports {
|
||||
|
@ -65,6 +66,14 @@ interface nsIXMLHttpRequest : nsISupports {
|
|||
*/
|
||||
attribute nsISupports onerror;
|
||||
|
||||
/**
|
||||
* The HTTP request uses an HTTP channel in order to perform the
|
||||
* request. This attribute represents the HTTP channel used
|
||||
* for the request. NULL if the HTTP channel has not yet been
|
||||
* created.
|
||||
*/
|
||||
readonly attribute nsIHTTPChannel channel;
|
||||
|
||||
/**
|
||||
* The response to the HTTP request is parsed as if it were a
|
||||
* text/xml stream. This attributes represents the response as
|
||||
|
|
|
@ -416,6 +416,7 @@ nsDOMParser::ParseFromString(const PRUnichar *str,
|
|||
return ParseFromStream(stream, "UTF-8", contentLength, contentType, _retval);
|
||||
}
|
||||
|
||||
|
||||
/* nsIDOMDocument parseFromStream (in nsIInputStream stream, in string charset, in string contentType); */
|
||||
NS_IMETHODIMP
|
||||
nsDOMParser::ParseFromStream(nsIInputStream *stream,
|
||||
|
@ -463,6 +464,19 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -525,6 +539,22 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
|
|||
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;
|
||||
}
|
||||
|
||||
static const char* kAllAccess = "AllAccess";
|
||||
|
||||
/* string canCreateWrapper (in nsIIDPtr iid); */
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
class nsDOMParser : public nsIDOMParser,
|
||||
public nsISecurityCheckedComponent
|
||||
|
@ -38,16 +39,12 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMParser
|
||||
NS_IMETHOD ParseFromString(const PRUnichar *str,
|
||||
const char *contentType,
|
||||
nsIDOMDocument **_retval);
|
||||
NS_IMETHOD ParseFromStream(nsIInputStream *stream,
|
||||
const char *charset,
|
||||
PRInt32 contentLength,
|
||||
const char *contentType,
|
||||
nsIDOMDocument **_retval);
|
||||
NS_DECL_NSIDOMPARSER
|
||||
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIURI> mBaseURI;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -552,6 +552,16 @@ nsXMLHttpRequest::SetOnerror(nsISupports * aOnerror)
|
|||
return AddEventListener(kErrorStr, listener);
|
||||
}
|
||||
|
||||
/* readonly attribute nsIHTTPChannel channel; */
|
||||
NS_IMETHODIMP nsXMLHttpRequest::GetChannel(nsIHTTPChannel **aChannel)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aChannel);
|
||||
*aChannel = mChannel;
|
||||
NS_IF_ADDREF(*aChannel);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMDocument responseXML; */
|
||||
NS_IMETHODIMP nsXMLHttpRequest::GetResponseXML(nsIDOMDocument **aResponseXML)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
|
||||
DEPTH=..\..
|
||||
|
||||
DIRS=base soap build
|
||||
DIRS= \
|
||||
base \
|
||||
soap \
|
||||
build \
|
||||
!if !defined(DISABLE_TESTS)
|
||||
tests \
|
||||
!endif
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# 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/
|
||||
#
|
||||
# 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 Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(topsrcdir)/config/autoconf.mk
|
||||
|
||||
CPPSRCS = \
|
||||
TestXMLExtras.cpp \
|
||||
$(NULL)
|
||||
|
||||
SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX))
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBS = \
|
||||
$(MOZ_JS_LIBS) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(LOST_SYM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -DUSE_NSREG
|
|
@ -0,0 +1,208 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 imitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is International
|
||||
* Business Machines Corporation. Portions created by IBM
|
||||
* Corporation are Copyright (C) 2000 International Business
|
||||
* Machines Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): IBM Corporation.
|
||||
* Heikki Toivonen <heikki@netscape.com>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <nsCOMPtr.h>
|
||||
#include <nsString.h>
|
||||
#include <nsIURI.h>
|
||||
#include <nsIChannel.h>
|
||||
#include <nsIInputStream.h>
|
||||
#include <nsIDOMDocument.h>
|
||||
#include <nsIDOMParser.h>
|
||||
#include <nsIXMLHttpRequest.h>
|
||||
#include <nsNetUtil.h>
|
||||
#include <nsIDOMElement.h>
|
||||
#include "nsIDocument.h"
|
||||
|
||||
void usage( ) {
|
||||
|
||||
printf( "\n" );
|
||||
printf( "Usage:\n" );
|
||||
printf( " TestXMLExtras {parsestr | parse | syncread} xmlfile\n\n" );
|
||||
printf( " parsestr = Invokes DOMParser against a string supplied as second argument\n" );
|
||||
printf( " parse = Invokes DOMParser against a local file\n" );
|
||||
printf( " xmlfile = A local XML URI (ie. file:///d:/file.xml)\n\n" );
|
||||
printf( " syncread = Invokes XMLHttpRequest for a synchronous read\n" );
|
||||
printf( " xmlfile = An XML URI (ie. http://www.w3.org/TR/P3P/base\n\n" );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> pURI;
|
||||
nsCOMPtr<nsIChannel> pChannel;
|
||||
nsCOMPtr<nsIInputStream> pInputStream;
|
||||
PRUint32 uiContentLength;
|
||||
nsCOMPtr<nsIDOMParser> pDOMParser;
|
||||
nsCOMPtr<nsIDOMDocument> pDOMDocument;
|
||||
nsCOMPtr<nsIXMLHttpRequest> pXMLHttpRequest;
|
||||
|
||||
if (argc > 2) {
|
||||
if (nsCRT::strcasecmp( argv[1], "parsestr" ) == 0) {
|
||||
pDOMParser = do_CreateInstance( NS_DOMPARSER_CONTRACTID,
|
||||
&rv );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
nsString str; str.AssignWithConversion(argv[2]);
|
||||
rv = pDOMParser->ParseFromString(str.GetUnicode(),"text/xml",
|
||||
getter_AddRefs( pDOMDocument ) );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
printf( "DOM parse string of\n\n%s\n\nsuccessful\n", argv[2] );
|
||||
}
|
||||
else {
|
||||
printf( "DOM parse of \n%s\n NOT successful\n", argv[2] );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "do_CreateInstance of DOMParser failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
} else if (nsCRT::strcasecmp( argv[1], "parse" ) == 0) {
|
||||
// DOM Parser
|
||||
rv = NS_NewURI( getter_AddRefs( pURI ),
|
||||
argv[2] );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = NS_OpenURI( getter_AddRefs( pChannel ),
|
||||
pURI,
|
||||
nsnull,
|
||||
nsnull );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = pChannel->OpenInputStream( getter_AddRefs( pInputStream ) );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = pInputStream->Available(&uiContentLength );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
pDOMParser = do_CreateInstance( NS_DOMPARSER_CONTRACTID,
|
||||
&rv );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
pDOMParser->SetBaseURI(pURI);
|
||||
|
||||
rv = pDOMParser->ParseFromStream( pInputStream,
|
||||
"UTF-8",
|
||||
uiContentLength,
|
||||
"text/xml",
|
||||
getter_AddRefs( pDOMDocument ) );
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
printf( "DOM parse of %s successful\n", argv[2] );
|
||||
}
|
||||
else {
|
||||
printf( "DOM parse of %s NOT successful\n", argv[2] );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "do_CreateInstance of DOMParser failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "pInputSteam->Available failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "pChannel->OpenInputStream failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "NS_OpenURI failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "NS_NewURI failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else if (nsCRT::strcasecmp( argv[1], "syncread" ) == 0) {
|
||||
// Synchronous Read
|
||||
pXMLHttpRequest = do_CreateInstance( NS_XMLHTTPREQUEST_CONTRACTID,
|
||||
&rv );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = pXMLHttpRequest->OpenRequest( "GET",
|
||||
argv[2],
|
||||
PR_FALSE,
|
||||
nsnull, nsnull );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = pXMLHttpRequest->Send( nsnull );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = pXMLHttpRequest->GetResponseXML( getter_AddRefs( pDOMDocument ) );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
|
||||
if (pDOMDocument) {
|
||||
printf( "Synchronous read of %s successful, DOMDocument created\n", argv[2] );
|
||||
}
|
||||
else {
|
||||
printf( "Synchronous read of %s NOT successful, DOMDocument NOT created\n", argv[2] );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "pXMLHttpRequest->GetResponseXML failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "pXMLHttpRequest->Send failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "pXMLHttpRequest->OpenRequest failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf( "do_CreateInstance of XMLHttpRequest failed for %s - %08X\n", argv[2], rv );
|
||||
}
|
||||
}
|
||||
else {
|
||||
usage( );
|
||||
}
|
||||
}
|
||||
else {
|
||||
usage( );
|
||||
}
|
||||
|
||||
if (pDOMDocument) {
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
pDOMDocument->GetDocumentElement(getter_AddRefs(element));
|
||||
nsAutoString tagName;
|
||||
if (element) element->GetTagName(tagName);
|
||||
char *s = tagName.ToNewCString();
|
||||
printf("Document element=\"%s\"\n",s);
|
||||
nsCRT::free(s);
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(pDOMDocument);
|
||||
if (doc) {
|
||||
nsCOMPtr<nsIURI> uri = dont_AddRef(doc->GetDocumentURL());
|
||||
nsXPIDLCString spec;
|
||||
uri->GetSpec(getter_Copies(spec));
|
||||
printf("Document URI=\"%s\"\n",spec.get());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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 imitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is International
|
||||
# Business Machines Corporation. Portions created by IBM
|
||||
# Corporation are Copyright (C) 2000 International Business
|
||||
# Machines Corporation. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): IBM Corporation.
|
||||
# Heikki Toivonen <heikki@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH = ..\..\..
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROG1 = .\$(OBJDIR)\TestXMLExtras.exe
|
||||
|
||||
PROGRAMS = $(PROG1) \
|
||||
$(NULL)
|
||||
|
||||
LCFLAGS = -DUSE_NSREG -GX
|
||||
|
||||
REQUIRES = libreg
|
||||
|
||||
LINCS = \
|
||||
-Iservices \
|
||||
-I$(PUBLIC)\xpcom
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
LLIBS = $(LLIBS) $(GLOWDIR)\glowcode.lib
|
||||
!endif
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(PROGRAMS)
|
||||
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
|
||||
|
||||
clobber::
|
||||
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
|
||||
|
||||
$(PROG1): $(OBJDIR) TestXMLExtras.cpp
|
Загрузка…
Ссылка в новой задаче