2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "Performance.h"
35 #include "DocumentLoader.h"
36 #include "MemoryInfo.h"
37 #include "PerformanceEntry.h"
38 #include "PerformanceNavigation.h"
39 #include "PerformanceResourceTiming.h"
40 #include "PerformanceTiming.h"
41 #include "ResourceResponse.h"
42 #include <wtf/CurrentTime.h>
44 #if ENABLE(WEB_TIMING)
50 Performance::Performance(Frame* frame)
51 : DOMWindowProperty(frame)
55 Performance::~Performance()
59 const AtomicString& Performance::interfaceName() const
61 return eventNames().interfaceForPerformance;
64 ScriptExecutionContext* Performance::scriptExecutionContext() const
68 return frame()->document();
71 PassRefPtr<MemoryInfo> Performance::memory() const
73 return MemoryInfo::create(m_frame);
76 PerformanceNavigation* Performance::navigation() const
79 m_navigation = PerformanceNavigation::create(m_frame);
81 return m_navigation.get();
84 PerformanceTiming* Performance::timing() const
87 m_timing = PerformanceTiming::create(m_frame);
89 return m_timing.get();
92 #if ENABLE(PERFORMANCE_TIMELINE)
94 PassRefPtr<PerformanceEntryList> Performance::webkitGetEntries() const
96 RefPtr<PerformanceEntryList> entries = PerformanceEntryList::create();
98 #if ENABLE(RESOURCE_TIMING)
99 entries->appendAll(m_resourceTimingBuffer);
100 #endif // ENABLE(RESOURCE_TIMING)
105 PassRefPtr<PerformanceEntryList> Performance::webkitGetEntriesByType(const String& entryType)
107 RefPtr<PerformanceEntryList> entries = PerformanceEntryList::create();
109 #if ENABLE(RESOURCE_TIMING)
110 if (equalIgnoringCase(entryType, "resource"))
111 for (Vector<RefPtr<PerformanceEntry> >::const_iterator resource = m_resourceTimingBuffer.begin(); resource != m_resourceTimingBuffer.end(); ++resource)
112 entries->append(*resource);
113 #endif // ENABLE(RESOURCE_TIMING)
118 PassRefPtr<PerformanceEntryList> Performance::webkitGetEntriesByName(const String& name, const String& entryType)
120 RefPtr<PerformanceEntryList> entries = PerformanceEntryList::create();
122 #if ENABLE(RESOURCE_TIMING)
123 if (entryType.isNull() || equalIgnoringCase(entryType, "resource"))
124 for (Vector<RefPtr<PerformanceEntry> >::const_iterator resource = m_resourceTimingBuffer.begin(); resource != m_resourceTimingBuffer.end(); ++resource)
125 if ((*resource)->name() == name)
126 entries->append(*resource);
127 #endif // ENABLE(RESOURCE_TIMING)
132 #endif // ENABLE(PERFORMANCE_TIMELINE)
134 #if ENABLE(RESOURCE_TIMING)
136 void Performance::webkitClearResourceTimings()
138 m_resourceTimingBuffer.clear();
141 void Performance::webkitSetResourceTimingBufferSize(unsigned int)
143 // FIXME: Implement this.
146 void Performance::addResourceTiming(const ResourceRequest& request, const ResourceResponse& response, double finishTime, Document* requestingDocument)
148 if (!response.resourceLoadTiming())
151 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(request, response, finishTime, requestingDocument);
152 // FIXME: Need to enforce buffer limits.
153 m_resourceTimingBuffer.append(entry);
156 #endif // ENABLE(RESOURCE_TIMING)
158 EventTargetData* Performance::eventTargetData()
160 return &m_eventTargetData;
163 EventTargetData* Performance::ensureEventTargetData()
165 return &m_eventTargetData;
168 double Performance::webkitNow() const
170 return 1000.0 * m_frame->document()->loader()->timing()->convertMonotonicTimeToZeroBasedDocumentTime(monotonicallyIncreasingTime());
173 } // namespace WebCore
175 #endif // ENABLE(WEB_TIMING)