Commit bd85085d authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Chromium LUCI CQ

Use correct active stylesheets for collecting user fonts.

If there were no @font-face rules in the document, but @font-face rules
in user origin stylesheets, we would collect fonts based on the previous
set of active user sheets. Pass the correct new active sheets.

Bug: 1157821
Change-Id: I19a4578b5cced1568516e586208e37066c7df873
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584926Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836642}
parent 14199559
......@@ -688,7 +688,8 @@ void StyleEngine::DidDetach() {
environment_variables_ = nullptr;
}
bool StyleEngine::ClearFontFaceCacheAndAddUserFonts() {
bool StyleEngine::ClearFontFaceCacheAndAddUserFonts(
const ActiveStyleSheetVector& user_sheets) {
bool fonts_changed = false;
if (font_selector_ &&
......@@ -699,9 +700,9 @@ bool StyleEngine::ClearFontFaceCacheAndAddUserFonts() {
}
// Rebuild the font cache with @font-face rules from user style sheets.
for (unsigned i = 0; i < active_user_style_sheets_.size(); ++i) {
DCHECK(active_user_style_sheets_[i].second);
if (AddUserFontFaceRules(*active_user_style_sheets_[i].second))
for (unsigned i = 0; i < user_sheets.size(); ++i) {
DCHECK(user_sheets[i].second);
if (AddUserFontFaceRules(*user_sheets[i].second))
fonts_changed = true;
}
......@@ -1541,7 +1542,8 @@ void StyleEngine::ApplyUserRuleSetChanges(
scoped_resolver->SetNeedsAppendAllSheets();
MarkDocumentDirty();
} else {
has_rebuilt_font_face_cache = ClearFontFaceCacheAndAddUserFonts();
has_rebuilt_font_face_cache =
ClearFontFaceCacheAndAddUserFonts(new_style_sheets);
}
}
......@@ -1662,8 +1664,10 @@ void StyleEngine::ApplyRuleSetChanges(
}
bool has_rebuilt_font_face_cache = false;
if (rebuild_font_face_cache)
has_rebuilt_font_face_cache = ClearFontFaceCacheAndAddUserFonts();
if (rebuild_font_face_cache) {
has_rebuilt_font_face_cache =
ClearFontFaceCacheAndAddUserFonts(active_user_style_sheets_);
}
unsigned append_start_index = 0;
if (scoped_resolver) {
......
......@@ -515,7 +515,8 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,
void UpdateStyleSheetList(TreeScope&);
// Returns true if any @font-face rules are added or removed.
bool ClearFontFaceCacheAndAddUserFonts();
bool ClearFontFaceCacheAndAddUserFonts(
const ActiveStyleSheetVector& user_sheets);
void ClearKeyframeRules() { keyframes_rule_map_.clear(); }
void ClearPropertyRules();
......
......@@ -652,6 +652,29 @@ TEST_F(StyleEngineTest, AnalyzedInject) {
t11->GetComputedStyle()->VisitedDependentColor(GetCSSPropertyColor()));
}
TEST_F(StyleEngineTest, InjectedUserNoAuthorFontFace) {
UpdateAllLifecyclePhases();
FontDescription font_description;
FontFaceCache* cache = GetStyleEngine().GetFontSelector()->GetFontFaceCache();
EXPECT_FALSE(cache->Get(font_description, "User"));
auto* user_sheet = MakeGarbageCollected<StyleSheetContents>(
MakeGarbageCollected<CSSParserContext>(GetDocument()));
user_sheet->ParseString(
"@font-face {"
" font-family: 'User';"
" src: url(font.ttf);"
"}");
StyleSheetKey user_key("user");
GetStyleEngine().InjectSheet(user_key, user_sheet, WebDocument::kUserOrigin);
UpdateAllLifecyclePhases();
EXPECT_TRUE(cache->Get(font_description, "User"));
}
TEST_F(StyleEngineTest, InjectedFontFace) {
GetDocument().body()->setInnerHTML(R"HTML(
<style>
......
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