Bug 1076836 - Stop storing a principal in txMozillaXSLTProcessor. r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Fri, 03 Oct 2014 12:23:10 +0200
changeset 233868 1da35b1d566319922decfbdd9d5ab6e18469ad5e
parent 233867 62babb0d3ae28b5b4c8f9b4269d3aad6c8004d09
child 233869 3e40213d4a2175c167406ab80cb5b36f66403ee1
push id611
push userraliiev@mozilla.com
push dateMon, 05 Jan 2015 23:23:16 +0000
treeherdermozilla-release@345cd3b9c445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
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. r=bz.
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
@@ -658,25 +658,25 @@ nsXMLContentSink::LoadXSLStyleSheet(nsIU
 {
   nsCOMPtr<nsIDocumentTransformer> processor =
     do_CreateInstance("@mozilla.org/document-transformer;1?type=xslt");
   if (!processor) {
     // No XSLT processor available, continue normal document loading
     return NS_OK;
   }
 
-  processor->Init(mDocument->NodePrincipal());
   processor->SetTransformObserver(this);
 
   nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
   if (!loadGroup) {
     return NS_ERROR_FAILURE;
   }
 
-  if (NS_SUCCEEDED(processor->LoadStyleSheet(aUrl, loadGroup))) {
+  if (NS_SUCCEEDED(processor->LoadStyleSheet(aUrl, loadGroup,
+                                             mDocument->NodePrincipal()))) {
     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
@@ -28,28 +28,28 @@ public:
   NS_IMETHOD OnTransformDone(nsresult aResult,
                              nsIDocument *aResultDocument) = 0;
 
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsITransformObserver, NS_ITRANSFORMOBSERVER_IID)
 
 #define NS_IDOCUMENTTRANSFORMER_IID \
-  {0x17c83d91, 0xac2f, 0x4658, \
-    { 0x91, 0x6c, 0xcb, 0xc4, 0xd2, 0xb5, 0x2c, 0xe }}
+{ 0xc75613ee, 0xcb6e, 0x4bf7, \
+ { 0x9e, 0x5b, 0x36, 0x50, 0x69, 0xc1, 0xe3, 0x55 } }
 
 class nsIDocumentTransformer : public nsISupports
 {
 public: 
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENTTRANSFORMER_IID)
 
-  NS_IMETHOD Init(nsIPrincipal* aPrincipal) = 0;
   NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver) = 0;
-  NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup) = 0;
+  NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup,
+                            nsIPrincipal* aPrincipal) = 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
@@ -695,17 +695,16 @@ void txSyncCompileObserver::onDoneCompil
                                             nsresult aResult,
                                             const char16_t *aErrorText,
                                             const char16_t *aParam)
 {
 }
 
 nsresult
 TX_CompileStylesheet(nsINode* aNode, txMozillaXSLTProcessor* aProcessor,
-                     nsIPrincipal* aCallerPrincipal,
                      txStylesheet** aStylesheet)
 {
     // If we move GetBaseURI to nsINode this can be simplified.
     nsCOMPtr<nsIDocument> doc = aNode->OwnerDoc();
 
     nsCOMPtr<nsIURI> uri;
     if (aNode->IsNodeOfType(nsINode::eCONTENT)) {
       uri = static_cast<nsIContent*>(aNode)->GetBaseURI();
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -292,40 +292,37 @@ private:
  * txMozillaXSLTProcessor
  */
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(txMozillaXSLTProcessor)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(txMozillaXSLTProcessor)
     NS_IMPL_CYCLE_COLLECTION_UNLINK(mEmbeddedStylesheetRoot)
     NS_IMPL_CYCLE_COLLECTION_UNLINK(mSource)
-    NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrincipal)
     tmp->mVariables.clear();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(txMozillaXSLTProcessor)
     NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEmbeddedStylesheetRoot)
     NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSource)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrincipal)
     txOwningExpandedNameMap<txIGlobalParameter>::iterator iter(tmp->mVariables);
     while (iter.next()) {
         cb.NoteXPCOMChild(static_cast<txVariable*>(iter.value())->getValue());
     }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(txMozillaXSLTProcessor)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(txMozillaXSLTProcessor)
 
 DOMCI_DATA(XSLTProcessor, txMozillaXSLTProcessor)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(txMozillaXSLTProcessor)
     NS_INTERFACE_MAP_ENTRY(nsIXSLTProcessor)
     NS_INTERFACE_MAP_ENTRY(nsIXSLTProcessorPrivate)
     NS_INTERFACE_MAP_ENTRY(nsIDocumentTransformer)
     NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
-    NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXSLTProcessor)
     NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XSLTProcessor)
 NS_INTERFACE_MAP_END
 
 txMozillaXSLTProcessor::txMozillaXSLTProcessor() : mStylesheetDocument(nullptr),
                                                    mTransformResult(NS_OK),
                                                    mCompileResult(NS_OK),
                                                    mFlags(0)
@@ -575,17 +572,17 @@ txMozillaXSLTProcessor::ImportStylesheet
     }
     
     nsCOMPtr<nsINode> styleNode = do_QueryInterface(aStyle);
     NS_ENSURE_TRUE(styleNode &&
                    (styleNode->IsElement() ||
                     styleNode->IsNodeOfType(nsINode::eDOCUMENT)),
                    NS_ERROR_INVALID_ARG);
 
-    nsresult rv = TX_CompileStylesheet(styleNode, this, mPrincipal,
+    nsresult rv = TX_CompileStylesheet(styleNode, 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);
 
@@ -1003,19 +1000,20 @@ txMozillaXSLTProcessor::GetFlags(uint32_
                    NS_ERROR_DOM_SECURITY_ERR);
 
     *aFlags = mFlags;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-txMozillaXSLTProcessor::LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup)
+txMozillaXSLTProcessor::LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup,
+                                       nsIPrincipal* aPrincipal)
 {
-    nsresult rv = TX_LoadSheet(aUri, this, aLoadGroup, mPrincipal);
+    nsresult rv = TX_LoadSheet(aUri, this, aLoadGroup, aPrincipal);
     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;
@@ -1176,18 +1174,17 @@ txMozillaXSLTProcessor::ensureStylesheet
 
     NS_ENSURE_TRUE(mStylesheetDocument, NS_ERROR_NOT_INITIALIZED);
 
     nsINode* style = mEmbeddedStylesheetRoot;
     if (!style) {
         style = mStylesheetDocument;
     }
 
-    return TX_CompileStylesheet(style, this, mPrincipal,
-                                getter_AddRefs(mStylesheet));
+    return TX_CompileStylesheet(style, this, getter_AddRefs(mStylesheet));
 }
 
 void
 txMozillaXSLTProcessor::NodeWillBeDestroyed(const nsINode* aNode)
 {
     nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
     if (NS_FAILED(mCompileResult)) {
         return;
@@ -1239,33 +1236,16 @@ txMozillaXSLTProcessor::ContentRemoved(n
                                        nsIContent* aContainer,
                                        nsIContent* aChild,
                                        int32_t aIndexInContainer,
                                        nsIContent* aPreviousSibling)
 {
     mStylesheet = nullptr;
 }
 
-NS_IMETHODIMP
-txMozillaXSLTProcessor::Initialize(nsISupports* aOwner, JSContext* cx,
-                                   JSObject* obj, const JS::CallArgs& args)
-{
-    MOZ_ASSERT(nsContentUtils::GetCurrentJSContext());
-    return Init(nsContentUtils::SubjectPrincipal());
-}
-
-NS_IMETHODIMP
-txMozillaXSLTProcessor::Init(nsIPrincipal* aPrincipal)
-{
-    NS_ENSURE_ARG_POINTER(aPrincipal);
-    mPrincipal = aPrincipal;
-
-    return NS_OK;
-}
-
 /* static*/
 nsresult
 txMozillaXSLTProcessor::Startup()
 {
     if (!txXSLTProcessor::init()) {
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.h
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.h
@@ -8,17 +8,16 @@
 
 #include "nsAutoPtr.h"
 #include "nsStubMutationObserver.h"
 #include "nsIDocumentTransformer.h"
 #include "nsIXSLTProcessor.h"
 #include "nsIXSLTProcessorPrivate.h"
 #include "txExpandedNameMap.h"
 #include "txNamespaceMap.h"
-#include "nsIJSNativeInitializer.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 
 class nsIDOMNode;
 class nsIPrincipal;
 class nsIURI;
 class nsIXMLContentSink;
 class txStylesheet;
@@ -35,18 +34,17 @@ class txIGlobalParameter;
 #define XSLT_MSGS_URL  "chrome://global/locale/xslt/xslt.properties"
 
 /**
  * txMozillaXSLTProcessor is a front-end to the XSLT Processor.
  */
 class txMozillaXSLTProcessor MOZ_FINAL : public nsIXSLTProcessor,
                                          public nsIXSLTProcessorPrivate,
                                          public nsIDocumentTransformer,
-                                         public nsStubMutationObserver,
-                                         public nsIJSNativeInitializer
+                                         public nsStubMutationObserver
 {
 public:
     /**
      * Creates a new txMozillaXSLTProcessor
      */
     txMozillaXSLTProcessor();
 
     // nsISupports interface
@@ -56,19 +54,19 @@ public:
 
     // nsIXSLTProcessor interface
     NS_DECL_NSIXSLTPROCESSOR
 
     // nsIXSLTProcessorPrivate interface
     NS_DECL_NSIXSLTPROCESSORPRIVATE
 
     // nsIDocumentTransformer interface
-    NS_IMETHOD Init(nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
     NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver) MOZ_OVERRIDE;
-    NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup) MOZ_OVERRIDE;
+    NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup,
+                              nsIPrincipal* aPrincipal);
     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,
@@ -94,20 +92,16 @@ public:
     nsresult TransformToDoc(nsIDOMDocument **aResult,
                             bool aCreateDataDocument);
 
     bool IsLoadDisabled()
     {
         return (mFlags & DISABLE_ALL_LOADS) != 0;
     }
 
-    // nsIJSNativeInitializer
-    NS_IMETHODIMP Initialize(nsISupports* aOwner, JSContext *cx, JSObject *obj,
-                             const JS::CallArgs& aArgs);
-
     static nsresult Startup();
     static void Shutdown();
 
 private:
     /**
      * Default destructor for txMozillaXSLTProcessor
      */
     ~txMozillaXSLTProcessor();
@@ -119,27 +113,25 @@ private:
     nsRefPtr<txStylesheet> mStylesheet;
     nsIDocument* mStylesheetDocument; // weak
     nsCOMPtr<nsIContent> mEmbeddedStylesheetRoot;
 
     nsCOMPtr<nsIDOMNode> mSource;
     nsresult mTransformResult;
     nsresult mCompileResult;
     nsString mErrorText, mSourceText;
-    nsCOMPtr<nsIPrincipal> mPrincipal;
     nsCOMPtr<nsITransformObserver> mObserver;
     txOwningExpandedNameMap<txIGlobalParameter> mVariables;
     txNamespaceMap mParamNamespaceMap;
     nsRefPtr<txResultRecycler> mRecycler;
 
     uint32_t mFlags;
 };
 
 extern nsresult TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor,
                              nsILoadGroup* aLoadGroup,
                              nsIPrincipal* aCallerPrincipal);
 
 extern nsresult TX_CompileStylesheet(nsINode* aNode,
                                      txMozillaXSLTProcessor* aProcessor,
-                                     nsIPrincipal* aCallerPrincipal,
                                      txStylesheet** aStylesheet);
 
 #endif