Bug 1076836 - Stop storing a principal in txMozillaXSLTProcessor, pass the document to TX_LoadSheet. r=sicking.
authorPeter Van der Beken <peterv@propagandism.org>
Wed, 08 Oct 2014 10:29:11 +0200
changeset 209285 3e40213d4a2175c167406ab80cb5b36f66403ee1
parent 209284 1da35b1d566319922decfbdd9d5ab6e18469ad5e
child 209286 b818ba8aabc28188ee0521778ef6712c178ba146
push id50140
push userpvanderbeken@mozilla.com
push dateWed, 08 Oct 2014 09:21:38 +0000
treeherdermozilla-inbound@3e40213d4a21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1076836
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1076836 - Stop storing a principal in txMozillaXSLTProcessor, pass the document to TX_LoadSheet. r=sicking.
dom/xml/nsXMLContentSink.cpp
dom/xslt/nsIDocumentTransformer.h
dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
dom/xslt/xslt/txMozillaXSLTProcessor.cpp
dom/xslt/xslt/txMozillaXSLTProcessor.h
--- a/dom/xml/nsXMLContentSink.cpp
+++ b/dom/xml/nsXMLContentSink.cpp
@@ -660,23 +660,17 @@ nsXMLContentSink::LoadXSLStyleSheet(nsIU
     do_CreateInstance("@mozilla.org/document-transformer;1?type=xslt");
   if (!processor) {
     // No XSLT processor available, continue normal document loading
     return NS_OK;
   }
 
   processor->SetTransformObserver(this);
 
-  nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
-  if (!loadGroup) {
-    return NS_ERROR_FAILURE;
-  }
-
-  if (NS_SUCCEEDED(processor->LoadStyleSheet(aUrl, loadGroup,
-                                             mDocument->NodePrincipal()))) {
+  if (NS_SUCCEEDED(processor->LoadStyleSheet(aUrl, mDocument))) {
     mXSLTProcessor.swap(processor);
   }
 
   // Intentionally ignore errors here, we should continue loading the
   // XML document whether we're able to load the XSLT stylesheet or
   // not.
 
   return NS_OK;
--- a/dom/xslt/nsIDocumentTransformer.h
+++ b/dom/xslt/nsIDocumentTransformer.h
@@ -2,20 +2,19 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
 #ifndef nsIDocumentTransformer_h__
 #define nsIDocumentTransformer_h__
 
 #include "nsISupports.h"
 
+class nsIDocument;
 class nsIDOMNode;
-class nsILoadGroup;
 class nsIURI;
-class nsIPrincipal;
 class nsString;
 
 #define NS_ITRANSFORMOBSERVER_IID \
 { 0x04b2d17c, 0xe98d, 0x45f5, \
   { 0x9a, 0x67, 0xb7, 0x01, 0x19, 0x59, 0x7d, 0xe7 } }
 
 class nsITransformObserver : public nsISupports
 {
@@ -28,28 +27,27 @@ public:
   NS_IMETHOD OnTransformDone(nsresult aResult,
                              nsIDocument *aResultDocument) = 0;
 
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsITransformObserver, NS_ITRANSFORMOBSERVER_IID)
 
 #define NS_IDOCUMENTTRANSFORMER_IID \
-{ 0xc75613ee, 0xcb6e, 0x4bf7, \
- { 0x9e, 0x5b, 0x36, 0x50, 0x69, 0xc1, 0xe3, 0x55 } }
+{ 0xf45e1ff8, 0x50f3, 0x4496, \
+ { 0xb3, 0xa2, 0x0e, 0x03, 0xe8, 0x4a, 0x57, 0x11 } }
 
 class nsIDocumentTransformer : public nsISupports
 {
 public: 
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENTTRANSFORMER_IID)
 
   NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver) = 0;
-  NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup,
-                            nsIPrincipal* aPrincipal) = 0;
+  NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsIDocument* aLoaderDocument) = 0;
   NS_IMETHOD SetSourceContentModel(nsIDOMNode* aSource) = 0;
   NS_IMETHOD CancelLoads() = 0;
 
   NS_IMETHOD AddXSLTParamNamespace(const nsString& aPrefix,
                                    const nsString& aNamespace) = 0;
   NS_IMETHOD AddXSLTParam(const nsString& aName,
                           const nsString& aNamespace,
                           const nsString& aValue,
--- a/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
+++ b/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
@@ -363,42 +363,41 @@ txStylesheetSink::GetInterface(const nsI
 
     return NS_ERROR_NO_INTERFACE;
 }
 
 class txCompileObserver MOZ_FINAL : public txACompileObserver
 {
 public:
     txCompileObserver(txMozillaXSLTProcessor* aProcessor,
-                      nsILoadGroup* aLoadGroup);
+                      nsIDocument* aLoaderDocument);
 
     TX_DECL_ACOMPILEOBSERVER
     NS_INLINE_DECL_REFCOUNTING(txCompileObserver)
 
     nsresult startLoad(nsIURI* aUri, txStylesheetCompiler* aCompiler,
                        nsIPrincipal* aSourcePrincipal);
 
 private:
     nsRefPtr<txMozillaXSLTProcessor> mProcessor;
-    nsCOMPtr<nsILoadGroup> mLoadGroup;
-    nsCOMPtr<nsIPrincipal> mCallerPrincipal;
+    nsCOMPtr<nsIDocument> mLoaderDocument;
 
     // This exists solely to suppress a warning from nsDerivedSafe
     txCompileObserver();
 
     // Private destructor, to discourage deletion outside of Release():
     ~txCompileObserver()
     {
     }
 };
 
 txCompileObserver::txCompileObserver(txMozillaXSLTProcessor* aProcessor,
-                                     nsILoadGroup* aLoadGroup)
+                                     nsIDocument* aLoaderDocument)
     : mProcessor(aProcessor),
-      mLoadGroup(aLoadGroup)
+      mLoaderDocument(aLoaderDocument)
 {
 }
 
 nsresult
 txCompileObserver::loadURI(const nsAString& aUri,
                            const nsAString& aReferrerUri,
                            txStylesheetCompiler* aCompiler)
 {
@@ -450,27 +449,32 @@ txCompileObserver::onDoneCompiling(txSty
         mProcessor->reportError(aResult, aErrorText, aParam);
     }
 }
 
 nsresult
 txCompileObserver::startLoad(nsIURI* aUri, txStylesheetCompiler* aCompiler,
                              nsIPrincipal* aReferrerPrincipal)
 {
+    nsCOMPtr<nsILoadGroup> loadGroup = mLoaderDocument->GetDocumentLoadGroup();
+    if (!loadGroup) {
+        return NS_ERROR_FAILURE;
+    }
+
     nsCOMPtr<nsIChannel> channel;
     nsresult rv = NS_NewChannel(getter_AddRefs(channel),
                                 aUri,
                                 aReferrerPrincipal,
                                 nsILoadInfo::SEC_NORMAL,
-                                nsIContentPolicy::TYPE_STYLESHEET);
+                                nsIContentPolicy::TYPE_STYLESHEET,
+                                nullptr,
+                                loadGroup);
 
     NS_ENSURE_SUCCESS(rv, rv);
 
-    channel->SetLoadGroup(mLoadGroup);
-
     channel->SetContentType(NS_LITERAL_CSTRING("text/xml"));
 
     nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
     if (httpChannel) {
         httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
                                       NS_LITERAL_CSTRING("*/*"),
                                       false);
 
@@ -499,46 +503,48 @@ txCompileObserver::startLoad(nsIURI* aUr
     rv = listener->Init(channel);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return channel->AsyncOpen(listener, parser);
 }
 
 nsresult
 TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor,
-             nsILoadGroup* aLoadGroup, nsIPrincipal* aCallerPrincipal)
+             nsIDocument* aLoaderDocument)
 {
+    nsIPrincipal* principal = aLoaderDocument->NodePrincipal();
+
     nsAutoCString spec;
     aUri->GetSpec(spec);
     PR_LOG(txLog::xslt, PR_LOG_ALWAYS, ("TX_LoadSheet: %s\n", spec.get()));
 
     // Content Policy
     int16_t shouldLoad = nsIContentPolicy::ACCEPT;
     nsresult rv =
         NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_STYLESHEET,
                                   aUri,
-                                  aCallerPrincipal,
+                                  principal,
                                   aProcessor->GetSourceContentModel(),
                                   NS_LITERAL_CSTRING("application/xml"),
                                   nullptr,
                                   &shouldLoad);
     NS_ENSURE_SUCCESS(rv, rv);
     if (NS_CP_REJECTED(shouldLoad)) {
         return NS_ERROR_DOM_BAD_URI;
     }
 
     nsRefPtr<txCompileObserver> observer =
-        new txCompileObserver(aProcessor, aLoadGroup);
+        new txCompileObserver(aProcessor, aLoaderDocument);
     NS_ENSURE_TRUE(observer, NS_ERROR_OUT_OF_MEMORY);
 
     nsRefPtr<txStylesheetCompiler> compiler =
         new txStylesheetCompiler(NS_ConvertUTF8toUTF16(spec), observer);
     NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
 
-    return observer->startLoad(aUri, compiler, aCallerPrincipal);
+    return observer->startLoad(aUri, compiler, principal);
 }
 
 /**
  * handling DOM->txStylesheet
  * Observer needs to do synchronous loads.
  */
 static nsresult
 handleNode(nsINode* aNode, txStylesheetCompiler* aCompiler)
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -1000,20 +1000,20 @@ txMozillaXSLTProcessor::GetFlags(uint32_
                    NS_ERROR_DOM_SECURITY_ERR);
 
     *aFlags = mFlags;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-txMozillaXSLTProcessor::LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup,
-                                       nsIPrincipal* aPrincipal)
+txMozillaXSLTProcessor::LoadStyleSheet(nsIURI* aUri,
+                                       nsIDocument* aLoaderDocument)
 {
-    nsresult rv = TX_LoadSheet(aUri, this, aLoadGroup, aPrincipal);
+    nsresult rv = TX_LoadSheet(aUri, this, aLoaderDocument);
     if (NS_FAILED(rv) && mObserver) {
         // This is most likely a network or security error, just
         // use the uri as context.
         nsAutoCString spec;
         aUri->GetSpec(spec);
         CopyUTF8toUTF16(spec, mSourceText);
         nsresult status = NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_XSLT ? rv :
                           NS_ERROR_XSLT_NETWORK_ERROR;
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.h
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.h
@@ -12,17 +12,16 @@
 #include "nsIXSLTProcessor.h"
 #include "nsIXSLTProcessorPrivate.h"
 #include "txExpandedNameMap.h"
 #include "txNamespaceMap.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 
 class nsIDOMNode;
-class nsIPrincipal;
 class nsIURI;
 class nsIXMLContentSink;
 class txStylesheet;
 class txResultRecycler;
 class txIGlobalParameter;
 
 /* bacd8ad0-552f-11d3-a9f7-000064657374 */
 #define TRANSFORMIIX_XSLT_PROCESSOR_CID   \
@@ -55,18 +54,17 @@ public:
     // nsIXSLTProcessor interface
     NS_DECL_NSIXSLTPROCESSOR
 
     // nsIXSLTProcessorPrivate interface
     NS_DECL_NSIXSLTPROCESSORPRIVATE
 
     // nsIDocumentTransformer interface
     NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver) MOZ_OVERRIDE;
-    NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup,
-                              nsIPrincipal* aPrincipal);
+    NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsIDocument* aLoaderDocument) MOZ_OVERRIDE;
     NS_IMETHOD SetSourceContentModel(nsIDOMNode* aSource) MOZ_OVERRIDE;
     NS_IMETHOD CancelLoads() MOZ_OVERRIDE {return NS_OK;}
     NS_IMETHOD AddXSLTParamNamespace(const nsString& aPrefix,
                                      const nsString& aNamespace) MOZ_OVERRIDE;
     NS_IMETHOD AddXSLTParam(const nsString& aName,
                             const nsString& aNamespace,
                             const nsString& aSelect,
                             const nsString& aValue,
@@ -122,16 +120,15 @@ private:
     txOwningExpandedNameMap<txIGlobalParameter> mVariables;
     txNamespaceMap mParamNamespaceMap;
     nsRefPtr<txResultRecycler> mRecycler;
 
     uint32_t mFlags;
 };
 
 extern nsresult TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor,
-                             nsILoadGroup* aLoadGroup,
-                             nsIPrincipal* aCallerPrincipal);
+                             nsIDocument* aLoaderDocument);
 
 extern nsresult TX_CompileStylesheet(nsINode* aNode,
                                      txMozillaXSLTProcessor* aProcessor,
                                      txStylesheet** aStylesheet);
 
 #endif