60 #endif |
60 #endif |
61 HashMap<String, CachedResource*>::iterator end = m_docResources.end(); |
61 HashMap<String, CachedResource*>::iterator end = m_docResources.end(); |
62 for (HashMap<String, CachedResource*>::iterator it = m_docResources.begin(); it != end; ++it) |
62 for (HashMap<String, CachedResource*>::iterator it = m_docResources.begin(); it != end; ++it) |
63 it->second->setDocLoader(0); |
63 it->second->setDocLoader(0); |
64 m_cache->removeDocLoader(this); |
64 m_cache->removeDocLoader(this); |
|
65 m_reloadedURLs.clear(); |
65 } |
66 } |
66 |
67 |
67 void DocLoader::checkForReload(const KURL& fullURL) |
68 void DocLoader::checkForReload(const KURL& fullURL) |
68 { |
69 { |
69 if (m_allowStaleResources) |
70 if (m_allowStaleResources) |
97 } |
98 } |
98 } |
99 } |
99 |
100 |
100 CachedImage* DocLoader::requestImage(const String& url) |
101 CachedImage* DocLoader::requestImage(const String& url) |
101 { |
102 { |
102 CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url)); |
103 CachedImage* resource = static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, url, String())); |
103 if (autoLoadImages() && resource && resource->stillNeedsLoad()) { |
104 if (autoLoadImages() && resource && resource->stillNeedsLoad()) { |
104 resource->setLoading(true); |
105 resource->setLoading(true); |
105 cache()->loader()->load(this, resource, true); |
106 cache()->loader()->load(this, resource, true); |
106 } |
107 } |
107 return resource; |
108 return resource; |
108 } |
109 } |
109 |
110 |
110 CachedCSSStyleSheet* DocLoader::requestCSSStyleSheet(const String& url, const String& charset, bool isUserStyleSheet) |
111 CachedCSSStyleSheet* DocLoader::requestCSSStyleSheet(const String& url, const String& charset) |
111 { |
112 { |
112 // FIXME: Passing true for "skipCanLoadCheck" here in the isUserStyleSheet case won't have any effect |
113 return static_cast<CachedCSSStyleSheet*>(requestResource(CachedResource::CSSStyleSheet, url, charset)); |
113 // if this resource is already in the cache. It's theoretically possible that what's in the cache already |
|
114 // is a load that failed because of the canLoad check. Probably not an issue in practice. |
|
115 CachedCSSStyleSheet *sheet = static_cast<CachedCSSStyleSheet*>(requestResource(CachedResource::CSSStyleSheet, url, &charset, isUserStyleSheet, !isUserStyleSheet)); |
|
116 |
|
117 // A user style sheet can outlive its DocLoader so don't store any pointers to it |
|
118 if (sheet && isUserStyleSheet) { |
|
119 sheet->setDocLoader(0); |
|
120 m_docResources.remove(sheet->url()); |
|
121 } |
|
122 |
|
123 return sheet; |
|
124 } |
114 } |
125 |
115 |
126 CachedCSSStyleSheet* DocLoader::requestUserCSSStyleSheet(const String& url, const String& charset) |
116 CachedCSSStyleSheet* DocLoader::requestUserCSSStyleSheet(const String& url, const String& charset) |
127 { |
117 { |
128 return requestCSSStyleSheet(url, charset, true); |
118 return cache()->requestUserCSSStyleSheet(this, url, charset); |
129 } |
119 } |
130 |
120 |
131 CachedScript* DocLoader::requestScript(const String& url, const String& charset) |
121 CachedScript* DocLoader::requestScript(const String& url, const String& charset) |
132 { |
122 { |
133 return static_cast<CachedScript*>(requestResource(CachedResource::Script, url, &charset)); |
123 return static_cast<CachedScript*>(requestResource(CachedResource::Script, url, charset)); |
134 } |
124 } |
135 |
125 |
136 #if ENABLE(XSLT) |
126 #if ENABLE(XSLT) |
137 CachedXSLStyleSheet* DocLoader::requestXSLStyleSheet(const String& url) |
127 CachedXSLStyleSheet* DocLoader::requestXSLStyleSheet(const String& url) |
138 { |
128 { |
139 return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XSLStyleSheet, url)); |
129 return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XSLStyleSheet, url, String())); |
140 } |
130 } |
141 #endif |
131 #endif |
142 |
132 |
143 #if ENABLE(XBL) |
133 #if ENABLE(XBL) |
144 CachedXBLDocument* DocLoader::requestXBLDocument(const String& url) |
134 CachedXBLDocument* DocLoader::requestXBLDocument(const String& url) |
145 { |
135 { |
146 return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XBL, url)); |
136 return static_cast<CachedXSLStyleSheet*>(requestResource(CachedResource::XBL, url, String())); |
147 } |
137 } |
148 #endif |
138 #endif |
149 |
139 |
150 #if PRELOAD_SCANNER_ENABLED |
140 #if PRELOAD_SCANNER_ENABLED |
151 CachedResource* DocLoader::requestResource(CachedResource::Type type, const String& url, const String* charset, bool skipCanLoadCheck, bool sendResourceLoadCallbacks, bool isPreload) |
141 CachedResource* DocLoader::requestResource(CachedResource::Type type, const String& url, const String& charset, bool isPreload) |
152 #else |
142 #else |
153 CachedResource* DocLoader::requestResource(CachedResource::Type type, const String& url, const String* charset, bool skipCanLoadCheck, bool sendResourceLoadCallbacks) |
143 CachedResource* DocLoader::requestResource(CachedResource::Type type, const String& url, const String& charset) |
154 #endif |
144 #endif |
155 { |
145 { |
156 KURL fullURL = m_doc->completeURL(url.deprecatedString()); |
146 KURL fullURL = m_doc->completeURL(url.deprecatedString()); |
157 |
147 |
158 if (cache()->disabled()) { |
148 if (cache()->disabled()) { |
168 setCachePolicy(CachePolicyReload); |
158 setCachePolicy(CachePolicyReload); |
169 |
159 |
170 checkForReload(fullURL); |
160 checkForReload(fullURL); |
171 |
161 |
172 #if PRELOAD_SCANNER_ENABLED |
162 #if PRELOAD_SCANNER_ENABLED |
173 CachedResource* resource = cache()->requestResource(this, type, fullURL, charset, skipCanLoadCheck, sendResourceLoadCallbacks, isPreload); |
163 CachedResource* resource = cache()->requestResource(this, type, fullURL, charset, isPreload); |
174 #else |
164 #else |
175 CachedResource* resource = cache()->requestResource(this, type, fullURL, charset, skipCanLoadCheck, sendResourceLoadCallbacks); |
165 CachedResource* resource = cache()->requestResource(this, type, fullURL, charset); |
176 #endif |
166 #endif |
177 if (resource) { |
167 if (resource) { |
178 m_docResources.set(resource->url(), resource); |
168 m_docResources.set(resource->url(), resource); |
179 checkCacheObjectStatus(resource); |
169 checkCacheObjectStatus(resource); |
180 } |
170 } |
274 #if PRELOAD_SCANNER_ENABLED |
264 #if PRELOAD_SCANNER_ENABLED |
275 #define PRELOAD_DEBUG 0 |
265 #define PRELOAD_DEBUG 0 |
276 void DocLoader::preload(CachedResource::Type type, const String& url) |
266 void DocLoader::preload(CachedResource::Type type, const String& url) |
277 { |
267 { |
278 String encoding = (type == CachedResource::Script || type == CachedResource::CSSStyleSheet) ? m_doc->frame()->loader()->encoding() : String(); |
268 String encoding = (type == CachedResource::Script || type == CachedResource::CSSStyleSheet) ? m_doc->frame()->loader()->encoding() : String(); |
279 CachedResource* resource = requestResource(type, url, &encoding, true); |
269 CachedResource* resource = requestResource(type, url, encoding, true); |
280 if (!resource || m_preloads.contains(resource)) |
270 if (!resource || m_preloads.contains(resource)) |
281 return; |
271 return; |
282 resource->increasePreloadCount(); |
272 resource->increasePreloadCount(); |
283 m_preloads.add(resource); |
273 m_preloads.add(resource); |
284 #if PRELOAD_DEBUG |
274 #if PRELOAD_DEBUG |
292 printPreloadStats(); |
282 printPreloadStats(); |
293 #endif |
283 #endif |
294 ListHashSet<CachedResource*>::iterator end = m_preloads.end(); |
284 ListHashSet<CachedResource*>::iterator end = m_preloads.end(); |
295 for (ListHashSet<CachedResource*>::iterator it = m_preloads.begin(); it != end; ++it) { |
285 for (ListHashSet<CachedResource*>::iterator it = m_preloads.begin(); it != end; ++it) { |
296 CachedResource* res = *it; |
286 CachedResource* res = *it; |
297 if (res->canDelete() && !res->inCache()) |
287 res->decreasePreloadCount(); |
|
288 if (res->canDelete()) |
|
289 { |
|
290 if(res->inCache()) |
|
291 cache()->remove(res); |
|
292 else |
298 delete res; |
293 delete res; |
|
294 } |
299 else if (res->preloadResult() == CachedResource::PreloadNotReferenced) |
295 else if (res->preloadResult() == CachedResource::PreloadNotReferenced) |
300 cache()->remove(res); |
296 cache()->remove(res); |
301 res->decreasePreloadCount(); |
297 |
302 } |
298 } |
303 m_preloads.clear(); |
299 m_preloads.clear(); |
304 } |
300 } |
305 |
301 |
306 #if PRELOAD_DEBUG |
302 #if PRELOAD_DEBUG |