Bug 1911977 - Don't abort networking activity on external protocol navigations. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D221029
This commit is contained in:
Emilio Cobos Álvarez
2024-09-04 20:18:55 +00:00
parent 9f46207409
commit ae7187bdd7
2 changed files with 10 additions and 2 deletions

View File

@@ -9271,6 +9271,8 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
// XXXbz mTiming should know what channel it's for, so we don't // XXXbz mTiming should know what channel it's for, so we don't
// need this hackery. // need this hackery.
const bool isJavaScript = SchemeIsJavascript(aLoadState->URI()); const bool isJavaScript = SchemeIsJavascript(aLoadState->URI());
const bool isExternalProtocol =
nsContentUtils::IsExternalProtocol(aLoadState->URI());
const bool isDownload = !aLoadState->FileName().IsVoid(); const bool isDownload = !aLoadState->FileName().IsVoid();
const bool toBeReset = !isJavaScript && MaybeInitTiming(); const bool toBeReset = !isJavaScript && MaybeInitTiming();
@@ -9281,6 +9283,9 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
} }
// Check if the page doesn't want to be unloaded. The javascript: // Check if the page doesn't want to be unloaded. The javascript:
// protocol handler deals with this for javascript: URLs. // protocol handler deals with this for javascript: URLs.
// NOTE(emilio): As of this writing, other browsers fire beforeunload for
// external protocols, so keep doing that even though they don't return data
// and thus we won't really unload this...
if (!isJavaScript && !isDownload && if (!isJavaScript && !isDownload &&
!aLoadState->NotifiedBeforeUnloadListeners() && mDocumentViewer) { !aLoadState->NotifiedBeforeUnloadListeners() && mDocumentViewer) {
// Check if request is exempted from HTTPSOnlyMode and if https-first is // Check if request is exempted from HTTPSOnlyMode and if https-first is
@@ -9380,7 +9385,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
// In the case where they do result in data, the javascript: URL channel takes // In the case where they do result in data, the javascript: URL channel takes
// care of stopping current network activity. Similarly, downloads don't // care of stopping current network activity. Similarly, downloads don't
// unload this document... // unload this document...
if (!isJavaScript && !isDownload) { if (!isJavaScript && !isDownload && !isExternalProtocol) {
// Stop any current network activity. // Stop any current network activity.
// Also stop content if this is a zombie doc. otherwise // Also stop content if this is a zombie doc. otherwise
// the onload will be delayed by other loads initiated in the // the onload will be delayed by other loads initiated in the

View File

@@ -3,8 +3,11 @@
onbeforeunload = function() { onbeforeunload = function() {
opener.onChildBeforeUnload(); opener.onChildBeforeUnload();
}; };
onload = function() { onload = async function() {
let ongoingLoad = fetch(location.href);
location.href = "this-protocol-is-unlikely-to-exist://foo"; location.href = "this-protocol-is-unlikely-to-exist://foo";
// Load shouldn't be canceled.
await ongoingLoad;
setTimeout(function() { setTimeout(function() {
opener.onChildLoadTimedOut(); opener.onChildLoadTimedOut();
}, 1000); }, 1000);