2011-06-23 10:39:48 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 10:39:48 +00:00
|
|
|
|
|
|
|
#include "nsPerformance.h"
|
2011-07-04 16:44:00 +00:00
|
|
|
#include "TimeStamp.h"
|
2011-06-23 10:39:48 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsIDocShell.h"
|
2011-07-04 16:44:00 +00:00
|
|
|
#include "nsITimedChannel.h"
|
2011-10-03 19:11:31 +00:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2011-06-23 10:39:48 +00:00
|
|
|
#include "nsDOMNavigationTiming.h"
|
|
|
|
|
|
|
|
DOMCI_DATA(PerformanceTiming, nsPerformanceTiming)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsPerformanceTiming)
|
|
|
|
NS_IMPL_RELEASE(nsPerformanceTiming)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformanceTiming
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsPerformanceTiming)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPerformanceTiming)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMPerformanceTiming)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PerformanceTiming)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-07-04 16:44:00 +00:00
|
|
|
nsPerformanceTiming::nsPerformanceTiming(nsDOMNavigationTiming* aDOMTiming,
|
|
|
|
nsITimedChannel* aChannel)
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
NS_ASSERTION(aDOMTiming, "DOM timing data should be provided");
|
|
|
|
mDOMTiming = aDOMTiming;
|
|
|
|
mChannel = aChannel;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceTiming::~nsPerformanceTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetNavigationStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetNavigationStart(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetUnloadEventStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetUnloadEventStart(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetUnloadEventEnd(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetUnloadEventEnd(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetRedirectStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetRedirectStart(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetRedirectEnd(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetRedirectEnd(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetFetchStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetFetchStart(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetDomainLookupStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return GetFetchStart(aTime);
|
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetDomainLookupStart(&stamp);
|
2011-08-08 12:20:03 +00:00
|
|
|
return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetDomainLookupEnd(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return GetFetchStart(aTime);
|
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetDomainLookupEnd(&stamp);
|
2011-08-08 12:20:03 +00:00
|
|
|
return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetConnectStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return GetFetchStart(aTime);
|
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectStart(&stamp);
|
2011-08-08 12:20:03 +00:00
|
|
|
return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetConnectEnd(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return GetFetchStart(aTime);
|
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectEnd(&stamp);
|
2011-08-08 12:20:03 +00:00
|
|
|
return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetRequestStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return GetFetchStart(aTime);
|
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetRequestStart(&stamp);
|
2011-08-08 12:20:03 +00:00
|
|
|
return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetResponseStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return GetFetchStart(aTime);
|
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseStart(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadStart(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2011-08-08 12:20:03 +00:00
|
|
|
return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetResponseEnd(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return GetFetchStart(aTime);
|
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseEnd(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadEnd(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2011-08-08 12:20:03 +00:00
|
|
|
return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetDomLoading(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetDomLoading(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetDomInteractive(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetDomInteractive(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetDomContentLoadedEventStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetDomContentLoadedEventStart(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetDomContentLoadedEventEnd(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetDomContentLoadedEventEnd(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetDomComplete(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetDomComplete(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetLoadEventStart(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetLoadEventStart(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceTiming::GetLoadEventEnd(DOMTimeMilliSec* aTime)
|
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
return mDOMTiming->GetLoadEventEnd(aTime);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOMCI_DATA(PerformanceNavigation, nsPerformanceNavigation)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsPerformanceNavigation)
|
|
|
|
NS_IMPL_RELEASE(nsPerformanceNavigation)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformanceNavigation
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsPerformanceNavigation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPerformanceNavigation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMPerformanceNavigation)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PerformanceNavigation)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
nsPerformanceNavigation::nsPerformanceNavigation(nsDOMNavigationTiming* aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aData, "Timing data should be provided");
|
|
|
|
mData = aData;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceNavigation::~nsPerformanceNavigation()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceNavigation::GetType(
|
|
|
|
nsDOMPerformanceNavigationType* aNavigationType)
|
|
|
|
{
|
|
|
|
return mData->GetType(aNavigationType);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformanceNavigation::GetRedirectCount(PRUint16* aRedirectCount)
|
|
|
|
{
|
|
|
|
return mData->GetRedirectCount(aRedirectCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DOMCI_DATA(Performance, nsPerformance)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsPerformance)
|
|
|
|
NS_IMPL_RELEASE(nsPerformance)
|
|
|
|
|
2011-07-04 16:44:00 +00:00
|
|
|
nsPerformance::nsPerformance(nsDOMNavigationTiming* aDOMTiming,
|
|
|
|
nsITimedChannel* aChannel)
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2011-07-04 16:44:00 +00:00
|
|
|
NS_ASSERTION(aDOMTiming, "DOM timing data should be provided");
|
|
|
|
mDOMTiming = aDOMTiming;
|
|
|
|
mChannel = aChannel;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformance::~nsPerformance()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformance
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsPerformance)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPerformance)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMPerformance)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Performance)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsIDOMPerformance methods
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformance::GetTiming(nsIDOMPerformanceTiming** aTiming)
|
|
|
|
{
|
|
|
|
if (!mTiming) {
|
2011-07-04 16:44:00 +00:00
|
|
|
mTiming = new nsPerformanceTiming(mDOMTiming, mChannel);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aTiming = mTiming);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformance::GetNavigation(nsIDOMPerformanceNavigation** aNavigation)
|
|
|
|
{
|
|
|
|
if (!mNavigation) {
|
2011-07-04 16:44:00 +00:00
|
|
|
mNavigation = new nsPerformanceNavigation(mDOMTiming);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aNavigation = mNavigation);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-27 07:22:06 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPerformance::Now(DOMHighResTimeStamp* aNow)
|
|
|
|
{
|
|
|
|
*aNow = mDOMTiming->TimeStampToDOMHighRes(mozilla::TimeStamp::Now());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|