Fixing bug 606058. Given XUL overlay documents the principals of the containing document. r=bzbarsky@mit.edu, a=blocker
☠☠ backed out by 3077e1c11fb6 ☠ ☠
authorJohnny Stenback <jst@mozilla.com>
Wed, 20 Oct 2010 18:44:07 -0700
changeset 57940 312bbc3ed89462e6bcd00be43e0950e6f3a6920e
parent 57939 076f5ea1f94a86a5079f97cf3907370dfe970490
child 57941 5fc1f9723b56dc409ecfa45fd9da7197d4f71ae6
child 57943 3077e1c11fb6a465333df44c63ad3f14021bdd55
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersbzbarsky, blocker
bugs606058
milestone2.0b8pre
Fixing bug 606058. Given XUL overlay documents the principals of the containing document. r=bzbarsky@mit.edu, a=blocker
content/xul/document/src/nsXULDocument.cpp
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -2771,17 +2771,28 @@ nsXULDocument::LoadOverlayInternal(nsIUR
         if (! parserObserver)
             return NS_ERROR_OUT_OF_MEMORY;
 
         NS_ADDREF(parserObserver);
         parser->Parse(aURI, parserObserver);
         NS_RELEASE(parserObserver);
 
         nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
-        rv = NS_OpenURI(listener, nsnull, aURI, nsnull, group);
+        nsCOMPtr<nsIChannel> channel;
+        rv = NS_NewChannel(getter_AddRefs(channel), aURI);
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        // Set the owner of the channel to be our principal so that
+        // the overlay's JSObjects etc end up being created with the
+        // right principal and in the correct compartment.
+        channel->SetOwner(NodePrincipal());
+
+        rv = channel->AsyncOpen(listener, nsnull);
+        NS_ENSURE_SUCCESS(rv, rv);
+
         if (NS_FAILED(rv)) {
             // Abandon this prototype
             mCurrentPrototype = nsnull;
 
             // The parser won't get an OnStartRequest and
             // OnStopRequest, so it needs a Terminate.
             parser->Terminate();
 
@@ -4527,17 +4538,17 @@ nsXULDocument::ParserObserver::OnStartRe
     if (mPrototype) {
         nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
         nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
         if (channel && secMan) {
             nsCOMPtr<nsIPrincipal> principal;
             secMan->GetChannelPrincipal(channel, getter_AddRefs(principal));
 
             // Failure there is ok -- it'll just set a (safe) null principal
-            mPrototype->SetDocumentPrincipal(principal);            
+            mPrototype->SetDocumentPrincipal(principal);
         }
 
         // Make sure to avoid cycles
         mPrototype = nsnull;
     }
         
     return NS_OK;
 }