OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> | 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
6 | 6 |
7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 void setIdentifier(unsigned long identifier) { m_identifier = identifier; } | 115 void setIdentifier(unsigned long identifier) { m_identifier = identifier; } |
116 unsigned long identifier() const { return m_identifier; } | 116 unsigned long identifier() const { return m_identifier; } |
117 | 117 |
118 virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; } | 118 virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; } |
119 | 119 |
120 ResourceRequest& mutableResourceRequest() { return m_resourceRequest; } | 120 ResourceRequest& mutableResourceRequest() { return m_resourceRequest; } |
121 const ResourceRequest& resourceRequest() const { return m_resourceRequest; } | 121 const ResourceRequest& resourceRequest() const { return m_resourceRequest; } |
122 const ResourceRequest& lastResourceRequest() const; | 122 const ResourceRequest& lastResourceRequest() const; |
123 | 123 |
124 void setRevalidatingRequest(const ResourceRequest& request) { m_revalidating
Request = request; } | |
125 | |
126 const KURL& url() const { return m_resourceRequest.url();} | 124 const KURL& url() const { return m_resourceRequest.url();} |
127 Type type() const { return static_cast<Type>(m_type); } | 125 Type type() const { return static_cast<Type>(m_type); } |
128 const ResourceLoaderOptions& options() const { return m_options; } | 126 const ResourceLoaderOptions& options() const { return m_options; } |
129 void setOptions(const ResourceLoaderOptions& options) { m_options = options;
} | 127 void setOptions(const ResourceLoaderOptions& options) { m_options = options;
} |
130 | 128 |
131 void didChangePriority(ResourceLoadPriority, int intraPriorityValue); | 129 void didChangePriority(ResourceLoadPriority, int intraPriorityValue); |
132 | 130 |
133 void addClient(ResourceClient*); | 131 void addClient(ResourceClient*); |
134 void removeClient(ResourceClient*); | 132 void removeClient(ResourceClient*); |
135 bool hasClients() const { return !m_clients.isEmpty() || !m_clientsAwaitingC
allback.isEmpty(); } | 133 bool hasClients() const { return !m_clients.isEmpty() || !m_clientsAwaitingC
allback.isEmpty(); } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 bool isPreloaded() const { return m_preloadCount; } | 223 bool isPreloaded() const { return m_preloadCount; } |
226 void increasePreloadCount() { ++m_preloadCount; } | 224 void increasePreloadCount() { ++m_preloadCount; } |
227 void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; } | 225 void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; } |
228 | 226 |
229 void registerHandle(ResourcePtrBase* h); | 227 void registerHandle(ResourcePtrBase* h); |
230 void unregisterHandle(ResourcePtrBase* h); | 228 void unregisterHandle(ResourcePtrBase* h); |
231 | 229 |
232 bool canReuseRedirectChain(); | 230 bool canReuseRedirectChain(); |
233 bool mustRevalidateDueToCacheHeaders(); | 231 bool mustRevalidateDueToCacheHeaders(); |
234 bool canUseCacheValidator(); | 232 bool canUseCacheValidator(); |
235 bool isCacheValidator() const { return !m_revalidatingRequest.isNull(); } | 233 bool isCacheValidator() const { return m_resourceToRevalidate; } |
| 234 Resource* resourceToRevalidate() const { return m_resourceToRevalidate; } |
| 235 void setResourceToRevalidate(Resource*); |
236 bool hasCacheControlNoStoreHeader(); | 236 bool hasCacheControlNoStoreHeader(); |
237 | 237 |
238 double currentAge() const; | 238 double currentAge() const; |
239 double freshnessLifetime(); | 239 double freshnessLifetime(); |
240 double stalenessLifetime(); | 240 double stalenessLifetime(); |
241 | 241 |
242 bool isPurgeable() const; | 242 bool isPurgeable() const; |
243 bool wasPurged() const; | 243 bool wasPurged() const; |
244 bool lock(); | 244 bool lock(); |
245 | 245 |
(...skipping 15 matching lines...) Expand all Loading... |
261 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK | 261 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
262 void assertAlive() const { RELEASE_ASSERT(!m_deleted); } | 262 void assertAlive() const { RELEASE_ASSERT(!m_deleted); } |
263 #else | 263 #else |
264 void assertAlive() const { } | 264 void assertAlive() const { } |
265 #endif | 265 #endif |
266 | 266 |
267 protected: | 267 protected: |
268 virtual void checkNotify(); | 268 virtual void checkNotify(); |
269 virtual void finishOnePart(); | 269 virtual void finishOnePart(); |
270 | 270 |
271 virtual void destroyDecodedDataForFailedRevalidation() { } | |
272 | |
273 // Normal resource pointers will silently switch what Resource* they referen
ce when we | 271 // Normal resource pointers will silently switch what Resource* they referen
ce when we |
274 // successfully revalidated the resource. We need a way to guarantee that th
e Resource | 272 // successfully revalidated the resource. We need a way to guarantee that th
e Resource |
275 // that received the 304 response survives long enough to switch everything
over to the | 273 // that received the 304 response survives long enough to switch everything
over to the |
276 // revalidatedresource. The normal mechanisms for keeping a Resource alive e
xternally | 274 // revalidatedresource. The normal mechanisms for keeping a Resource alive e
xternally |
277 // (ResourcePtrs and ResourceClients registering themselves) don't work in t
his case, so | 275 // (ResourcePtrs and ResourceClients registering themselves) don't work in t
his case, so |
278 // have a separate internal protector). | 276 // have a separate internal protector). |
279 class InternalResourcePtr { | 277 class InternalResourcePtr { |
280 public: | 278 public: |
281 explicit InternalResourcePtr(Resource* resource) | 279 explicit InternalResourcePtr(Resource* resource) |
282 : m_resource(resource) | 280 : m_resource(resource) |
(...skipping 10 matching lines...) Expand all Loading... |
293 Resource* m_resource; | 291 Resource* m_resource; |
294 }; | 292 }; |
295 | 293 |
296 void incrementProtectorCount() { m_protectorCount++; } | 294 void incrementProtectorCount() { m_protectorCount++; } |
297 void decrementProtectorCount() { m_protectorCount--; } | 295 void decrementProtectorCount() { m_protectorCount--; } |
298 | 296 |
299 void setEncodedSize(size_t); | 297 void setEncodedSize(size_t); |
300 void setDecodedSize(size_t); | 298 void setDecodedSize(size_t); |
301 void didAccessDecodedData(); | 299 void didAccessDecodedData(); |
302 | 300 |
| 301 void clearResourceToRevalidate(); |
| 302 void updateResponseAfterRevalidation(const ResourceResponse& validatingRespo
nse); |
| 303 |
303 void finishPendingClients(); | 304 void finishPendingClients(); |
304 | 305 |
305 HashCountedSet<ResourceClient*> m_clients; | 306 HashCountedSet<ResourceClient*> m_clients; |
306 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback; | 307 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback; |
307 | 308 |
308 class ResourceCallback { | 309 class ResourceCallback { |
309 public: | 310 public: |
310 static ResourceCallback* callbackHandler(); | 311 static ResourceCallback* callbackHandler(); |
311 void schedule(Resource*); | 312 void schedule(Resource*); |
312 void cancel(Resource*); | 313 void cancel(Resource*); |
(...skipping 17 matching lines...) Expand all Loading... |
330 | 331 |
331 ResourceRequest m_request; | 332 ResourceRequest m_request; |
332 ResourceResponse m_redirectResponse; | 333 ResourceResponse m_redirectResponse; |
333 }; | 334 }; |
334 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain;
} | 335 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain;
} |
335 | 336 |
336 virtual bool isSafeToUnlock() const { return false; } | 337 virtual bool isSafeToUnlock() const { return false; } |
337 virtual void destroyDecodedDataIfPossible() { } | 338 virtual void destroyDecodedDataIfPossible() { } |
338 | 339 |
339 ResourceRequest m_resourceRequest; | 340 ResourceRequest m_resourceRequest; |
340 ResourceRequest m_revalidatingRequest; | |
341 AtomicString m_accept; | 341 AtomicString m_accept; |
342 PersistentWillBeMember<ResourceLoader> m_loader; | 342 PersistentWillBeMember<ResourceLoader> m_loader; |
343 ResourceLoaderOptions m_options; | 343 ResourceLoaderOptions m_options; |
344 | 344 |
345 ResourceResponse m_response; | 345 ResourceResponse m_response; |
346 double m_responseTimestamp; | 346 double m_responseTimestamp; |
347 | 347 |
348 RefPtr<SharedBuffer> m_data; | 348 RefPtr<SharedBuffer> m_data; |
349 Timer<Resource> m_cancelTimer; | 349 Timer<Resource> m_cancelTimer; |
350 | 350 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 unsigned m_status : 3; // Status | 395 unsigned m_status : 3; // Status |
396 | 396 |
397 unsigned m_wasPurged : 1; | 397 unsigned m_wasPurged : 1; |
398 | 398 |
399 unsigned m_needsSynchronousCacheHit : 1; | 399 unsigned m_needsSynchronousCacheHit : 1; |
400 | 400 |
401 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK | 401 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
402 bool m_deleted; | 402 bool m_deleted; |
403 #endif | 403 #endif |
404 | 404 |
| 405 // If this field is non-null we are using the resource as a proxy for checki
ng whether an existing resource is still up to date |
| 406 // using HTTP If-Modified-Since/If-None-Match headers. If the response is 30
4 all clients of this resource are moved |
| 407 // to to be clients of m_resourceToRevalidate and the resource is deleted. I
f not, the field is zeroed and this |
| 408 // resources becomes normal resource load. |
| 409 RawPtrWillBeMember<Resource> m_resourceToRevalidate; |
| 410 |
| 411 // If this field is non-null, the resource has a proxy for checking whether
it is still up to date (see m_resourceToRevalidate). |
| 412 RawPtrWillBeMember<Resource> m_proxyResource; |
| 413 |
| 414 // These handles will need to be updated to point to the m_resourceToRevalid
ate in case we get 304 response. |
| 415 HashSet<ResourcePtrBase*> m_handlesToRevalidate; |
| 416 |
405 // Ordered list of all redirects followed while fetching this resource. | 417 // Ordered list of all redirects followed while fetching this resource. |
406 Vector<RedirectPair> m_redirectChain; | 418 Vector<RedirectPair> m_redirectChain; |
407 }; | 419 }; |
408 | 420 |
409 class ResourceFactory { | 421 class ResourceFactory { |
410 public: | 422 public: |
411 virtual Resource* create(const ResourceRequest&, const String&) const = 0; | 423 virtual Resource* create(const ResourceRequest&, const String&) const = 0; |
412 Resource::Type type() const { return m_type; } | 424 Resource::Type type() const { return m_type; } |
413 | 425 |
414 protected: | 426 protected: |
415 ResourceFactory(Resource::Type type) : m_type(type) { } | 427 ResourceFactory(Resource::Type type) : m_type(type) { } |
416 | 428 |
417 Resource::Type m_type; | 429 Resource::Type m_type; |
418 }; | 430 }; |
419 | 431 |
420 #if !LOG_DISABLED | 432 #if !LOG_DISABLED |
421 // Intended to be used in LOG statements. | 433 // Intended to be used in LOG statements. |
422 const char* ResourceTypeName(Resource::Type); | 434 const char* ResourceTypeName(Resource::Type); |
423 #endif | 435 #endif |
424 | 436 |
425 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ | 437 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
426 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ | 438 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ |
427 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource
>& ptr) { return to##typeName##Resource(ptr.get()); } | 439 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource
>& ptr) { return to##typeName##Resource(ptr.get()); } |
428 | 440 |
429 } | 441 } |
430 | 442 |
431 #endif | 443 #endif |
OLD | NEW |