Fixing bug 470356. Make the cookie dialogs open up modal to their origin tabs chrome window so that the dialog is centered on the window, and no centered on the screen. r=dwitte@stanford.edu, sr+a=jst@mozilla.org
authorBen Newman <bnewman@mozilla.com>
Thu, 22 Jan 2009 21:33:10 -0800
changeset 24103 7fdc9ed7396804cac517f4131dad0e3425a816b0
parent 24102 952de712fb34e8fafc98c94907e698636d147113
child 24104 aa27de3b85637bed160aa6419f4b99333bea69fd
push id4905
push userjst@mozilla.com
push dateFri, 23 Jan 2009 05:33:37 +0000
treeherdermozilla-central@7fdc9ed73968 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdwitte
bugs470356
milestone1.9.2a1pre
Fixing bug 470356. Make the cookie dialogs open up modal to their origin tabs chrome window so that the dialog is centered on the window, and no centered on the screen. r=dwitte@stanford.edu, sr+a=jst@mozilla.org
extensions/cookie/nsCookiePromptService.cpp
--- a/extensions/cookie/nsCookiePromptService.cpp
+++ b/extensions/cookie/nsCookiePromptService.cpp
@@ -34,16 +34,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #include "nsCookiePromptService.h"
 #include "nsICookie.h"
 #include "nsICookieAcceptDialog.h"
 #include "nsIDOMWindow.h"
+#include "nsPIDOMWindow.h"
 #include "nsIWindowWatcher.h"
 #include "nsIServiceManager.h"
 #include "nsString.h"
 #include "nsIDialogParamBlock.h"
 #include "nsIMutableArray.h"
 
 /****************************************************************
  ************************ nsCookiePromptService *****************
@@ -88,21 +89,32 @@ nsCookiePromptService::CookieDialog(nsID
   block->SetObjects(objects);
 
   nsCOMPtr<nsIWindowWatcher> wwatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsISupports> arguments = do_QueryInterface(block);
   nsCOMPtr<nsIDOMWindow> dialog;
 
-  // Given the nature of this dialog and the frequency of it popping
-  // up for those few users that have it enabled we do not want this
-  // dialog to be parented at a window. Pass in nsnull as the
-  // parent. See bug 405239 for more details.
-  rv = wwatcher->OpenWindow(nsnull, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
+  nsCOMPtr<nsIDOMWindow> parent(aParent);
+  if (!parent) // if no parent provided, consult the window watcher:
+    wwatcher->GetActiveWindow(getter_AddRefs(parent));
+
+  if (parent) {
+    nsCOMPtr<nsPIDOMWindow> privateParent(do_QueryInterface(parent));
+    if (privateParent)
+      privateParent = privateParent->GetPrivateRoot();
+    parent = do_QueryInterface(privateParent);
+  }
+
+  // The cookie dialog will be modal for the root chrome window rather than the
+  // tab containing the permission-requesting page.  This removes confusion
+  // about which monitor is displaying the dialog (see bug 470356), but also
+  // avoids unwanted tab switches (see bug 405239).
+  rv = wwatcher->OpenWindow(parent, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
                             "centerscreen,chrome,modal,titlebar", arguments,
                             getter_AddRefs(dialog));
 
   if (NS_FAILED(rv)) return rv;
 
   // get back output parameters
   PRBool tempValue;
   block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);