зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1830794 - Add the WebIDL support for LargestContentfulPaint r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D167816
This commit is contained in:
Родитель
4dfac443d7
Коммит
cbc6a366eb
|
@ -2695,7 +2695,7 @@ nsINode* nsContentUtils::Retarget(nsINode* aTargetA, nsINode* aTargetB) {
|
|||
}
|
||||
|
||||
// static
|
||||
nsINode* nsContentUtils::GetAnElementForTiming(Element* aTarget,
|
||||
Element* nsContentUtils::GetAnElementForTiming(Element* aTarget,
|
||||
const Document* aDocument,
|
||||
nsIGlobalObject* aGlobal) {
|
||||
if (!aTarget->IsInComposedDoc()) {
|
||||
|
|
|
@ -460,7 +460,7 @@ class nsContentUtils {
|
|||
/**
|
||||
* @see https://wicg.github.io/element-timing/#get-an-element
|
||||
*/
|
||||
static nsINode* GetAnElementForTiming(Element* aTarget,
|
||||
static Element* GetAnElementForTiming(Element* aTarget,
|
||||
const Document* aDocument,
|
||||
nsIGlobalObject* aGlobal);
|
||||
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/* -*- 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 "mozilla/dom/Element.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsRFPService.h"
|
||||
#include "Performance.h"
|
||||
#include "PerformanceMainThread.h"
|
||||
#include "LargestContentfulPaint.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(LargestContentfulPaint, PerformanceEntry,
|
||||
mPerformance, mURI, mElement)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(LargestContentfulPaint)
|
||||
NS_INTERFACE_MAP_END_INHERITING(PerformanceEntry)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(LargestContentfulPaint, PerformanceEntry)
|
||||
NS_IMPL_RELEASE_INHERITED(LargestContentfulPaint, PerformanceEntry)
|
||||
|
||||
LargestContentfulPaint::LargestContentfulPaint(Performance* aPerformance,
|
||||
DOMHighResTimeStamp aRenderTime,
|
||||
DOMHighResTimeStamp aLoadTime,
|
||||
unsigned long aSize,
|
||||
nsIURI* aURI, Element* aElement)
|
||||
: PerformanceEntry(aPerformance->GetParentObject(), u""_ns,
|
||||
kLargestContentfulPaintName),
|
||||
mPerformance(static_cast<PerformanceMainThread*>(aPerformance)),
|
||||
mRenderTime(aRenderTime),
|
||||
mLoadTime(aLoadTime),
|
||||
mSize(aSize),
|
||||
mURI(aURI),
|
||||
mElement(aElement) {
|
||||
MOZ_ASSERT(mPerformance);
|
||||
MOZ_ASSERT(mElement);
|
||||
// The element could be a pseudo-element
|
||||
if (mElement->ChromeOnlyAccess()) {
|
||||
mElement = Element::FromNodeOrNull(
|
||||
aElement->FindFirstNonChromeOnlyAccessContent());
|
||||
}
|
||||
|
||||
if (const Element* element = GetElement()) {
|
||||
mId = element->GetID();
|
||||
}
|
||||
}
|
||||
|
||||
JSObject* LargestContentfulPaint::WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
||||
return LargestContentfulPaint_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
Element* LargestContentfulPaint::GetElement() const {
|
||||
return mElement ? nsContentUtils::GetAnElementForTiming(
|
||||
mElement, mElement->GetComposedDoc(), nullptr)
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp LargestContentfulPaint::RenderTime() const {
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
mRenderTime, mPerformance->GetRandomTimelineSeed(),
|
||||
mPerformance->GetRTPCallerType());
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp LargestContentfulPaint::LoadTime() const {
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
mLoadTime, mPerformance->GetRandomTimelineSeed(),
|
||||
mPerformance->GetRTPCallerType());
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp LargestContentfulPaint::StartTime() const {
|
||||
DOMHighResTimeStamp startTime = !mRenderTime ? mLoadTime : mRenderTime;
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
startTime, mPerformance->GetRandomTimelineSeed(),
|
||||
mPerformance->GetRTPCallerType());
|
||||
}
|
||||
|
||||
void LargestContentfulPaint::GetUrl(nsAString& aUrl) {
|
||||
if (mURI) {
|
||||
CopyUTF8toUTF16(mURI->GetSpecOrDefault(), aUrl);
|
||||
}
|
||||
}
|
||||
} // namespace mozilla::dom
|
|
@ -0,0 +1,68 @@
|
|||
/* -*- 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_LargestContentfulPaint_h___
|
||||
#define mozilla_dom_LargestContentfulPaint_h___
|
||||
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/dom/PerformanceEntry.h"
|
||||
#include "mozilla/dom/PerformanceLargestContentfulPaintBinding.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
|
||||
class nsTextFrame;
|
||||
namespace mozilla::dom {
|
||||
|
||||
static constexpr nsLiteralString kLargestContentfulPaintName =
|
||||
u"largest-contentful-paint"_ns;
|
||||
|
||||
class Performance;
|
||||
class PerformanceMainThread;
|
||||
|
||||
// https://w3c.github.io/largest-contentful-paint/
|
||||
class LargestContentfulPaint final : public PerformanceEntry {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LargestContentfulPaint,
|
||||
PerformanceEntry)
|
||||
|
||||
LargestContentfulPaint(Performance* aPerformance,
|
||||
DOMHighResTimeStamp aRenderTime,
|
||||
DOMHighResTimeStamp aLoadTime, unsigned long aSize,
|
||||
nsIURI* aURI, Element* aElement);
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
DOMHighResTimeStamp RenderTime() const;
|
||||
DOMHighResTimeStamp LoadTime() const;
|
||||
DOMHighResTimeStamp StartTime() const override;
|
||||
|
||||
unsigned long Size() const { return mSize; }
|
||||
void GetId(nsAString& aId) const {
|
||||
if (mId) {
|
||||
mId->ToString(aId);
|
||||
}
|
||||
}
|
||||
void GetUrl(nsAString& aUrl);
|
||||
|
||||
Element* GetElement() const;
|
||||
|
||||
private:
|
||||
~LargestContentfulPaint() = default;
|
||||
|
||||
RefPtr<PerformanceMainThread> mPerformance;
|
||||
|
||||
DOMHighResTimeStamp mRenderTime;
|
||||
DOMHighResTimeStamp mLoadTime;
|
||||
unsigned long mSize;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
|
||||
RefPtr<Element> mElement;
|
||||
RefPtr<nsAtom> mId;
|
||||
};
|
||||
} // namespace mozilla::dom
|
||||
#endif
|
|
@ -9,6 +9,7 @@ with Files("**"):
|
|||
|
||||
EXPORTS.mozilla.dom += [
|
||||
"EventCounts.h",
|
||||
"LargestContentfulPaint.h",
|
||||
"Performance.h",
|
||||
"PerformanceEntry.h",
|
||||
"PerformanceEventTiming.h",
|
||||
|
@ -31,6 +32,7 @@ EXPORTS.mozilla.dom += [
|
|||
|
||||
UNIFIED_SOURCES += [
|
||||
"EventCounts.cpp",
|
||||
"LargestContentfulPaint.cpp",
|
||||
"Performance.cpp",
|
||||
"PerformanceEntry.cpp",
|
||||
"PerformanceEventTiming.cpp",
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/* -*- 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/largest-contentful-paint/
|
||||
*
|
||||
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
[Pref="dom.enable_largest_contentful_paint",
|
||||
Exposed=Window]
|
||||
interface LargestContentfulPaint : PerformanceEntry {
|
||||
readonly attribute DOMHighResTimeStamp renderTime;
|
||||
readonly attribute DOMHighResTimeStamp loadTime;
|
||||
readonly attribute unsigned long size;
|
||||
readonly attribute DOMString id;
|
||||
readonly attribute DOMString url;
|
||||
readonly attribute Element? element;
|
||||
[Default] object toJSON();
|
||||
};
|
|
@ -776,6 +776,7 @@ WEBIDL_FILES = [
|
|||
"Performance.webidl",
|
||||
"PerformanceEntry.webidl",
|
||||
"PerformanceEventTiming.webidl",
|
||||
"PerformanceLargestContentfulPaint.webidl",
|
||||
"PerformanceMark.webidl",
|
||||
"PerformanceMeasure.webidl",
|
||||
"PerformanceNavigation.webidl",
|
||||
|
|
|
@ -2484,6 +2484,12 @@
|
|||
value: true
|
||||
mirror: always
|
||||
|
||||
# Whether the LargestContentfulPaint API will be gathered and returned by performance observer*
|
||||
- name: dom.enable_largest_contentful_paint
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether performance.GetEntries* will contain an entry for the active document
|
||||
- name: dom.enable_performance_navigation_timing
|
||||
type: bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче