Commit 68a6c2c2 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Chromium LUCI CQ

[PM] Fix origin computation of about:blank frame nodes

An about:blank frame inherits its origin from its parent [1, 2].
This adjust the node aggregation type computation return
kSameOriginAggregationPoint in the case when
- the current frame is about:blank and
- its parent has the same origin as the requesting origin.

This change provides better results for pages that create and pool
many about:blank iframe for warming up.

[1]: https://html.spec.whatwg.org/multipage/browsers.html#determining-the-origin
[2]: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#inherited_origins

Bug: 1085129
Change-Id: Iffe6b09a6b8ec1e2fd7b9a293e4b714a955d95fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627492
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843649}
parent 15836261
......@@ -32,8 +32,16 @@ bool ShouldFollowOpenerLink(const PageNode* page_node) {
}
// Returns |frame_node|'s origin based on its current url.
// An about:blank iframe inherits the origin of its parent. See:
// https://html.spec.whatwg.org/multipage/browsers.html#determining-the-origin
url::Origin GetOrigin(const FrameNode* frame_node) {
return url::Origin::Create(frame_node->GetURL());
if (frame_node->GetParentFrameNode()) {
return url::Origin::Resolve(
frame_node->GetURL(),
url::Origin::Create(frame_node->GetParentFrameNode()->GetURL()));
} else {
return url::Origin::Create(frame_node->GetURL());
}
}
#if DCHECK_IS_ON()
......@@ -152,8 +160,10 @@ WebMemoryAggregator::FindNodeAggregationType(const FrameNode* frame_node) {
return NodeAggregationType::kInvisible;
}
if (requesting_origin_.IsSameOriginWith(GetOrigin(parent_node)))
auto parent_origin = GetOrigin(parent_node);
if (requesting_origin_.IsSameOriginWith(parent_origin)) {
return NodeAggregationType::kCrossOriginAggregationPoint;
}
// Otherwise |frame_node|'s memory should be aggregated into the last
// aggregation point.
......
......@@ -397,6 +397,39 @@ TEST_F(WebMemoryAggregatorTest, AggregateNestedCrossOrigin) {
EXPECT_EQ(MeasurementToJSON(result), MeasurementToJSON(expected_result));
}
TEST_F(WebMemoryAggregatorTest, AggregateSameOriginAboutBlank) {
FrameNodeImpl* main_frame = AddFrameNode("https://example.com/", Bytes{10});
AddFrameNode("about:blank", Bytes{20}, main_frame);
auto expected_result = CreateExpectedMemoryMeasurement({
ExpectedMemoryBreakdown(10, AttributionScope::kWindow,
"https://example.com/"),
ExpectedMemoryBreakdown(20, AttributionScope::kWindow, "about:blank"),
});
EXPECT_EQ(internal::FindAggregationStartNode(main_frame), main_frame);
WebMemoryAggregator aggregator(main_frame);
auto result = aggregator.AggregateMeasureMemoryResult();
EXPECT_EQ(MeasurementToJSON(result), MeasurementToJSON(expected_result));
}
TEST_F(WebMemoryAggregatorTest, SkipCrossOriginAboutBlank) {
FrameNodeImpl* main_frame = AddFrameNode("https://example.com/", Bytes{10});
FrameNodeImpl* cross_site_child =
AddFrameNode("https://foo.com/", Bytes{20}, main_frame);
AddFrameNode("about:blank", Bytes{30}, cross_site_child);
auto expected_result = CreateExpectedMemoryMeasurement({
ExpectedMemoryBreakdown(10, AttributionScope::kWindow,
"https://example.com/"),
ExpectedMemoryBreakdown(50, AttributionScope::kCrossOriginAggregated,
base::nullopt),
});
EXPECT_EQ(internal::FindAggregationStartNode(main_frame), main_frame);
WebMemoryAggregator aggregator(main_frame);
auto result = aggregator.AggregateMeasureMemoryResult();
EXPECT_EQ(MeasurementToJSON(result), MeasurementToJSON(expected_result));
}
TEST_F(WebMemoryAggregatorTest, FindAggregationStartNode) {
FrameNodeImpl* main_frame = AddFrameNode("https://example.com/", Bytes{10});
FrameNodeImpl* cross_site_child = AddFrameNode(
......
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