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 "config.h" | 5 #include "config.h" |
6 #include "core/css/RemoteFontFaceSource.h" | 6 #include "core/css/RemoteFontFaceSource.h" |
7 | 7 |
8 #include "FetchInitiatorTypeNames.h" | |
8 #include "core/css/CSSCustomFontData.h" | 9 #include "core/css/CSSCustomFontData.h" |
9 #include "core/css/CSSFontFace.h" | 10 #include "core/css/CSSFontFace.h" |
11 #include "core/css/CSSFontSelector.h" | |
12 #include "core/fetch/ResourceFetcher.h" | |
10 #include "platform/fonts/FontCache.h" | 13 #include "platform/fonts/FontCache.h" |
11 #include "platform/fonts/FontDescription.h" | 14 #include "platform/fonts/FontDescription.h" |
12 #include "platform/fonts/SimpleFontData.h" | 15 #include "platform/fonts/SimpleFontData.h" |
13 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
14 #include "wtf/CurrentTime.h" | 17 #include "wtf/CurrentTime.h" |
15 | 18 |
16 namespace WebCore { | 19 namespace WebCore { |
17 | 20 |
18 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font) | 21 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font) |
19 : m_font(font) | 22 : m_font(font) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 78 |
76 void RemoteFontFaceSource::fontLoadWaitLimitExceeded(FontResource*) | 79 void RemoteFontFaceSource::fontLoadWaitLimitExceeded(FontResource*) |
77 { | 80 { |
78 pruneTable(); | 81 pruneTable(); |
79 if (m_face) | 82 if (m_face) |
80 m_face->fontLoadWaitLimitExceeded(this); | 83 m_face->fontLoadWaitLimitExceeded(this); |
81 | 84 |
82 m_histograms.recordFallbackTime(m_font.get()); | 85 m_histograms.recordFallbackTime(m_font.get()); |
83 } | 86 } |
84 | 87 |
88 void RemoteFontFaceSource::corsFailed(FontResource*) | |
89 { | |
90 pruneTable(); | |
91 | |
92 if (m_face) { | |
93 Document* document = m_face->fontSelector() ? m_face->fontSelector()->do cument() : 0; | |
94 if (document) { | |
95 FetchRequest request(ResourceRequest(m_font->url()), FetchInitiatorT ypeNames::css); | |
96 m_font->removeClient(this); | |
Kunihiko Sakamoto
2014/04/09 10:24:18
CSSFontFaceSrcValue have a reference to this FontR
bashi
2014/04/10 03:40:56
Thank you for pointing this out. But it's difficul
| |
97 m_font = document->fetcher()->fetchFont(request); | |
98 m_font->addClient(this); | |
99 m_face->fontSelector()->beginLoadingFontSoon(m_font.get()); | |
100 } else { | |
101 m_face->fontLoaded(this); | |
102 } | |
103 } | |
104 } | |
105 | |
85 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri ption& fontDescription) | 106 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri ption& fontDescription) |
86 { | 107 { |
87 if (!isLoaded()) | 108 if (!isLoaded()) |
88 return createLoadingFallbackFontData(fontDescription); | 109 return createLoadingFallbackFontData(fontDescription); |
89 | 110 |
90 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef . | 111 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef . |
91 if (!m_font->ensureCustomFontData()) | 112 if (!m_font->ensureCustomFontData()) |
92 return nullptr; | 113 return nullptr; |
93 | 114 |
94 m_histograms.recordFallbackTime(m_font.get()); | 115 m_histograms.recordFallbackTime(m_font.get()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 if (m_loadStartTime > 0 && font && !font->isLoading()) { | 170 if (m_loadStartTime > 0 && font && !font->isLoading()) { |
150 int duration = static_cast<int>(currentTimeMS() - m_loadStartTime); | 171 int duration = static_cast<int>(currentTimeMS() - m_loadStartTime); |
151 blink::Platform::current()->histogramCustomCounts(histogramName(font), d uration, 0, 10000, 50); | 172 blink::Platform::current()->histogramCustomCounts(histogramName(font), d uration, 0, 10000, 50); |
152 m_loadStartTime = -1; | 173 m_loadStartTime = -1; |
153 | 174 |
154 enum { Miss, Hit, DataUrl, CacheHitEnumMax }; | 175 enum { Miss, Hit, DataUrl, CacheHitEnumMax }; |
155 int histogramValue = font->url().protocolIsData() ? DataUrl | 176 int histogramValue = font->url().protocolIsData() ? DataUrl |
156 : font->response().wasCached() ? Hit | 177 : font->response().wasCached() ? Hit |
157 : Miss; | 178 : Miss; |
158 blink::Platform::current()->histogramEnumeration("WebFont.CacheHit", his togramValue, CacheHitEnumMax); | 179 blink::Platform::current()->histogramEnumeration("WebFont.CacheHit", his togramValue, CacheHitEnumMax); |
180 | |
181 if (!font->errorOccurred()) { | |
182 enum { CORSSuccess, CORSFail, CORSEnumMax }; | |
183 int corsValue = font->options().corsEnabled == IsCORSEnabled ? CORSS uccess : CORSFail; | |
184 blink::Platform::current()->histogramEnumeration("WebFont.CORSSucces s", corsValue, CORSEnumMax); | |
185 } | |
159 } | 186 } |
160 } | 187 } |
161 | 188 |
162 const char* RemoteFontFaceSource::FontLoadHistograms::histogramName(const FontRe source* font) | 189 const char* RemoteFontFaceSource::FontLoadHistograms::histogramName(const FontRe source* font) |
163 { | 190 { |
164 if (font->errorOccurred()) | 191 if (font->errorOccurred()) |
165 return "WebFont.DownloadTime.LoadError"; | 192 return "WebFont.DownloadTime.LoadError"; |
166 | 193 |
167 unsigned size = font->encodedSize(); | 194 unsigned size = font->encodedSize(); |
168 if (size < 10 * 1024) | 195 if (size < 10 * 1024) |
169 return "WebFont.DownloadTime.0.Under10KB"; | 196 return "WebFont.DownloadTime.0.Under10KB"; |
170 if (size < 50 * 1024) | 197 if (size < 50 * 1024) |
171 return "WebFont.DownloadTime.1.10KBTo50KB"; | 198 return "WebFont.DownloadTime.1.10KBTo50KB"; |
172 if (size < 100 * 1024) | 199 if (size < 100 * 1024) |
173 return "WebFont.DownloadTime.2.50KBTo100KB"; | 200 return "WebFont.DownloadTime.2.50KBTo100KB"; |
174 if (size < 1024 * 1024) | 201 if (size < 1024 * 1024) |
175 return "WebFont.DownloadTime.3.100KBTo1MB"; | 202 return "WebFont.DownloadTime.3.100KBTo1MB"; |
176 return "WebFont.DownloadTime.4.Over1MB"; | 203 return "WebFont.DownloadTime.4.Over1MB"; |
177 } | 204 } |
178 | 205 |
179 } // namespace WebCore | 206 } // namespace WebCore |
OLD | NEW |