Commit 5fe74f83 authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

Do not forward resource timing to parent frame after back-forward navigation

LocalFrame has |should_send_resource_timing_info_to_parent_| flag not to
send timing info to parent except for the first navigation. This flag is
cleared when the first timing is sent to parent, however this does not happen
if iframe's first navigation was by back-forward navigation. For such
iframes, we shouldn't send timings to parent at all.

Bug: 876822
Change-Id: I128b51a82ef278c439548afc8283ae63abdef5c5
Reviewed-on: https://chromium-review.googlesource.com/1186215Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585736}
parent 7dc9d5bf
ALERT: Going back.
Tests that subsequent navigation in an iframe restored from history does not report resource timing.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS resources.length is 1
PASS resources[0].name is "http://127.0.0.1:8000/js-test-resources/js-test.js"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="/js-test-resources/js-test.js"></script>
<script>
description('Tests that subsequent navigation in an iframe restored from history does not report resource timing.');
window.jsTestIsAsync = true;
function runTest() {
if (!sessionStorage.didNav) {
sessionStorage.didNav = true;
// Navigate a timeout to make sure we generate a history entry that we can go back to.
setTimeout(function() {
location.href = 'resources/alert-then-back.html';
}, 0);
} else {
delete sessionStorage.didNav;
window.addEventListener('message', (event) => {
resources = performance.getEntriesByType('resource');
shouldBe('resources.length', '1');
shouldBeEqualToString('resources[0].name', 'http://127.0.0.1:8000/js-test-resources/js-test.js');
if (window.testRunner)
finishJSTest();
});
document.getElementById('target-iframe').contentWindow.postMessage('navigate', '*');
}
}
window.onload = runTest;
</script>
<iframe id="target-iframe" src="http://localhost:8080/misc/resources/navigate-on-message.html"></iframe>
<!DOCTYPE html>
<script>
function handleMessage() {
window.location = 'post-message-to-parent.html';
}
window.addEventListener("message", handleMessage);
</script>
<!DOCTYPE html>
<script>
window.parent.postMessage('navigated', '*');
</script>
...@@ -325,8 +325,8 @@ class CORE_EXPORT LocalFrame final : public Frame, ...@@ -325,8 +325,8 @@ class CORE_EXPORT LocalFrame final : public Frame,
bool should_send_resource_timing_info_to_parent() const { bool should_send_resource_timing_info_to_parent() const {
return should_send_resource_timing_info_to_parent_; return should_send_resource_timing_info_to_parent_;
} }
void DidSendResourceTimingInfoToParent() { void SetShouldSendResourceTimingInfoToParent(bool value) {
should_send_resource_timing_info_to_parent_ = false; should_send_resource_timing_info_to_parent_ = value;
} }
// TODO(https://crbug.com/578349): provisional frames are a hack that should // TODO(https://crbug.com/578349): provisional frames are a hack that should
......
...@@ -2251,7 +2251,7 @@ void WebLocalFrameImpl::SetCommittedFirstRealLoad() { ...@@ -2251,7 +2251,7 @@ void WebLocalFrameImpl::SetCommittedFirstRealLoad() {
DCHECK(GetFrame()); DCHECK(GetFrame());
GetFrame()->Loader().StateMachine()->AdvanceTo( GetFrame()->Loader().StateMachine()->AdvanceTo(
FrameLoaderStateMachine::kCommittedMultipleRealLoads); FrameLoaderStateMachine::kCommittedMultipleRealLoads);
GetFrame()->DidSendResourceTimingInfoToParent(); GetFrame()->SetShouldSendResourceTimingInfoToParent(false);
} }
void WebLocalFrameImpl::NotifyUserActivation() { void WebLocalFrameImpl::NotifyUserActivation() {
......
...@@ -818,7 +818,7 @@ void FrameFetchContext::AddResourceTiming(const ResourceTimingInfo& info) { ...@@ -818,7 +818,7 @@ void FrameFetchContext::AddResourceTiming(const ResourceTimingInfo& info) {
// Main resource timing information is reported through the owner to be // Main resource timing information is reported through the owner to be
// passed to the parent frame, if appropriate. // passed to the parent frame, if appropriate.
frame->Owner()->AddResourceTiming(info); frame->Owner()->AddResourceTiming(info);
frame->DidSendResourceTimingInfoToParent(); frame->SetShouldSendResourceTimingInfoToParent(false);
return; return;
} }
...@@ -896,9 +896,12 @@ bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation( ...@@ -896,9 +896,12 @@ bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation(
if (!GetFrame()->should_send_resource_timing_info_to_parent()) if (!GetFrame()->should_send_resource_timing_info_to_parent())
return false; return false;
// Do not report iframe navigation that restored from history, since its // Do not report iframe navigation that restored from history, since its
// location may have been changed after initial navigation. // location may have been changed after initial navigation,
if (MasterDocumentLoader()->LoadType() == WebFrameLoadType::kBackForward) if (MasterDocumentLoader()->LoadType() == WebFrameLoadType::kBackForward) {
// ...and do not report subsequent navigations in the iframe too.
GetFrame()->SetShouldSendResourceTimingInfoToParent(false);
return false; return false;
}
return true; return true;
} }
......
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