From a2778c903370f895aedc8f747c65ad73208708fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 4 Sep 2024 20:18:55 +0000 Subject: [PATCH] Bug 1911977 - Minor clean-ups in nsDocShell::InternalLoad. r=smaug Use const and the same style for download and JS checks. Differential Revision: https://phabricator.services.mozilla.com/D221028 --- docshell/base/nsDocShell.cpp | 47 +++++++++++++++------------------- uriloader/base/nsDocLoader.cpp | 2 +- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 1a0711d843ba..2b31d3050f45 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -9270,43 +9270,39 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, // XXXbz mTiming should know what channel it's for, so we don't // need this hackery. - bool toBeReset = false; - bool isJavaScript = SchemeIsJavascript(aLoadState->URI()); + const bool isJavaScript = SchemeIsJavascript(aLoadState->URI()); + const bool isDownload = !aLoadState->FileName().IsVoid(); + const bool toBeReset = !isJavaScript && MaybeInitTiming(); - if (!isJavaScript) { - toBeReset = MaybeInitTiming(); - } - bool isNotDownload = aLoadState->FileName().IsVoid(); - if (mTiming && isNotDownload) { + // FIXME(emilio): Should this be done by javascript: uris? What about external + // protocols? + if (mTiming && !isDownload) { mTiming->NotifyBeforeUnload(); } // Check if the page doesn't want to be unloaded. The javascript: // protocol handler deals with this for javascript: URLs. - if (!isJavaScript && isNotDownload && + if (!isJavaScript && !isDownload && !aLoadState->NotifiedBeforeUnloadListeners() && mDocumentViewer) { - bool okToUnload; - // Check if request is exempted from HTTPSOnlyMode and if https-first is // enabled, if so it means: // * https-first failed to upgrade request to https // * we already asked for permission to unload and the user accepted // otherwise we wouldn't be here. - bool isPrivateWin = GetOriginAttributes().IsPrivateBrowsing(); - bool isHistoryOrReload = false; - uint32_t loadType = aLoadState->LoadType(); + const bool isPrivateWin = GetOriginAttributes().IsPrivateBrowsing(); + const uint32_t loadType = aLoadState->LoadType(); // Check if request is a reload. - if (loadType == LOAD_RELOAD_NORMAL || + const bool isHistoryOrReload = + loadType == LOAD_RELOAD_NORMAL || loadType == LOAD_RELOAD_BYPASS_CACHE || loadType == LOAD_RELOAD_BYPASS_PROXY || loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE || - loadType == LOAD_HISTORY) { - isHistoryOrReload = true; - } + loadType == LOAD_HISTORY; // If it isn't a reload, the request already failed to be upgraded and // https-first is enabled then don't ask the user again for permission to // unload and just unload. + bool okToUnload; if (!isHistoryOrReload && aLoadState->IsExemptFromHTTPSFirstMode() && nsHTTPSOnlyUtils::IsHttpsFirstModeEnabled(isPrivateWin)) { rv = mDocumentViewer->PermitUnload( @@ -9324,7 +9320,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, } } - if (mTiming && isNotDownload) { + if (mTiming && !isDownload) { mTiming->NotifyUnloadAccepted(mCurrentURI); } @@ -9358,7 +9354,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, // new request parameter. // Also pass nullptr for the document, since it doesn't affect the return // value for our purposes here. - bool savePresentation = + const bool savePresentation = CanSavePresentation(aLoadState->LoadType(), nullptr, nullptr, /* aReportBFCacheComboTelemetry */ true); @@ -9379,12 +9375,12 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, } } - // Don't stop current network activity for javascript: URL's since - // they might not result in any data, and thus nothing should be - // stopped in those cases. In the case where they do result in - // data, the javascript: URL channel takes care of stopping - // current network activity. - if (!isJavaScript && isNotDownload) { + // Don't stop current network activity for javascript: URL's since they might + // not result in any data, and thus nothing should be stopped in those cases. + // In the case where they do result in data, the javascript: URL channel takes + // care of stopping current network activity. Similarly, downloads don't + // unload this document... + if (!isJavaScript && !isDownload) { // Stop any current network activity. // Also stop content if this is a zombie doc. otherwise // the onload will be delayed by other loads initiated in the @@ -9392,7 +9388,6 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, // didn't fully load before the next load was initiated. // If not a zombie, don't stop content until data // starts arriving from the new URI... - if ((mDocumentViewer && mDocumentViewer->GetPreviousViewer()) || LOAD_TYPE_HAS_FLAGS(aLoadState->LoadType(), LOAD_FLAGS_STOP_CONTENT)) { rv = Stop(nsIWebNavigation::STOP_ALL); diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index fe72a2715da8..3156444e6165 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -242,7 +242,7 @@ nsresult nsDocLoader::AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader) { } // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230) -MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocLoader::Stop(void) { +MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocLoader::Stop() { nsresult rv = NS_OK; MOZ_LOG(gDocLoaderLog, LogLevel::Debug,