зеркало из https://github.com/mozilla/pjs.git
Bug 78622, DOMParser and XMLHttpRequest failures when parser blocked (with xml-stylesheet for example). r=harishd,sr=vidur.
This commit is contained in:
Родитель
861ddc03d5
Коммит
cbfc1b0687
|
@ -34,6 +34,7 @@ CPPSRCS = \
|
|||
nsDOMSerializer.cpp \
|
||||
nsXMLHttpRequest.cpp \
|
||||
nsDOMParser.cpp \
|
||||
nsLoadListenerProxy.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
|
|
|
@ -31,6 +31,7 @@ CPPSRCS= \
|
|||
nsDOMSerializer.cpp \
|
||||
nsXMLHttpRequest.cpp \
|
||||
nsDOMParser.cpp \
|
||||
nsLoadListenerProxy.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
@ -38,6 +39,7 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\nsDOMSerializer.obj \
|
||||
.\$(OBJDIR)\nsXMLHttpRequest.obj \
|
||||
.\$(OBJDIR)\nsDOMParser.obj \
|
||||
.\$(OBJDIR)\nsLoadListenerProxy.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -41,6 +41,21 @@
|
|||
#include "nsICodebasePrincipal.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsLoadListenerProxy.h"
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
#endif
|
||||
|
||||
static const char* kLoadAsData = "loadAsData";
|
||||
|
||||
static NS_DEFINE_CID(kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID);
|
||||
|
@ -252,6 +267,71 @@ NS_IMETHODIMP nsDOMParserChannel::AsyncOpen(nsIStreamListener *listener, nsISupp
|
|||
//
|
||||
/////////////////////////////////////////////
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
// See if we have a modal event loop
|
||||
static inline PRBool IsModal(nsIWebBrowserChrome *aWindow)
|
||||
{
|
||||
if (aWindow) {
|
||||
PRBool isModal;
|
||||
if (NS_SUCCEEDED(aWindow->IsWindowModal(&isModal))) {
|
||||
return isModal;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// nsIDOMEventListener
|
||||
nsresult
|
||||
nsDOMParser::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIDOMLoadListener
|
||||
nsresult
|
||||
nsDOMParser::Load(nsIDOMEvent* aEvent)
|
||||
{
|
||||
if (IsModal(mChromeWindow)) {
|
||||
mChromeWindow->ExitModalEventLoop(NS_OK);
|
||||
}
|
||||
|
||||
mChromeWindow = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMParser::Unload(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMParser::Abort(nsIDOMEvent* aEvent)
|
||||
{
|
||||
if (IsModal(mChromeWindow)) {
|
||||
mChromeWindow->ExitModalEventLoop(NS_OK);
|
||||
}
|
||||
|
||||
mChromeWindow = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMParser::Error(nsIDOMEvent* aEvent)
|
||||
{
|
||||
if (IsModal(mChromeWindow)) {
|
||||
mChromeWindow->ExitModalEventLoop(NS_OK);
|
||||
}
|
||||
|
||||
mChromeWindow = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
nsDOMParser::nsDOMParser()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
@ -259,13 +339,22 @@ nsDOMParser::nsDOMParser()
|
|||
|
||||
nsDOMParser::~nsDOMParser()
|
||||
{
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
if (IsModal(mChromeWindow)) {
|
||||
mChromeWindow->ExitModalEventLoop(NS_OK);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// QueryInterface implementation for nsDOMParser
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMParser)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMParser)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMParser)
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMLoadListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
#endif
|
||||
NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(DOMParser)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
@ -435,6 +524,22 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
|
|||
getter_AddRefs(domDocument));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
// Register as a load listener on the document
|
||||
nsCOMPtr<nsIDOMEventReceiver> target(do_QueryInterface(domDocument));
|
||||
if (target) {
|
||||
nsWeakPtr requestWeak(getter_AddRefs(NS_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;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create a fake channel
|
||||
nsDOMParserChannel* parserChannel = new nsDOMParserChannel(baseURI, contentType);
|
||||
if (!parserChannel) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -449,14 +554,69 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
|
|||
// Tell the document to start loading
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
nsCOMPtr<nsIDocument> document(do_QueryInterface(domDocument));
|
||||
|
||||
if (!document) return NS_ERROR_FAILURE;
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
nsCOMPtr<nsIEventQueue> modalEventQueue;
|
||||
nsCOMPtr<nsIEventQueueService> eventQService;
|
||||
|
||||
if (cc) {
|
||||
JSContext* cx;
|
||||
rv = cc->GetJSContext(&cx);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
// We can only do this if we're called from a DOM script context
|
||||
nsIScriptContext* scriptCX = (nsIScriptContext*)JS_GetContextPrivate(cx);
|
||||
if (!scriptCX) return NS_OK;
|
||||
|
||||
// Get the nsIDocShellTreeOwner associated with the window
|
||||
// containing this script context
|
||||
// XXX Need to find a better way to do this rather than
|
||||
// chaining through a bunch of getters and QIs
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
scriptCX->GetGlobalObject(getter_AddRefs(global));
|
||||
if (!global) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
rv = global->GetDocShell(getter_AddRefs(docshell));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(docshell);
|
||||
if (!item) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
rv = item->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIInterfaceRequestor> treeRequestor(do_GetInterface(treeOwner));
|
||||
if (!treeRequestor) return NS_ERROR_FAILURE;
|
||||
|
||||
treeRequestor->GetInterface(NS_GET_IID(nsIWebBrowserChrome), getter_AddRefs(mChromeWindow));
|
||||
if (!mChromeWindow) return NS_ERROR_FAILURE;
|
||||
|
||||
eventQService = do_GetService(kEventQueueServiceCID);
|
||||
if(!eventQService ||
|
||||
NS_FAILED(eventQService->PushThreadEventQueue(getter_AddRefs(modalEventQueue)))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
rv = document->StartDocumentLoad(kLoadAsData, channel,
|
||||
nsnull, nsnull,
|
||||
getter_AddRefs(listener),
|
||||
PR_FALSE);
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
if (NS_FAILED(rv) || !listener) {
|
||||
if (modalEventQueue) {
|
||||
eventQService->PopThreadEventQueue(modalEventQueue);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
#else
|
||||
if (NS_FAILED(rv) || !listener) return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
|
||||
// Now start pumping data to the listener
|
||||
nsresult status;
|
||||
|
@ -470,7 +630,29 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
|
|||
}
|
||||
|
||||
rv = listener->OnStopRequest(request, nsnull, status);
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
if (NS_FAILED(rv)) {
|
||||
if (modalEventQueue) {
|
||||
eventQService->PopThreadEventQueue(modalEventQueue);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
#else
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
// Spin an event loop here and wait
|
||||
if (mChromeWindow) {
|
||||
rv = mChromeWindow->ShowAsModal();
|
||||
|
||||
eventQService->PopThreadEventQueue(modalEventQueue);
|
||||
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
} else if (modalEventQueue) {
|
||||
eventQService->PopThreadEventQueue(modalEventQueue);
|
||||
}
|
||||
#endif
|
||||
|
||||
*_retval = domDocument;
|
||||
NS_ADDREF(*_retval);
|
||||
|
|
|
@ -29,7 +29,18 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
#define IMPLEMENT_SYNC_LOAD
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIDOMLoadListener.h"
|
||||
#include "nsWeakReference.h"
|
||||
#endif
|
||||
|
||||
class nsDOMParser : public nsIDOMParser
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
, public nsIDOMLoadListener
|
||||
, public nsSupportsWeakReference
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
nsDOMParser();
|
||||
|
@ -40,8 +51,23 @@ public:
|
|||
// nsIDOMParser
|
||||
NS_DECL_NSIDOMPARSER
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
// nsIDOMEventListener
|
||||
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMLoadListener
|
||||
NS_IMETHOD Load(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Error(nsIDOMEvent* aEvent);
|
||||
#endif
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIURI> mBaseURI;
|
||||
|
||||
#ifdef IMPLEMENT_SYNC_LOAD
|
||||
nsCOMPtr<nsIWebBrowserChrome> mChromeWindow;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
#include "nsLoadListenerProxy.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
|
||||
nsLoadListenerProxy::nsLoadListenerProxy(nsWeakPtr aParent)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mParent = aParent;
|
||||
}
|
||||
|
||||
nsLoadListenerProxy::~nsLoadListenerProxy()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsLoadListenerProxy, 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::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;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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):
|
||||
*/
|
||||
|
||||
#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 Unload(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Error(nsIDOMEvent* aEvent);
|
||||
|
||||
protected:
|
||||
nsWeakPtr mParent;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -60,6 +60,8 @@
|
|||
#endif
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsLoadListenerProxy.h"
|
||||
|
||||
static const char* kLoadAsData = "loadAsData";
|
||||
#define LOADSTR NS_LITERAL_STRING("load")
|
||||
|
@ -106,109 +108,6 @@ GetCurrentContext(nsIScriptContext **aScriptContext)
|
|||
return;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
// This class exists to prevent a circular reference between
|
||||
// the loaded document and the nsXMLHttpRequest instance. 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 Unload(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Error(nsIDOMEvent* aEvent);
|
||||
|
||||
protected:
|
||||
nsWeakPtr mParent;
|
||||
};
|
||||
|
||||
nsLoadListenerProxy::nsLoadListenerProxy(nsWeakPtr aParent)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mParent = aParent;
|
||||
}
|
||||
|
||||
nsLoadListenerProxy::~nsLoadListenerProxy()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsLoadListenerProxy, 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::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;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
|
@ -929,12 +828,23 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
|||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult status)
|
||||
{
|
||||
nsCOMPtr<nsIParser> parser(do_QueryInterface(mXMLParserStreamListener));
|
||||
NS_ABORT_IF_FALSE(parser, "stream listener was expected to be a parser");
|
||||
|
||||
nsresult rv = mXMLParserStreamListener->OnStopRequest(request,ctxt,status);
|
||||
mXMLParserStreamListener = nsnull;
|
||||
mReadRequest = nsnull;
|
||||
mContext = nsnull;
|
||||
|
||||
// The parser needs to be enabled for us to safely call RequestCompleted().
|
||||
// If the parser is not enabled, it means it was blocked, by xml-stylesheet PI
|
||||
// for example, and is still building the document. RequestCompleted() must be
|
||||
// called later, when we get the load event from the document.
|
||||
if (parser && parser->IsParserEnabled()) {
|
||||
RequestCompleted();
|
||||
} else {
|
||||
ChangeState(XML_HTTP_REQUEST_STOPPED,PR_FALSE);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -945,8 +855,10 @@ nsXMLHttpRequest::RequestCompleted()
|
|||
nsresult rv = NS_OK;
|
||||
|
||||
// If we're uninitialized at this point, we encountered an error
|
||||
// earlier and listeners have already been notified.
|
||||
if (mStatus == XML_HTTP_REQUEST_UNINITIALIZED) {
|
||||
// earlier and listeners have already been notified. Also we do
|
||||
// not want to do this if we already completed.
|
||||
if ((mStatus == XML_HTTP_REQUEST_UNINITIALIZED) ||
|
||||
(mStatus == XML_HTTP_REQUEST_COMPLETED)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1275,10 +1187,17 @@ NS_IMETHODIMP
|
|||
nsXMLHttpRequest::GetReadyState(PRInt32 *aState)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aState);
|
||||
if (mStatus == XML_HTTP_REQUEST_SENT) {
|
||||
// Translate some of our internal states for external consumers
|
||||
switch (mStatus) {
|
||||
case XML_HTTP_REQUEST_SENT:
|
||||
*aState = XML_HTTP_REQUEST_OPENED;
|
||||
} else {
|
||||
break;
|
||||
case XML_HTTP_REQUEST_STOPPED:
|
||||
*aState = XML_HTTP_REQUEST_INTERACTIVE;
|
||||
break;
|
||||
default:
|
||||
*aState = mStatus;
|
||||
break;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1301,6 +1220,16 @@ nsXMLHttpRequest::Load(nsIDOMEvent* aEvent)
|
|||
// sending the load event until OnStopRequest(). In normal case
|
||||
// there is no harm done, we will get OnStopRequest() immediately
|
||||
// after the load event.
|
||||
//
|
||||
// However, if the data we were loading caused the parser to stop,
|
||||
// for example when loading external stylesheets, we can receive
|
||||
// the OnStopRequest() call before the parser has finished building
|
||||
// the document. In that case, we obviously should not fire the event
|
||||
// in OnStopRequest(). For those documents, we must wait for the load
|
||||
// event from the document to fire our RequestCompleted().
|
||||
if (mStatus == XML_HTTP_REQUEST_STOPPED) {
|
||||
RequestCompleted();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,8 @@ enum nsXMLHttpRequestState {
|
|||
XML_HTTP_REQUEST_LOADED,
|
||||
XML_HTTP_REQUEST_INTERACTIVE,
|
||||
XML_HTTP_REQUEST_COMPLETED,
|
||||
XML_HTTP_REQUEST_SENT // This is Mozilla-internal only, LOADING in IE and external view
|
||||
XML_HTTP_REQUEST_SENT, // This is Mozilla-internal only, LOADING in IE and external view
|
||||
XML_HTTP_REQUEST_STOPPED // This is Mozilla-internal only, INTERACTIVE in IE and external view
|
||||
};
|
||||
|
||||
class nsXMLHttpRequest : public nsIXMLHttpRequest,
|
||||
|
|
Двоичные данные
extensions/xmlextras/macbuild/xmlextras.mcp
Двоичные данные
extensions/xmlextras/macbuild/xmlextras.mcp
Двоичный файл не отображается.
|
@ -43,7 +43,7 @@ function myfunc(e)
|
|||
document.getElementById("id4").firstChild.nodeValue = p.status;
|
||||
document.getElementById("id5").firstChild.nodeValue = p.statusText;
|
||||
document.getElementById("id6").firstChild.nodeValue = p.readyState;
|
||||
var eventProperties;
|
||||
var eventProperties = "";
|
||||
for (prop in e) {
|
||||
eventProperties += prop + " : '" + e[prop] + "'\n";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,298 @@
|
|||
/**
|
||||
* A CSS test file for display.xml
|
||||
*
|
||||
* This file is intentionally long to make parsing
|
||||
* it last a little longer.
|
||||
*/
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
doc {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
foo {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
d {
|
||||
display: block;
|
||||
color: red;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f1 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f2 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f3 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f4 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f5 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f6 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f7 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f8 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f9 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f10 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f11 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f12 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f13 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f14 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f15 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f21 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f22 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f23 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f24 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f25 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f26 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f27 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f28 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f29 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f210 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f211 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f212 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f213 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f214 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/***********************************************
|
||||
* S O M E C O M M E N T S *
|
||||
**********************************************/
|
||||
f215 {
|
||||
display: block;
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>HTML File</title>
|
||||
<link type="text/css" rel="stylesheet" href="display.css">
|
||||
</head>
|
||||
<body>
|
||||
<p>HTML File</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/css" href="display.css"?>
|
||||
<!DOCTYPE doc [
|
||||
<!ATTLIST d id ID #IMPLIED>
|
||||
]>
|
||||
<doc>
|
||||
<foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>
|
||||
<d id="id3">Three</d>
|
||||
</doc>
|
|
@ -31,7 +31,7 @@ function myfunc(e)
|
|||
document.getElementById("id4").firstChild.nodeValue = p.status;
|
||||
document.getElementById("id5").firstChild.nodeValue = p.statusText;
|
||||
document.getElementById("id6").firstChild.nodeValue = p.readyState;
|
||||
var eventProperties;
|
||||
var eventProperties = "";
|
||||
for (prop in e) {
|
||||
eventProperties += prop + " : '" + e[prop] + "'\n";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>GET test</title>
|
||||
<style type="text/css">
|
||||
.box {
|
||||
display: box;
|
||||
border: 1px solid black;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.boxheader {
|
||||
font-weight: bold;
|
||||
color: maroon;
|
||||
}
|
||||
pre {
|
||||
margin-left: 2em;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
var p = new XMLHttpRequest();
|
||||
|
||||
function myfunc(e)
|
||||
{
|
||||
document.getElementById("id1").firstChild.nodeValue = p.responseText;
|
||||
if (p.responseXML) {
|
||||
var s = new XMLSerializer();
|
||||
var d = p.responseXML;
|
||||
var str = s.serializeToString(d);
|
||||
document.getElementById("id2").firstChild.nodeValue = str;
|
||||
}
|
||||
document.getElementById("id3").firstChild.nodeValue = p.getAllResponseHeaders();
|
||||
document.getElementById("id4").firstChild.nodeValue = p.status;
|
||||
document.getElementById("id5").firstChild.nodeValue = p.statusText;
|
||||
document.getElementById("id6").firstChild.nodeValue = p.readyState;
|
||||
var eventProperties = "";
|
||||
for (prop in e) {
|
||||
eventProperties += prop + " : '" + e[prop] + "'\n";
|
||||
}
|
||||
document.getElementById("id7").firstChild.nodeValue =
|
||||
"Event object: " + e + "\n" +
|
||||
"Event properties:\n" + eventProperties;
|
||||
}
|
||||
|
||||
p.onload = myfunc;
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
|
||||
p.open("GET", "http://green/heikki/display.xml");
|
||||
p.send(null);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>GET test</h1>
|
||||
|
||||
<div class="box"><span class="boxheader">responseText</span>
|
||||
<pre id="id1">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">responseXML serialized</span>
|
||||
<pre id="id2">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">getAllResponseHeaders()</span>
|
||||
<pre id="id3">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">status</span>
|
||||
<pre id="id4">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">statusText</span>
|
||||
<pre id="id5">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">readyState</span>
|
||||
<pre id="id6">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">Event information</span>
|
||||
<pre id="id7">@@No result@@</pre>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,75 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>GET test</title>
|
||||
<style type="text/css">
|
||||
.box {
|
||||
display: box;
|
||||
border: 1px solid black;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.boxheader {
|
||||
font-weight: bold;
|
||||
color: maroon;
|
||||
}
|
||||
pre {
|
||||
margin-left: 2em;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
var p = new XMLHttpRequest();
|
||||
|
||||
function myfunc(e)
|
||||
{
|
||||
document.getElementById("id1").firstChild.nodeValue = p.responseText;
|
||||
if (p.responseXML) {
|
||||
var s = new XMLSerializer();
|
||||
var d = p.responseXML;
|
||||
var str = s.serializeToString(d);
|
||||
document.getElementById("id2").firstChild.nodeValue = str;
|
||||
}
|
||||
document.getElementById("id3").firstChild.nodeValue = p.getAllResponseHeaders();
|
||||
document.getElementById("id4").firstChild.nodeValue = p.status;
|
||||
document.getElementById("id5").firstChild.nodeValue = p.statusText;
|
||||
document.getElementById("id6").firstChild.nodeValue = p.readyState;
|
||||
var eventProperties = "";
|
||||
for (prop in e) {
|
||||
eventProperties += prop + " : '" + e[prop] + "'\n";
|
||||
}
|
||||
document.getElementById("id7").firstChild.nodeValue =
|
||||
"Event object: " + e + "\n" +
|
||||
"Event properties:\n" + eventProperties;
|
||||
}
|
||||
|
||||
p.onload = myfunc;
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
|
||||
p.open("GET", "http://green/heikki/display.html");
|
||||
p.send(null);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>GET test</h1>
|
||||
|
||||
<div class="box"><span class="boxheader">responseText</span>
|
||||
<pre id="id1">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">responseXML serialized</span>
|
||||
<pre id="id2">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">getAllResponseHeaders()</span>
|
||||
<pre id="id3">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">status</span>
|
||||
<pre id="id4">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">statusText</span>
|
||||
<pre id="id5">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">readyState</span>
|
||||
<pre id="id6">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">Event information</span>
|
||||
<pre id="id7">@@No result@@</pre>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,49 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>DOMParser/XMLSerializer test</title>
|
||||
<style type="text/css">
|
||||
.box {
|
||||
display: box;
|
||||
border: 1px solid black;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.boxheader {
|
||||
font-weight: bold;
|
||||
color: maroon;
|
||||
}
|
||||
pre {
|
||||
margin-left: 2em;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function execute()
|
||||
{
|
||||
var parser = new DOMParser();
|
||||
var str =
|
||||
'<?xml version="1.0"?>\n<!DOCTYPE doc [\n<!ATTLIST d id ID #IMPLIED>\n]>\n<doc>\n <foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>\n <d id="id3">Three</d>\n</doc>\n';
|
||||
var doc = parser.parseFromString(str,"text/xml");
|
||||
|
||||
document.getElementById("id1").firstChild.nodeValue = str;
|
||||
document.getElementById("id2").firstChild.nodeValue = doc;
|
||||
var ser = new XMLSerializer();
|
||||
document.getElementById("id3").firstChild.nodeValue = ser.serializeToString(doc);
|
||||
}
|
||||
|
||||
setTimeout(execute,0);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>DOMParser/XMLSerializer test</h1>
|
||||
|
||||
<div class="box"><span class="boxheader">text to parse</span>
|
||||
<pre id="id1">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">document object</span>
|
||||
<pre id="id2">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">document object serialized</span>
|
||||
<pre id="id3">@@No result@@</pre>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,49 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>DOMParser/XMLSerializer test</title>
|
||||
<style type="text/css">
|
||||
.box {
|
||||
display: box;
|
||||
border: 1px solid black;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.boxheader {
|
||||
font-weight: bold;
|
||||
color: maroon;
|
||||
}
|
||||
pre {
|
||||
margin-left: 2em;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function execute()
|
||||
{
|
||||
var parser = new DOMParser();
|
||||
var str =
|
||||
'<?xml version="1.0"?>\n<?xml-stylesheet href="display.css" type="text/css"?>\n<!DOCTYPE doc [\n<!ATTLIST d id ID #IMPLIED>\n]>\n<doc>\n <foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>\n <d id="id3">Three</d>\n</doc>\n';
|
||||
var doc = parser.parseFromString(str,"text/xml");
|
||||
|
||||
document.getElementById("id1").firstChild.nodeValue = str;
|
||||
document.getElementById("id2").firstChild.nodeValue = doc;
|
||||
var ser = new XMLSerializer();
|
||||
document.getElementById("id3").firstChild.nodeValue = ser.serializeToString(doc);
|
||||
}
|
||||
|
||||
setTimeout(execute,0);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>DOMParser/XMLSerializer test</h1>
|
||||
|
||||
<div class="box"><span class="boxheader">text to parse</span>
|
||||
<pre id="id1">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">document object</span>
|
||||
<pre id="id2">@@No result@@</pre>
|
||||
</div>
|
||||
<div class="box"><span class="boxheader">document object serialized</span>
|
||||
<pre id="id3">@@No result@@</pre>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -43,7 +43,7 @@ function myfunc(e)
|
|||
document.getElementById("id4").firstChild.nodeValue = p.status;
|
||||
document.getElementById("id5").firstChild.nodeValue = p.statusText;
|
||||
document.getElementById("id6").firstChild.nodeValue = p.readyState;
|
||||
var eventProperties;
|
||||
var eventProperties = "";
|
||||
for (prop in e) {
|
||||
eventProperties += prop + " : '" + e[prop] + "'\n";
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче