Commit b0aabd4f authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by Commit Bot

[ElementTiming] Change |name| and add |url| to PerformanceElementTiming

This CL makes the implementation match the changes in the explainer:
https://github.com/WICG/element-timing. In particular, name is now set
to "image-paint" for image entries, and url is added.

Bug: 879270
Change-Id: Id02e5305ac1e9bf9fa1fc18efe63d8cc280c5f4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635733Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665930}
parent 319747c3
...@@ -109,7 +109,7 @@ void ImageElementTiming::NotifyImagePaintedInternal( ...@@ -109,7 +109,7 @@ void ImageElementTiming::NotifyImagePaintedInternal(
performance->ShouldBufferEntries())) { performance->ShouldBufferEntries())) {
// Create an entry with a |startTime| of 0. // Create an entry with a |startTime| of 0.
performance->AddElementTiming( performance->AddElementTiming(
AtomicString(url.GetString()), intersection_rect, TimeTicks(), url.GetString(), intersection_rect, TimeTicks(),
cached_image.LoadResponseEnd(), attr, cached_image.LoadResponseEnd(), attr,
cached_image.IntrinsicSize(kDoNotRespectImageOrientation), id, cached_image.IntrinsicSize(kDoNotRespectImageOrientation), id,
element); element);
...@@ -121,12 +121,11 @@ void ImageElementTiming::NotifyImagePaintedInternal( ...@@ -121,12 +121,11 @@ void ImageElementTiming::NotifyImagePaintedInternal(
// PerformanceElementTiming entry should be the URL trimmed to 100 characters. // PerformanceElementTiming entry should be the URL trimmed to 100 characters.
// If it is not, then pass in the full URL regardless of the length to be // If it is not, then pass in the full URL regardless of the length to be
// consistent with Resource Timing. // consistent with Resource Timing.
const String& image_name = url.ProtocolIsData() const String& image_url = url.ProtocolIsData()
? url.GetString().Left(kInlineImageMaxChars) ? url.GetString().Left(kInlineImageMaxChars)
: url.GetString(); : url.GetString();
element_timings_.emplace_back(MakeGarbageCollected<ElementTimingInfo>( element_timings_.emplace_back(MakeGarbageCollected<ElementTimingInfo>(
AtomicString(image_name), intersection_rect, image_url, intersection_rect, cached_image.LoadResponseEnd(), attr,
cached_image.LoadResponseEnd(), attr,
cached_image.IntrinsicSize(kDoNotRespectImageOrientation), id, element)); cached_image.IntrinsicSize(kDoNotRespectImageOrientation), id, element));
// Only queue a swap promise when |element_timings_| was empty. All of the // Only queue a swap promise when |element_timings_| was empty. All of the
// records in |element_timings_| will be processed when the promise succeeds // records in |element_timings_| will be processed when the promise succeeds
...@@ -201,7 +200,7 @@ void ImageElementTiming::ReportImagePaintSwapTime(WebWidgetClient::SwapResult, ...@@ -201,7 +200,7 @@ void ImageElementTiming::ReportImagePaintSwapTime(WebWidgetClient::SwapResult,
performance->ShouldBufferEntries())) { performance->ShouldBufferEntries())) {
for (const auto& element_timing : element_timings_) { for (const auto& element_timing : element_timings_) {
performance->AddElementTiming( performance->AddElementTiming(
element_timing->name, element_timing->rect, timestamp, element_timing->url, element_timing->rect, timestamp,
element_timing->response_end, element_timing->identifier, element_timing->response_end, element_timing->identifier,
element_timing->intrinsic_size, element_timing->id, element_timing->intrinsic_size, element_timing->id,
element_timing->element); element_timing->element);
......
...@@ -82,14 +82,14 @@ class CORE_EXPORT ImageElementTiming final ...@@ -82,14 +82,14 @@ class CORE_EXPORT ImageElementTiming final
class ElementTimingInfo class ElementTimingInfo
: public GarbageCollectedFinalized<ElementTimingInfo> { : public GarbageCollectedFinalized<ElementTimingInfo> {
public: public:
ElementTimingInfo(const AtomicString& name, ElementTimingInfo(const String& url,
const FloatRect& rect, const FloatRect& rect,
const TimeTicks& response_end, const TimeTicks& response_end,
const AtomicString& identifier, const AtomicString& identifier,
const IntSize& intrinsic_size, const IntSize& intrinsic_size,
const AtomicString& id, const AtomicString& id,
Element* element) Element* element)
: name(name), : url(url),
rect(rect), rect(rect),
response_end(response_end), response_end(response_end),
identifier(identifier), identifier(identifier),
...@@ -100,7 +100,7 @@ class CORE_EXPORT ImageElementTiming final ...@@ -100,7 +100,7 @@ class CORE_EXPORT ImageElementTiming final
void Trace(blink::Visitor* visitor) { visitor->Trace(element); } void Trace(blink::Visitor* visitor) { visitor->Trace(element); }
AtomicString name; String url;
FloatRect rect; FloatRect rect;
TimeTicks response_end; TimeTicks response_end;
AtomicString identifier; AtomicString identifier;
......
...@@ -11,7 +11,7 @@ namespace blink { ...@@ -11,7 +11,7 @@ namespace blink {
// static // static
PerformanceElementTiming* PerformanceElementTiming::Create( PerformanceElementTiming* PerformanceElementTiming::Create(
const AtomicString& name, const String& url,
const FloatRect& intersection_rect, const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time, DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end, DOMHighResTimeStamp response_end,
...@@ -26,12 +26,12 @@ PerformanceElementTiming* PerformanceElementTiming::Create( ...@@ -26,12 +26,12 @@ PerformanceElementTiming* PerformanceElementTiming::Create(
DCHECK_GE(naturalHeight, 0); DCHECK_GE(naturalHeight, 0);
DCHECK(element); DCHECK(element);
return MakeGarbageCollected<PerformanceElementTiming>( return MakeGarbageCollected<PerformanceElementTiming>(
name, intersection_rect, start_time, response_end, identifier, url, intersection_rect, start_time, response_end, identifier,
naturalWidth, naturalHeight, id, element); naturalWidth, naturalHeight, id, element);
} }
PerformanceElementTiming::PerformanceElementTiming( PerformanceElementTiming::PerformanceElementTiming(
const AtomicString& name, const String& url,
const FloatRect& intersection_rect, const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time, DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end, DOMHighResTimeStamp response_end,
...@@ -40,14 +40,15 @@ PerformanceElementTiming::PerformanceElementTiming( ...@@ -40,14 +40,15 @@ PerformanceElementTiming::PerformanceElementTiming(
int naturalHeight, int naturalHeight,
const AtomicString& id, const AtomicString& id,
Element* element) Element* element)
: PerformanceEntry(name, start_time, start_time), : PerformanceEntry("image-paint", start_time, start_time),
element_(element), element_(element),
intersection_rect_(DOMRectReadOnly::FromFloatRect(intersection_rect)), intersection_rect_(DOMRectReadOnly::FromFloatRect(intersection_rect)),
response_end_(response_end), response_end_(response_end),
identifier_(identifier), identifier_(identifier),
naturalWidth_(naturalWidth), naturalWidth_(naturalWidth),
naturalHeight_(naturalHeight), naturalHeight_(naturalHeight),
id_(id) {} id_(id),
url_(url) {}
PerformanceElementTiming::~PerformanceElementTiming() = default; PerformanceElementTiming::~PerformanceElementTiming() = default;
......
...@@ -21,7 +21,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry { ...@@ -21,7 +21,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static PerformanceElementTiming* Create(const AtomicString& name, static PerformanceElementTiming* Create(const String& url,
const FloatRect& intersection_rect, const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time, DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end, DOMHighResTimeStamp response_end,
...@@ -30,7 +30,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry { ...@@ -30,7 +30,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
int naturalHeight, int naturalHeight,
const AtomicString& id, const AtomicString& id,
Element*); Element*);
PerformanceElementTiming(const AtomicString& name, PerformanceElementTiming(const String& url,
const FloatRect& intersection_rect, const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time, DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end, DOMHighResTimeStamp response_end,
...@@ -57,6 +57,8 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry { ...@@ -57,6 +57,8 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
AtomicString id() const { return id_; } AtomicString id() const { return id_; }
String url() const { return url_; }
Element* element() const; Element* element() const;
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
...@@ -71,6 +73,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry { ...@@ -71,6 +73,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
unsigned naturalWidth_; unsigned naturalWidth_;
unsigned naturalHeight_; unsigned naturalHeight_;
AtomicString id_; AtomicString id_;
String url_;
}; };
} // namespace blink } // namespace blink
......
...@@ -12,6 +12,7 @@ interface PerformanceElementTiming : PerformanceEntry { ...@@ -12,6 +12,7 @@ interface PerformanceElementTiming : PerformanceEntry {
readonly attribute unsigned long naturalHeight; readonly attribute unsigned long naturalHeight;
readonly attribute DOMString id; readonly attribute DOMString id;
readonly attribute Element? element; readonly attribute Element? element;
readonly attribute DOMString url;
// TODO(peria): toJSON is not in spec. https://crbug.com/736332 // TODO(peria): toJSON is not in spec. https://crbug.com/736332
[CallWith=ScriptState, ImplementedAs=toJSONForBinding] object toJSON(); [CallWith=ScriptState, ImplementedAs=toJSONForBinding] object toJSON();
......
...@@ -392,7 +392,7 @@ void WindowPerformance::ReportEventTimings(WebWidgetClient::SwapResult result, ...@@ -392,7 +392,7 @@ void WindowPerformance::ReportEventTimings(WebWidgetClient::SwapResult result,
event_timings_.clear(); event_timings_.clear();
} }
void WindowPerformance::AddElementTiming(const AtomicString& name, void WindowPerformance::AddElementTiming(const String& url,
const FloatRect& rect, const FloatRect& rect,
TimeTicks start_time, TimeTicks start_time,
TimeTicks response_end, TimeTicks response_end,
...@@ -402,7 +402,7 @@ void WindowPerformance::AddElementTiming(const AtomicString& name, ...@@ -402,7 +402,7 @@ void WindowPerformance::AddElementTiming(const AtomicString& name,
Element* element) { Element* element) {
DCHECK(RuntimeEnabledFeatures::ElementTimingEnabled(GetExecutionContext())); DCHECK(RuntimeEnabledFeatures::ElementTimingEnabled(GetExecutionContext()));
PerformanceElementTiming* entry = PerformanceElementTiming::Create( PerformanceElementTiming* entry = PerformanceElementTiming::Create(
name, rect, MonotonicTimeToDOMHighResTimeStamp(start_time), url, rect, MonotonicTimeToDOMHighResTimeStamp(start_time),
MonotonicTimeToDOMHighResTimeStamp(response_end), identifier, MonotonicTimeToDOMHighResTimeStamp(response_end), identifier,
intrinsic_size.Width(), intrinsic_size.Height(), id, element); intrinsic_size.Width(), intrinsic_size.Height(), id, element);
if (HasObserverFor(PerformanceEntry::kElement)) { if (HasObserverFor(PerformanceEntry::kElement)) {
......
...@@ -76,7 +76,7 @@ class CORE_EXPORT WindowPerformance final : public Performance, ...@@ -76,7 +76,7 @@ class CORE_EXPORT WindowPerformance final : public Performance,
TimeTicks processing_end, TimeTicks processing_end,
bool cancelable); bool cancelable);
void AddElementTiming(const AtomicString& name, void AddElementTiming(const String& url,
const FloatRect& rect, const FloatRect& rect,
TimeTicks start_time, TimeTicks start_time,
TimeTicks response_end, TimeTicks response_end,
......
...@@ -31,20 +31,20 @@ body { ...@@ -31,20 +31,20 @@ body {
t.step_func(entryList => { t.step_func(entryList => {
entryList.getEntries().forEach(entry => { entryList.getEntries().forEach(entry => {
numObservedElements++; numObservedElements++;
if (entry.name.endsWith('square100.png')) { if (entry.url.endsWith('square100.png')) {
observedSquare = true; observedSquare = true;
checkElement(entry, pathname + 'square100.png', 'multi', 'target', beforeRender, div); checkElement(entry, pathname + 'square100.png', 'multi', 'target', beforeRender, div);
checkRect(entry, [0, 200, 0, 200]); checkRect(entry, [0, 200, 0, 200]);
checkNaturalSize(entry, 100, 100); checkNaturalSize(entry, 100, 100);
} }
else if (entry.name.endsWith('circle.svg')) { else if (entry.url.endsWith('circle.svg')) {
observedCircle = true; observedCircle = true;
checkElement(entry, pathname + 'circle.svg', 'multi', 'target', beforeRender, div); checkElement(entry, pathname + 'circle.svg', 'multi', 'target', beforeRender, div);
checkRect(entry, [0, 200, 0, 200]); checkRect(entry, [0, 200, 0, 200]);
checkNaturalSize(entry, 200, 200); checkNaturalSize(entry, 200, 200);
} }
else { else {
assert_unreached("Should not have observed an entry with different name!"); assert_unreached("Should not have observed an entry with different url!");
} }
if (numObservedElements === 2) { if (numObservedElements === 2) {
assert_true(observedCircle); assert_true(observedCircle);
......
// Common checks between checkElement() and checkElementWithoutResourceTiming(). // Common checks between checkElement() and checkElementWithoutResourceTiming().
function checkElementInternal(entry, expectedName, expectedIdentifier, expectedID, beforeRender, function checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement) { expectedElement) {
assert_equals(entry.entryType, 'element'); assert_equals(entry.entryType, 'element');
assert_equals(entry.name, expectedName); assert_equals(entry.name, 'image-paint');
assert_equals(entry.url, expectedUrl);
assert_equals(entry.identifier, expectedIdentifier); assert_equals(entry.identifier, expectedIdentifier);
assert_equals(entry.duration, 0); assert_equals(entry.duration, 0);
assert_equals(entry.id, expectedID); assert_equals(entry.id, expectedID);
...@@ -12,20 +13,20 @@ function checkElementInternal(entry, expectedName, expectedIdentifier, expectedI ...@@ -12,20 +13,20 @@ function checkElementInternal(entry, expectedName, expectedIdentifier, expectedI
assert_equals(entry.element, expectedElement); assert_equals(entry.element, expectedElement);
} }
// Checks that this is an ElementTiming entry with name |expectedName|. It also // Checks that this is an ElementTiming entry with url |expectedUrl|. It also
// does a very basic check on |startTime|: after |beforeRender| and before now(). // does a very basic check on |startTime|: after |beforeRender| and before now().
function checkElement(entry, expectedName, expectedIdentifier, expectedID, beforeRender, function checkElement(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement) { expectedElement) {
checkElementInternal(entry, expectedName, expectedIdentifier, expectedID, beforeRender, checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement); expectedElement);
const rt_entries = performance.getEntriesByName(expectedName, 'resource'); const rt_entries = performance.getEntriesByName(expectedUrl, 'resource');
assert_equals(rt_entries.length, 1); assert_equals(rt_entries.length, 1);
assert_equals(rt_entries[0].responseEnd, entry.responseEnd); assert_equals(rt_entries[0].responseEnd, entry.responseEnd);
} }
function checkElementWithoutResourceTiming(entry, expectedName, expectedIdentifier, function checkElementWithoutResourceTiming(entry, expectedUrl, expectedIdentifier,
expectedID, beforeRender, expectedElement) { expectedID, beforeRender, expectedElement) {
checkElementInternal(entry, expectedName, expectedIdentifier, expectedID, beforeRender, checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement); expectedElement);
// No associated resource from ResourceTiming, so the responseEnd should be 0. // No associated resource from ResourceTiming, so the responseEnd should be 0.
assert_equals(entry.responseEnd, 0); assert_equals(entry.responseEnd, 0);
......
...@@ -5377,6 +5377,7 @@ interface PerformanceElementTiming : PerformanceEntry ...@@ -5377,6 +5377,7 @@ interface PerformanceElementTiming : PerformanceEntry
getter naturalHeight getter naturalHeight
getter naturalWidth getter naturalWidth
getter responseEnd getter responseEnd
getter url
method constructor method constructor
method toJSON method toJSON
interface PerformanceEntry interface PerformanceEntry
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment