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/CSSFontSelector.h" | 9 #include "core/css/CSSFontSelector.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, | 53 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, |
| 54 CSSFontSelector* fontSelector, | 54 CSSFontSelector* fontSelector, |
| 55 FontDisplay display) | 55 FontDisplay display) |
| 56 : m_font(font), | 56 : m_font(font), |
| 57 m_fontSelector(fontSelector), | 57 m_fontSelector(fontSelector), |
| 58 m_display(display), | 58 m_display(display), |
| 59 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), | 59 m_period(BlockPeriod), |
| 60 m_histograms(font->url().protocolIsData() | 60 m_histograms(font->url().protocolIsData() |
| 61 ? FontLoadHistograms::FromDataURL | 61 ? FontLoadHistograms::FromDataURL |
| 62 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache | 62 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache |
| 63 : FontLoadHistograms::FromUnknown), | 63 : FontLoadHistograms::FromUnknown), |
| 64 m_isInterventionTriggered(false) { | 64 m_isInterventionTriggered(false) { |
| 65 ThreadState::current()->registerPreFinalizer(this); | 65 ThreadState::current()->registerPreFinalizer(this); |
| 66 m_font->addClient(this); | 66 m_font->addClient(this); |
| 67 | 67 |
| 68 if (shouldTriggerWebFontsIntervention()) { | 68 if (shouldTriggerWebFontsIntervention()) { |
| 69 m_isInterventionTriggered = true; | 69 m_isInterventionTriggered = true; |
| 70 m_period = SwapPeriod; | 70 m_period = SwapPeriod; |
| 71 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( | 71 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( |
| 72 OtherMessageSource, InfoMessageLevel, | 72 OtherMessageSource, InfoMessageLevel, |
| 73 "Slow network is detected. Fallback font will be used while loading: " + | 73 "Slow network is detected. Fallback font will be used while loading: " + |
| 74 m_font->url().elidedString())); | 74 m_font->url().elidedString())); |
| 75 } | 75 } |
| 76 | |
| 77 if (m_display == FontDisplaySwap && | |
| 78 !m_font->resourceRequest().isCacheAwareLoadingActivated()) | |
| 79 m_period = SwapPeriod; | |
| 76 } | 80 } |
| 77 | 81 |
| 78 RemoteFontFaceSource::~RemoteFontFaceSource() {} | 82 RemoteFontFaceSource::~RemoteFontFaceSource() {} |
| 79 | 83 |
| 80 void RemoteFontFaceSource::dispose() { | 84 void RemoteFontFaceSource::dispose() { |
| 81 m_font->removeClient(this); | 85 m_font->removeClient(this); |
| 82 m_font = nullptr; | 86 m_font = nullptr; |
| 83 pruneTable(); | 87 pruneTable(); |
| 84 } | 88 } |
| 85 | 89 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 155 |
| 152 if (m_display == FontDisplayBlock || | 156 if (m_display == FontDisplayBlock || |
| 153 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) | 157 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) |
| 154 switchToSwapPeriod(); | 158 switchToSwapPeriod(); |
| 155 else if (m_display == FontDisplayFallback) | 159 else if (m_display == FontDisplayFallback) |
| 156 switchToFailurePeriod(); | 160 switchToFailurePeriod(); |
| 157 | 161 |
| 158 m_histograms.longLimitExceeded(m_isInterventionTriggered); | 162 m_histograms.longLimitExceeded(m_isInterventionTriggered); |
| 159 } | 163 } |
| 160 | 164 |
| 165 void RemoteFontFaceSource::willReloadAfterDiskCacheMiss(const FontResource*) { | |
| 166 if (m_display == FontDisplaySwap) | |
| 167 switchToSwapPeriod(); | |
| 168 } | |
| 169 | |
| 161 void RemoteFontFaceSource::switchToSwapPeriod() { | 170 void RemoteFontFaceSource::switchToSwapPeriod() { |
| 162 ASSERT(m_period == BlockPeriod); | 171 ASSERT(m_period == BlockPeriod); |
| 163 m_period = SwapPeriod; | 172 m_period = SwapPeriod; |
| 164 | 173 |
| 165 pruneTable(); | 174 pruneTable(); |
| 166 if (m_face) { | 175 if (m_face) { |
| 167 m_fontSelector->fontFaceInvalidated(); | 176 m_fontSelector->fontFaceInvalidated(); |
| 168 m_face->didBecomeVisibleFallback(this); | 177 m_face->didBecomeVisibleFallback(this); |
| 169 } | 178 } |
| 170 | 179 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 return nullptr; | 236 return nullptr; |
| 228 } | 237 } |
| 229 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create( | 238 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create( |
| 230 this, m_period == BlockPeriod ? CSSCustomFontData::InvisibleFallback | 239 this, m_period == BlockPeriod ? CSSCustomFontData::InvisibleFallback |
| 231 : CSSCustomFontData::VisibleFallback); | 240 : CSSCustomFontData::VisibleFallback); |
| 232 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); | 241 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); |
| 233 } | 242 } |
| 234 | 243 |
| 235 void RemoteFontFaceSource::beginLoadIfNeeded() { | 244 void RemoteFontFaceSource::beginLoadIfNeeded() { |
| 236 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { | 245 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { |
| 246 // TODO(shaochuan): Cache-aware loading may be deactivated in startLoad(), | |
| 247 // set |m_period| to correct value if deactivated. crbug.com/632580 | |
| 248 bool wasCacheAwareLoadingActivated = | |
| 249 m_font->resourceRequest().isCacheAwareLoadingActivated(); | |
| 237 m_fontSelector->document()->fetcher()->startLoad(m_font); | 250 m_fontSelector->document()->fetcher()->startLoad(m_font); |
| 251 if (m_display == FontDisplaySwap && wasCacheAwareLoadingActivated && | |
| 252 !m_font->resourceRequest().isCacheAwareLoadingActivated()) | |
| 253 m_period = SwapPeriod; | |
|
Kunihiko Sakamoto
2016/10/21 05:41:07
You should call switchToSwapPeriod() instead, so t
Shao-Chuan Lee
2016/10/21 07:18:01
Done.
| |
| 254 | |
| 238 if (!m_font->isLoaded()) | 255 if (!m_font->isLoaded()) |
| 239 m_font->startLoadLimitTimers(); | 256 m_font->startLoadLimitTimers(); |
| 240 m_histograms.loadStarted(); | 257 m_histograms.loadStarted(); |
| 241 } | 258 } |
| 242 | 259 |
| 243 if (m_face) | 260 if (m_face) |
| 244 m_face->didBeginLoad(); | 261 m_face->didBeginLoad(); |
| 245 } | 262 } |
| 246 | 263 |
| 247 DEFINE_TRACE(RemoteFontFaceSource) { | 264 DEFINE_TRACE(RemoteFontFaceSource) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 return Miss; | 441 return Miss; |
| 425 case FromUnknown: | 442 case FromUnknown: |
| 426 // Fall through. | 443 // Fall through. |
| 427 default: | 444 default: |
| 428 NOTREACHED(); | 445 NOTREACHED(); |
| 429 } | 446 } |
| 430 return Miss; | 447 return Miss; |
| 431 } | 448 } |
| 432 | 449 |
| 433 } // namespace blink | 450 } // namespace blink |
| OLD | NEW |