2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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 "nsDOMNavigationTiming.h"
|
2013-10-16 05:35:44 +04:00
|
|
|
#include "nsPerformance.h"
|
2011-06-23 14:39:48 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2013-07-02 22:15:39 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-07-03 19:56:26 +04:00
|
|
|
#include "prtime.h"
|
2013-08-15 22:17:48 +04:00
|
|
|
#include "nsIURI.h"
|
2013-08-24 10:12:51 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2011-06-23 14:39:48 +04:00
|
|
|
|
|
|
|
nsDOMNavigationTiming::nsDOMNavigationTiming()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMNavigationTiming::~nsDOMNavigationTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::Clear()
|
|
|
|
{
|
2012-07-17 06:44:22 +04:00
|
|
|
mNavigationType = mozilla::dom::PerformanceNavigation::TYPE_RESERVED;
|
2013-10-16 05:35:44 +04:00
|
|
|
mNavigationStartHighRes = 0;
|
2011-06-23 14:39:48 +04:00
|
|
|
mBeforeUnloadStart = 0;
|
|
|
|
mUnloadStart = 0;
|
|
|
|
mUnloadEnd = 0;
|
|
|
|
mLoadEventStart = 0;
|
|
|
|
mLoadEventEnd = 0;
|
|
|
|
mDOMLoading = 0;
|
|
|
|
mDOMInteractive = 0;
|
|
|
|
mDOMContentLoadedEventStart = 0;
|
|
|
|
mDOMContentLoadedEventEnd = 0;
|
|
|
|
mDOMComplete = 0;
|
2012-08-09 07:47:04 +04:00
|
|
|
|
|
|
|
mLoadEventStartSet = false;
|
|
|
|
mLoadEventEndSet = false;
|
|
|
|
mDOMLoadingSet = false;
|
|
|
|
mDOMInteractiveSet = false;
|
|
|
|
mDOMContentLoadedEventStartSet = false;
|
|
|
|
mDOMContentLoadedEventEndSet = false;
|
|
|
|
mDOMCompleteSet = false;
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::TimeStampToDOM(mozilla::TimeStamp aStamp) const
|
2011-07-04 20:44:00 +04:00
|
|
|
{
|
|
|
|
if (aStamp.IsNull()) {
|
2012-07-17 05:42:18 +04:00
|
|
|
return 0;
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp;
|
2013-10-16 05:35:44 +04:00
|
|
|
return GetNavigationStart() + static_cast<int64_t>(duration.ToMilliseconds());
|
2011-08-08 16:20:03 +04:00
|
|
|
}
|
|
|
|
|
2015-05-25 19:53:07 +03:00
|
|
|
DOMTimeMilliSec nsDOMNavigationTiming::DurationFromStart()
|
|
|
|
{
|
2012-07-17 05:42:18 +04:00
|
|
|
return TimeStampToDOM(mozilla::TimeStamp::Now());
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyNavigationStart()
|
|
|
|
{
|
2013-10-16 05:35:44 +04:00
|
|
|
mNavigationStartHighRes = (double)PR_Now() / PR_USEC_PER_MSEC;
|
2011-06-23 14:39:48 +04:00
|
|
|
mNavigationStartTimeStamp = mozilla::TimeStamp::Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyFetchStart(nsIURI* aURI, nsDOMPerformanceNavigationType aNavigationType)
|
|
|
|
{
|
|
|
|
mNavigationType = aNavigationType;
|
|
|
|
// At the unload event time we don't really know the loading uri.
|
|
|
|
// Need it for later check for unload timing access.
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyBeforeUnload()
|
|
|
|
{
|
|
|
|
mBeforeUnloadStart = DurationFromStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyUnloadAccepted(nsIURI* aOldURI)
|
|
|
|
{
|
|
|
|
mUnloadStart = mBeforeUnloadStart;
|
|
|
|
mUnloadedURI = aOldURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyUnloadEventStart()
|
|
|
|
{
|
|
|
|
mUnloadStart = DurationFromStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyUnloadEventEnd()
|
|
|
|
{
|
|
|
|
mUnloadEnd = DurationFromStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyLoadEventStart()
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mLoadEventStartSet) {
|
|
|
|
mLoadEventStart = DurationFromStart();
|
|
|
|
mLoadEventStartSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyLoadEventEnd()
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mLoadEventEndSet) {
|
|
|
|
mLoadEventEnd = DurationFromStart();
|
|
|
|
mLoadEventEndSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::SetDOMLoadingTimeStamp(nsIURI* aURI, mozilla::TimeStamp aValue)
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mDOMLoadingSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMLoading = TimeStampToDOM(aValue);
|
|
|
|
mDOMLoadingSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMLoading(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mDOMLoadingSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMLoading = DurationFromStart();
|
|
|
|
mDOMLoadingSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMInteractive(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mDOMInteractiveSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMInteractive = DurationFromStart();
|
|
|
|
mDOMInteractiveSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMComplete(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mDOMCompleteSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMComplete = DurationFromStart();
|
|
|
|
mDOMCompleteSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mDOMContentLoadedEventStartSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMContentLoadedEventStart = DurationFromStart();
|
|
|
|
mDOMContentLoadedEventStartSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 07:47:04 +04:00
|
|
|
if (!mDOMContentLoadedEventEndSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMContentLoadedEventEnd = DurationFromStart();
|
|
|
|
mDOMContentLoadedEventEndSet = true;
|
|
|
|
}
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::GetUnloadEventStart()
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false);
|
2011-06-23 14:39:48 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-17 05:42:18 +04:00
|
|
|
return mUnloadStart;
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
2012-07-17 05:42:18 +04:00
|
|
|
return 0;
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::GetUnloadEventEnd()
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false);
|
2011-06-23 14:39:48 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-17 05:42:18 +04:00
|
|
|
return mUnloadEnd;
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
2012-07-17 05:42:18 +04:00
|
|
|
return 0;
|
2011-06-23 14:39:48 +04:00
|
|
|
}
|
|
|
|
|