Fix for bug 540443 (Change one argument of nsContentUtils::CheckSameOrigin from nsIDOMNode to nsINode). r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 12 Jan 2010 14:08:44 +0100
changeset 37947 5824949270093a74033cbc4e95525be274f4ee49
parent 37946 794c61af2b5a8327eccb8e6dc8df5c1e6004b6e2
child 37948 ab20dd6c7d09b523eea0f86fc7576a8669b0c2e1
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs540443
milestone1.9.3a2pre
Fix for bug 540443 (Change one argument of nsContentUtils::CheckSameOrigin from nsIDOMNode to nsINode). r=bz.
content/base/public/nsContentUtils.h
content/base/src/nsContentUtils.cpp
content/base/src/nsTreeWalker.cpp
content/xul/document/src/nsXULCommandDispatcher.cpp
content/xul/document/src/nsXULDocument.cpp
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -388,17 +388,17 @@ public:
 
   /**
    * Checks whether two nodes come from the same origin. aTrustedNode is
    * considered 'safe' in that a user can operate on it and that it isn't
    * a js-object that implements nsIDOMNode.
    * Never call this function with the first node provided by script, it
    * must always be known to be a 'real' node!
    */
-  static nsresult CheckSameOrigin(nsIDOMNode* aTrustedNode,
+  static nsresult CheckSameOrigin(nsINode* aTrustedNode,
                                   nsIDOMNode* aUnTrustedNode);
 
   // Check if the (JS) caller can access aNode.
   static PRBool CanCallerAccess(nsIDOMNode *aNode);
 
   // Check if the (JS) caller can access aWindow.
   // aWindow can be either outer or inner window.
   static PRBool CanCallerAccess(nsPIDOMWindow* aWindow);
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -975,39 +975,38 @@ nsContentUtils::IsCallerTrustedForCapabi
  * Checks whether two nodes come from the same origin. aTrustedNode is
  * considered 'safe' in that a user can operate on it and that it isn't
  * a js-object that implements nsIDOMNode.
  * Never call this function with the first node provided by script, it
  * must always be known to be a 'real' node!
  */
 // static
 nsresult
-nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode,
+nsContentUtils::CheckSameOrigin(nsINode *aTrustedNode,
                                 nsIDOMNode *aUnTrustedNode)
 {
   NS_PRECONDITION(aTrustedNode, "There must be a trusted node");
 
   PRBool isSystem = PR_FALSE;
   sSecurityManager->SubjectPrincipalIsSystem(&isSystem);
   if (isSystem) {
     // we're running as system, grant access to the node.
 
     return NS_OK;
   }
 
   /*
    * Get hold of each node's principal
    */
-  nsCOMPtr<nsINode> trustedNode = do_QueryInterface(aTrustedNode);
   nsCOMPtr<nsINode> unTrustedNode = do_QueryInterface(aUnTrustedNode);
 
   // Make sure these are both real nodes
-  NS_ENSURE_TRUE(trustedNode && unTrustedNode, NS_ERROR_UNEXPECTED);
-
-  nsIPrincipal* trustedPrincipal = trustedNode->NodePrincipal();
+  NS_ENSURE_TRUE(aTrustedNode && unTrustedNode, NS_ERROR_UNEXPECTED);
+
+  nsIPrincipal* trustedPrincipal = aTrustedNode->NodePrincipal();
   nsIPrincipal* unTrustedPrincipal = unTrustedNode->NodePrincipal();
 
   if (trustedPrincipal == unTrustedPrincipal) {
     return NS_OK;
   }
 
   PRBool equal;
   // XXXbz should we actually have a Subsumes() check here instead?  Or perhaps
--- a/content/base/src/nsTreeWalker.cpp
+++ b/content/base/src/nsTreeWalker.cpp
@@ -142,18 +142,17 @@ NS_IMETHODIMP nsTreeWalker::GetCurrentNo
 
     return NS_OK;
 }
 NS_IMETHODIMP nsTreeWalker::SetCurrentNode(nsIDOMNode * aCurrentNode)
 {
     NS_ENSURE_TRUE(aCurrentNode, NS_ERROR_DOM_NOT_SUPPORTED_ERR);
 
     // This QI is dumb, but this shouldn't be a critical operation
-    nsCOMPtr<nsIDOMNode> domRoot = do_QueryInterface(mRoot);
-    nsresult rv = nsContentUtils::CheckSameOrigin(domRoot, aCurrentNode);
+    nsresult rv = nsContentUtils::CheckSameOrigin(mRoot, aCurrentNode);
     NS_ENSURE_SUCCESS(rv, rv);
 
     mCurrentNode = do_QueryInterface(aCurrentNode);
     mPossibleIndexes.Clear();
     mPossibleIndexesPos = -1;
 
     return NS_OK;
 }
--- a/content/xul/document/src/nsXULCommandDispatcher.cpp
+++ b/content/xul/document/src/nsXULCommandDispatcher.cpp
@@ -282,19 +282,17 @@ NS_IMETHODIMP
 nsXULCommandDispatcher::AddCommandUpdater(nsIDOMElement* aElement,
                                           const nsAString& aEvents,
                                           const nsAString& aTargets)
 {
   NS_PRECONDITION(aElement != nsnull, "null ptr");
   if (! aElement)
     return NS_ERROR_NULL_POINTER;
 
-  nsCOMPtr<nsIDOMNode> doc(do_QueryInterface(mDocument));
-
-  nsresult rv = nsContentUtils::CheckSameOrigin(doc, aElement);
+  nsresult rv = nsContentUtils::CheckSameOrigin(mDocument, aElement);
 
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   Updater* updater = mUpdaters;
   Updater** link = &mUpdaters;
 
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -777,25 +777,23 @@ nsXULDocument::SynchronizeBroadcastListe
 NS_IMETHODIMP
 nsXULDocument::AddBroadcastListenerFor(nsIDOMElement* aBroadcaster,
                                        nsIDOMElement* aListener,
                                        const nsAString& aAttr)
 {
     NS_ENSURE_ARG(aBroadcaster && aListener);
     
     nsresult rv =
-        nsContentUtils::CheckSameOrigin(static_cast<nsDocument *>(this),
-                                        aBroadcaster);
+        nsContentUtils::CheckSameOrigin(this, aBroadcaster);
 
     if (NS_FAILED(rv)) {
         return rv;
     }
 
-    rv = nsContentUtils::CheckSameOrigin(static_cast<nsDocument *>(this),
-                                         aListener);
+    rv = nsContentUtils::CheckSameOrigin(this, aListener);
 
     if (NS_FAILED(rv)) {
         return rv;
     }
 
     static PLDHashTableOps gOps = {
         PL_DHashAllocTable,
         PL_DHashFreeTable,