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
This commit is contained in:
Emilio Cobos Álvarez 2024-09-05 17:08:39 +00:00
parent 13a6dc30e5
commit 69d03391c0
2 changed files with 22 additions and 27 deletions

View File

@ -9270,43 +9270,39 @@ 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.
bool toBeReset = false; const bool isJavaScript = SchemeIsJavascript(aLoadState->URI());
bool isJavaScript = SchemeIsJavascript(aLoadState->URI()); const bool isDownload = !aLoadState->FileName().IsVoid();
const bool toBeReset = !isJavaScript && MaybeInitTiming();
if (!isJavaScript) { // FIXME(emilio): Should this be done by javascript: uris? What about external
toBeReset = MaybeInitTiming(); // protocols?
} if (mTiming && !isDownload) {
bool isNotDownload = aLoadState->FileName().IsVoid();
if (mTiming && isNotDownload) {
mTiming->NotifyBeforeUnload(); mTiming->NotifyBeforeUnload();
} }
// 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.
if (!isJavaScript && isNotDownload && if (!isJavaScript && !isDownload &&
!aLoadState->NotifiedBeforeUnloadListeners() && mDocumentViewer) { !aLoadState->NotifiedBeforeUnloadListeners() && mDocumentViewer) {
bool okToUnload;
// Check if request is exempted from HTTPSOnlyMode and if https-first is // Check if request is exempted from HTTPSOnlyMode and if https-first is
// enabled, if so it means: // enabled, if so it means:
// * https-first failed to upgrade request to https // * https-first failed to upgrade request to https
// * we already asked for permission to unload and the user accepted // * we already asked for permission to unload and the user accepted
// otherwise we wouldn't be here. // otherwise we wouldn't be here.
bool isPrivateWin = GetOriginAttributes().IsPrivateBrowsing(); const bool isPrivateWin = GetOriginAttributes().IsPrivateBrowsing();
bool isHistoryOrReload = false; const uint32_t loadType = aLoadState->LoadType();
uint32_t loadType = aLoadState->LoadType();
// Check if request is a reload. // 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_CACHE ||
loadType == LOAD_RELOAD_BYPASS_PROXY || loadType == LOAD_RELOAD_BYPASS_PROXY ||
loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE || loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
loadType == LOAD_HISTORY) { loadType == LOAD_HISTORY;
isHistoryOrReload = true;
}
// If it isn't a reload, the request already failed to be upgraded and // 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 // https-first is enabled then don't ask the user again for permission to
// unload and just unload. // unload and just unload.
bool okToUnload;
if (!isHistoryOrReload && aLoadState->IsExemptFromHTTPSFirstMode() && if (!isHistoryOrReload && aLoadState->IsExemptFromHTTPSFirstMode() &&
nsHTTPSOnlyUtils::IsHttpsFirstModeEnabled(isPrivateWin)) { nsHTTPSOnlyUtils::IsHttpsFirstModeEnabled(isPrivateWin)) {
rv = mDocumentViewer->PermitUnload( rv = mDocumentViewer->PermitUnload(
@ -9324,7 +9320,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
} }
} }
if (mTiming && isNotDownload) { if (mTiming && !isDownload) {
mTiming->NotifyUnloadAccepted(mCurrentURI); mTiming->NotifyUnloadAccepted(mCurrentURI);
} }
@ -9358,7 +9354,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
// new request parameter. // new request parameter.
// Also pass nullptr for the document, since it doesn't affect the return // Also pass nullptr for the document, since it doesn't affect the return
// value for our purposes here. // value for our purposes here.
bool savePresentation = const bool savePresentation =
CanSavePresentation(aLoadState->LoadType(), nullptr, nullptr, CanSavePresentation(aLoadState->LoadType(), nullptr, nullptr,
/* aReportBFCacheComboTelemetry */ true); /* aReportBFCacheComboTelemetry */ true);
@ -9379,12 +9375,12 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
} }
} }
// Don't stop current network activity for javascript: URL's since // Don't stop current network activity for javascript: URL's since they might
// they might not result in any data, and thus nothing should be // not result in any data, and thus nothing should be stopped in those cases.
// stopped in those cases. In the case where they do result in // In the case where they do result in data, the javascript: URL channel takes
// data, the javascript: URL channel takes care of stopping // care of stopping current network activity. Similarly, downloads don't
// current network activity. // unload this document...
if (!isJavaScript && isNotDownload) { if (!isJavaScript && !isDownload) {
// 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
@ -9392,7 +9388,6 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
// didn't fully load before the next load was initiated. // didn't fully load before the next load was initiated.
// If not a zombie, don't stop content until data // If not a zombie, don't stop content until data
// starts arriving from the new URI... // starts arriving from the new URI...
if ((mDocumentViewer && mDocumentViewer->GetPreviousViewer()) || if ((mDocumentViewer && mDocumentViewer->GetPreviousViewer()) ||
LOAD_TYPE_HAS_FLAGS(aLoadState->LoadType(), LOAD_FLAGS_STOP_CONTENT)) { LOAD_TYPE_HAS_FLAGS(aLoadState->LoadType(), LOAD_FLAGS_STOP_CONTENT)) {
rv = Stop(nsIWebNavigation::STOP_ALL); rv = Stop(nsIWebNavigation::STOP_ALL);

View File

@ -242,7 +242,7 @@ nsresult nsDocLoader::AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader) {
} }
// TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230) // 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; nsresult rv = NS_OK;
MOZ_LOG(gDocLoaderLog, LogLevel::Debug, MOZ_LOG(gDocLoaderLog, LogLevel::Debug,