OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "SVGNames.h" | 39 #include "SVGNames.h" |
40 #include "core/dom/XMLDocument.h" | 40 #include "core/dom/XMLDocument.h" |
41 #include "core/html/HTMLCollection.h" | 41 #include "core/html/HTMLCollection.h" |
42 #include "core/svg/SVGFontElement.h" | 42 #include "core/svg/SVGFontElement.h" |
43 #endif | 43 #endif |
44 | 44 |
45 namespace WebCore { | 45 namespace WebCore { |
46 | 46 |
47 static const double fontLoadWaitLimitSec = 3.0; | 47 static const double fontLoadWaitLimitSec = 3.0; |
48 | 48 |
| 49 enum FontPackageFormat { |
| 50 PackageFormatUnknown, |
| 51 PackageFormatSFNT, |
| 52 PackageFormatWOFF, |
| 53 PackageFormatWOFF2, |
| 54 PackageFormatSVG, |
| 55 PackageFormatEnumMax |
| 56 }; |
| 57 |
| 58 static FontPackageFormat packageFormatOf(SharedBuffer* buffer) |
| 59 { |
| 60 if (buffer->size() < 4) |
| 61 return PackageFormatUnknown; |
| 62 |
| 63 const char* data = buffer->data(); |
| 64 if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') |
| 65 return PackageFormatWOFF; |
| 66 if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == '2') |
| 67 return PackageFormatWOFF2; |
| 68 return PackageFormatSFNT; |
| 69 } |
| 70 |
| 71 static void recordPackageFormatHistogram(FontPackageFormat format) |
| 72 { |
| 73 blink::Platform::current()->histogramEnumeration("WebFont.PackageFormat", fo
rmat, PackageFormatEnumMax); |
| 74 } |
| 75 |
49 FontResource::FontResource(const ResourceRequest& resourceRequest) | 76 FontResource::FontResource(const ResourceRequest& resourceRequest) |
50 : Resource(resourceRequest, Font) | 77 : Resource(resourceRequest, Font) |
51 , m_loadInitiated(false) | 78 , m_loadInitiated(false) |
52 , m_exceedsFontLoadWaitLimit(false) | 79 , m_exceedsFontLoadWaitLimit(false) |
53 , m_fontLoadWaitLimitTimer(this, &FontResource::fontLoadWaitLimitCallback) | 80 , m_fontLoadWaitLimitTimer(this, &FontResource::fontLoadWaitLimitCallback) |
54 { | 81 { |
55 } | 82 } |
56 | 83 |
57 FontResource::~FontResource() | 84 FontResource::~FontResource() |
58 { | 85 { |
(...skipping 25 matching lines...) Expand all Loading... |
84 while (FontResourceClient* client = walker.next()) | 111 while (FontResourceClient* client = walker.next()) |
85 client->didStartFontLoad(this); | 112 client->didStartFontLoad(this); |
86 } | 113 } |
87 } | 114 } |
88 | 115 |
89 bool FontResource::ensureCustomFontData() | 116 bool FontResource::ensureCustomFontData() |
90 { | 117 { |
91 if (!m_fontData && !errorOccurred() && !isLoading()) { | 118 if (!m_fontData && !errorOccurred() && !isLoading()) { |
92 if (m_data) | 119 if (m_data) |
93 m_fontData = FontCustomPlatformData::create(m_data.get()); | 120 m_fontData = FontCustomPlatformData::create(m_data.get()); |
94 if (!m_fontData) | 121 |
| 122 if (m_fontData) { |
| 123 recordPackageFormatHistogram(packageFormatOf(m_data.get())); |
| 124 } else { |
95 setStatus(DecodeError); | 125 setStatus(DecodeError); |
| 126 recordPackageFormatHistogram(PackageFormatUnknown); |
| 127 } |
96 } | 128 } |
97 return m_fontData; | 129 return m_fontData; |
98 } | 130 } |
99 | 131 |
100 FontPlatformData FontResource::platformDataFromCustomData(float size, bool bold,
bool italic, FontOrientation orientation, FontWidthVariant widthVariant) | 132 FontPlatformData FontResource::platformDataFromCustomData(float size, bool bold,
bool italic, FontOrientation orientation, FontWidthVariant widthVariant) |
101 { | 133 { |
102 #if ENABLE(SVG_FONTS) | 134 #if ENABLE(SVG_FONTS) |
103 if (m_externalSVGDocument) | 135 if (m_externalSVGDocument) |
104 return FontPlatformData(size, bold, italic); | 136 return FontPlatformData(size, bold, italic); |
105 #endif | 137 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
116 | 148 |
117 OwnPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("a
pplication/xml"); | 149 OwnPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("a
pplication/xml"); |
118 String svgSource = decoder->decode(m_data->data(), m_data->size()); | 150 String svgSource = decoder->decode(m_data->data(), m_data->size()); |
119 svgSource = svgSource + decoder->flush(); | 151 svgSource = svgSource + decoder->flush(); |
120 | 152 |
121 m_externalSVGDocument->setContent(svgSource); | 153 m_externalSVGDocument->setContent(svgSource); |
122 | 154 |
123 if (decoder->sawError()) | 155 if (decoder->sawError()) |
124 m_externalSVGDocument = nullptr; | 156 m_externalSVGDocument = nullptr; |
125 } | 157 } |
126 if (!m_externalSVGDocument) | 158 if (m_externalSVGDocument) { |
| 159 recordPackageFormatHistogram(PackageFormatSVG); |
| 160 } else { |
127 setStatus(DecodeError); | 161 setStatus(DecodeError); |
| 162 recordPackageFormatHistogram(PackageFormatUnknown); |
| 163 } |
128 } | 164 } |
129 | 165 |
130 return m_externalSVGDocument; | 166 return m_externalSVGDocument; |
131 } | 167 } |
132 | 168 |
133 SVGFontElement* FontResource::getSVGFontById(const String& fontName) const | 169 SVGFontElement* FontResource::getSVGFontById(const String& fontName) const |
134 { | 170 { |
135 RefPtrWillBeRawPtr<HTMLCollection> collection = m_externalSVGDocument->getEl
ementsByTagNameNS(SVGNames::fontTag.namespaceURI(), SVGNames::fontTag.localName(
)); | 171 RefPtrWillBeRawPtr<HTMLCollection> collection = m_externalSVGDocument->getEl
ementsByTagNameNS(SVGNames::fontTag.namespaceURI(), SVGNames::fontTag.localName(
)); |
136 if (!collection) | 172 if (!collection) |
137 return 0; | 173 return 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 219 |
184 void FontResource::checkNotify() | 220 void FontResource::checkNotify() |
185 { | 221 { |
186 m_fontLoadWaitLimitTimer.stop(); | 222 m_fontLoadWaitLimitTimer.stop(); |
187 ResourceClientWalker<FontResourceClient> w(m_clients); | 223 ResourceClientWalker<FontResourceClient> w(m_clients); |
188 while (FontResourceClient* c = w.next()) | 224 while (FontResourceClient* c = w.next()) |
189 c->fontLoaded(this); | 225 c->fontLoaded(this); |
190 } | 226 } |
191 | 227 |
192 } | 228 } |
OLD | NEW |