Bug 103452: When window.close() is called, close the tab for that content window, not the whole (XUL) window. r=hewitt, sr=jag, sr=jst

git-svn-id: svn://10.0.0.236/trunk@122718 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jaggernaut%netscape.com 2002-06-05 00:31:45 +00:00
parent a15b86895e
commit 96adc87948
2 changed files with 42 additions and 0 deletions

View File

@ -2983,6 +2983,34 @@ GlobalWindowImpl::Close()
return NS_OK;
}
// Fire a DOM event notifying listeners that this window is about to
// be closed. The tab UI code may choose to cancel the default
// action for this event, if so, we won't actually close the window
// (since the tab UI code will close the tab in stead). Sure, this
// could be abused by content code, but do we care? I don't think
// so...
nsCOMPtr<nsIDOMDocumentEvent> doc(do_QueryInterface(mDocument));
nsCOMPtr<nsIDOMEvent> event;
if (doc) {
doc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
}
if (event) {
event->InitEvent(NS_LITERAL_STRING("DOMWindowClose"), PR_TRUE, PR_TRUE);
PRBool executeDefault = PR_TRUE;
DispatchEvent(event, &executeDefault);
if (!executeDefault) {
// Someone chose to prevent the default action for this event,
// if so, let's not close this window after all...
return NS_OK;
}
}
// Note: the basic security check, rejecting windows not opened through JS,
// has been removed. This was approved long ago by ...you're going to call me
// on this, aren't you... well it was. And anyway, a better means is coming.

View File

@ -1128,6 +1128,20 @@
<handlers>
<handler event="keypress" modifiers="control" keycode="vk_f4" action="this.removeCurrentTab();"/>
<handler event="DOMWindowClose">
<![CDATA[
const browser = this.browsers;
if (browser.length == 1)
return;
var i = 0;
for (; i < browsers.length; ++i) {
if (browsers[i].contentWindow == event.target)
break;
}
this.removeTab(this.mTabContainer.childNodes[i]);
event.preventDefault();
]]>
</handler>
</handlers>
</binding>