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-04 20:18:55 +00:00
Родитель 7bb3833689
Коммит a2778c9033
2 изменённых файлов: 22 добавлений и 27 удалений

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

@ -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);

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

@ -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,