From daa2640fb66871cc3f3282ace0effe4d66169cc0 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 5 Feb 2018 16:00:04 -0500 Subject: [PATCH] Bug 1435430 part 3. Remove nsIXSLTProcessor::ImportStylesheet. r=mystor MozReview-Commit-ID: Csqh40GjqJn --- dom/xml/nsXMLPrettyPrinter.cpp | 9 ++-- dom/xslt/nsIXSLTProcessor.idl | 13 ------ dom/xslt/xslt/txMozillaXSLTProcessor.cpp | 58 ++++++++++-------------- 3 files changed, 30 insertions(+), 50 deletions(-) diff --git a/dom/xml/nsXMLPrettyPrinter.cpp b/dom/xml/nsXMLPrettyPrinter.cpp index a885a72c5dc9..5aabf31d9b0c 100644 --- a/dom/xml/nsXMLPrettyPrinter.cpp +++ b/dom/xml/nsXMLPrettyPrinter.cpp @@ -113,10 +113,13 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocument* aDocument, // Transform the document RefPtr transformer = new txMozillaXSLTProcessor(); - rv = transformer->ImportStylesheet(xslDocument); - NS_ENSURE_SUCCESS(rv, rv); - ErrorResult err; + nsCOMPtr xslDoc = do_QueryInterface(xslDocument); + transformer->ImportStylesheet(*xslDoc, err); + if (NS_WARN_IF(err.Failed())) { + return err.StealNSResult(); + } + RefPtr resultFragment = transformer->TransformToFragment(*aDocument, *aDocument, err); if (NS_WARN_IF(err.Failed())) { diff --git a/dom/xslt/nsIXSLTProcessor.idl b/dom/xslt/nsIXSLTProcessor.idl index 5c94447d4620..ee655222ad22 100644 --- a/dom/xslt/nsIXSLTProcessor.idl +++ b/dom/xslt/nsIXSLTProcessor.idl @@ -10,19 +10,6 @@ interface nsIVariant; [scriptable, uuid(4a91aeb3-4100-43ee-a21e-9866268757c5)] interface nsIXSLTProcessor : nsISupports { - /** - * Import the stylesheet into this XSLTProcessor for transformations. - * - * @param style The root-node of a XSLT stylesheet. This can be either - * a document node or an element node. If a document node - * then the document can contain either a XSLT stylesheet - * or a LRE stylesheet. - * If the argument is an element node it must be the - * xsl:stylesheet (or xsl:transform) element of an XSLT - * stylesheet. - */ - void importStylesheet(in nsIDOMNode style); - /** * Transforms the node source applying the stylesheet given by the * importStylesheet() function. diff --git a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp index 35a6e1f42721..2d504ca1efa3 100644 --- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp +++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp @@ -595,44 +595,41 @@ txMozillaXSLTProcessor::DoTransform() return rv; } -NS_IMETHODIMP -txMozillaXSLTProcessor::ImportStylesheet(nsIDOMNode *aStyle) +void +txMozillaXSLTProcessor::ImportStylesheet(nsINode& aStyle, + mozilla::ErrorResult& aRv) { - NS_ENSURE_TRUE(aStyle, NS_ERROR_NULL_POINTER); - // We don't support importing multiple stylesheets yet. - NS_ENSURE_TRUE(!mStylesheetDocument && !mStylesheet, - NS_ERROR_NOT_IMPLEMENTED); - - nsCOMPtr node = do_QueryInterface(aStyle); - if (!node || !nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(node->NodePrincipal())) { - return NS_ERROR_DOM_SECURITY_ERR; + if (NS_WARN_IF(mStylesheetDocument || mStylesheet)) { + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); + return; } - nsCOMPtr styleNode = do_QueryInterface(aStyle); - NS_ENSURE_TRUE(styleNode && - (styleNode->IsElement() || - styleNode->IsNodeOfType(nsINode::eDOCUMENT)), - NS_ERROR_INVALID_ARG); + if (!nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(aStyle.NodePrincipal())) { + aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); + return; + } - nsresult rv = TX_CompileStylesheet(styleNode, this, + if (NS_WARN_IF(!aStyle.IsElement() && + !aStyle.IsNodeOfType(nsINode::eDOCUMENT))) { + aRv.Throw(NS_ERROR_INVALID_ARG); + return; + } + + nsresult rv = TX_CompileStylesheet(&aStyle, this, getter_AddRefs(mStylesheet)); // XXX set up exception context, bug 204658 - NS_ENSURE_SUCCESS(rv, rv); - - if (styleNode->IsElement()) { - mStylesheetDocument = styleNode->OwnerDoc(); - NS_ENSURE_TRUE(mStylesheetDocument, NS_ERROR_UNEXPECTED); - - mEmbeddedStylesheetRoot = static_cast(styleNode.get()); + if (NS_WARN_IF(NS_FAILED(rv))) { + aRv.Throw(rv); + return; } - else { - mStylesheetDocument = static_cast(styleNode.get()); + + mStylesheetDocument = aStyle.OwnerDoc(); + if (aStyle.IsElement()) { + mEmbeddedStylesheetRoot = aStyle.AsElement(); } mStylesheetDocument->AddMutationObserver(this); - - return NS_OK; } NS_IMETHODIMP @@ -1282,13 +1279,6 @@ txMozillaXSLTProcessor::Constructor(const GlobalObject& aGlobal, return processor.forget(); } -void -txMozillaXSLTProcessor::ImportStylesheet(nsINode& stylesheet, - mozilla::ErrorResult& aRv) -{ - aRv = ImportStylesheet(stylesheet.AsDOMNode()); -} - already_AddRefed txMozillaXSLTProcessor::TransformToDocument(nsINode& source, mozilla::ErrorResult& aRv)