Bug 833971 LDAP password requested for each lookup even if password is saved - obtain a window to pass to the password manager so that it can detect private browsing even though this isn't supported in mail. r=Neil,a=Standard8
authorMark Banner <bugzilla@standard8.plus.com>
Tue, 09 Apr 2013 20:44:47 +0100
changeset 14980 d5ea73d10f3aa3459707a753f477aafed4bde002
parent 14979 147ec991f2dd4291145cc36d513db0cf36c843a4
child 14981 9277665dfff33ea2c36cff019bbb59e31635dd10
push id873
push userbugzilla@standard8.plus.com
push dateTue, 09 Apr 2013 19:47:37 +0000
treeherdercomm-beta@1d1de403c584 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil, Standard8
bugs833971
Bug 833971 LDAP password requested for each lookup even if password is saved - obtain a window to pass to the password manager so that it can detect private browsing even though this isn't supported in mail. r=Neil,a=Standard8
mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
--- a/mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsAbLDAPListenerBase.h"
 #include "nsIWindowWatcher.h"
+#include "nsIWindowMediator.h"
 #include "nsIDOMWindow.h"
 #include "nsIAuthPrompt.h"
 #include "nsIStringBundle.h"
 #include "nsILDAPMessage.h"
 #include "nsILDAPErrors.h"
 #include "nsILoginManager.h"
 #include "nsILoginInfo.h"
 #include "nsServiceManagerUtils.h"
@@ -140,47 +141,58 @@ NS_IMETHODIMP nsAbLDAPListenerBase::OnLD
     {
       NS_ERROR("nsAbLDAPListenerBase::OnLDAPInit():"
                "error getting 'authPromptText' string from bundle "
                "chrome://mozldap/locale/ldap.properties");
       InitFailed();
       return rv;
     }
 
+    // get the window mediator service, so we can get an auth prompter
+    //
+    nsCOMPtr<nsIWindowMediator> windowMediator =
+      do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
+    if (NS_FAILED(rv))
+    {
+      NS_ERROR("nsAbLDAPListenerBase::OnLDAPInit():"
+               " couldn't get window mediator service.");
+      InitFailed();
+      return rv;
+    }
+
+    // get the addressbook window, as it will be used to parent the auth
+    // prompter dialog
+    //
+    nsCOMPtr<nsIDOMWindow> window;
+    rv = windowMediator->GetMostRecentWindow(nullptr,
+                                               getter_AddRefs(window));
+    if (NS_FAILED(rv))
+    {
+      NS_ERROR("nsAbLDAPListenerBase::OnLDAPInit():"
+               " error getting most recent window");
+      InitFailed();
+      return rv;
+    }
+
     // get the window watcher service, so we can get an auth prompter
     //
     nsCOMPtr<nsIWindowWatcher> windowWatcherSvc = 
       do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
     if (NS_FAILED(rv))
     {
       NS_ERROR("nsAbLDAPListenerBase::OnLDAPInit():"
                " couldn't get window watcher service.");
       InitFailed();
       return rv;
     }
 
-    // get the addressbook window, as it will be used to parent the auth
-    // prompter dialog
-    //
-    nsCOMPtr<nsIDOMWindow> abDOMWindow;
-    rv = windowWatcherSvc->GetWindowByName(NS_LITERAL_STRING("addressbookWindow").get(),
-                                           nullptr,
-                                           getter_AddRefs(abDOMWindow));
-    if (NS_FAILED(rv))
-    {
-      NS_ERROR("nsAbLDAPListenerBase::OnLDAPInit():"
-               " error getting addressbook Window");
-      InitFailed();
-      return rv;
-    }
-
     // get the auth prompter itself
     //
     nsCOMPtr<nsIAuthPrompt> authPrompter;
-    rv = windowWatcherSvc->GetNewAuthPrompter(abDOMWindow,
+    rv = windowWatcherSvc->GetNewAuthPrompter(window,
                                               getter_AddRefs(authPrompter));
     if (NS_FAILED(rv))
     {
       NS_ERROR("nsAbLDAPMessageBase::OnLDAPInit():"
                " error getting auth prompter");
       InitFailed();
       return rv;
     }