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"
|
|
|
|
#include "nsCOMPtr.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"
|
|
|
|
#include "mozilla/dom/PerformanceBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceTimingBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceNavigationBinding.h"
|
2013-08-24 10:12:51 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-07-17 05:42:18 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-06-23 14:39:48 +04:00
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPerformanceTiming, mPerformance)
|
2011-06-23 14:39:48 +04:00
|
|
|
|
2012-12-07 01:01:59 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceTiming, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceTiming, Release)
|
2011-06-23 14:39:48 +04:00
|
|
|
|
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
|
|
|
{
|
2013-05-11 02:57:58 +04:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
2013-05-11 02:57:58 +04:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
2013-05-11 02:57:58 +04:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
2013-05-11 02:57:58 +04:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
2013-05-11 02:57:58 +04:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
2013-05-11 02:57:58 +04:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
2013-05-11 02:57:58 +04:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
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*
|
2013-04-25 20:29:54 +04:00
|
|
|
nsPerformanceTiming::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
|
2012-07-17 05:42:18 +04:00
|
|
|
{
|
2013-03-12 03:03:47 +04:00
|
|
|
return dom::PerformanceTimingBinding::Wrap(cx, scope, this);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPerformanceNavigation, mPerformance)
|
2011-06-23 14:39:48 +04:00
|
|
|
|
2012-12-07 01:01:59 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceNavigation, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceNavigation, Release)
|
2011-06-23 14:39:48 +04:00
|
|
|
|
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*
|
2013-04-25 20:29:54 +04:00
|
|
|
nsPerformanceNavigation::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
|
2012-07-17 05:42:18 +04:00
|
|
|
{
|
2013-03-12 03:03:47 +04:00
|
|
|
return dom::PerformanceNavigationBinding::Wrap(cx, scope, this);
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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*
|
2013-04-25 20:29:54 +04:00
|
|
|
nsPerformance::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
|
2012-07-17 05:42:18 +04:00
|
|
|
{
|
2013-03-12 03:03:47 +04:00
|
|
|
return dom::PerformanceBinding::Wrap(cx, scope, this);
|
2012-07-17 05:42:18 +04:00
|
|
|
}
|
|
|
|
|