Commit a8385691 authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

Make web font timeouts work for preloaded fonts

This patch fixes a bug where font display timeouts (100ms and 3s)
didn't start if the font resource is already started loading by
<link rel=preload>.

Bug: 835583
Change-Id: Ie464179ebcc56f2d18c99d234eadd4fc26bc1fcd
Reviewed-on: https://chromium-review.googlesource.com/1027331Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553896}
parent f7be5d1d
<!DOCTYPE html>
<html>
<title>font-display should work for preloaded fonts</title>
<style>
.arial {
height: 20px;
font-family: Arial;
}
</style>
<div id="container">
<div class="arial"></div>
<div class="arial"></div>
<div class="arial">Swap</div>
<div class="arial">Fallback</div>
<div class="arial">Optional</div>
</div>
</html>
<!DOCTYPE html>
<html class="reftest-wait">
<title>font-display should work for preloaded fonts</title>
<link id="link" href="/fonts/Ahem.ttf?pipe=trickle(d5)" as="font" type="font/ttf" crossorigin>
<link rel="match" href="font-display-preload-ref.html">
<style>
@font-face {
font-family: 'Auto';
src: url('/fonts/Ahem.ttf?pipe=trickle(d5)');
font-display: auto;
}
@font-face {
font-family: 'Block';
src: url('/fonts/Ahem.ttf?pipe=trickle(d5)');
font-display: block;
}
@font-face {
font-family: 'Swap';
src: url('/fonts/Ahem.ttf?pipe=trickle(d5)');
font-display: swap;
}
@font-face {
font-family: 'Fallback';
src: url('/fonts/Ahem.ttf?pipe=trickle(d5)');
font-display: fallback;
}
@font-face {
font-family: 'Optional';
src: url('/fonts/Ahem.ttf?pipe=trickle(d5)');
font-display: optional;
}
</style>
<div id="container" hidden>
<div style="height: 20px; font-family: 'Auto', Arial">Auto</div>
<div style="height: 20px; font-family: 'Block', Arial">Block</div>
<div style="height: 20px; font-family: 'Swap', Arial">Swap</div>
<div style="height: 20px; font-family: 'Fallback', Arial">Fallback</div>
<div style="height: 20px; font-family: 'Optional', Arial">Optional</div>
</div>
<script>
window.onload = () => {
document.getElementById('link').rel = 'preload';
document.getElementById('container').hidden = false;
const timeoutMsec = 200; // Between the short limit and the long limit
setTimeout(() => {
document.documentElement.classList.remove("reftest-wait");
}, timeoutMsec);
};
</script>
</html>
...@@ -269,18 +269,18 @@ void RemoteFontFaceSource::BeginLoadIfNeeded() { ...@@ -269,18 +269,18 @@ void RemoteFontFaceSource::BeginLoadIfNeeded() {
// that this font is not required for painting the text. // that this font is not required for painting the text.
font->DidChangePriority(ResourceLoadPriority::kVeryLow, 0); font->DidChangePriority(ResourceLoadPriority::kVeryLow, 0);
} }
if (font_selector_->GetExecutionContext()->Fetcher()->StartLoad(font)) { if (font_selector_->GetExecutionContext()->Fetcher()->StartLoad(font))
// Start timers only when load is actually started asynchronously.
if (!IsLoaded()) {
font->StartLoadLimitTimers(
font_selector_->GetExecutionContext()
->GetTaskRunner(TaskType::kInternalLoading)
.get());
}
histograms_.LoadStarted(); histograms_.LoadStarted();
}
} }
// Start the timers upon the first load request from RemoteFontFaceSource.
// Note that <link rel=preload> may have initiated loading without kicking
// off the timers.
font->StartLoadLimitTimersIfNecessary(
font_selector_->GetExecutionContext()
->GetTaskRunner(TaskType::kInternalLoading)
.get());
face_->DidBeginLoad(); face_->DidBeginLoad();
} }
......
...@@ -119,10 +119,12 @@ void FontResource::SetRevalidatingRequest(const ResourceRequest& request) { ...@@ -119,10 +119,12 @@ void FontResource::SetRevalidatingRequest(const ResourceRequest& request) {
Resource::SetRevalidatingRequest(request); Resource::SetRevalidatingRequest(request);
} }
void FontResource::StartLoadLimitTimers( void FontResource::StartLoadLimitTimersIfNecessary(
base::SingleThreadTaskRunner* task_runner) { base::SingleThreadTaskRunner* task_runner) {
DCHECK(IsLoading()); if (!IsLoading() || load_limit_state_ != kLoadNotStarted)
DCHECK_EQ(load_limit_state_, kLoadNotStarted); return;
DCHECK(!font_load_short_limit_.IsActive());
DCHECK(!font_load_long_limit_.IsActive());
load_limit_state_ = kUnderLimit; load_limit_state_ = kUnderLimit;
font_load_short_limit_ = PostDelayedCancellableTask( font_load_short_limit_ = PostDelayedCancellableTask(
......
...@@ -54,7 +54,7 @@ class CORE_EXPORT FontResource final : public Resource { ...@@ -54,7 +54,7 @@ class CORE_EXPORT FontResource final : public Resource {
void SetRevalidatingRequest(const ResourceRequest&) override; void SetRevalidatingRequest(const ResourceRequest&) override;
void AllClientsAndObserversRemoved() override; void AllClientsAndObserversRemoved() override;
void StartLoadLimitTimers(base::SingleThreadTaskRunner*); void StartLoadLimitTimersIfNecessary(base::SingleThreadTaskRunner*);
String OtsParsingMessage() const { return ots_parsing_message_; } String OtsParsingMessage() const { return ots_parsing_message_; }
......
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