Commit 4cf82bbb authored by Richard Townsend's avatar Richard Townsend Committed by Commit Bot

fix: improve prefetching conformance for the foreground parser

Dispatches link=rel preloads before they're added to the page,
which makes prefetching behaviour more similar to the
background parser.

Bug: 901056
Change-Id: Ia60c5c241c96860fb50218d4eca71eedb4ec91b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2540449
Commit-Queue: Richard Townsend <richard.townsend@arm.com>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828736}
parent 99fb6fc3
......@@ -131,7 +131,9 @@ class HTMLDocumentParserState
meta_csp_state_(MetaCSPTokenState::kNotSeen),
mode_(mode),
end_if_delayed_forbidden_(0),
should_complete_(0) {}
should_complete_(0),
needs_viewport_update_(false),
needs_link_header_dispatch_(true) {}
void Trace(Visitor* v) const {}
......@@ -153,6 +155,17 @@ class HTMLDocumentParserState
}
}
bool NeedsLinkHeaderPreloadsDispatch() const {
return needs_link_header_dispatch_;
}
bool NeedsViewportUpdate() const { return needs_viewport_update_; }
void SetNeedsViewportUpdate() { needs_viewport_update_ = true; }
void DispatchedLinkHeaderPreloads() { needs_link_header_dispatch_ = false; }
void UpdatedViewport() {
needs_viewport_update_ = false;
needs_link_header_dispatch_ = true;
}
bool ShouldEndIfDelayed() const { return end_if_delayed_forbidden_ == 0; }
bool ShouldComplete() const {
return should_complete_ || GetMode() != kAllowDeferredParsing;
......@@ -196,6 +209,8 @@ class HTMLDocumentParserState
ParserSynchronizationPolicy mode_;
int end_if_delayed_forbidden_;
int should_complete_;
bool needs_viewport_update_;
bool needs_link_header_dispatch_;
};
class EndIfDelayedForbiddenScope {
......@@ -1232,12 +1247,6 @@ void HTMLDocumentParser::Append(const String& input_source) {
return;
}
if (preload_scanner_) {
if (input_.Current().IsEmpty() && !IsPaused()) {
// We have parsed until the end of the current input and so are now
// moving ahead of the preload scanner. Clear the scanner so we know to
// scan starting from the current input point if we block again.
preload_scanner_.reset();
} else {
preload_scanner_->AppendToEnd(source);
if (preloader_) {
if (!task_runner_state_->IsSynchronous() || IsPaused()) {
......@@ -1247,7 +1256,6 @@ void HTMLDocumentParser::Append(const String& input_source) {
ScanAndPreload(preload_scanner_.get());
}
}
}
}
input_.AppendToEnd(source);
......@@ -1672,8 +1680,42 @@ void HTMLDocumentParser::ScanAndPreload(HTMLPreloadScanner* scanner) {
TRACE_EVENT0("blink", "HTMLDocumentParser::ScanAndPreload");
DCHECK(preloader_);
bool seen_csp_meta_tag = false;
PreloadRequestStream requests = scanner->Scan(
GetDocument()->ValidBaseElementURL(), nullptr, seen_csp_meta_tag);
base::Optional<ViewportDescription> viewport_description;
PreloadRequestStream requests =
scanner->Scan(GetDocument()->ValidBaseElementURL(), &viewport_description,
seen_csp_meta_tag);
if (viewport_description.has_value()) {
task_runner_state_->SetNeedsViewportUpdate();
}
// Make sure that the viewport is up-to-date, so that the correct viewport
// dimensions will be fed to the background parser and preload scanner.
if (GetDocument()->Loader() &&
task_runner_state_->GetMode() == kAllowDeferredParsing) {
if (task_runner_state_->NeedsViewportUpdate()) {
GetDocument()->GetStyleEngine().UpdateViewport();
task_runner_state_->UpdatedViewport();
}
if (task_runner_state_->NeedsLinkHeaderPreloadsDispatch()) {
if (GetDocument()->Loader()->GetPrefetchedSignedExchangeManager()) {
TRACE_EVENT0("blink",
"HTMLDocumentParser::DispatchSignedExchangeManager");
// Link header preloads for prefetched signed exchanges won't be started
// until StartPrefetchedLinkHeaderPreloads() is called. See the header
// comment of PrefetchedSignedExchangeManager.
GetDocument()
->Loader()
->GetPrefetchedSignedExchangeManager()
->StartPrefetchedLinkHeaderPreloads();
} else {
TRACE_EVENT0("blink", "HTMLDocumentParser::DispatchLinkHeaderPreloads");
GetDocument()->Loader()->DispatchLinkHeaderPreloads(
base::OptionalOrNullptr(viewport_description),
PreloadHelper::kOnlyLoadMedia);
}
task_runner_state_->DispatchedLinkHeaderPreloads();
}
}
task_runner_state_->SetSeenCSPMetaTag(seen_csp_meta_tag);
for (auto& request : requests) {
queued_preloads_.push_back(std::move(request));
......
......@@ -151,7 +151,8 @@ TEST_P(HTMLDocumentParserTest, AppendNoPrefetch) {
// The bytes are forwarded to the tokenizer.
HTMLParserScriptRunnerHost* script_runner_host =
parser->AsHTMLParserScriptRunnerHostForTesting();
EXPECT_FALSE(script_runner_host->HasPreloadScanner());
EXPECT_EQ(script_runner_host->HasPreloadScanner(),
testing::get<0>(GetParam()) == kAllowDeferredParsing);
EXPECT_EQ(HTMLTokenizer::kTagNameState, parser->Tokenizer()->GetState());
// Cancel any pending work to make sure that RuntimeFeatures DCHECKs do not
// fire.
......
......@@ -4,13 +4,8 @@
# File containing known test issues under the synchronous, budgeted foreground HTML parser
# Ordered from most to least serious.
# This set of test crashes comes because response_document_ is unexpectedly nullptr in DCHECK builds.
### external/wpt/service-workers/service-worker/
crbug.com/901056 external/wpt/service-workers/service-worker/xhr-response-url.https.html [ Crash ]
### virtual/plz-dedicated-worker/external/wpt/service-workers/service-worker/
crbug.com/901056 virtual/plz-dedicated-worker/external/wpt/service-workers/service-worker/xhr-response-url.https.html [ Crash ]
#
# Timeouts
#
......@@ -18,29 +13,13 @@ crbug.com/901056 virtual/plz-dedicated-worker/external/wpt/service-workers/servi
### http/tests/loading/sxg/
crbug.com/901056 http/tests/loading/sxg/sxg-subresource-origin-trial.https.html [ Timeout Failure ]
### http/tests/preload/
crbug.com/901056 http/tests/preload/meta-viewport-link-headers-imagesrcset.html [ Timeout ]
### http/tests/inspector-protocol/issues/
crbug.com/901056 http/tests/inspector-protocol/issues/mixed-content-issue-creation-js-within-oopif.js [ Timeout ]
### virtual/gpu/fast/canvas/
crbug.com/901056 virtual/gpu/fast/canvas/canvas-drawImage-live-video.html [ Timeout ]
### external/wpt/signed-exchange/subresource/
crbug.com/901056 external/wpt/signed-exchange/subresource/sxg-subresource.tentative.html [ Timeout ]
### http/tests/inspector-protocol/issues/
crbug.com/901056 http/tests/inspector-protocol/issues/mixed-content-issue-creation-css.js [ Timeout ]
crbug.com/901056 http/tests/inspector-protocol/issues/mixed-content-issue-creation-js-within-iframe.js [ Timeout ]
crbug.com/901056 http/tests/inspector-protocol/issues/mixed-content-issue-creation-js.js [ Timeout ]
#
# Harness failures
#
# Most of these failures are due to layout viewport issues
### external/wpt/preload/
crbug.com/901056 external/wpt/preload/link-header-preload-imagesrcset.html [ Failure ]
### http/tests/preload/
# This one happens because HTMLPreloadSanner discards all scanned preloads whenever it sees a <meta> CSP token.
......@@ -57,28 +36,12 @@ crbug.com/901056 media/controls/rotated-video-has-right-panel-width.html [ Failu
### virtual/plz-dedicated-worker/external/wpt/resource-timing/
crbug.com/901056 virtual/plz-dedicated-worker/external/wpt/resource-timing/nested-context-navigations-object.html [ Failure ]
#
# Image failures
#
### css1/pseudo/
# Line-wrapping is slightly different
crbug.com/901056 css1/pseudo/pseudo_elements_in_selectors.html [ Failure ]
### fast/hidpi/
# Document width is different
crbug.com/901056 fast/hidpi/image-srcset-png-canvas.html [ Failure ]
#
# Text failures
#
### fast/block/float
crbug.com/901056 fast/block/float/4145535Crash.html [ Failure Pass ]
### fast/preloader/
# Two new subtests fail (investigation required)
crbug.com/901056 fast/preloader/is-preloaded-after-load.html [ Failure ]
### http/tests/devtools/console
# An extra "VM" is printed in front of the page name.
crbug.com/901056 http/tests/devtools/console/console-uncaught-exception.js [ Failure ]
......@@ -105,10 +68,6 @@ crbug.com/901056 http/tests/security/contentSecurityPolicy/nonces/scriptnonce-re
# Probably a viewport sizing issue (investigation needed).
crbug.com/901056 paint/invalidation/overflow/resize-child-within-overflow.html [ Failure ]
### tables/mozilla_expected_failures/bugs/
# Blocked access message no longer emitted (investigation needed).
crbug.com/901056 tables/mozilla_expected_failures/bugs/bug128876.html [ Failure ]
### virtual/conditional-appcache-delay/http/tests/loading/appcache-delay/
# WontFix (AppCache will be removed at some point.)
crbug.com/901056 virtual/conditional-appcache-delay/http/tests/loading/appcache-delay/appcache-loads-subresource.html [ Failure ]
......
......@@ -74,20 +74,12 @@ external/wpt/css/compositing/root-element-background-transparency.html [ Failure
# ====== Synchronous, budgeted HTML parser tests from here ======
### virtual/synchronous_html_parser/http/tests/preload/
# An extra line ("linear_memory_inspector") appears in the output in some cases.
crbug.com/901056 http/tests/devtools/modules-load-source.js [ Failure Pass ]
# Extra line info appears in the output in some cases.
crbug.com/901056 virtual/synchronous_html_parser/http/tests/inspector-protocol/issues/content-security-policy-issue-creation-img.js [ Failure Pass ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/preload/meta-csp.html [ Failure ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/preload/meta-viewport-device-width-link-headers.html [ Failure ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/preload/meta-viewport-link-headers-imagesrcset.html [ Timeout Failure ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/inspector-protocol/issues/mixed-content-issue-creation-js-within-oopif.js [ Timeout ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/inspector-protocol/issues/mixed-content-issue-creation-css.js [ Timeout ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/inspector-protocol/issues/mixed-content-issue-creation-js-within-iframe.js [ Timeout ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/inspector-protocol/issues/mixed-content-issue-creation-js.js [ Timeout ]
# Minor issues, need rebaselining
crbug.com/901056 virtual/synchronous_html_parser/fast/css/focus-display-block-inline.html [ Failure ]
crbug.com/901056 virtual/synchronous_html_parser/fast/css/fontfaceset-multiple-families.html [ Failure ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/inspector-protocol/issues/content-security-policy-issue-creation-img.js [ Failure ]
crbug.com/901056 virtual/synchronous_html_parser/http/tests/inspector-protocol/network/initiator-minified.js [ Failure ]
crbug.com/901056 virtual/synchronous_html_parser/external/wpt/signed-exchange/subresource/sxg-subresource.tentative.html [ Failure Timeout ]
# ====== Site Isolation failures from here ======
# See also third_party/blink/web_tests/virtual/not-site-per-process/README.md
# Tests temporarily disabled with Site Isolation - uninvestigated bugs:
......
Verifies that CSP issue is created from a page with image source violation.
Inspector issue: {
issue : {
code : ContentSecurityPolicyIssue
details : {
contentSecurityPolicyIssueDetails : {
blockedURL : https://thirdparty.test/network/resources/to-be-blocked.jpg
contentSecurityPolicyViolationType : kURLViolation
isReportOnly : false
sourceCodeLocation : {
columnNumber : 0
lineNumber : 8
url : https://devtools.test:8443/inspector-protocol/resources/content-security-policy-issue-image.php
}
violatedDirective : img-src
}
}
}
}
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