2011-06-23 03:39:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 03:39:48 -07:00
|
|
|
|
|
|
|
#include "nsPerformance.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsIHttpChannel.h"
|
2011-07-04 09:44:00 -07:00
|
|
|
#include "nsITimedChannel.h"
|
2011-06-23 03:39:48 -07:00
|
|
|
#include "nsDOMNavigationTiming.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "PerformanceEntry.h"
|
|
|
|
#include "PerformanceResourceTiming.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
#include "mozilla/dom/PerformanceBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceTimingBinding.h"
|
|
|
|
#include "mozilla/dom/PerformanceNavigationBinding.h"
|
2013-08-23 23:12:51 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-10-15 18:35:44 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2012-07-16 18:42:18 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPerformanceTiming, mPerformance)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-12-06 13:01:59 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceTiming, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceTiming, Release)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
nsPerformanceTiming::nsPerformanceTiming(nsPerformance* aPerformance,
|
2013-10-15 18:35:44 -07:00
|
|
|
nsITimedChannel* aChannel,
|
|
|
|
nsIHttpChannel* aHttpChannel,
|
|
|
|
DOMHighResTimeStamp aZeroTime)
|
2012-07-16 18:42:18 -07:00
|
|
|
: mPerformance(aPerformance),
|
2013-10-15 18:35:44 -07:00
|
|
|
mChannel(aChannel),
|
|
|
|
mFetchStart(0.0),
|
|
|
|
mZeroTime(aZeroTime),
|
|
|
|
mReportCrossOriginResources(true)
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2012-07-16 18:42:18 -07:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2013-10-15 18:35:44 -07: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 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceTiming::~nsPerformanceTiming()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::FetchStartHighRes()
|
|
|
|
{
|
|
|
|
if (!mFetchStart) {
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-10-15 18:35:44 -07: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-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07: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 06:34:33 -07:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-15 18:35:44 -07: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 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
return mReportCrossOriginResources;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
nsPerformanceTiming::GetRedirectCount() const
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bool sameOrigin;
|
|
|
|
mChannel->GetAllRedirectsSameOrigin(&sameOrigin);
|
|
|
|
if (!sameOrigin) {
|
2013-05-10 15:57:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-15 18:35:44 -07: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 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2011-07-04 09:44:00 -07:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
2013-10-15 18:35:44 -07:00
|
|
|
mChannel->GetRedirectStart(&stamp);
|
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::RedirectStart()
|
|
|
|
{
|
2014-04-21 06:34:33 -07:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return mZeroTime;
|
|
|
|
}
|
2013-10-15 18:35:44 -07: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 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-10-15 18:35:44 -07:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetRedirectEnd(&stamp);
|
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::RedirectEnd()
|
|
|
|
{
|
2014-04-21 06:34:33 -07:00
|
|
|
if (!IsInitialized()) {
|
|
|
|
return mZeroTime;
|
|
|
|
}
|
2013-10-15 18:35:44 -07: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 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2013-10-15 18:35:44 -07: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 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2011-07-04 09:44:00 -07:00
|
|
|
}
|
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetDomainLookupEnd(&stamp);
|
2013-10-15 18:35:44 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::DomainLookupEnd()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
return static_cast<int64_t>(DomainLookupEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ConnectStartHighRes()
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2011-07-04 09:44:00 -07:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectStart(&stamp);
|
2013-10-15 18:35:44 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::ConnectStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ConnectStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ConnectEndHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2011-07-04 09:44:00 -07:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetConnectEnd(&stamp);
|
2013-10-15 18:35:44 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::ConnectEnd()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ConnectEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::RequestStartHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2011-07-04 09:44:00 -07:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetRequestStart(&stamp);
|
2013-10-15 18:35:44 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::RequestStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(RequestStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ResponseStartHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2011-07-04 09:44:00 -07:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseStart(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadStart(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2013-10-15 18:35:44 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
DOMTimeMilliSec
|
2013-10-15 18:35:44 -07:00
|
|
|
nsPerformanceTiming::ResponseStart()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ResponseStartHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformanceTiming::ResponseEndHighRes()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2013-10-15 18:35:44 -07:00
|
|
|
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) {
|
2014-04-21 06:34:33 -07:00
|
|
|
return mZeroTime;
|
2013-05-10 15:57:58 -07:00
|
|
|
}
|
2011-07-04 09:44:00 -07:00
|
|
|
mozilla::TimeStamp stamp;
|
|
|
|
mChannel->GetResponseEnd(&stamp);
|
|
|
|
mozilla::TimeStamp cacheStamp;
|
|
|
|
mChannel->GetCacheReadEnd(&cacheStamp);
|
|
|
|
if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
|
|
|
|
stamp = cacheStamp;
|
|
|
|
}
|
2013-10-15 18:35:44 -07:00
|
|
|
return TimeStampToDOMHighResOrFetchStart(stamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec
|
|
|
|
nsPerformanceTiming::ResponseEnd()
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(ResponseEndHighRes());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPerformanceTiming::IsInitialized() const
|
|
|
|
{
|
|
|
|
return !!mChannel;
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
nsPerformanceTiming::WrapObject(JSContext *cx)
|
2012-07-16 18:42:18 -07: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 15:27:17 -07:00
|
|
|
return dom::PerformanceTimingBinding::Wrap(cx, this);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPerformanceNavigation, mPerformance)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-12-06 13:01:59 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsPerformanceNavigation, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsPerformanceNavigation, Release)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
nsPerformanceNavigation::nsPerformanceNavigation(nsPerformance* aPerformance)
|
|
|
|
: mPerformance(aPerformance)
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2012-07-16 18:42:18 -07:00
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformanceNavigation::~nsPerformanceNavigation()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
nsPerformanceNavigation::WrapObject(JSContext *cx)
|
2012-07-16 18:42:18 -07: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 15:27:17 -07:00
|
|
|
return dom::PerformanceNavigationBinding::Wrap(cx, this);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_5(nsPerformance,
|
2012-07-16 18:42:18 -07:00
|
|
|
mWindow, mTiming,
|
2013-10-15 18:35:44 -07:00
|
|
|
mNavigation, mEntries,
|
|
|
|
mParentPerformance)
|
2012-07-16 18:42:18 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPerformance)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPerformance)
|
2011-06-23 03:39:48 -07:00
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
nsPerformance::nsPerformance(nsIDOMWindow* aWindow,
|
|
|
|
nsDOMNavigationTiming* aDOMTiming,
|
2013-10-15 18:35:44 -07:00
|
|
|
nsITimedChannel* aChannel,
|
|
|
|
nsPerformance* aParentPerformance)
|
2012-07-16 18:42:18 -07:00
|
|
|
: mWindow(aWindow),
|
|
|
|
mDOMTiming(aDOMTiming),
|
2013-10-15 18:35:44 -07:00
|
|
|
mChannel(aChannel),
|
|
|
|
mParentPerformance(aParentPerformance),
|
|
|
|
mBufferSizeSet(kDefaultBufferSize),
|
|
|
|
mPrimaryBufferSize(kDefaultBufferSize)
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
2012-07-16 18:42:18 -07:00
|
|
|
MOZ_ASSERT(aWindow, "Parent window object should be provided");
|
|
|
|
SetIsDOMBinding();
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformance::~nsPerformance()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsPerformance
|
2012-07-16 18:42:18 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsPerformance)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-07-16 19:44:22 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2011-06-23 03:39:48 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
|
|
|
|
nsPerformanceTiming*
|
2012-09-11 12:08:24 -07:00
|
|
|
nsPerformance::Timing()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
|
|
|
if (!mTiming) {
|
2013-10-15 18:35:44 -07: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 03:39:48 -07:00
|
|
|
}
|
2012-07-16 18:42:18 -07:00
|
|
|
return mTiming;
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:42:18 -07:00
|
|
|
nsPerformanceNavigation*
|
2012-09-11 12:08:24 -07:00
|
|
|
nsPerformance::Navigation()
|
2011-06-23 03:39:48 -07:00
|
|
|
{
|
|
|
|
if (!mNavigation) {
|
2012-07-16 18:42:18 -07:00
|
|
|
mNavigation = new nsPerformanceNavigation(this);
|
2011-06-23 03:39:48 -07:00
|
|
|
}
|
2012-07-16 18:42:18 -07:00
|
|
|
return mNavigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
nsPerformance::Now()
|
|
|
|
{
|
|
|
|
return GetDOMTiming()->TimeStampToDOMHighRes(mozilla::TimeStamp::Now());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
nsPerformance::WrapObject(JSContext *cx)
|
2012-07-16 18:42:18 -07: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 15:27:17 -07:00
|
|
|
return dom::PerformanceBinding::Wrap(cx, this);
|
2012-07-16 18:42:18 -07:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:35:44 -07:00
|
|
|
void
|
|
|
|
nsPerformance::GetEntries(nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
retval.Clear();
|
|
|
|
uint32_t count = mEntries.Length();
|
|
|
|
if (count > mPrimaryBufferSize) {
|
|
|
|
count = mPrimaryBufferSize;
|
|
|
|
}
|
|
|
|
retval.AppendElements(mEntries.Elements(), count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::GetEntriesByType(const nsAString& entryType,
|
|
|
|
nsTArray<nsRefPtr<PerformanceEntry> >& retval)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
retval.Clear();
|
|
|
|
uint32_t count = mEntries.Length();
|
|
|
|
for (uint32_t i = 0 ; i < count && i < mPrimaryBufferSize ; i++) {
|
|
|
|
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();
|
|
|
|
for (uint32_t i = 0 ; i < count && i < mPrimaryBufferSize ; i++) {
|
|
|
|
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());
|
|
|
|
mPrimaryBufferSize = mBufferSizeSet;
|
|
|
|
mEntries.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPerformance::SetResourceTimingBufferSize(uint64_t maxSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mBufferSizeSet = maxSize;
|
|
|
|
if (mBufferSizeSet < mEntries.Length()) {
|
|
|
|
// call onresourcetimingbufferfull
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=936813
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
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());
|
|
|
|
if (mEntries.Length() > mPrimaryBufferSize) {
|
|
|
|
// call onresourcetimingbufferfull
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=936813
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|