Bug 1357880 - Add a telemetry probe for non-passive keyboard event listeners r=smaug, data-review=bsmedberg

This commit adds a telemetry probe to track the percentage of pages that ever
have a non-passive 'keydown' or 'keypress' event that could preventDefault()
APZ key scrolling of the root of a page.

A flag is added to each EventListenerManager to track whether it ever had
a qualifying event listener, and then in nsGlobalWindow::FreeInnerObjects()
the event targets that could preventDefault() a scroll are checked for this
flag. This check is done at nsGlobalWindow::FreeInnerObjects() so that the
DOM is still alive.

MozReview-Commit-ID: EkK3vxehZA5

--HG--
extra : rebase_source : 4642189d0065254cf74dfe8475403f0bf8210bca
This commit is contained in:
Ryan Hunt 2017-04-27 18:32:08 -04:00
Родитель 213466c2df
Коммит ebd2c4d010
6 изменённых файлов: 38 добавлений и 1 удалений

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

@ -103,6 +103,7 @@
#include "nsIDocShell.h"
#include "nsIDocCharset.h"
#include "nsIDocument.h"
#include "nsIDocumentInlines.h"
#include "Crypto.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
@ -2044,6 +2045,20 @@ nsGlobalWindow::FreeInnerObjects()
{
NS_ASSERTION(IsInnerWindow(), "Don't free inner objects on an outer window");
if (mDoc && !nsContentUtils::IsSystemPrincipal(mDoc->NodePrincipal())) {
EventTarget* win = this;
EventTarget* html = mDoc->GetHtmlElement();
EventTarget* body = mDoc->GetBodyElement();
bool keyboardAware = win->MayHaveAPZAwareKeyEventListener() ||
mDoc->MayHaveAPZAwareKeyEventListener() ||
(html && html->MayHaveAPZAwareKeyEventListener()) ||
(body && body->MayHaveAPZAwareKeyEventListener());
Telemetry::Accumulate(Telemetry::APZ_AWARE_KEY_LISTENERS,
keyboardAware ? 1 : 0);
}
// Make sure that this is called before we null out the document and
// other members that the window destroyed observers could
// re-create.

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

@ -129,6 +129,7 @@ EventListenerManagerBase::EventListenerManagerBase()
, mMayHaveTouchEventListener(false)
, mMayHaveMouseEnterLeaveEventListener(false)
, mMayHavePointerEnterLeaveEventListener(false)
, mMayHaveAPZAwareKeyEventListener(false)
, mMayHaveKeyEventListener(false)
, mMayHaveInputOrCompositionEventListener(false)
, mClearingListeners(false)
@ -411,6 +412,9 @@ EventListenerManager::AddEventListenerInternal(
if (!aFlags.mInSystemGroup) {
mMayHaveKeyEventListener = true;
}
if (!aFlags.mPassive && aTypeAtom != nsGkAtoms::onkeyup) {
mMayHaveAPZAwareKeyEventListener = true;
}
} else if (aTypeAtom == nsGkAtoms::oncompositionend ||
aTypeAtom == nsGkAtoms::oncompositionstart ||
aTypeAtom == nsGkAtoms::oncompositionupdate ||

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

@ -163,11 +163,12 @@ protected:
uint16_t mMayHaveTouchEventListener : 1;
uint16_t mMayHaveMouseEnterLeaveEventListener : 1;
uint16_t mMayHavePointerEnterLeaveEventListener : 1;
uint16_t mMayHaveAPZAwareKeyEventListener : 1;
uint16_t mMayHaveKeyEventListener : 1;
uint16_t mMayHaveInputOrCompositionEventListener : 1;
uint16_t mClearingListeners : 1;
uint16_t mIsMainThreadELM : 1;
// uint16_t mUnused : 5;
// uint16_t mUnused : 4;
};
/*
@ -442,6 +443,8 @@ public:
bool MayHaveMouseEnterLeaveEventListener() { return mMayHaveMouseEnterLeaveEventListener; }
bool MayHavePointerEnterLeaveEventListener() { return mMayHavePointerEnterLeaveEventListener; }
bool MayHaveAPZAwareKeyEventListener() const { return mMayHaveAPZAwareKeyEventListener; }
/**
* Returns true if there may be a key event listener (keydown, keypress,
* or keyup) registered, or false if there definitely isn't.

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

@ -64,6 +64,13 @@ EventTarget::IsApzAware() const
return elm && elm->HasApzAwareListeners();
}
bool
EventTarget::MayHaveAPZAwareKeyEventListener() const
{
EventListenerManager* elm = GetExistingListenerManager();
return elm && elm->MayHaveAPZAwareKeyEventListener();
}
bool
EventTarget::DispatchEvent(Event& aEvent,
CallerType aCallerType,

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

@ -100,6 +100,7 @@ public:
virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) {}
virtual bool IsApzAware() const;
bool MayHaveAPZAwareKeyEventListener() const;
protected:
EventHandlerNonNull* GetEventHandler(nsIAtom* aType,

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

@ -10435,6 +10435,13 @@
"releaseChannelCollection": "opt-out",
"description": "Graphics Crash Reason (...)"
},
"APZ_AWARE_KEY_LISTENERS": {
"alert_emails": ["rhunt@mozilla.com"],
"bug_numbers": [1352654],
"expires_in_version": "58",
"kind": "boolean",
"description": "The percentage of pages with a non-passive key event on the path to the root scrolling element that would disable APZ key scrolling. This is tracked for non system principal windows, so it applies to toplevel windows and subframes/iframes, but not chrome windows. "
},
"SCROLL_INPUT_METHODS": {
"alert_emails": ["botond@mozilla.com"],
"bug_numbers": [1238137],