From 6d9c1486db160ead4abbddd424300fc7b16e8185 Mon Sep 17 00:00:00 2001 From: "peterv%netscape.com" Date: Thu, 20 Jun 2002 12:04:22 +0000 Subject: [PATCH] Fix for bug 142108 (Crash when reloading XML+XSLT Trunk, M100, N70PR1, M11A [@ nsXMLContentSink::Observe][@ 0x00000001]). r=Pike, sr=jst. --- build/mac/build_scripts/MozillaBuildList.pm | 3 +- config/module2dir.pl | 1 - content/base/public/nsIDocumentViewer.h | 3 - content/base/src/Makefile.in | 1 - content/base/src/makefile.win | 120 ------------ content/base/src/nsDocumentViewer.cpp | 18 +- content/macbuild/contentIDL.xml | 34 +++- content/xml/document/src/nsXMLContentSink.cpp | 172 +++++++----------- content/xml/document/src/nsXMLContentSink.h | 11 +- content/xsl/document/Makefile.in | 2 +- content/xsl/document/makefile.win | 26 --- .../{src/MANIFEST_IDL => public/.cvsignore} | 0 .../MANIFEST} | 0 .../MANIFEST_IDL} | 0 content/xsl/document/public/Makefile.in | 0 content/xsl/document/public/makefile.win | 0 .../public/nsIDocumentTransformer.idl | 0 .../document/public/nsITransformMediator.h | 0 .../document/public/nsITransformObserver.idl | 0 content/xsl/document/src/Makefile.in | 10 +- content/xsl/document/src/makefile.win | 14 +- .../xsl/document/src/nsTransformMediator.cpp | 42 ++--- .../xsl/document/src/nsTransformMediator.h | 15 +- content/xsl/document/src/nsXSLContentSink.cpp | 35 ++-- extensions/transformiix/build/Makefile.in | 1 - extensions/transformiix/build/makefile.win | 1 - .../transformiix/source/xslt/Makefile.in | 1 - .../source/xslt/XSLTProcessor.cpp | 29 +-- .../transformiix/source/xslt/XSLTProcessor.h | 6 +- .../transformiix/source/xslt/makefile.win | 1 - layout/base/nsDocumentViewer.cpp | 18 +- layout/base/nsIDocumentViewer.h | 3 - xpinstall/packager/packages-static-unix | 2 +- xpinstall/packager/packages-static-win | 2 +- xpinstall/packager/packages-unix | 2 +- xpinstall/packager/packages-win | 2 +- 36 files changed, 178 insertions(+), 397 deletions(-) rename content/xsl/document/{src/MANIFEST_IDL => public/.cvsignore} (100%) rename content/xsl/document/{src/nsIDocumentTransformer.idl => public/MANIFEST} (100%) rename content/xsl/document/{src/nsITransformMediator.h => public/MANIFEST_IDL} (100%) create mode 100644 content/xsl/document/public/Makefile.in create mode 100644 content/xsl/document/public/makefile.win create mode 100644 content/xsl/document/public/nsIDocumentTransformer.idl create mode 100644 content/xsl/document/public/nsITransformMediator.h create mode 100644 content/xsl/document/public/nsITransformObserver.idl diff --git a/build/mac/build_scripts/MozillaBuildList.pm b/build/mac/build_scripts/MozillaBuildList.pm index 6d65ac718d6..48a9f300014 100644 --- a/build/mac/build_scripts/MozillaBuildList.pm +++ b/build/mac/build_scripts/MozillaBuildList.pm @@ -941,7 +941,8 @@ sub BuildClientDist() InstallFromManifest(":mozilla:content:xbl:public:MANIFEST", "$distdirectory:content:"); InstallFromManifest(":mozilla:content:xml:content:public:MANIFEST", "$distdirectory:content:"); InstallFromManifest(":mozilla:content:xml:document:public:MANIFEST", "$distdirectory:content:"); - InstallFromManifest(":mozilla:content:xsl:document:src:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:content:xsl:document:public:MANIFEST", "$distdirectory:content:"); + InstallFromManifest(":mozilla:content:xsl:document:public:MANIFEST_IDL", "$distdirectory:idl:"); InstallFromManifest(":mozilla:content:xul:content:public:MANIFEST", "$distdirectory:content:"); InstallFromManifest(":mozilla:content:xul:document:public:MANIFEST", "$distdirectory:content:"); InstallFromManifest(":mozilla:content:xul:document:public:MANIFEST_IDL", "$distdirectory:idl:"); diff --git a/config/module2dir.pl b/config/module2dir.pl index f81261b57f5..6d1998aa523 100755 --- a/config/module2dir.pl +++ b/config/module2dir.pl @@ -40,7 +40,6 @@ my %map = ( 'commandhandler', 'embedding/components/commandhandler', 'composer', 'editor/composer', 'content', 'content', - 'content_xsl', 'content/xsl/document', 'cookie', 'extensions/cookie', 'ctl', 'extensions/ctl', 'dbm', 'dbm', diff --git a/content/base/public/nsIDocumentViewer.h b/content/base/public/nsIDocumentViewer.h index 4dfb623de81..058c6dc8dd9 100644 --- a/content/base/public/nsIDocumentViewer.h +++ b/content/base/public/nsIDocumentViewer.h @@ -44,7 +44,6 @@ class nsIDocument; class nsIPresContext; class nsIPresShell; class nsIStyleSheet; -class nsITransformMediator; #define NS_IDOCUMENT_VIEWER_IID \ { 0xa6cf9057, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} @@ -68,8 +67,6 @@ public: NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, nsIDocumentViewer*& aResult) = 0; - - NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator)=0; }; #endif /* nsIDocumentViewer_h___ */ diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index c38ba65576a..e260cccb050 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -49,7 +49,6 @@ REQUIRES = xpcom \ xpconnect \ util \ unicharutil \ - content_xsl \ xuldoc \ intl \ windowwatcher \ diff --git a/content/base/src/makefile.win b/content/base/src/makefile.win index 5b44dd33307..e69de29bb2d 100644 --- a/content/base/src/makefile.win +++ b/content/base/src/makefile.win @@ -1,120 +0,0 @@ -#!nmake -# -# The contents of this file are subject to the Netscape Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/NPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): - -DEPTH=..\..\.. - -LIBRARY_NAME=contentbase_s -DEFINES=-D_IMPL_NS_LAYOUT -DWIN32_LEAN_AND_MEAN -!if defined(XP_NEW_SELECTION) -DEFINES = $(DEFINES) -DXP_NEW_SELECTION -!endif - -MODULE=content -REQUIRES = xpcom \ - string \ - dom \ - widget \ - view \ - locale \ - htmlparser \ - js \ - webshell \ - necko \ - caps \ - lwbrk \ - uconv \ - chrome \ - docshell \ - uriloader \ - pref \ - xpconnect \ - util \ - unicharutil \ - layout \ - gfx \ - layout_xul \ - content_xsl \ - content_xul \ - windowwatcher \ - intl \ - imglib2 \ - gfx2 \ - uriloader \ - webBrowser_core\ - $(NULL) - -CPP_OBJS= \ - .\$(OBJDIR)\nsPrintPreviewListener.obj \ - .\$(OBJDIR)\nsStyleContext.obj \ - .\$(OBJDIR)\nsStyleSet.obj \ - .\$(OBJDIR)\nsCommentNode.obj \ - .\$(OBJDIR)\nsGenericDOMDataNode.obj \ - .\$(OBJDIR)\nsGenericDOMNodeList.obj \ - .\$(OBJDIR)\nsGenericElement.obj \ - .\$(OBJDIR)\nsContentList.obj \ - .\$(OBJDIR)\nsContentIterator.obj \ - .\$(OBJDIR)\nsContentPolicy.obj \ - .\$(OBJDIR)\nsDocument.obj \ - .\$(OBJDIR)\nsDocumentEncoder.obj \ - .\$(OBJDIR)\nsDocumentFragment.obj \ - .\$(OBJDIR)\nsDocumentViewer.obj \ - .\$(OBJDIR)\nsDOMAttribute.obj \ - .\$(OBJDIR)\nsDOMAttributeMap.obj \ - .\$(OBJDIR)\nsDOMDocumentType.obj \ - .\$(OBJDIR)\nsGeneratedIterator.obj \ - .\$(OBJDIR)\nsNameSpaceManager.obj \ - .\$(OBJDIR)\nsNodeInfo.obj \ - .\$(OBJDIR)\nsNodeInfoManager.obj \ - .\$(OBJDIR)\nsSelection.obj \ - .\$(OBJDIR)\nsRange.obj \ - .\$(OBJDIR)\nsRuleNode.obj \ - .\$(OBJDIR)\nsTextContentChangeData.obj \ - .\$(OBJDIR)\nsTextNode.obj \ - .\$(OBJDIR)\nsTreeWalker.obj \ - .\$(OBJDIR)\nsXMLContentSerializer.obj \ - .\$(OBJDIR)\nsHTMLContentSerializer.obj \ - .\$(OBJDIR)\nsParserUtils.obj \ - .\$(OBJDIR)\nsPlainTextSerializer.obj \ - .\$(OBJDIR)\mozSanitizingSerializer.obj \ - .\$(OBJDIR)\nsContentUtils.obj \ - .\$(OBJDIR)\nsScriptLoader.obj \ - .\$(OBJDIR)\nsStyleLinkElement.obj \ - .\$(OBJDIR)\nsContentAreaDragDrop.obj \ - .\$(OBJDIR)\nsFrameLoader.obj \ - $(NULL) - -LINCS=-I..\..\html\base\src -I..\..\html\style\src \ - -I..\..\xul\base\src -I..\..\xul\content\src \ - -I..\..\events\src -I..\..\html\content\src - -LCFLAGS = \ - $(LCFLAGS) \ - $(DEFINES) \ - $(NULL) - -include <$(DEPTH)\config\rules.mak> - -libs:: $(LIBRARY) - $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib - -clobber:: - rm -f $(DIST)\lib\$(LIBRARY_NAME).lib - rm -f $(PDBFILE).pdb diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 4bef747c2a9..14836311485 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -184,8 +184,6 @@ const char* kPrintingPromptService = "@mozilla.org/embedcomp/printingprompt-serv #include "nsIDOMFocusListener.h" #include "nsISelectionController.h" -#include "nsITransformMediator.h" - #ifdef IBMBIDI #include "nsBidiUtils.h" #endif @@ -511,7 +509,6 @@ public: NS_IMETHOD GetPresContext(nsIPresContext*& aResult); NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, nsIDocumentViewer*& aResult); - NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator); // nsIContentViewerEdit NS_DECL_NSICONTENTVIEWEREDIT @@ -698,9 +695,8 @@ protected: nsISupports* mContainer; // [WEAK] it owns me! nsCOMPtr mDeviceContext; // ??? can't hurt, but... - // the following seven items are explicitly in this order + // the following six items are explicitly in this order // so they will be destroyed in the reverse order (pinkerton, scc) - nsCOMPtr mTransformMediator; nsCOMPtr mDocument; nsCOMPtr mWindow; // ??? should we really own it? nsCOMPtr mViewManager; @@ -1389,8 +1385,6 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, const nsRect& aBounds, PRBool aDoCreation) { - mTransformMediator = nsnull; - #ifdef NS_PRINT_PREVIEW mParentWidget = aParentWidget; // not ref counted #endif @@ -5343,16 +5337,6 @@ nsresult DocumentViewerImpl::DocumentReadyForPrinting() return rv; } -NS_IMETHODIMP -DocumentViewerImpl::SetTransformMediator(nsITransformMediator* aMediator) -{ - NS_ASSERTION(!mTransformMediator || !aMediator, - "nsXMLDocument::SetTransformMediator(): \ - Cannot set a second transform mediator\n"); - mTransformMediator = aMediator; - return NS_OK; -} - #ifdef XP_MAC #pragma mark - #endif diff --git a/content/macbuild/contentIDL.xml b/content/macbuild/contentIDL.xml index c1679539c79..0d8e32f0b8c 100644 --- a/content/macbuild/contentIDL.xml +++ b/content/macbuild/contentIDL.xml @@ -347,7 +347,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password25jysun5jyay2Ù±ÀÑ“( + MWFTP_Post_password0 MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -897,6 +897,13 @@ Text + + Name + nsITransformObserver.idl + MacOS + Text + + @@ -1004,6 +1011,11 @@ nsIDragDropOverride.idl MacOS + + Name + nsITransformObserver.idl + MacOS + @@ -1300,7 +1312,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password25jysun5jyay2Ù±ÀÑ“( + MWFTP_Post_password0 MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -1850,6 +1862,13 @@ Text + + Name + nsITransformObserver.idl + MacOS + Text + + @@ -1957,6 +1976,11 @@ nsIDragDropOverride.idl MacOS + + Name + nsITransformObserver.idl + MacOS + @@ -2093,6 +2117,12 @@ nsIDragDropOverride.idl MacOS + + headers + Name + nsITransformObserver.idl + MacOS + diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index dde5f9017df..98e71e26482 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -88,7 +88,6 @@ #include "nsXSLContentSink.h" #include "nsParserCIID.h" #include "nsParserUtils.h" -#include "nsIDocumentViewer.h" #include "nsIScrollable.h" #include "nsRect.h" #include "nsGenericElement.h" @@ -260,7 +259,7 @@ NS_INTERFACE_MAP_BEGIN(nsXMLContentSink) NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink) NS_INTERFACE_MAP_ENTRY(nsIContentSink) NS_INTERFACE_MAP_ENTRY(nsIExpatSink) - NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsITransformObserver) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIScriptLoaderObserver) NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) @@ -362,13 +361,14 @@ nsXMLContentSink::DidBuildModel(PRInt32 aQualityLevel) rv = SetupTransformMediator(); } - nsCOMPtr loader; - mDocument->GetScriptLoader(getter_AddRefs(loader)); - if (loader) { - loader->RemoveObserver(this); - } - + // Kick off layout for non-XSLT transformed documents. if (!mXSLTransformMediator || NS_FAILED(rv)) { + nsCOMPtr loader; + mDocument->GetScriptLoader(getter_AddRefs(loader)); + if (loader) { + loader->RemoveObserver(this); + } + StartLayout(); #if 0 /* Disable until this works for XML */ @@ -392,7 +392,7 @@ nsXMLContentSink::DidBuildModel(PRInt32 aQualityLevel) // Do this hack to make sure that the parser // doesn't get destroyed, accidently, before // the circularity, between sink & parser, is - // actually borken. + // actually broken. nsCOMPtr kungFuDeathGrip(mParser); // Drop our reference to the parser to get rid of a circular @@ -402,88 +402,71 @@ nsXMLContentSink::DidBuildModel(PRInt32 aQualityLevel) return NS_OK; } -// The observe method is called on completion of the transform. The nsISupports argument is an -// nsIContent interface to the root node of the output content model. NS_IMETHODIMP -nsXMLContentSink::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData) +nsXMLContentSink::OnTransformDone(nsresult aResult, + nsIDOMDocument* aResultDocument) { - nsresult rv = NS_OK; + NS_ASSERTION(NS_FAILED(aResult) || aResultDocument, + "Don't notify about transform success without a document."); - if (!nsCRT::strcmp(aTopic, "xslt-done")) { - nsCOMPtr docShell(do_QueryInterface(mWebShell)); - nsCOMPtr contentViewer; - docShell->GetContentViewer(getter_AddRefs(contentViewer)); + // Reset the observer on the transform mediator + mXSLTransformMediator->SetTransformObserver(nsnull); - // Set the output content model on the document - nsCOMPtr content = do_QueryInterface(aSubject, &rv); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr resultDOMDoc; - mXSLTransformMediator->GetResultDocument(getter_AddRefs(resultDOMDoc)); - nsCOMPtr resultDoc = do_QueryInterface(resultDOMDoc); + nsCOMPtr docShell(do_QueryInterface(mWebShell)); + nsCOMPtr contentViewer; + docShell->GetContentViewer(getter_AddRefs(contentViewer)); - nsCOMPtr sourceDoc = mDocument; - NS_RELEASE(mDocument); - - mDocument = resultDoc; - NS_ADDREF(mDocument); - nsCOMPtr root; - mDocument->GetRootContent(getter_AddRefs(root)); - if (!root) - mDocument->SetRootContent(content); - - // Reset the observer on the transform mediator - mXSLTransformMediator->SetTransformObserver(nsnull); - - // Start the layout process - StartLayout(); - -#if 0 /* Disable until this works for XML */ - // Scroll to Anchor only if the document was *not* loaded through history means. - PRUint32 documentLoadType = 0; - docShell->GetLoadType(&documentLoadType); - if (!(documentLoadType & nsIDocShell::LOAD_CMD_HISTORY)) { - ScrollToRef(); - } -#else - ScrollToRef(); -#endif - - sourceDoc->EndLoad(); - - if (contentViewer) { - contentViewer->LoadComplete(NS_OK); - } + if (NS_FAILED(aResult) && contentViewer) { + // Transform failed. + if (aResultDocument) { + // We have an error document. + contentViewer->SetDOMDocument(aResultDocument); } - else - { - // Transform failed - nsCOMPtr documentViewer(do_QueryInterface(contentViewer)); - if (documentViewer) { - documentViewer->SetTransformMediator(nsnull); - } - - mDocument->SetRootContent(mDocElement); - - // Start the layout process - StartLayout(); - -#if 0 /* Disable until this works for XML */ - // Scroll to Anchor only if the document was *not* loaded through history means. - PRUint32 documentLoadType = 0; - docShell->GetLoadType(&documentLoadType); - if (!(documentLoadType & nsIDocShell::LOAD_CMD_HISTORY)) { - ScrollToRef(); - } -#else - ScrollToRef(); -#endif - - mDocument->EndLoad(); + else { + // We don't have an error document, display the + // untransformed source document. + nsCOMPtr document = do_QueryInterface(mDocument); + contentViewer->SetDOMDocument(document); } - - mXSLTransformMediator = nsnull; } - return rv; + + nsCOMPtr originalDocument = mDocument; + if (NS_SUCCEEDED(aResult) || aResultDocument) { + // Transform succeeded or it failed and we have an error + // document to display. + NS_RELEASE(mDocument); + CallQueryInterface(aResultDocument, &mDocument); // addrefs + } + else + { + // Transform failed and we don't have an error document, display the + // untransformed source document. + mDocument->SetRootContent(mDocElement); + } + + nsCOMPtr loader; + originalDocument->GetScriptLoader(getter_AddRefs(loader)); + if (loader) { + loader->RemoveObserver(this); + } + + // Start the layout process + StartLayout(); + +#if 0 /* Disable until this works for XML */ + // Scroll to Anchor only if the document was *not* loaded through history means. + PRUint32 documentLoadType = 0; + docShell->GetLoadType(&documentLoadType); + if (!(documentLoadType & nsIDocShell::LOAD_CMD_HISTORY)) { + ScrollToRef(); + } +#else + ScrollToRef(); +#endif + + originalDocument->EndLoad(); + + return NS_OK; } @@ -512,13 +495,10 @@ nsXMLContentSink::SetupTransformMediator() rv = NS_NewDOMDocument(getter_AddRefs(resultDOMDoc), emptyStr, emptyStr, nsnull, url); if (NS_FAILED(rv)) return rv; - nsCOMPtr resultXMLDoc(do_QueryInterface(resultDOMDoc)); - resultXMLDoc->SetDefaultStylesheets(url); - nsCOMPtr docShell(do_QueryInterface(mWebShell)); nsCOMPtr contentViewer; - rv = docShell->GetContentViewer(getter_AddRefs(contentViewer)); - if (NS_SUCCEEDED(rv) && contentViewer) { + docShell->GetContentViewer(getter_AddRefs(contentViewer)); + if (contentViewer) { contentViewer->SetDOMDocument(resultDOMDoc); } @@ -651,15 +631,6 @@ nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl) // this state by calling the various setters on nsITransformMediator. mXSLTransformMediator->SetEnabled(PR_TRUE); - // The document viewer owns the transform mediator. - nsCOMPtr docShell(do_QueryInterface(mWebShell)); - nsCOMPtr contentViewer; - rv = docShell->GetContentViewer(getter_AddRefs(contentViewer)); - nsCOMPtr documentViewer(do_QueryInterface(contentViewer)); - if (documentViewer) { - documentViewer->SetTransformMediator(mXSLTransformMediator); - } - // Create the XSL stylesheet document nsCOMPtr styleDOMDoc; nsAutoString emptyStr; @@ -1972,13 +1943,6 @@ nsXMLContentSink::ReportError(const PRUnichar* aErrorText, if (mXSLTransformMediator) { // Get rid of the transform mediator. - nsCOMPtr docShell(do_QueryInterface(mWebShell)); - nsCOMPtr contentViewer; - rv = docShell->GetContentViewer(getter_AddRefs(contentViewer)); - nsCOMPtr documentViewer(do_QueryInterface(contentViewer)); - if (documentViewer) { - documentViewer->SetTransformMediator(nsnull); - } mXSLTransformMediator->SetEnabled(PR_FALSE); mXSLTransformMediator = nsnull; } diff --git a/content/xml/document/src/nsXMLContentSink.h b/content/xml/document/src/nsXMLContentSink.h index 41e7d5f2f4a..f2b4c1c17ed 100644 --- a/content/xml/document/src/nsXMLContentSink.h +++ b/content/xml/document/src/nsXMLContentSink.h @@ -42,7 +42,6 @@ #include "nsIXMLContentSink.h" #include "nsIViewManager.h" #include "nsIScrollableView.h" -#include "nsIObserver.h" #include "nsWeakReference.h" #include "nsITransformMediator.h" #include "nsIUnicharInputStream.h" @@ -58,6 +57,7 @@ class nsICSSStyleSheet; #include "nsIScriptLoaderObserver.h" #include "nsSupportsArray.h" #include "nsIExpatSink.h" +#include "nsITransformObserver.h" class nsIDocument; class nsIURI; @@ -81,7 +81,7 @@ typedef enum { // XXX Till the parser knows a little bit more about XML, // this is a HTMLContentSink. class nsXMLContentSink : public nsIXMLContentSink, - public nsIObserver, + public nsITransformObserver, public nsSupportsWeakReference, public nsIScriptLoaderObserver, public nsICSSLoaderObserver, @@ -99,7 +99,7 @@ public: // nsISupports NS_DECL_ISUPPORTS NS_DECL_NSISCRIPTLOADEROBSERVER - + NS_DECL_NSITRANSFORMOBSERVER NS_DECL_NSIEXPATSINK // nsIContentSink @@ -114,11 +114,6 @@ public: // nsICSSLoaderObserver NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet*aSheet, PRBool aNotify); - // nsIObserver - NS_IMETHOD Observe(nsISupports *aSubject, - const char *aTopic, - const PRUnichar *someData); - protected: void StartLayout(); diff --git a/content/xsl/document/Makefile.in b/content/xsl/document/Makefile.in index e98c66370c1..b120f610dea 100755 --- a/content/xsl/document/Makefile.in +++ b/content/xsl/document/Makefile.in @@ -21,7 +21,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = src +DIRS = public src include $(topsrcdir)/config/config.mk diff --git a/content/xsl/document/makefile.win b/content/xsl/document/makefile.win index 841cfcbc222..e69de29bb2d 100644 --- a/content/xsl/document/makefile.win +++ b/content/xsl/document/makefile.win @@ -1,26 +0,0 @@ -#!nmake -# -# The contents of this file are subject to the Netscape Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/NPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): - -DEPTH=..\..\.. - -DIRS=src - -include <$(DEPTH)\config\rules.mak> diff --git a/content/xsl/document/src/MANIFEST_IDL b/content/xsl/document/public/.cvsignore similarity index 100% rename from content/xsl/document/src/MANIFEST_IDL rename to content/xsl/document/public/.cvsignore diff --git a/content/xsl/document/src/nsIDocumentTransformer.idl b/content/xsl/document/public/MANIFEST similarity index 100% rename from content/xsl/document/src/nsIDocumentTransformer.idl rename to content/xsl/document/public/MANIFEST diff --git a/content/xsl/document/src/nsITransformMediator.h b/content/xsl/document/public/MANIFEST_IDL similarity index 100% rename from content/xsl/document/src/nsITransformMediator.h rename to content/xsl/document/public/MANIFEST_IDL diff --git a/content/xsl/document/public/Makefile.in b/content/xsl/document/public/Makefile.in new file mode 100644 index 00000000000..e69de29bb2d diff --git a/content/xsl/document/public/makefile.win b/content/xsl/document/public/makefile.win new file mode 100644 index 00000000000..e69de29bb2d diff --git a/content/xsl/document/public/nsIDocumentTransformer.idl b/content/xsl/document/public/nsIDocumentTransformer.idl new file mode 100644 index 00000000000..e69de29bb2d diff --git a/content/xsl/document/public/nsITransformMediator.h b/content/xsl/document/public/nsITransformMediator.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/content/xsl/document/public/nsITransformObserver.idl b/content/xsl/document/public/nsITransformObserver.idl new file mode 100644 index 00000000000..e69de29bb2d diff --git a/content/xsl/document/src/Makefile.in b/content/xsl/document/src/Makefile.in index 87115a00656..205b99e96f1 100755 --- a/content/xsl/document/src/Makefile.in +++ b/content/xsl/document/src/Makefile.in @@ -22,7 +22,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -MODULE = content_xsl +MODULE = content LIBRARY_NAME = gkconxsldoc_s REQUIRES = xpcom \ string \ @@ -44,19 +44,11 @@ ifeq ($(OS_ARCH),WINNT) DEFINES += -DWIN32_LEAN_AND_MEAN endif -XPIDLSRCS= \ - nsIDocumentTransformer.idl \ - $(NULL) - CPPSRCS = \ nsXSLContentSink.cpp \ nsTransformMediator.cpp \ $(NULL) -EXPORTS = \ - nsITransformMediator.h \ - $(NULL) - LOCAL_INCLUDES = \ -I$(srcdir)/../../../xml/document/src \ $(NULL) diff --git a/content/xsl/document/src/makefile.win b/content/xsl/document/src/makefile.win index 1b33815e501..6638979308a 100644 --- a/content/xsl/document/src/makefile.win +++ b/content/xsl/document/src/makefile.win @@ -21,9 +21,10 @@ DEPTH=..\..\..\.. -LIBRARY_NAME=contentxsldoc_s -MODULE=content_xsl -REQUIRES = xpcom \ +LIBRARY_NAME = contentxsldoc_s +MODULE = content + +REQUIRES = xpcom \ string \ htmlparser \ view \ @@ -37,18 +38,11 @@ REQUIRES = xpcom \ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN -XPIDLSRCS= .\nsIDocumentTransformer.idl \ - $(NULL) - CPP_OBJS= \ .\$(OBJDIR)\nsXSLContentSink.obj \ .\$(OBJDIR)\nsTransformMediator.obj \ $(NULL) -EXPORTS = \ - nsITransformMediator.h \ - $(NULL) - LINCS= -I..\..\..\html\style\src -I..\..\..\html\base\src \ -I..\..\..\html\content\src -I..\..\..\html\document\src \ -I..\..\..\xul\content\src -I..\..\..\xml\document\src \ diff --git a/content/xsl/document/src/nsTransformMediator.cpp b/content/xsl/document/src/nsTransformMediator.cpp index 8d10b0e5cf1..a4a225fba28 100644 --- a/content/xsl/document/src/nsTransformMediator.cpp +++ b/content/xsl/document/src/nsTransformMediator.cpp @@ -38,11 +38,6 @@ #include "nsTransformMediator.h" #include "nsIComponentManager.h" -#include "nsIContent.h" -#include "nsIDocument.h" -#include "nsIDOMElement.h" -#include "nsIServiceManagerUtils.h" -#include "nsObserverService.h" #include "nsString.h" nsresult @@ -102,37 +97,24 @@ NS_IMPL_ISUPPORTS1(nsTransformMediator, nsITransformMediator) void nsTransformMediator::TryToTransform() { - if (mSourceDOM && mStyleDOM && mResultDoc && mObserver) + nsCOMPtr observer = do_QueryReferent(mObserver); + if (mSourceDOM && mStyleDOM && mResultDoc && observer) { if (mEnabled && mTransformer) { mTransformer->TransformDocument(mSourceDOM, mStyleDOM, mResultDoc, - mObserver); + observer); } else if (mStyleInvalid) { - // Copy the error message from the stylesheet document to the result - // result document and notify the observer. - nsCOMPtr docElement; - mResultDoc->GetDocumentElement(getter_AddRefs(docElement)); - nsCOMPtr newRoot, root; - mResultDoc->ImportNode(mStyleDOM, PR_TRUE, getter_AddRefs(newRoot)); - if (docElement) { - nsCOMPtr origRoot; - root = newRoot; - mResultDoc->ReplaceChild(docElement, root, getter_AddRefs(origRoot)); - } - else { - mResultDoc->AppendChild(newRoot, getter_AddRefs(root)); - } + // Avoid recursion. + mStyleInvalid = PR_FALSE; - nsresult rv; - nsCOMPtr anObserverService = - do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - anObserverService->AddObserver(mObserver, "xslt-done", PR_TRUE); - anObserverService->NotifyObservers(root, "xslt-done", nsnull); - } + // Notify the observer with the stylesheet which contains + // the error message. + nsCOMPtr errorDoc; + mStyleDOM->GetOwnerDocument(getter_AddRefs(errorDoc)); + observer->OnTransformDone(NS_ERROR_FAILURE, errorDoc); } } } @@ -179,9 +161,9 @@ nsTransformMediator::GetResultDocument(nsIDOMDocument** aDoc) } NS_IMETHODIMP -nsTransformMediator::SetTransformObserver(nsIObserver* aObserver) +nsTransformMediator::SetTransformObserver(nsITransformObserver* aObserver) { - mObserver = aObserver; + mObserver = do_GetWeakReference(aObserver); TryToTransform(); return NS_OK; } diff --git a/content/xsl/document/src/nsTransformMediator.h b/content/xsl/document/src/nsTransformMediator.h index f13fb8d5582..8c631eba2e1 100644 --- a/content/xsl/document/src/nsTransformMediator.h +++ b/content/xsl/document/src/nsTransformMediator.h @@ -44,7 +44,8 @@ #include "nsIDocumentTransformer.h" #include "nsIDOMNode.h" #include "nsIDOMDocument.h" -#include "nsIObserver.h" +#include "nsITransformObserver.h" +#include "nsWeakPtr.h" class nsTransformMediator : public nsITransformMediator { public: @@ -62,7 +63,7 @@ public: NS_IMETHOD SetStyleSheetContentModel(nsIDOMNode* aStyle); NS_IMETHOD SetResultDocument(nsIDOMDocument* aDoc); NS_IMETHOD GetResultDocument(nsIDOMDocument** aDoc); - NS_IMETHOD SetTransformObserver(nsIObserver* aObserver); + NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver); NS_IMETHOD SetStyleInvalid(PRBool aInvalid); protected: @@ -70,11 +71,11 @@ protected: PRBool mEnabled; PRBool mStyleInvalid; - nsCOMPtr mTransformer; // Strong reference - nsCOMPtr mSourceDOM; // Strong reference - nsCOMPtr mStyleDOM; // Strong reference - nsCOMPtr mResultDoc; // Strong reference - nsCOMPtr mObserver; // Strong reference + nsCOMPtr mTransformer; + nsCOMPtr mSourceDOM; + nsCOMPtr mStyleDOM; + nsCOMPtr mResultDoc; + nsWeakPtr mObserver; }; #endif // nsTransformMediator_h__ diff --git a/content/xsl/document/src/nsXSLContentSink.cpp b/content/xsl/document/src/nsXSLContentSink.cpp index 51272058b8b..595f7800ddd 100644 --- a/content/xsl/document/src/nsXSLContentSink.cpp +++ b/content/xsl/document/src/nsXSLContentSink.cpp @@ -41,6 +41,7 @@ #include "nsIDocument.h" #include "nsIDOMDocument.h" #include "nsIDOMElement.h" +#include "nsILoadGroup.h" #include "nsIParser.h" #include "nsIStyleSheetLinkingElement.h" #include "nsITransformMediator.h" @@ -55,21 +56,17 @@ NS_NewXSLContentSink(nsIXMLContentSink** aResult, nsIURI* aURL, nsIWebShell* aWebShell) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_ENSURE_ARG(aResult); + nsXSLContentSink* it; NS_NEWXPCOM(it, nsXSLContentSink); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } + NS_ENSURE_TRUE(it, NS_ERROR_OUT_OF_MEMORY); + + nsCOMPtr sink = it; nsresult rv = it->Init(aTM, aDoc, aURL, aWebShell); - if (NS_OK != rv) { - delete it; - return rv; - } - return it->QueryInterface(NS_GET_IID(nsIXMLContentSink), (void **)aResult); + NS_ENSURE_SUCCESS(rv, rv); + + return CallQueryInterface(it, aResult); } nsXSLContentSink::nsXSLContentSink() @@ -82,15 +79,13 @@ nsXSLContentSink::~nsXSLContentSink() // Empty } - nsresult nsXSLContentSink::Init(nsITransformMediator* aTM, nsIDocument* aDoc, nsIURI* aURL, nsIWebShell* aContainer) { - nsresult rv; - rv = nsXMLContentSink::Init(aDoc, aURL, aContainer, nsnull); + nsresult rv = nsXMLContentSink::Init(aDoc, aURL, aContainer, nsnull); NS_ENSURE_SUCCESS(rv, rv); mXSLTransformMediator = aTM; @@ -98,7 +93,10 @@ nsXSLContentSink::Init(nsITransformMediator* aTM, nsCOMPtr loader; rv = mDocument->GetScriptLoader(getter_AddRefs(loader)); NS_ENSURE_SUCCESS(rv, rv); + loader->Suspend(); + loader->RemoveObserver(this); + return rv; } @@ -140,6 +138,7 @@ nsXSLContentSink::DidBuildModel(PRInt32 aQualityLevel) if (mXSLTransformMediator) { // Pass the style content model to the tranform mediator. mXSLTransformMediator->SetStyleSheetContentModel(styleNode); + mXSLTransformMediator = nsnull; } // Drop our reference to the parser to get rid of a circular @@ -222,6 +221,12 @@ nsXSLContentSink::ReportError(const PRUnichar* aErrorText, // nsXMLContentSink::ReportError sets mXSLTransformMediator to nsnull nsCOMPtr mediator = mXSLTransformMediator; + nsCOMPtr channel; + nsCOMPtr loadGroup; + mParser->GetChannel(getter_AddRefs(channel)); + mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup)); + mDocument->Reset(channel, loadGroup); + nsXMLContentSink::ReportError(aErrorText, aSourceText); if (mediator) { diff --git a/extensions/transformiix/build/Makefile.in b/extensions/transformiix/build/Makefile.in index 26005622a20..2f27300cd46 100644 --- a/extensions/transformiix/build/Makefile.in +++ b/extensions/transformiix/build/Makefile.in @@ -37,7 +37,6 @@ REQUIRES = xpcom \ dom \ layout \ content \ - content_xsl \ widget \ necko \ js \ diff --git a/extensions/transformiix/build/makefile.win b/extensions/transformiix/build/makefile.win index 36c39245b3c..54ac744396e 100644 --- a/extensions/transformiix/build/makefile.win +++ b/extensions/transformiix/build/makefile.win @@ -25,7 +25,6 @@ REQUIRES = xpcom \ string \ dom \ widget \ - content_xsl \ necko \ content \ xpconnect \ diff --git a/extensions/transformiix/source/xslt/Makefile.in b/extensions/transformiix/source/xslt/Makefile.in index 8694f050c51..52a9961dcfb 100644 --- a/extensions/transformiix/source/xslt/Makefile.in +++ b/extensions/transformiix/source/xslt/Makefile.in @@ -35,7 +35,6 @@ REQUIRES = string \ dom \ layout \ content \ - content_xsl \ widget \ necko \ unicharutil \ diff --git a/extensions/transformiix/source/xslt/XSLTProcessor.cpp b/extensions/transformiix/source/xslt/XSLTProcessor.cpp index a2c4e6509e8..2eaa5abd930 100644 --- a/extensions/transformiix/source/xslt/XSLTProcessor.cpp +++ b/extensions/transformiix/source/xslt/XSLTProcessor.cpp @@ -2275,7 +2275,7 @@ NS_IMETHODIMP XSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM, nsIDOMNode* aStyleDOM, nsIDOMDocument* aOutputDoc, - nsIObserver* aObserver) + nsITransformObserver* aObserver) { // We need source and result documents but no stylesheet. NS_ENSURE_ARG(aSourceDOM); @@ -2402,7 +2402,7 @@ XSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM, document->ContentInserted(nsnull, root, 0); } - mObserver = aObserver; + mObserver = do_GetWeakReference(aObserver); SignalTransformEnd(); return NS_OK; @@ -2442,7 +2442,8 @@ XSLTProcessor::ScriptEvaluated(nsresult aResult, void XSLTProcessor::SignalTransformEnd() { - if (!mObserver) + nsCOMPtr observer = do_QueryReferent(mObserver); + if (!observer) return; if (!mOutputHandler || !mOutputHandler->isDone()) @@ -2453,15 +2454,21 @@ XSLTProcessor::SignalTransformEnd() mScriptLoader = nsnull; } - nsresult rv; - nsCOMPtr anObserverService = do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr rootContent; - mOutputHandler->getRootContent(getter_AddRefs(rootContent)); - anObserverService->AddObserver(mObserver, "xslt-done", PR_TRUE); - anObserverService->NotifyObservers(rootContent, "xslt-done", nsnull); - } mObserver = nsnull; + + // XXX Need a better way to determine transform success/failure + nsCOMPtr rootContent; + mOutputHandler->getRootContent(getter_AddRefs(rootContent)); + nsCOMPtr root = do_QueryInterface(rootContent); + if (root) { + nsCOMPtr resultDoc; + root->GetOwnerDocument(getter_AddRefs(resultDoc)); + observer->OnTransformDone(NS_OK, resultDoc); + } + else { + // XXX Need better error message and code. + observer->OnTransformDone(NS_ERROR_FAILURE, nsnull); + } } // XXX diff --git a/extensions/transformiix/source/xslt/XSLTProcessor.h b/extensions/transformiix/source/xslt/XSLTProcessor.h index 16be7563675..e9c04615556 100644 --- a/extensions/transformiix/source/xslt/XSLTProcessor.h +++ b/extensions/transformiix/source/xslt/XSLTProcessor.h @@ -41,10 +41,10 @@ #include "nsICSSLoaderObserver.h" #include "nsIDocumentTransformer.h" #include "nsIDOMHTMLScriptElement.h" -#include "nsIObserver.h" #include "nsIScriptLoader.h" #include "nsIScriptLoaderObserver.h" - +#include "nsITransformObserver.h" +#include "nsWeakPtr.h" #include "txMozillaTextOutput.h" #include "txMozillaXMLOutput.h" #endif @@ -374,7 +374,7 @@ private: void SignalTransformEnd(); nsCOMPtr mScriptLoader; - nsCOMPtr mObserver; + nsWeakPtr mObserver; #endif }; //-- XSLTProcessor diff --git a/extensions/transformiix/source/xslt/makefile.win b/extensions/transformiix/source/xslt/makefile.win index 83d05c18595..18f916e62c7 100644 --- a/extensions/transformiix/source/xslt/makefile.win +++ b/extensions/transformiix/source/xslt/makefile.win @@ -26,7 +26,6 @@ REQUIRES = string \ dom \ widget \ necko \ - content_xsl \ content \ unicharutil \ xpconnect \ diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 4bef747c2a9..14836311485 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -184,8 +184,6 @@ const char* kPrintingPromptService = "@mozilla.org/embedcomp/printingprompt-serv #include "nsIDOMFocusListener.h" #include "nsISelectionController.h" -#include "nsITransformMediator.h" - #ifdef IBMBIDI #include "nsBidiUtils.h" #endif @@ -511,7 +509,6 @@ public: NS_IMETHOD GetPresContext(nsIPresContext*& aResult); NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, nsIDocumentViewer*& aResult); - NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator); // nsIContentViewerEdit NS_DECL_NSICONTENTVIEWEREDIT @@ -698,9 +695,8 @@ protected: nsISupports* mContainer; // [WEAK] it owns me! nsCOMPtr mDeviceContext; // ??? can't hurt, but... - // the following seven items are explicitly in this order + // the following six items are explicitly in this order // so they will be destroyed in the reverse order (pinkerton, scc) - nsCOMPtr mTransformMediator; nsCOMPtr mDocument; nsCOMPtr mWindow; // ??? should we really own it? nsCOMPtr mViewManager; @@ -1389,8 +1385,6 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, const nsRect& aBounds, PRBool aDoCreation) { - mTransformMediator = nsnull; - #ifdef NS_PRINT_PREVIEW mParentWidget = aParentWidget; // not ref counted #endif @@ -5343,16 +5337,6 @@ nsresult DocumentViewerImpl::DocumentReadyForPrinting() return rv; } -NS_IMETHODIMP -DocumentViewerImpl::SetTransformMediator(nsITransformMediator* aMediator) -{ - NS_ASSERTION(!mTransformMediator || !aMediator, - "nsXMLDocument::SetTransformMediator(): \ - Cannot set a second transform mediator\n"); - mTransformMediator = aMediator; - return NS_OK; -} - #ifdef XP_MAC #pragma mark - #endif diff --git a/layout/base/nsIDocumentViewer.h b/layout/base/nsIDocumentViewer.h index 4dfb623de81..058c6dc8dd9 100644 --- a/layout/base/nsIDocumentViewer.h +++ b/layout/base/nsIDocumentViewer.h @@ -44,7 +44,6 @@ class nsIDocument; class nsIPresContext; class nsIPresShell; class nsIStyleSheet; -class nsITransformMediator; #define NS_IDOCUMENT_VIEWER_IID \ { 0xa6cf9057, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} @@ -68,8 +67,6 @@ public: NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, nsIDocumentViewer*& aResult) = 0; - - NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator)=0; }; #endif /* nsIDocumentViewer_h___ */ diff --git a/xpinstall/packager/packages-static-unix b/xpinstall/packager/packages-static-unix index 395880e6acc..fe299f94c5d 100644 --- a/xpinstall/packager/packages-static-unix +++ b/xpinstall/packager/packages-static-unix @@ -93,7 +93,7 @@ bin/components/jar.xpt bin/components/jsconsole-clhandler.js bin/components/content_base.xpt bin/components/content_html.xpt -bin/components/content_xsl.xpt +bin/components/content_xslt.xpt bin/components/webBrowser_core.xpt bin/components/locale.xpt bin/components/mozbrwsr.xpt diff --git a/xpinstall/packager/packages-static-win b/xpinstall/packager/packages-static-win index 7e5bf07ffc4..dcd3bf3c81d 100644 --- a/xpinstall/packager/packages-static-win +++ b/xpinstall/packager/packages-static-win @@ -101,7 +101,7 @@ bin\components\gfx.xpt bin\components\gfx2.xpt bin\components\content_base.xpt bin\components\content_html.xpt -bin\components\content_xsl.xpt +bin\components\content_xslt.xpt bin\components\xuldoc.xpt bin\components\xultmpl.xpt bin\components\imglib2.xpt diff --git a/xpinstall/packager/packages-unix b/xpinstall/packager/packages-unix index 005fbf77325..836904ea1b6 100644 --- a/xpinstall/packager/packages-unix +++ b/xpinstall/packager/packages-unix @@ -140,7 +140,7 @@ bin/components/libprofile.so bin/components/libgkcontent.so bin/components/content_base.xpt bin/components/content_html.xpt -bin/components/content_xsl.xpt +bin/components/content_xslt.xpt bin/components/libgklayout.so bin/components/libgkplugin.so bin/components/libhtmlpars.so diff --git a/xpinstall/packager/packages-win b/xpinstall/packager/packages-win index c11840c233b..1ebca4f8566 100644 --- a/xpinstall/packager/packages-win +++ b/xpinstall/packager/packages-win @@ -127,7 +127,7 @@ bin\components\gfx2.dll bin\components\gkcontent.dll bin\components\content_base.xpt bin\components\content_html.xpt -bin\components\content_xsl.xpt +bin\components\content_xslt.xpt bin\components\xuldoc.xpt bin\components\xultmpl.xpt bin\components\gklayout.dll