2011-06-23 14:39:48 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 14:39:48 +04:00
|
|
|
|
|
|
|
#include "nsPerformance.h"
|
2011-07-04 20:44:00 +04:00
|
|
|
#include "TimeStamp.h"
|
2011-06-23 14:39:48 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsIDocShell.h"
|
2011-07-04 20:44:00 +04:00
|
|
|
#include "nsITimedChannel.h"
|
2011-06-23 14:39:48 +04:00
|
|
|
#include "nsDOMNavigationTiming.h"
|
2012-07-17 05:42:18 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2012-07-20 21:40:13 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2012-07-17 05:42:18 +04:00
|
|
|
#include "mozilla/dom/PerformanceBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceTimingBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceNavigationBinding.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-06-23 14:39:48 +04:00
|
|
|
|
|
|
|
DOMCI_DATA(PerformanceTiming, nsPerformanceTiming)
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPerformanceTiming, mPerformance)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPerformanceTiming)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPerformanceTiming)
|
2011-06-23 14:39:48 +04:00
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformanceTiming
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPerformanceTiming)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-07-17 06:44:22 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2011-06-23 14:39:48 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
nsPerformanceTiming::nsPerformanceTiming(nsPerformance* aPerformance,
|
2011-07-04 20:44:00 +04:00
|
|
|
nsITimedChannel* aChannel)
|
2012-07-17 05:42:18 +04:00
|
|
|
: mPerformance(aPerformance),
|
|
|
|
mChannel(aChannel)
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2012-07-17 05:42:18 +04:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceTiming::~nsPerformanceTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformanceTiming::DomainLookupStart() const
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2011-07-04 20:44:00 +04:00
|
|
|
if (!mChannel) {
|
2012-09-11 23:08:24 +04:00
|
|
|
return FetchStart();
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetDomainLookupStart(&stamp);
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetDOMTiming()->TimeStampToDOMOrFetchStart(stamp);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformanceTiming::DomainLookupEnd() const
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2011-07-04 20:44:00 +04:00
|
|
|
if (!mChannel) {
|
2012-09-11 23:08:24 +04:00
|
|
|
return FetchStart();
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetDomainLookupEnd(&stamp);
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetDOMTiming()->TimeStampToDOMOrFetchStart(stamp);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformanceTiming::ConnectStart() const
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2011-07-04 20:44:00 +04:00
|
|
|
if (!mChannel) {
|
2012-09-11 23:08:24 +04:00
|
|
|
return FetchStart();
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectStart(&stamp);
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetDOMTiming()->TimeStampToDOMOrFetchStart(stamp);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformanceTiming::ConnectEnd() const
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2011-07-04 20:44:00 +04:00
|
|
|
if (!mChannel) {
|
2012-09-11 23:08:24 +04:00
|
|
|
return FetchStart();
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectEnd(&stamp);
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetDOMTiming()->TimeStampToDOMOrFetchStart(stamp);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformanceTiming::RequestStart() const
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2011-07-04 20:44:00 +04:00
|
|
|
if (!mChannel) {
|
2012-09-11 23:08:24 +04:00
|
|
|
return FetchStart();
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetRequestStart(&stamp);
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetDOMTiming()->TimeStampToDOMOrFetchStart(stamp);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformanceTiming::ResponseStart() const
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2011-07-04 20:44:00 +04:00
|
|
|
if (!mChannel) {
|
2012-09-11 23:08:24 +04:00
|
|
|
return FetchStart();
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseStart(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadStart(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetDOMTiming()->TimeStampToDOMOrFetchStart(stamp);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformanceTiming::ResponseEnd() const
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2011-07-04 20:44:00 +04:00
|
|
|
if (!mChannel) {
|
2012-09-11 23:08:24 +04:00
|
|
|
return FetchStart();
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseEnd(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadEnd(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetDOMTiming()->TimeStampToDOMOrFetchStart(stamp);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
JSObject*
|
|
|
|
nsPerformanceTiming::WrapObject(JSContext *cx, JSObject *scope,
|
|
|
|
bool *triedToWrap)
|
|
|
|
{
|
|
|
|
return dom::PerformanceTimingBinding::Wrap(cx, scope, this,
|
|
|
|
triedToWrap);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOMCI_DATA(PerformanceNavigation, nsPerformanceNavigation)
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPerformanceNavigation, mPerformance)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPerformanceNavigation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPerformanceNavigation)
|
2011-06-23 14:39:48 +04:00
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformanceNavigation
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPerformanceNavigation)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-07-17 06:44:22 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2011-06-23 14:39:48 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
nsPerformanceNavigation::nsPerformanceNavigation(nsPerformance* aPerformance)
|
|
|
|
: mPerformance(aPerformance)
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2012-07-17 05:42:18 +04:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceNavigation::~nsPerformanceNavigation()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
JSObject*
|
|
|
|
nsPerformanceNavigation::WrapObject(JSContext *cx, JSObject *scope,
|
|
|
|
bool *triedToWrap)
|
|
|
|
{
|
|
|
|
return dom::PerformanceNavigationBinding::Wrap(cx, scope, this,
|
|
|
|
triedToWrap);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DOMCI_DATA(Performance, nsPerformance)
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_3(nsPerformance,
|
|
|
|
mWindow, mTiming,
|
|
|
|
mNavigation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPerformance)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPerformance)
|
2011-06-23 14:39:48 +04:00
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
nsPerformance::nsPerformance(nsIDOMWindow* aWindow,
|
|
|
|
nsDOMNavigationTiming* aDOMTiming,
|
2011-07-04 20:44:00 +04:00
|
|
|
nsITimedChannel* aChannel)
|
2012-07-17 05:42:18 +04:00
|
|
|
: mWindow(aWindow),
|
|
|
|
mDOMTiming(aDOMTiming),
|
|
|
|
mChannel(aChannel)
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
2012-07-17 05:42:18 +04:00
|
|
|
MOZ_ASSERT(aWindow, "Parent window object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformance::~nsPerformance()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformance
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPerformance)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-07-17 06:44:22 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2011-06-23 14:39:48 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
|
|
|
|
nsPerformanceTiming*
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformance::Timing()
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
|
|
|
if (!mTiming) {
|
2012-07-17 05:42:18 +04:00
|
|
|
mTiming = new nsPerformanceTiming(this, mChannel);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
2012-07-17 05:42:18 +04:00
|
|
|
return mTiming;
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
nsPerformanceNavigation*
|
2012-09-11 23:08:24 +04:00
|
|
|
nsPerformance::Navigation()
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
|
|
|
if (!mNavigation) {
|
2012-07-17 05:42:18 +04:00
|
|
|
mNavigation = new nsPerformanceNavigation(this);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
2012-07-17 05:42:18 +04:00
|
|
|
return mNavigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformance::Now()
|
|
|
|
{
|
|
|
|
return GetDOMTiming()->TimeStampToDOMHighRes(mozilla::TimeStamp::Now());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
nsPerformance::WrapObject(JSContext *cx, JSObject *scope,
|
|
|
|
bool *triedToWrap)
|
|
|
|
{
|
|
|
|
return dom::PerformanceBinding::Wrap(cx, scope, this,
|
|
|
|
triedToWrap);
|
|
|
|
}
|
|
|
|
|