Bug 1551264 - Move user-initiated flag for form submission from HTMLFormElement to HTMLFormSubmission; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D30945

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edgar Chen 2019-05-14 12:41:19 +00:00
Родитель 4534b7e9ee
Коммит 2617857bc6
3 изменённых файлов: 13 добавлений и 9 удалений

Просмотреть файл

@ -9,7 +9,6 @@
#include "jsapi.h" #include "jsapi.h"
#include "mozilla/ContentEvents.h" #include "mozilla/ContentEvents.h"
#include "mozilla/EventDispatcher.h" #include "mozilla/EventDispatcher.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h" #include "mozilla/EventStates.h"
#include "mozilla/dom/nsCSPUtils.h" #include "mozilla/dom/nsCSPUtils.h"
#include "mozilla/dom/nsCSPContext.h" #include "mozilla/dom/nsCSPContext.h"
@ -115,7 +114,6 @@ HTMLFormElement::HTMLFormElement(
mDeferSubmission(false), mDeferSubmission(false),
mNotifiedObservers(false), mNotifiedObservers(false),
mNotifiedObserversResult(false), mNotifiedObserversResult(false),
mSubmitInitiatedFromUserInput(false),
mEverTriedInvalidSubmit(false) { mEverTriedInvalidSubmit(false) {
// We start out valid. // We start out valid.
AddStatesSilently(NS_EVENT_STATE_VALID); AddStatesSilently(NS_EVENT_STATE_VALID);
@ -571,8 +569,6 @@ nsresult HTMLFormElement::DoSubmit(WidgetEvent* aEvent) {
mSubmitPopupState = PopupBlocker::openAbused; mSubmitPopupState = PopupBlocker::openAbused;
} }
mSubmitInitiatedFromUserInput = EventStateManager::IsHandlingUserInput();
if (mDeferSubmission) { if (mDeferSubmission) {
// we are in an event handler, JS submitted so we have to // we are in an event handler, JS submitted so we have to
// defer this submission. let's remember it and return // defer this submission. let's remember it and return
@ -696,7 +692,7 @@ nsresult HTMLFormElement::SubmitSubmission(
nsAutoPopupStatePusher popupStatePusher(mSubmitPopupState); nsAutoPopupStatePusher popupStatePusher(mSubmitPopupState);
AutoHandlingUserInputStatePusher userInpStatePusher( AutoHandlingUserInputStatePusher userInpStatePusher(
mSubmitInitiatedFromUserInput, nullptr, doc); aFormSubmission->IsInitiatedFromUserInput(), nullptr, doc);
nsCOMPtr<nsIInputStream> postDataStream; nsCOMPtr<nsIInputStream> postDataStream;
rv = aFormSubmission->GetEncodedSubmission( rv = aFormSubmission->GetEncodedSubmission(
@ -708,7 +704,7 @@ nsresult HTMLFormElement::SubmitSubmission(
rv = linkHandler->OnLinkClickSync( rv = linkHandler->OnLinkClickSync(
this, actionURI, target, VoidString(), postDataStream, nullptr, false, this, actionURI, target, VoidString(), postDataStream, nullptr, false,
getter_AddRefs(docShell), getter_AddRefs(mSubmittingRequest), getter_AddRefs(docShell), getter_AddRefs(mSubmittingRequest),
EventStateManager::IsHandlingUserInput()); aFormSubmission->IsInitiatedFromUserInput());
NS_ENSURE_SUBMIT_SUCCESS(rv); NS_ENSURE_SUBMIT_SUCCESS(rv);
} }

Просмотреть файл

@ -594,8 +594,6 @@ class HTMLFormElement final : public nsGenericHTMLElement,
bool mNotifiedObservers; bool mNotifiedObservers;
/** If we notified the listeners early, what was the result? */ /** If we notified the listeners early, what was the result? */
bool mNotifiedObserversResult; bool mNotifiedObserversResult;
/** Keep track of whether a submission was user-initiated or not */
bool mSubmitInitiatedFromUserInput;
/** /**
* Whether the submission of this form has been ever prevented because of * Whether the submission of this form has been ever prevented because of
* being invalid. * being invalid.

Просмотреть файл

@ -9,6 +9,7 @@
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/EventStateManager.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "mozilla/Encoding.h" #include "mozilla/Encoding.h"
#include "nsString.h" #include "nsString.h"
@ -103,6 +104,11 @@ class HTMLFormSubmission {
*/ */
void GetTarget(nsAString& aTarget) { aTarget = mTarget; } void GetTarget(nsAString& aTarget) { aTarget = mTarget; }
/**
* Return true if this form submission was user-initiated.
*/
bool IsInitiatedFromUserInput() const { return mInitiatedFromUserInput; }
protected: protected:
/** /**
* Can only be constructed by subclasses. * Can only be constructed by subclasses.
@ -116,7 +122,8 @@ class HTMLFormSubmission {
: mActionURL(aActionURL), : mActionURL(aActionURL),
mTarget(aTarget), mTarget(aTarget),
mEncoding(aEncoding), mEncoding(aEncoding),
mOriginatingElement(aOriginatingElement) { mOriginatingElement(aOriginatingElement),
mInitiatedFromUserInput(EventStateManager::IsHandlingUserInput()) {
MOZ_COUNT_CTOR(HTMLFormSubmission); MOZ_COUNT_CTOR(HTMLFormSubmission);
} }
@ -131,6 +138,9 @@ class HTMLFormSubmission {
// Originating element. // Originating element.
RefPtr<Element> mOriginatingElement; RefPtr<Element> mOriginatingElement;
// Keep track of whether this form submission was user-initiated or not
bool mInitiatedFromUserInput;
}; };
class EncodingFormSubmission : public HTMLFormSubmission { class EncodingFormSubmission : public HTMLFormSubmission {