| 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_display), |   64                    m_display), | 
|   65       m_isInterventionTriggered(false) { |   65       m_isInterventionTriggered(false) { | 
|   66   ThreadState::current()->registerPreFinalizer(this); |   66   ThreadState::current()->registerPreFinalizer(this); | 
|   67   m_font->addClient(this); |   67   m_font->addClient(this); | 
|   68  |   68  | 
|   69   if (shouldTriggerWebFontsIntervention()) { |   69   if (shouldTriggerWebFontsIntervention()) { | 
|   70     m_isInterventionTriggered = true; |   70     m_isInterventionTriggered = true; | 
|   71     m_period = SwapPeriod; |   71     m_period = SwapPeriod; | 
|   72     m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( |   72     m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( | 
|   73         OtherMessageSource, InfoMessageLevel, |   73         OtherMessageSource, InfoMessageLevel, | 
|   74         "Slow network is detected. Fallback font will be used while loading: " + |   74         "Slow network is detected. Fallback font will be used while loading: " + | 
|   75             m_font->url().elidedString())); |   75             m_font->url().elidedString())); | 
|   76   } |   76   } | 
 |   77  | 
 |   78   if (m_display == FontDisplaySwap && | 
 |   79       !m_font->resourceRequest().isCacheAwareLoadingActivated()) | 
 |   80     m_period = SwapPeriod; | 
|   77 } |   81 } | 
|   78  |   82  | 
|   79 RemoteFontFaceSource::~RemoteFontFaceSource() {} |   83 RemoteFontFaceSource::~RemoteFontFaceSource() {} | 
|   80  |   84  | 
|   81 void RemoteFontFaceSource::dispose() { |   85 void RemoteFontFaceSource::dispose() { | 
|   82   m_font->removeClient(this); |   86   m_font->removeClient(this); | 
|   83   m_font = nullptr; |   87   m_font = nullptr; | 
|   84   pruneTable(); |   88   pruneTable(); | 
|   85 } |   89 } | 
|   86  |   90  | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  154  |  158  | 
|  155   if (m_display == FontDisplayBlock || |  159   if (m_display == FontDisplayBlock || | 
|  156       (!m_isInterventionTriggered && m_display == FontDisplayAuto)) |  160       (!m_isInterventionTriggered && m_display == FontDisplayAuto)) | 
|  157     switchToSwapPeriod(); |  161     switchToSwapPeriod(); | 
|  158   else if (m_display == FontDisplayFallback) |  162   else if (m_display == FontDisplayFallback) | 
|  159     switchToFailurePeriod(); |  163     switchToFailurePeriod(); | 
|  160  |  164  | 
|  161   m_histograms.longLimitExceeded(m_isInterventionTriggered); |  165   m_histograms.longLimitExceeded(m_isInterventionTriggered); | 
|  162 } |  166 } | 
|  163  |  167  | 
 |  168 void RemoteFontFaceSource::willReloadAfterDiskCacheMiss(const FontResource*) { | 
 |  169   if (m_display == FontDisplaySwap) | 
 |  170     switchToSwapPeriod(); | 
 |  171 } | 
 |  172  | 
|  164 void RemoteFontFaceSource::switchToSwapPeriod() { |  173 void RemoteFontFaceSource::switchToSwapPeriod() { | 
|  165   ASSERT(m_period == BlockPeriod); |  174   ASSERT(m_period == BlockPeriod); | 
|  166   m_period = SwapPeriod; |  175   m_period = SwapPeriod; | 
|  167  |  176  | 
|  168   pruneTable(); |  177   pruneTable(); | 
|  169   if (m_face) { |  178   if (m_face) { | 
|  170     m_fontSelector->fontFaceInvalidated(); |  179     m_fontSelector->fontFaceInvalidated(); | 
|  171     m_face->didBecomeVisibleFallback(this); |  180     m_face->didBecomeVisibleFallback(this); | 
|  172   } |  181   } | 
|  173  |  182  | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  230     return nullptr; |  239     return nullptr; | 
|  231   } |  240   } | 
|  232   RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create( |  241   RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create( | 
|  233       this, m_period == BlockPeriod ? CSSCustomFontData::InvisibleFallback |  242       this, m_period == BlockPeriod ? CSSCustomFontData::InvisibleFallback | 
|  234                                     : CSSCustomFontData::VisibleFallback); |  243                                     : CSSCustomFontData::VisibleFallback); | 
|  235   return SimpleFontData::create(temporaryFont->platformData(), cssFontData); |  244   return SimpleFontData::create(temporaryFont->platformData(), cssFontData); | 
|  236 } |  245 } | 
|  237  |  246  | 
|  238 void RemoteFontFaceSource::beginLoadIfNeeded() { |  247 void RemoteFontFaceSource::beginLoadIfNeeded() { | 
|  239   if (m_fontSelector->document() && m_font->stillNeedsLoad()) { |  248   if (m_fontSelector->document() && m_font->stillNeedsLoad()) { | 
 |  249     // TODO(shaochuan): Cache-aware loading may be deactivated in startLoad(), | 
 |  250     // set |m_period| to correct value if deactivated. crbug.com/632580 | 
 |  251     bool wasCacheAwareLoadingActivated = | 
 |  252         m_font->resourceRequest().isCacheAwareLoadingActivated(); | 
|  240     m_fontSelector->document()->fetcher()->startLoad(m_font); |  253     m_fontSelector->document()->fetcher()->startLoad(m_font); | 
 |  254     if (m_display == FontDisplaySwap && wasCacheAwareLoadingActivated && | 
 |  255         !m_font->resourceRequest().isCacheAwareLoadingActivated()) | 
 |  256       switchToSwapPeriod(); | 
 |  257  | 
|  241     if (!m_font->isLoaded()) |  258     if (!m_font->isLoaded()) | 
|  242       m_font->startLoadLimitTimers(); |  259       m_font->startLoadLimitTimers(); | 
|  243     m_histograms.loadStarted(); |  260     m_histograms.loadStarted(); | 
|  244   } |  261   } | 
|  245  |  262  | 
|  246   if (m_face) |  263   if (m_face) | 
|  247     m_face->didBeginLoad(); |  264     m_face->didBeginLoad(); | 
|  248 } |  265 } | 
|  249  |  266  | 
|  250 DEFINE_TRACE(RemoteFontFaceSource) { |  267 DEFINE_TRACE(RemoteFontFaceSource) { | 
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  432       return Miss; |  449       return Miss; | 
|  433     case FromUnknown: |  450     case FromUnknown: | 
|  434     // Fall through. |  451     // Fall through. | 
|  435     default: |  452     default: | 
|  436       NOTREACHED(); |  453       NOTREACHED(); | 
|  437   } |  454   } | 
|  438   return Miss; |  455   return Miss; | 
|  439 } |  456 } | 
|  440  |  457  | 
|  441 }  // namespace blink |  458 }  // namespace blink | 
| OLD | NEW |