Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / Source / WebCore / page / Performance.cpp
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #include "config.h"
32 #include "Performance.h"
33
34 #include "Document.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>
43
44 #if ENABLE(WEB_TIMING)
45
46 #include "Frame.h"
47
48 namespace WebCore {
49
50 Performance::Performance(Frame* frame)
51     : DOMWindowProperty(frame)
52 {
53 }
54
55 Performance::~Performance()
56 {
57 }
58
59 const AtomicString& Performance::interfaceName() const
60 {
61     return eventNames().interfaceForPerformance;
62 }
63
64 ScriptExecutionContext* Performance::scriptExecutionContext() const
65 {
66     if (!frame())
67         return 0;
68     return frame()->document();
69 }
70
71 PassRefPtr<MemoryInfo> Performance::memory() const
72 {
73     return MemoryInfo::create(m_frame);
74 }
75
76 PerformanceNavigation* Performance::navigation() const
77 {
78     if (!m_navigation)
79         m_navigation = PerformanceNavigation::create(m_frame);
80
81     return m_navigation.get();
82 }
83
84 PerformanceTiming* Performance::timing() const
85 {
86     if (!m_timing)
87         m_timing = PerformanceTiming::create(m_frame);
88
89     return m_timing.get();
90 }
91
92 #if ENABLE(PERFORMANCE_TIMELINE)
93
94 PassRefPtr<PerformanceEntryList> Performance::webkitGetEntries() const
95 {
96     RefPtr<PerformanceEntryList> entries = PerformanceEntryList::create();
97
98 #if ENABLE(RESOURCE_TIMING)
99     entries->appendAll(m_resourceTimingBuffer);
100 #endif // ENABLE(RESOURCE_TIMING)
101
102     return entries;
103 }
104
105 PassRefPtr<PerformanceEntryList> Performance::webkitGetEntriesByType(const String& entryType)
106 {
107     RefPtr<PerformanceEntryList> entries = PerformanceEntryList::create();
108
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)
114
115     return entries;
116 }
117
118 PassRefPtr<PerformanceEntryList> Performance::webkitGetEntriesByName(const String& name, const String& entryType)
119 {
120     RefPtr<PerformanceEntryList> entries = PerformanceEntryList::create();
121
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)
128
129     return entries;
130 }
131
132 #endif // ENABLE(PERFORMANCE_TIMELINE)
133
134 #if ENABLE(RESOURCE_TIMING)
135
136 void Performance::webkitClearResourceTimings()
137 {
138     m_resourceTimingBuffer.clear();
139 }
140
141 void Performance::webkitSetResourceTimingBufferSize(unsigned int)
142 {
143     // FIXME: Implement this.
144 }
145
146 void Performance::addResourceTiming(const ResourceRequest& request, const ResourceResponse& response, double finishTime, Document* requestingDocument)
147 {
148     if (!response.resourceLoadTiming())
149         return;
150
151     RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(request, response, finishTime, requestingDocument);
152     // FIXME: Need to enforce buffer limits.
153     m_resourceTimingBuffer.append(entry);
154 }
155
156 #endif // ENABLE(RESOURCE_TIMING)
157
158 EventTargetData* Performance::eventTargetData()
159 {
160     return &m_eventTargetData;
161 }
162
163 EventTargetData* Performance::ensureEventTargetData()
164 {
165     return &m_eventTargetData;
166 }
167
168 double Performance::webkitNow() const
169 {
170     return 1000.0 * m_frame->document()->loader()->timing()->convertMonotonicTimeToZeroBasedDocumentTime(monotonicallyIncreasingTime());
171 }
172
173 } // namespace WebCore
174
175 #endif // ENABLE(WEB_TIMING)