Bug 1397512 - Part 1: Use LOAD_NORMAL_REPLACE in OnLinkClickSync if it's running inside an onload handler. r?smaug
MozReview-Commit-ID: BILgS0XTAIc
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -14457,32 +14457,38 @@ nsDocShell::OnLinkClickSync(nsIContent*
}
// if the triggeringPrincipal is not passed explicitly, then we
// fall back to using doc->NodePrincipal() as the triggeringPrincipal.
nsCOMPtr<nsIPrincipal> triggeringPrincipal =
aTriggeringPrincipal ? aTriggeringPrincipal
: aContent->NodePrincipal();
+ // Link click (or form submission) can be triggered inside an onload handler,
+ // and we don't want to add history entry in this case.
+ bool inOnLoadHandler = false;
+ GetIsExecutingOnLoadHandler(&inOnLoadHandler);
+ uint32_t loadType = inOnLoadHandler ? LOAD_NORMAL_REPLACE : LOAD_LINK;
+
nsresult rv = InternalLoad(clonedURI, // New URI
nullptr, // Original URI
Nothing(), // Let the protocol handler assign it
false, // LoadReplace
referer, // Referer URI
refererPolicy, // Referer policy
triggeringPrincipal,
aContent->NodePrincipal(),
flags,
target, // Window target
NS_LossyConvertUTF16toASCII(typeHint).get(),
aFileName, // Download as file
aPostDataStream, // Post data stream
aPostDataStreamLength, // Post data stream length
aHeadersDataStream, // Headers stream
- LOAD_LINK, // Load type
+ loadType, // Load type
nullptr, // No SHEntry
true, // first party site
VoidString(), // No srcdoc
this, // We are the source
nullptr, // baseURI not needed
true, // Check for prerendered doc
aDocShell, // DocShell out-param
aRequest); // Request out-param