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; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 pruneTable(); | 131 pruneTable(); |
132 if (m_face) { | 132 if (m_face) { |
133 m_fontSelector->fontFaceInvalidated(); | 133 m_fontSelector->fontFaceInvalidated(); |
134 m_face->fontLoaded(this); | 134 m_face->fontLoaded(this); |
135 } | 135 } |
136 // Should not do anything after this line since the m_face->fontLoaded() | 136 // Should not do anything after this line since the m_face->fontLoaded() |
137 // above may trigger deleting this object. | 137 // above may trigger deleting this object. |
138 } | 138 } |
139 | 139 |
140 void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*) { | 140 void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*) { |
141 if (m_font->resourceRequest().isCacheAwareLoadingActivated()) | |
142 return; | |
143 | |
141 if (m_display == FontDisplayFallback) | 144 if (m_display == FontDisplayFallback) |
142 switchToSwapPeriod(); | 145 switchToSwapPeriod(); |
143 else if (m_display == FontDisplayOptional) | 146 else if (m_display == FontDisplayOptional) |
144 switchToFailurePeriod(); | 147 switchToFailurePeriod(); |
145 } | 148 } |
146 | 149 |
147 void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) { | 150 void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) { |
151 if (m_font->resourceRequest().isCacheAwareLoadingActivated()) | |
152 return; | |
153 | |
148 if (m_display == FontDisplayBlock || | 154 if (m_display == FontDisplayBlock || |
149 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) | 155 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) |
150 switchToSwapPeriod(); | 156 switchToSwapPeriod(); |
151 else if (m_display == FontDisplayFallback) | 157 else if (m_display == FontDisplayFallback) |
152 switchToFailurePeriod(); | 158 switchToFailurePeriod(); |
153 | 159 |
154 m_histograms.longLimitExceeded(m_isInterventionTriggered); | 160 m_histograms.longLimitExceeded(m_isInterventionTriggered); |
155 } | 161 } |
156 | 162 |
163 void RemoteFontFaceSource::willReloadAfterDiskCacheMiss(const FontResource*) { | |
164 if (m_display == FontDisplaySwap) | |
165 switchToSwapPeriod(); | |
166 | |
167 DCHECK(!m_font->resourceRequest().isCacheAwareLoadingActivated()); | |
168 if (m_font->loadLimitState() == FontResource::ShortLimitExceeded || | |
Kunihiko Sakamoto
2016/10/12 01:38:46
Now we know that the font have to be fetched from
| |
169 m_font->loadLimitState() == FontResource::LongLimitExceeded) | |
170 fontLoadShortLimitExceeded(m_font.get()); | |
171 if (m_font->loadLimitState() == FontResource::LongLimitExceeded) | |
172 fontLoadLongLimitExceeded(m_font.get()); | |
173 } | |
174 | |
157 void RemoteFontFaceSource::switchToSwapPeriod() { | 175 void RemoteFontFaceSource::switchToSwapPeriod() { |
158 ASSERT(m_period == BlockPeriod); | 176 ASSERT(m_period == BlockPeriod); |
159 m_period = SwapPeriod; | 177 m_period = SwapPeriod; |
160 | 178 |
161 pruneTable(); | 179 pruneTable(); |
162 if (m_face) { | 180 if (m_face) { |
163 m_fontSelector->fontFaceInvalidated(); | 181 m_fontSelector->fontFaceInvalidated(); |
164 m_face->didBecomeVisibleFallback(this); | 182 m_face->didBecomeVisibleFallback(this); |
165 } | 183 } |
166 | 184 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 return Miss; | 437 return Miss; |
420 case FromUnknown: | 438 case FromUnknown: |
421 // Fall through. | 439 // Fall through. |
422 default: | 440 default: |
423 NOTREACHED(); | 441 NOTREACHED(); |
424 } | 442 } |
425 return Miss; | 443 return Miss; |
426 } | 444 } |
427 | 445 |
428 } // namespace blink | 446 } // namespace blink |
OLD | NEW |