Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorInputAgent.cpp

Issue 1949793002: Emit a console warning when blocking event listener is delayed for too long (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/inspector/InspectorInputAgent.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorInputAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorInputAgent.cpp
index 1fe3e8cb546a0153fa4808ee6db2fcf228984562..e6a4f40baf620e1a90c0e5ca6be4a92d610d84a4 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorInputAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorInputAgent.cpp
@@ -30,10 +30,14 @@
#include "core/inspector/InspectorInputAgent.h"
+#include "bindings/core/v8/V8AbstractEventListener.h"
+#include "core/dom/ExecutionContext.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/input/EventHandler.h"
+#include "core/inspector/ConsoleMessage.h"
#include "core/inspector/InspectedFrames.h"
+#include "core/inspector/InspectorDOMDebuggerAgent.h"
#include "core/page/ChromeClient.h"
#include "core/page/Page.h"
#include "platform/PlatformEvent.h"
@@ -124,9 +128,14 @@ void ConvertInspectorPoint(blink::LocalFrame* frame, const blink::IntPoint& poin
namespace blink {
+namespace InputAgentState {
+static const char blockedEventsWarningThreshold[] = "blockedEventsWarningThreshold";
+}
+
InspectorInputAgent::InspectorInputAgent(InspectedFrames* inspectedFrames)
: InspectorBaseAgent<InspectorInputAgent, protocol::Frontend::Input>("Input")
, m_inspectedFrames(inspectedFrames)
+ , m_blockedEventsWarningThreshold(0.0)
{
}
@@ -203,6 +212,82 @@ void InspectorInputAgent::dispatchTouchEvent(ErrorString* error, const String& t
m_inspectedFrames->root()->eventHandler().handleTouchEvent(event);
}
+void InspectorInputAgent::restore()
+{
+ ErrorString dummy;
+
+ setBlockedEventsWarningThreshold(&dummy, m_state->numberProperty(InputAgentState::blockedEventsWarningThreshold, 0.0));
+}
+
+void InspectorInputAgent::setBlockedEventsWarningThreshold(ErrorString*, double threshold)
+{
+ m_blockedEventsWarningThreshold = threshold;
+ m_state->setNumber(InputAgentState::blockedEventsWarningThreshold, threshold);
+ setEnabled(threshold > 0);
+}
+
+void InspectorInputAgent::disable(ErrorString*)
+{
+ setEnabled(false);
+}
+
+void InspectorInputAgent::setEnabled(bool enabled)
+{
+ if (enabled)
+ m_instrumentingAgents->addInspectorInputAgent(this);
+ else
+ m_instrumentingAgents->removeInspectorInputAgent(this);
+}
+
+bool InspectorInputAgent::shouldReportBlockedEvent(const Event* event)
+{
+ if (m_blockedEventsWarningThreshold <= 0)
+ return false;
+
+ const AtomicString& eventType = event->type();
+ if (!event->cancelable())
+ return false;
+ if (eventType != EventTypeNames::touchstart
+ && eventType != EventTypeNames::touchmove
+ && eventType != EventTypeNames::touchend
+ && eventType != EventTypeNames::mousewheel
+ && eventType != EventTypeNames::wheel) {
+ return false;
+ }
+ double now = WTF::monotonicallyIncreasingTime();
+ if (now < event->platformTimeStamp()) {
+ NOTREACHED() << "Event timestamp from the future";
+ return false;
+ }
+ bool report = now - event->platformTimeStamp() > m_blockedEventsWarningThreshold;
+ return report;
+}
+
+void InspectorInputAgent::reportBlockedEvent(ExecutionContext* context, const Event* event, RegisteredEventListener* registeredListener, double delayedSeconds)
+{
+ if (registeredListener->listener->type() != EventListener::JSEventListenerType)
+ return;
+
+ V8AbstractEventListener* v8Listener = V8AbstractEventListener::cast(registeredListener->listener);
+ v8::HandleScope handles(v8Listener->isolate());
+ v8::Local<v8::Object> handler = v8Listener->getListenerObject(context);
+
+ String messageText = String::format(
+ "Handling of %s input event was delayed for %ld ms. due to main thread being busy. "
+ "Consider marking event handler as passive to make the page appear more responive.",
+ event->type().characters8(), lround(delayedSeconds * 1000));
+ ConsoleMessage* message = ConsoleMessage::create(JSMessageSource, WarningMessageLevel, messageText);
+
+ v8::Local<v8::Function> function = InspectorDOMDebuggerAgent::eventListenerEffectiveFunction(v8Listener->isolate(), handler);
+ if (!function.IsEmpty()) {
+ message->setLineNumber(function->GetScriptLineNumber() + 1);
+ message->setColumnNumber(function->GetScriptColumnNumber());
+ message->setScriptId(function->ScriptId());
+ }
+ context->addConsoleMessage(message);
+ registeredListener->blockedEventWarningEmitted = true;
+}
+
DEFINE_TRACE(InspectorInputAgent)
{
visitor->trace(m_inspectedFrames);

Powered by Google App Engine
This is Rietveld 408576698