From 10ebae6d329e6c3650bb0a374c3426471cb12f60 Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Fri, 17 Sep 2010 14:54:40 -0700 Subject: [PATCH] bug 580128 - Fix code that expects XPConnect to hand outer windows to C++ from JS. r=peterv --- dom/base/nsDOMClassInfo.cpp | 6 ------ dom/base/nsFocusManager.cpp | 3 ++- dom/base/nsGlobalWindow.cpp | 10 +--------- security/manager/boot/src/nsSecureBrowserUIImpl.cpp | 7 ++++++- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 432c20127cc..9d23d130f9b 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -6970,15 +6970,9 @@ nsWindowSH::Equality(nsIXPConnectWrappedNative *wrapper, JSContext * cx, nsGlobalWindow *win = nsGlobalWindow::FromWrapper(wrapper); - NS_ASSERTION(win->IsOuterWindow(), - "Inner window detected in Equality hook!"); - nsCOMPtr other = do_QueryWrappedNative(other_wrapper); if (other) { - NS_ASSERTION(other->IsOuterWindow(), - "Inner window detected in Equality hook!"); - *bp = win->GetOuterWindow() == other->GetOuterWindow(); } diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 7cdc4cd6a08..4162e61abe3 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -328,7 +328,8 @@ nsFocusManager::SetActiveWindow(nsIDOMWindow* aWindow) { // only top-level windows can be made active nsCOMPtr piWindow = do_QueryInterface(aWindow); - NS_ASSERTION(!piWindow || piWindow->IsOuterWindow(), "outer window expected"); + if (piWindow) + piWindow = piWindow->GetOuterWindow(); NS_ENSURE_TRUE(piWindow && (piWindow == piWindow->GetPrivateRoot()), NS_ERROR_INVALID_ARG); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 73fce378718..03d5bd5371f 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -5717,15 +5717,7 @@ PostMessageEvent::Run() NS_IMETHODIMP nsGlobalWindow::PostMessageMoz(const nsAString& aMessage, const nsAString& aOrigin) { - // NB: Since much of what this method does must happen at event dispatch time, - // this method does not forward to the inner window, unlike most other - // methods. We do this because the only time we need to refer to this - // window, we need a reference to the outer window (the PostMessageEvent - // ctor call), and we don't want to pay the price of forwarding to the - // inner window for no actual benefit. Furthermore, this function must - // only be called from script anyway, which should only have references to - // outer windows (and if script has an inner window we've already lost). - NS_ABORT_IF_FALSE(IsOuterWindow(), "only call this method on outer windows"); + FORWARD_TO_OUTER(PostMessageMoz, (aMessage, aOrigin), NS_ERROR_NOT_INITIALIZED); // // Window.postMessage is an intentional subversion of the same-origin policy. diff --git a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index 01d478fa3c7..8fd55b8ad34 100644 --- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -223,8 +223,13 @@ nsSecureBrowserUIImpl::Init(nsIDOMWindow *aWindow) return NS_ERROR_ALREADY_INITIALIZED; } + nsCOMPtr pwin(do_QueryInterface(aWindow)); + if (pwin->IsInnerWindow()) { + pwin = pwin->GetOuterWindow(); + } + nsresult rv; - mWindow = do_GetWeakReference(aWindow, &rv); + mWindow = do_GetWeakReference(pwin, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr service(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));