Bug 1374779 - Open address book dialog from privileged window. r=bz
authorJorg K <jorgk@jorgk.com>
Thu, 22 Jun 2017 07:25:56 +0200
changeset 28372 4e64a09ef23545c60be574f055c892a06a537344
parent 28371 4f6639dc0572bc3dc0f08c60f355d1ea2448355b
child 28373 e164cc084e8fc75d967652f7e9ff48436b33d619
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1374779
Bug 1374779 - Open address book dialog from privileged window. r=bz
mailnews/addrbook/src/nsAbContentHandler.cpp
--- a/mailnews/addrbook/src/nsAbContentHandler.cpp
+++ b/mailnews/addrbook/src/nsAbContentHandler.cpp
@@ -8,16 +8,18 @@
 #include "nsNetUtil.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "NullPrincipal.h"
 #include "nsISupportsPrimitives.h"
 #include "plstr.h"
 #include "nsPIDOMWindow.h"
 #include "mozIDOMWindow.h"
+#include "nsIDocShell.h"
+#include "nsIDocShellTreeItem.h"
 #include "nsMsgUtils.h"
 #include "nsIMsgVCardService.h"
 #include "nsIAbCard.h"
 #include "nsIAbManager.h"
 #include "nsVCard.h"
 #include "nsIChannel.h"
 //
 // nsAbContentHandler
@@ -84,19 +86,24 @@ nsAbContentHandler::HandleContent(const 
 
             nsCOMPtr<nsISupportsInterfacePointer> ifptr =
                 do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
             NS_ENSURE_SUCCESS(rv, rv);
 
             ifptr->SetData(cardFromVCard);
             ifptr->SetDataIID(&NS_GET_IID(nsIAbCard));
 
-            nsCOMPtr<nsPIDOMWindowOuter> dialogWindow;
+            // Find a privileged chrome window to open the dialog from.
+            nsCOMPtr<nsIDocShell> docShell(parentWindow->GetDocShell());
+            nsCOMPtr<nsIDocShellTreeItem> root;
+            docShell->GetRootTreeItem(getter_AddRefs(root));
+            nsCOMPtr<nsPIDOMWindowOuter> window(do_GetInterface(root));
 
-            rv = parentWindow->OpenDialog(
+            nsCOMPtr<nsPIDOMWindowOuter> dialogWindow;
+            rv = window->OpenDialog(
                 NS_LITERAL_STRING("chrome://messenger/content/addressbook/abNewCardDialog.xul"),
                 EmptyString(),
                 NS_LITERAL_STRING("chrome,resizable=no,titlebar,modal,centerscreen"),
                 ifptr, getter_AddRefs(dialogWindow));
             NS_ENSURE_SUCCESS(rv, rv);
         }
         rv = NS_OK;
     }