Bug 774633 - Move the call to SetInitialPrincipalToSubject into nsAppShellService::RegisterTopLevelWindow. r=jst

This means that we get the correct principal on the window before sending notifying
any consumers about the window's creation.
This commit is contained in:
Bobby Holley 2012-09-05 11:32:06 -07:00
parent 76dfb3183c
commit bf0b5bba7c
2 changed files with 12 additions and 10 deletions

View File

@ -878,6 +878,10 @@ nsWindowWatcher::OpenWindowInternal(nsIDOMWindow *aParent,
nsCOMPtr<nsPIDOMWindow> newDebugWindow = do_GetInterface(newDocShell);
NS_ASSERTION(newWindow == newDebugWindow, "Different windows??");
#endif
// The principal of the initial about:blank document gets set up in
// nsWindowWatcher::AddWindow. Make sure to call it. In the common case
// this call already happened when the window was created, but
// SetInitialPrincipalToSubject is safe to call multiple times.
if (newWindow) {
newWindow->SetInitialPrincipalToSubject();
}

View File

@ -19,6 +19,7 @@
#include "nsIWindowWatcher.h"
#include "nsPIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsWebShellWindow.h"
#include "nsIEnumerator.h"
@ -450,6 +451,11 @@ nsAppShellService::GetApplicationProvidedHiddenWindow(bool* aAPHW)
NS_IMETHODIMP
nsAppShellService::RegisterTopLevelWindow(nsIXULWindow* aWindow)
{
nsCOMPtr<nsIDocShell> docShell;
aWindow->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsPIDOMWindow> domWindow(do_GetInterface(docShell));
domWindow->SetInitialPrincipalToSubject();
// tell the window mediator about the new window
nsCOMPtr<nsIWindowMediator> mediator
( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) );
@ -461,16 +467,8 @@ nsAppShellService::RegisterTopLevelWindow(nsIXULWindow* aWindow)
// tell the window watcher about the new window
nsCOMPtr<nsPIWindowWatcher> wwatcher ( do_GetService(NS_WINDOWWATCHER_CONTRACTID) );
NS_ASSERTION(wwatcher, "No windowwatcher?");
if (wwatcher) {
nsCOMPtr<nsIDocShell> docShell;
aWindow->GetDocShell(getter_AddRefs(docShell));
NS_ASSERTION(docShell, "Window has no docshell");
if (docShell) {
nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docShell));
NS_ASSERTION(domWindow, "Couldn't get DOM window.");
if (domWindow)
wwatcher->AddWindow(domWindow, 0);
}
if (wwatcher && domWindow) {
wwatcher->AddWindow(domWindow, 0);
}
// an ongoing attempt to quit is stopped by a newly opened window