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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 PassRefPtrWillBeRawPtr<FontResource> FontResource::fetch(FetchRequest& request,
ResourceFetcher* fetcher) | 73 PassRefPtrWillBeRawPtr<FontResource> FontResource::fetch(FetchRequest& request,
ResourceFetcher* fetcher) |
74 { | 74 { |
75 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); | 75 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); |
76 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textFont); | 76 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textFont); |
77 return toFontResource(fetcher->requestResource(request, FontResourceFactory(
))); | 77 return toFontResource(fetcher->requestResource(request, FontResourceFactory(
))); |
78 } | 78 } |
79 | 79 |
80 FontResource::FontResource(const ResourceRequest& resourceRequest, const Resourc
eLoaderOptions& options) | 80 FontResource::FontResource(const ResourceRequest& resourceRequest, const Resourc
eLoaderOptions& options) |
81 : Resource(resourceRequest, Font, options) | 81 : Resource(resourceRequest, Font, options) |
82 , m_state(Unloaded) | 82 , m_loadLimitState(UnderLimit) |
83 , m_corsFailed(false) | 83 , m_corsFailed(false) |
84 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) | 84 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) |
85 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) | 85 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) |
86 { | 86 { |
87 } | 87 } |
88 | 88 |
89 FontResource::~FontResource() | 89 FontResource::~FontResource() |
90 { | 90 { |
91 } | 91 } |
92 | 92 |
93 void FontResource::didScheduleLoad() | 93 void FontResource::didScheduleLoad() |
94 { | 94 { |
95 if (m_state == Unloaded) | 95 if (getStatus() == NotStarted) |
96 m_state = LoadScheduled; | 96 setStatus(LoadStartScheduled); |
97 } | 97 } |
98 | 98 |
99 void FontResource::didUnscheduleLoad() | 99 void FontResource::didUnscheduleLoad() |
100 { | 100 { |
101 if (m_state == LoadScheduled) | 101 if (getStatus() == LoadStartScheduled) |
102 m_state = Unloaded; | 102 setStatus(NotStarted); |
103 } | 103 } |
104 | 104 |
105 void FontResource::load(ResourceFetcher*) | 105 void FontResource::load(ResourceFetcher*) |
106 { | 106 { |
107 // Don't load the file yet. Wait for an access before triggering the load. | 107 // Don't load the file yet. Wait for an access before triggering the load. |
108 setLoading(true); | |
109 if (!m_revalidatingRequest.isNull()) | 108 if (!m_revalidatingRequest.isNull()) |
110 m_state = Unloaded; | 109 setStatus(NotStarted); |
111 } | 110 } |
112 | 111 |
113 void FontResource::didAddClient(ResourceClient* c) | 112 void FontResource::didAddClient(ResourceClient* c) |
114 { | 113 { |
115 ASSERT(FontResourceClient::isExpectedType(c)); | 114 ASSERT(FontResourceClient::isExpectedType(c)); |
116 Resource::didAddClient(c); | 115 Resource::didAddClient(c); |
117 if (!isLoading()) | 116 if (isLoaded()) |
118 static_cast<FontResourceClient*>(c)->fontLoaded(this); | 117 static_cast<FontResourceClient*>(c)->fontLoaded(this); |
119 if (m_state == ShortLimitExceeded || m_state == LongLimitExceeded) | 118 if (m_loadLimitState == ShortLimitExceeded || m_loadLimitState == LongLimitE
xceeded) |
120 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); | 119 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
121 if (m_state == LongLimitExceeded) | 120 if (m_loadLimitState == LongLimitExceeded) |
122 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); | 121 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); |
123 } | 122 } |
124 | 123 |
125 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) | 124 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) |
126 { | 125 { |
127 if (stillNeedsLoad()) { | 126 if (stillNeedsLoad()) { |
128 m_state = LoadInitiated; | |
129 Resource::load(dl); | 127 Resource::load(dl); |
130 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_
FROM_HERE); | 128 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_
FROM_HERE); |
131 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FR
OM_HERE); | 129 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FR
OM_HERE); |
132 | 130 |
133 ResourceClientWalker<FontResourceClient> walker(m_clients); | 131 ResourceClientWalker<FontResourceClient> walker(m_clients); |
134 while (FontResourceClient* client = walker.next()) | 132 while (FontResourceClient* client = walker.next()) |
135 client->didStartFontLoad(this); | 133 client->didStartFontLoad(this); |
136 } | 134 } |
137 } | 135 } |
138 | 136 |
(...skipping 21 matching lines...) Expand all Loading... |
160 | 158 |
161 bool FontResource::isSafeToUnlock() const | 159 bool FontResource::isSafeToUnlock() const |
162 { | 160 { |
163 return m_data->hasOneRef(); | 161 return m_data->hasOneRef(); |
164 } | 162 } |
165 | 163 |
166 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) | 164 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) |
167 { | 165 { |
168 if (!isLoading()) | 166 if (!isLoading()) |
169 return; | 167 return; |
170 ASSERT(m_state == LoadInitiated); | 168 ASSERT(m_loadLimitState == UnderLimit); |
171 m_state = ShortLimitExceeded; | 169 m_loadLimitState = ShortLimitExceeded; |
172 ResourceClientWalker<FontResourceClient> walker(m_clients); | 170 ResourceClientWalker<FontResourceClient> walker(m_clients); |
173 while (FontResourceClient* client = walker.next()) | 171 while (FontResourceClient* client = walker.next()) |
174 client->fontLoadShortLimitExceeded(this); | 172 client->fontLoadShortLimitExceeded(this); |
175 } | 173 } |
176 | 174 |
177 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) | 175 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) |
178 { | 176 { |
179 if (!isLoading()) | 177 if (!isLoading()) |
180 return; | 178 return; |
181 ASSERT(m_state == ShortLimitExceeded); | 179 ASSERT(m_loadLimitState == ShortLimitExceeded); |
182 m_state = LongLimitExceeded; | 180 m_loadLimitState = LongLimitExceeded; |
183 ResourceClientWalker<FontResourceClient> walker(m_clients); | 181 ResourceClientWalker<FontResourceClient> walker(m_clients); |
184 while (FontResourceClient* client = walker.next()) | 182 while (FontResourceClient* client = walker.next()) |
185 client->fontLoadLongLimitExceeded(this); | 183 client->fontLoadLongLimitExceeded(this); |
186 } | 184 } |
187 | 185 |
188 void FontResource::allClientsRemoved() | 186 void FontResource::allClientsRemoved() |
189 { | 187 { |
190 m_fontData.clear(); | 188 m_fontData.clear(); |
191 Resource::allClientsRemoved(); | 189 Resource::allClientsRemoved(); |
192 } | 190 } |
193 | 191 |
194 void FontResource::checkNotify() | 192 void FontResource::checkNotify() |
195 { | 193 { |
196 m_fontLoadShortLimitTimer.stop(); | 194 m_fontLoadShortLimitTimer.stop(); |
197 m_fontLoadLongLimitTimer.stop(); | 195 m_fontLoadLongLimitTimer.stop(); |
198 ResourceClientWalker<FontResourceClient> w(m_clients); | 196 ResourceClientWalker<FontResourceClient> w(m_clients); |
199 while (FontResourceClient* c = w.next()) | 197 while (FontResourceClient* c = w.next()) |
200 c->fontLoaded(this); | 198 c->fontLoaded(this); |
201 } | 199 } |
202 | 200 |
203 } // namespace blink | 201 } // namespace blink |
OLD | NEW |