diff options
Diffstat (limited to 'dom/performance/PerformanceTiming.h')
-rwxr-xr-x | dom/performance/PerformanceTiming.h | 288 |
1 files changed, 180 insertions, 108 deletions
diff --git a/dom/performance/PerformanceTiming.h b/dom/performance/PerformanceTiming.h index c0d4b6237b..91bd14f0d7 100755 --- a/dom/performance/PerformanceTiming.h +++ b/dom/performance/PerformanceTiming.h @@ -19,44 +19,38 @@ class nsITimedChannel; namespace mozilla { namespace dom { -// Script "performance.timing" object -class PerformanceTiming final : public nsWrapperCache +class PerformanceTimingData final { public: -/** - * @param aPerformance - * The performance object (the JS parent). - * This will allow access to "window.performance.timing" attribute for - * the navigation timing (can't be null). - * @param aChannel - * An nsITimedChannel used to gather all the networking timings by both - * the navigation timing and the resource timing (can't be null). - * @param aHttpChannel - * An nsIHttpChannel (the resource's http channel). - * This will be used by the resource timing cross-domain check - * algorithm. - * Argument is null for the navigation timing (navigation timing uses - * another algorithm for the cross-domain redirects). - * @param aZeroTime - * The offset that will be added to the timestamp of each event. This - * argument should be equal to performance.navigationStart for - * navigation timing and "0" for the resource timing. - */ - PerformanceTiming(Performance* aPerformance, - nsITimedChannel* aChannel, - nsIHttpChannel* aHttpChannel, - DOMHighResTimeStamp aZeroTime); - NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PerformanceTiming) - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(PerformanceTiming) + PerformanceTimingData(nsITimedChannel* aChannel, + nsIHttpChannel* aHttpChannel, + DOMHighResTimeStamp aZeroTime); - nsDOMNavigationTiming* GetDOMTiming() const + void SetPropertiesFromHttpChannel(nsIHttpChannel* aHttpChannel, nsITimedChannel* aChannel); + + bool IsInitialized() const { - return mPerformance->GetDOMTiming(); + return mInitialized; } - Performance* GetParentObject() const + const nsString& NextHopProtocol() const { - return mPerformance; + return mNextHopProtocol; + } + + uint64_t TransferSize() const + { + return mTimingAllowed ? mTransferSize : 0; + } + + uint64_t EncodedBodySize() const + { + return mTimingAllowed ? mEncodedBodySize : 0; + } + + uint64_t DecodedBodySize() const + { + return mTimingAllowed ? mDecodedBodySize : 0; } /** @@ -68,11 +62,16 @@ public: * page), if the given TimeStamp is valid. Otherwise, it will return * the FetchStart timing value. */ - inline DOMHighResTimeStamp TimeStampToReducedDOMHighResOrFetchStart(TimeStamp aStamp) + inline DOMHighResTimeStamp + TimeStampToReducedDOMHighResOrFetchStart(Performance* aPerformance, + TimeStamp aStamp) { + MOZ_ASSERT(aPerformance); + return (!aStamp.IsNull()) - ? TimerClamping::ReduceMsTimeValue(TimeStampToDOMHighRes(aStamp)) - : FetchStartHighRes(); + ? TimerClamping::ReduceMsTimeValue( + TimeStampToDOMHighRes(aPerformance, aStamp)) + : FetchStartHighRes(aPerformance); } /** @@ -83,7 +82,7 @@ public: * * The algorithm operates in 2 steps: * 1. The first step is to subtract the two timestamps: the argument (the - * envet's timesramp) and the navigation start timestamp. This will result in + * event's timestamp) and the navigation start timestamp. This will result in * a relative timestamp of the event (relative to the navigation start - * window.performance.timing.navigationStart). * 2. The second step is to add any required offset (the mZeroTime). For now, @@ -99,17 +98,154 @@ public: * be null. * @return number of milliseconds value as one of: * - relative to the navigation start time, time the user has landed on the - * page + * page * - an absolute wall clock time since the unix epoch */ - inline DOMHighResTimeStamp TimeStampToDOMHighRes(TimeStamp aStamp) const + inline DOMHighResTimeStamp + TimeStampToDOMHighRes(Performance* aPerformance, TimeStamp aStamp) const { + MOZ_ASSERT(aPerformance); MOZ_ASSERT(!aStamp.IsNull()); + TimeDuration duration = - aStamp - GetDOMTiming()->GetNavigationStartTimeStamp(); + aStamp - aPerformance->GetDOMTiming()->GetNavigationStartTimeStamp(); return duration.ToMilliseconds() + mZeroTime; } + // The last channel's AsyncOpen time. This may occur before the FetchStart + // in some cases. + DOMHighResTimeStamp AsyncOpenHighRes(Performance* aPerformance); + + // High resolution (used by resource timing) + DOMHighResTimeStamp WorkerStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp FetchStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp RedirectStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp RedirectEndHighRes(Performance* aPerformance); + DOMHighResTimeStamp DomainLookupStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp DomainLookupEndHighRes(Performance* aPerformance); + DOMHighResTimeStamp ConnectStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp SecureConnectionStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp ConnectEndHighRes(Performance* aPerformance); + DOMHighResTimeStamp RequestStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp ResponseStartHighRes(Performance* aPerformance); + DOMHighResTimeStamp ResponseEndHighRes(Performance* aPerformance); + + DOMHighResTimeStamp ZeroTime() const { return mZeroTime; } + + uint8_t RedirectCountReal() const { return mRedirectCount; } + uint8_t GetRedirectCount() const; + + bool AllRedirectsSameOrigin() const { return mAllRedirectsSameOrigin; } + + // If this is false the values of redirectStart/End will be 0 This is false if + // no redirects occured, or if any of the responses failed the + // timing-allow-origin check in HttpBaseChannel::TimingAllowCheck + bool ShouldReportCrossOriginRedirect() const; + + // Cached result of CheckAllowedOrigin. If false, security sensitive + // attributes of the resourceTiming object will be set to 0 + bool TimingAllowed() const + { + return mTimingAllowed; + } + +private: + // Checks if the resource is either same origin as the page that started + // the load, or if the response contains the Timing-Allow-Origin header + // with a value of * or matching the domain of the loading Principal + bool CheckAllowedOrigin(nsIHttpChannel* aResourceChannel, + nsITimedChannel* aChannel); + + nsString mNextHopProtocol; + + TimeStamp mAsyncOpen; + TimeStamp mRedirectStart; + TimeStamp mRedirectEnd; + TimeStamp mDomainLookupStart; + TimeStamp mDomainLookupEnd; + TimeStamp mConnectStart; + TimeStamp mSecureConnectionStart; + TimeStamp mConnectEnd; + TimeStamp mRequestStart; + TimeStamp mResponseStart; + TimeStamp mCacheReadStart; + TimeStamp mResponseEnd; + TimeStamp mCacheReadEnd; + + // ServiceWorker interception timing information + TimeStamp mWorkerStart; + TimeStamp mWorkerRequestStart; + TimeStamp mWorkerResponseEnd; + + // This is an offset that will be added to each timing ([ms] resolution). + // There are only 2 possible values: (1) logicaly equal to navigationStart + // TimeStamp (results are absolute timstamps - wallclock); (2) "0" (results + // are relative to the navigation start). + DOMHighResTimeStamp mZeroTime; + + DOMHighResTimeStamp mFetchStart; + + uint64_t mEncodedBodySize; + uint64_t mTransferSize; + uint64_t mDecodedBodySize; + + uint8_t mRedirectCount; + + bool mAllRedirectsSameOrigin; + + // If the resourceTiming object should have non-zero redirectStart and + // redirectEnd attributes. It is false if there were no redirects, or if any + // of the responses didn't pass the timing-allow-check + bool mReportCrossOriginRedirect; + + bool mSecureConnection; + + bool mTimingAllowed; + + bool mInitialized; + +}; + +// Script "performance.timing" object +class PerformanceTiming final : public nsWrapperCache +{ +public: +/** + * @param aPerformance + * The performance object (the JS parent). + * This will allow access to "window.performance.timing" attribute for + * the navigation timing (can't be null). + * @param aChannel + * An nsITimedChannel used to gather all the networking timings by both + * the navigation timing and the resource timing (can't be null). + * @param aHttpChannel + * An nsIHttpChannel (the resource's http channel). + * This will be used by the resource timing cross-domain check + * algorithm. + * Argument is null for the navigation timing (navigation timing uses + * another algorithm for the cross-domain redirects). + * @param aZeroTime + * The offset that will be added to the timestamp of each event. This + * argument should be equal to performance.navigationStart for + * navigation timing and "0" for the resource timing. + */ + PerformanceTiming(Performance* aPerformance, + nsITimedChannel* aChannel, + nsIHttpChannel* aHttpChannel, + DOMHighResTimeStamp aZeroTime); + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PerformanceTiming) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(PerformanceTiming) + + nsDOMNavigationTiming* GetDOMTiming() const + { + return mPerformance->GetDOMTiming(); + } + + Performance* GetParentObject() const + { + return mPerformance; + } + virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override; @@ -138,40 +274,6 @@ public: return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetUnloadEventEnd()); } - uint8_t GetRedirectCount() const; - - // Checks if the resource is either same origin as the page that started - // the load, or if the response contains the Timing-Allow-Origin header - // with a value of * or matching the domain of the loading Principal - bool CheckAllowedOrigin(nsIHttpChannel* aResourceChannel, nsITimedChannel* aChannel); - - // Cached result of CheckAllowedOrigin. If false, security sensitive - // attributes of the resourceTiming object will be set to 0 - bool TimingAllowed() const; - - // If this is false the values of redirectStart/End will be 0 - // This is false if no redirects occured, or if any of the responses failed - // the timing-allow-origin check in HttpBaseChannel::TimingAllowCheck - bool ShouldReportCrossOriginRedirect() const; - - // The last channel's AsyncOpen time. This may occur before the FetchStart - // in some cases. - DOMHighResTimeStamp AsyncOpenHighRes(); - - // High resolution (used by resource timing) - DOMHighResTimeStamp WorkerStartHighRes(); - DOMHighResTimeStamp FetchStartHighRes(); - DOMHighResTimeStamp RedirectStartHighRes(); - DOMHighResTimeStamp RedirectEndHighRes(); - DOMHighResTimeStamp DomainLookupStartHighRes(); - DOMHighResTimeStamp DomainLookupEndHighRes(); - DOMHighResTimeStamp ConnectStartHighRes(); - DOMHighResTimeStamp SecureConnectionStartHighRes(); - DOMHighResTimeStamp ConnectEndHighRes(); - DOMHighResTimeStamp RequestStartHighRes(); - DOMHighResTimeStamp ResponseStartHighRes(); - DOMHighResTimeStamp ResponseEndHighRes(); - // Low resolution (used by navigation timing) DOMTimeMilliSec FetchStart(); DOMTimeMilliSec RedirectStart(); @@ -249,46 +351,16 @@ public: return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetTimeToNonBlankPaint()); } + PerformanceTimingData* Data() const + { + return mTimingData.get(); + } + private: ~PerformanceTiming(); - bool IsInitialized() const; - void InitializeTimingInfo(nsITimedChannel* aChannel); - RefPtr<Performance> mPerformance; - DOMHighResTimeStamp mFetchStart; - - // This is an offset that will be added to each timing ([ms] resolution). - // There are only 2 possible values: (1) logicaly equal to navigationStart - // TimeStamp (results are absolute timstamps - wallclock); (2) "0" (results - // are relative to the navigation start). - DOMHighResTimeStamp mZeroTime; - - TimeStamp mAsyncOpen; - TimeStamp mWorkerStart; - TimeStamp mRedirectStart; - TimeStamp mRedirectEnd; - TimeStamp mDomainLookupStart; - TimeStamp mDomainLookupEnd; - TimeStamp mConnectStart; - TimeStamp mSecureConnectionStart; - TimeStamp mConnectEnd; - TimeStamp mRequestStart; - TimeStamp mResponseStart; - TimeStamp mCacheReadStart; - TimeStamp mResponseEnd; - TimeStamp mCacheReadEnd; - uint8_t mRedirectCount; - bool mTimingAllowed; - bool mAllRedirectsSameOrigin; - bool mInitialized; - - // If the resourceTiming object should have non-zero redirectStart and - // redirectEnd attributes. It is false if there were no redirects, or if - // any of the responses didn't pass the timing-allow-check - bool mReportCrossOriginRedirect; - - bool mSecureConnection; + UniquePtr<PerformanceTimingData> mTimingData; }; } // namespace dom |