diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 62915eb80f860bc2af25bf6637999e664f219e00..b1621b4d6f688b500fb3c875beaa044000972a9d 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,33 @@ +2009-10-26 Kelly Norton + + Reviewed by Pavel Feldman. + + Adds DOMTimer support to InspectorTimelineAgent. + https://bugs.webkit.org/show_bug.cgi?id=30467 + + * inspector/InspectorTimelineAgent.cpp: Added timer support and fixed some method names. + (WebCore::InspectorTimelineAgent::didDispatchDOMEvent): + (WebCore::InspectorTimelineAgent::didLayout): + (WebCore::InspectorTimelineAgent::didRecalculateStyle): + (WebCore::InspectorTimelineAgent::didPaint): + (WebCore::InspectorTimelineAgent::didWriteHTML): + (WebCore::InspectorTimelineAgent::didInstallTimer): Added. + (WebCore::InspectorTimelineAgent::didRemoveTimer): Added. + (WebCore::InspectorTimelineAgent::willFireTimer): Added. + (WebCore::InspectorTimelineAgent::didFireTimer): Added. + (WebCore::InspectorTimelineAgent::addItemToTimeline): Added. + (WebCore::InspectorTimelineAgent::didCompleteCurrentTimelineItem): Renamed. + * inspector/InspectorTimelineAgent.h: + (WebCore::): + * inspector/TimelineItemFactory.cpp: Add methods for timer-related ScriptObjects. + (WebCore::TimelineItemFactory::createGenericTimerTimelineItem): + (WebCore::TimelineItemFactory::createTimerInstallTimelineItem): + * inspector/TimelineItemFactory.h: + * page/DOMTimer.cpp: Added instrumentation points. + (WebCore::DOMTimer::install): + (WebCore::DOMTimer::removeById): + (WebCore::DOMTimer::fired): + 2009-10-26 Simon Fraser Reviewed by Sam Weinig. diff --git a/WebCore/inspector/InspectorTimelineAgent.cpp b/WebCore/inspector/InspectorTimelineAgent.cpp index d1d54f39b94030465bfafe435969ed4951eedf7c..4a3409e6d7a094ba312c64271e9f423a97309e97 100644 --- a/WebCore/inspector/InspectorTimelineAgent.cpp +++ b/WebCore/inspector/InspectorTimelineAgent.cpp @@ -58,7 +58,7 @@ void InspectorTimelineAgent::willDispatchDOMEvent(const Event& event) void InspectorTimelineAgent::didDispatchDOMEvent() { - didCompleteCurrentRecord(DOMDispatchTimelineItemType); + didCompleteCurrentTimelineItem(DOMDispatchTimelineItemType); } void InspectorTimelineAgent::willLayout() @@ -68,7 +68,7 @@ void InspectorTimelineAgent::willLayout() void InspectorTimelineAgent::didLayout() { - didCompleteCurrentRecord(LayoutTimelineItemType); + didCompleteCurrentTimelineItem(LayoutTimelineItemType); } void InspectorTimelineAgent::willRecalculateStyle() @@ -78,7 +78,7 @@ void InspectorTimelineAgent::willRecalculateStyle() void InspectorTimelineAgent::didRecalculateStyle() { - didCompleteCurrentRecord(RecalculateStylesTimelineItemType); + didCompleteCurrentTimelineItem(RecalculateStylesTimelineItemType); } void InspectorTimelineAgent::willPaint() @@ -88,7 +88,7 @@ void InspectorTimelineAgent::willPaint() void InspectorTimelineAgent::didPaint() { - didCompleteCurrentRecord(PaintTimelineItemType); + didCompleteCurrentTimelineItem(PaintTimelineItemType); } void InspectorTimelineAgent::willWriteHTML() @@ -98,7 +98,30 @@ void InspectorTimelineAgent::willWriteHTML() void InspectorTimelineAgent::didWriteHTML() { - didCompleteCurrentRecord(ParseHTMLTimelineItemType); + didCompleteCurrentTimelineItem(ParseHTMLTimelineItemType); +} + +void InspectorTimelineAgent::didInstallTimer(int timerId, int timeout, bool singleShot) +{ + addItemToTimeline(TimelineItemFactory::createTimerInstallTimelineItem(m_frontend, currentTimeInMilliseconds(), timerId, + timeout, singleShot), TimerInstallTimelineItemType); +} + +void InspectorTimelineAgent::didRemoveTimer(int timerId) +{ + addItemToTimeline(TimelineItemFactory::createGenericTimerTimelineItem(m_frontend, currentTimeInMilliseconds(), timerId), + TimerRemoveTimelineItemType); +} + +void InspectorTimelineAgent::willFireTimer(int timerId) +{ + pushCurrentTimelineItem(TimelineItemFactory::createGenericTimerTimelineItem(m_frontend, currentTimeInMilliseconds(), timerId), + TimerFireTimelineItemType); +} + +void InspectorTimelineAgent::didFireTimer() +{ + didCompleteCurrentTimelineItem(TimerFireTimelineItemType); } void InspectorTimelineAgent::reset() @@ -106,21 +129,26 @@ void InspectorTimelineAgent::reset() m_itemStack.clear(); } -void InspectorTimelineAgent::didCompleteCurrentRecord(TimelineItemType type) +void InspectorTimelineAgent::addItemToTimeline(ScriptObject item, TimelineItemType type) { + item.set("type", type); + if (m_itemStack.isEmpty()) + m_frontend->addItemToTimeline(item); + else { + TimelineItemEntry parent = m_itemStack.last(); + parent.children.set(parent.children.length(), item); + } +} + +void InspectorTimelineAgent::didCompleteCurrentTimelineItem(TimelineItemType type) +{ + ASSERT(!m_itemStack.isEmpty()); TimelineItemEntry entry = m_itemStack.last(); m_itemStack.removeLast(); ASSERT(entry.type == type); - entry.item.set("type", type); entry.item.set("children", entry.children); entry.item.set("endTime", currentTimeInMilliseconds()); - - if (m_itemStack.isEmpty()) { - m_frontend->addItemToTimeline(entry.item); - } else { - TimelineItemEntry parent = m_itemStack.last(); - parent.children.set(parent.children.length(), entry.item); - } + addItemToTimeline(entry.item, type); } double InspectorTimelineAgent::currentTimeInMilliseconds() diff --git a/WebCore/inspector/InspectorTimelineAgent.h b/WebCore/inspector/InspectorTimelineAgent.h index ceefed761ba09d82c14d6ee03f38d24fbb5e7630..0bf39659ef30b992897f502549f6c3d4052e1885 100644 --- a/WebCore/inspector/InspectorTimelineAgent.h +++ b/WebCore/inspector/InspectorTimelineAgent.h @@ -31,9 +31,10 @@ #ifndef InspectorTimelineAgent_h #define InspectorTimelineAgent_h +#include "Document.h" +#include "ScriptExecutionContext.h" #include "ScriptObject.h" #include "ScriptArray.h" - #include namespace WebCore { @@ -47,6 +48,9 @@ namespace WebCore { RecalculateStylesTimelineItemType = 2, PaintTimelineItemType = 3, ParseHTMLTimelineItemType = 4, + TimerInstallTimelineItemType = 5, + TimerRemoveTimelineItemType = 6, + TimerFireTimelineItemType = 7, }; class InspectorTimelineAgent { @@ -59,15 +63,25 @@ namespace WebCore { // Methods called from WebCore. void willDispatchDOMEvent(const Event&); void didDispatchDOMEvent(); + void willLayout(); void didLayout(); + void willRecalculateStyle(); void didRecalculateStyle(); + void willPaint(); void didPaint(); - void didWriteHTML(); + void willWriteHTML(); + void didWriteHTML(); + + void didInstallTimer(int timerId, int timeout, bool singleShot); + void didRemoveTimer(int timerId); + void willFireTimer(int timerId); + void didFireTimer(); + static InspectorTimelineAgent* retrieve(ScriptExecutionContext*); private: struct TimelineItemEntry { TimelineItemEntry(ScriptObject item, ScriptArray children, TimelineItemType type) : item(item), children(children), type(type) { } @@ -80,13 +94,22 @@ namespace WebCore { static double currentTimeInMilliseconds(); - void didCompleteCurrentRecord(TimelineItemType); + void didCompleteCurrentTimelineItem(TimelineItemType); + void addItemToTimeline(ScriptObject, TimelineItemType); + InspectorFrontend* m_frontend; Vector< TimelineItemEntry > m_itemStack; }; +inline InspectorTimelineAgent* InspectorTimelineAgent::retrieve(ScriptExecutionContext* context) +{ + if (context->isDocument()) + return static_cast(context)->inspectorTimelineAgent(); + return 0; +} + } // namespace WebCore #endif // !defined(InspectorTimelineAgent_h) diff --git a/WebCore/inspector/TimelineItemFactory.cpp b/WebCore/inspector/TimelineItemFactory.cpp index d10bd513a37d05ec7494191bd6ab7d3e2813a1c7..3255e78cdf899b68131a49b40c89a74327afb8ff 100644 --- a/WebCore/inspector/TimelineItemFactory.cpp +++ b/WebCore/inspector/TimelineItemFactory.cpp @@ -57,6 +57,28 @@ ScriptObject TimelineItemFactory::createDOMDispatchTimelineItem(InspectorFronten return item; } +// static +ScriptObject TimelineItemFactory::createGenericTimerTimelineItem(InspectorFrontend* frontend, double startTime, int timerId) +{ + ScriptObject item = createGenericTimelineItem(frontend, startTime); + ScriptObject data = frontend->newScriptObject(); + data.set("timerId", timerId); + item.set("data", data); + return item; +} + +// static +ScriptObject TimelineItemFactory::createTimerInstallTimelineItem(InspectorFrontend* frontend, double startTime, int timerId, int timeout, bool singleShot) +{ + ScriptObject item = createGenericTimelineItem(frontend, startTime); + ScriptObject data = frontend->newScriptObject(); + data.set("timerId", timerId); + data.set("timeout", timeout); + data.set("singleShot", singleShot); + item.set("data", data); + return item; +} + } // namespace WebCore #endif // ENABLE(INSPECTOR) diff --git a/WebCore/inspector/TimelineItemFactory.h b/WebCore/inspector/TimelineItemFactory.h index 395d645a54d33ae7560e963bd029396a8e357b05..b41f76971c760e91f4394a3db64d97286bca2ad4 100644 --- a/WebCore/inspector/TimelineItemFactory.h +++ b/WebCore/inspector/TimelineItemFactory.h @@ -40,8 +40,13 @@ namespace WebCore { class TimelineItemFactory { public: static ScriptObject createGenericTimelineItem(InspectorFrontend*, double startTime); + + static ScriptObject createDOMDispatchTimelineItem(InspectorFrontend*, double startTime, const Event&); + + static ScriptObject createGenericTimerTimelineItem(InspectorFrontend*, double startTime, int timerId); + + static ScriptObject createTimerInstallTimelineItem(InspectorFrontend*, double startTime, int timerId, int timeout, bool singleShot); - static ScriptObject createDOMDispatchTimelineItem(InspectorFrontend*, double startTime, const Event&); private: TimelineItemFactory() { } }; diff --git a/WebCore/inspector/front-end/TimelineAgent.js b/WebCore/inspector/front-end/TimelineAgent.js index a310c38e8ccfffe169c754d707f6d4533564f485..edd97a908053357f36eeda298113f62f2cc93974 100644 --- a/WebCore/inspector/front-end/TimelineAgent.js +++ b/WebCore/inspector/front-end/TimelineAgent.js @@ -38,7 +38,10 @@ WebInspector.TimelineAgent.ItemType = { Layout : 1, RecalculateStyles : 2, Paint : 3, - ParseHTML : 4 + ParseHTML : 4, + TimerInstall : 5, + TimerRemove : 6, + TimerFire : 7, }; WebInspector.addItemToTimeline = function(record) { diff --git a/WebCore/page/DOMTimer.cpp b/WebCore/page/DOMTimer.cpp index dd1e8424c4151945e6068d0b2e221bf06de11b17..83bcb0291337908a78b0ae7edb05cfad441001b7 100644 --- a/WebCore/page/DOMTimer.cpp +++ b/WebCore/page/DOMTimer.cpp @@ -27,6 +27,7 @@ #include "config.h" #include "DOMTimer.h" +#include "InspectorTimelineAgent.h" #include "ScheduledAction.h" #include "ScriptExecutionContext.h" #include @@ -87,6 +88,12 @@ int DOMTimer::install(ScriptExecutionContext* context, ScheduledAction* action, // The timer is deleted when context is deleted (DOMTimer::contextDestroyed) or explicitly via DOMTimer::removeById(), // or if it is a one-time timer and it has fired (DOMTimer::fired). DOMTimer* timer = new DOMTimer(context, action, timeout, singleShot); + +#if ENABLE(INSPECTOR) + if (InspectorTimelineAgent* timelineAgent = InspectorTimelineAgent::retrieve(context)) + timelineAgent->didInstallTimer(timer->m_timeoutId, timeout, singleShot); +#endif + return timer->m_timeoutId; } @@ -97,6 +104,12 @@ void DOMTimer::removeById(ScriptExecutionContext* context, int timeoutId) // respectively if (timeoutId <= 0) return; + +#if ENABLE(INSPECTOR) + if (InspectorTimelineAgent* timelineAgent = InspectorTimelineAgent::retrieve(context)) + timelineAgent->didRemoveTimer(timeoutId); +#endif + delete context->findTimeout(timeoutId); } @@ -105,6 +118,12 @@ void DOMTimer::fired() ScriptExecutionContext* context = scriptExecutionContext(); timerNestingLevel = m_nestingLevel; +#if ENABLE(INSPECTOR) + InspectorTimelineAgent* timelineAgent = InspectorTimelineAgent::retrieve(context); + if (timelineAgent) + timelineAgent->willFireTimer(m_timeoutId); +#endif + // Simple case for non-one-shot timers. if (isActive()) { if (repeatInterval() && repeatInterval() < s_minTimerInterval) { @@ -115,6 +134,10 @@ void DOMTimer::fired() // No access to member variables after this point, it can delete the timer. m_action->execute(context); +#if ENABLE(INSPECTOR) + if (timelineAgent) + timelineAgent->didFireTimer(); +#endif return; } @@ -125,6 +148,10 @@ void DOMTimer::fired() delete this; action->execute(context); +#if ENABLE(INSPECTOR) + if (timelineAgent) + timelineAgent->didFireTimer(); +#endif delete action; timerNestingLevel = 0; } diff --git a/WebCore/page/DOMTimer.h b/WebCore/page/DOMTimer.h index 3c652583c51c9f14dd1743b15a0e8b8d070ef7d4..460430f4d28c18b9a753de078880a39a5a47a516 100644 --- a/WebCore/page/DOMTimer.h +++ b/WebCore/page/DOMTimer.h @@ -33,6 +33,7 @@ namespace WebCore { + class InspectorTimelineAgent; class ScheduledAction; class DOMTimer : public TimerBase, public ActiveDOMObject {