Commit bf3b5969 authored by eric@webkit.org's avatar eric@webkit.org

2009-10-26 Kelly Norton <knorton@google.com>

        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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50068 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8110a530
2009-10-26 Kelly Norton <knorton@google.com>
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 <simon.fraser@apple.com>
Reviewed by Sam Weinig.
......@@ -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()
......
......@@ -31,9 +31,10 @@
#ifndef InspectorTimelineAgent_h
#define InspectorTimelineAgent_h
#include "Document.h"
#include "ScriptExecutionContext.h"
#include "ScriptObject.h"
#include "ScriptArray.h"
#include <wtf/Vector.h>
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<Document*>(context)->inspectorTimelineAgent();
return 0;
}
} // namespace WebCore
#endif // !defined(InspectorTimelineAgent_h)
......@@ -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)
......@@ -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() { }
};
......
......@@ -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) {
......
......@@ -27,6 +27,7 @@
#include "config.h"
#include "DOMTimer.h"
#include "InspectorTimelineAgent.h"
#include "ScheduledAction.h"
#include "ScriptExecutionContext.h"
#include <wtf/HashSet.h>
......@@ -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;
}
......
......@@ -33,6 +33,7 @@
namespace WebCore {
class InspectorTimelineAgent;
class ScheduledAction;
class DOMTimer : public TimerBase, public ActiveDOMObject {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment