Skip to content

Commit c8e38a7

Browse files
committed
Revert "Bug 1991265 - Make push to replace load conversion follow spec. r=smaug" for causing wpt failures.
This reverts commit 91a14bd.
1 parent b383d13 commit c8e38a7

File tree

48 files changed

+152
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+152
-244
lines changed

docshell/base/BrowsingContext.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,6 @@ nsresult BrowsingContext::LoadURI(nsDocShellLoadState* aLoadState,
21272127

21282128
if (mDocShell) {
21292129
nsCOMPtr<nsIDocShell> docShell = mDocShell;
2130-
21312130
return docShell->LoadURI(aLoadState, aSetNavigating);
21322131
}
21332132

@@ -2438,7 +2437,7 @@ BrowsingContext::CheckURLAndCreateLoadState(nsIURI* aURI,
24382437
void BrowsingContext::Navigate(nsIURI* aURI, nsIPrincipal& aSubjectPrincipal,
24392438
ErrorResult& aRv,
24402439
NavigationHistoryBehavior aHistoryHandling,
2441-
bool aNeedsCompletelyLoadedDocument) {
2440+
bool aShouldNotForceReplaceInOnLoad) {
24422441
MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug, "Navigate to {} as {}", *aURI,
24432442
aHistoryHandling);
24442443
CallerType callerType = aSubjectPrincipal.IsSystemPrincipal()
@@ -2457,16 +2456,27 @@ void BrowsingContext::Navigate(nsIURI* aURI, nsIPrincipal& aSubjectPrincipal,
24572456
return;
24582457
}
24592458

2460-
if (mozilla::SessionHistoryInParent()) {
2461-
loadState->SetNeedsCompletelyLoadedDocument(aNeedsCompletelyLoadedDocument);
2462-
2463-
loadState->SetShouldNotForceReplaceInOnLoad(
2464-
/* aShouldNotForceReplaceInOnLoad */ true);
2459+
loadState->SetShouldNotForceReplaceInOnLoad(aShouldNotForceReplaceInOnLoad);
24652460

2466-
loadState->SetHistoryBehavior(aHistoryHandling);
2461+
// Step 12
2462+
NavigationHistoryBehavior historyHandling = aHistoryHandling;
2463+
if (aHistoryHandling == NavigationHistoryBehavior::Auto) {
2464+
if (auto* document = GetExtantDocument()) {
2465+
bool equals = false;
2466+
aURI->Equals(document->GetDocumentURI(), &equals);
2467+
if (equals && document->GetPrincipal()) {
2468+
document->GetPrincipal()->Equals(&aSubjectPrincipal, &equals);
2469+
}
2470+
if (equals) {
2471+
historyHandling = NavigationHistoryBehavior::Replace;
2472+
} else {
2473+
historyHandling = NavigationHistoryBehavior::Push;
2474+
}
2475+
}
24672476
}
24682477

2469-
if (aHistoryHandling == NavigationHistoryBehavior::Replace) {
2478+
// Step 13 of #navigate are handled later in nsDocShell::InternalLoad().
2479+
if (historyHandling == NavigationHistoryBehavior::Replace) {
24702480
loadState->SetLoadType(LOAD_STOP_CONTENT_AND_REPLACE);
24712481
} else {
24722482
loadState->SetLoadType(LOAD_STOP_CONTENT);

docshell/base/BrowsingContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
459459
void Navigate(nsIURI* aURI, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv,
460460
NavigationHistoryBehavior aHistoryHandling =
461461
NavigationHistoryBehavior::Auto,
462-
bool aNeedsCompletelyLoadedDocument = false);
462+
bool aShouldNotForceReplaceInOnLoad = false);
463463

464464
// Removes the root document for this BrowsingContext tree from the BFCache,
465465
// if it is cached, and returns true if it was.

docshell/base/nsDocShell.cpp

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
#include "mozilla/dom/Navigation.h"
7373
#include "mozilla/dom/NavigationBinding.h"
7474
#include "mozilla/dom/NavigationHistoryEntry.h"
75-
#include "mozilla/dom/NavigationUtils.h"
7675
#include "mozilla/dom/PerformanceNavigation.h"
7776
#include "mozilla/dom/PermissionMessageUtils.h"
7877
#include "mozilla/dom/PolicyContainer.h"
@@ -8730,7 +8729,6 @@ struct SameDocumentNavigationState {
87308729
bool mSameExceptHashes = false;
87318730
bool mSecureUpgradeURI = false;
87328731
bool mHistoryNavBetweenSameDoc = false;
8733-
bool mIdentical = false;
87348732
};
87358733

87368734
bool nsDocShell::IsSameDocumentNavigation(nsDocShellLoadState* aLoadState,
@@ -8836,12 +8834,6 @@ bool nsDocShell::IsSameDocumentNavigation(nsDocShellLoadState* aLoadState,
88368834
}
88378835
}
88388836

8839-
// Two URIs are identical if they're same except hashes, they both have
8840-
// hashes, and their hashes are the same.
8841-
aState.mIdentical = aState.mSameExceptHashes &&
8842-
(aState.mNewURIHasRef == aState.mCurrentURIHasRef) &&
8843-
aState.mCurrentHash.Equals(aState.mNewHash);
8844-
88458837
// A same document navigation happens when we navigate between two SHEntries
88468838
// for the same document. We do a same document navigation under two
88478839
// circumstances. Either
@@ -9389,8 +9381,10 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
93899381
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#updating-the-document
93909382
navigation->UpdateEntriesForSameDocumentNavigation(
93919383
mActiveEntry.get(),
9392-
NavigationUtils::NavigationTypeFromLoadType(mLoadType).valueOr(
9393-
NavigationType::Push));
9384+
LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)
9385+
? NavigationType::Replace
9386+
: aLoadState->LoadIsFromSessionHistory() ? NavigationType::Traverse
9387+
: NavigationType::Push);
93949388
}
93959389

93969390
// Fire a hashchange event URIs differ, and only in their hashes.
@@ -9471,34 +9465,6 @@ uint32_t nsDocShell::GetLoadTypeForFormSubmission(
94719465
: LOAD_LINK;
94729466
}
94739467

9474-
static void MaybeConvertToReplaceLoad(nsDocShellLoadState* aLoadState,
9475-
Document* aExtantDocument,
9476-
bool aIdenticalURI) {
9477-
if (!aExtantDocument || !mozilla::SessionHistoryInParent()) {
9478-
return;
9479-
}
9480-
9481-
bool convertToReplaceLoad = aLoadState->NeedsCompletelyLoadedDocument() &&
9482-
!aExtantDocument->IsCompletelyLoaded();
9483-
if (const auto& historyBehavior = aLoadState->HistoryBehavior();
9484-
!convertToReplaceLoad && historyBehavior &&
9485-
*historyBehavior == NavigationHistoryBehavior::Auto) {
9486-
convertToReplaceLoad = aIdenticalURI;
9487-
if (convertToReplaceLoad && aExtantDocument->GetPrincipal()) {
9488-
aExtantDocument->GetPrincipal()->Equals(aLoadState->TriggeringPrincipal(),
9489-
&convertToReplaceLoad);
9490-
}
9491-
}
9492-
9493-
if (convertToReplaceLoad) {
9494-
MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug,
9495-
"Convert to replace when navigating from {} to {}",
9496-
*aExtantDocument->GetDocumentURI(), *aLoadState->URI());
9497-
aLoadState->SetLoadType(MaybeAddLoadFlags(
9498-
aLoadState->LoadType(), nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY));
9499-
}
9500-
}
9501-
95029468
// InternalLoad performs several of the steps from
95039469
// https://html.spec.whatwg.org/#navigate.
95049470
nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
@@ -9559,11 +9525,6 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
95599525
IsSameDocumentNavigation(aLoadState, sameDocumentNavigationState) &&
95609526
!aLoadState->GetPendingRedirectedChannel();
95619527

9562-
if (mLoadType != LOAD_ERROR_PAGE) {
9563-
MaybeConvertToReplaceLoad(aLoadState, GetExtantDocument(),
9564-
sameDocumentNavigationState.mIdentical);
9565-
}
9566-
95679528
// Note: We do this check both here and in BrowsingContext::
95689529
// LoadURI/InternalLoad, since document-specific sandbox flags are only
95699530
// available in the process triggering the load, and we don't want the target

docshell/base/nsDocShellLoadState.cpp

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ nsDocShellLoadState::nsDocShellLoadState(
7171
mOriginalFrameSrc = aLoadState.OriginalFrameSrc();
7272
mShouldCheckForRecursion = aLoadState.ShouldCheckForRecursion();
7373
mIsFormSubmission = aLoadState.IsFormSubmission();
74-
mShouldNotForceReplaceInOnLoad = aLoadState.ShouldNotForceReplaceInOnLoad();
75-
mNeedsCompletelyLoadedDocument = aLoadState.NeedsCompletelyLoadedDocument();
76-
mHistoryBehavior = aLoadState.HistoryBehavior();
7774
mLoadType = aLoadState.LoadType();
7875
mTarget = aLoadState.Target();
7976
mTargetBrowsingContext = aLoadState.TargetBrowsingContext();
@@ -175,6 +172,7 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
175172
mInheritPrincipal(aOther.mInheritPrincipal),
176173
mPrincipalIsExplicit(aOther.mPrincipalIsExplicit),
177174
mNotifiedBeforeUnloadListeners(aOther.mNotifiedBeforeUnloadListeners),
175+
mShouldNotForceReplaceInOnLoad(aOther.mShouldNotForceReplaceInOnLoad),
178176
mPrincipalToInherit(aOther.mPrincipalToInherit),
179177
mPartitionedPrincipalToInherit(aOther.mPartitionedPrincipalToInherit),
180178
mForceAllowDataURI(aOther.mForceAllowDataURI),
@@ -183,9 +181,6 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
183181
mOriginalFrameSrc(aOther.mOriginalFrameSrc),
184182
mShouldCheckForRecursion(aOther.mShouldCheckForRecursion),
185183
mIsFormSubmission(aOther.mIsFormSubmission),
186-
mShouldNotForceReplaceInOnLoad(aOther.mShouldNotForceReplaceInOnLoad),
187-
mNeedsCompletelyLoadedDocument(aOther.mNeedsCompletelyLoadedDocument),
188-
mHistoryBehavior(aOther.mHistoryBehavior),
189184
mLoadType(aOther.mLoadType),
190185
mSHEntry(aOther.mSHEntry),
191186
mTarget(aOther.mTarget),
@@ -240,14 +235,12 @@ nsDocShellLoadState::nsDocShellLoadState(nsIURI* aURI, uint64_t aLoadIdentifier)
240235
mInheritPrincipal(false),
241236
mPrincipalIsExplicit(false),
242237
mNotifiedBeforeUnloadListeners(false),
238+
mShouldNotForceReplaceInOnLoad(false),
243239
mForceAllowDataURI(false),
244240
mIsExemptFromHTTPSFirstMode(false),
245241
mOriginalFrameSrc(false),
246242
mShouldCheckForRecursion(false),
247243
mIsFormSubmission(false),
248-
mShouldNotForceReplaceInOnLoad(false),
249-
mNeedsCompletelyLoadedDocument(false),
250-
mHistoryBehavior(Nothing()),
251244
mLoadType(LOAD_NORMAL),
252245
mSrcdocData(VoidString()),
253246
mLoadFlags(0),
@@ -677,6 +670,15 @@ void nsDocShellLoadState::SetNotifiedBeforeUnloadListeners(
677670
mNotifiedBeforeUnloadListeners = aNotifiedBeforeUnloadListeners;
678671
}
679672

673+
bool nsDocShellLoadState::ShouldNotForceReplaceInOnLoad() const {
674+
return mShouldNotForceReplaceInOnLoad;
675+
}
676+
677+
void nsDocShellLoadState::SetShouldNotForceReplaceInOnLoad(
678+
bool aShouldNotForceReplaceInOnLoad) {
679+
mShouldNotForceReplaceInOnLoad = aShouldNotForceReplaceInOnLoad;
680+
}
681+
680682
bool nsDocShellLoadState::ForceAllowDataURI() const {
681683
return mForceAllowDataURI;
682684
}
@@ -725,34 +727,6 @@ void nsDocShellLoadState::SetIsFormSubmission(bool aIsFormSubmission) {
725727
mIsFormSubmission = aIsFormSubmission;
726728
}
727729

728-
bool nsDocShellLoadState::ShouldNotForceReplaceInOnLoad() const {
729-
return mShouldNotForceReplaceInOnLoad;
730-
}
731-
732-
void nsDocShellLoadState::SetShouldNotForceReplaceInOnLoad(
733-
bool aShouldNotForceReplaceInOnLoad) {
734-
mShouldNotForceReplaceInOnLoad = aShouldNotForceReplaceInOnLoad;
735-
}
736-
737-
bool nsDocShellLoadState::NeedsCompletelyLoadedDocument() const {
738-
return mNeedsCompletelyLoadedDocument;
739-
}
740-
741-
void nsDocShellLoadState::SetNeedsCompletelyLoadedDocument(
742-
bool aNeedsCompletelyLoadedDocument) {
743-
mNeedsCompletelyLoadedDocument = aNeedsCompletelyLoadedDocument;
744-
}
745-
746-
Maybe<mozilla::dom::NavigationHistoryBehavior>
747-
nsDocShellLoadState::HistoryBehavior() const {
748-
return mHistoryBehavior;
749-
}
750-
751-
void nsDocShellLoadState::SetHistoryBehavior(
752-
mozilla::dom::NavigationHistoryBehavior aHistoryBehavior) {
753-
mHistoryBehavior = Some(aHistoryBehavior);
754-
}
755-
756730
uint32_t nsDocShellLoadState::LoadType() const { return mLoadType; }
757731

758732
void nsDocShellLoadState::SetLoadType(uint32_t aLoadType) {
@@ -1403,9 +1377,6 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize(
14031377
loadState.OriginalFrameSrc() = mOriginalFrameSrc;
14041378
loadState.ShouldCheckForRecursion() = mShouldCheckForRecursion;
14051379
loadState.IsFormSubmission() = mIsFormSubmission;
1406-
loadState.ShouldNotForceReplaceInOnLoad() = mShouldNotForceReplaceInOnLoad;
1407-
loadState.NeedsCompletelyLoadedDocument() = mNeedsCompletelyLoadedDocument;
1408-
loadState.HistoryBehavior() = mHistoryBehavior;
14091380
loadState.LoadType() = mLoadType;
14101381
loadState.userNavigationInvolvement() = mUserNavigationInvolvement;
14111382
loadState.Target() = mTarget;

docshell/base/nsDocShellLoadState.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,6 @@ class nsDocShellLoadState final {
178178

179179
void SetIsFormSubmission(bool aIsFormSubmission);
180180

181-
bool NeedsCompletelyLoadedDocument() const;
182-
183-
void SetNeedsCompletelyLoadedDocument(bool aNeedsCompletelyLoadedDocument);
184-
185-
mozilla::Maybe<mozilla::dom::NavigationHistoryBehavior> HistoryBehavior()
186-
const;
187-
188-
void SetHistoryBehavior(
189-
mozilla::dom::NavigationHistoryBehavior aHistoryBehavior);
190-
191181
uint32_t LoadType() const;
192182

193183
void SetLoadType(uint32_t aLoadType);
@@ -552,6 +542,10 @@ class nsDocShellLoadState final {
552542
// notified if applicable.
553543
bool mNotifiedBeforeUnloadListeners;
554544

545+
// If this attribute is true, navigations for subframes taking place inside of
546+
// an onload handler will not be changed to replace loads.
547+
bool mShouldNotForceReplaceInOnLoad;
548+
555549
// Principal we're inheriting. If null, this means the principal should be
556550
// inherited from the current document. If set to NullPrincipal, the channel
557551
// will fill in principal information later in the load. See internal comments
@@ -591,18 +585,6 @@ class nsDocShellLoadState final {
591585
// form submission.
592586
bool mIsFormSubmission;
593587

594-
// If this attribute is true, navigations for subframes taking place inside of
595-
// an onload handler will not be changed to replace loads.
596-
bool mShouldNotForceReplaceInOnLoad;
597-
598-
// If this attribute is true, we need to check if the current document is
599-
// completely loaded to determine if we should perform a push or replace load.
600-
bool mNeedsCompletelyLoadedDocument;
601-
602-
// If this attribute is `Auto`, we should determine if this should be a push
603-
// or replace load when actually loading.
604-
mozilla::Maybe<mozilla::dom::NavigationHistoryBehavior> mHistoryBehavior;
605-
606588
// Contains a load type as specified by the nsDocShellLoadTypes::load*
607589
// constants
608590
uint32_t mLoadType;

docshell/base/nsDocShellLoadTypes.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
# define MAKE_LOAD_TYPE(type, flags) ((type) | ((flags) << 16))
2323
# define LOAD_TYPE_HAS_FLAGS(type, flags) ((type) & ((flags) << 16))
24-
# define LOAD_TYPE_SET_FLAGS(type, flags) ((type) | ((flags) << 16))
2524

2625
/**
2726
* These are flags that confuse ConvertLoadTypeToDocShellLoadInfo and should
@@ -202,17 +201,5 @@ inline nsDOMNavigationTiming::Type ConvertLoadTypeToNavigationType(
202201
return result;
203202
}
204203

205-
static inline uint32_t MaybeAddLoadFlags(uint32_t aLoadType, uint32_t aFlags) {
206-
uint32_t loadType = LOAD_TYPE_SET_FLAGS(aLoadType, aFlags);
207-
if (IsValidLoadType(loadType)) {
208-
return loadType;
209-
}
210-
211-
NS_WARNING("Adjusting load flags results in an invalid load type.");
212-
return aLoadType;
213-
}
214-
215-
# undef LOAD_TYPE_SET_FLAGS
216-
217204
#endif // MOZILLA_INTERNAL_API
218205
#endif

docshell/test/chrome/bug311007_window.xhtml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ function step2A() {
114114
}
115115

116116
function step2B(aWebProgress, aRequest, aLocation, aFlags) {
117-
content.addEventListener(
118-
'load',
119-
() => step2C(aWebProgress, aRequest, aLocation, aFlags),
120-
{once: true});
121-
}
122-
123-
function step2C(aWebProgress, aRequest, aLocation, aFlags) {
124117
is(aLocation.spec, kSecureURI, "A URI on HTTPS (2)");
125118

126119
ok(!(aFlags & Ci.nsIWebProgressListener

dom/base/Document.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,6 @@ Document::Document(const char* aContentType)
13911391
mHaveFiredTitleChange(false),
13921392
mIsShowing(false),
13931393
mVisible(true),
1394-
mIsCompletelyLoaded(false),
13951394
mRemovedFromDocShell(false),
13961395
// mAllowDNSPrefetch starts true, so that we can always reliably && it
13971396
// with various values that might disable it. Since we never prefetch
@@ -12573,8 +12572,6 @@ void Document::OnPageShow(bool aPersisted, EventTarget* aDispatchStartTarget,
1257312572
if (auto* wgc = GetWindowGlobalChild()) {
1257412573
wgc->UnblockBFCacheFor(BFCacheStatus::PAGE_LOADING);
1257512574
}
12576-
12577-
mIsCompletelyLoaded = true;
1257812575
}
1257912576

1258012577
static void DispatchFullscreenChange(Document& aDocument, nsINode* aTarget) {

dom/base/Document.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,20 +2676,12 @@ class Document : public nsINode,
26762676
* called yet.
26772677
*/
26782678
bool IsShowing() const { return mIsShowing; }
2679-
26802679
/**
26812680
* Return whether the document is currently visible (in the sense of
26822681
* OnPageHide having been called and OnPageShow not yet having been called)
26832682
*/
26842683
bool IsVisible() const { return mVisible; }
26852684

2686-
/**
2687-
* Return whether the document has completely finished loading, in the spec
2688-
* sense. We only store a bool though, whereas spec stores when loading
2689-
* finished. See https://html.spec.whatwg.org/#completely-loaded-time
2690-
*/
2691-
bool IsCompletelyLoaded() const { return mIsCompletelyLoaded; }
2692-
26932685
void SetSuppressedEventListener(EventListener* aListener);
26942686

26952687
EventListener* GetSuppressedEventListener() {
@@ -4846,10 +4838,6 @@ class Document : public nsINode,
48464838
// it's false only when we're in bfcache or unloaded.
48474839
bool mVisible : 1;
48484840

4849-
// State for IsCompletelyLoaded. Starts off false and becomes true after
4850-
// pageshow has fired. Doesn't reset after that.
4851-
bool mIsCompletelyLoaded : 1;
4852-
48534841
// True if our content viewer has been removed from the docshell
48544842
// (it may still be displayed, but in zombie state). Form control data
48554843
// has been saved.

0 commit comments

Comments
 (0)