Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/RemoteFontFaceSource.h" | 5 #include "core/css/RemoteFontFaceSource.h" |
| 6 | 6 |
| 7 #include "core/css/CSSCustomFontData.h" | 7 #include "core/css/CSSCustomFontData.h" |
| 8 #include "core/css/CSSFontFace.h" | 8 #include "core/css/CSSFontFace.h" |
| 9 #include "core/css/FontLoader.h" | 9 #include "core/css/CSSFontSelector.h" |
| 10 #include "core/dom/Document.h" | |
| 11 #include "core/inspector/ConsoleMessage.h" | |
| 10 #include "core/page/NetworkStateNotifier.h" | 12 #include "core/page/NetworkStateNotifier.h" |
| 11 #include "platform/Histogram.h" | 13 #include "platform/Histogram.h" |
| 12 #include "platform/RuntimeEnabledFeatures.h" | 14 #include "platform/RuntimeEnabledFeatures.h" |
| 13 #include "platform/fonts/FontCache.h" | 15 #include "platform/fonts/FontCache.h" |
| 14 #include "platform/fonts/FontDescription.h" | 16 #include "platform/fonts/FontDescription.h" |
| 15 #include "platform/fonts/SimpleFontData.h" | 17 #include "platform/fonts/SimpleFontData.h" |
| 16 #include "wtf/CurrentTime.h" | 18 #include "wtf/CurrentTime.h" |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, FontLoader* fontL oader, FontDisplay display) | 22 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, CSSFontSelector* fontSelector, FontDisplay display) |
| 21 : m_font(font) | 23 : m_font(font) |
| 22 , m_fontLoader(fontLoader) | 24 , m_fontSelector(fontSelector) |
| 23 , m_display(display) | 25 , m_display(display) |
| 24 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) | 26 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) |
| 25 , m_isInterventionTriggered(false) | 27 , m_isInterventionTriggered(false) |
| 26 { | 28 { |
| 27 #if ENABLE(OILPAN) | 29 #if ENABLE(OILPAN) |
| 28 ThreadState::current()->registerPreFinalizer(this); | 30 ThreadState::current()->registerPreFinalizer(this); |
| 29 #endif | 31 #endif |
| 30 m_font->addClient(this); | 32 m_font->addClient(this); |
| 31 | 33 |
| 32 if (RuntimeEnabledFeatures::webFontsInterventionEnabled()) { | 34 if (RuntimeEnabledFeatures::webFontsInterventionEnabled()) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 bool RemoteFontFaceSource::isLoaded() const | 77 bool RemoteFontFaceSource::isLoaded() const |
| 76 { | 78 { |
| 77 return m_font->isLoaded(); | 79 return m_font->isLoaded(); |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool RemoteFontFaceSource::isValid() const | 82 bool RemoteFontFaceSource::isValid() const |
| 81 { | 83 { |
| 82 return !m_font->errorOccurred(); | 84 return !m_font->errorOccurred(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void RemoteFontFaceSource::didStartFontLoad(FontResource*) | |
| 86 { | |
| 87 // We may send duplicated reports when multiple CSSFontFaceSource are | |
| 88 // registered at this FontResource. Associating the same URL to different | |
| 89 // font-family causes the case, but we treat them as indivisual resources. | |
| 90 m_histograms.loadStarted(); | |
| 91 } | |
| 92 | |
| 93 void RemoteFontFaceSource::fontLoaded(FontResource*) | 87 void RemoteFontFaceSource::fontLoaded(FontResource*) |
| 94 { | 88 { |
| 95 m_histograms.recordRemoteFont(m_font.get()); | 89 m_histograms.recordRemoteFont(m_font.get()); |
| 96 m_histograms.fontLoaded(m_isInterventionTriggered); | 90 m_histograms.fontLoaded(m_isInterventionTriggered); |
| 97 | 91 |
| 98 m_font->ensureCustomFontData(); | 92 m_font->ensureCustomFontData(); |
| 99 if (m_font->getStatus() == Resource::DecodeError) | 93 // FIXME: Provide more useful message such as OTS rejection reason. |
| 100 m_fontLoader->didFailToDecode(m_font.get()); | 94 // See crbug.com/97467 |
| 95 if (m_font->getStatus() == Resource::DecodeError && m_fontSelector->document ()) { | |
| 96 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(Oth erMessageSource, WarningMessageLevel, "Failed to decode downloaded font: " + m_f ont->url().elidedString())); | |
| 97 if (m_font->otsParsingMessage().length() > 1) | |
| 98 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create (OtherMessageSource, WarningMessageLevel, "OTS parsing error: " + m_font->otsPar singMessage())); | |
| 99 } | |
| 101 | 100 |
| 102 pruneTable(); | 101 pruneTable(); |
| 103 if (m_face) { | 102 if (m_face) { |
| 104 m_fontLoader->fontFaceInvalidated(); | 103 m_fontSelector->fontFaceInvalidated(); |
| 105 m_face->fontLoaded(this); | 104 m_face->fontLoaded(this); |
| 106 } | 105 } |
| 107 // Should not do anything after this line since the m_face->fontLoaded() | 106 // Should not do anything after this line since the m_face->fontLoaded() |
| 108 // above may trigger deleting this object. | 107 // above may trigger deleting this object. |
| 109 } | 108 } |
| 110 | 109 |
| 111 void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*) | 110 void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*) |
| 112 { | 111 { |
| 113 if (m_display == FontDisplayFallback) | 112 if (m_display == FontDisplayFallback) |
| 114 switchToSwapPeriod(); | 113 switchToSwapPeriod(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 126 m_histograms.longLimitExceeded(m_isInterventionTriggered); | 125 m_histograms.longLimitExceeded(m_isInterventionTriggered); |
| 127 } | 126 } |
| 128 | 127 |
| 129 void RemoteFontFaceSource::switchToSwapPeriod() | 128 void RemoteFontFaceSource::switchToSwapPeriod() |
| 130 { | 129 { |
| 131 ASSERT(m_period == BlockPeriod); | 130 ASSERT(m_period == BlockPeriod); |
| 132 m_period = SwapPeriod; | 131 m_period = SwapPeriod; |
| 133 | 132 |
| 134 pruneTable(); | 133 pruneTable(); |
| 135 if (m_face) { | 134 if (m_face) { |
| 136 m_fontLoader->fontFaceInvalidated(); | 135 m_fontSelector->fontFaceInvalidated(); |
| 137 m_face->didBecomeVisibleFallback(this); | 136 m_face->didBecomeVisibleFallback(this); |
| 138 } | 137 } |
| 139 | 138 |
| 140 m_histograms.recordFallbackTime(m_font.get()); | 139 m_histograms.recordFallbackTime(m_font.get()); |
| 141 } | 140 } |
| 142 | 141 |
| 143 void RemoteFontFaceSource::switchToFailurePeriod() | 142 void RemoteFontFaceSource::switchToFailurePeriod() |
| 144 { | 143 { |
| 145 if (m_period == BlockPeriod) | 144 if (m_period == BlockPeriod) |
| 146 switchToSwapPeriod(); | 145 switchToSwapPeriod(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 172 if (!temporaryFont) { | 171 if (!temporaryFont) { |
| 173 ASSERT_NOT_REACHED(); | 172 ASSERT_NOT_REACHED(); |
| 174 return nullptr; | 173 return nullptr; |
| 175 } | 174 } |
| 176 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_pe riod == BlockPeriod ? CSSCustomFontData::InvisibleFallback : CSSCustomFontData:: VisibleFallback); | 175 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_pe riod == BlockPeriod ? CSSCustomFontData::InvisibleFallback : CSSCustomFontData:: VisibleFallback); |
| 177 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); | 176 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); |
| 178 } | 177 } |
| 179 | 178 |
| 180 void RemoteFontFaceSource::beginLoadIfNeeded() | 179 void RemoteFontFaceSource::beginLoadIfNeeded() |
| 181 { | 180 { |
| 182 if (m_font->stillNeedsLoad()) | 181 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { |
| 183 m_fontLoader->addFontToBeginLoading(m_font.get()); | 182 m_font->load(m_fontSelector->document()->fetcher()); |
| 183 m_histograms.loadStarted(); | |
| 184 } | |
| 185 m_font->startLoadLimitTimersIfNeeded(); | |
|
Nate Chapin
2016/04/07 23:46:16
https://tabatkins.github.io/specs/css-font-display
Kunihiko Sakamoto
2016/04/08 02:37:16
Agreed, thanks for doing this!
| |
| 184 | 186 |
| 185 if (m_face) | 187 if (m_face) |
| 186 m_face->didBeginLoad(); | 188 m_face->didBeginLoad(); |
| 187 } | 189 } |
| 188 | 190 |
| 189 DEFINE_TRACE(RemoteFontFaceSource) | 191 DEFINE_TRACE(RemoteFontFaceSource) |
| 190 { | 192 { |
| 191 visitor->trace(m_font); | 193 visitor->trace(m_font); |
| 192 visitor->trace(m_fontLoader); | 194 visitor->trace(m_fontSelector); |
| 193 CSSFontFaceSource::trace(visitor); | 195 CSSFontFaceSource::trace(visitor); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void RemoteFontFaceSource::FontLoadHistograms::loadStarted() | 198 void RemoteFontFaceSource::FontLoadHistograms::loadStarted() |
| 197 { | 199 { |
| 198 if (!m_loadStartTime) | 200 if (!m_loadStartTime) |
| 199 m_loadStartTime = currentTimeMS(); | 201 m_loadStartTime = currentTimeMS(); |
| 200 } | 202 } |
| 201 | 203 |
| 202 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod period) | 204 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod period) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 interventionResult |= 1 << 0; | 293 interventionResult |= 1 << 0; |
| 292 if (triggered) | 294 if (triggered) |
| 293 interventionResult |= 1 << 1; | 295 interventionResult |= 1 << 1; |
| 294 const int boundary = 1 << 2; | 296 const int boundary = 1 << 2; |
| 295 | 297 |
| 296 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, ("WebFont.I nterventionResult", boundary)); | 298 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, ("WebFont.I nterventionResult", boundary)); |
| 297 interventionHistogram.count(interventionResult); | 299 interventionHistogram.count(interventionResult); |
| 298 } | 300 } |
| 299 | 301 |
| 300 } // namespace blink | 302 } // namespace blink |
| OLD | NEW |