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:
heikki%netscape.com 2006-04-20 03:37:01 +00:00
Родитель dfd330609b
Коммит e7bb5cd292
5 изменённых файлов: 64 добавлений и 9 удалений

Просмотреть файл

@ -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,
@ -449,7 +450,7 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
@ -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)
{