@@ -971,10 +971,21 @@ bool nsDocShell::MaybeHandleSubframeHistory(
971
971
// executing an onLoad Handler,this load will not go
972
972
// into session history.
973
973
// XXX Why is this code in a method which deals with iframes!
974
- bool inOnLoadHandler = false ;
975
- GetIsExecutingOnLoadHandler (&inOnLoadHandler);
976
- if (inOnLoadHandler) {
977
- aLoadState->SetLoadType (LOAD_NORMAL_REPLACE);
974
+ if (aLoadState->IsFormSubmission ()) {
975
+ #ifdef DEBUG
976
+ if (!mEODForCurrentDocument ) {
977
+ const MaybeDiscarded<BrowsingContext>& targetBC =
978
+ aLoadState->TargetBrowsingContext ();
979
+ MOZ_ASSERT_IF (GetBrowsingContext () == targetBC.get (),
980
+ aLoadState->LoadType () == LOAD_NORMAL_REPLACE);
981
+ }
982
+ #endif
983
+ } else {
984
+ bool inOnLoadHandler = false ;
985
+ GetIsExecutingOnLoadHandler (&inOnLoadHandler);
986
+ if (inOnLoadHandler) {
987
+ aLoadState->SetLoadType (LOAD_NORMAL_REPLACE);
988
+ }
978
989
}
979
990
}
980
991
return false ;
@@ -8561,7 +8572,7 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
8561
8572
// Explicit principal because we do not want any guesses as to what the
8562
8573
// principal to inherit is: it should be aTriggeringPrincipal.
8563
8574
loadState->SetPrincipalIsExplicit (true );
8564
- loadState->SetLoadType (LOAD_LINK );
8575
+ loadState->SetLoadType (aLoadState-> LoadType () );
8565
8576
loadState->SetForceAllowDataURI (aLoadState->HasInternalLoadFlags (
8566
8577
INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI));
8567
8578
@@ -8613,6 +8624,11 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
8613
8624
}
8614
8625
8615
8626
aLoadState->SetTargetBrowsingContext (targetContext);
8627
+ if (aLoadState->IsFormSubmission ()) {
8628
+ aLoadState->SetLoadType (
8629
+ GetLoadTypeForFormSubmission (targetContext, aLoadState));
8630
+ }
8631
+
8616
8632
//
8617
8633
// Transfer the load to the target BrowsingContext... Clear the window target
8618
8634
// name to the empty string to prevent recursive retargeting!
@@ -9226,6 +9242,20 @@ static bool NavigationShouldTakeFocus(nsDocShell* aDocShell,
9226
9242
return !Preferences::GetBool (" browser.tabs.loadDivertedInBackground" , false );
9227
9243
}
9228
9244
9245
+ uint32_t nsDocShell::GetLoadTypeForFormSubmission (
9246
+ BrowsingContext* aTargetBC, nsDocShellLoadState* aLoadState) {
9247
+ MOZ_ASSERT (aLoadState->IsFormSubmission ());
9248
+
9249
+ // https://html.spec.whatwg.org/#form-submission-algorithm
9250
+ // 22. Let historyHandling be "push".
9251
+ // 23. If form document equals targetNavigable's active document, and
9252
+ // form document has not yet completely loaded, then set
9253
+ // historyHandling to "replace".
9254
+ return GetBrowsingContext () == aTargetBC && !mEODForCurrentDocument
9255
+ ? LOAD_NORMAL_REPLACE
9256
+ : LOAD_LINK;
9257
+ }
9258
+
9229
9259
nsresult nsDocShell::InternalLoad (nsDocShellLoadState* aLoadState,
9230
9260
Maybe<uint32_t > aCacheKey) {
9231
9261
MOZ_ASSERT (aLoadState, " need a load state!" );
@@ -9265,6 +9295,8 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
9265
9295
return PerformRetargeting (aLoadState);
9266
9296
}
9267
9297
9298
+ // This is the non-retargeting load path, we've already set the right loadtype
9299
+ // for form submissions in nsDocShell::OnLinkClickSync.
9268
9300
if (aLoadState->TargetBrowsingContext ().IsNull ()) {
9269
9301
aLoadState->SetTargetBrowsingContext (GetBrowsingContext ());
9270
9302
}
@@ -13084,11 +13116,24 @@ nsresult nsDocShell::OnLinkClickSync(nsIContent* aContent,
13084
13116
CopyUTF8toUTF16 (type, typeHint);
13085
13117
}
13086
13118
13087
- // Link click (or form submission) can be triggered inside an onload
13088
- // handler, and we don't want to add history entry in this case.
13089
- bool inOnLoadHandler = false ;
13090
- GetIsExecutingOnLoadHandler (&inOnLoadHandler);
13091
- uint32_t loadType = inOnLoadHandler ? LOAD_NORMAL_REPLACE : LOAD_LINK;
13119
+ uint32_t loadType = LOAD_LINK;
13120
+ if (aLoadState->IsFormSubmission ()) {
13121
+ if (aLoadState->Target ().IsEmpty ()) {
13122
+ // We set the right load type here for form submissions with an empty
13123
+ // target. Form submission with a non-empty target are handled in
13124
+ // nsDocShell::PerformRetargeting after we've selected the correct target
13125
+ // BC.
13126
+ loadType = GetLoadTypeForFormSubmission (GetBrowsingContext (), aLoadState);
13127
+ }
13128
+ } else {
13129
+ // Link click can be triggered inside an onload handler, and we don't want
13130
+ // to add history entry in this case.
13131
+ bool inOnLoadHandler = false ;
13132
+ GetIsExecutingOnLoadHandler (&inOnLoadHandler);
13133
+ if (inOnLoadHandler) {
13134
+ loadType = LOAD_NORMAL_REPLACE;
13135
+ }
13136
+ }
13092
13137
13093
13138
nsCOMPtr<nsIReferrerInfo> referrerInfo =
13094
13139
elementCanHaveNoopener ? new ReferrerInfo (*aContent->AsElement ())
0 commit comments