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 "nsDOMNavigationTiming.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-07-02 18:15:39 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-07-03 15:56:26 +00:00
|
|
|
#include "prtime.h"
|
2013-08-15 18:17:48 +00:00
|
|
|
#include "nsIURI.h"
|
2013-08-24 06:12:51 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2011-06-23 10:39:48 +00:00
|
|
|
|
|
|
|
nsDOMNavigationTiming::nsDOMNavigationTiming()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMNavigationTiming::~nsDOMNavigationTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::Clear()
|
|
|
|
{
|
2012-07-17 02:44:22 +00:00
|
|
|
mNavigationType = mozilla::dom::PerformanceNavigation::TYPE_RESERVED;
|
2011-06-23 10:39:48 +00:00
|
|
|
mNavigationStart = 0;
|
|
|
|
mFetchStart = 0;
|
|
|
|
mRedirectStart = 0;
|
|
|
|
mRedirectEnd = 0;
|
2011-07-04 09:30:43 +00:00
|
|
|
mRedirectCount = 0;
|
2011-06-23 10:39:48 +00: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 03:47:04 +00:00
|
|
|
|
|
|
|
mLoadEventStartSet = false;
|
|
|
|
mLoadEventEndSet = false;
|
|
|
|
mDOMLoadingSet = false;
|
|
|
|
mDOMInteractiveSet = false;
|
|
|
|
mDOMContentLoadedEventStartSet = false;
|
|
|
|
mDOMContentLoadedEventEndSet = false;
|
|
|
|
mDOMCompleteSet = false;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::TimeStampToDOM(mozilla::TimeStamp aStamp) const
|
2011-07-04 16:44:00 +00:00
|
|
|
{
|
|
|
|
if (aStamp.IsNull()) {
|
2012-07-17 01:42:18 +00:00
|
|
|
return 0;
|
2011-07-04 16:44:00 +00:00
|
|
|
}
|
|
|
|
mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp;
|
2012-08-22 15:56:38 +00:00
|
|
|
return mNavigationStart + static_cast<int32_t>(duration.ToMilliseconds());
|
2011-07-04 16:44:00 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::TimeStampToDOMOrFetchStart(mozilla::TimeStamp aStamp) const
|
2011-08-08 12:20:03 +00:00
|
|
|
{
|
|
|
|
if (!aStamp.IsNull()) {
|
2012-07-17 01:42:18 +00:00
|
|
|
return TimeStampToDOM(aStamp);
|
2011-08-08 12:20:03 +00:00
|
|
|
} else {
|
2012-07-17 01:42:18 +00:00
|
|
|
return GetFetchStart();
|
2011-08-08 12:20:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-23 10:39:48 +00:00
|
|
|
DOMTimeMilliSec nsDOMNavigationTiming::DurationFromStart(){
|
2012-07-17 01:42:18 +00:00
|
|
|
return TimeStampToDOM(mozilla::TimeStamp::Now());
|
2011-06-23 10:39:48 +00: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 03:47:04 +00:00
|
|
|
if (!mLoadEventStartSet) {
|
|
|
|
mLoadEventStart = DurationFromStart();
|
|
|
|
mLoadEventStartSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyLoadEventEnd()
|
|
|
|
{
|
2012-08-09 03:47:04 +00:00
|
|
|
if (!mLoadEventEndSet) {
|
|
|
|
mLoadEventEnd = DurationFromStart();
|
|
|
|
mLoadEventEndSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-06-23 10:39:48 +00:00
|
|
|
nsDOMNavigationTiming::ReportRedirects()
|
|
|
|
{
|
|
|
|
if (mRedirectCheck == NOT_CHECKED) {
|
2011-07-04 09:30:43 +00:00
|
|
|
mRedirectCount = mRedirects.Count();
|
2011-06-23 10:39:48 +00: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 14:59:28 +00:00
|
|
|
nsresult rv = ssm->CheckSameOriginURI(curr, mLoadedURI, false);
|
2011-06-23 10:39:48 +00:00
|
|
|
if (!NS_SUCCEEDED(rv)) {
|
|
|
|
mRedirectCheck = CHECK_FAILED;
|
2011-07-04 09:30:43 +00:00
|
|
|
mRedirectCount = 0;
|
2011-06-23 10:39:48 +00: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 03:47:04 +00:00
|
|
|
if (!mDOMLoadingSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMLoading = TimeStampToDOM(aValue);
|
|
|
|
mDOMLoadingSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMLoading(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 03:47:04 +00:00
|
|
|
if (!mDOMLoadingSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMLoading = DurationFromStart();
|
|
|
|
mDOMLoadingSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMInteractive(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 03:47:04 +00:00
|
|
|
if (!mDOMInteractiveSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMInteractive = DurationFromStart();
|
|
|
|
mDOMInteractiveSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMComplete(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 03:47:04 +00:00
|
|
|
if (!mDOMCompleteSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMComplete = DurationFromStart();
|
|
|
|
mDOMCompleteSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 03:47:04 +00:00
|
|
|
if (!mDOMContentLoadedEventStartSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMContentLoadedEventStart = DurationFromStart();
|
|
|
|
mDOMContentLoadedEventStartSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI)
|
|
|
|
{
|
2012-08-09 03:47:04 +00:00
|
|
|
if (!mDOMContentLoadedEventEndSet) {
|
|
|
|
mLoadedURI = aURI;
|
|
|
|
mDOMContentLoadedEventEnd = DurationFromStart();
|
|
|
|
mDOMContentLoadedEventEndSet = true;
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t
|
2012-07-17 01:42:18 +00:00
|
|
|
nsDOMNavigationTiming::GetRedirectCount()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
|
|
|
if (ReportRedirects()) {
|
2012-07-17 01:42:18 +00:00
|
|
|
return mRedirectCount;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
2012-07-17 01:42:18 +00:00
|
|
|
return 0;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::GetRedirectStart()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
|
|
|
if (ReportRedirects()) {
|
2012-07-17 01:42:18 +00:00
|
|
|
return mRedirectStart;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
2012-07-17 01:42:18 +00:00
|
|
|
return 0;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::GetRedirectEnd()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
|
|
|
if (ReportRedirects()) {
|
2012-07-17 01:42:18 +00:00
|
|
|
return mRedirectEnd;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
2012-07-17 01:42:18 +00:00
|
|
|
return 0;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::GetUnloadEventStart()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
2011-10-17 14:59:28 +00:00
|
|
|
nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false);
|
2011-06-23 10:39:48 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-17 01:42:18 +00:00
|
|
|
return mUnloadStart;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
2012-07-17 01:42:18 +00:00
|
|
|
return 0;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
|
|
|
nsDOMNavigationTiming::GetUnloadEventEnd()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
2011-10-17 14:59:28 +00:00
|
|
|
nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false);
|
2011-06-23 10:39:48 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-17 01:42:18 +00:00
|
|
|
return mUnloadEnd;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
2012-07-17 01:42:18 +00:00
|
|
|
return 0;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|