Skip to content

Commit

Permalink
Bug 1699003 - Simplify initial about:blank detection in SetCurrentURI…
Browse files Browse the repository at this point in the history
…, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D109110
  • Loading branch information
mystor committed Mar 22, 2021
1 parent 6805775 commit 79390b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
32 changes: 21 additions & 11 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,9 @@ void nsDocShell::FirePageHideShowNonRecursive(bool aShow) {

nsCOMPtr<nsIChannel> channel = doc->GetChannel();
if (channel) {
SetCurrentURI(doc->GetDocumentURI(), channel, true, 0);
SetCurrentURI(doc->GetDocumentURI(), channel,
/* aFireOnLocationChange */ true,
/* aIsInitialAboutBlank */ false, /* aLocationFlags */ 0);
mEODForCurrentDocument = false;
mIsRestoringDocument = true;
mLoadGroup->AddRequest(channel, nullptr);
Expand Down Expand Up @@ -1477,12 +1479,14 @@ NS_IMETHODIMP
nsDocShell::SetCurrentURI(nsIURI* aURI) {
// Note that securityUI will set STATE_IS_INSECURE, even if
// the scheme of |aURI| is "https".
SetCurrentURI(aURI, nullptr, true, 0);
SetCurrentURI(aURI, nullptr, /* aFireOnLocationChange */ true,
/* aIsInitialAboutBlank */ false, /* aLocationFlags */ 0);
return NS_OK;
}

bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
bool aFireOnLocationChange,
bool aIsInitialAboutBlank,
uint32_t aLocationFlags) {
MOZ_ASSERT(!mIsBeingDestroyed);

Expand Down Expand Up @@ -1512,11 +1516,11 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
mHasLoadedNonBlankURI = true;
}

// Don't bother firing onLocationChange when creating a subframe's initial
// about:blank document, as this can happen when it's not safe for us to run
// script.
if (!(mLoadingEntry || mLSHE) && !mHasLoadedNonBlankURI && !aRequest &&
aLocationFlags == 0 && !mBrowsingContext->IsTop()) {
// Don't fire onLocationChange when creating a subframe's initial about:blank
// document, as this can happen when it's not safe for us to run script.
if (aIsInitialAboutBlank && !mHasLoadedNonBlankURI &&
!mBrowsingContext->IsTop()) {
MOZ_ASSERT(!aRequest && aLocationFlags == 0);
return false;
}

Expand Down Expand Up @@ -6885,7 +6889,9 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
rv = Embed(viewer, aActor, true, false);
NS_ENSURE_SUCCESS(rv, rv);

SetCurrentURI(blankDoc->GetDocumentURI(), nullptr, true, 0);
SetCurrentURI(blankDoc->GetDocumentURI(), nullptr,
/* aFireLocationChange */ true,
/* aIsInitialAboutBlank */ true, /* aLocationFlags */ 0);
rv = mIsBeingDestroyed ? NS_ERROR_NOT_AVAILABLE : NS_OK;
}
}
Expand Down Expand Up @@ -7678,7 +7684,8 @@ nsresult nsDocShell::RestoreFromHistory() {
// origLSHE we don't have to worry about whether the entry in question
// is still mLSHE or whether it's now mOSHE.
nsCOMPtr<nsIURI> uri = origLSHE->GetURI();
SetCurrentURI(uri, document->GetChannel(), true, 0);
SetCurrentURI(uri, document->GetChannel(), /* aFireLocationChange */ true,
/* aIsInitialAboutBlank */ false, /* aLocationFlags */ 0);
}

// This is the end of our CreateContentViewer() replacement.
Expand Down Expand Up @@ -11121,7 +11128,8 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
aCloneSHChildren ? uint32_t(LOCATION_CHANGE_SAME_DOCUMENT) : 0;

bool onLocationChangeNeeded =
SetCurrentURI(aURI, aChannel, aFireOnLocationChange, locationFlags);
SetCurrentURI(aURI, aChannel, aFireOnLocationChange,
/* aIsInitialAboutBlank */ false, locationFlags);
// Make sure to store the referrer from the channel, if any
SetupReferrerInfoFromChannel(aChannel);
return onLocationChangeNeeded;
Expand Down Expand Up @@ -11527,7 +11535,9 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
// can't load into a docshell that is being destroyed.
if (!aEqualURIs && !mIsBeingDestroyed) {
aDocument->SetDocumentURI(aNewURI);
SetCurrentURI(aNewURI, nullptr, true, LOCATION_CHANGE_SAME_DOCUMENT);
SetCurrentURI(aNewURI, nullptr, /* aFireLocationChange */ true,
/* aIsInitialAboutBlank */ false,
LOCATION_CHANGE_SAME_DOCUMENT);

AddURIVisit(aNewURI, aCurrentURI, 0);

Expand Down
3 changes: 2 additions & 1 deletion docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ class nsDocShell final : public nsDocLoader,
// FireOnLocationChange is called.
// In all other cases false is returned.
bool SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
bool aFireOnLocationChange, uint32_t aLocationFlags);
bool aFireOnLocationChange, bool aIsInitialAboutBlank,
uint32_t aLocationFlags);

// The following methods deal with saving and restoring content viewers
// in session history.
Expand Down

0 comments on commit 79390b2

Please sign in to comment.