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" |
| 11 #include "core/fetch/ResourceFetcher.h" | 11 #include "core/fetch/ResourceFetcher.h" |
| 12 #include "core/inspector/ConsoleMessage.h" | 12 #include "core/inspector/ConsoleMessage.h" |
| 13 #include "core/loader/FrameLoaderClient.h" | 13 #include "core/loader/FrameLoaderClient.h" |
| 14 #include "core/page/NetworkStateNotifier.h" | 14 #include "core/page/NetworkStateNotifier.h" |
| 15 #include "platform/Histogram.h" | 15 #include "platform/Histogram.h" |
| 16 #include "platform/RuntimeEnabledFeatures.h" | 16 #include "platform/RuntimeEnabledFeatures.h" |
| 17 #include "platform/fonts/FontCache.h" | 17 #include "platform/fonts/FontCache.h" |
| 18 #include "platform/fonts/FontDescription.h" | 18 #include "platform/fonts/FontDescription.h" |
| 19 #include "platform/fonts/SimpleFontData.h" | 19 #include "platform/fonts/SimpleFontData.h" |
| 20 #include "platform/network/ResourceLoadPriority.h" | |
| 20 #include "public/platform/WebEffectiveConnectionType.h" | 21 #include "public/platform/WebEffectiveConnectionType.h" |
| 21 #include "wtf/CurrentTime.h" | 22 #include "wtf/CurrentTime.h" |
| 22 | 23 |
| 23 namespace blink { | 24 namespace blink { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 bool isEffectiveConnectionTypeSlowFor(Document* document) { | 28 bool isEffectiveConnectionTypeSlowFor(Document* document) { |
| 28 WebEffectiveConnectionType type = | 29 WebEffectiveConnectionType type = |
| 29 document->frame()->loader().client()->getEffectiveConnectionType(); | 30 document->frame()->loader().client()->getEffectiveConnectionType(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 ThreadState::current()->registerPreFinalizer(this); | 67 ThreadState::current()->registerPreFinalizer(this); |
| 67 m_font->addClient(this); | 68 m_font->addClient(this); |
| 68 | 69 |
| 69 if (shouldTriggerWebFontsIntervention()) { | 70 if (shouldTriggerWebFontsIntervention()) { |
| 70 m_isInterventionTriggered = true; | 71 m_isInterventionTriggered = true; |
| 71 m_period = SwapPeriod; | 72 m_period = SwapPeriod; |
| 72 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( | 73 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( |
| 73 OtherMessageSource, InfoMessageLevel, | 74 OtherMessageSource, InfoMessageLevel, |
| 74 "Slow network is detected. Fallback font will be used while loading: " + | 75 "Slow network is detected. Fallback font will be used while loading: " + |
| 75 m_font->url().elidedString())); | 76 m_font->url().elidedString())); |
| 77 if (!font->url().protocolIsData() && !font->isLoaded() && | |
|
Takashi Toyoshima
2016/11/14 03:53:56
|font| is shared by multiple RemoteFontFaceSource
tbansal1
2016/11/14 20:12:08
Done.
| |
| 78 m_display == FontDisplayAuto) { | |
| 79 m_font->didChangePriority(ResourceLoadPriorityVeryLow, 0); | |
| 80 } | |
| 76 } | 81 } |
| 77 } | 82 } |
| 78 | 83 |
| 79 RemoteFontFaceSource::~RemoteFontFaceSource() {} | 84 RemoteFontFaceSource::~RemoteFontFaceSource() {} |
| 80 | 85 |
| 81 void RemoteFontFaceSource::dispose() { | 86 void RemoteFontFaceSource::dispose() { |
| 82 m_font->removeClient(this); | 87 m_font->removeClient(this); |
| 83 m_font = nullptr; | 88 m_font = nullptr; |
| 84 pruneTable(); | 89 pruneTable(); |
| 85 } | 90 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 if (!temporaryFont) { | 233 if (!temporaryFont) { |
| 229 ASSERT_NOT_REACHED(); | 234 ASSERT_NOT_REACHED(); |
| 230 return nullptr; | 235 return nullptr; |
| 231 } | 236 } |
| 232 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create( | 237 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create( |
| 233 this, m_period == BlockPeriod ? CSSCustomFontData::InvisibleFallback | 238 this, m_period == BlockPeriod ? CSSCustomFontData::InvisibleFallback |
| 234 : CSSCustomFontData::VisibleFallback); | 239 : CSSCustomFontData::VisibleFallback); |
| 235 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); | 240 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); |
| 236 } | 241 } |
| 237 | 242 |
| 238 void RemoteFontFaceSource::beginLoadIfNeeded() { | 243 void RemoteFontFaceSource::beginLoadIfNeeded() { |
|
Takashi Toyoshima
2016/11/14 03:53:56
This is called for each RemoteFontFaceSource insta
tbansal1
2016/11/14 20:12:08
Done.
| |
| 239 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { | 244 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { |
| 240 m_fontSelector->document()->fetcher()->startLoad(m_font); | 245 m_fontSelector->document()->fetcher()->startLoad(m_font); |
| 241 if (!m_font->isLoaded()) | 246 if (!m_font->isLoaded()) |
| 242 m_font->startLoadLimitTimers(); | 247 m_font->startLoadLimitTimers(); |
| 243 m_histograms.loadStarted(); | 248 m_histograms.loadStarted(); |
| 244 } | 249 } |
| 245 | 250 |
| 246 if (m_face) | 251 if (m_face) |
| 247 m_face->didBeginLoad(); | 252 m_face->didBeginLoad(); |
| 248 } | 253 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 return Miss; | 457 return Miss; |
| 453 case FromUnknown: | 458 case FromUnknown: |
| 454 // Fall through. | 459 // Fall through. |
| 455 default: | 460 default: |
| 456 NOTREACHED(); | 461 NOTREACHED(); |
| 457 } | 462 } |
| 458 return Miss; | 463 return Miss; |
| 459 } | 464 } |
| 460 | 465 |
| 461 } // namespace blink | 466 } // namespace blink |
| OLD | NEW |