Bug 1578355 - Part 1: Move user-activation code from EventStateManager to UserActivation; r=smaug

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edgar Chen 2019-09-20 20:51:25 +00:00
Родитель a6deb8b6f9
Коммит 5bc0854d2b
37 изменённых файлов: 311 добавлений и 251 удалений

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

@ -12,8 +12,8 @@
#include "States.h"
#include "xpcAccessibleDocument.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/UserActivation.h"
using namespace mozilla;
using namespace mozilla::a11y;
@ -33,7 +33,7 @@ AccEvent::AccEvent(uint32_t aEventType, Accessible* aAccessible,
EIsFromUserInput aIsFromUserInput, EEventRule aEventRule)
: mEventType(aEventType), mEventRule(aEventRule), mAccessible(aAccessible) {
if (aIsFromUserInput == eAutoDetect)
mIsFromUserInput = EventStateManager::IsHandlingUserInput();
mIsFromUserInput = dom::UserActivation::IsHandlingUserInput();
else
mIsFromUserInput = aIsFromUserInput == eFromUserInput ? true : false;
}

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

@ -69,7 +69,6 @@
#include "mozilla/Assertions.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/MouseEvents.h"
@ -83,6 +82,7 @@
#include "mozilla/dom/HTMLBodyElement.h"
#include "mozilla/dom/KeyboardEventBinding.h"
#include "mozilla/dom/TreeWalker.h"
#include "mozilla/dom/UserActivation.h"
using namespace mozilla;
using namespace mozilla::a11y;
@ -753,7 +753,7 @@ void Accessible::TakeFocus() const {
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
AutoHandlingUserInputStatePusher inputStatePusher(true);
dom::AutoHandlingUserInputStatePusher inputStatePusher(true);
// XXXbz: Can we actually have a non-element content here?
RefPtr<Element> element =
focusContent->IsElement() ? focusContent->AsElement() : nullptr;

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

@ -39,7 +39,6 @@
#include "nsFocusManager.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/HTMLEditor.h"
#include "mozilla/PresShell.h"
@ -48,6 +47,7 @@
#include "mozilla/dom/DocumentType.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/MutationEventBinding.h"
#include "mozilla/dom/UserActivation.h"
#include "HTMLElementAccessibles.h"
using namespace mozilla;
@ -287,7 +287,7 @@ void DocAccessible::TakeFocus() const {
// Focus the document.
nsFocusManager* fm = nsFocusManager::GetFocusManager();
RefPtr<dom::Element> newFocus;
AutoHandlingUserInputStatePusher inputStatePusher(true);
dom::AutoHandlingUserInputStatePusher inputStatePusher(true);
fm->MoveFocus(mDocumentNode->GetWindow(), nullptr,
nsFocusManager::MOVEFOCUS_ROOT, 0, getter_AddRefs(newFocus));
}

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

@ -66,6 +66,7 @@
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/TabGroup.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/ChildSHistory.h"
#include "mozilla/dom/nsCSPContext.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
@ -13056,7 +13057,7 @@ nsresult nsDocShell::OnLeaveLink() {
bool nsDocShell::ShouldBlockLoadingForBackButton() {
if (!(mLoadType & LOAD_CMD_HISTORY) ||
EventStateManager::IsHandlingUserInput() ||
UserActivation::IsHandlingUserInput() ||
!Preferences::GetBool("accessibility.blockjsredirection")) {
return false;
}

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

@ -113,6 +113,7 @@
#include "mozilla/dom/ShadowIncludingTreeIterator.h"
#include "mozilla/dom/StyleSheetList.h"
#include "mozilla/dom/SVGUseElement.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/net/CookieSettings.h"
#include "nsGenericHTMLElement.h"
#include "mozilla/dom/CDATASection.h"
@ -14023,7 +14024,7 @@ void Document::RequestPointerLock(Element* aElement, CallerType aCallerType) {
return;
}
bool userInputOrSystemCaller = EventStateManager::IsHandlingUserInput() ||
bool userInputOrSystemCaller = UserActivation::IsHandlingUserInput() ||
aCallerType == CallerType::System;
nsCOMPtr<nsIRunnable> request =
new PointerLockRequest(aElement, userInputOrSystemCaller);
@ -14536,13 +14537,12 @@ void Document::SetCssUseCounterBits() {
for (size_t i = 0; i < size_t(CountedUnknownProperty::Count); ++i) {
if (Servo_IsUnknownPropertyRecordedInUseCounter(
mStyleUseCounters.get(), CountedUnknownProperty(i))) {
mStyleUseCounters.get(), CountedUnknownProperty(i))) {
SetUseCounter(UseCounter(eUseCounter_FirstCountedUnknownProperty + i));
}
}
}
void Document::PropagateUseCountersToPage() {
if (mDisplayDocument) {
// If we are a resource document, we won't have a docshell and so we won't
@ -15626,7 +15626,7 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
}
// Step 8. If the browser is not processing a user gesture, reject.
if (!EventStateManager::IsHandlingUserInput()) {
if (!UserActivation::IsHandlingUserInput()) {
promise->MaybeRejectWithUndefined();
return promise.forget();
}

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

@ -5,7 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/PopupBlocker.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/TextEvents.h"
@ -185,8 +186,8 @@ PopupBlocker::PopupControlState PopupBlocker::GetEventPopupControlState(
case eBasicEventClass:
// For these following events only allow popups if they're
// triggered while handling user input. See
// EventStateManager::IsUserInteractionEvent() for details.
if (EventStateManager::IsHandlingUserInput()) {
// UserActivation::IsUserInteractionEvent() for details.
if (UserActivation::IsHandlingUserInput()) {
abuse = PopupBlocker::openBlocked;
switch (aEvent->mMessage) {
case eFormSelect:
@ -207,8 +208,8 @@ PopupBlocker::PopupControlState PopupBlocker::GetEventPopupControlState(
case eEditorInputEventClass:
// For this following event only allow popups if it's triggered
// while handling user input. See
// EventStateManager::IsUserInteractionEvent() for details.
if (EventStateManager::IsHandlingUserInput()) {
// UserActivation::IsUserInteractionEvent() for details.
if (UserActivation::IsHandlingUserInput()) {
abuse = PopupBlocker::openBlocked;
switch (aEvent->mMessage) {
case eEditorInput:
@ -224,8 +225,8 @@ PopupBlocker::PopupControlState PopupBlocker::GetEventPopupControlState(
case eInputEventClass:
// For this following event only allow popups if it's triggered
// while handling user input. See
// EventStateManager::IsUserInteractionEvent() for details.
if (EventStateManager::IsHandlingUserInput()) {
// UserActivation::IsUserInteractionEvent() for details.
if (UserActivation::IsHandlingUserInput()) {
abuse = PopupBlocker::openBlocked;
switch (aEvent->mMessage) {
case eFormChange:
@ -370,8 +371,8 @@ PopupBlocker::PopupControlState PopupBlocker::GetEventPopupControlState(
case eFormEventClass:
// For these following events only allow popups if they're
// triggered while handling user input. See
// EventStateManager::IsUserInteractionEvent() for details.
if (EventStateManager::IsHandlingUserInput()) {
// UserActivation::IsUserInteractionEvent() for details.
if (UserActivation::IsHandlingUserInput()) {
abuse = PopupBlocker::openBlocked;
switch (aEvent->mMessage) {
case eFormSubmit:

130
dom/base/UserActivation.cpp Normal file
Просмотреть файл

@ -0,0 +1,130 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/UserActivation.h"
#include "mozilla/TextEvents.h"
namespace mozilla {
namespace dom {
namespace {
// The current depth of user and keyboard inputs. sUserInputEventDepth
// is the number of any user input events, page load events and mouse over
// events. sUserKeyboardEventDepth is the number of keyboard input events.
// Incremented whenever we start handling a user input, decremented when we
// have finished handling a user input. This depth is *not* reset in case
// of nested event loops.
static int32_t sUserInputEventDepth = 0;
static int32_t sUserKeyboardEventDepth = 0;
// Time at which we began handling user input. Reset to the epoch
// once we have finished handling user input.
static TimeStamp sHandlingInputStart;
// Time at which we began handling the latest user input. Not reset
// at the end of the input.
static TimeStamp sLatestUserInputStart;
} // namespace
/* static */
bool UserActivation::IsHandlingUserInput() { return sUserInputEventDepth > 0; }
/* static */
bool UserActivation::IsHandlingKeyboardInput() {
return sUserKeyboardEventDepth > 0;
}
/* static */
bool UserActivation::IsUserInteractionEvent(const WidgetEvent* aEvent) {
if (!aEvent->IsTrusted()) {
return false;
}
switch (aEvent->mMessage) {
// eKeyboardEventClass
case eKeyPress:
case eKeyDown:
case eKeyUp:
// Not all keyboard events are treated as user input, so that popups
// can't be opened, fullscreen mode can't be started, etc at
// unexpected time.
return aEvent->AsKeyboardEvent()->CanTreatAsUserInput();
// eBasicEventClass
case eFormChange:
// eMouseEventClass
case eMouseClick:
case eMouseDown:
case eMouseUp:
// ePointerEventClass
case ePointerDown:
case ePointerUp:
// eTouchEventClass
case eTouchStart:
case eTouchEnd:
return true;
default:
return false;
}
}
/* static */
void UserActivation::StartHandlingUserInput(EventMessage aMessage) {
++sUserInputEventDepth;
if (sUserInputEventDepth == 1) {
sLatestUserInputStart = sHandlingInputStart = TimeStamp::Now();
}
if (WidgetEvent::IsKeyEventMessage(aMessage)) {
++sUserKeyboardEventDepth;
}
}
/* static */
void UserActivation::StopHandlingUserInput(EventMessage aMessage) {
--sUserInputEventDepth;
if (sUserInputEventDepth == 0) {
sHandlingInputStart = TimeStamp();
}
if (WidgetEvent::IsKeyEventMessage(aMessage)) {
--sUserKeyboardEventDepth;
}
}
/* static */
TimeStamp UserActivation::GetHandlingInputStart() {
return sHandlingInputStart;
}
/* static */
TimeStamp UserActivation::LatestUserInputStart() {
return sLatestUserInputStart;
}
//-----------------------------------------------------------------------------
// mozilla::dom::AutoHandlingUserInputStatePusher
//-----------------------------------------------------------------------------
AutoHandlingUserInputStatePusher::AutoHandlingUserInputStatePusher(
bool aIsHandlingUserInput, WidgetEvent* aEvent)
: mMessage(aEvent ? aEvent->mMessage : eVoidEvent),
mIsHandlingUserInput(aIsHandlingUserInput) {
if (!aIsHandlingUserInput) {
return;
}
UserActivation::StartHandlingUserInput(mMessage);
}
AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher() {
if (!mIsHandlingUserInput) {
return;
}
UserActivation::StopHandlingUserInput(mMessage);
}
} // namespace dom
} // namespace mozilla

75
dom/base/UserActivation.h Normal file
Просмотреть файл

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_UserAcitvation_h
#define mozilla_dom_UserAcitvation_h
#include "mozilla/EventForwards.h"
namespace mozilla {
namespace dom {
class UserActivation final {
public:
/**
* Returns true if the current code is being executed as a result of
* user input or keyboard input. The former includes anything that is
* initiated by user, with the exception of page load events or mouse
* over events. And the latter returns true when one of the user inputs
* is an input from keyboard. If these methods are called from asynchronously
* executed code, such as during layout reflows, it will return false.
*/
static bool IsHandlingUserInput();
static bool IsHandlingKeyboardInput();
/**
* Returns true if the event is considered as user interaction event. I.e.,
* enough obvious input to allow to open popup, etc. Otherwise, returns false.
*/
static bool IsUserInteractionEvent(const WidgetEvent* aEvent);
/**
* StartHandlingUserInput() is called when we start to handle a user input.
* StopHandlingUserInput() is called when we finish handling a user input.
* If the caller knows which input event caused that, it should set
* aMessage to the event message. Otherwise, set eVoidEvent.
* Note that StopHandlingUserInput() caller should call it with exactly same
* event message as its corresponding StartHandlingUserInput() call because
* these methods may count the number of specific event message.
*/
static void StartHandlingUserInput(EventMessage aMessage);
static void StopHandlingUserInput(EventMessage aMessage);
static TimeStamp GetHandlingInputStart();
/**
* Get the timestamp at which the latest user input was handled.
*
* Guaranteed to be monotonic. Until the first user input, return
* the epoch.
*/
static TimeStamp LatestUserInputStart();
};
/**
* This class is used while processing real user input. During this time, popups
* are allowed. For mousedown events, mouse capturing is also permitted.
*/
class MOZ_RAII AutoHandlingUserInputStatePusher final {
public:
explicit AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
WidgetEvent* aEvent = nullptr);
~AutoHandlingUserInputStatePusher();
protected:
EventMessage mMessage;
bool mIsHandlingUserInput;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_UserAcitvation_h

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

@ -245,6 +245,7 @@ EXPORTS.mozilla.dom += [
'TreeOrderedArrayInlines.h',
'TreeWalker.h',
'UIDirectionManager.h',
'UserActivation.h',
'ViewportMetaData.h',
'VisualViewport.h',
'WindowOrientationObserver.h',
@ -416,6 +417,7 @@ UNIFIED_SOURCES += [
'TimeoutManager.cpp',
'TreeWalker.cpp',
'UIDirectionManager.cpp',
'UserActivation.cpp',
'ViewportMetaData.cpp',
'VisualViewport.cpp',
'WindowDestroyedEvent.cpp',

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

@ -7,6 +7,8 @@
#include <map>
#include "nsCOMPtr.h"
#include "nsIPrincipal.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/Element.h"
@ -16,10 +18,8 @@
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/PContentPermissionRequestParent.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/Attributes.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/Preferences.h"
#include "mozilla/Unused.h"
#include "nsComponentManagerUtils.h"
@ -551,7 +551,7 @@ ContentPermissionRequestBase::ContentPermissionRequestBase(
mRequester(aWindow ? new nsContentPermissionRequester(aWindow) : nullptr),
mPrefName(aPrefName),
mType(aType),
mIsHandlingUserInput(EventStateManager::IsHandlingUserInput()),
mIsHandlingUserInput(UserActivation::IsHandlingUserInput()),
mUserHadInteractedWithDocument(false),
mDocumentDOMContentLoadedTimestamp(0) {
if (!aWindow) {

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

@ -78,6 +78,7 @@
#include "mozilla/dom/TouchEvent.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/XULCommandEvent.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/net/CookieSettings.h"
@ -5073,7 +5074,7 @@ void nsContentUtils::TriggerLink(nsIContent* aContent, nsIURI* aLinkURI,
nsDocShell::Cast(docShell)->OnLinkClick(
aContent, aLinkURI, fileName.IsVoid() ? aTargetSpec : EmptyString(),
fileName, nullptr, nullptr, EventStateManager::IsHandlingUserInput(),
fileName, nullptr, nullptr, UserActivation::IsHandlingUserInput(),
aIsTrusted, triggeringPrincipal, csp);
}
}
@ -6393,7 +6394,7 @@ const char* nsContentUtils::CheckRequestFullscreenAllowed(
return nullptr;
}
if (!EventStateManager::IsHandlingUserInput()) {
if (!UserActivation::IsHandlingUserInput()) {
return "FullscreenDeniedNotInputDriven";
}
@ -6402,8 +6403,7 @@ const char* nsContentUtils::CheckRequestFullscreenAllowed(
// disallow fullscreen
TimeDuration timeout = HandlingUserInputTimeout();
if (timeout > TimeDuration(nullptr) &&
(TimeStamp::Now() - EventStateManager::GetHandlingInputStart()) >
timeout) {
(TimeStamp::Now() - UserActivation::GetHandlingInputStart()) > timeout) {
return "FullscreenDeniedNotInputDriven";
}
@ -6421,7 +6421,7 @@ const char* nsContentUtils::CheckRequestFullscreenAllowed(
/* static */
bool nsContentUtils::IsCutCopyAllowed(nsIPrincipal* aSubjectPrincipal) {
if (StaticPrefs::dom_allow_cut_copy() &&
EventStateManager::IsHandlingUserInput()) {
UserActivation::IsHandlingUserInput()) {
return true;
}

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

@ -22,6 +22,7 @@
#include "mozilla/dom/DocumentInlines.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/Touch.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/PendingAnimationTracker.h"
#include "nsIObjectLoadingContent.h"
#include "nsFrame.h"
@ -42,7 +43,6 @@
#include "nsJSUtils.h"
#include "mozilla/ChaosMode.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/MiscEvents.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/PresShell.h"
@ -3240,7 +3240,7 @@ nsDOMWindowUtils::RemoveSheetUsingURIString(const nsACString& aSheetURI,
NS_IMETHODIMP
nsDOMWindowUtils::GetIsHandlingUserInput(bool* aHandlingUserInput) {
*aHandlingUserInput = EventStateManager::IsHandlingUserInput();
*aHandlingUserInput = UserActivation::IsHandlingUserInput();
return NS_OK;
}
@ -3248,7 +3248,7 @@ nsDOMWindowUtils::GetIsHandlingUserInput(bool* aHandlingUserInput) {
NS_IMETHODIMP
nsDOMWindowUtils::GetMillisSinceLastUserInput(
double* aMillisSinceLastUserInput) {
TimeStamp lastInput = EventStateManager::LatestUserInputStart();
TimeStamp lastInput = UserActivation::LatestUserInputStart();
if (lastInput.IsNull()) {
*aMillisSinceLastUserInput = -1.0f;
return NS_OK;
@ -3559,7 +3559,7 @@ NS_IMPL_ISUPPORTS(HandlingUserInputHelper, nsIJSRAIIHelper)
HandlingUserInputHelper::HandlingUserInputHelper(bool aHandlingUserInput)
: mHandlingUserInput(aHandlingUserInput), mDestructCalled(false) {
if (aHandlingUserInput) {
EventStateManager::StartHandlingUserInput(eVoidEvent);
UserActivation::StartHandlingUserInput(eVoidEvent);
}
}
@ -3579,7 +3579,7 @@ HandlingUserInputHelper::Destruct() {
mDestructCalled = true;
if (mHandlingUserInput) {
EventStateManager::StopHandlingUserInput(eVoidEvent);
UserActivation::StopHandlingUserInput(eVoidEvent);
}
return NS_OK;

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

@ -82,7 +82,6 @@
#include "mozilla/dom/PluginCrashedEvent.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/widget/IMEData.h"
@ -90,6 +89,7 @@
#include "mozilla/dom/HTMLObjectElementBinding.h"
#include "mozilla/dom/HTMLEmbedElement.h"
#include "mozilla/dom/HTMLObjectElement.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/net/UrlClassifierFeatureFactory.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/PresShell.h"
@ -2330,7 +2330,7 @@ nsresult nsObjectLoadingContent::OpenChannel() {
}
nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(httpChan));
if (cos && EventStateManager::IsHandlingUserInput()) {
if (cos && UserActivation::IsHandlingUserInput()) {
cos->AddClassFlags(nsIClassOfService::UrgentStart);
}
}

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

@ -12,7 +12,11 @@
#ifndef nsSyncLoadService_h__
#define nsSyncLoadService_h__
#include "mozilla/AlreadyAddRefed.h"
#include "nscore.h"
#include "nsIContentPolicy.h"
#include "nsILoadInfo.h"
#include "nsIReferrerInfo.h"
class nsICookieSettings;
class nsIInputStream;

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

@ -11,9 +11,9 @@
#include "nsIConsoleService.h"
#include "nsICanvasRenderingContextInternal.h"
#include "nsIHTMLCollection.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "nsIPrincipal.h"
@ -142,7 +142,7 @@ bool IsImageExtractionAllowed(Document* aDocument, JSContext* aCx,
bool isAutoBlockCanvas =
StaticPrefs::
privacy_resistFingerprinting_autoDeclineNoUserInputCanvasPrompts() &&
!EventStateManager::IsHandlingUserInput();
!UserActivation::IsHandlingUserInput();
if (isAutoBlockCanvas) {
nsAutoString message;

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

@ -30,6 +30,7 @@
#include "mozilla/dom/ScriptLoader.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/TouchEvent.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/TimelineConsumers.h"
#include "mozilla/EventTimelineMarker.h"
#include "mozilla/TimeStamp.h"
@ -1135,8 +1136,8 @@ void EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
Maybe<AutoHandlingUserInputStatePusher> userInputStatePusher;
Maybe<AutoPopupStatePusher> popupStatePusher;
if (mIsMainThreadELM) {
userInputStatePusher.emplace(
EventStateManager::IsUserInteractionEvent(aEvent), aEvent);
userInputStatePusher.emplace(UserActivation::IsUserInteractionEvent(aEvent),
aEvent);
popupStatePusher.emplace(
PopupBlocker::GetEventPopupControlState(aEvent, *aDOMEvent));
}

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

@ -28,6 +28,7 @@
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/UIEvent.h"
#include "mozilla/dom/UIEventBinding.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WheelEventBinding.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_layout.h"
@ -199,8 +200,6 @@ NS_INTERFACE_MAP_END
static uint32_t sESMInstanceCount = 0;
int32_t EventStateManager::sUserInputEventDepth = 0;
int32_t EventStateManager::sUserKeyboardEventDepth = 0;
bool EventStateManager::sNormalLMouseEventInProcess = false;
int16_t EventStateManager::sCurrentMouseBtn = MouseButton::eNotPressed;
EventStateManager* EventStateManager::sActiveESM = nullptr;
@ -218,8 +217,6 @@ nsWeakPtr EventStateManager::sPointerLockedElement;
// Reference to the document which requested pointer lock.
nsWeakPtr EventStateManager::sPointerLockedDoc;
nsCOMPtr<nsIContent> EventStateManager::sDragOverContent = nullptr;
TimeStamp EventStateManager::sLatestUserInputStart;
TimeStamp EventStateManager::sHandlingInputStart;
EventStateManager::WheelPrefs* EventStateManager::WheelPrefs::sInstance =
nullptr;
@ -4089,71 +4086,6 @@ class MOZ_STACK_CLASS ESMEventCB : public EventDispatchingCallback {
nsCOMPtr<nsIContent> mTarget;
};
/*static*/
bool EventStateManager::IsUserInteractionEvent(const WidgetEvent* aEvent) {
if (!aEvent->IsTrusted()) {
return false;
}
switch (aEvent->mMessage) {
// eKeyboardEventClass
case eKeyPress:
case eKeyDown:
case eKeyUp:
// Not all keyboard events are treated as user input, so that popups
// can't be opened, fullscreen mode can't be started, etc at
// unexpected time.
return aEvent->AsKeyboardEvent()->CanTreatAsUserInput();
// eBasicEventClass
case eFormChange:
// eMouseEventClass
case eMouseClick:
case eMouseDown:
case eMouseUp:
// ePointerEventClass
case ePointerDown:
case ePointerUp:
// eTouchEventClass
case eTouchStart:
case eTouchEnd:
return true;
default:
return false;
}
}
/*static*/
bool EventStateManager::IsHandlingUserInput() {
return sUserInputEventDepth > 0;
}
/*static*/
bool EventStateManager::IsHandlingKeyboardInput() {
return sUserKeyboardEventDepth > 0;
}
/*static*/
void EventStateManager::StartHandlingUserInput(EventMessage aMessage) {
++sUserInputEventDepth;
if (sUserInputEventDepth == 1) {
sLatestUserInputStart = sHandlingInputStart = TimeStamp::Now();
}
if (WidgetEvent::IsKeyEventMessage(aMessage)) {
++sUserKeyboardEventDepth;
}
}
/*static*/
void EventStateManager::StopHandlingUserInput(EventMessage aMessage) {
--sUserInputEventDepth;
if (sUserInputEventDepth == 0) {
sHandlingInputStart = TimeStamp();
}
if (WidgetEvent::IsKeyEventMessage(aMessage)) {
--sUserKeyboardEventDepth;
}
}
static void CreateMouseOrPointerWidgetEvent(
WidgetMouseEvent* aMouseEvent, EventMessage aMessage,
nsIContent* aRelatedContent, nsAutoPtr<WidgetMouseEvent>& aNewEvent) {
@ -6346,25 +6278,4 @@ void EventStateManager::Prefs::Init() {
sPrefsAlreadyCached = true;
}
/******************************************************************/
/* mozilla::AutoHandlingUserInputStatePusher */
/******************************************************************/
AutoHandlingUserInputStatePusher::AutoHandlingUserInputStatePusher(
bool aIsHandlingUserInput, WidgetEvent* aEvent)
: mMessage(aEvent ? aEvent->mMessage : eVoidEvent),
mIsHandlingUserInput(aIsHandlingUserInput) {
if (!aIsHandlingUserInput) {
return;
}
EventStateManager::StartHandlingUserInput(mMessage);
}
AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher() {
if (!mIsHandlingUserInput) {
return;
}
EventStateManager::StopHandlingUserInput(mMessage);
}
} // namespace mozilla

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

@ -252,45 +252,6 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
*/
void RecomputeMouseEnterStateForRemoteFrame(Element& aElement);
/**
* Returns true if the event is considered as user interaction event. I.e.,
* enough obvious input to allow to open popup, etc. Otherwise, returns false.
*/
static bool IsUserInteractionEvent(const WidgetEvent* aEvent);
/**
* StartHandlingUserInput() is called when we start to handle a user input.
* StopHandlingUserInput() is called when we finish handling a user input.
* If the caller knows which input event caused that, it should set
* aMessage to the event message. Otherwise, set eVoidEvent.
* Note that StopHandlingUserInput() caller should call it with exactly same
* event message as its corresponding StartHandlingUserInput() call because
* these methods may count the number of specific event message.
*/
static void StartHandlingUserInput(EventMessage aMessage);
static void StopHandlingUserInput(EventMessage aMessage);
static TimeStamp GetHandlingInputStart() { return sHandlingInputStart; }
/**
* Returns true if the current code is being executed as a result of
* user input or keyboard input. The former includes anything that is
* initiated by user, with the exception of page load events or mouse
* over events. And the latter returns true when one of the user inputs
* is an input from keyboard. If these methods are called from asynchronously
* executed code, such as during layout reflows, it will return false.
*/
static bool IsHandlingUserInput();
static bool IsHandlingKeyboardInput();
/**
* Get the timestamp at which the latest user input was handled.
*
* Guaranteed to be monotonic. Until the first user input, return
* the epoch.
*/
static TimeStamp LatestUserInputStart() { return sLatestUserInputStart; }
nsPresContext* GetPresContext() { return mPresContext; }
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EventStateManager, nsIObserver)
@ -1255,14 +1216,6 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
bool m_haveShutdown;
// Time at which we began handling user input. Reset to the epoch
// once we have finished handling user input.
static TimeStamp sHandlingInputStart;
// Time at which we began handling the latest user input. Not reset
// at the end of the input.
static TimeStamp sLatestUserInputStart;
RefPtr<OverOutElementsWrapper> mMouseEnterLeaveHelper;
nsRefPtrHashtable<nsUint32HashKey, OverOutElementsWrapper>
mPointersEnterLeaveHelper;
@ -1272,15 +1225,6 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
// Array for accesskey support
nsCOMArray<nsIContent> mAccessKeys;
// The current depth of user and keyboard inputs. sUserInputEventDepth
// is the number of any user input events, page load events and mouse over
// events. sUserKeyboardEventDepth is the number of keyboard input events.
// Incremented whenever we start handling a user input, decremented when we
// have finished handling a user input. This depth is *not* reset in case
// of nested event loops.
static int32_t sUserInputEventDepth;
static int32_t sUserKeyboardEventDepth;
static bool sNormalLMouseEventInProcess;
static int16_t sCurrentMouseBtn;
@ -1300,21 +1244,6 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
static void sClickHoldCallback(nsITimer* aTimer, void* aESM);
};
/**
* This class is used while processing real user input. During this time, popups
* are allowed. For mousedown events, mouse capturing is also permitted.
*/
class MOZ_RAII AutoHandlingUserInputStatePusher final {
public:
explicit AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
WidgetEvent* aEvent = nullptr);
~AutoHandlingUserInputStatePusher();
protected:
EventMessage mMessage;
bool mIsHandlingUserInput;
};
} // namespace mozilla
// Click and double-click events need to be handled even for content that

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

@ -21,10 +21,11 @@
#include "mozilla/ToString.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/BrowserBridgeChild.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/HTMLFormElement.h"
#include "mozilla/dom/HTMLTextAreaElement.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/UserActivation.h"
#include "HTMLInputElement.h"
#include "IMEContentObserver.h"
@ -1317,9 +1318,9 @@ void IMEStateManager::SetIMEState(const IMEState& aState,
if ((aAction.mCause == InputContextAction::CAUSE_UNKNOWN ||
aAction.mCause == InputContextAction::CAUSE_UNKNOWN_CHROME) &&
EventStateManager::IsHandlingUserInput()) {
UserActivation::IsHandlingUserInput()) {
aAction.mCause =
EventStateManager::IsHandlingKeyboardInput()
UserActivation::IsHandlingKeyboardInput()
? InputContextAction::CAUSE_UNKNOWN_DURING_KEYBOARD_INPUT
: InputContextAction::CAUSE_UNKNOWN_DURING_NON_KEYBOARD_INPUT;
}

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

@ -33,9 +33,9 @@
#include "mozilla/dom/BlobURLProtocolHandler.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/PerformanceStorage.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/net/NeckoChannelParams.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/StaticPrefs_browser.h"
#include "mozilla/StaticPrefs_network.h"
@ -554,7 +554,7 @@ nsresult FetchDriver::HttpFetch(
nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(chan));
// Mark channel as urgent-start if the Fetch is triggered by user input
// events.
if (cos && EventStateManager::IsHandlingUserInput()) {
if (cos && UserActivation::IsHandlingUserInput()) {
cos->AddClassFlags(nsIClassOfService::UrgentStart);
}

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

@ -9,7 +9,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/dom/Element.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/dom/UserActivation.h"
#include "nsCOMPtr.h"
#include "mozilla/Encoding.h"
#include "nsString.h"
@ -124,7 +124,7 @@ class HTMLFormSubmission {
mTarget(aTarget),
mEncoding(aEncoding),
mOriginatingElement(aOriginatingElement),
mInitiatedFromUserInput(EventStateManager::IsHandlingUserInput()) {
mInitiatedFromUserInput(UserActivation::IsHandlingUserInput()) {
MOZ_COUNT_CTOR(HTMLFormSubmission);
}

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

@ -27,6 +27,7 @@
#include "nsFocusManager.h"
#include "mozilla/dom/HTMLFormElement.h"
#include "mozilla/dom/MutationEventBinding.h"
#include "mozilla/dom/UserActivation.h"
#include "nsAttrValueOrString.h"
#include "imgLoader.h"
#include "Image.h"
@ -316,7 +317,7 @@ nsresult HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
if (aName == nsGkAtoms::src && aNameSpaceID == kNameSpaceID_None && !aValue) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
// SetAttr handles setting src since it needs to catch img.src =
// img.src, so we only need to handle the unset case
@ -332,7 +333,7 @@ nsresult HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
} else if (aName == nsGkAtoms::srcset && aNameSpaceID == kNameSpaceID_None) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
mSrcsetTriggeringPrincipal = aMaybeScriptedPrincipal;
@ -340,7 +341,7 @@ nsresult HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
} else if (aName == nsGkAtoms::sizes && aNameSpaceID == kNameSpaceID_None) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
PictureSourceSizesChanged(this, attrVal.String(), aNotify);
} else if (aName == nsGkAtoms::decoding &&
@ -383,7 +384,7 @@ void HTMLImageElement::AfterMaybeChangeAttr(
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue.String(), aMaybeScriptedPrincipal);
@ -446,7 +447,7 @@ void HTMLImageElement::AfterMaybeChangeAttr(
if (forceReload) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
if (InResponsiveMode()) {
// per spec, full selection runs when this changes, even though
@ -518,7 +519,7 @@ nsresult HTMLImageElement::BindToTree(BindContext& aContext, nsINode& aParent) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
// Run selection algorithm when an img element is inserted into a document
// in order to react to changes in the environment. See note of
@ -534,7 +535,7 @@ nsresult HTMLImageElement::BindToTree(BindContext& aContext, nsINode& aParent) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
// We still act synchronously for the non-responsive case (Bug
// 1076583), but still need to delay if it is unsafe to run
@ -722,7 +723,7 @@ nsresult HTMLImageElement::CopyInnerTo(HTMLImageElement* aDest) {
aDest->OwnerDoc()->ShouldLoadImages()) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
nsContentUtils::AddScriptRunner(NewRunnableMethod<bool>(
"dom::HTMLImageElement::MaybeLoadImage", aDest,

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

@ -15,6 +15,7 @@
#include "mozilla/dom/HTMLFormSubmission.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "mozilla/dom/GetFilesHelper.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WheelEventBinding.h"
#include "mozilla/PresShell.h"
#include "mozilla/StaticPrefs_dom.h"
@ -1198,7 +1199,7 @@ nsresult HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
if (aValue) {
// Mark channel as urgent-start before load image if the image load is
// initiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
LoadImage(aValue->GetStringValue(), true, aNotify,
eImageLoadType_Normal, mSrcTriggeringPrincipal);
@ -4324,7 +4325,7 @@ nsresult HTMLInputElement::BindToTree(BindContext& aContext, nsINode& aParent) {
if (HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
nsContentUtils::AddScriptRunner(
NewRunnableMethod("dom::HTMLInputElement::MaybeLoadImage", this,
@ -4596,7 +4597,7 @@ void HTMLInputElement::HandleTypeChange(uint8_t aNewType, bool aNotify) {
if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
LoadImage(src, false, aNotify, eImageLoadType_Normal,
mSrcTriggeringPrincipal);

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

@ -50,7 +50,6 @@
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/EMEUtils.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/NotNull.h"
@ -74,6 +73,7 @@
#include "mozilla/dom/PlayPromise.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/TextTrack.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/VideoPlaybackQuality.h"
#include "mozilla/dom/VideoTrack.h"
#include "mozilla/dom/VideoTrackList.h"
@ -2174,7 +2174,7 @@ void HTMLMediaElement::Load() {
"ownerDoc=%p (%s) ownerDocUserActivated=%d "
"muted=%d volume=%f",
this, !!mSrcAttrStream, HasAttr(kNameSpaceID_None, nsGkAtoms::src),
HasSourceChildren(this), EventStateManager::IsHandlingUserInput(),
HasSourceChildren(this), UserActivation::IsHandlingUserInput(),
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay),
AutoplayPolicy::IsAllowedToPlay(*this), OwnerDoc(),
DocumentOrigin(OwnerDoc()).get(),
@ -2201,7 +2201,7 @@ void HTMLMediaElement::DoLoad() {
return;
}
if (EventStateManager::IsHandlingUserInput()) {
if (UserActivation::IsHandlingUserInput()) {
// Detect if user has interacted with element so that play will not be
// blocked when initiated by a script. This enables sites to capture user
// intent to play by calling load() in the click handler of a "catalog
@ -2911,7 +2911,7 @@ void HTMLMediaElement::Seek(double aTime, SeekTarget::Type aSeekType,
// Detect if user has interacted with element by seeking so that
// play will not be blocked when initiated by a script.
if (EventStateManager::IsHandlingUserInput()) {
if (UserActivation::IsHandlingUserInput()) {
mIsBlessed = true;
}
@ -3880,7 +3880,7 @@ already_AddRefed<Promise> HTMLMediaElement::Play(ErrorResult& aRv) {
UpdateHadAudibleAutoplayState();
const bool handlingUserInput = EventStateManager::IsHandlingUserInput();
const bool handlingUserInput = UserActivation::IsHandlingUserInput();
mPendingPlayPromises.AppendElement(promise);
if (AutoplayPolicy::IsAllowedToPlay(*this)) {

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

@ -27,6 +27,7 @@
#include "mozilla/dom/RemoteWebProgressRequest.h"
#include "mozilla/dom/SessionStoreUtils.h"
#include "mozilla/dom/SessionStoreUtilsBinding.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"

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

@ -6,13 +6,13 @@
#include "AutoplayPolicy.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/Logging.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/AudioContext.h"
#include "mozilla/dom/FeaturePolicyUtils.h"
#include "mozilla/dom/HTMLMediaElement.h"
#include "mozilla/dom/HTMLMediaElementBinding.h"
#include "mozilla/dom/UserActivation.h"
#include "nsGlobalWindowInner.h"
#include "nsIAutoplay.h"
#include "nsContentUtils.h"
@ -175,7 +175,7 @@ bool AutoplayPolicy::WouldBeAllowedToPlayIfAutoplayDisabled(
static bool IsAllowedToPlayByBlockingModel(const HTMLMediaElement& aElement) {
if (!StaticPrefs::media_autoplay_enabled_user_gestures_needed()) {
// If element is blessed, it would always be allowed to play().
return aElement.IsBlessed() || EventStateManager::IsHandlingUserInput();
return aElement.IsBlessed() || UserActivation::IsHandlingUserInput();
}
return IsWindowAllowedToPlay(aElement.OwnerDoc()->GetInnerWindow());
}

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

@ -36,7 +36,6 @@
#include "nsILineInputStream.h"
#include "nsIWeakReferenceUtils.h"
#include "nsPIDOMWindow.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/MozPromise.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/Telemetry.h"
@ -46,11 +45,12 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/FeaturePolicyUtils.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/MediaDevices.h"
#include "mozilla/dom/MediaStreamBinding.h"
#include "mozilla/dom/MediaStreamTrackBinding.h"
#include "mozilla/dom/GetUserMediaRequestBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/MediaDevices.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/Base64.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/media/MediaChild.h"
@ -196,6 +196,7 @@ using dom::OwningStringOrStringSequence;
using dom::OwningStringOrStringSequenceOrConstrainDOMStringParameters;
using dom::Promise;
using dom::Sequence;
using dom::UserActivation;
using media::NewRunnableFrom;
using media::NewTaskFrom;
using media::Refcountable;
@ -525,7 +526,7 @@ class GetUserMediaWindowListener {
if (globalWindow) {
auto req = MakeRefPtr<GetUserMediaRequest>(
globalWindow, VoidString(), VoidString(),
EventStateManager::IsHandlingUserInput());
UserActivation::IsHandlingUserInput());
obs->NotifyObservers(req, "recording-device-stopped", nullptr);
}
return;
@ -587,7 +588,7 @@ class GetUserMediaWindowListener {
auto* window = nsGlobalWindowInner::GetInnerWindowWithId(mWindowID);
auto req = MakeRefPtr<GetUserMediaRequest>(
window, removedRawId, removedSourceType,
EventStateManager::IsHandlingUserInput());
UserActivation::IsHandlingUserInput());
obs->NotifyObservers(req, "recording-device-stopped", nullptr);
}
}
@ -614,7 +615,7 @@ class GetUserMediaWindowListener {
auto* window = nsGlobalWindowInner::GetInnerWindowWithId(mWindowID);
auto req = MakeRefPtr<GetUserMediaRequest>(
window, removedRawId, removedSourceType,
EventStateManager::IsHandlingUserInput());
UserActivation::IsHandlingUserInput());
obs->NotifyObservers(req, "recording-device-stopped", nullptr);
}
}
@ -2381,7 +2382,7 @@ RefPtr<MediaManager::StreamPromise> MediaManager::GetUserMedia(
isChrome ||
Preferences::GetBool("media.navigator.permission.disabled", false);
bool isSecure = aWindow->IsSecureContext();
bool isHandlingUserInput = EventStateManager::IsHandlingUserInput();
bool isHandlingUserInput = UserActivation::IsHandlingUserInput();
nsCString host;
nsresult rv = docURI->GetHost(host);

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

@ -11,9 +11,9 @@
#include "mozilla/dom/PaymentRequestChild.h"
#include "mozilla/dom/PaymentRequestManager.h"
#include "mozilla/dom/RootedDictionary.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/intl/LocaleService.h"
#include "mozilla/intl/MozLocale.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/StaticPrefs_dom.h"
#include "nsContentUtils.h"
#include "nsIScriptError.h"
@ -701,7 +701,7 @@ already_AddRefed<Promise> PaymentRequest::Show(
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(global);
Document* doc = win->GetExtantDoc();
if (!EventStateManager::IsHandlingUserInput()) {
if (!UserActivation::IsHandlingUserInput()) {
nsString msg = NS_LITERAL_STRING(
"User activation is now required to call PaymentRequest.show()");
nsContentUtils::ReportToConsoleNonLocalized(

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

@ -11,7 +11,6 @@
#include "mozilla/Atomics.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/Preferences.h"
#include "mozilla/ResultExtensions.h"
@ -23,6 +22,7 @@
#include "mozilla/dom/MediaStreamError.h"
#include "mozilla/dom/PromiseBinding.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/dom/WorkerRef.h"
@ -103,7 +103,7 @@ already_AddRefed<Promise> Promise::Create(
bool Promise::MaybePropagateUserInputEventHandling() {
JS::PromiseUserInputEventHandlingState state =
EventStateManager::IsHandlingUserInput()
UserActivation::IsHandlingUserInput()
? JS::PromiseUserInputEventHandlingState::HadUserInteractionAtCreation
: JS::PromiseUserInputEventHandlingState::
DidntHaveUserInteractionAtCreation;

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

@ -6,10 +6,10 @@
#include "mozilla/dom/SVGFEImageElement.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/dom/SVGFEImageElementBinding.h"
#include "mozilla/dom/SVGFilterElement.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/RefPtr.h"
#include "nsContentUtils.h"
@ -84,7 +84,7 @@ nsresult SVGFEImageElement::LoadSVGImage(bool aForce, bool aNotify) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
return LoadImage(href, aForce, aNotify, eImageLoadType_Normal);
}

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

@ -7,7 +7,6 @@
#include "mozilla/dom/SVGImageElement.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/gfx/2D.h"
#include "nsCOMPtr.h"
@ -16,6 +15,7 @@
#include "imgINotificationObserver.h"
#include "mozilla/dom/SVGImageElementBinding.h"
#include "mozilla/dom/SVGLengthBinding.h"
#include "mozilla/dom/UserActivation.h"
#include "nsContentUtils.h"
#include "SVGGeometryProperty.h"
@ -142,7 +142,7 @@ nsresult SVGImageElement::LoadSVGImage(bool aForce, bool aNotify) {
// Mark channel as urgent-start before load image if the image load is
// initaiated by a user interaction.
mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput();
return LoadImage(href, aForce, aNotify, eImageLoadType_Normal);
}

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

@ -9,11 +9,11 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ElementBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/VRDisplay.h"
#include "mozilla/HoldDropJSObjects.h"
#include "mozilla/dom/VRDisplayBinding.h"
#include "mozilla/HoldDropJSObjects.h"
#include "mozilla/Base64.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "Navigator.h"
@ -461,7 +461,7 @@ already_AddRefed<Promise> VRDisplay::RequestPresent(
uint32_t presentationGroup =
isChromePresentation ? gfx::kVRGroupChrome : gfx::kVRGroupContent;
if (!EventStateManager::IsHandlingUserInput() && !isChromePresentation &&
if (!UserActivation::IsHandlingUserInput() && !isChromePresentation &&
!IsHandlingVRNavigationEvent() && StaticPrefs::dom_vr_require_gesture() &&
!IsPresenting()) {
// The WebVR API states that if called outside of a user gesture, the

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

@ -24,13 +24,13 @@
#include "mozilla/dom/MutableBlobStorage.h"
#include "mozilla/dom/XMLDocument.h"
#include "mozilla/dom/URLSearchParams.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseNativeHandler.h"
#include "mozilla/dom/WorkerError.h"
#include "mozilla/Encoding.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/LoadContext.h"
#include "mozilla/MemoryReporting.h"
@ -2559,7 +2559,7 @@ nsresult XMLHttpRequestMainThread::InitiateFetch(
// Mark channel as urgent-start if the XHR is triggered by user input
// events.
if (EventStateManager::IsHandlingUserInput()) {
if (UserActivation::IsHandlingUserInput()) {
cos->AddClassFlags(nsIClassOfService::UrgentStart);
}
}

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

@ -54,6 +54,7 @@
#include "mozilla/dom/PopupBlocker.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/DocumentInlines.h"
#include "mozilla/dom/UserActivation.h"
#include "nsAnimationManager.h"
#include "nsNameSpaceManager.h" // for Pref-related rule management (bugs 22963,20760,31816)
#include "nsFrame.h"
@ -7757,7 +7758,7 @@ nsresult PresShell::EventHandler::HandleEventWithCurrentEventInfo(
RecordEventPreparationPerformance(aEvent);
AutoHandlingUserInputStatePusher userInpStatePusher(
EventStateManager::IsUserInteractionEvent(aEvent), aEvent);
UserActivation::IsUserInteractionEvent(aEvent), aEvent);
AutoEventHandler eventHandler(aEvent, GetDocument());
AutoPopupStatePusher popupStatePusher(
PopupBlocker::GetEventPopupControlState(aEvent));

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

@ -34,7 +34,6 @@
#include "nsIDOMXULMenuListElement.h"
#include "mozilla/Attributes.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/Likely.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/MouseEvents.h"
@ -44,6 +43,7 @@
#include "mozilla/TextEvents.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/UserActivation.h"
#include <algorithm>
using namespace mozilla;
@ -1115,7 +1115,7 @@ void nsMenuFrame::CreateMenuCommandEvent(WidgetGUIEvent* aEvent,
// Because the command event is firing asynchronously, a flag is needed to
// indicate whether user input is being handled. This ensures that a popup
// window won't get blocked.
bool userinput = EventStateManager::IsHandlingUserInput();
bool userinput = UserActivation::IsHandlingUserInput();
mDelayedMenuCommandEvent =
new nsXULMenuCommandEvent(mContent->AsElement(), isTrusted, shift,

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

@ -41,8 +41,8 @@
#include "mozilla/dom/KeyboardEventBinding.h"
#include "mozilla/dom/MouseEvent.h"
#include "mozilla/dom/UIEvent.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/PresShell.h"

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

@ -10,7 +10,6 @@
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/Move.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Sprintf.h"
@ -28,6 +27,7 @@
#include "mozilla/dom/PromiseRejectionEvent.h"
#include "mozilla/dom/PromiseRejectionEventBinding.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/UserActivation.h"
#include "jsapi.h"
#include "js/Debug.h"
#include "js/GCAPI.h"