| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 RuntimeEnabledFeatures::webFontsInterventionV2With3GEnabled() || | 194 RuntimeEnabledFeatures::webFontsInterventionV2With3GEnabled() || |
| 194 RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); | 195 RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); |
| 195 | 196 |
| 196 bool networkIsSlow = | 197 bool networkIsSlow = |
| 197 isV2Enabled ? isEffectiveConnectionTypeSlowFor(m_fontSelector->document()) | 198 isV2Enabled ? isEffectiveConnectionTypeSlowFor(m_fontSelector->document()) |
| 198 : isConnectionTypeSlow(); | 199 : isConnectionTypeSlow(); |
| 199 | 200 |
| 200 return networkIsSlow && m_display == FontDisplayAuto; | 201 return networkIsSlow && m_display == FontDisplayAuto; |
| 201 } | 202 } |
| 202 | 203 |
| 204 bool RemoteFontFaceSource::isLowPriorityLoadingAllowedForRemoteFont() const { |
| 205 return m_isInterventionTriggered; |
| 206 } |
| 207 |
| 203 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData( | 208 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData( |
| 204 const FontDescription& fontDescription) { | 209 const FontDescription& fontDescription) { |
| 205 if (!isLoaded()) | 210 if (!isLoaded()) |
| 206 return createLoadingFallbackFontData(fontDescription); | 211 return createLoadingFallbackFontData(fontDescription); |
| 207 | 212 |
| 208 if (!m_font->ensureCustomFontData() || m_period == FailurePeriod) | 213 if (!m_font->ensureCustomFontData() || m_period == FailurePeriod) |
| 209 return nullptr; | 214 return nullptr; |
| 210 | 215 |
| 211 m_histograms.recordFallbackTime(m_font.get()); | 216 m_histograms.recordFallbackTime(m_font.get()); |
| 212 | 217 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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() { |
| 239 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { | 244 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { |
| 245 if (!m_font->url().protocolIsData() && !m_font->isLoaded() && |
| 246 m_display == FontDisplayAuto && |
| 247 m_font->isLowPriorityLoadingAllowedForRemoteFont()) { |
| 248 // Set the loading priority to VeryLow since this font is not required |
| 249 // for painting the text. |
| 250 m_font->didChangePriority(ResourceLoadPriorityVeryLow, 0); |
| 251 } |
| 240 m_fontSelector->document()->fetcher()->startLoad(m_font); | 252 m_fontSelector->document()->fetcher()->startLoad(m_font); |
| 241 if (!m_font->isLoaded()) | 253 if (!m_font->isLoaded()) |
| 242 m_font->startLoadLimitTimers(); | 254 m_font->startLoadLimitTimers(); |
| 243 m_histograms.loadStarted(); | 255 m_histograms.loadStarted(); |
| 244 } | 256 } |
| 245 | 257 |
| 246 if (m_face) | 258 if (m_face) |
| 247 m_face->didBeginLoad(); | 259 m_face->didBeginLoad(); |
| 248 } | 260 } |
| 249 | 261 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 return Miss; | 464 return Miss; |
| 453 case FromUnknown: | 465 case FromUnknown: |
| 454 // Fall through. | 466 // Fall through. |
| 455 default: | 467 default: |
| 456 NOTREACHED(); | 468 NOTREACHED(); |
| 457 } | 469 } |
| 458 return Miss; | 470 return Miss; |
| 459 } | 471 } |
| 460 | 472 |
| 461 } // namespace blink | 473 } // namespace blink |
| OLD | NEW |