Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: third_party/WebKit/Source/core/timing/PerformanceBase.cpp

Issue 2472583003: Navigation Timing Level 2 (Closed)
Patch Set: added TAO(timing-allow-origin) check and RA(redirect allow) check Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 "core/timing/PerformanceBase.h" 32 #include "core/timing/PerformanceBase.h"
33 33
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/DocumentTiming.h"
36 #include "core/dom/Element.h"
Yoav Weiss 2016/11/10 14:58:58 I believe DocumentTiming.h and Element.h are not n
sunjian 2016/11/11 21:48:05 I think i can be onboard with getting rid of "core
35 #include "core/events/Event.h" 37 #include "core/events/Event.h"
38 #include "core/frame/LocalFrame.h"
36 #include "core/frame/UseCounter.h" 39 #include "core/frame/UseCounter.h"
40 #include "core/loader/DocumentLoadTiming.h"
41 #include "core/loader/DocumentLoader.h"
37 #include "core/timing/PerformanceLongTaskTiming.h" 42 #include "core/timing/PerformanceLongTaskTiming.h"
43 #include "core/timing/PerformanceNavigationTiming.h"
38 #include "core/timing/PerformanceObserver.h" 44 #include "core/timing/PerformanceObserver.h"
39 #include "core/timing/PerformanceResourceTiming.h" 45 #include "core/timing/PerformanceResourceTiming.h"
40 #include "core/timing/PerformanceUserTiming.h" 46 #include "core/timing/PerformanceUserTiming.h"
47 #include "platform/RuntimeEnabledFeatures.h"
41 #include "platform/network/ResourceTimingInfo.h" 48 #include "platform/network/ResourceTimingInfo.h"
42 #include "platform/weborigin/SecurityOrigin.h" 49 #include "platform/weborigin/SecurityOrigin.h"
43 #include "wtf/CurrentTime.h" 50 #include "wtf/CurrentTime.h"
44 #include <algorithm> 51 #include <algorithm>
45 52
46 namespace blink { 53 namespace blink {
47 54
48 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; 55 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>;
49 56
50 static const size_t defaultResourceTimingBufferSize = 150; 57 static const size_t defaultResourceTimingBufferSize = 150;
51 static const size_t defaultFrameTimingBufferSize = 150; 58 static const size_t defaultFrameTimingBufferSize = 150;
52 59
53 PerformanceBase::PerformanceBase(double timeOrigin) 60 PerformanceBase::PerformanceBase(double timeOrigin)
54 : m_frameTimingBufferSize(defaultFrameTimingBufferSize), 61 : m_frameTimingBufferSize(defaultFrameTimingBufferSize),
55 m_resourceTimingBufferSize(defaultResourceTimingBufferSize), 62 m_resourceTimingBufferSize(defaultResourceTimingBufferSize),
63 m_navigationTiming(nullptr),
Yoav Weiss 2016/11/10 14:58:58 Is the nullptr initialization needed? (both here a
sunjian 2016/11/11 21:48:05 I will get rid of m_navigationTiming's redundant i
56 m_userTiming(nullptr), 64 m_userTiming(nullptr),
kinuko 2016/11/10 17:55:33 it's not related to this change but ditto for this
sunjian 2016/11/11 21:48:05 Acknowledged.
57 m_timeOrigin(timeOrigin), 65 m_timeOrigin(timeOrigin),
58 m_observerFilterOptions(PerformanceEntry::Invalid), 66 m_observerFilterOptions(PerformanceEntry::Invalid),
59 m_deliverObservationsTimer( 67 m_deliverObservationsTimer(
60 this, 68 this,
61 &PerformanceBase::deliverObservationsTimerFired) {} 69 &PerformanceBase::deliverObservationsTimerFired) {}
62 70
63 PerformanceBase::~PerformanceBase() {} 71 PerformanceBase::~PerformanceBase() {}
64 72
65 const AtomicString& PerformanceBase::interfaceName() const { 73 const AtomicString& PerformanceBase::interfaceName() const {
66 return EventTargetNames::Performance; 74 return EventTargetNames::Performance;
67 } 75 }
68 76
69 PerformanceTiming* PerformanceBase::timing() const { 77 PerformanceTiming* PerformanceBase::timing() const {
70 return nullptr; 78 return nullptr;
71 } 79 }
72 80
73 PerformanceEntryVector PerformanceBase::getEntries() const { 81 PerformanceEntryVector PerformanceBase::getEntries() const {
74 PerformanceEntryVector entries; 82 PerformanceEntryVector entries;
75 83
76 entries.appendVector(m_resourceTimingBuffer); 84 entries.appendVector(m_resourceTimingBuffer);
85 if (RuntimeEnabledFeatures::performanceNavigationTiming2Enabled())
Yoav Weiss 2016/11/10 14:58:58 We should append m_navigationTiming only when it's
sunjian 2016/11/11 21:48:05 Done.
86 entries.append(m_navigationTiming);
77 entries.appendVector(m_frameTimingBuffer); 87 entries.appendVector(m_frameTimingBuffer);
78 88
79 if (m_userTiming) { 89 if (m_userTiming) {
80 entries.appendVector(m_userTiming->getMarks()); 90 entries.appendVector(m_userTiming->getMarks());
81 entries.appendVector(m_userTiming->getMeasures()); 91 entries.appendVector(m_userTiming->getMeasures());
82 } 92 }
83 93
84 std::sort(entries.begin(), entries.end(), 94 std::sort(entries.begin(), entries.end(),
85 PerformanceEntry::startTimeCompareLessThan); 95 PerformanceEntry::startTimeCompareLessThan);
86 return entries; 96 return entries;
87 } 97 }
88 98
89 PerformanceEntryVector PerformanceBase::getEntriesByType( 99 PerformanceEntryVector PerformanceBase::getEntriesByType(
90 const String& entryType) { 100 const String& entryType) {
91 PerformanceEntryVector entries; 101 PerformanceEntryVector entries;
92 PerformanceEntry::EntryType type = 102 PerformanceEntry::EntryType type =
93 PerformanceEntry::toEntryTypeEnum(entryType); 103 PerformanceEntry::toEntryTypeEnum(entryType);
94 104
95 switch (type) { 105 switch (type) {
96 case PerformanceEntry::Invalid: 106 case PerformanceEntry::Invalid:
97 return entries; 107 return entries;
98 case PerformanceEntry::LongTask: 108 case PerformanceEntry::LongTask:
99 // Unsupported for LongTask. Per the spec, Long task entries can only be 109 // Unsupported for LongTask. Per the spec, Long task entries can only be
100 // accessed via Performance Observer. No separate buffer is maintained. 110 // accessed via Performance Observer. No separate buffer is maintained.
101 return entries; 111 return entries;
102 case PerformanceEntry::Resource: 112 case PerformanceEntry::Resource:
103 for (const auto& resource : m_resourceTimingBuffer) 113 for (const auto& resource : m_resourceTimingBuffer)
104 entries.append(resource); 114 entries.append(resource);
105 break; 115 break;
116 case PerformanceEntry::Navigation:
117 if (RuntimeEnabledFeatures::performanceNavigationTiming2Enabled())
Yoav Weiss 2016/11/10 14:58:58 same as above. Only add when non-null and no need
sunjian 2016/11/11 21:48:05 Done.
118 entries.append(m_navigationTiming);
119 break;
106 case PerformanceEntry::Composite: 120 case PerformanceEntry::Composite:
107 case PerformanceEntry::Render: 121 case PerformanceEntry::Render:
108 for (const auto& frame : m_frameTimingBuffer) { 122 for (const auto& frame : m_frameTimingBuffer) {
109 if (type == frame->entryTypeEnum()) { 123 if (type == frame->entryTypeEnum()) {
110 entries.append(frame); 124 entries.append(frame);
111 } 125 }
112 } 126 }
113 break; 127 break;
114 case PerformanceEntry::Mark: 128 case PerformanceEntry::Mark:
115 if (m_userTiming) 129 if (m_userTiming)
(...skipping 20 matching lines...) Expand all
136 if (!entryType.isNull() && type == PerformanceEntry::Invalid) 150 if (!entryType.isNull() && type == PerformanceEntry::Invalid)
137 return entries; 151 return entries;
138 152
139 if (entryType.isNull() || type == PerformanceEntry::Resource) { 153 if (entryType.isNull() || type == PerformanceEntry::Resource) {
140 for (const auto& resource : m_resourceTimingBuffer) { 154 for (const auto& resource : m_resourceTimingBuffer) {
141 if (resource->name() == name) 155 if (resource->name() == name)
142 entries.append(resource); 156 entries.append(resource);
143 } 157 }
144 } 158 }
145 159
160 if (entryType.isNull() || type == PerformanceEntry::Navigation) {
161 if (RuntimeEnabledFeatures::performanceNavigationTiming2Enabled() &&
162 m_navigationTiming->name() == name)
Yoav Weiss 2016/11/10 14:58:58 A check for nav timing not being null would preven
sunjian 2016/11/11 21:48:05 Done.
163 entries.append(m_navigationTiming);
164 }
165
146 if (entryType.isNull() || type == PerformanceEntry::Composite || 166 if (entryType.isNull() || type == PerformanceEntry::Composite ||
147 type == PerformanceEntry::Render) { 167 type == PerformanceEntry::Render) {
148 for (const auto& frame : m_frameTimingBuffer) { 168 for (const auto& frame : m_frameTimingBuffer) {
149 if (frame->name() == name && 169 if (frame->name() == name &&
150 (entryType.isNull() || entryType == frame->entryType())) 170 (entryType.isNull() || entryType == frame->entryType()))
151 entries.append(frame); 171 entries.append(frame);
152 } 172 }
153 } 173 }
154 174
155 if (m_userTiming) { 175 if (m_userTiming) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); 305 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd();
286 306
287 PerformanceEntry* entry = PerformanceResourceTiming::create( 307 PerformanceEntry* entry = PerformanceResourceTiming::create(
288 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, 308 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails,
289 allowRedirectDetails); 309 allowRedirectDetails);
290 notifyObserversOfEntry(*entry); 310 notifyObserversOfEntry(*entry);
291 if (!isResourceTimingBufferFull()) 311 if (!isResourceTimingBufferFull())
292 addResourceTimingBuffer(*entry); 312 addResourceTimingBuffer(*entry);
293 } 313 }
294 314
315 void PerformanceBase::addNavigationTiming(LocalFrame* frame) {
316 if (!RuntimeEnabledFeatures::performanceNavigationTiming2Enabled())
317 return;
318 DCHECK(frame);
kinuko 2016/11/10 17:55:33 We have null-checks for frame() at the callsite, a
panicker 2016/11/11 17:14:02 Yep, if frame is NULL we should not call addNaviga
sunjian 2016/11/11 21:48:05 Done.
319 const DocumentLoader* documentLoader = frame->loader().documentLoader();
320 DCHECK(documentLoader);
321 const DocumentLoadTiming documentLoadTiming = documentLoader->timing();
322 const DocumentTiming documentTiming = frame->document()->timing();
323
324 ResourceResponse finalResponse = documentLoader->response();
kinuko 2016/11/10 17:55:33 This creates a copy, looks like just using a const
sunjian 2016/11/11 21:48:05 Done.
325
326 ResourceLoadTiming* resourceLoadTiming = finalResponse.resourceLoadTiming();
327 double lastRedirectEndTime = documentLoadTiming.redirectEnd();
328 double finishTime = documentLoadTiming.loadEventEnd();
329
330 // TODO(sunjian) Implement transfer size. crbug/663187
331 unsigned long long transferSize = 0;
332 unsigned long long encodedBodyLength = finalResponse.encodedBodyLength();
333 unsigned long long decodedBodyLength = finalResponse.decodedBodyLength();
334 bool didReuseConnection = finalResponse.connectionReused();
335
336 m_navigationTiming = new PerformanceNavigationTiming(
337 timeOrigin(), documentLoadTiming.unloadEventStart(),
338 documentLoadTiming.unloadEventEnd(), documentLoadTiming.loadEventStart(),
339 documentLoadTiming.loadEventEnd(), documentLoadTiming.redirectCount(),
340 documentTiming.domInteractive(),
341 documentTiming.domContentLoadedEventStart(),
342 documentTiming.domContentLoadedEventEnd(), documentTiming.domComplete(),
343 documentLoader->getNavigationType(), documentLoadTiming.redirectStart(),
344 documentLoadTiming.redirectEnd(), documentLoadTiming.fetchStart(),
345 documentLoadTiming.responseEnd(),
346 documentLoadTiming.hasCrossOriginRedirect(),
347 documentLoadTiming.hasSameOriginAsPreviousDocument(), resourceLoadTiming,
348 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength,
349 decodedBodyLength, didReuseConnection);
350 notifyObserversOfEntry(*m_navigationTiming);
351 }
352
295 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) { 353 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) {
296 m_resourceTimingBuffer.append(&entry); 354 m_resourceTimingBuffer.append(&entry);
297 355
298 if (isResourceTimingBufferFull()) { 356 if (isResourceTimingBufferFull()) {
299 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); 357 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull));
300 dispatchEvent( 358 dispatchEvent(
301 Event::create(EventTypeNames::webkitresourcetimingbufferfull)); 359 Event::create(EventTypeNames::webkitresourcetimingbufferfull));
302 } 360 }
303 } 361 }
304 362
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 return monotonicTimeToDOMHighResTimeStamp(monotonicTime) * 1000; 515 return monotonicTimeToDOMHighResTimeStamp(monotonicTime) * 1000;
458 } 516 }
459 517
460 DOMHighResTimeStamp PerformanceBase::now() const { 518 DOMHighResTimeStamp PerformanceBase::now() const {
461 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime()); 519 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime());
462 } 520 }
463 521
464 DEFINE_TRACE(PerformanceBase) { 522 DEFINE_TRACE(PerformanceBase) {
465 visitor->trace(m_frameTimingBuffer); 523 visitor->trace(m_frameTimingBuffer);
466 visitor->trace(m_resourceTimingBuffer); 524 visitor->trace(m_resourceTimingBuffer);
525 visitor->trace(m_navigationTiming);
467 visitor->trace(m_userTiming); 526 visitor->trace(m_userTiming);
468 visitor->trace(m_observers); 527 visitor->trace(m_observers);
469 visitor->trace(m_activeObservers); 528 visitor->trace(m_activeObservers);
470 visitor->trace(m_suspendedObservers); 529 visitor->trace(m_suspendedObservers);
471 EventTargetWithInlineData::trace(visitor); 530 EventTargetWithInlineData::trace(visitor);
472 } 531 }
473 532
474 } // namespace blink 533 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698