diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index 1ac2f3a6c55..17e072e93de 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -3027,8 +3027,13 @@ nsHTMLDocument::GetSelection(nsAString& aReturn)
consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get());
}
- nsIDOMWindow *window = GetWindow();
- NS_ENSURE_TRUE(window, NS_OK);
+ nsCOMPtr window = do_QueryInterface(GetScopeObject());
+ nsCOMPtr pwin = do_QueryInterface(window);
+ NS_ENSURE_TRUE(pwin, NS_OK);
+ NS_ASSERTION(pwin->IsInnerWindow(), "Should have inner window here!");
+ NS_ENSURE_TRUE(pwin->GetOuterWindow() &&
+ pwin->GetOuterWindow()->GetCurrentInnerWindow() == pwin,
+ NS_OK);
nsCOMPtr selection;
nsresult rv = window->GetSelection(getter_AddRefs(selection));