OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Intel Inc. All rights reserved. | 3 * Copyright (C) 2012 Intel Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 17 matching lines...) Expand all Loading... |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 #include "config.h" | 32 #include "config.h" |
33 #include "core/timing/Performance.h" | 33 #include "core/timing/Performance.h" |
34 | 34 |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
37 #include "core/loader/DocumentLoader.h" | 37 #include "core/loader/DocumentLoader.h" |
38 #include "core/timing/ResourceTimingInfo.h" | 38 #include "core/timing/PerformanceDrawTiming.h" |
39 #include "core/timing/PerformanceResourceTiming.h" | 39 #include "core/timing/PerformanceResourceTiming.h" |
40 #include "core/timing/PerformanceUserTiming.h" | 40 #include "core/timing/PerformanceUserTiming.h" |
| 41 #include "core/timing/ResourceTimingInfo.h" |
41 #include "platform/weborigin/SecurityOrigin.h" | 42 #include "platform/weborigin/SecurityOrigin.h" |
42 #include "wtf/CurrentTime.h" | 43 #include "wtf/CurrentTime.h" |
43 | 44 |
44 namespace WebCore { | 45 namespace WebCore { |
45 | 46 |
46 static const size_t defaultResourceTimingBufferSize = 150; | 47 static const size_t defaultResourceTimingBufferSize = 150; |
| 48 static const size_t defaultDrawTimingBufferSize = 150; |
47 | 49 |
48 Performance::Performance(LocalFrame* frame) | 50 Performance::Performance(LocalFrame* frame) |
49 : DOMWindowProperty(frame) | 51 : DOMWindowProperty(frame) |
50 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) | 52 , m_resourceTimingBufferSize(defaultResourceTimingBufferSize) |
| 53 , m_drawTimingBufferSize(defaultDrawTimingBufferSize) |
51 , m_referenceTime(frame && frame->host() ? frame->document()->loader()->timi
ng()->referenceMonotonicTime() : 0.0) | 54 , m_referenceTime(frame && frame->host() ? frame->document()->loader()->timi
ng()->referenceMonotonicTime() : 0.0) |
52 , m_userTiming(nullptr) | 55 , m_userTiming(nullptr) |
53 { | 56 { |
54 ScriptWrappable::init(this); | 57 ScriptWrappable::init(this); |
55 } | 58 } |
56 | 59 |
57 Performance::~Performance() | 60 Performance::~Performance() |
58 { | 61 { |
59 } | 62 } |
60 | 63 |
(...skipping 29 matching lines...) Expand all Loading... |
90 | 93 |
91 return m_timing.get(); | 94 return m_timing.get(); |
92 } | 95 } |
93 | 96 |
94 PerformanceEntryVector Performance::getEntries() const | 97 PerformanceEntryVector Performance::getEntries() const |
95 { | 98 { |
96 PerformanceEntryVector entries; | 99 PerformanceEntryVector entries; |
97 | 100 |
98 entries.appendVector(m_resourceTimingBuffer); | 101 entries.appendVector(m_resourceTimingBuffer); |
99 | 102 |
| 103 entries.appendVector(m_drawTimingBuffer); |
| 104 |
100 if (m_userTiming) { | 105 if (m_userTiming) { |
101 entries.appendVector(m_userTiming->getMarks()); | 106 entries.appendVector(m_userTiming->getMarks()); |
102 entries.appendVector(m_userTiming->getMeasures()); | 107 entries.appendVector(m_userTiming->getMeasures()); |
103 } | 108 } |
104 | 109 |
105 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 110 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
106 return entries; | 111 return entries; |
107 } | 112 } |
108 | 113 |
109 PerformanceEntryVector Performance::getEntriesByType(const String& entryType) | 114 PerformanceEntryVector Performance::getEntriesByType(const String& entryType) |
110 { | 115 { |
111 PerformanceEntryVector entries; | 116 PerformanceEntryVector entries; |
112 | 117 |
113 if (equalIgnoringCase(entryType, "resource")) | 118 if (equalIgnoringCase(entryType, "resource")) |
114 for (PerformanceEntryVector::const_iterator resource = m_resourceTimingB
uffer.begin(); resource != m_resourceTimingBuffer.end(); ++resource) | 119 for (PerformanceEntryVector::const_iterator resource = m_resourceTimingB
uffer.begin(); resource != m_resourceTimingBuffer.end(); ++resource) |
115 entries.append(*resource); | 120 entries.append(*resource); |
116 | 121 |
| 122 if (equalIgnoringCase(entryType, "draw")) |
| 123 for (PerformanceEntryVector::const_iterator draw = m_drawTimingBuffer.be
gin(); draw != m_drawTimingBuffer.end(); ++draw) |
| 124 entries.append(*draw); |
| 125 |
117 if (m_userTiming) { | 126 if (m_userTiming) { |
118 if (equalIgnoringCase(entryType, "mark")) | 127 if (equalIgnoringCase(entryType, "mark")) |
119 entries.appendVector(m_userTiming->getMarks()); | 128 entries.appendVector(m_userTiming->getMarks()); |
120 else if (equalIgnoringCase(entryType, "measure")) | 129 else if (equalIgnoringCase(entryType, "measure")) |
121 entries.appendVector(m_userTiming->getMeasures()); | 130 entries.appendVector(m_userTiming->getMeasures()); |
122 } | 131 } |
123 | 132 |
124 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 133 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
125 return entries; | 134 return entries; |
126 } | 135 } |
127 | 136 |
128 PerformanceEntryVector Performance::getEntriesByName(const String& name, const S
tring& entryType) | 137 PerformanceEntryVector Performance::getEntriesByName(const String& name, const S
tring& entryType) |
129 { | 138 { |
130 PerformanceEntryVector entries; | 139 PerformanceEntryVector entries; |
131 | 140 |
132 if (entryType.isNull() || equalIgnoringCase(entryType, "resource")) | 141 if (entryType.isNull() || equalIgnoringCase(entryType, "resource")) |
133 for (PerformanceEntryVector::const_iterator resource = m_resourceTimingB
uffer.begin(); resource != m_resourceTimingBuffer.end(); ++resource) | 142 for (PerformanceEntryVector::const_iterator resource = m_resourceTimingB
uffer.begin(); resource != m_resourceTimingBuffer.end(); ++resource) |
134 if ((*resource)->name() == name) | 143 if ((*resource)->name() == name) |
135 entries.append(*resource); | 144 entries.append(*resource); |
136 | 145 |
| 146 if (entryType.isNull() || equalIgnoringCase(entryType, "draw")) { |
| 147 for (PerformanceEntryVector::const_iterator draw = m_drawTimingBuffer.be
gin(); draw != m_drawTimingBuffer.end(); ++draw) { |
| 148 if ((*draw)->name() == name) |
| 149 entries.append(*draw); |
| 150 } |
| 151 } |
137 if (m_userTiming) { | 152 if (m_userTiming) { |
138 if (entryType.isNull() || equalIgnoringCase(entryType, "mark")) | 153 if (entryType.isNull() || equalIgnoringCase(entryType, "mark")) |
139 entries.appendVector(m_userTiming->getMarks(name)); | 154 entries.appendVector(m_userTiming->getMarks(name)); |
140 if (entryType.isNull() || equalIgnoringCase(entryType, "measure")) | 155 if (entryType.isNull() || equalIgnoringCase(entryType, "measure")) |
141 entries.appendVector(m_userTiming->getMeasures(name)); | 156 entries.appendVector(m_userTiming->getMeasures(name)); |
142 } | 157 } |
143 | 158 |
144 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); | 159 std::sort(entries.begin(), entries.end(), PerformanceEntry::startTimeCompare
LessThan); |
145 return entries; | 160 return entries; |
146 } | 161 } |
147 | 162 |
148 void Performance::webkitClearResourceTimings() | 163 void Performance::webkitClearResourceTimings() |
149 { | 164 { |
150 m_resourceTimingBuffer.clear(); | 165 m_resourceTimingBuffer.clear(); |
151 } | 166 } |
152 | 167 |
153 void Performance::webkitSetResourceTimingBufferSize(unsigned size) | 168 void Performance::webkitSetResourceTimingBufferSize(unsigned size) |
154 { | 169 { |
155 m_resourceTimingBufferSize = size; | 170 m_resourceTimingBufferSize = size; |
156 if (isResourceTimingBufferFull()) | 171 if (isResourceTimingBufferFull()) |
157 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); | 172 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); |
158 } | 173 } |
159 | 174 |
| 175 void Performance::webkitClearDrawTimings() |
| 176 { |
| 177 m_drawTimingBuffer.clear(); |
| 178 } |
| 179 |
| 180 void Performance::webkitSetDrawTimingBufferSize(unsigned size) |
| 181 { |
| 182 m_drawTimingBufferSize = size; |
| 183 if (isDrawTimingBufferFull()) |
| 184 dispatchEvent(Event::create(EventTypeNames::webkitdrawtimingbufferfull))
; |
| 185 } |
| 186 |
160 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r
equestingDocument, const AtomicString& originalTimingAllowOrigin) | 187 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r
equestingDocument, const AtomicString& originalTimingAllowOrigin) |
161 { | 188 { |
162 AtomicallyInitializedStatic(AtomicString&, timingAllowOrigin = *new AtomicSt
ring("timing-allow-origin")); | 189 AtomicallyInitializedStatic(AtomicString&, timingAllowOrigin = *new AtomicSt
ring("timing-allow-origin")); |
163 | 190 |
164 RefPtr<SecurityOrigin> resourceOrigin = SecurityOrigin::create(response.url(
)); | 191 RefPtr<SecurityOrigin> resourceOrigin = SecurityOrigin::create(response.url(
)); |
165 if (resourceOrigin->isSameSchemeHostPort(requestingDocument->securityOrigin(
))) | 192 if (resourceOrigin->isSameSchemeHostPort(requestingDocument->securityOrigin(
))) |
166 return true; | 193 return true; |
167 | 194 |
168 const AtomicString& timingAllowOriginString = originalTimingAllowOrigin.isEm
pty() ? response.httpHeaderField(timingAllowOrigin) : originalTimingAllowOrigin; | 195 const AtomicString& timingAllowOriginString = originalTimingAllowOrigin.isEm
pty() ? response.httpHeaderField(timingAllowOrigin) : originalTimingAllowOrigin; |
169 if (timingAllowOriginString.isEmpty() || equalIgnoringCase(timingAllowOrigin
String, "null")) | 196 if (timingAllowOriginString.isEmpty() || equalIgnoringCase(timingAllowOrigin
String, "null")) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 262 |
236 if (isResourceTimingBufferFull()) | 263 if (isResourceTimingBufferFull()) |
237 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); | 264 dispatchEvent(Event::create(EventTypeNames::webkitresourcetimingbufferfu
ll)); |
238 } | 265 } |
239 | 266 |
240 bool Performance::isResourceTimingBufferFull() | 267 bool Performance::isResourceTimingBufferFull() |
241 { | 268 { |
242 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; | 269 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; |
243 } | 270 } |
244 | 271 |
| 272 void Performance::addDrawTiming(Document* initiatorDocument, unsigned sourceFram
e, double startTime) |
| 273 { |
| 274 if (isDrawTimingBufferFull()) |
| 275 return; |
| 276 |
| 277 RefPtrWillBeRawPtr<PerformanceEntry> entry = PerformanceDrawTiming::create(i
nitiatorDocument, sourceFrame, startTime); |
| 278 addDrawTimingBuffer(entry); |
| 279 } |
| 280 |
| 281 void Performance::addDrawTimingBuffer(PassRefPtrWillBeRawPtr<PerformanceEntry> e
ntry) |
| 282 { |
| 283 m_drawTimingBuffer.append(entry); |
| 284 |
| 285 if (isDrawTimingBufferFull()) |
| 286 dispatchEvent(Event::create(EventTypeNames::webkitdrawtimingbufferfull))
; |
| 287 } |
| 288 |
| 289 bool Performance::isDrawTimingBufferFull() |
| 290 { |
| 291 return m_drawTimingBuffer.size() >= m_drawTimingBufferSize; |
| 292 } |
| 293 |
245 void Performance::mark(const String& markName, ExceptionState& exceptionState) | 294 void Performance::mark(const String& markName, ExceptionState& exceptionState) |
246 { | 295 { |
247 if (!m_userTiming) | 296 if (!m_userTiming) |
248 m_userTiming = UserTiming::create(this); | 297 m_userTiming = UserTiming::create(this); |
249 m_userTiming->mark(markName, exceptionState); | 298 m_userTiming->mark(markName, exceptionState); |
250 } | 299 } |
251 | 300 |
252 void Performance::clearMarks(const String& markName) | 301 void Performance::clearMarks(const String& markName) |
253 { | 302 { |
254 if (!m_userTiming) | 303 if (!m_userTiming) |
(...skipping 18 matching lines...) Expand all Loading... |
273 double Performance::now() const | 322 double Performance::now() const |
274 { | 323 { |
275 return 1000.0 * (monotonicallyIncreasingTime() - m_referenceTime); | 324 return 1000.0 * (monotonicallyIncreasingTime() - m_referenceTime); |
276 } | 325 } |
277 | 326 |
278 void Performance::trace(Visitor* visitor) | 327 void Performance::trace(Visitor* visitor) |
279 { | 328 { |
280 visitor->trace(m_navigation); | 329 visitor->trace(m_navigation); |
281 visitor->trace(m_timing); | 330 visitor->trace(m_timing); |
282 visitor->trace(m_resourceTimingBuffer); | 331 visitor->trace(m_resourceTimingBuffer); |
| 332 visitor->trace(m_drawTimingBuffer); |
283 visitor->trace(m_userTiming); | 333 visitor->trace(m_userTiming); |
284 EventTargetWithInlineData::trace(visitor); | 334 EventTargetWithInlineData::trace(visitor); |
285 } | 335 } |
286 | 336 |
287 } // namespace WebCore | 337 } // namespace WebCore |
OLD | NEW |