Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: third_party/WebKit/Source/core/css/FontLoader.cpp

Issue 1829403002: Clean up font loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Resource_status
Patch Set: Address hiroshige's comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/FontLoader.cpp
diff --git a/third_party/WebKit/Source/core/css/FontLoader.cpp b/third_party/WebKit/Source/core/css/FontLoader.cpp
deleted file mode 100644
index 94b4e16704c4bdccabb630cda0d86032b22d72f9..0000000000000000000000000000000000000000
--- a/third_party/WebKit/Source/core/css/FontLoader.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "core/css/FontLoader.h"
-
-#include "core/css/CSSFontSelector.h"
-#include "core/dom/Document.h"
-#include "core/dom/IncrementLoadEventDelayCount.h"
-#include "core/fetch/FontResource.h"
-#include "core/inspector/ConsoleMessage.h"
-
-namespace blink {
-
-struct FontLoader::FontToLoad : public GarbageCollectedFinalized<FontLoader::FontToLoad> {
-public:
- static FontToLoad* create(FontResource* fontResource, Document& document)
- {
- return new FontToLoad(fontResource, document);
- }
-
- virtual ~FontToLoad()
- {
- ASSERT(!fontResource);
- }
-
- Member<FontResource> fontResource;
- OwnPtr<IncrementLoadEventDelayCount> delay;
-
- void dispose()
- {
- fontResource = nullptr;
- delay.clear();
- }
-
- DEFINE_INLINE_TRACE() { visitor->trace(fontResource); }
-
-private:
- FontToLoad(FontResource* resource, Document& document)
- : fontResource(resource)
- , delay(IncrementLoadEventDelayCount::create(document))
- {
- }
-};
-
-FontLoader::FontLoader(CSSFontSelector* fontSelector, Document* document)
- : m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired)
- , m_fontSelector(fontSelector)
- , m_document(document)
-{
-}
-
-FontLoader::~FontLoader()
-{
-#if ENABLE(OILPAN)
- if (!m_document) {
- ASSERT(m_fontsToBeginLoading.isEmpty());
- return;
- }
- m_beginLoadingTimer.stop();
- // This will decrement the request counts on the ResourceFetcher for all the
- // fonts that were pending at the time the FontLoader dies.
- clearPendingFonts();
-#endif
-}
-
-void FontLoader::addFontToBeginLoading(FontResource* fontResource)
-{
- if (!m_document || !fontResource->stillNeedsLoad() || fontResource->loadScheduled())
- return;
-
- m_fontsToBeginLoading.append(FontToLoad::create(fontResource, *m_document));
- fontResource->didScheduleLoad();
- if (!m_beginLoadingTimer.isActive())
- m_beginLoadingTimer.startOneShot(0, BLINK_FROM_HERE);
-}
-
-void FontLoader::beginLoadTimerFired(Timer<blink::FontLoader>*)
-{
- loadPendingFonts();
-}
-
-void FontLoader::loadPendingFonts()
-{
- ASSERT(m_document);
-
- FontsToLoadVector fontsToBeginLoading;
- fontsToBeginLoading.swap(m_fontsToBeginLoading);
- for (const auto& fontToLoad : fontsToBeginLoading) {
- if (m_document->frame())
- fontToLoad->fontResource->beginLoadIfNeeded(m_document->fetcher());
- else
- fontToLoad->fontResource->error(Resource::LoadError);
- fontToLoad->dispose();
- }
-
- // When the local fontsToBeginLoading vector goes out of scope it will
- // decrement the request counts on the ResourceFetcher for all the fonts
- // that were just loaded.
-}
-
-void FontLoader::fontFaceInvalidated()
-{
- if (m_fontSelector)
- m_fontSelector->fontFaceInvalidated();
-}
-
-void FontLoader::didFailToDecode(FontResource* fontResource)
-{
- // FIXME: Provide more useful message such as OTS rejection reason.
- // See crbug.com/97467
- if (m_fontSelector && m_fontSelector->document()) {
- m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, "Failed to decode downloaded font: " + fontResource->url().elidedString()));
- if (fontResource->otsParsingMessage().length() > 1)
- m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, "OTS parsing error: " + fontResource->otsParsingMessage()));
- }
-}
-
-#if !ENABLE(OILPAN)
-void FontLoader::clearDocumentAndFontSelector()
-{
- if (!m_document) {
- ASSERT(m_fontsToBeginLoading.isEmpty());
- return;
- }
-
- m_beginLoadingTimer.stop();
- clearPendingFonts();
- m_document = nullptr;
- m_fontSelector = nullptr;
-}
-#endif
-
-void FontLoader::clearPendingFonts()
-{
- for (const auto& fontToLoad : m_fontsToBeginLoading) {
- fontToLoad->fontResource->didUnscheduleLoad();
- fontToLoad->dispose();
- }
- m_fontsToBeginLoading.clear();
-}
-
-DEFINE_TRACE(FontLoader)
-{
- visitor->trace(m_fontsToBeginLoading);
- visitor->trace(m_document);
- visitor->trace(m_fontSelector);
-}
-
-} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698