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(
performance->ShouldBufferEntries())) {
// Create an entry with a |startTime| of 0.
performance->AddElementTiming(
AtomicString(url.GetString()), intersection_rect, TimeTicks(),
url.GetString(), intersection_rect, TimeTicks(),
cached_image.LoadResponseEnd(), attr,
cached_image.IntrinsicSize(kDoNotRespectImageOrientation), id,
element);
......@@ -121,12 +121,11 @@ void ImageElementTiming::NotifyImagePaintedInternal(
// 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
// consistent with Resource Timing.
const String& image_name = url.ProtocolIsData()
? url.GetString().Left(kInlineImageMaxChars)
: url.GetString();
const String& image_url = url.ProtocolIsData()
? url.GetString().Left(kInlineImageMaxChars)
: url.GetString();
element_timings_.emplace_back(MakeGarbageCollected<ElementTimingInfo>(
AtomicString(image_name), intersection_rect,
cached_image.LoadResponseEnd(), attr,
image_url, intersection_rect, cached_image.LoadResponseEnd(), attr,
cached_image.IntrinsicSize(kDoNotRespectImageOrientation), id, element));
// Only queue a swap promise when |element_timings_| was empty. All of the
// records in |element_timings_| will be processed when the promise succeeds
......@@ -201,7 +200,7 @@ void ImageElementTiming::ReportImagePaintSwapTime(WebWidgetClient::SwapResult,
performance->ShouldBufferEntries())) {
for (const auto& element_timing : element_timings_) {
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->intrinsic_size, element_timing->id,
element_timing->element);
......
......@@ -82,14 +82,14 @@ class CORE_EXPORT ImageElementTiming final
class ElementTimingInfo
: public GarbageCollectedFinalized<ElementTimingInfo> {
public:
ElementTimingInfo(const AtomicString& name,
ElementTimingInfo(const String& url,
const FloatRect& rect,
const TimeTicks& response_end,
const AtomicString& identifier,
const IntSize& intrinsic_size,
const AtomicString& id,
Element* element)
: name(name),
: url(url),
rect(rect),
response_end(response_end),
identifier(identifier),
......@@ -100,7 +100,7 @@ class CORE_EXPORT ImageElementTiming final
void Trace(blink::Visitor* visitor) { visitor->Trace(element); }
AtomicString name;
String url;
FloatRect rect;
TimeTicks response_end;
AtomicString identifier;
......
......@@ -11,7 +11,7 @@ namespace blink {
// static
PerformanceElementTiming* PerformanceElementTiming::Create(
const AtomicString& name,
const String& url,
const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end,
......@@ -26,12 +26,12 @@ PerformanceElementTiming* PerformanceElementTiming::Create(
DCHECK_GE(naturalHeight, 0);
DCHECK(element);
return MakeGarbageCollected<PerformanceElementTiming>(
name, intersection_rect, start_time, response_end, identifier,
url, intersection_rect, start_time, response_end, identifier,
naturalWidth, naturalHeight, id, element);
}
PerformanceElementTiming::PerformanceElementTiming(
const AtomicString& name,
const String& url,
const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end,
......@@ -40,14 +40,15 @@ PerformanceElementTiming::PerformanceElementTiming(
int naturalHeight,
const AtomicString& id,
Element* element)
: PerformanceEntry(name, start_time, start_time),
: PerformanceEntry("image-paint", start_time, start_time),
element_(element),
intersection_rect_(DOMRectReadOnly::FromFloatRect(intersection_rect)),
response_end_(response_end),
identifier_(identifier),
naturalWidth_(naturalWidth),
naturalHeight_(naturalHeight),
id_(id) {}
id_(id),
url_(url) {}
PerformanceElementTiming::~PerformanceElementTiming() = default;
......
......@@ -21,7 +21,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
DEFINE_WRAPPERTYPEINFO();
public:
static PerformanceElementTiming* Create(const AtomicString& name,
static PerformanceElementTiming* Create(const String& url,
const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end,
......@@ -30,7 +30,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
int naturalHeight,
const AtomicString& id,
Element*);
PerformanceElementTiming(const AtomicString& name,
PerformanceElementTiming(const String& url,
const FloatRect& intersection_rect,
DOMHighResTimeStamp start_time,
DOMHighResTimeStamp response_end,
......@@ -57,6 +57,8 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
AtomicString id() const { return id_; }
String url() const { return url_; }
Element* element() const;
void Trace(blink::Visitor*) override;
......@@ -71,6 +73,7 @@ class CORE_EXPORT PerformanceElementTiming final : public PerformanceEntry {
unsigned naturalWidth_;
unsigned naturalHeight_;
AtomicString id_;
String url_;
};
} // namespace blink
......
......@@ -12,6 +12,7 @@ interface PerformanceElementTiming : PerformanceEntry {
readonly attribute unsigned long naturalHeight;
readonly attribute DOMString id;
readonly attribute Element? element;
readonly attribute DOMString url;
// TODO(peria): toJSON is not in spec. https://crbug.com/736332
[CallWith=ScriptState, ImplementedAs=toJSONForBinding] object toJSON();
......
......@@ -392,7 +392,7 @@ void WindowPerformance::ReportEventTimings(WebWidgetClient::SwapResult result,
event_timings_.clear();
}
void WindowPerformance::AddElementTiming(const AtomicString& name,
void WindowPerformance::AddElementTiming(const String& url,
const FloatRect& rect,
TimeTicks start_time,
TimeTicks response_end,
......@@ -402,7 +402,7 @@ void WindowPerformance::AddElementTiming(const AtomicString& name,
Element* element) {
DCHECK(RuntimeEnabledFeatures::ElementTimingEnabled(GetExecutionContext()));
PerformanceElementTiming* entry = PerformanceElementTiming::Create(
name, rect, MonotonicTimeToDOMHighResTimeStamp(start_time),
url, rect, MonotonicTimeToDOMHighResTimeStamp(start_time),
MonotonicTimeToDOMHighResTimeStamp(response_end), identifier,
intrinsic_size.Width(), intrinsic_size.Height(), id, element);
if (HasObserverFor(PerformanceEntry::kElement)) {
......
......@@ -76,7 +76,7 @@ class CORE_EXPORT WindowPerformance final : public Performance,
TimeTicks processing_end,
bool cancelable);
void AddElementTiming(const AtomicString& name,
void AddElementTiming(const String& url,
const FloatRect& rect,
TimeTicks start_time,
TimeTicks response_end,
......
......@@ -31,20 +31,20 @@ body {
t.step_func(entryList => {
entryList.getEntries().forEach(entry => {
numObservedElements++;
if (entry.name.endsWith('square100.png')) {
if (entry.url.endsWith('square100.png')) {
observedSquare = true;
checkElement(entry, pathname + 'square100.png', 'multi', 'target', beforeRender, div);
checkRect(entry, [0, 200, 0, 200]);
checkNaturalSize(entry, 100, 100);
}
else if (entry.name.endsWith('circle.svg')) {
else if (entry.url.endsWith('circle.svg')) {
observedCircle = true;
checkElement(entry, pathname + 'circle.svg', 'multi', 'target', beforeRender, div);
checkRect(entry, [0, 200, 0, 200]);
checkNaturalSize(entry, 200, 200);
}
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) {
assert_true(observedCircle);
......
// Common checks between checkElement() and checkElementWithoutResourceTiming().
function checkElementInternal(entry, expectedName, expectedIdentifier, expectedID, beforeRender,
function checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement) {
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.duration, 0);
assert_equals(entry.id, expectedID);
......@@ -12,20 +13,20 @@ function checkElementInternal(entry, expectedName, expectedIdentifier, expectedI
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().
function checkElement(entry, expectedName, expectedIdentifier, expectedID, beforeRender,
function checkElement(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement) {
checkElementInternal(entry, expectedName, expectedIdentifier, expectedID, beforeRender,
checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
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[0].responseEnd, entry.responseEnd);
}
function checkElementWithoutResourceTiming(entry, expectedName, expectedIdentifier,
function checkElementWithoutResourceTiming(entry, expectedUrl, expectedIdentifier,
expectedID, beforeRender, expectedElement) {
checkElementInternal(entry, expectedName, expectedIdentifier, expectedID, beforeRender,
checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement);
// No associated resource from ResourceTiming, so the responseEnd should be 0.
assert_equals(entry.responseEnd, 0);
......
......@@ -5377,6 +5377,7 @@ interface PerformanceElementTiming : PerformanceEntry
getter naturalHeight
getter naturalWidth
getter responseEnd
getter url
method constructor
method toJSON
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