InspectorTimelineAgent.cpp 5.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
*     * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*     * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "InspectorTimelineAgent.h"

bolsinga@apple.com's avatar
bolsinga@apple.com committed
34 35
#if ENABLE(INSPECTOR)

36 37
#include "Event.h"
#include "InspectorFrontend.h"
38
#include "TimelineItemFactory.h"
39 40 41 42 43 44

#include <wtf/CurrentTime.h>

namespace WebCore {

InspectorTimelineAgent::InspectorTimelineAgent(InspectorFrontend* frontend)
45
    : m_frontend(frontend)
46 47 48 49 50 51 52 53 54 55
{
    ASSERT(m_frontend);
}

InspectorTimelineAgent::~InspectorTimelineAgent()
{
}

void InspectorTimelineAgent::willDispatchDOMEvent(const Event& event)
{
56
    pushCurrentTimelineItem(TimelineItemFactory::createDOMDispatchTimelineItem(m_frontend, currentTimeInMilliseconds(), event), DOMDispatchTimelineItemType);
57 58 59 60
}

void InspectorTimelineAgent::didDispatchDOMEvent()
{
61
    didCompleteCurrentTimelineItem(DOMDispatchTimelineItemType);
62 63 64 65
}

void InspectorTimelineAgent::willLayout()
{
66
    pushCurrentTimelineItem(TimelineItemFactory::createGenericTimelineItem(m_frontend, currentTimeInMilliseconds()), LayoutTimelineItemType);
67 68 69 70
}

void InspectorTimelineAgent::didLayout()
{
71
    didCompleteCurrentTimelineItem(LayoutTimelineItemType);
72 73 74 75
}

void InspectorTimelineAgent::willRecalculateStyle()
{
76
    pushCurrentTimelineItem(TimelineItemFactory::createGenericTimelineItem(m_frontend, currentTimeInMilliseconds()), RecalculateStylesTimelineItemType);
77 78 79 80
}

void InspectorTimelineAgent::didRecalculateStyle()
{
81
    didCompleteCurrentTimelineItem(RecalculateStylesTimelineItemType);
82 83 84 85
}

void InspectorTimelineAgent::willPaint()
{
86
    pushCurrentTimelineItem(TimelineItemFactory::createGenericTimelineItem(m_frontend, currentTimeInMilliseconds()), PaintTimelineItemType);
87 88 89 90
}

void InspectorTimelineAgent::didPaint()
{
91
    didCompleteCurrentTimelineItem(PaintTimelineItemType);
92 93 94 95
}

void InspectorTimelineAgent::willWriteHTML()
{
96
    pushCurrentTimelineItem(TimelineItemFactory::createGenericTimelineItem(m_frontend, currentTimeInMilliseconds()), ParseHTMLTimelineItemType);
97 98 99 100
}

void InspectorTimelineAgent::didWriteHTML()
{
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    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);
125 126 127 128
}

void InspectorTimelineAgent::reset()
{
129
    m_itemStack.clear();
130 131
}

132
void InspectorTimelineAgent::addItemToTimeline(ScriptObject item, TimelineItemType type)
133
{
134 135 136 137 138 139 140 141 142 143 144 145
    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());
146 147 148 149 150
    TimelineItemEntry entry = m_itemStack.last();
    m_itemStack.removeLast();
    ASSERT(entry.type == type);
    entry.item.set("children", entry.children);
    entry.item.set("endTime", currentTimeInMilliseconds());
151
    addItemToTimeline(entry.item, type);
152 153 154 155 156 157 158
}

double InspectorTimelineAgent::currentTimeInMilliseconds()
{
    return currentTime() * 1000.0;
}

159 160 161 162 163
void InspectorTimelineAgent::pushCurrentTimelineItem(ScriptObject item, TimelineItemType type)
{
    m_itemStack.append(TimelineItemEntry(item, m_frontend->newScriptArray(), type));
}

164
} // namespace WebCore
bolsinga@apple.com's avatar
bolsinga@apple.com committed
165 166

#endif // ENABLE(INSPECTOR)