From 306db80410e802b0fe9a3b5273d4cf29586a1b17 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 14:15:18 +0200 Subject: moebius#161: The Performance Resource Timing (make timestamps be relative to startTime) https://github.com/MoonchildProductions/moebius/pull/161 --- dom/performance/PerformanceMainThread.cpp | 99 ++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 34 deletions(-) (limited to 'dom/performance/PerformanceMainThread.cpp') diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index 5c259cfb8..64c06d3ea 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -16,7 +16,8 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceMainThread) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PerformanceMainThread, Performance) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTiming, - mNavigation) + mNavigation, + mDocEntry) tmp->mMozMemory = nullptr; mozilla::DropJSObjects(this); NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -24,7 +25,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PerformanceMainThread, Performance) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTiming, - mNavigation) + mNavigation, + mDocEntry) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -152,38 +154,7 @@ PerformanceMainThread::AddEntry(nsIHttpChannel* channel, // The PerformanceResourceTiming object will use the PerformanceTiming // object to get all the required timings. RefPtr performanceEntry = - new PerformanceResourceTiming(performanceTiming, this, entryName); - - nsAutoCString protocol; - channel->GetProtocolVersion(protocol); - - // If this is a local fetch, nextHopProtocol should be set to empty string. - nsCOMPtr cachedChannel = do_QueryInterface(channel); - if (cachedChannel) { - bool isFromCache; - if (NS_SUCCEEDED(cachedChannel->IsFromCache(&isFromCache)) - && isFromCache) { - protocol.Truncate(); - } - } - - performanceEntry->SetNextHopProtocol(NS_ConvertUTF8toUTF16(protocol)); - - uint64_t encodedBodySize = 0; - channel->GetEncodedBodySize(&encodedBodySize); - performanceEntry->SetEncodedBodySize(encodedBodySize); - - uint64_t transferSize = 0; - channel->GetTransferSize(&transferSize); - performanceEntry->SetTransferSize(transferSize); - - uint64_t decodedBodySize = 0; - channel->GetDecodedBodySize(&decodedBodySize); - if (decodedBodySize == 0) { - decodedBodySize = encodedBodySize; - } - performanceEntry->SetDecodedBodySize(decodedBodySize); - + new PerformanceResourceTiming(performanceTiming, this, entryName, channel); // If the initiator type had no valid value, then set it to the default // ("other") value. if (initiatorType.IsEmpty()) { @@ -337,5 +308,65 @@ PerformanceMainThread::CreationTime() const return GetDOMTiming()->GetNavigationStart(); } +void +PerformanceMainThread::EnsureDocEntry() +{ + if (!mDocEntry && nsContentUtils::IsPerformanceNavigationTimingEnabled()) { + nsCOMPtr httpChannel = do_QueryInterface(mChannel); + RefPtr timing = + new PerformanceTiming(this, mChannel, nullptr, 0); + mDocEntry = new PerformanceNavigationTiming(timing, this, + httpChannel); + } +} + + +void +PerformanceMainThread::GetEntries(nsTArray>& aRetval) +{ + aRetval = mResourceEntries; + aRetval.AppendElements(mUserEntries); + + EnsureDocEntry(); + if (mDocEntry) { + aRetval.AppendElement(mDocEntry); + } + + aRetval.Sort(PerformanceEntryComparator()); +} + +void +PerformanceMainThread::GetEntriesByType(const nsAString& aEntryType, + nsTArray>& aRetval) +{ + if (aEntryType.EqualsLiteral("navigation")) { + aRetval.Clear(); + EnsureDocEntry(); + if (mDocEntry) { + aRetval.AppendElement(mDocEntry); + } + return; + } + + Performance::GetEntriesByType(aEntryType, aRetval); +} + +void +PerformanceMainThread::GetEntriesByName(const nsAString& aName, + const Optional& aEntryType, + nsTArray>& aRetval) +{ + if (aName.EqualsLiteral("document")) { + aRetval.Clear(); + EnsureDocEntry(); + if (mDocEntry) { + aRetval.AppendElement(mDocEntry); + } + return; + } + + Performance::GetEntriesByName(aName, aEntryType, aRetval); +} + } // dom namespace } // mozilla namespace -- cgit v1.2.3