Chromium Code Reviews| 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..2706e97863a9815b536f0f2a2b78467e66329341 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,76 @@ 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 (eventType != EventTypeNames::touchstart |
|
dtapuska
2016/05/04 17:46:09
I think this needs a event->cancelable() &&
|
| + && eventType != EventTypeNames::touchmove |
| + && eventType != EventTypeNames::touchend |
| + && eventType != EventTypeNames::mousewheel |
| + && eventType != EventTypeNames::wheel) { |
| + return false; |
| + } |
| + double now = WTF::monotonicallyIncreasingTime(); |
| + bool report = now - event->platformTimeStamp() > m_blockedEventsWarningThreshold; |
|
dtapuska
2016/05/04 17:46:09
There should likely be a test for now - event->pla
|
| + return report; |
| +} |
| + |
| +void InspectorInputAgent::reportBlockedEvent(ExecutionContext* context, 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); |