Bug 818559 - Don't ask to unload if we know we're going to download. r=smaug

This commit is contained in:
Benjamin Peterson 2012-12-07 20:35:17 -05:00
Родитель 30a7312ec3
Коммит 9832aabc4c
4 изменённых файлов: 18 добавлений и 8 удалений

Просмотреть файл

@ -23,6 +23,7 @@ function test () {
function testLink(link, name, next) {
addWindowListener("chrome://mozapps/content/downloads/unknownContentType.xul", function (win) {
is(doc.getElementById("unload-flag").textContent, "Okay", "beforeunload shouldn't have fired");
is(win.document.getElementById("location").value, name, "file name should match");
win.close();
next();
@ -117,4 +118,4 @@ TabOpenListener.prototype = {
this.closecallback = null;
}
}
};
};

Просмотреть файл

@ -33,10 +33,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=676619
li.appendChild(a);
document.getElementsByTagName('ul')[0].appendChild(li);
window.addEventListener("beforeunload", function (evt) {
document.getElementById("unload-flag").textContent = "Fail";
});
</script>
<ul>
<li><a href="http://example.com/"
download="example.com" id="link7" target="_blank">Download "example.com"</a></li>
<ul>
<div id="unload-flag">Okay</div>
</body>
</html>

Просмотреть файл

@ -8982,12 +8982,13 @@ nsDocShell::InternalLoad(nsIURI * aURI,
if (!bIsJavascript) {
MaybeInitTiming();
}
if (mTiming) {
bool timeBeforeUnload = mTiming && aFileName.IsVoid();
if (timeBeforeUnload) {
mTiming->NotifyBeforeUnload();
}
// Check if the page doesn't want to be unloaded. The javascript:
// protocol handler deals with this for javascript: URLs.
if (!bIsJavascript && mContentViewer) {
if (!bIsJavascript && aFileName.IsVoid() && mContentViewer) {
bool okToUnload;
rv = mContentViewer->PermitUnload(false, &okToUnload);
@ -8998,7 +8999,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
}
}
if (mTiming) {
if (timeBeforeUnload) {
mTiming->NotifyUnloadAccepted(mCurrentURI);
}

Просмотреть файл

@ -785,10 +785,13 @@ nsJSChannel::EvaluateScript()
nsLoadFlags loadFlags;
mStreamChannel->GetLoadFlags(&loadFlags);
if (loadFlags & LOAD_DOCUMENT_URI) {
// We're loaded as the document channel. If we go on,
// we'll blow away the current document. Make sure that's
// ok. If so, stop all pending network loads.
uint32_t disposition;
if (NS_FAILED(mStreamChannel->GetContentDisposition(&disposition)))
disposition = nsIChannel::DISPOSITION_INLINE;
if (loadFlags & LOAD_DOCUMENT_URI && disposition != nsIChannel::DISPOSITION_ATTACHMENT) {
// We're loaded as the document channel and not expecting to download
// the result. If we go on, we'll blow away the current document. Make
// sure that's ok. If so, stop all pending network loads.
nsCOMPtr<nsIDocShell> docShell;
NS_QueryNotificationCallbacks(mStreamChannel, docShell);