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 20 matching lines...) Expand all Loading... |
31 #include "core/fetch/ResourceClientWalker.h" | 31 #include "core/fetch/ResourceClientWalker.h" |
32 #include "core/fetch/ResourceFetcher.h" | 32 #include "core/fetch/ResourceFetcher.h" |
33 #include "platform/SharedBuffer.h" | 33 #include "platform/SharedBuffer.h" |
34 #include "platform/fonts/FontCustomPlatformData.h" | 34 #include "platform/fonts/FontCustomPlatformData.h" |
35 #include "platform/fonts/FontPlatformData.h" | 35 #include "platform/fonts/FontPlatformData.h" |
36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
37 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 static const double fontLoadWaitLimitSec = 3.0; | 41 // Durations of font-display periods. |
| 42 // https://tabatkins.github.io/specs/css-font-display/#font-display-desc |
| 43 static const double fontLoadWaitShortLimitSec = 0.1; |
| 44 static const double fontLoadWaitLongLimitSec = 3.0; |
42 | 45 |
43 enum FontPackageFormat { | 46 enum FontPackageFormat { |
44 PackageFormatUnknown, | 47 PackageFormatUnknown, |
45 PackageFormatSFNT, | 48 PackageFormatSFNT, |
46 PackageFormatWOFF, | 49 PackageFormatWOFF, |
47 PackageFormatWOFF2, | 50 PackageFormatWOFF2, |
48 PackageFormatSVG, | 51 PackageFormatSVG, |
49 PackageFormatEnumMax | 52 PackageFormatEnumMax |
50 }; | 53 }; |
51 | 54 |
(...skipping 18 matching lines...) Expand all Loading... |
70 ResourcePtr<FontResource> FontResource::fetch(FetchRequest& request, ResourceFet
cher* fetcher) | 73 ResourcePtr<FontResource> FontResource::fetch(FetchRequest& request, ResourceFet
cher* fetcher) |
71 { | 74 { |
72 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); | 75 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); |
73 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textFont); | 76 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textFont); |
74 return toFontResource(fetcher->requestResource(request, FontResourceFactory(
))); | 77 return toFontResource(fetcher->requestResource(request, FontResourceFactory(
))); |
75 } | 78 } |
76 | 79 |
77 FontResource::FontResource(const ResourceRequest& resourceRequest) | 80 FontResource::FontResource(const ResourceRequest& resourceRequest) |
78 : Resource(resourceRequest, Font) | 81 : Resource(resourceRequest, Font) |
79 , m_state(Unloaded) | 82 , m_state(Unloaded) |
80 , m_exceedsFontLoadWaitLimit(false) | |
81 , m_corsFailed(false) | 83 , m_corsFailed(false) |
82 , m_fontLoadWaitLimitTimer(this, &FontResource::fontLoadWaitLimitCallback) | 84 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) |
| 85 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) |
83 { | 86 { |
84 } | 87 } |
85 | 88 |
86 FontResource::~FontResource() | 89 FontResource::~FontResource() |
87 { | 90 { |
88 } | 91 } |
89 | 92 |
90 void FontResource::didScheduleLoad() | 93 void FontResource::didScheduleLoad() |
91 { | 94 { |
92 if (m_state == Unloaded) | 95 if (m_state == Unloaded) |
(...skipping 21 matching lines...) Expand all Loading... |
114 Resource::didAddClient(c); | 117 Resource::didAddClient(c); |
115 if (!isLoading()) | 118 if (!isLoading()) |
116 static_cast<FontResourceClient*>(c)->fontLoaded(this); | 119 static_cast<FontResourceClient*>(c)->fontLoaded(this); |
117 } | 120 } |
118 | 121 |
119 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) | 122 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) |
120 { | 123 { |
121 if (m_state != LoadInitiated) { | 124 if (m_state != LoadInitiated) { |
122 m_state = LoadInitiated; | 125 m_state = LoadInitiated; |
123 Resource::load(dl, m_options); | 126 Resource::load(dl, m_options); |
124 m_fontLoadWaitLimitTimer.startOneShot(fontLoadWaitLimitSec, BLINK_FROM_H
ERE); | 127 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_
FROM_HERE); |
| 128 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FR
OM_HERE); |
125 | 129 |
126 ResourceClientWalker<FontResourceClient> walker(m_clients); | 130 ResourceClientWalker<FontResourceClient> walker(m_clients); |
127 while (FontResourceClient* client = walker.next()) | 131 while (FontResourceClient* client = walker.next()) |
128 client->didStartFontLoad(this); | 132 client->didStartFontLoad(this); |
129 } | 133 } |
130 } | 134 } |
131 | 135 |
132 bool FontResource::ensureCustomFontData() | 136 bool FontResource::ensureCustomFontData() |
133 { | 137 { |
134 if (!m_fontData && !errorOccurred() && !isLoading()) { | 138 if (!m_fontData && !errorOccurred() && !isLoading()) { |
(...skipping 14 matching lines...) Expand all Loading... |
149 { | 153 { |
150 ASSERT(m_fontData); | 154 ASSERT(m_fontData); |
151 return m_fontData->fontPlatformData(size, bold, italic, orientation); | 155 return m_fontData->fontPlatformData(size, bold, italic, orientation); |
152 } | 156 } |
153 | 157 |
154 bool FontResource::isSafeToUnlock() const | 158 bool FontResource::isSafeToUnlock() const |
155 { | 159 { |
156 return m_data->hasOneRef(); | 160 return m_data->hasOneRef(); |
157 } | 161 } |
158 | 162 |
159 void FontResource::fontLoadWaitLimitCallback(Timer<FontResource>*) | 163 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) |
160 { | 164 { |
161 if (!isLoading()) | 165 if (!isLoading()) |
162 return; | 166 return; |
163 m_exceedsFontLoadWaitLimit = true; | |
164 ResourceClientWalker<FontResourceClient> walker(m_clients); | 167 ResourceClientWalker<FontResourceClient> walker(m_clients); |
165 while (FontResourceClient* client = walker.next()) | 168 while (FontResourceClient* client = walker.next()) |
166 client->fontLoadWaitLimitExceeded(this); | 169 client->fontLoadShortLimitExceeded(this); |
| 170 } |
| 171 |
| 172 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) |
| 173 { |
| 174 if (!isLoading()) |
| 175 return; |
| 176 ResourceClientWalker<FontResourceClient> walker(m_clients); |
| 177 while (FontResourceClient* client = walker.next()) |
| 178 client->fontLoadLongLimitExceeded(this); |
167 } | 179 } |
168 | 180 |
169 void FontResource::allClientsRemoved() | 181 void FontResource::allClientsRemoved() |
170 { | 182 { |
171 m_fontData.clear(); | 183 m_fontData.clear(); |
172 Resource::allClientsRemoved(); | 184 Resource::allClientsRemoved(); |
173 } | 185 } |
174 | 186 |
175 void FontResource::checkNotify() | 187 void FontResource::checkNotify() |
176 { | 188 { |
177 m_fontLoadWaitLimitTimer.stop(); | 189 m_fontLoadShortLimitTimer.stop(); |
| 190 m_fontLoadLongLimitTimer.stop(); |
178 ResourceClientWalker<FontResourceClient> w(m_clients); | 191 ResourceClientWalker<FontResourceClient> w(m_clients); |
179 while (FontResourceClient* c = w.next()) | 192 while (FontResourceClient* c = w.next()) |
180 c->fontLoaded(this); | 193 c->fontLoaded(this); |
181 } | 194 } |
182 | 195 |
183 } | 196 } |
OLD | NEW |