diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 43e54a69d8a6..2da821ce6afd 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -13358,6 +13358,7 @@ public: int64_t aPostDataStreamLength, nsIInputStream* aHeadersDataStream, bool aNoOpenerImplied, + bool aIsUserTriggered, bool aIsTrusted, nsIPrincipal* aTriggeringPrincipal); @@ -13376,7 +13377,8 @@ public: mTargetSpec.get(), mFileName, mPostDataStream, mPostDataStreamLength, mHeadersDataStream, mNoOpenerImplied, - nullptr, nullptr, mTriggeringPrincipal); + nullptr, nullptr, mIsUserTriggered, + mTriggeringPrincipal); } return NS_OK; } @@ -13392,6 +13394,7 @@ private: nsCOMPtr mContent; PopupControlState mPopupState; bool mNoOpenerImplied; + bool mIsUserTriggered; bool mIsTrusted; nsCOMPtr mTriggeringPrincipal; }; @@ -13405,6 +13408,7 @@ OnLinkClickEvent::OnLinkClickEvent(nsDocShell* aHandler, int64_t aPostDataStreamLength, nsIInputStream* aHeadersDataStream, bool aNoOpenerImplied, + bool aIsUserTriggered, bool aIsTrusted, nsIPrincipal* aTriggeringPrincipal) : mozilla::Runnable("OnLinkClickEvent") @@ -13418,6 +13422,7 @@ OnLinkClickEvent::OnLinkClickEvent(nsDocShell* aHandler, , mContent(aContent) , mPopupState(mHandler->mScriptGlobal->GetPopupControlState()) , mNoOpenerImplied(aNoOpenerImplied) + , mIsUserTriggered(aIsUserTriggered) , mIsTrusted(aIsTrusted) , mTriggeringPrincipal(aTriggeringPrincipal) { @@ -13431,6 +13436,7 @@ nsDocShell::OnLinkClick(nsIContent* aContent, nsIInputStream* aPostDataStream, int64_t aPostDataStreamLength, nsIInputStream* aHeadersDataStream, + bool aIsUserTriggered, bool aIsTrusted, nsIPrincipal* aTriggeringPrincipal) { @@ -13477,7 +13483,7 @@ nsDocShell::OnLinkClick(nsIContent* aContent, new OnLinkClickEvent(this, aContent, aURI, target.get(), aFileName, aPostDataStream, aPostDataStreamLength, aHeadersDataStream, noOpenerImplied, - aIsTrusted, aTriggeringPrincipal); + aIsUserTriggered, aIsTrusted, aTriggeringPrincipal); return DispatchToTabGroup(TaskCategory::UI, ev.forget()); } @@ -13500,6 +13506,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, bool aNoOpenerImplied, nsIDocShell** aDocShell, nsIRequest** aRequest, + bool aIsUserTriggered, nsIPrincipal* aTriggeringPrincipal) { // Initialize the DocShell / Request @@ -13638,6 +13645,10 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, GetIsExecutingOnLoadHandler(&inOnLoadHandler); uint32_t loadType = inOnLoadHandler ? LOAD_NORMAL_REPLACE : LOAD_LINK; + if (aIsUserTriggered) { + flags |= INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED; + } + nsresult rv = InternalLoad(clonedURI, // New URI nullptr, // Original URI Nothing(), // Let the protocol handler assign it diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 7ff0f7040d7b..6e6c26156ea8 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -210,6 +210,7 @@ public: nsIInputStream* aPostDataStream, int64_t aPostDataStreamLength, nsIInputStream* aHeadersDataStream, + bool aIsUserTriggered, bool aIsTrusted, nsIPrincipal* aTriggeringPrincipal) override; NS_IMETHOD OnLinkClickSync(nsIContent* aContent, @@ -222,6 +223,7 @@ public: bool aNoOpenerImplied = false, nsIDocShell** aDocShell = 0, nsIRequest** aRequest = 0, + bool aIsUserTriggered = false, nsIPrincipal* aTriggeringPrincipal = nullptr) override; NS_IMETHOD OnOverLink(nsIContent* aContent, nsIURI* aURI, diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 4c3035c3ae9b..f02ef43cb582 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -139,6 +139,9 @@ interface nsIDocShell : nsIDocShellTreeItem // Whether a top-level data URI navigation is allowed for that load const long INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI = 0x200; + // Whether the load was triggered by user interaction. + const long INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED = 0x1000; + /** * Loads the given URI. This method is identical to loadURI(...) except * that its parameter list is broken out instead of being packaged inside diff --git a/docshell/base/nsILinkHandler.h b/docshell/base/nsILinkHandler.h index d28f0b487fb4..eaed03452467 100644 --- a/docshell/base/nsILinkHandler.h +++ b/docshell/base/nsILinkHandler.h @@ -49,6 +49,7 @@ public: nsIInputStream* aPostDataStream, int64_t aPostDataStreamLength, nsIInputStream* aHeadersDataStream, + bool aIsUserTriggered, bool aIsTrusted, nsIPrincipal* aTriggeringPrincipal) = 0; @@ -82,6 +83,7 @@ public: bool aNoOpenerImplied = false, nsIDocShell** aDocShell = 0, nsIRequest** aRequest = 0, + bool aIsUserTriggered = false, nsIPrincipal* aTriggeringPrincipal = nullptr) = 0; /** diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 832816ca5390..39cdba0dace4 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -5544,8 +5544,8 @@ nsContentUtils::TriggerLink(nsIContent *aContent, nsPresContext *aPresContext, handler->OnLinkClick(aContent, aLinkURI, fileName.IsVoid() ? aTargetSpec.get() : EmptyString().get(), - fileName, nullptr, -1, nullptr, aIsTrusted, - aContent->NodePrincipal()); + fileName, nullptr, -1, nullptr, EventStateManager::IsHandlingUserInput(), + aIsTrusted, aContent->NodePrincipal()); } } diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index ed56f278448d..2874e596874b 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -784,7 +784,8 @@ HTMLFormElement::SubmitSubmission(HTMLFormSubmission* aFormSubmission) postDataStream, postDataStreamLength, nullptr, false, getter_AddRefs(docShell), - getter_AddRefs(mSubmittingRequest)); + getter_AddRefs(mSubmittingRequest), + EventStateManager::IsHandlingUserInput()); NS_ENSURE_SUBMIT_SUCCESS(rv); } diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index e4fd3774cb7b..044d887594ca 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -485,7 +485,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, } rv = lh->OnLinkClick(content, uri, unitarget.get(), VoidString(), - aPostStream, -1, headersDataStream, true, triggeringPrincipal); + aPostStream, -1, headersDataStream, + /* isUserTriggered */ false, + /* isTrusted */ true, triggeringPrincipal); return rv; }