Prettyprint without modifying the DOM by using an XBL binding. Use viewsource.css for styling. Also refactor a real sync-load service and make transformiix and XBL use it.

r=jkeiser sr=darin
This commit is contained in:
sicking%bigfoot.com 2002-10-09 07:03:15 +00:00
Родитель 5e174c6a8d
Коммит 8ad1aece33
38 изменённых файлов: 723 добавлений и 549 удалений

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

@ -244,9 +244,6 @@ sub InstallNonChromeResources()
my($html_dir) = "$resource_dir" . "html:";
InstallResources(":mozilla:layout:html:base:src:MANIFEST_RES", "$html_dir");
my($xml_dir) = "$resource_dir" . "xml:";
InstallResources(":mozilla:content:xml:document:resources:MANIFEST_RES", "$xml_dir");
my($throbber_dir) = "$resource_dir" . "throbber:";
BuildFolderResourceAliases(":mozilla:webshell:tests:viewer:throbber:", "$throbber_dir");
@ -628,8 +625,8 @@ sub ProcessJarManifests()
else {
MakeAlias(":mozilla:themes:classic:global:mac:xulscrollbars.css", ":mozilla:themes:classic:global:mac:scrollbars.css");
}
CreateJarFromManifest(":mozilla:content:xml:document:resources:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:themes:classic:global:mac:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:themes:classic:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:themes:modern:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:xpcom:base:jar.mn", $chrome_dir, \%jars);

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

@ -9,9 +9,9 @@ nsISelectionListener.idl
nsISelectionPrivate.idl
nsIScriptLoader.idl
nsIScriptLoaderObserver.idl
nsISyncLoadDOMService.idl
nsIPrintProgress.idl
nsIPrintStatusFeedback.idl
nsIPrintProgressParams.idl
nsIDragDropHandler.idl
nsIDragDropOverride.idl

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

@ -72,6 +72,7 @@ XPIDLSRCS = \
nsISelectionPrivate.idl \
nsIScriptLoader.idl \
nsIScriptLoaderObserver.idl \
nsISyncLoadDOMService.idl \
nsIPrintProgress.idl \
nsIPrintProgressParams.idl \
nsIPrintStatusFeedback.idl \

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

@ -306,4 +306,11 @@
#endif // MOZ_SVG
#define NS_SYNCLOADDOMSERVICE_CID \
{ /* 0e4e7d00-f71a-439f-9178-1a71ff11b55f */ \
0x0e4e7d00, 0xf71a, 0x439f, \
{0x91, 0x78, 0x1a, 0x71, 0xff, 0x11, 0xb5, 0x5f} }
#define NS_SYNCLOADDOMSERVICE_CONTRACTID \
"@mozilla.org/content/syncload-dom-service;1"
#endif /* nsContentCID_h__ */

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

@ -0,0 +1,100 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jonas Sicking <sicking@bigfoot.com> (Original author)
*
* 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 nsIURI;
interface nsIDOMDocument;
interface nsIChannel;
/*************************************************************************
* *
* **** NOTICE **** *
* *
* nsISyncLoadDOMService defines synchronous methods to download *
* data from the network. Any delays from the server will *
* appear as a hang in the mozilla UI. Therefore, this interface *
* should be avoided as much as possible. *
* *
* Don't make me come over there!! *
* *
* *
************************************************************************/
/**
* The nsISyncDOMLoadService interface can be used to synchronously load
* a document.
*/
[scriptable, uuid(96a13c30-695a-492c-918b-04ae3edb4e4c)]
interface nsISyncLoadDOMService : nsISupports
{
/**
* Synchronously load the document from the specified channel.
*
* @param aChannel The channel to load the document from.
* @param aLoaderURI URI of loading document. For security checks
* null if no securitychecks should be done
*
* @returns The document loaded from the URI.
*/
nsIDOMDocument loadDocument(in nsIChannel aChannel, in nsIURI aLoaderURI);
/**
* Synchronously load the document from the specified channel. The channel
* must be possible to open synchronously.
*
* @param aChannel The channel to load the document from.
* @param aLoaderURI URI of loading document. For security checks
* null if no securitychecks should be done
*
* @returns The document loaded from the URI.
*/
nsIDOMDocument loadLocalDocument(in nsIChannel aChannel,
in nsIURI aLoaderURI);
/**
* Synchronously load the xbl-document from the specified channel. The channel
* must be possible to open synchronously.
*
* @param aChannel The channel to load the document from.
*
* @returns The document loaded from the URI.
*/
nsIDOMDocument loadLocalXBLDocument(in nsIChannel aChannel);
};

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

@ -88,6 +88,7 @@ CPPSRCS = \
nsSelection.cpp \
nsStyleContext.cpp \
nsStyleSet.cpp \
nsSyncLoadService.cpp \
nsTextContentChangeData.cpp \
nsTextNode.cpp \
nsTreeWalker.cpp \

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

@ -37,7 +37,15 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsSyncLoader.h"
#include "nsCOMPtr.h"
#include "nsIChannel.h"
#include "nsIDOMLoadListener.h"
#include "nsIHttpEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsIScriptContext.h"
#include "nsISyncLoadDOMService.h"
#include "nsString.h"
#include "nsWeakReference.h"
#include "jsapi.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
@ -52,15 +60,85 @@
#include "nsContentCID.h"
#include "nsNetUtil.h"
#include "nsIHttpChannel.h"
#include "nsIScriptLoader.h"
#include "nsIScriptLoaderObserver.h"
#include "nsIXMLContentSink.h"
#include "nsIContent.h"
static const char* kLoadAsData = "loadAsData";
static NS_DEFINE_CID(kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
// This is ugly, but nsXBLContentSink.h isn't exported
extern
nsresult
NS_NewXBLContentSink(nsIXMLContentSink** aResult,
nsIDocument* aDoc,
nsIURI* aURL,
nsIWebShell* aWebShell);
class nsSyncLoadService : public nsISyncLoadDOMService
{
public:
nsSyncLoadService();
virtual ~nsSyncLoadService();
NS_DECL_ISUPPORTS
NS_DECL_NSISYNCLOADDOMSERVICE
static
nsresult PushSyncStreamToListener(nsIInputStream* aIn,
nsIStreamListener* aListener,
nsIChannel* aChannel);
};
/**
* This class manages loading a single XML document
*/
class nsSyncLoader : public nsIDOMLoadListener,
public nsIHttpEventSink,
public nsIInterfaceRequestor,
public nsSupportsWeakReference
{
public:
nsSyncLoader();
virtual ~nsSyncLoader();
NS_DECL_ISUPPORTS
NS_IMETHOD LoadDocument(nsIChannel* aChannel, nsIURI *aLoaderURI,
PRBool aChannelIsSync,
nsIDOMDocument** _retval);
// 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);
NS_DECL_NSIHTTPEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
protected:
PushAsyncStream(nsIStreamListener* aListener);
PushSyncStream(nsIStreamListener* aListener);
nsCOMPtr<nsIChannel> mChannel;
PRPackedBool mLoading;
PRPackedBool mLoadSuccess;
};
/*
* This class exists to prevent a circular reference between
* the loaded document and the nsSyncloader instance. The
* the loaded document and the nsSyncLoader 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
@ -172,107 +250,63 @@ nsSyncLoader::~nsSyncLoader()
}
}
NS_IMPL_ISUPPORTS5(nsSyncLoader,
nsISyncLoader,
NS_IMPL_ISUPPORTS4(nsSyncLoader,
nsIDOMLoadListener,
nsIHttpEventSink,
nsIInterfaceRequestor,
nsISupportsWeakReference)
NS_IMETHODIMP
nsSyncLoader::LoadDocument(nsIURI* aDocumentURI,
nsIDocument *aLoader,
nsSyncLoader::LoadDocument(nsIChannel* aChannel,
nsIURI *aLoaderURI,
PRBool aChannelIsSync,
nsIDOMDocument **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
nsCOMPtr<nsIURI> loaderURI;
aLoader->GetDocumentURL(getter_AddRefs(loaderURI));
nsresult rv = NS_OK;
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = securityManager->CheckLoadURI(loaderURI, aDocumentURI,
nsIScriptSecurityManager::STANDARD);
NS_ENSURE_SUCCESS(rv, rv);
mChannel = aChannel;
rv = securityManager->CheckSameOriginURI(loaderURI, aDocumentURI);
NS_ENSURE_SUCCESS(rv, rv);
if (aLoaderURI) {
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIURI> docURI;
rv = aChannel->GetURI(getter_AddRefs(docURI));
NS_ENSURE_SUCCESS(rv, rv);
rv = securityManager->CheckLoadURI(aLoaderURI, docURI,
nsIScriptSecurityManager::STANDARD);
NS_ENSURE_SUCCESS(rv, rv);
rv = securityManager->CheckSameOriginURI(aLoaderURI, docURI);
NS_ENSURE_SUCCESS(rv, rv);
}
// Get the loadgroup of the channel
nsCOMPtr<nsILoadGroup> loadGroup;
rv = aLoader->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
rv = aChannel->GetLoadGroup(getter_AddRefs(loadGroup));
NS_ENSURE_SUCCESS(rv, rv);
// Get and initialize a DOMImplementation
nsCOMPtr<nsIDOMDOMImplementation> implementation =
do_CreateInstance(kIDOMDOMImplementationCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrivateDOMImplementation> privImplementation(do_QueryInterface(implementation, &rv));
NS_ENSURE_SUCCESS(rv, rv);
privImplementation->Init(aDocumentURI);
// Create an empty document from it
nsString emptyStr;
nsCOMPtr<nsIDOMDocument> DOMDocument;
rv = implementation->CreateDocument(emptyStr,
emptyStr,
nsnull,
getter_AddRefs(DOMDocument));
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewChannel(getter_AddRefs(mChannel), aDocumentURI, nsnull, loadGroup);
NS_ENSURE_SUCCESS(rv, rv);
// Make sure we've been opened
if (!mChannel) {
return NS_ERROR_NOT_INITIALIZED;
}
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
if (httpChannel) {
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
NS_LITERAL_CSTRING(""));
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"));
// XXX need to set the HTTP referrer
}
// Tell the document to start loading
nsCOMPtr<nsIDocument> document = do_QueryInterface(DOMDocument, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEventQueueService> service =
do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEventQueue> currentThreadQ;
rv = service->PushThreadEventQueue(getter_AddRefs(currentThreadQ));
// Create document
nsCOMPtr<nsIDocument> document = do_CreateInstance(kXMLDocumentCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
// Register as a load listener on the document
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(DOMDocument);
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(document);
NS_ENSURE_TRUE(target, NS_ERROR_FAILURE);
nsWeakPtr requestWeak = getter_AddRefs(NS_GetWeakReference(NS_STATIC_CAST(nsIDOMLoadListener*, this)));
txLoadListenerProxy* proxy = new txLoadListenerProxy(requestWeak);
if (!proxy) {
service->PopThreadEventQueue(currentThreadQ);
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ENSURE_TRUE(proxy, 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)) {
service->PopThreadEventQueue(currentThreadQ);
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
mLoadSuccess = PR_FALSE;
@ -281,55 +315,86 @@ nsSyncLoader::LoadDocument(nsIURI* aDocumentURI,
loadGroup, nsnull,
getter_AddRefs(listener),
PR_FALSE);
if (NS_SUCCEEDED(rv)) {
// Hook us up to listen to redirects and the like
mChannel->SetNotificationCallbacks(this);
// Start reading from the channel
rv = mChannel->AsyncOpen(listener, nsnull);
if (NS_SUCCEEDED(rv)) {
mLoading = PR_TRUE;
// process events until we're finished.
PLEvent *event;
while (mLoading && NS_SUCCEEDED(rv)) {
rv = currentThreadQ->WaitForEvent(&event);
NS_ASSERTION(NS_SUCCEEDED(rv), ": currentThreadQ->WaitForEvent failed...\n");
if (NS_SUCCEEDED(rv)) {
rv = currentThreadQ->HandleEvent(event);
NS_ASSERTION(NS_SUCCEEDED(rv), ": currentThreadQ->HandleEvent failed...\n");
}
}
}
}
mChannel = 0;
if (NS_FAILED(rv)) {
service->PopThreadEventQueue(currentThreadQ);
// This will release the proxy
target->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*,
proxy),
NS_GET_IID(nsIDOMLoadListener));
return rv;
}
// This will release the proxy
rv = target->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*,
proxy),
NS_GET_IID(nsIDOMLoadListener));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> documentElement;
DOMDocument->GetDocumentElement(getter_AddRefs(documentElement));
if (mLoadSuccess && documentElement) {
*aResult = DOMDocument;
NS_ADDREF(*aResult);
if (aChannelIsSync) {
rv = PushSyncStream(listener);
}
else {
rv = PushAsyncStream(listener);
}
rv = service->PopThreadEventQueue(currentThreadQ);
mChannel = nsnull;
// This will release the proxy. Don't use the errorvalue from this since
// we're more interested in the errorvalue from the loading
target->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*,
proxy),
NS_GET_IID(nsIDOMLoadListener));
// check that the load succeeded
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(mLoadSuccess, NS_ERROR_FAILURE);
nsCOMPtr<nsIContent> rootContent;
document->GetRootContent(getter_AddRefs(rootContent));
NS_ENSURE_TRUE(rootContent, NS_ERROR_FAILURE);
return CallQueryInterface(document, aResult);
}
nsSyncLoader::PushAsyncStream(nsIStreamListener* aListener)
{
nsresult rv = NS_OK;
// Set up a new eventqueue
nsCOMPtr<nsIEventQueueService> service =
do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEventQueue> currentThreadQ;
rv = service->PushThreadEventQueue(getter_AddRefs(currentThreadQ));
NS_ENSURE_SUCCESS(rv, rv);
// Hook us up to listen to redirects and the like
mChannel->SetNotificationCallbacks(this);
// Start reading from the channel
rv = mChannel->AsyncOpen(aListener, nsnull);
if (NS_SUCCEEDED(rv)) {
mLoading = PR_TRUE;
// process events until we're finished.
PLEvent *event;
while (mLoading && NS_SUCCEEDED(rv)) {
rv = currentThreadQ->WaitForEvent(&event);
NS_ASSERTION(NS_SUCCEEDED(rv), ": currentThreadQ->WaitForEvent failed...\n");
if (NS_SUCCEEDED(rv)) {
rv = currentThreadQ->HandleEvent(event);
NS_ASSERTION(NS_SUCCEEDED(rv), ": currentThreadQ->HandleEvent failed...\n");
}
}
}
service->PopThreadEventQueue(currentThreadQ);
return rv;
}
nsSyncLoader::PushSyncStream(nsIStreamListener* aListener)
{
nsCOMPtr<nsIInputStream> in;
nsresult rv = mChannel->Open(getter_AddRefs(in));
NS_ENSURE_SUCCESS(rv, rv);
rv = nsSyncLoadService::PushSyncStreamToListener(in, aListener, mChannel);
return rv;
}
@ -414,3 +479,134 @@ nsSyncLoader::GetInterface(const nsIID & aIID,
{
return QueryInterface(aIID, aResult);
}
nsSyncLoadService::nsSyncLoadService()
{
NS_INIT_ISUPPORTS();
}
nsSyncLoadService::~nsSyncLoadService()
{
}
NS_IMPL_ISUPPORTS1(nsSyncLoadService,
nsISyncLoadDOMService)
NS_IMETHODIMP
nsSyncLoadService::LoadDocument(nsIChannel* aChannel, nsIURI* aLoaderURI,
nsIDOMDocument** _retval)
{
nsSyncLoader* loader = new nsSyncLoader();
NS_ENSURE_TRUE(loader, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(loader);
nsresult rv = loader->LoadDocument(aChannel, aLoaderURI, PR_FALSE,
_retval);
NS_RELEASE(loader);
return rv;
}
nsresult
nsSyncLoadService::LoadLocalDocument(nsIChannel* aChannel, nsIURI* aLoaderURI,
nsIDOMDocument** _retval)
{
nsSyncLoader* loader = new nsSyncLoader();
NS_ENSURE_TRUE(loader, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(loader);
nsresult rv = loader->LoadDocument(aChannel, aLoaderURI, PR_TRUE, _retval);
NS_RELEASE(loader);
return rv;
}
nsresult
nsSyncLoadService::LoadLocalXBLDocument(nsIChannel* aChannel,
nsIDOMDocument** _retval)
{
*_retval = nsnull;
nsCOMPtr<nsIInputStream> in;
nsresult rv = aChannel->Open(getter_AddRefs(in));
if (NS_FAILED(rv)) {
return rv;
}
// Get uri and loadgroup
nsCOMPtr<nsIURI> docURI;
rv = aChannel->GetURI(getter_AddRefs(docURI));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILoadGroup> loadGroup;
rv = aChannel->GetLoadGroup(getter_AddRefs(loadGroup));
NS_ENSURE_SUCCESS(rv, rv);
// Create document and contentsink and set them up.
nsCOMPtr<nsIDocument> doc = do_CreateInstance(kXMLDocumentCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
// Do this after making sure the |channel->Open| succeeded (which it
// won't if the file doesn't exist) so that we don't have to go
// through the work of breaking the circular references between
// content sink, script loader, and document.
nsCOMPtr<nsIXMLContentSink> xblSink;
rv = NS_NewXBLContentSink(getter_AddRefs(xblSink), doc, docURI, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> listener;
rv = doc->StartDocumentLoad(kLoadAsData,
aChannel,
loadGroup,
nsnull,
getter_AddRefs(listener),
PR_TRUE,
xblSink);
NS_ENSURE_SUCCESS(rv, rv);
rv = PushSyncStreamToListener(in, listener, aChannel);
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(doc, _retval);
}
// static
nsresult
nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
nsIStreamListener* aListener,
nsIChannel* aChannel)
{
// Set up buffering stream
nsCOMPtr<nsIInputStream> bufferedStream;
nsresult rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
aIn, 4096);
NS_ENSURE_SUCCESS(rv, rv);
// Load
aListener->OnStartRequest(aChannel, nsnull);
PRUint32 sourceOffset = 0;
while (1) {
PRUint32 readCount = 0;
rv = bufferedStream->Available(&readCount);
if (NS_FAILED(rv) || !readCount) {
break;
}
rv = aListener->OnDataAvailable(aChannel, nsnull, bufferedStream,
sourceOffset, readCount);
if (NS_FAILED(rv)) {
break;
}
sourceOffset += readCount;
}
aListener->OnStopRequest(aChannel, nsnull, rv);
return rv;
}
nsresult
NS_NewSyncLoadDOMService(nsISyncLoadDOMService** aResult)
{
*aResult = new nsSyncLoadService();
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*aResult);
return NS_OK;
}

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

@ -306,4 +306,11 @@
#endif // MOZ_SVG
#define NS_SYNCLOADDOMSERVICE_CID \
{ /* 0e4e7d00-f71a-439f-9178-1a71ff11b55f */ \
0x0e4e7d00, 0xf71a, 0x439f, \
{0x91, 0x78, 0x1a, 0x71, 0xff, 0x11, 0xb5, 0x5f} }
#define NS_SYNCLOADDOMSERVICE_CONTRACTID \
"@mozilla.org/content/syncload-dom-service;1"
#endif /* nsContentCID_h__ */

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

@ -109,6 +109,7 @@
#include "nsWyciwygProtocolHandler.h"
#include "nsContentAreaDragDrop.h"
#include "nsContentList.h"
#include "nsISyncLoadDOMService.h"
class nsIDocumentLoaderFactory;
@ -285,6 +286,7 @@ extern nsresult NS_NewBindingManager(nsIBindingManager** aResult);
extern nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult);
extern nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
extern nsresult NS_NewFrameLoader(nsIFrameLoader** aResult);
extern nsresult NS_NewSyncLoadDOMService(nsISyncLoadDOMService** aResult);
#ifdef MOZ_XUL
extern nsresult NS_NewXULElementFactory(nsIElementFactory** aResult);
@ -379,11 +381,12 @@ MAKE_CTOR(CreateMathMLElementFactory, nsIElementFactory, NS_NewMat
MAKE_CTOR(CreateSVGElementFactory, nsIElementFactory, NS_NewSVGElementFactory)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsContentHTTPStartup)
MAKE_CTOR(CreateContentDLF, nsIDocumentLoaderFactory, NS_NewContentDocumentLoaderFactory)
MAKE_CTOR(CreateContentDLF, nsIDocumentLoaderFactory, NS_NewContentDocumentLoaderFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCSSOMFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsInspectorCSSUtils)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWyciwygProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsContentAreaDragDrop)
MAKE_CTOR(CreateSyncLoadDOMService, nsISyncLoadDOMService, NS_NewSyncLoadDOMService)
static NS_IMETHODIMP
CreateHTMLImgElement(nsISupports* aOuter, REFNSIID aIID, void** aResult)
@ -876,7 +879,12 @@ static const nsModuleComponentInfo gComponents[] = {
{ "Content Area DragDrop",
NS_CONTENTAREADRAGDROP_CID,
NS_CONTENTAREADRAGDROP_CONTRACTID,
nsContentAreaDragDropConstructor }
nsContentAreaDragDropConstructor },
{ "SyncLoad DOM Service",
NS_SYNCLOADDOMSERVICE_CID,
NS_SYNCLOADDOMSERVICE_CONTRACTID,
CreateSyncLoadDOMService }
};

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

@ -1981,6 +1981,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoadService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContentDLF.cpp</PATH>
@ -3252,6 +3259,11 @@
<PATH>nsContentUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoadService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContentDLF.cpp</PATH>
@ -5542,6 +5554,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoadService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContentDLF.cpp</PATH>
@ -6813,6 +6832,11 @@
<PATH>nsContentUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoadService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContentDLF.cpp</PATH>
@ -7214,6 +7238,12 @@
<PATH>nsContentUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>content.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoadService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>content.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

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

@ -156,7 +156,7 @@ protected:
nsXBLProtoImplField* mField;
};
// This is also declared in nsSyncLoadService.cpp
nsresult
NS_NewXBLContentSink(nsIXMLContentSink** aResult,
nsIDocument* aDoc,

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

@ -77,6 +77,8 @@
#include "nsXBLAtoms.h"
#include "nsXULAtoms.h"
#include "nsCRT.h"
#include "nsContentUtils.h"
#include "nsISyncLoadDOMService.h"
#include "nsIXBLPrototypeHandler.h"
@ -466,75 +468,6 @@ nsXBLStreamListener::Load(nsIDOMEvent* aEvent)
return rv;
}
// nsProxyStream
// A helper class used for synchronous parsing of URLs.
class nsProxyStream : public nsIInputStream
{
private:
const char* mBuffer;
PRUint32 mSize;
PRUint32 mIndex;
public:
nsProxyStream(void) : mBuffer(nsnull)
{
NS_INIT_ISUPPORTS();
}
virtual ~nsProxyStream(void) {
}
// nsISupports
NS_DECL_ISUPPORTS
// nsIBaseStream
NS_IMETHOD Close(void) {
return NS_OK;
}
// nsIInputStream
NS_IMETHOD Available(PRUint32 *aLength) {
*aLength = mSize - mIndex;
return NS_OK;
}
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) {
PRUint32 readCount = PR_MIN(aCount, (mSize-mIndex));
memcpy(aBuf, mBuffer+mIndex, readCount);
mIndex += readCount;
*aReadCount = readCount;
return NS_OK;
}
NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) {
PRUint32 readCount = PR_MIN(count, (mSize-mIndex));
*_retval = 0;
nsresult rv = writer (this, closure, mBuffer+mIndex, mIndex, readCount, _retval);
mIndex += *_retval;
return rv;
}
NS_IMETHOD IsNonBlocking(PRBool *aNonBlocking) {
*aNonBlocking = PR_TRUE;
return NS_OK;
}
// Implementation
void SetBuffer(const char* aBuffer, PRUint32 aSize) {
mBuffer = aBuffer;
mSize = aSize;
mIndex = 0;
}
};
NS_IMPL_ISUPPORTS1(nsProxyStream, nsIInputStream)
// Implementation /////////////////////////////////////////////////////////////////
// Static member variable initialization
@ -1198,100 +1131,27 @@ nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement, nsIDocument* aB
NS_IMETHODIMP
nsXBLService::FetchSyncXMLDocument(nsIURI* aURI, nsIDocument** aResult)
{
// Initialize our out pointer to nsnull
*aResult = nsnull;
nsresult rv = NS_OK;
nsCOMPtr<nsIDOMDocument> domDoc;
nsCOMPtr<nsISyncLoadDOMService> loader =
do_GetService("@mozilla.org/content/syncload-dom-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
// Create the XML document
nsCOMPtr<nsIDocument> doc;
nsresult rv = nsComponentManager::CreateInstance(kXMLDocumentCID, nsnull,
NS_GET_IID(nsIDocument),
getter_AddRefs(doc));
if (NS_FAILED(rv)) return rv;
// XXX This is evil, but we're living in layout, so I'm
// just going to do it.
nsXMLDocument* xmlDoc = (nsXMLDocument*)(doc.get());
// Now we have to synchronously load the binding file.
// Create an XML content sink and a parser.
nsCOMPtr<nsIRequest> request;
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel), aURI, nsnull, nsnull);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> listener;
// Now do a blocking synchronous parse of the file.
nsCOMPtr<nsIInputStream> in;
rv = channel->Open(getter_AddRefs(in));
// If we couldn't open the channel, then just return.
if (NS_FAILED(rv)) return NS_OK;
request = do_QueryInterface(channel);
NS_ASSERTION(request != nsnull, "no request info");
NS_ASSERTION(in != nsnull, "no input stream");
NS_ENSURE_TRUE(in,NS_ERROR_FAILURE);
nsProxyStream* proxy = new nsProxyStream();
NS_ENSURE_TRUE(proxy,NS_ERROR_OUT_OF_MEMORY);
// Do this after making sure the |channel->Open| succeeded (which it
// won't if the file doesn't exist) so that we don't have to go
// through the work of breaking the circular references between
// content sink, script loader, and document.
nsCOMPtr<nsIXMLContentSink> xmlSink;
NS_NewXMLContentSink(getter_AddRefs(xmlSink), xmlDoc, aURI, nsnull, nsnull);
if (!xmlSink)
return NS_ERROR_FAILURE;
// Call StartDocumentLoad
if (NS_FAILED(rv = xmlDoc->StartDocumentLoad("loadAsData",
channel,
nsnull,
nsnull,
getter_AddRefs(listener),
PR_TRUE,
xmlSink))) {
NS_ERROR("Failure to init XML doc prior to load.");
return rv;
rv = loader->LoadLocalDocument(channel, nsnull, getter_AddRefs(domDoc));
if (rv == NS_ERROR_FILE_NOT_FOUND) {
return NS_OK;
}
NS_ENSURE_SUCCESS(rv, rv);
listener->OnStartRequest(request, nsnull);
while (PR_TRUE) {
char buf[4096];
PRUint32 readCount;
if (NS_FAILED(rv = in->Read(buf, sizeof(buf), &readCount)))
break; // error
if (readCount == 0)
break; // eof
proxy->SetBuffer(buf, readCount);
PRUint32 sourceOffset = 0;
rv = listener->OnDataAvailable(request, nsnull, proxy, sourceOffset, readCount);
sourceOffset += readCount;
if (NS_FAILED(rv))
break;
}
listener->OnStopRequest(request, nsnull, NS_OK);
// don't leak proxy!
proxy->Close();
delete proxy;
// The document is parsed. We now have a prototype document.
// Everything worked, so we can just hand this back now.
*aResult = doc;
NS_IF_ADDREF(*aResult);
return NS_OK;
return CallQueryInterface(domDoc, aResult);
}
NS_IMETHODIMP
@ -1299,30 +1159,15 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
nsIURI* aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIDocument** aResult)
{
nsresult rv = NS_OK;
// Initialize our out pointer to nsnull
*aResult = nsnull;
// Create the XML document
nsCOMPtr<nsIDocument> doc;
nsresult rv = nsComponentManager::CreateInstance(kXMLDocumentCID, nsnull,
NS_GET_IID(nsIDocument),
getter_AddRefs(doc));
if (NS_FAILED(rv)) return rv;
// XXX This is evil, but we're living in layout, so I'm
// just going to do it.
nsXMLDocument* xmlDoc = (nsXMLDocument*)(doc.get());
// Now we have to synchronously load the binding file.
// Create an XML content sink and a parser.
nsCOMPtr<nsILoadGroup> loadGroup;
if (aBoundDocument)
aBoundDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
nsCOMPtr<nsIRequest> request;
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel), aURI, nsnull, loadGroup);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIAtom> tagName;
if (aBoundElement)
@ -1333,20 +1178,28 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
tagName == nsHTMLAtoms::select || IsResourceURI(aURI))
aForceSyncLoad = PR_TRUE;
nsCOMPtr<nsIStreamListener> listener;
if(!aForceSyncLoad) {
// Create the XML document
nsCOMPtr<nsIDocument> doc = do_CreateInstance(kXMLDocumentCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel), aURI, nsnull, loadGroup);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIStreamListener> listener;
nsCOMPtr<nsIXMLContentSink> xblSink;
NS_NewXBLContentSink(getter_AddRefs(xblSink), xmlDoc, aURI, nsnull);
NS_NewXBLContentSink(getter_AddRefs(xblSink), doc, aURI, nsnull);
if (!xblSink)
return NS_ERROR_FAILURE;
if (NS_FAILED(rv = xmlDoc->StartDocumentLoad("loadAsData",
channel,
loadGroup,
nsnull,
getter_AddRefs(listener),
PR_TRUE,
xblSink))) {
if (NS_FAILED(rv = doc->StartDocumentLoad("loadAsData",
channel,
loadGroup,
nsnull,
getter_AddRefs(listener),
PR_TRUE,
xblSink))) {
NS_ERROR("Failure to init XBL doc prior to load.");
return rv;
}
@ -1379,75 +1232,24 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
}
// Now do a blocking synchronous parse of the file.
nsCOMPtr<nsIInputStream> in;
rv = channel->Open(getter_AddRefs(in));
// If we couldn't open the channel, then just return.
if (NS_FAILED(rv)) return NS_OK;
nsCOMPtr<nsIDOMDocument> domDoc;
nsCOMPtr<nsISyncLoadDOMService> loader =
do_GetService("@mozilla.org/content/syncload-dom-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
request = do_QueryInterface(channel);
// Open channel
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel), aURI, nsnull, loadGroup);
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(request != nsnull, "no request info");
NS_ASSERTION(in != nsnull, "no input stream");
NS_ENSURE_TRUE(in,NS_ERROR_FAILURE);
nsProxyStream* proxy = new nsProxyStream();
NS_ENSURE_TRUE(proxy,NS_ERROR_OUT_OF_MEMORY);
// Do this after making sure the |channel->Open| succeeded (which it
// won't if the file doesn't exist) so that we don't have to go
// through the work of breaking the circular references between
// content sink, script loader, and document.
nsCOMPtr<nsIXMLContentSink> xblSink;
NS_NewXBLContentSink(getter_AddRefs(xblSink), xmlDoc, aURI, nsnull);
if (!xblSink)
return NS_ERROR_FAILURE;
// Call StartDocumentLoad
if (NS_FAILED(rv = xmlDoc->StartDocumentLoad("loadAsData",
channel,
loadGroup,
nsnull,
getter_AddRefs(listener),
PR_TRUE,
xblSink))) {
NS_ERROR("Failure to init XBL doc prior to load.");
return rv;
rv = loader->LoadLocalXBLDocument(channel, getter_AddRefs(domDoc));
if (rv == NS_ERROR_FILE_NOT_FOUND) {
return NS_OK;
}
NS_ENSURE_SUCCESS(rv, rv);
listener->OnStartRequest(request, nsnull);
while (PR_TRUE) {
char buf[4096];
PRUint32 readCount;
if (NS_FAILED(rv = in->Read(buf, sizeof(buf), &readCount)))
break; // error
if (readCount == 0)
break; // eof
proxy->SetBuffer(buf, readCount);
PRUint32 sourceOffset = 0;
rv = listener->OnDataAvailable(request, nsnull, proxy, sourceOffset, readCount);
sourceOffset += readCount;
if (NS_FAILED(rv))
break;
}
listener->OnStopRequest(request, nsnull, NS_OK);
// don't leak proxy!
proxy->Close();
delete proxy;
// The document is parsed. We now have a prototype document.
// Everything worked, so we can just hand this back now.
*aResult = doc;
NS_IF_ADDREF(*aResult);
return NS_OK;
return CallQueryInterface(domDoc, aResult);
}
static void GetImmediateChild(nsIAtom* aTag, nsIContent* aParent, nsIContent** aResult)

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

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

@ -27,13 +27,3 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
EXPORT_RESOURCE_CONTENT = \
$(srcdir)/XMLPrettyPrint.xsl \
$(srcdir)/XMLPrettyPrint.css \
$(NULL)
libs::
$(INSTALL) $(EXPORT_RESOURCE_CONTENT) $(DIST)/bin/res/xml
install::
$(SYSINSTALL) $(IFLAGS1) $(EXPORT_RESOURCE_CONTENT) $(DESTDIR)$(mozappdir)/res/xml

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

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

@ -35,17 +35,14 @@
*
* ***** END LICENSE BLOCK ***** */
body {
font-family: 'Verdana', sans-serif;
width: 100%;
margin: 0;
padding: 0;
}
@import url("resource:/res/viewsource.css");
html {
width: 100%;
margin: 0;
padding: 0;
#top {
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
}
#header {
@ -55,11 +52,6 @@ html {
margin-bottom: 1em;
}
img {
float: left;
margin: 0.5em;
}
table {
border-spacing: 0;
margin: 0;
@ -69,41 +61,11 @@ td {
padding: 0;
}
.markup {
color: blue
}
.elemname {
color: red;
}
.attrname {
color: #f88;
}
.attrvalue {
color: black;
}
.text {
color: black;
font-weight: bold;
}
.indent {
margin-left: 1em;
}
.comment {
color: green;
font-style: italic;
}
.pi {
color: blue;
}
.expander > div {
.spacer {
width: 1em;
}
@ -114,6 +76,6 @@ td {
text-align: center;
}
.expander-closed .expander-content {
.expander-closed > * > .expander-content {
display: none;
}

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

@ -1,18 +1,83 @@
<?xml version="1.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) 2002
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Jonas Sicking <sicking@bigfoot.com> (Original author)
-
- 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 LGPL or the GPL. 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 ***** -->
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml">
<binding id="prettyprint">
<content>
We are prettyprinting using bindings!!<children/>
<content><html:div id='top'/>
<html:span style="display: none;"><children/></html:span>
</content>
<implementation>
<constructor><![CDATA[
alert('prettyprint is cool');
]]></constructor>
<implementation implements="nsIObserver">
<method name="observe">
<parameter name="aSubject"/>
<parameter name="aTopic"/>
<parameter name="aData"/>
<body>
if (aTopic == "prettyprint-dom-created")
document.getAnonymousNodes(this).item(0).appendChild(aSubject.documentElement);
</body>
</method>
</implementation>
<handlers>
<handler event="click" button="0">
<![CDATA[
try {
var par = event.originalTarget.parentNode;
if (par.nodeName == 'td' && par.className == 'expander') {
if (par.parentNode.className == 'expander-closed') {
par.parentNode.className = '';
event.originalTarget.src = 'chrome://global/skin/tree/twisty-open.gif';
}
else {
par.parentNode.className = 'expander-closed';
event.originalTarget.src = 'chrome://global/skin/tree/twisty-clsd.gif';
}
}
} catch (e) {
}
]]>
</handler>
</handlers>
</binding>
</bindings>

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

@ -36,49 +36,29 @@
-
- ***** END LICENSE BLOCK ***** -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html"/>
<xsl:output method="xml"/>
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" href="resource:///res/xml/XMLPrettyPrint.css"/>
<script><![CDATA[
function clicked(event) {
try {
var par = event.target.parentNode;
if (par.nodeName == 'td' && par.className == 'expander') {
if (par.parentNode.className == 'expander-closed') {
par.parentNode.className = '';
event.target.data = '-';
}
else {
par.parentNode.className = 'expander-closed';
event.target.data = '+';
}
}
} catch (e) {
}
}
]]></script>
</head>
<body onclick="clicked(event)">
<div id="header">
<p>
This XML file does not appear to have any style information
associated with it. The document tree is shown below.
</p>
</div>
<xsl:apply-templates/>
</body>
</html>
<div>
<link href="chrome://communicator/content/xml/XMLPrettyPrint.css" type="text/css" rel="stylesheet"/>
<div id="header">
<p>
This XML file does not appear to have any style information
associated with it. The document tree is shown below.
</p>
</div>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="*">
<div class="indent">
<span class="markup">&lt;</span>
<span class="elemname"><xsl:value-of select="name(.)"/></span>
<span class="start-tag"><xsl:value-of select="name(.)"/></span>
<xsl:apply-templates select="@*"/>
<span class="markup">/&gt;</span>
</div>
@ -87,14 +67,14 @@ function clicked(event) {
<xsl:template match="*[node()]">
<div class="indent">
<span class="markup">&lt;</span>
<span class="elemname"><xsl:value-of select="name(.)"/></span>
<span class="start-tag"><xsl:value-of select="name(.)"/></span>
<xsl:apply-templates select="@*"/>
<span class="markup">&gt;</span>
<span class="text"><xsl:value-of select="."/></span>
<span class="markup">&lt;/</span>
<span class="elemname"><xsl:value-of select="name(.)"/></span>
<span class="end-tag"><xsl:value-of select="name(.)"/></span>
<span class="markup">&gt;</span>
</div>
</xsl:template>
@ -102,17 +82,17 @@ function clicked(event) {
<xsl:template match="*[* or processing-instruction() or comment() or string-length(.) &gt; 50]">
<table>
<tr>
<td class="expander">-<div/></td>
<xsl:call-template name="expander"/>
<td>
<span class="markup">&lt;</span>
<span class="elemname"><xsl:value-of select="name(.)"/></span>
<span class="start-tag"><xsl:value-of select="name(.)"/></span>
<xsl:apply-templates select="@*"/>
<span class="markup">&gt;</span>
<div class="expander-content"><xsl:apply-templates/></div>
<span class="markup">&lt;/</span>
<span class="elemname"><xsl:value-of select="name(.)"/></span>
<span class="end-tag"><xsl:value-of select="name(.)"/></span>
<span class="markup">&gt;</span>
</td>
</tr>
@ -121,10 +101,9 @@ function clicked(event) {
<xsl:template match="@*">
<xsl:text> </xsl:text>
<span class="attrname"><xsl:value-of select="name(.)"/></span>
<span class="markup">="</span>
<span class="attrvalue"><xsl:value-of select="."/></span>
<span class="markup">"</span>
<span class="attribute-name"><xsl:value-of select="name(.)"/></span>
<span class="markup">=</span>
<span class="attribute-value">"<xsl:value-of select="."/>"</span>
</xsl:template>
<xsl:template match="text()">
@ -135,16 +114,18 @@ function clicked(event) {
<xsl:template match="processing-instruction()">
<div class="indent pi">
&lt;?<xsl:value-of select="name(.)"/>
<xsl:text>&lt;?</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>?&gt;
<xsl:value-of select="."/>
<xsl:text>?&gt;</xsl:text>
</div>
</xsl:template>
<xsl:template match="processing-instruction()[string-length(.) &gt; 50]">
<table>
<tr>
<td class="expander">-<div/></td>
<xsl:call-template name="expander"/>
<td class="pi">
&lt;?<xsl:value-of select="name(.)"/>
<div class="indent expander-content"><xsl:value-of select="."/></div>
@ -156,23 +137,27 @@ function clicked(event) {
<xsl:template match="comment()">
<div class="comment indent">
&lt;!--
<xsl:text>&lt;!--</xsl:text>
<xsl:value-of select="."/>
--&gt;
<xsl:text>--&gt;</xsl:text>
</div>
</xsl:template>
<xsl:template match="comment()[string-length(.) &gt; 50]">
<table>
<tr>
<td class="expander">-<div/></td>
<xsl:call-template name="expander"/>
<td class="comment">
&lt;!--
<xsl:text>&lt;!--</xsl:text>
<div class="indent expander-content"><xsl:value-of select="."/></div>
<xsl:text>--&gt;</xsl:text>
</td>
</tr>
</table>
</xsl:template>
<xsl:template name="expander">
<td class="expander"><img src="chrome://global/skin/tree/twisty-open.gif"/><div class="spacer"/></td>
</xsl:template>
</xsl:stylesheet>

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

@ -0,0 +1,4 @@
comm.jar:
content/communicator/xml/XMLPrettyPrint.css (XMLPrettyPrint.css)
content/communicator/xml/XMLPrettyPrint.xml (XMLPrettyPrint.xml)
content/communicator/xml/XMLPrettyPrint.xsl (XMLPrettyPrint.xsl)

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

@ -114,6 +114,10 @@
#include "nsXBLAtoms.h"
#include "nsIPref.h"
#include "nsIDOMDocumentXBL.h"
#include "nsIBindingManager.h"
#include "nsIObserver.h"
#include "nsIDocumentTransformer.h"
#include "nsISyncLoadDOMService.h"
// XXX misnamed header file, but oh well
#include "nsHTMLTokens.h"
@ -122,6 +126,7 @@ static char kNameSpaceSeparator = ':';
#define kXSLType "text/xsl"
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
nsINameSpaceManager* nsXMLContentSink::gNameSpaceManager = nsnull;
PRUint32 nsXMLContentSink::gRefCnt = 0;
@ -346,14 +351,14 @@ nsXMLContentSink::ScrollToRef()
}
}
PRBool
nsXMLContentSink::ShouldPrettyPrint()
nsresult
nsXMLContentSink::MaybePrettyPrint()
{
if (!mPrettyPrintXML || (mPrettyPrintHasFactoredElements &&
!mPrettyPrintHasSpecialRoot)) {
mPrettyPrintXML = PR_FALSE;
return PR_FALSE;
return NS_OK;
}
// Check for correct load-command or if we're in a display:none iframe
@ -363,7 +368,7 @@ nsXMLContentSink::ShouldPrettyPrint()
!mDocument->GetNumberOfShells()) {
mPrettyPrintXML = PR_FALSE;
return PR_FALSE;
return NS_OK;
}
// check if we're in an invisible iframe
@ -396,7 +401,7 @@ nsXMLContentSink::ShouldPrettyPrint()
if (!visibility.Equals(NS_LITERAL_STRING("visible"))) {
mPrettyPrintXML = PR_FALSE;
return PR_FALSE;
return NS_OK;
}
}
}
@ -409,11 +414,69 @@ nsXMLContentSink::ShouldPrettyPrint()
if (!pref) {
mPrettyPrintXML = PR_FALSE;
return PR_FALSE;
return NS_OK;
}
}
return PR_TRUE;
// Ok, we should prettyprint. Let's do it!
nsresult rv = NS_OK;
// Load the XSLT
nsCOMPtr<nsIURI> xslUri;
rv = NS_NewURI(getter_AddRefs(xslUri),
NS_LITERAL_CSTRING("chrome://communicator/content/xml/XMLPrettyPrint.xsl"));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel), xslUri, nsnull, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMDocument> xslDocument;
nsCOMPtr<nsISyncLoadDOMService> loader =
do_GetService("@mozilla.org/content/syncload-dom-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = loader->LoadLocalDocument(channel, nsnull, getter_AddRefs(xslDocument));
NS_ENSURE_SUCCESS(rv, rv);
// Transform the document
nsCOMPtr<nsIDocumentTransformer> transformer =
do_CreateInstance("@mozilla.org/document-transformer;1?type=text/xsl", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMDocument> resultDocument;
nsAutoString emptyStr;
rv = NS_NewDOMDocument(getter_AddRefs(resultDocument), emptyStr, emptyStr,
nsnull, mDocumentURL);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMDocument> sourceDocument = do_QueryInterface(mDocument);
rv = transformer->TransformDocument(sourceDocument, xslDocument,
resultDocument, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
// Add the binding
nsCOMPtr<nsIDOMDocumentXBL> xblDoc = do_QueryInterface(mDocument);
NS_ASSERTION(xblDoc, "xml document doesn't implement nsIDOMDocumentXBL");
NS_ENSURE_TRUE(xblDoc, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMDocument> dummy;
xblDoc->LoadBindingDocument(NS_LITERAL_STRING("chrome://communicator/content/xml/XMLPrettyPrint.xml"), getter_AddRefs(dummy));
nsCOMPtr<nsIDOMElement> rootElem = do_QueryInterface(mDocElement);
NS_ASSERTION(rootElem, "No root element");
rv = xblDoc->AddBinding(rootElem, NS_LITERAL_STRING("chrome://communicator/content/xml/XMLPrettyPrint.xml#prettyprint"));
NS_ENSURE_SUCCESS(rv, rv);
// Hand the result document to the binding
nsCOMPtr<nsIBindingManager> manager;
mDocument->GetBindingManager(getter_AddRefs(manager));
nsCOMPtr<nsIObserver> binding;
manager->GetBindingImplementation(mDocElement, NS_GET_IID(nsIObserver), (void**)getter_AddRefs(binding));
NS_ASSERTION(binding, "Prettyprint binding doesn't implement nsIObserver");
NS_ENSURE_TRUE(binding, NS_ERROR_UNEXPECTED);
return binding->Observe(resultDocument, "prettyprint-dom-created", NS_LITERAL_STRING("").get());
}
@ -446,15 +509,7 @@ nsXMLContentSink::DidBuildModel(PRInt32 aQualityLevel)
mDocument->SetRootContent(mDocElement);
// Check if we want to prettyprint
if (ShouldPrettyPrint()) {
NS_ASSERTION(!mXSLTransformMediator, "Prettyprinting an XSLT styled document");
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri),
NS_LITERAL_STRING("resource:///res/xml/XMLPrettyPrint.xsl"));
NS_ENSURE_SUCCESS(rv, rv);
LoadXSLStyleSheet(uri);
}
MaybePrettyPrint();
if (mXSLTransformMediator) {
rv = SetupTransformMediator();

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

@ -173,7 +173,7 @@ protected:
void ScrollToRef();
PRBool ShouldPrettyPrint();
nsresult MaybePrettyPrint();
static nsINameSpaceManager* gNameSpaceManager;
static PRUint32 gRefCnt;

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

@ -28,7 +28,7 @@ include $(DEPTH)/config/autoconf.mk
DIRS = source
ifndef TX_EXE
DIRS += build public
DIRS += build
endif
include $(topsrcdir)/config/rules.mk

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

@ -112,7 +112,6 @@ LOBJS =../source/base/ArrayList.$(OBJ_SUFFIX) \
../source/xml/XMLUtils.$(OBJ_SUFFIX) \
../source/xml/XMLDOMUtils.$(OBJ_SUFFIX) \
../source/xml/parser/XMLParser.$(OBJ_SUFFIX) \
../source/xml/parser/nsSyncLoader.$(OBJ_SUFFIX) \
../source/xslt/txOutputFormat.$(OBJ_SUFFIX) \
../source/xslt/Names.$(OBJ_SUFFIX) \
../source/xslt/ProcessorState.$(OBJ_SUFFIX) \

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

@ -29,7 +29,6 @@
#include "nsIGenericFactory.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIServiceManager.h"
#include "nsSyncLoader.h"
#include "nsXPathEvaluator.h"
#include "nsXPathException.h"
#include "nsXPathExpression.h"
@ -89,7 +88,6 @@ NS_DOMCI_EXTENSION_END
// Factory Constructor
NS_GENERIC_FACTORY_CONSTRUCTOR(XSLTProcessor)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPathEvaluator)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSyncLoader)
NS_DECL_DOM_CLASSINFO(XSLTProcessor)
NS_DECL_DOM_CLASSINFO(XPathEvaluator)
@ -253,10 +251,6 @@ static const nsModuleComponentInfo gComponents[] = {
TRANSFORMIIX_XPATH_EVALUATOR_CID,
NS_XPATH_EVALUATOR_CONTRACTID,
nsXPathEvaluatorConstructor },
{ "Transformiix Synchronous Loader",
TRANSFORMIIX_SYNCLOADER_CID,
TRANSFORMIIX_SYNCLOADER_CONTRACTID,
nsSyncLoaderConstructor },
{ "Transformiix DOMCI Extender",
TRANSFORMIIX_DOMCI_EXTENSION_CID,
TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID,

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

@ -1405,13 +1405,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoader.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -1921,11 +1914,6 @@
<PATH>DocumentFunctionCall.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoader.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -3377,13 +3365,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoader.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -3901,11 +3882,6 @@
<PATH>DocumentFunctionCall.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoader.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -4212,12 +4188,6 @@
</FILEREF>
</GROUP>
<GROUP><NAME>parser</NAME>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsSyncLoader.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

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

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

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

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

@ -45,9 +45,6 @@ REQUIRES = expat \
endif
CPPSRCS = XMLParser.cpp
ifndef TX_EXE
CPPSRCS += nsSyncLoader.cpp
endif
include $(topsrcdir)/config/rules.mk

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

@ -41,7 +41,7 @@
#ifndef TX_EXE
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsSyncLoader.h"
#include "nsISyncLoadDOMService.h"
#include "nsNetUtil.h"
#else
#include "xmlparse.h"
@ -72,14 +72,24 @@ Document* XMLParser::getDocumentFromURI(const String& href,
#ifndef TX_EXE
nsCOMPtr<nsIURI> documentURI;
nsresult rv = NS_NewURI(getter_AddRefs(documentURI), href);
NS_ENSURE_SUCCESS(rv, NULL);
nsCOMPtr<nsISyncLoader> loader = do_CreateInstance(TRANSFORMIIX_SYNCLOADER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, NULL);
NS_ENSURE_SUCCESS(rv, 0);
nsCOMPtr<nsIDOMDocument> theDocument;
nsCOMPtr<nsIDocument> loaderDocument = do_QueryInterface(aLoader->getNSObj());
rv = loader->LoadDocument(documentURI, loaderDocument, getter_AddRefs(theDocument));
nsCOMPtr<nsILoadGroup> loadGroup;
nsCOMPtr<nsIURI> loaderUri;
loaderDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
loaderDocument->GetDocumentURL(getter_AddRefs(loaderUri));
NS_ENSURE_TRUE(loaderUri, 0);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel), documentURI, nsnull, loadGroup);
NS_ENSURE_SUCCESS(rv, 0);
nsCOMPtr<nsISyncLoadDOMService> loader =
do_GetService("@mozilla.org/content/syncload-dom-service;1", &rv);
NS_ENSURE_SUCCESS(rv, 0);
rv = loader->LoadDocument(channel, loaderUri, getter_AddRefs(theDocument));
if (NS_FAILED(rv) || !theDocument) {
errMsg.append("Document load of ");
errMsg.append(href);

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

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

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

@ -293,7 +293,6 @@ viewer:res:cmessage.txt
viewer:res:samples:sampleimages
viewer:res:builtin:htmlBindings.xml
viewer:res:builtin:platformHTMLBindings.xml
viewer:res:xml:*
-viewer:res:samples:.cvsignore
-viewer:res:samples:Makefile.in

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

@ -342,7 +342,6 @@ bin/res/throbber/*
bin/res/samples/*
bin/res/builtin/htmlBindings.xml
bin/res/builtin/platformHTMLBindings.xml
bin/res/xml/*
[mail]
bin/msgbsutl.dll

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

@ -231,7 +231,6 @@ bin/res/dtd/*
bin/res/samples/*
bin/res/builtin/htmlBindings.xml
bin/res/builtin/platformHTMLBindings.xml
bin/res/xml/*
[mail]

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

@ -260,7 +260,6 @@ bin\res\throbber\*
bin\res\samples\*
bin\res\builtin\htmlBindings.xml
bin\res\builtin\platformHTMLBindings.xml
bin\res\xml\*
[mail]
bin\components\mail.dll

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

@ -309,7 +309,6 @@ bin/res/dtd/*
bin/res/samples/*
bin/res/builtin/htmlBindings.xml
bin/res/builtin/platformHTMLBindings.xml
bin/res/xml/*
[mail]

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

@ -332,7 +332,6 @@ bin\res\throbber\*
bin\res\samples\*
bin\res\builtin\htmlBindings.xml
bin\res\builtin\platformHTMLBindings.xml
bin\res\xml\*
[mail]
bin\msgbsutl.dll