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 "nsPerformance.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-10-16 01:35:44 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2011-07-04 16:44:00 +00:00
|
|
|
#include "nsITimedChannel.h"
|
2011-06-23 10:39:48 +00:00
|
|
|
#include "nsDOMNavigationTiming.h"
|
2012-07-17 01:42:18 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-16 01:35:44 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2012-07-17 01:42:18 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
2013-10-16 01:35:44 +00:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "PerformanceEntry.h"
|
|
|
|
#include "PerformanceResourceTiming.h"
|
2012-07-17 01:42:18 +00:00
|
|
|
#include "mozilla/dom/PerformanceBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceTimingBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceNavigationBinding.h"
|
2013-08-24 06:12:51 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-10-16 01:35:44 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2012-07-17 01:42:18 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-06-23 10:39:48 +00:00
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPerformanceTiming, mPerformance)
|
2011-06-23 10:39:48 +00:00
|
|
|
|
2012-12-06 21:01:59 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceTiming, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceTiming, Release)
|
2011-06-23 10:39:48 +00:00
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
nsPerformanceTiming::nsPerformanceTiming(nsPerformance* aPerformance,
|
2013-10-16 01:35:44 +00:00
|
|
|
nsITimedChannel* aChannel,
|
|
|
|
nsIHttpChannel* aHttpChannel,
|
|
|
|
DOMHighResTimeStamp aZeroTime)
|
2012-07-17 01:42:18 +00:00
|
|
|
: mPerformance(aPerformance),
|
2013-10-16 01:35:44 +00:00
|
|
|
mChannel(aChannel),
|
|
|
|
mFetchStart(0.0),
|
|
|
|
mZeroTime(aZeroTime),
|
|
|
|
mReportCrossOriginResources(true)
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2012-07-17 01:42:18 +00:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2013-10-16 01:35:44 +00:00
|
|
|
// The aHttpChannel argument is null if this nsPerformanceTiming object
|
|
|
|
// is being used for the navigation timing (document) and has a non-null
|
|
|
|
// value for the resource timing (any resources within the page).
|
|
|
|
if (aHttpChannel) {
|
|
|
|
CheckRedirectCrossOrigin(aHttpChannel);
|
|
|
|
}
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceTiming::~nsPerformanceTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-16 01:35:44 +00:00
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::FetchStartHighRes()
|
|
|
|
{
|
|
|
|
if (!mFetchStart) {
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-10-16 01:35:44 +00:00
|
|
|
}
|
|
|
|
TimeStamp stamp;
|
|
|
|
mChannel->GetAsyncOpen(&stamp);
|
|
|
|
MOZ_ASSERT(!stamp.IsNull(), "The fetch start time stamp should always be "
|
|
|
|
"valid if the performance timing is enabled");
|
|
|
|
mFetchStart = (!stamp.IsNull())
|
|
|
|
? TimeStampToDOMHighRes(stamp)
|
|
|
|
: 0.0;
|
|
|
|
}
|
|
|
|
return mFetchStart;
|
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
2013-10-16 01:35:44 +00:00
|
|
|
nsPerformanceTiming::FetchStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(FetchStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method will implement the timing allow check algorithm
|
|
|
|
// http://w3c-test.org/webperf/specs/ResourceTiming/#timing-allow-check
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=936814
|
|
|
|
void
|
|
|
|
nsPerformanceTiming::CheckRedirectCrossOrigin(nsIHttpChannel* aResourceChannel)
|
|
|
|
{
|
2014-04-21 13:34:33 +00:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-16 01:35:44 +00:00
|
|
|
uint16_t redirectCount;
|
|
|
|
mChannel->GetRedirectCount(&redirectCount);
|
|
|
|
if (redirectCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> resourceURI, referrerURI;
|
|
|
|
aResourceChannel->GetReferrer(getter_AddRefs(referrerURI));
|
|
|
|
aResourceChannel->GetURI(getter_AddRefs(resourceURI));
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
|
|
nsresult rv = ssm->CheckSameOriginURI(resourceURI, referrerURI, false);
|
|
|
|
if (!NS_SUCCEEDED(rv)) {
|
|
|
|
mReportCrossOriginResources = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformanceTiming::IsSameOriginAsReferral() const
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2013-10-16 01:35:44 +00:00
|
|
|
return mReportCrossOriginResources;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
nsPerformanceTiming::GetRedirectCount() const
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bool sameOrigin;
|
|
|
|
mChannel->GetAllRedirectsSameOrigin(&sameOrigin);
|
|
|
|
if (!sameOrigin) {
|
2013-05-10 22:57:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-16 01:35:44 +00:00
|
|
|
uint16_t redirectCount;
|
|
|
|
mChannel->GetRedirectCount(&redirectCount);
|
|
|
|
return redirectCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RedirectStartHighRes() is used by both the navigation timing and the
|
|
|
|
* resource timing. Since, navigation timing and resource timing check and
|
|
|
|
* interpret cross-domain redirects in a different manner,
|
|
|
|
* RedirectStartHighRes() will make no checks for cross-domain redirect.
|
|
|
|
* It's up to the consumers of this method (nsPerformanceTiming::RedirectStart()
|
|
|
|
* and PerformanceResourceTiming::RedirectStart() to make such verifications.
|
|
|
|
*
|
|
|
|
* @return a valid timing if the Performance Timing is enabled
|
|
|
|
*/
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::RedirectStartHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2011-07-04 16:44:00 +00:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
2013-10-16 01:35:44 +00:00
|
|
|
mChannel->GetRedirectStart(&stamp);
|
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::RedirectStart()
|
|
|
|
{
|
2014-04-21 13:34:33 +00:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return mZeroTime;
|
|
|
|
}
|
2013-10-16 01:35:44 +00:00
|
|
|
// We have to check if all the redirect URIs had the same origin (since there
|
|
|
|
// is no check in RedirectStartHighRes())
|
|
|
|
bool sameOrigin;
|
|
|
|
mChannel->GetAllRedirectsSameOrigin(&sameOrigin);
|
|
|
|
if (sameOrigin) {
|
|
|
|
return static_cast<int64_t>(RedirectStartHighRes());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RedirectEndHighRes() is used by both the navigation timing and the resource
|
|
|
|
* timing. Since, navigation timing and resource timing check and interpret
|
|
|
|
* cross-domain redirects in a different manner, RedirectEndHighRes() will make
|
|
|
|
* no checks for cross-domain redirect. It's up to the consumers of this method
|
|
|
|
* (nsPerformanceTiming::RedirectEnd() and
|
|
|
|
* PerformanceResourceTiming::RedirectEnd() to make such verifications.
|
|
|
|
*
|
|
|
|
* @return a valid timing if the Performance Timing is enabled
|
|
|
|
*/
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::RedirectEndHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-10-16 01:35:44 +00:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetRedirectEnd(&stamp);
|
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
2013-10-16 01:35:44 +00:00
|
|
|
nsPerformanceTiming::RedirectEnd()
|
|
|
|
{
|
2014-04-21 13:34:33 +00:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return mZeroTime;
|
|
|
|
}
|
2013-10-16 01:35:44 +00:00
|
|
|
// We have to check if all the redirect URIs had the same origin (since there
|
|
|
|
// is no check in RedirectEndHighRes())
|
|
|
|
bool sameOrigin;
|
|
|
|
mChannel->GetAllRedirectsSameOrigin(&sameOrigin);
|
|
|
|
if (sameOrigin) {
|
|
|
|
return static_cast<int64_t>(RedirectEndHighRes());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::DomainLookupStartHighRes()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2013-10-16 01:35:44 +00:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-05-10 22:57:58 +00:00
|
|
|
}
|
2013-10-16 01:35:44 +00:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetDomainLookupStart(&stamp);
|
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::DomainLookupStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(DomainLookupStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::DomainLookupEndHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2011-07-04 16:44:00 +00:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetDomainLookupEnd(&stamp);
|
2013-10-16 01:35:44 +00:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
2013-10-16 01:35:44 +00:00
|
|
|
nsPerformanceTiming::DomainLookupEnd()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2013-10-16 01:35:44 +00:00
|
|
|
return static_cast<int64_t>(DomainLookupEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ConnectStartHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-05-10 22:57:58 +00:00
|
|
|
}
|
2011-07-04 16:44:00 +00:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectStart(&stamp);
|
2013-10-16 01:35:44 +00:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
2013-10-16 01:35:44 +00:00
|
|
|
nsPerformanceTiming::ConnectStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ConnectStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ConnectEndHighRes()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2013-10-16 01:35:44 +00:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-05-10 22:57:58 +00:00
|
|
|
}
|
2011-07-04 16:44:00 +00:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectEnd(&stamp);
|
2013-10-16 01:35:44 +00:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
2013-10-16 01:35:44 +00:00
|
|
|
nsPerformanceTiming::ConnectEnd()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ConnectEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::RequestStartHighRes()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2013-10-16 01:35:44 +00:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-05-10 22:57:58 +00:00
|
|
|
}
|
2011-07-04 16:44:00 +00:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetRequestStart(&stamp);
|
2013-10-16 01:35:44 +00:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
2013-10-16 01:35:44 +00:00
|
|
|
nsPerformanceTiming::RequestStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(RequestStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ResponseStartHighRes()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2013-10-16 01:35:44 +00:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-05-10 22:57:58 +00:00
|
|
|
}
|
2011-07-04 16:44:00 +00:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseStart(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadStart(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2013-10-16 01:35:44 +00:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
DOMTimeMilliSec
|
2013-10-16 01:35:44 +00:00
|
|
|
nsPerformanceTiming::ResponseStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ResponseStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ResponseEndHighRes()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2013-10-16 01:35:44 +00:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 13:34:33 +00:00
|
|
|
return mZeroTime;
|
2013-05-10 22:57:58 +00:00
|
|
|
}
|
2011-07-04 16:44:00 +00:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseEnd(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadEnd(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2013-10-16 01:35:44 +00:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::ResponseEnd()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ResponseEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformanceTiming::IsInitialized() const
|
|
|
|
{
|
|
|
|
return !!mChannel;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
nsPerformanceTiming::WrapObject(JSContext *cx)
|
2012-07-17 01:42:18 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return dom::PerformanceTimingBinding::Wrap(cx, this);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsPerformanceNavigation, mPerformance)
|
2011-06-23 10:39:48 +00:00
|
|
|
|
2012-12-06 21:01:59 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceNavigation, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceNavigation, Release)
|
2011-06-23 10:39:48 +00:00
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
nsPerformanceNavigation::nsPerformanceNavigation(nsPerformance* aPerformance)
|
|
|
|
: mPerformance(aPerformance)
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2012-07-17 01:42:18 +00:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceNavigation::~nsPerformanceNavigation()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
nsPerformanceNavigation::WrapObject(JSContext *cx)
|
2012-07-17 01:42:18 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return dom::PerformanceNavigationBinding::Wrap(cx, this);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-10 02:12:06 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsPerformance, DOMEventTargetHelper,
|
|
|
|
mWindow, mTiming,
|
|
|
|
mNavigation, mEntries,
|
|
|
|
mParentPerformance)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsPerformance, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsPerformance, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
nsPerformance::nsPerformance(nsPIDOMWindow* aWindow,
|
2012-07-17 01:42:18 +00:00
|
|
|
nsDOMNavigationTiming* aDOMTiming,
|
2013-10-16 01:35:44 +00:00
|
|
|
nsITimedChannel* aChannel,
|
|
|
|
nsPerformance* aParentPerformance)
|
2014-05-10 02:12:06 +00:00
|
|
|
: DOMEventTargetHelper(aWindow),
|
|
|
|
mWindow(aWindow),
|
2012-07-17 01:42:18 +00:00
|
|
|
mDOMTiming(aDOMTiming),
|
2013-10-16 01:35:44 +00:00
|
|
|
mChannel(aChannel),
|
|
|
|
mParentPerformance(aParentPerformance),
|
|
|
|
mPrimaryBufferSize(kDefaultBufferSize)
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
2012-07-17 01:42:18 +00:00
|
|
|
MOZ_ASSERT(aWindow, "Parent window object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformance::~nsPerformance()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformance
|
2012-07-17 01:42:18 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPerformance)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-07-17 02:44:22 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2014-05-10 02:12:06 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2011-06-23 10:39:48 +00:00
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
|
|
|
|
nsPerformanceTiming*
|
2012-09-11 19:08:24 +00:00
|
|
|
nsPerformance::Timing()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
|
|
|
if (!mTiming) {
|
2013-10-16 01:35:44 +00:00
|
|
|
// For navigation timing, the third argument (an nsIHtttpChannel) is null
|
|
|
|
// since the cross-domain redirect were already checked.
|
|
|
|
// The last argument (zero time) for performance.timing is the navigation
|
|
|
|
// start value.
|
|
|
|
mTiming = new nsPerformanceTiming(this, mChannel, nullptr,
|
|
|
|
mDOMTiming->GetNavigationStart());
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
2012-07-17 01:42:18 +00:00
|
|
|
return mTiming;
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
|
|
|
|
2014-05-10 02:12:06 +00:00
|
|
|
void
|
|
|
|
nsPerformance::DispatchBufferFullEvent()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// it bubbles, and it isn't cancelable
|
|
|
|
rv = event->InitEvent(NS_LITERAL_STRING("resourcetimingbufferfull"), true, false);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
event->SetTrusted(true);
|
|
|
|
DispatchDOMEvent(nullptr, event, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 01:42:18 +00:00
|
|
|
nsPerformanceNavigation*
|
2012-09-11 19:08:24 +00:00
|
|
|
nsPerformance::Navigation()
|
2011-06-23 10:39:48 +00:00
|
|
|
{
|
|
|
|
if (!mNavigation) {
|
2012-07-17 01:42:18 +00:00
|
|
|
mNavigation = new nsPerformanceNavigation(this);
|
2011-06-23 10:39:48 +00:00
|
|
|
}
|
2012-07-17 01:42:18 +00:00
|
|
|
return mNavigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformance::Now()
|
|
|
|
{
|
|
|
|
return GetDOMTiming()->TimeStampToDOMHighRes(mozilla::TimeStamp::Now());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
nsPerformance::WrapObject(JSContext *cx)
|
2012-07-17 01:42:18 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return dom::PerformanceBinding::Wrap(cx, this);
|
2012-07-17 01:42:18 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 01:35:44 +00:00
|
|
|
void
|
|
|
|
nsPerformance::GetEntries(nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-05-10 02:11:54 +00:00
|
|
|
retval = mEntries;
|
2013-10-16 01:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::GetEntriesByType(const nsAString& entryType,
|
|
|
|
nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
retval.Clear();
|
|
|
|
uint32_t count = mEntries.Length();
|
2014-05-10 02:11:54 +00:00
|
|
|
for (uint32_t i = 0 ; i < count; i++) {
|
2013-10-16 01:35:44 +00:00
|
|
|
if (mEntries[i]->GetEntryType().Equals(entryType)) {
|
|
|
|
retval.AppendElement(mEntries[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::GetEntriesByName(const nsAString& name,
|
|
|
|
const mozilla::dom::Optional<nsAString>& entryType,
|
|
|
|
nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
retval.Clear();
|
|
|
|
uint32_t count = mEntries.Length();
|
2014-05-10 02:11:54 +00:00
|
|
|
for (uint32_t i = 0 ; i < count; i++) {
|
2013-10-16 01:35:44 +00:00
|
|
|
if (mEntries[i]->GetName().Equals(name) &&
|
|
|
|
(!entryType.WasPassed() ||
|
|
|
|
mEntries[i]->GetEntryType().Equals(entryType.Value()))) {
|
|
|
|
retval.AppendElement(mEntries[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::ClearResourceTimings()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mEntries.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::SetResourceTimingBufferSize(uint64_t maxSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-05-10 02:11:54 +00:00
|
|
|
mPrimaryBufferSize = maxSize;
|
2013-10-16 01:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An entry should be added only after the resource is loaded.
|
|
|
|
* This method is not thread safe and can only be called on the main thread.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsPerformance::AddEntry(nsIHttpChannel* channel,
|
|
|
|
nsITimedChannel* timedChannel)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// Check if resource timing is prefed off.
|
|
|
|
if (!nsContentUtils::IsResourceTimingEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-10 02:11:54 +00:00
|
|
|
|
|
|
|
// Don't add the entry if the buffer is full
|
|
|
|
if (mEntries.Length() >= mPrimaryBufferSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-16 01:35:44 +00:00
|
|
|
if (channel && timedChannel) {
|
|
|
|
nsAutoCString name;
|
|
|
|
nsAutoString initiatorType;
|
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
|
|
|
|
timedChannel->GetInitiatorType(initiatorType);
|
|
|
|
|
|
|
|
// According to the spec, "The name attribute must return the resolved URL
|
|
|
|
// of the requested resource. This attribute must not change even if the
|
|
|
|
// fetch redirected to a different URL."
|
|
|
|
channel->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
originalURI->GetSpec(name);
|
|
|
|
NS_ConvertUTF8toUTF16 entryName(name);
|
|
|
|
|
|
|
|
// The nsITimedChannel argument will be used to gather all the timings.
|
|
|
|
// The nsIHttpChannel argument will be used to check if any cross-origin
|
|
|
|
// redirects occurred.
|
|
|
|
// The last argument is the "zero time" (offset). Since we don't want
|
|
|
|
// any offset for the resource timing, this will be set to "0" - the
|
|
|
|
// resource timing returns a relative timing (no offset).
|
|
|
|
nsRefPtr<nsPerformanceTiming> performanceTiming =
|
|
|
|
new nsPerformanceTiming(this, timedChannel, channel,
|
|
|
|
0);
|
|
|
|
|
|
|
|
// The PerformanceResourceTiming object will use the nsPerformanceTiming
|
|
|
|
// object to get all the required timings.
|
|
|
|
nsRefPtr<dom::PerformanceResourceTiming> performanceEntry =
|
|
|
|
new dom::PerformanceResourceTiming(performanceTiming, this);
|
|
|
|
|
|
|
|
performanceEntry->SetName(entryName);
|
|
|
|
performanceEntry->SetEntryType(NS_LITERAL_STRING("resource"));
|
|
|
|
// If the initiator type had no valid value, then set it to the default
|
|
|
|
// ("other") value.
|
|
|
|
if (initiatorType.IsEmpty()) {
|
|
|
|
initiatorType = NS_LITERAL_STRING("other");
|
|
|
|
}
|
|
|
|
performanceEntry->SetInitiatorType(initiatorType);
|
|
|
|
|
|
|
|
mEntries.InsertElementSorted(performanceEntry,
|
|
|
|
PerformanceEntryComparator());
|
2014-05-10 02:11:54 +00:00
|
|
|
if (mEntries.Length() >= mPrimaryBufferSize) {
|
2013-10-16 01:35:44 +00:00
|
|
|
// call onresourcetimingbufferfull
|
2014-05-10 02:12:06 +00:00
|
|
|
DispatchBufferFullEvent();
|
2013-10-16 01:35:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformance::PerformanceEntryComparator::Equals(
|
|
|
|
const PerformanceEntry* aElem1,
|
|
|
|
const PerformanceEntry* aElem2) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElem1 && aElem2,
|
|
|
|
"Trying to compare null performance entries");
|
|
|
|
return aElem1->StartTime() == aElem2->StartTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformance::PerformanceEntryComparator::LessThan(
|
|
|
|
const PerformanceEntry* aElem1,
|
|
|
|
const PerformanceEntry* aElem2) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aElem1 && aElem2,
|
|
|
|
"Trying to compare null performance entries");
|
|
|
|
return aElem1->StartTime() < aElem2->StartTime();
|
|
|
|
}
|