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 "nsDOMNavigationTiming.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "TimeStamp.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
|
|
|
|
nsDOMNavigationTiming::nsDOMNavigationTiming()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMNavigationTiming::~nsDOMNavigationTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::Clear()
|
|
|
|
{
|
2012-07-17 06:44:22 +04:00
|
|
|
mNavigationType = mozilla::dom::PerformanceNavigation::TYPE_RESERVED;
|
2011-06-23 14:39:48 +04:00
|
|
|
mNavigationStart = 0;
|
|
|
|
mFetchStart = 0;
|
|
|
|
mRedirectStart = 0;
|
|
|
|
mRedirectEnd = 0;
|
2011-07-04 13:30:43 +04:00
|
|
|
mRedirectCount = 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;
|
|
|
|
mRedirectCheck = NOT_CHECKED;
|
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;
|
2012-07-17 05:42:18 +04:00
|
|
|
return mNavigationStart + static_cast<PRInt32>(duration.ToMilliseconds());
|
2011-07-04 20:44:00 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 05:42:18 +04:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::TimeStampToDOMOrFetchStart(mozilla::TimeStamp aStamp) const
|
2011-08-08 16:20:03 +04:00
|
|
|
{
|
|
|
|
if (!aStamp.IsNull()) {
|
2012-07-17 05:42:18 +04:00
|
|
|
return TimeStampToDOM(aStamp);
|
2011-08-08 16:20:03 +04:00
|
|
|
} else {
|
2012-07-17 05:42:18 +04:00
|
|
|
return GetFetchStart();
|
2011-08-08 16:20:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-23 14:39:48 +04: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()
|
|
|
|
{
|
|
|
|
mNavigationStart = PR_Now() / PR_USEC_PER_MSEC;
|
|
|
|
mNavigationStartTimeStamp = mozilla::TimeStamp::Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyFetchStart(nsIURI* aURI, nsDOMPerformanceNavigationType aNavigationType)
|
|
|
|
{
|
|
|
|
mFetchStart = DurationFromStart();
|
|
|
|
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::NotifyRedirect(nsIURI* aOldURI, nsIURI* aNewURI)
|
|
|
|
{
|
|
|
|
if (mRedirects.Count() == 0) {
|
|
|
|
mRedirectStart = mFetchStart;
|
|
|
|
}
|
|
|
|
mFetchStart = DurationFromStart();
|
|
|
|
mRedirectEnd = mFetchStart;
|
|
|
|
|
|
|
|
// At the unload event time we don't really know the loading uri.
|
|
|
|
// Need it for later check for unload timing access.
|
|
|
|
mLoadedURI = aNewURI;
|
|
|
|
|
|
|
|
mRedirects.AppendObject(aOldURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-06-23 14:39:48 +04:00
|
|
|
nsDOMNavigationTiming::ReportRedirects()
|
|
|
|
{
|
|
|
|
if (mRedirectCheck == NOT_CHECKED) {
|
2011-07-04 13:30:43 +04:00
|
|
|
mRedirectCount = mRedirects.Count();
|
2011-06-23 14:39:48 +04:00
|
|
|
if (mRedirects.Count() == 0) {
|
|
|
|
mRedirectCheck = NO_REDIRECTS;
|
|
|
|
} else {
|
|
|
|
mRedirectCheck = CHECK_PASSED;
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
|
|
for (int i = mRedirects.Count() - 1; i >= 0; --i) {
|
|
|
|
nsIURI * curr = mRedirects[i];
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = ssm->CheckSameOriginURI(curr, mLoadedURI, false);
|
2011-06-23 14:39:48 +04:00
|
|
|
if (!NS_SUCCEEDED(rv)) {
|
|
|
|
mRedirectCheck = CHECK_FAILED;
|
2011-07-04 13:30:43 +04:00
|
|
|
mRedirectCount = 0;
|
2011-06-23 14:39:48 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// All we need to know is in mRedirectCheck now. Clear history.
|
|
|
|
mRedirects.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mRedirectCheck == CHECK_PASSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
PRUint16
|
|
|
|
nsDOMNavigationTiming::GetRedirectCount()
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
|
|
|
if (ReportRedirects()) {
|
2012-07-17 05:42:18 +04:00
|
|
|
return mRedirectCount;
|
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::GetRedirectStart()
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
|
|
|
if (ReportRedirects()) {
|
2012-07-17 05:42:18 +04:00
|
|
|
return mRedirectStart;
|
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::GetRedirectEnd()
|
2011-06-23 14:39:48 +04:00
|
|
|
{
|
|
|
|
if (ReportRedirects()) {
|
2012-07-17 05:42:18 +04:00
|
|
|
return mRedirectEnd;
|
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::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
|
|
|
}
|
|
|
|
|