Skip to content

Commit

Permalink
Bug 793433 - Fix crash when nsAppShellService::RegisterTopLevelWindow…
Browse files Browse the repository at this point in the history
… called with invalid arguments. r=bholley
  • Loading branch information
foudfou committed Oct 9, 2012
1 parent c7d55df commit 6664771
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion js/xpconnect/tests/chrome/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ MOCHITEST_CHROME_FILES = \
test_bug763343.xul \
test_bug771429.xul \
test_bug773962.xul \
test_bug793433.xul \
test_bug795275.xul \
test_APIExposer.xul \
test_chrometoSource.xul \
Expand All @@ -60,7 +61,6 @@ MOCHITEST_CHROME_FILES = \
test_weakmaps.xul \
test_weakref.xul \
test_wrappers.xul \
test_bug720619.xul \
$(NULL)

# Disabled until this test gets updated to test the new proxy based
Expand Down
48 changes: 48 additions & 0 deletions js/xpconnect/tests/chrome/test_bug793433.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=793433
-->
<window title="Mozilla Bug 793433"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=793433"
target="_blank">Mozilla Bug 793433</a>
<p id="display"></p>
<div id="content" style="display: none"/>
</body>

<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
const Cc = Components.classes;
const Ci = Components.interfaces;
function shouldThrow(fun, args, msg) {
try {
fun.apply(this, args);
ok(false, msg);
} catch (e) {
ok(true, msg+" -- "+e);
}
}
function do_registerTopLevelWindow(win) {
Cc['@mozilla.org/appshell/appShellService;1'].
getService(Ci.nsIAppShellService).registerTopLevelWindow(win);
}
shouldThrow(
do_registerTopLevelWindow, [null],
"registering null as a top-level window should throw");
shouldThrow(
do_registerTopLevelWindow, [{}],
"registering a void object as a top-level window should throw");
]]></script>
</window>
13 changes: 8 additions & 5 deletions xpfe/appshell/src/nsAppShellService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ nsAppShellService::CreateHiddenWindow()
{
nsresult rv;
int32_t initialHeight = 100, initialWidth = 100;

#ifdef XP_MACOSX
uint32_t chromeMask = 0;
nsAdoptingCString prefVal =
Expand Down Expand Up @@ -349,7 +349,7 @@ nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent,
nsresult rv = window->Initialize(parent, center ? aParent : nullptr,
aUrl, aInitialWidth, aInitialHeight,
aIsHiddenWindow, widgetInitData);

NS_ENSURE_SUCCESS(rv, rv);

window.swap(*aResult); // transfer reference
Expand Down Expand Up @@ -381,7 +381,7 @@ nsAppShellService::GetHiddenDOMWindow(nsIDOMWindow **aWindow)

rv = mHiddenWindow->GetDocShell(getter_AddRefs(docShell));
NS_ENSURE_SUCCESS(rv, rv);

nsCOMPtr<nsIDOMWindow> hiddenDOMWindow(do_GetInterface(docShell, &rv));
NS_ENSURE_SUCCESS(rv, rv);

Expand Down Expand Up @@ -451,9 +451,12 @@ nsAppShellService::GetApplicationProvidedHiddenWindow(bool* aAPHW)
NS_IMETHODIMP
nsAppShellService::RegisterTopLevelWindow(nsIXULWindow* aWindow)
{
NS_ENSURE_ARG_POINTER(aWindow);

nsCOMPtr<nsIDocShell> docShell;
aWindow->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsPIDOMWindow> domWindow(do_GetInterface(docShell));
NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
domWindow->SetInitialPrincipalToSubject();

// tell the window mediator about the new window
Expand Down Expand Up @@ -497,7 +500,7 @@ nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow)
*/
return NS_ERROR_FAILURE;
}

NS_ENSURE_ARG_POINTER(aWindow);

if (aWindow == mHiddenWindow) {
Expand All @@ -512,7 +515,7 @@ nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow)

if (mediator)
mediator->UnregisterWindow(aWindow);

// tell the window watcher
nsCOMPtr<nsPIWindowWatcher> wwatcher ( do_GetService(NS_WINDOWWATCHER_CONTRACTID) );
NS_ASSERTION(wwatcher, "Couldn't get windowwatcher, doing xpcom shutdown?");
Expand Down

0 comments on commit 6664771

Please sign in to comment.