Bug 659126 - Implement additional NavigationTiming properties

r=smaug
This commit is contained in:
Igor Bazarny 2011-07-04 18:44:00 +02:00
Родитель 6f9ab0331e
Коммит 8dc2e8c907
7 изменённых файлов: 155 добавлений и 140 удалений

Просмотреть файл

@ -234,6 +234,7 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
#include "nsXULAppAPI.h"
#include "nsDOMNavigationTiming.h"
#include "nsITimedChannel.h"
using namespace mozilla;
@ -9078,6 +9079,13 @@ nsDocShell::DoURILoad(nsIURI * aURI,
}
}
if (Preferences::GetBool("dom.enable_performance", PR_FALSE)) {
nsCOMPtr<nsITimedChannel> timedChannel(do_QueryInterface(channel));
if (timedChannel) {
timedChannel->SetTimingEnabled(PR_TRUE);
}
}
rv = DoChannelLoad(channel, uriLoader, aBypassClassifier);
//

Просмотреть файл

@ -78,9 +78,23 @@ nsDOMNavigationTiming::Clear()
mRedirectCheck = NOT_CHECKED;
}
nsresult
nsDOMNavigationTiming::TimeStampToDOM(mozilla::TimeStamp aStamp,
DOMTimeMilliSec* aResult)
{
if (aStamp.IsNull()) {
*aResult = 0;
return NS_OK;
}
mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp;
*aResult = mNavigationStart + static_cast<PRInt32>(duration.ToMilliseconds());
return NS_OK;
}
DOMTimeMilliSec nsDOMNavigationTiming::DurationFromStart(){
mozilla::TimeDuration duration = mozilla::TimeStamp::Now() - mNavigationStartTimeStamp;
return mNavigationStart + static_cast<PRInt32>(duration.ToMilliseconds());
DOMTimeMilliSec result;
TimeStampToDOM(mozilla::TimeStamp::Now(), &result);
return result;
}
void
@ -183,8 +197,7 @@ void
nsDOMNavigationTiming::SetDOMLoadingTimeStamp(nsIURI* aURI, mozilla::TimeStamp aValue)
{
mLoadedURI = aURI;
mozilla::TimeDuration duration = aValue - mNavigationStartTimeStamp;
mDOMLoading = mNavigationStart + (int)(duration.ToMilliseconds());
TimeStampToDOM(aValue, &mDOMLoading);
}
void
@ -222,18 +235,7 @@ nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI)
mDOMContentLoadedEventEnd = DurationFromStart();
}
NS_IMPL_ADDREF(nsDOMNavigationTiming)
NS_IMPL_RELEASE(nsDOMNavigationTiming)
// QueryInterface implementation for nsDOMNavigationTiming
NS_INTERFACE_MAP_BEGIN(nsDOMNavigationTiming)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPerformanceTiming)
NS_INTERFACE_MAP_ENTRY(nsIDOMPerformanceTiming)
NS_INTERFACE_MAP_ENTRY(nsIDOMPerformanceNavigation)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetType(
nsDOMPerformanceNavigationType* aNavigationType)
{
@ -241,7 +243,7 @@ nsDOMNavigationTiming::GetType(
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetRedirectCount(PRUint16* aRedirectCount)
{
*aRedirectCount = 0;
@ -251,7 +253,7 @@ nsDOMNavigationTiming::GetRedirectCount(PRUint16* aRedirectCount)
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetRedirectStart(DOMTimeMilliSec* aRedirectStart)
{
*aRedirectStart = 0;
@ -261,7 +263,7 @@ nsDOMNavigationTiming::GetRedirectStart(DOMTimeMilliSec* aRedirectStart)
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetRedirectEnd(DOMTimeMilliSec* aEnd)
{
*aEnd = 0;
@ -271,14 +273,14 @@ nsDOMNavigationTiming::GetRedirectEnd(DOMTimeMilliSec* aEnd)
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetNavigationStart(DOMTimeMilliSec* aNavigationStart)
{
*aNavigationStart = mNavigationStart;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetUnloadEventStart(DOMTimeMilliSec* aStart)
{
*aStart = 0;
@ -290,7 +292,7 @@ nsDOMNavigationTiming::GetUnloadEventStart(DOMTimeMilliSec* aStart)
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetUnloadEventEnd(DOMTimeMilliSec* aEnd)
{
*aEnd = 0;
@ -302,120 +304,56 @@ nsDOMNavigationTiming::GetUnloadEventEnd(DOMTimeMilliSec* aEnd)
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetFetchStart(DOMTimeMilliSec* aStart)
{
*aStart = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetDomainLookupStart(DOMTimeMilliSec* aStart)
{
// TODO: Implement me! (bug 659126)
*aStart = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetDomainLookupEnd(DOMTimeMilliSec* aEnd)
{
// TODO: Implement me! (bug 659126)
*aEnd = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetConnectStart(DOMTimeMilliSec* aStart)
{
// TODO: Implement me! (bug 659126)
*aStart = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetConnectEnd(DOMTimeMilliSec* aEnd)
{
// TODO: Implement me! (bug 659126)
*aEnd = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetHandshakeStart(DOMTimeMilliSec* aStart)
{
// TODO: Implement me! (bug 659126)
*aStart = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetRequestStart(DOMTimeMilliSec* aStart)
{
// TODO: Implement me! (bug 659126)
*aStart = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetResponseStart(DOMTimeMilliSec* aStart)
{
// TODO: Implement me! (bug 659126)
*aStart = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsDOMNavigationTiming::GetResponseEnd(DOMTimeMilliSec* aEnd)
{
// TODO: Implement me! (bug 659126)
*aEnd = mFetchStart;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetDomLoading(DOMTimeMilliSec* aTime)
{
*aTime = mDOMLoading;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetDomInteractive(DOMTimeMilliSec* aTime)
{
*aTime = mDOMInteractive;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetDomContentLoadedEventStart(DOMTimeMilliSec* aStart)
{
*aStart = mDOMContentLoadedEventStart;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetDomContentLoadedEventEnd(DOMTimeMilliSec* aEnd)
{
*aEnd = mDOMContentLoadedEventEnd;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetDomComplete(DOMTimeMilliSec* aTime)
{
*aTime = mDOMComplete;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetLoadEventStart(DOMTimeMilliSec* aStart)
{
*aStart = mLoadEventStart;
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsDOMNavigationTiming::GetLoadEventEnd(DOMTimeMilliSec* aEnd)
{
*aEnd = mLoadEventEnd;

Просмотреть файл

@ -51,15 +51,28 @@ class nsDOMNavigationTimingClock;
class nsIURI;
class nsIDocument;
class nsDOMNavigationTiming : public nsIDOMPerformanceTiming,
public nsIDOMPerformanceNavigation
class nsDOMNavigationTiming
{
public:
nsDOMNavigationTiming();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMPERFORMANCETIMING
NS_DECL_NSIDOMPERFORMANCENAVIGATION
NS_INLINE_DECL_REFCOUNTING(nsDOMNavigationTiming)
nsresult GetType(nsDOMPerformanceNavigationType* aNavigationType);
nsresult GetRedirectCount(PRUint16* aCount);
nsresult GetRedirectStart(DOMTimeMilliSec* aRedirectStart);
nsresult GetRedirectEnd(DOMTimeMilliSec* aEnd);
nsresult GetNavigationStart(DOMTimeMilliSec* aNavigationStart);
nsresult GetUnloadEventStart(DOMTimeMilliSec* aStart);
nsresult GetUnloadEventEnd(DOMTimeMilliSec* aEnd);
nsresult GetFetchStart(DOMTimeMilliSec* aStart);
nsresult GetDomLoading(DOMTimeMilliSec* aTime);
nsresult GetDomInteractive(DOMTimeMilliSec* aTime);
nsresult GetDomContentLoadedEventStart(DOMTimeMilliSec* aStart);
nsresult GetDomContentLoadedEventEnd(DOMTimeMilliSec* aEnd);
nsresult GetDomComplete(DOMTimeMilliSec* aTime);
nsresult GetLoadEventStart(DOMTimeMilliSec* aStart);
nsresult GetLoadEventEnd(DOMTimeMilliSec* aEnd);
void NotifyNavigationStart();
void NotifyFetchStart(nsIURI* aURI, nsDOMPerformanceNavigationType aNavigationType);
@ -78,6 +91,7 @@ public:
void NotifyDOMComplete(nsIURI* aURI);
void NotifyDOMContentLoadedStart(nsIURI* aURI);
void NotifyDOMContentLoadedEnd(nsIURI* aURI);
nsresult TimeStampToDOM(mozilla::TimeStamp aStamp, DOMTimeMilliSec* aResult);
private:
nsDOMNavigationTiming(const nsDOMNavigationTiming &){};

Просмотреть файл

@ -189,6 +189,7 @@
#include "nsFocusManager.h"
#include "nsIXULWindow.h"
#include "nsEventStateManager.h"
#include "nsITimedChannel.h"
#ifdef MOZ_XUL
#include "nsXULPopupManager.h"
#include "nsIDOMXULControlElement.h"
@ -3002,8 +3003,15 @@ nsGlobalWindow::GetPerformance(nsIDOMPerformance** aPerformance)
return NS_OK;
}
nsRefPtr<nsDOMNavigationTiming> timing = mDoc->GetNavigationTiming();
nsCOMPtr<nsITimedChannel> timedChannel(do_QueryInterface(mDoc->GetChannel()));
PRBool timingEnabled = PR_FALSE;
if (!timedChannel ||
!NS_SUCCEEDED(timedChannel->GetTimingEnabled(&timingEnabled)) ||
!timingEnabled) {
timedChannel = nsnull;
}
if (timing) {
mPerformance = new nsPerformance(timing);
mPerformance = new nsPerformance(timing, timedChannel);
}
}
NS_IF_ADDREF(*aPerformance = mPerformance);

Просмотреть файл

@ -38,9 +38,11 @@
* ***** END LICENSE BLOCK ***** */
#include "nsPerformance.h"
#include "TimeStamp.h"
#include "nsCOMPtr.h"
#include "nscore.h"
#include "nsIDocShell.h"
#include "nsITimedChannel.h"
#include "nsDOMClassInfo.h"
#include "nsDOMNavigationTiming.h"
@ -56,10 +58,12 @@ NS_INTERFACE_MAP_BEGIN(nsPerformanceTiming)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PerformanceTiming)
NS_INTERFACE_MAP_END
nsPerformanceTiming::nsPerformanceTiming(nsDOMNavigationTiming* aData)
nsPerformanceTiming::nsPerformanceTiming(nsDOMNavigationTiming* aDOMTiming,
nsITimedChannel* aChannel)
{
NS_ASSERTION(aData, "Timing data should be provided");
mData = aData;
NS_ASSERTION(aDOMTiming, "DOM timing data should be provided");
mDOMTiming = aDOMTiming;
mChannel = aChannel;
}
nsPerformanceTiming::~nsPerformanceTiming()
@ -69,127 +73,166 @@ nsPerformanceTiming::~nsPerformanceTiming()
NS_IMETHODIMP
nsPerformanceTiming::GetNavigationStart(DOMTimeMilliSec* aTime)
{
return mData->GetNavigationStart(aTime);
return mDOMTiming->GetNavigationStart(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetUnloadEventStart(DOMTimeMilliSec* aTime)
{
return mData->GetUnloadEventStart(aTime);
return mDOMTiming->GetUnloadEventStart(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetUnloadEventEnd(DOMTimeMilliSec* aTime)
{
return mData->GetUnloadEventEnd(aTime);
return mDOMTiming->GetUnloadEventEnd(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetRedirectStart(DOMTimeMilliSec* aTime)
{
return mData->GetRedirectStart(aTime);
return mDOMTiming->GetRedirectStart(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetRedirectEnd(DOMTimeMilliSec* aTime)
{
return mData->GetRedirectEnd(aTime);
return mDOMTiming->GetRedirectEnd(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetFetchStart(DOMTimeMilliSec* aTime)
{
return mData->GetFetchStart(aTime);
return mDOMTiming->GetFetchStart(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetDomainLookupStart(DOMTimeMilliSec* aTime)
{
return mData->GetDomainLookupStart(aTime);
if (!mChannel) {
return GetFetchStart(aTime);
}
mozilla::TimeStamp stamp;
mChannel->GetDomainLookupStart(&stamp);
return mDOMTiming->TimeStampToDOM(stamp, aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetDomainLookupEnd(DOMTimeMilliSec* aTime)
{
return mData->GetDomainLookupEnd(aTime);
if (!mChannel) {
return GetFetchStart(aTime);
}
mozilla::TimeStamp stamp;
mChannel->GetDomainLookupEnd(&stamp);
return mDOMTiming->TimeStampToDOM(stamp, aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetConnectStart(DOMTimeMilliSec* aTime)
{
return mData->GetConnectStart(aTime);
if (!mChannel) {
return GetFetchStart(aTime);
}
mozilla::TimeStamp stamp;
mChannel->GetConnectStart(&stamp);
return mDOMTiming->TimeStampToDOM(stamp, aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetConnectEnd(DOMTimeMilliSec* aTime)
{
return mData->GetConnectEnd(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetHandshakeStart(DOMTimeMilliSec* aTime)
{
return mData->GetHandshakeStart(aTime);
if (!mChannel) {
return GetFetchStart(aTime);
}
mozilla::TimeStamp stamp;
mChannel->GetConnectEnd(&stamp);
return mDOMTiming->TimeStampToDOM(stamp, aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetRequestStart(DOMTimeMilliSec* aTime)
{
return mData->GetRequestStart(aTime);
if (!mChannel) {
return GetFetchStart(aTime);
}
mozilla::TimeStamp stamp;
mChannel->GetRequestStart(&stamp);
return mDOMTiming->TimeStampToDOM(stamp, aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetResponseStart(DOMTimeMilliSec* aTime)
{
return mData->GetResponseStart(aTime);
if (!mChannel) {
return GetFetchStart(aTime);
}
mozilla::TimeStamp stamp;
mChannel->GetResponseStart(&stamp);
mozilla::TimeStamp cacheStamp;
mChannel->GetCacheReadStart(&cacheStamp);
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
stamp = cacheStamp;
}
return mDOMTiming->TimeStampToDOM(stamp, aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetResponseEnd(DOMTimeMilliSec* aTime)
{
return mData->GetResponseEnd(aTime);
if (!mChannel) {
return GetFetchStart(aTime);
}
mozilla::TimeStamp stamp;
mChannel->GetResponseEnd(&stamp);
mozilla::TimeStamp cacheStamp;
mChannel->GetCacheReadEnd(&cacheStamp);
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
stamp = cacheStamp;
}
return mDOMTiming->TimeStampToDOM(stamp, aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetDomLoading(DOMTimeMilliSec* aTime)
{
return mData->GetDomLoading(aTime);
return mDOMTiming->GetDomLoading(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetDomInteractive(DOMTimeMilliSec* aTime)
{
return mData->GetDomInteractive(aTime);
return mDOMTiming->GetDomInteractive(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetDomContentLoadedEventStart(DOMTimeMilliSec* aTime)
{
return mData->GetDomContentLoadedEventStart(aTime);
return mDOMTiming->GetDomContentLoadedEventStart(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetDomContentLoadedEventEnd(DOMTimeMilliSec* aTime)
{
return mData->GetDomContentLoadedEventEnd(aTime);
return mDOMTiming->GetDomContentLoadedEventEnd(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetDomComplete(DOMTimeMilliSec* aTime)
{
return mData->GetDomComplete(aTime);
return mDOMTiming->GetDomComplete(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetLoadEventStart(DOMTimeMilliSec* aTime)
{
return mData->GetLoadEventStart(aTime);
return mDOMTiming->GetLoadEventStart(aTime);
}
NS_IMETHODIMP
nsPerformanceTiming::GetLoadEventEnd(DOMTimeMilliSec* aTime)
{
return mData->GetLoadEventEnd(aTime);
return mDOMTiming->GetLoadEventEnd(aTime);
}
@ -235,10 +278,12 @@ DOMCI_DATA(Performance, nsPerformance)
NS_IMPL_ADDREF(nsPerformance)
NS_IMPL_RELEASE(nsPerformance)
nsPerformance::nsPerformance(nsDOMNavigationTiming* aTiming)
nsPerformance::nsPerformance(nsDOMNavigationTiming* aDOMTiming,
nsITimedChannel* aChannel)
{
NS_ASSERTION(aTiming, "Timing data should be provided");
mData = aTiming;
NS_ASSERTION(aDOMTiming, "DOM timing data should be provided");
mDOMTiming = aDOMTiming;
mChannel = aChannel;
}
nsPerformance::~nsPerformance()
@ -259,7 +304,7 @@ NS_IMETHODIMP
nsPerformance::GetTiming(nsIDOMPerformanceTiming** aTiming)
{
if (!mTiming) {
mTiming = new nsPerformanceTiming(mData);
mTiming = new nsPerformanceTiming(mDOMTiming, mChannel);
}
NS_IF_ADDREF(*aTiming = mTiming);
return NS_OK;
@ -269,7 +314,7 @@ NS_IMETHODIMP
nsPerformance::GetNavigation(nsIDOMPerformanceNavigation** aNavigation)
{
if (!mNavigation) {
mNavigation = new nsPerformanceNavigation(mData);
mNavigation = new nsPerformanceNavigation(mDOMTiming);
}
NS_IF_ADDREF(*aNavigation = mNavigation);
return NS_OK;

Просмотреть файл

@ -49,17 +49,19 @@
class nsIDocument;
class nsIURI;
class nsDOMNavigationTiming;
class nsITimedChannel;
// Script "performance.timing" object
class nsPerformanceTiming : public nsIDOMPerformanceTiming
{
public:
nsPerformanceTiming(nsDOMNavigationTiming* data);
nsPerformanceTiming(nsDOMNavigationTiming* aDOMTiming, nsITimedChannel* aChannel);
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMPERFORMANCETIMING
private:
~nsPerformanceTiming();
nsRefPtr<nsDOMNavigationTiming> mData;
nsRefPtr<nsDOMNavigationTiming> mDOMTiming;
nsCOMPtr<nsITimedChannel> mChannel;
};
// Script "performance.navigation" object
@ -78,7 +80,7 @@ private:
class nsPerformance : public nsIDOMPerformance
{
public:
nsPerformance(nsDOMNavigationTiming* timing);
nsPerformance(nsDOMNavigationTiming* aDOMTiming, nsITimedChannel* aChannel);
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMPERFORMANCE
@ -86,7 +88,8 @@ public:
private:
~nsPerformance();
nsRefPtr<nsDOMNavigationTiming> mData;
nsRefPtr<nsDOMNavigationTiming> mDOMTiming;
nsCOMPtr<nsITimedChannel> mChannel;
nsCOMPtr<nsIDOMPerformanceTiming> mTiming;
nsCOMPtr<nsIDOMPerformanceNavigation> mNavigation;
};

Просмотреть файл

@ -39,7 +39,7 @@
#include "domstubs.idl"
[scriptable, uuid(2a630b50-61b6-41b3-996d-70be67fbbcb0)]
[scriptable, uuid(8e09c825-da49-4a39-876b-ce2ff767dbe1)]
interface nsIDOMPerformanceTiming : nsISupports
{
readonly attribute DOMTimeMilliSec navigationStart;
@ -52,7 +52,6 @@ interface nsIDOMPerformanceTiming : nsISupports
readonly attribute DOMTimeMilliSec domainLookupEnd;
readonly attribute DOMTimeMilliSec connectStart;
readonly attribute DOMTimeMilliSec connectEnd;
readonly attribute DOMTimeMilliSec handshakeStart;
readonly attribute DOMTimeMilliSec requestStart;
readonly attribute DOMTimeMilliSec responseStart;
readonly attribute DOMTimeMilliSec responseEnd;