2011-06-23 03:39:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-06-23 03:39:48 -07:00
|
|
|
|
|
|
|
#include "nsPerformance.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsIHttpChannel.h"
|
2011-07-04 09:44:00 -07:00
|
|
|
#include "nsITimedChannel.h"
|
2011-06-23 03:39:48 -07:00
|
|
|
#include "nsDOMNavigationTiming.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "PerformanceEntry.h"
|
|
|
|
#include "PerformanceResourceTiming.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
#include "mozilla/dom/PerformanceBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceTimingBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceNavigationBinding.h"
|
2013-08-23 23:12:51 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2014-05-14 22:26:07 -07:00
|
|
|
#include "nsILoadInfo.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPerformanceTiming, mPerformance)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-12-06 13:01:59 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceTiming, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceTiming, Release)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
nsPerformanceTiming::nsPerformanceTiming(nsPerformance* aPerformance,
|
2013-10-15 18:35:44 -07:00
|
|
|
nsITimedChannel* aChannel,
|
|
|
|
nsIHttpChannel* aHttpChannel,
|
|
|
|
DOMHighResTimeStamp aZeroTime)
|
2012-07-16 18:42:18 -07:00
|
|
|
: mPerformance(aPerformance),
|
2013-10-15 18:35:44 -07:00
|
|
|
mFetchStart(0.0),
|
|
|
|
mZeroTime(aZeroTime),
|
2014-10-21 05:49:40 -07:00
|
|
|
mRedirectCount(0),
|
2014-05-14 22:26:07 -07:00
|
|
|
mTimingAllowed(true),
|
2014-10-21 05:49:40 -07:00
|
|
|
mAllRedirectsSameOrigin(true),
|
|
|
|
mInitialized(!!aChannel),
|
2014-05-14 22:26:07 -07:00
|
|
|
mReportCrossOriginRedirect(true)
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2012-07-16 18:42:18 -07:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
2014-09-23 13:18:28 -07:00
|
|
|
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
mZeroTime = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
// The aHttpChannel argument is null if this nsPerformanceTiming object
|
|
|
|
// is being used for the navigation timing (document) and has a non-null
|
|
|
|
// value for the resource timing (any resources within the page).
|
|
|
|
if (aHttpChannel) {
|
2014-10-21 05:49:40 -07:00
|
|
|
mTimingAllowed = CheckAllowedOrigin(aHttpChannel, aChannel);
|
2014-05-14 22:26:07 -07:00
|
|
|
bool redirectsPassCheck = false;
|
2014-10-21 05:49:40 -07:00
|
|
|
aChannel->GetAllRedirectsPassTimingAllowCheck(&redirectsPassCheck);
|
2014-05-14 22:26:07 -07:00
|
|
|
mReportCrossOriginRedirect = mTimingAllowed && redirectsPassCheck;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
|
|
|
|
InitializeTimingInfo(aChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the timing info from the channel so we don't need to keep the channel
|
|
|
|
// alive just to get the timestamps.
|
|
|
|
void
|
|
|
|
nsPerformanceTiming::InitializeTimingInfo(nsITimedChannel* aChannel)
|
|
|
|
{
|
|
|
|
if (aChannel) {
|
|
|
|
aChannel->GetAsyncOpen(&mAsyncOpen);
|
|
|
|
aChannel->GetAllRedirectsSameOrigin(&mAllRedirectsSameOrigin);
|
|
|
|
aChannel->GetRedirectCount(&mRedirectCount);
|
|
|
|
aChannel->GetRedirectStart(&mRedirectStart);
|
|
|
|
aChannel->GetRedirectEnd(&mRedirectEnd);
|
|
|
|
aChannel->GetDomainLookupStart(&mDomainLookupStart);
|
|
|
|
aChannel->GetDomainLookupEnd(&mDomainLookupEnd);
|
|
|
|
aChannel->GetConnectStart(&mConnectStart);
|
|
|
|
aChannel->GetConnectEnd(&mConnectEnd);
|
|
|
|
aChannel->GetRequestStart(&mRequestStart);
|
|
|
|
aChannel->GetResponseStart(&mResponseStart);
|
|
|
|
aChannel->GetCacheReadStart(&mCacheReadStart);
|
|
|
|
aChannel->GetResponseEnd(&mResponseEnd);
|
|
|
|
aChannel->GetCacheReadEnd(&mCacheReadEnd);
|
|
|
|
}
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceTiming::~nsPerformanceTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::FetchStartHighRes()
|
|
|
|
{
|
|
|
|
if (!mFetchStart) {
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
MOZ_ASSERT(!mAsyncOpen.IsNull(), "The fetch start time stamp should always be "
|
2013-10-15 18:35:44 -07:00
|
|
|
"valid if the performance timing is enabled");
|
2014-10-21 05:49:40 -07:00
|
|
|
mFetchStart = (!mAsyncOpen.IsNull())
|
|
|
|
? TimeStampToDOMHighRes(mAsyncOpen)
|
2013-10-15 18:35:44 -07:00
|
|
|
: 0.0;
|
|
|
|
}
|
|
|
|
return mFetchStart;
|
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::FetchStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(FetchStartHighRes());
|
|
|
|
}
|
|
|
|
|
2014-05-14 22:26:07 -07:00
|
|
|
bool
|
2014-10-21 05:49:40 -07:00
|
|
|
nsPerformanceTiming::CheckAllowedOrigin(nsIHttpChannel* aResourceChannel,
|
|
|
|
nsITimedChannel* aChannel)
|
2013-10-15 18:35:44 -07:00
|
|
|
{
|
2014-04-21 06:34:33 -07:00
|
|
|
if (!IsInitialized()) {
|
2014-05-14 22:26:07 -07:00
|
|
|
return false;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
2014-05-14 22:26:07 -07:00
|
|
|
|
|
|
|
// Check that the current document passes the ckeck.
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
aResourceChannel->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
if (!loadInfo) {
|
|
|
|
return false;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
2014-05-14 22:26:07 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = loadInfo->LoadingPrincipal();
|
|
|
|
|
|
|
|
// Check if the resource is either same origin as the page that started
|
|
|
|
// the load, or if the response contains the proper Timing-Allow-Origin
|
|
|
|
// header with the domain of the page that started the load.
|
2014-10-21 05:49:40 -07:00
|
|
|
return aChannel->TimingAllowCheck(principal);
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-05-14 22:26:07 -07:00
|
|
|
nsPerformanceTiming::TimingAllowed() const
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2014-05-14 22:26:07 -07:00
|
|
|
return mTimingAllowed;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
nsPerformanceTiming::GetRedirectCount() const
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
if (!mAllRedirectsSameOrigin) {
|
2013-05-10 15:57:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return mRedirectCount;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
2014-05-14 22:26:07 -07:00
|
|
|
bool
|
|
|
|
nsPerformanceTiming::ShouldReportCrossOriginRedirect() const
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the redirect count is 0, or if one of the cross-origin
|
|
|
|
// redirects doesn't have the proper Timing-Allow-Origin header,
|
|
|
|
// then RedirectStart and RedirectEnd will be set to zero
|
2014-10-21 05:49:40 -07:00
|
|
|
return (mRedirectCount != 0) && mReportCrossOriginRedirect;
|
2014-05-14 22:26:07 -07:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
/**
|
|
|
|
* RedirectStartHighRes() is used by both the navigation timing and the
|
|
|
|
* resource timing. Since, navigation timing and resource timing check and
|
|
|
|
* interpret cross-domain redirects in a different manner,
|
|
|
|
* RedirectStartHighRes() will make no checks for cross-domain redirect.
|
|
|
|
* It's up to the consumers of this method (nsPerformanceTiming::RedirectStart()
|
|
|
|
* and PerformanceResourceTiming::RedirectStart() to make such verifications.
|
|
|
|
*
|
|
|
|
* @return a valid timing if the Performance Timing is enabled
|
|
|
|
*/
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::RedirectStartHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2011-07-04 09:44:00 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mRedirectStart);
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::RedirectStart()
|
|
|
|
{
|
2014-04-21 06:34:33 -07:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return mZeroTime;
|
|
|
|
}
|
2013-10-15 18:35:44 -07:00
|
|
|
// We have to check if all the redirect URIs had the same origin (since there
|
|
|
|
// is no check in RedirectStartHighRes())
|
2014-10-21 05:49:40 -07:00
|
|
|
if (mAllRedirectsSameOrigin) {
|
2013-10-15 18:35:44 -07:00
|
|
|
return static_cast<int64_t>(RedirectStartHighRes());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RedirectEndHighRes() is used by both the navigation timing and the resource
|
|
|
|
* timing. Since, navigation timing and resource timing check and interpret
|
|
|
|
* cross-domain redirects in a different manner, RedirectEndHighRes() will make
|
|
|
|
* no checks for cross-domain redirect. It's up to the consumers of this method
|
|
|
|
* (nsPerformanceTiming::RedirectEnd() and
|
|
|
|
* PerformanceResourceTiming::RedirectEnd() to make such verifications.
|
|
|
|
*
|
|
|
|
* @return a valid timing if the Performance Timing is enabled
|
|
|
|
*/
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::RedirectEndHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mRedirectEnd);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::RedirectEnd()
|
|
|
|
{
|
2014-04-21 06:34:33 -07:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return mZeroTime;
|
|
|
|
}
|
2013-10-15 18:35:44 -07:00
|
|
|
// We have to check if all the redirect URIs had the same origin (since there
|
|
|
|
// is no check in RedirectEndHighRes())
|
2014-10-21 05:49:40 -07:00
|
|
|
if (mAllRedirectsSameOrigin) {
|
2013-10-15 18:35:44 -07:00
|
|
|
return static_cast<int64_t>(RedirectEndHighRes());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::DomainLookupStartHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mDomainLookupStart);
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::DomainLookupStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(DomainLookupStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::DomainLookupEndHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2011-07-04 09:44:00 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mDomainLookupEnd);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::DomainLookupEnd()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
return static_cast<int64_t>(DomainLookupEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ConnectStartHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mConnectStart);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::ConnectStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ConnectStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ConnectEndHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mConnectEnd);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::ConnectEnd()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ConnectEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::RequestStartHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mRequestStart);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::RequestStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(RequestStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ResponseStartHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
if (mResponseStart.IsNull() ||
|
|
|
|
(!mCacheReadStart.IsNull() && mCacheReadStart < mResponseStart)) {
|
|
|
|
mResponseStart = mCacheReadStart;
|
2011-07-04 09:44:00 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mResponseStart);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::ResponseStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ResponseStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ResponseEndHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
if (mResponseEnd.IsNull() ||
|
|
|
|
(!mCacheReadEnd.IsNull() && mCacheReadEnd < mResponseEnd)) {
|
|
|
|
mResponseEnd = mCacheReadEnd;
|
2011-07-04 09:44:00 -07:00
|
|
|
}
|
2014-10-21 05:49:40 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(mResponseEnd);
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::ResponseEnd()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ResponseEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformanceTiming::IsInitialized() const
|
|
|
|
{
|
2014-10-21 05:49:40 -07:00
|
|
|
return mInitialized;
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
nsPerformanceTiming::WrapObject(JSContext *cx)
|
2012-07-16 18:42:18 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return dom::PerformanceTimingBinding::Wrap(cx, this);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-29 01:57:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPerformanceNavigation, mPerformance)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-12-06 13:01:59 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceNavigation, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceNavigation, Release)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
nsPerformanceNavigation::nsPerformanceNavigation(nsPerformance* aPerformance)
|
|
|
|
: mPerformance(aPerformance)
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2012-07-16 18:42:18 -07:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceNavigation::~nsPerformanceNavigation()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
nsPerformanceNavigation::WrapObject(JSContext *cx)
|
2012-07-16 18:42:18 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return dom::PerformanceNavigationBinding::Wrap(cx, this);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-09 19:12:06 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsPerformance, DOMEventTargetHelper,
|
|
|
|
mWindow, mTiming,
|
|
|
|
mNavigation, mEntries,
|
|
|
|
mParentPerformance)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsPerformance, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsPerformance, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
nsPerformance::nsPerformance(nsPIDOMWindow* aWindow,
|
2012-07-16 18:42:18 -07:00
|
|
|
nsDOMNavigationTiming* aDOMTiming,
|
2013-10-15 18:35:44 -07:00
|
|
|
nsITimedChannel* aChannel,
|
|
|
|
nsPerformance* aParentPerformance)
|
2014-05-09 19:12:06 -07:00
|
|
|
: DOMEventTargetHelper(aWindow),
|
|
|
|
mWindow(aWindow),
|
2012-07-16 18:42:18 -07:00
|
|
|
mDOMTiming(aDOMTiming),
|
2013-10-15 18:35:44 -07:00
|
|
|
mChannel(aChannel),
|
|
|
|
mParentPerformance(aParentPerformance),
|
|
|
|
mPrimaryBufferSize(kDefaultBufferSize)
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2012-07-16 18:42:18 -07:00
|
|
|
MOZ_ASSERT(aWindow, "Parent window object should be provided");
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformance::~nsPerformance()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformance
|
2012-07-16 18:42:18 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPerformance)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-07-16 19:44:22 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2014-05-09 19:12:06 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
|
|
|
|
nsPerformanceTiming*
|
2012-09-11 12:08:24 -07:00
|
|
|
nsPerformance::Timing()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
|
|
|
if (!mTiming) {
|
2013-10-15 18:35:44 -07:00
|
|
|
// For navigation timing, the third argument (an nsIHtttpChannel) is null
|
|
|
|
// since the cross-domain redirect were already checked.
|
|
|
|
// The last argument (zero time) for performance.timing is the navigation
|
|
|
|
// start value.
|
|
|
|
mTiming = new nsPerformanceTiming(this, mChannel, nullptr,
|
|
|
|
mDOMTiming->GetNavigationStart());
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
2012-07-16 18:42:18 -07:00
|
|
|
return mTiming;
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2014-05-09 19:12:06 -07:00
|
|
|
void
|
|
|
|
nsPerformance::DispatchBufferFullEvent()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// it bubbles, and it isn't cancelable
|
|
|
|
rv = event->InitEvent(NS_LITERAL_STRING("resourcetimingbufferfull"), true, false);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
event->SetTrusted(true);
|
|
|
|
DispatchDOMEvent(nullptr, event, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
nsPerformanceNavigation*
|
2012-09-11 12:08:24 -07:00
|
|
|
nsPerformance::Navigation()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
|
|
|
if (!mNavigation) {
|
2012-07-16 18:42:18 -07:00
|
|
|
mNavigation = new nsPerformanceNavigation(this);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
2012-07-16 18:42:18 -07:00
|
|
|
return mNavigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformance::Now()
|
|
|
|
{
|
|
|
|
return GetDOMTiming()->TimeStampToDOMHighRes(mozilla::TimeStamp::Now());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
nsPerformance::WrapObject(JSContext *cx)
|
2012-07-16 18:42:18 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return dom::PerformanceBinding::Wrap(cx, this);
|
2012-07-16 18:42:18 -07:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
void
|
|
|
|
nsPerformance::GetEntries(nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-05-09 19:11:54 -07:00
|
|
|
retval = mEntries;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::GetEntriesByType(const nsAString& entryType,
|
|
|
|
nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
retval.Clear();
|
|
|
|
uint32_t count = mEntries.Length();
|
2014-05-09 19:11:54 -07:00
|
|
|
for (uint32_t i = 0 ; i < count; i++) {
|
2013-10-15 18:35:44 -07:00
|
|
|
if (mEntries[i]->GetEntryType().Equals(entryType)) {
|
|
|
|
retval.AppendElement(mEntries[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::GetEntriesByName(const nsAString& name,
|
|
|
|
const mozilla::dom::Optional<nsAString>& entryType,
|
|
|
|
nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
retval.Clear();
|
|
|
|
uint32_t count = mEntries.Length();
|
2014-05-09 19:11:54 -07:00
|
|
|
for (uint32_t i = 0 ; i < count; i++) {
|
2013-10-15 18:35:44 -07:00
|
|
|
if (mEntries[i]->GetName().Equals(name) &&
|
|
|
|
(!entryType.WasPassed() ||
|
|
|
|
mEntries[i]->GetEntryType().Equals(entryType.Value()))) {
|
|
|
|
retval.AppendElement(mEntries[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::ClearResourceTimings()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mEntries.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::SetResourceTimingBufferSize(uint64_t maxSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-05-09 19:11:54 -07:00
|
|
|
mPrimaryBufferSize = maxSize;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An entry should be added only after the resource is loaded.
|
|
|
|
* This method is not thread safe and can only be called on the main thread.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsPerformance::AddEntry(nsIHttpChannel* channel,
|
|
|
|
nsITimedChannel* timedChannel)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// Check if resource timing is prefed off.
|
|
|
|
if (!nsContentUtils::IsResourceTimingEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-09 19:11:54 -07:00
|
|
|
|
|
|
|
// Don't add the entry if the buffer is full
|
|
|
|
if (mEntries.Length() >= mPrimaryBufferSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
if (channel && timedChannel) {
|
|
|
|
nsAutoCString name;
|
|
|
|
nsAutoString initiatorType;
|
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
|
|
|
|
timedChannel->GetInitiatorType(initiatorType);
|
|
|
|
|
|
|
|
// According to the spec, "The name attribute must return the resolved URL
|
|
|
|
// of the requested resource. This attribute must not change even if the
|
|
|
|
// fetch redirected to a different URL."
|
|
|
|
channel->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
originalURI->GetSpec(name);
|
|
|
|
NS_ConvertUTF8toUTF16 entryName(name);
|
|
|
|
|
|
|
|
// The nsITimedChannel argument will be used to gather all the timings.
|
|
|
|
// The nsIHttpChannel argument will be used to check if any cross-origin
|
|
|
|
// redirects occurred.
|
|
|
|
// The last argument is the "zero time" (offset). Since we don't want
|
|
|
|
// any offset for the resource timing, this will be set to "0" - the
|
|
|
|
// resource timing returns a relative timing (no offset).
|
|
|
|
nsRefPtr<nsPerformanceTiming> performanceTiming =
|
|
|
|
new nsPerformanceTiming(this, timedChannel, channel,
|
|
|
|
0);
|
|
|
|
|
|
|
|
// The PerformanceResourceTiming object will use the nsPerformanceTiming
|
|
|
|
// object to get all the required timings.
|
|
|
|
nsRefPtr<dom::PerformanceResourceTiming> performanceEntry =
|
|
|
|
new dom::PerformanceResourceTiming(performanceTiming, this);
|
|
|
|
|
|
|
|
performanceEntry->SetName(entryName);
|
|
|
|
performanceEntry->SetEntryType(NS_LITERAL_STRING("resource"));
|
|
|
|
// If the initiator type had no valid value, then set it to the default
|
|
|
|
// ("other") value.
|
|
|
|
if (initiatorType.IsEmpty()) {
|
|
|
|
initiatorType = NS_LITERAL_STRING("other");
|
|
|
|
}
|
|
|
|
performanceEntry->SetInitiatorType(initiatorType);
|
|
|
|
|
|
|
|
mEntries.InsertElementSorted(performanceEntry,
|
|
|
|
PerformanceEntryComparator());
|
2014-05-09 19:11:54 -07:00
|
|
|
if (mEntries.Length() >= mPrimaryBufferSize) {
|
2013-10-15 18:35:44 -07:00
|
|
|
// call onresourcetimingbufferfull
|
2014-05-09 19:12:06 -07:00
|
|
|
DispatchBufferFullEvent();
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformance::PerformanceEntryComparator::Equals(
|
|
|
|
const PerformanceEntry* aElem1,
|
|
|
|
const PerformanceEntry* aElem2) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElem1 && aElem2,
|
|
|
|
"Trying to compare null performance entries");
|
|
|
|
return aElem1->StartTime() == aElem2->StartTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformance::PerformanceEntryComparator::LessThan(
|
|
|
|
const PerformanceEntry* aElem1,
|
|
|
|
const PerformanceEntry* aElem2) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElem1 && aElem2,
|
|
|
|
"Trying to compare null performance entries");
|
|
|
|
return aElem1->StartTime() < aElem2->StartTime();
|
|
|
|
}
|