зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1423495 - Part 1: Implement PerformanceServerTiming. r=baku
This patch includes: 1. Introduce PerformanceServerTiming.webidl. 2. Add serverTiming in PerformanceResourceTiming.webidl. 3. Get serverTiming data from nsITimedChannel and keep it in PerformanceTimng class. 4. Add PerformanceServerTiming to test_interfaces.js.
This commit is contained in:
Родитель
b282ac3a3f
Коммит
dfd9fce569
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "PerformanceResourceTiming.h"
|
||||
#include "mozilla/dom/PerformanceResourceTimingBinding.h"
|
||||
#include "nsArrayUtils.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
|
@ -108,3 +109,29 @@ PerformanceResourceTiming::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSize
|
|||
mInitiatorType.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
||||
mNextHopProtocol.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
}
|
||||
|
||||
void
|
||||
PerformanceResourceTiming::GetServerTiming(
|
||||
nsTArray<RefPtr<PerformanceServerTiming>>& aRetval)
|
||||
{
|
||||
aRetval.Clear();
|
||||
|
||||
nsCOMPtr<nsIArray> serverTimingArray = mTiming->GetServerTiming();
|
||||
if (!serverTimingArray) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t length = 0;
|
||||
if (NS_FAILED(serverTimingArray->GetLength(&length))) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < length; ++index) {
|
||||
nsCOMPtr<nsIServerTiming> serverTiming =
|
||||
do_QueryElementAt(serverTimingArray, index);
|
||||
MOZ_ASSERT(serverTiming);
|
||||
|
||||
aRetval.AppendElement(
|
||||
new PerformanceServerTiming(GetParentObject(), serverTiming));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "nsITimedChannel.h"
|
||||
#include "Performance.h"
|
||||
#include "PerformanceEntry.h"
|
||||
#include "PerformanceServerTiming.h"
|
||||
#include "PerformanceTiming.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -178,6 +179,8 @@ public:
|
|||
size_t
|
||||
SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
|
||||
|
||||
void GetServerTiming(nsTArray<RefPtr<PerformanceServerTiming>>& aRetval);
|
||||
|
||||
protected:
|
||||
virtual ~PerformanceResourceTiming();
|
||||
void SetPropertiesFromChannel(nsIHttpChannel* aChannel);
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "PerformanceServerTiming.h"
|
||||
|
||||
#include "mozilla/dom/PerformanceServerTimingBinding.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsITimedChannel.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PerformanceServerTiming, mParent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(PerformanceServerTiming)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(PerformanceServerTiming)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceServerTiming)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
JSObject*
|
||||
PerformanceServerTiming::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return mozilla::dom::PerformanceServerTimingBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
void
|
||||
PerformanceServerTiming::GetName(nsAString& aName) const
|
||||
{
|
||||
if (!mServerTiming) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString name;
|
||||
Unused << mServerTiming->GetName(name);
|
||||
aName.Assign(NS_ConvertUTF8toUTF16(name));
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp
|
||||
PerformanceServerTiming::Duration() const
|
||||
{
|
||||
if (!mServerTiming) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double duration = 0;
|
||||
Unused << mServerTiming->GetDuration(&duration);
|
||||
return duration;
|
||||
}
|
||||
|
||||
void
|
||||
PerformanceServerTiming::GetDescription(nsAString& aDescription) const
|
||||
{
|
||||
if (!mServerTiming) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString description;
|
||||
Unused << mServerTiming->GetDescription(description);
|
||||
aDescription.Assign(NS_ConvertUTF8toUTF16(description));
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_PerformanceServerTiming_h
|
||||
#define mozilla_dom_PerformanceServerTiming_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIServerTiming;
|
||||
class nsISupports;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class PerformanceServerTiming final : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
PerformanceServerTiming(nsISupports* aParent, nsIServerTiming* aServerTiming)
|
||||
: mParent(aParent)
|
||||
, mServerTiming(aServerTiming)
|
||||
{
|
||||
MOZ_ASSERT(mServerTiming);
|
||||
}
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PerformanceServerTiming)
|
||||
|
||||
JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
nsISupports* GetParentObject() const
|
||||
{
|
||||
return mParent;
|
||||
}
|
||||
|
||||
void GetName(nsAString& aName) const;
|
||||
|
||||
DOMHighResTimeStamp Duration() const;
|
||||
|
||||
void GetDescription(nsAString& aDescription) const;
|
||||
|
||||
private:
|
||||
~PerformanceServerTiming() = default;
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
nsCOMPtr<nsIServerTiming> mServerTiming;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_PerformanceServerTiming_h
|
|
@ -109,6 +109,8 @@ PerformanceTiming::InitializeTimingInfo(nsITimedChannel* aChannel)
|
|||
// ServiceWorker interception responseStart?
|
||||
aChannel->GetHandleFetchEventEnd(&mWorkerResponseEnd);
|
||||
|
||||
aChannel->GetServerTiming(getter_AddRefs(mServerTiming));
|
||||
|
||||
// The performance timing api essentially requires that the event timestamps
|
||||
// have a strict relation with each other. The truth, however, is the browser
|
||||
// engages in a number of speculative activities that sometimes mean connections
|
||||
|
@ -520,5 +522,17 @@ PerformanceTiming::IsTopLevelContentDocument() const
|
|||
return rootItem->ItemType() == nsIDocShellTreeItem::typeContent;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIArray>
|
||||
PerformanceTiming::GetServerTiming() const
|
||||
{
|
||||
if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized() ||
|
||||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIArray> serverTiming = mServerTiming;
|
||||
return serverTiming.forget();
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
|
|
@ -260,6 +260,8 @@ public:
|
|||
return GetDOMTiming()->GetTimeToNonBlankPaint();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIArray> GetServerTiming() const;
|
||||
|
||||
private:
|
||||
~PerformanceTiming();
|
||||
|
||||
|
@ -307,6 +309,7 @@ private:
|
|||
bool mReportCrossOriginRedirect;
|
||||
|
||||
bool mSecureConnection;
|
||||
nsCOMPtr<nsIArray> mServerTiming;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -17,6 +17,7 @@ EXPORTS.mozilla.dom += [
|
|||
'PerformanceObserver.h',
|
||||
'PerformanceObserverEntryList.h',
|
||||
'PerformanceResourceTiming.h',
|
||||
'PerformanceServerTiming.h',
|
||||
'PerformanceService.h',
|
||||
'PerformanceTiming.h',
|
||||
]
|
||||
|
@ -32,6 +33,7 @@ UNIFIED_SOURCES += [
|
|||
'PerformanceObserver.cpp',
|
||||
'PerformanceObserverEntryList.cpp',
|
||||
'PerformanceResourceTiming.cpp',
|
||||
'PerformanceServerTiming.cpp',
|
||||
'PerformanceService.cpp',
|
||||
'PerformanceTiming.cpp',
|
||||
'PerformanceWorker.cpp',
|
||||
|
|
|
@ -732,6 +732,8 @@ var interfaceNamesInGlobalScope =
|
|||
"PerformanceObserverEntryList",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"PerformanceResourceTiming",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"PerformanceServerTiming",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"PerformanceTiming",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
|
@ -32,5 +32,10 @@ interface PerformanceResourceTiming : PerformanceEntry
|
|||
readonly attribute unsigned long long encodedBodySize;
|
||||
readonly attribute unsigned long long decodedBodySize;
|
||||
|
||||
// TODO: Use FrozenArray once available. (Bug 1236777)
|
||||
// readonly attribute FrozenArray<PerformanceServerTiming> serverTiming;
|
||||
[Frozen, Cached, Pure]
|
||||
readonly attribute sequence<PerformanceServerTiming> serverTiming;
|
||||
|
||||
jsonifier;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* https://w3c.github.io/server-timing/
|
||||
*
|
||||
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
interface PerformanceServerTiming {
|
||||
readonly attribute DOMString name;
|
||||
readonly attribute DOMHighResTimeStamp duration;
|
||||
readonly attribute DOMString description;
|
||||
|
||||
jsonifier;
|
||||
};
|
|
@ -725,6 +725,7 @@ WEBIDL_FILES = [
|
|||
'PerformanceObserver.webidl',
|
||||
'PerformanceObserverEntryList.webidl',
|
||||
'PerformanceResourceTiming.webidl',
|
||||
'PerformanceServerTiming.webidl',
|
||||
'PerformanceTiming.webidl',
|
||||
'PeriodicWave.webidl',
|
||||
'Permissions.webidl',
|
||||
|
|
|
@ -188,6 +188,8 @@ var interfaceNamesInGlobalScope =
|
|||
"PerformanceObserver",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"PerformanceObserverEntryList",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"PerformanceServerTiming",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"ProgressEvent",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
|
@ -182,6 +182,8 @@ var interfaceNamesInGlobalScope =
|
|||
"PerformanceObserver",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"PerformanceObserverEntryList",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"PerformanceServerTiming",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"ProgressEvent",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
Загрузка…
Ссылка в новой задаче