Bug 462739: Send cookies as appropriate with xpinstall requests. r+sr=dveditz, a1.9.1=beltzner
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 28 Nov 2008 12:49:07 -0800
changeset 22096 c99b74e60a17765f56dc4a25ec4b36e63d8d41b6
parent 22095 118ca6994ff52e80ae07cad093c125f3b3708b7c
child 22097 169f2cc23290f64465169635768558d01ca6e804
push idunknown
push userunknown
push dateunknown
bugs462739
milestone1.9.1b3pre
Bug 462739: Send cookies as appropriate with xpinstall requests. r+sr=dveditz, a1.9.1=beltzner
xpinstall/src/nsXPInstallManager.cpp
xpinstall/src/nsXPInstallManager.h
--- a/xpinstall/src/nsXPInstallManager.cpp
+++ b/xpinstall/src/nsXPInstallManager.cpp
@@ -62,16 +62,18 @@
 
 #include "nsIStringEnumerator.h"
 #include "nsXPITriggerInfo.h"
 #include "nsXPInstallManager.h"
 #include "nsInstallTrigger.h"
 #include "nsIWindowWatcher.h"
 #include "nsIAuthPrompt.h"
 #include "nsIWindowMediator.h"
+#include "nsIDocument.h"
+#include "nsIDOMDocument.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsDirectoryService.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsAppDirectoryServiceDefs.h"
 
 #include "nsReadableUtils.h"
 #include "nsIPromptService.h"
 #include "nsIScriptGlobalObject.h"
@@ -227,26 +229,37 @@ nsXPInstallManager::InitManager(nsIDOMWi
     nsresult rv = NS_OK;
 
     mNeedsShutdown = PR_TRUE;
     mTriggers = aTriggers;
     mChromeType = aChromeType;
 
     mParentWindow = aParentWindow;
 
+    // Attempt to find a load group, continue if we can't find one though
+    if (aParentWindow) {
+        nsCOMPtr<nsIDOMDocument> domdoc;
+        rv = aParentWindow->GetDocument(getter_AddRefs(domdoc));
+        if (NS_SUCCEEDED(rv) && domdoc) {
+            nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
+            if (doc)
+                mLoadGroup = doc->GetDocumentLoadGroup();
+        }
+    }
+
     // Start downloading initial chunks looking for signatures,
     mOutstandingCertLoads = mTriggers->Size();
 
     nsXPITriggerItem *item = mTriggers->Get(--mOutstandingCertLoads);
 
     nsCOMPtr<nsIURI> uri;
     NS_NewURI(getter_AddRefs(uri), NS_ConvertUTF16toUTF8(item->mURL));
     nsCOMPtr<nsIStreamListener> listener = new CertReader(uri, nsnull, this);
     if (listener)
-        rv = NS_OpenURI(listener, nsnull, uri);
+        rv = NS_OpenURI(listener, nsnull, uri, nsnull, mLoadGroup);
     else
         rv = NS_ERROR_OUT_OF_MEMORY;
 
     if (NS_FAILED(rv)) {
         Shutdown();
     }
     return rv;
 }
@@ -875,17 +888,17 @@ NS_IMETHODIMP nsXPInstallManager::Downlo
             if (NS_SUCCEEDED(rv))
             {
                 nsCOMPtr<nsIURI> pURL;
                 rv = NS_NewURI(getter_AddRefs(pURL), mItem->mURL);
                 if (NS_SUCCEEDED(rv))
                 {
                     nsCOMPtr<nsIChannel> channel;
 
-                    rv = NS_NewChannel(getter_AddRefs(channel), pURL, nsnull, nsnull, this);
+                    rv = NS_NewChannel(getter_AddRefs(channel), pURL, nsnull, mLoadGroup, this);
                     if (NS_SUCCEEDED(rv))
                     {
                         rv = channel->AsyncOpen(this, nsnull);
                     }
                 }
             }
 
             if (NS_FAILED(rv))
@@ -1366,17 +1379,17 @@ nsXPInstallManager::OnCertAvailable(nsIU
     if (!uri || mChromeType != NOT_CHROME)
         return OnCertAvailable(uri, context, NS_ERROR_FAILURE, nsnull);
 
     nsIStreamListener* listener = new CertReader(uri, nsnull, this);
     if (!listener)
         return OnCertAvailable(uri, context, NS_ERROR_FAILURE, nsnull);
 
     NS_ADDREF(listener);
-    nsresult rv = NS_OpenURI(listener, nsnull, uri);
+    nsresult rv = NS_OpenURI(listener, nsnull, uri, nsnull, mLoadGroup);
 
     NS_ASSERTION(NS_SUCCEEDED(rv), "OpenURI failed");
     NS_RELEASE(listener);
 
     if (NS_FAILED(rv))
         return OnCertAvailable(uri, context, NS_ERROR_FAILURE, nsnull);
 
     return NS_OK;
--- a/xpinstall/src/nsXPInstallManager.h
+++ b/xpinstall/src/nsXPInstallManager.h
@@ -56,16 +56,17 @@
 #include "nsIChromeRegistry.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsIObserver.h"
 #include "nsIBadCertListener2.h"
 #include "nsISSLErrorListener.h"
 #include "nsIChannelEventSink.h"
 #include "nsIZipReader.h"
 #include "nsIXPIInstallInfo.h"
+#include "nsILoadGroup.h"
 
 #include "nsCOMPtr.h"
 
 #include "nsIProgressEventSink.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 
 #include "nsIDialogParamBlock.h"
@@ -132,11 +133,12 @@ class nsXPInstallManager : public nsIXPI
         PRBool              mDialogOpen;
         PRBool              mCancelled;
         PRBool              mNeedsShutdown;
         PRBool              mFromChrome;
 
         nsCOMPtr<nsIXPIProgressDialog>  mDlg;
 
         nsCOMPtr<nsIDOMWindowInternal>  mParentWindow;
+        nsCOMPtr<nsILoadGroup>          mLoadGroup;
 };
 
 #endif