Index: third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
diff --git a/third_party/WebKit/Source/core/timing/PerformanceBase.cpp b/third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
index 88094fa06e3bbc734cc74a5cfebffa8c64b236f7..01716862be34b13ebaadc2db368f9b5c562628a2 100644 |
--- a/third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
+++ b/third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
@@ -32,9 +32,15 @@ |
#include "core/timing/PerformanceBase.h" |
#include "core/dom/Document.h" |
+#include "core/dom/DocumentTiming.h" |
+#include "core/dom/Element.h" |
#include "core/events/Event.h" |
+#include "core/frame/LocalFrame.h" |
#include "core/frame/UseCounter.h" |
+#include "core/loader/DocumentLoadTiming.h" |
+#include "core/loader/DocumentLoader.h" |
#include "core/timing/PerformanceLongTaskTiming.h" |
+#include "core/timing/PerformanceNavigationTiming.h" |
#include "core/timing/PerformanceObserver.h" |
#include "core/timing/PerformanceResourceTiming.h" |
#include "core/timing/PerformanceUserTiming.h" |
@@ -74,6 +80,7 @@ PerformanceEntryVector PerformanceBase::getEntries() const { |
PerformanceEntryVector entries; |
entries.appendVector(m_resourceTimingBuffer); |
+ entries.appendVector(m_navigationTimingBuffer); |
entries.appendVector(m_frameTimingBuffer); |
if (m_userTiming) { |
@@ -168,6 +175,10 @@ void PerformanceBase::clearResourceTimings() { |
m_resourceTimingBuffer.clear(); |
} |
+void PerformanceBase::clearNavigationTimings() { |
+ m_navigationTimingBuffer.clear(); |
+} |
+ |
void PerformanceBase::setResourceTimingBufferSize(unsigned size) { |
m_resourceTimingBufferSize = size; |
if (isResourceTimingBufferFull()) { |
@@ -292,6 +303,100 @@ void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info) { |
addResourceTimingBuffer(*entry); |
} |
+const DocumentLoader* PerformanceBase::documentLoader(LocalFrame* frame) { |
+ if (!frame) |
+ return nullptr; |
+ return frame->loader().documentLoader(); |
+} |
+ |
+const DocumentLoadTiming* PerformanceBase::documentLoadTiming( |
+ LocalFrame* frame) { |
+ const DocumentLoader* loader = documentLoader(frame); |
+ if (!loader) |
+ return nullptr; |
+ return &loader->timing(); |
+} |
+ |
+const DocumentTiming* PerformanceBase::documentTiming(LocalFrame* frame) { |
+ if (!frame) |
+ return nullptr; |
+ |
+ Document* document = frame->document(); |
+ if (!document) |
+ return nullptr; |
+ |
+ return &document->timing(); |
+} |
+ |
+AtomicString PerformanceBase::getNavigationType(LocalFrame* frame) { |
+ if (!frame) |
+ return "navigate"; |
+ |
+ DocumentLoader* documentLoader = frame->loader().documentLoader(); |
+ if (!documentLoader) |
+ return "navigate"; |
+ |
+ switch (documentLoader->getNavigationType()) { |
+ case NavigationTypeReload: |
+ return "reload"; |
+ case NavigationTypeBackForward: |
+ return "back_forward"; |
+ default: |
+ return "navigate"; |
+ } |
+} |
+ |
+void PerformanceBase::addNavigationTiming(LocalFrame* frame) { |
panicker
2016/11/02 20:12:37
Add a check for the runtimeflag:
if (!RuntimeEnabl
sunjian
2016/11/04 01:12:38
Done.
|
+ DCHECK(!frame); |
+ if (!frame) |
+ return; |
+ const DocumentLoader* documentLoader = PerformanceBase::documentLoader(frame); |
+ DCHECK(!documentLoader); |
+ if (!documentLoader) |
panicker
2016/11/02 20:12:37
replace DCHECK with ASSERT and remove this if
sunjian
2016/11/04 01:12:38
Done.
|
+ return; |
+ const DocumentLoadTiming* documentLoadTiming = |
+ PerformanceBase::documentLoadTiming(frame); |
+ const DocumentTiming* documentTiming = PerformanceBase::documentTiming(frame); |
+ DCHECK(!documentLoadTiming); |
+ DCHECK(!documentTiming); |
+ if (!documentTiming || !documentLoadTiming) |
panicker
2016/11/02 20:12:37
(same comment)
sunjian
2016/11/04 01:12:38
Done.
|
+ return; |
+ |
+ ResourceResponse finalResponse = documentLoader->response(); |
+ |
+ // Right now NavigationType doesn't seem to have a Prerender type yet |
panicker
2016/11/02 20:12:37
Prefix with:
// TODO(sunjian): Right now ....
sunjian
2016/11/04 01:12:39
Done.
|
+ // Need to look into this |
+ AtomicString type = getNavigationType(frame); |
+ |
+ ResourceLoadTiming* resourceLoadTiming = finalResponse.resourceLoadTiming(); |
+ double lastRedirectEndTime = documentLoadTiming->redirectEnd(); |
+ double finishTime = documentLoadTiming->loadEventEnd(); |
+ // TODO(sunjian) for now just use encodedDataLength as transferSize, but will |
panicker
2016/11/02 20:12:37
for now just set it to 0
sunjian
2016/11/04 01:12:39
Done.
|
+ // have to come |
+ // back and fix it. |
+ unsigned long long transferSize = finalResponse.encodedDataLength(); |
+ unsigned long long encodedBodyLength = finalResponse.encodedBodyLength(); |
+ unsigned long long decodedBodyLength = finalResponse.decodedBodyLength(); |
+ bool didReuseConnection = finalResponse.connectionReused(); |
+ |
+ PerformanceEntry* entry = PerformanceNavigationTiming::create( |
+ timeOrigin(), documentLoadTiming->unloadEventStart(), |
+ documentLoadTiming->unloadEventEnd(), |
+ documentLoadTiming->loadEventStart(), documentLoadTiming->loadEventEnd(), |
+ documentLoadTiming->redirectCount(), documentTiming->domInteractive(), |
+ documentTiming->domContentLoadedEventStart(), |
+ documentTiming->domContentLoadedEventEnd(), documentTiming->domComplete(), |
+ type, documentLoadTiming->redirectStart(), |
+ documentLoadTiming->redirectEnd(), documentLoadTiming->fetchStart(), |
+ documentLoadTiming->responseEnd(), |
+ documentLoadTiming->hasCrossOriginRedirect(), |
+ documentLoadTiming->hasSameOriginAsPreviousDocument(), resourceLoadTiming, |
+ lastRedirectEndTime, finishTime, transferSize, encodedBodyLength, |
+ decodedBodyLength, didReuseConnection); |
+ notifyObserversOfEntry(*entry); |
+ m_navigationTimingBuffer.append(entry); |
panicker
2016/11/02 20:12:37
assert that there's at most 1 entry in buffer?
sunjian
2016/11/04 01:12:38
Done.
|
+} |
+ |
void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) { |
m_resourceTimingBuffer.append(&entry); |
@@ -464,6 +569,7 @@ DOMHighResTimeStamp PerformanceBase::now() const { |
DEFINE_TRACE(PerformanceBase) { |
visitor->trace(m_frameTimingBuffer); |
visitor->trace(m_resourceTimingBuffer); |
+ visitor->trace(m_navigationTimingBuffer); |
visitor->trace(m_userTiming); |
visitor->trace(m_observers); |
visitor->trace(m_activeObservers); |