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) | 80 FontResource::FontResource(const ResourceRequest& resourceRequest) |
81 : Resource(resourceRequest, Font) | 81 : Resource(resourceRequest, Font) |
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*, const ResourceLoaderOptions& options) | 105 void FontResource::load(ResourceFetcher*, const ResourceLoaderOptions& options) |
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 m_options = options; | 108 m_options = options; |
110 if (!m_revalidatingRequest.isNull()) | 109 if (!m_revalidatingRequest.isNull()) |
111 m_state = Unloaded; | 110 setStatus(NotStarted); |
112 } | 111 } |
113 | 112 |
114 void FontResource::didAddClient(ResourceClient* c) | 113 void FontResource::didAddClient(ResourceClient* c) |
115 { | 114 { |
116 ASSERT(FontResourceClient::isExpectedType(c)); | 115 ASSERT(FontResourceClient::isExpectedType(c)); |
117 Resource::didAddClient(c); | 116 Resource::didAddClient(c); |
118 if (!isLoading()) | 117 if (isLoaded()) |
119 static_cast<FontResourceClient*>(c)->fontLoaded(this); | 118 static_cast<FontResourceClient*>(c)->fontLoaded(this); |
120 if (m_state == ShortLimitExceeded || m_state == LongLimitExceeded) | 119 if (m_loadLimitState == ShortLimitExceeded || m_loadLimitState == LongLimitE
xceeded) |
121 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); | 120 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
122 if (m_state == LongLimitExceeded) | 121 if (m_loadLimitState == LongLimitExceeded) |
123 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); | 122 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); |
124 } | 123 } |
125 | 124 |
126 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) | 125 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) |
127 { | 126 { |
128 if (stillNeedsLoad()) { | 127 if (stillNeedsLoad()) { |
129 m_state = LoadInitiated; | |
130 Resource::load(dl, m_options); | 128 Resource::load(dl, m_options); |
131 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_
FROM_HERE); | 129 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_
FROM_HERE); |
132 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FR
OM_HERE); | 130 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FR
OM_HERE); |
133 | 131 |
134 ResourceClientWalker<FontResourceClient> walker(m_clients); | 132 ResourceClientWalker<FontResourceClient> walker(m_clients); |
135 while (FontResourceClient* client = walker.next()) | 133 while (FontResourceClient* client = walker.next()) |
136 client->didStartFontLoad(this); | 134 client->didStartFontLoad(this); |
137 } | 135 } |
138 } | 136 } |
139 | 137 |
(...skipping 21 matching lines...) Expand all Loading... |
161 | 159 |
162 bool FontResource::isSafeToUnlock() const | 160 bool FontResource::isSafeToUnlock() const |
163 { | 161 { |
164 return m_data->hasOneRef(); | 162 return m_data->hasOneRef(); |
165 } | 163 } |
166 | 164 |
167 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) | 165 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) |
168 { | 166 { |
169 if (!isLoading()) | 167 if (!isLoading()) |
170 return; | 168 return; |
171 ASSERT(m_state == LoadInitiated); | 169 ASSERT(m_loadLimitState == UnderLimit); |
172 m_state = ShortLimitExceeded; | 170 m_loadLimitState = ShortLimitExceeded; |
173 ResourceClientWalker<FontResourceClient> walker(m_clients); | 171 ResourceClientWalker<FontResourceClient> walker(m_clients); |
174 while (FontResourceClient* client = walker.next()) | 172 while (FontResourceClient* client = walker.next()) |
175 client->fontLoadShortLimitExceeded(this); | 173 client->fontLoadShortLimitExceeded(this); |
176 } | 174 } |
177 | 175 |
178 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) | 176 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) |
179 { | 177 { |
180 if (!isLoading()) | 178 if (!isLoading()) |
181 return; | 179 return; |
182 ASSERT(m_state == ShortLimitExceeded); | 180 ASSERT(m_loadLimitState == ShortLimitExceeded); |
183 m_state = LongLimitExceeded; | 181 m_loadLimitState = LongLimitExceeded; |
184 ResourceClientWalker<FontResourceClient> walker(m_clients); | 182 ResourceClientWalker<FontResourceClient> walker(m_clients); |
185 while (FontResourceClient* client = walker.next()) | 183 while (FontResourceClient* client = walker.next()) |
186 client->fontLoadLongLimitExceeded(this); | 184 client->fontLoadLongLimitExceeded(this); |
187 } | 185 } |
188 | 186 |
189 void FontResource::allClientsRemoved() | 187 void FontResource::allClientsRemoved() |
190 { | 188 { |
191 m_fontData.clear(); | 189 m_fontData.clear(); |
192 Resource::allClientsRemoved(); | 190 Resource::allClientsRemoved(); |
193 } | 191 } |
194 | 192 |
195 void FontResource::checkNotify() | 193 void FontResource::checkNotify() |
196 { | 194 { |
197 m_fontLoadShortLimitTimer.stop(); | 195 m_fontLoadShortLimitTimer.stop(); |
198 m_fontLoadLongLimitTimer.stop(); | 196 m_fontLoadLongLimitTimer.stop(); |
199 ResourceClientWalker<FontResourceClient> w(m_clients); | 197 ResourceClientWalker<FontResourceClient> w(m_clients); |
200 while (FontResourceClient* c = w.next()) | 198 while (FontResourceClient* c = w.next()) |
201 c->fontLoaded(this); | 199 c->fontLoaded(this); |
202 } | 200 } |
203 | 201 |
204 } // namespace blink | 202 } // namespace blink |
OLD | NEW |