| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 void setIdentifier(unsigned long identifier) { m_identifier = identifier; } | 118 void setIdentifier(unsigned long identifier) { m_identifier = identifier; } |
| 119 unsigned long identifier() const { return m_identifier; } | 119 unsigned long identifier() const { return m_identifier; } |
| 120 | 120 |
| 121 virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; } | 121 virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; } |
| 122 | 122 |
| 123 ResourceRequest& mutableResourceRequest() { return m_resourceRequest; } | 123 ResourceRequest& mutableResourceRequest() { return m_resourceRequest; } |
| 124 const ResourceRequest& resourceRequest() const { return m_resourceRequest; } | 124 const ResourceRequest& resourceRequest() const { return m_resourceRequest; } |
| 125 const ResourceRequest& lastResourceRequest() const; | 125 const ResourceRequest& lastResourceRequest() const; |
| 126 | 126 |
| 127 void setRevalidatingRequest(const ResourceRequest& request) { m_revalidating
Request = request; } |
| 128 |
| 127 const KURL& url() const { return m_resourceRequest.url();} | 129 const KURL& url() const { return m_resourceRequest.url();} |
| 128 Type type() const { return static_cast<Type>(m_type); } | 130 Type type() const { return static_cast<Type>(m_type); } |
| 129 const ResourceLoaderOptions& options() const { return m_options; } | 131 const ResourceLoaderOptions& options() const { return m_options; } |
| 130 void setOptions(const ResourceLoaderOptions& options) { m_options = options;
} | 132 void setOptions(const ResourceLoaderOptions& options) { m_options = options;
} |
| 131 | 133 |
| 132 void didChangePriority(ResourceLoadPriority, int intraPriorityValue); | 134 void didChangePriority(ResourceLoadPriority, int intraPriorityValue); |
| 133 ResourcePriority priorityFromClients(); | 135 ResourcePriority priorityFromClients(); |
| 134 | 136 |
| 135 void addClient(ResourceClient*); | 137 void addClient(ResourceClient*); |
| 136 void removeClient(ResourceClient*); | 138 void removeClient(ResourceClient*); |
| 137 bool hasClients() const { return !m_clients.isEmpty() || !m_clientsAwaitingC
allback.isEmpty(); } | 139 bool hasClients() const { return !m_clients.isEmpty() || !m_clientsAwaitingC
allback.isEmpty() || !m_finishedClients.isEmpty(); } |
| 138 bool deleteIfPossible(); | 140 bool deleteIfPossible(); |
| 139 | 141 |
| 140 enum PreloadResult { | 142 enum PreloadResult { |
| 141 PreloadNotReferenced, | 143 PreloadNotReferenced, |
| 142 PreloadReferenced, | 144 PreloadReferenced, |
| 143 PreloadReferencedWhileLoading, | 145 PreloadReferencedWhileLoading, |
| 144 PreloadReferencedWhileComplete | 146 PreloadReferencedWhileComplete |
| 145 }; | 147 }; |
| 146 PreloadResult preloadResult() const { return static_cast<PreloadResult>(m_pr
eloadResult); } | 148 PreloadResult preloadResult() const { return static_cast<PreloadResult>(m_pr
eloadResult); } |
| 147 | 149 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 bool isPreloaded() const { return m_preloadCount; } | 229 bool isPreloaded() const { return m_preloadCount; } |
| 228 void increasePreloadCount() { ++m_preloadCount; } | 230 void increasePreloadCount() { ++m_preloadCount; } |
| 229 void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; } | 231 void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; } |
| 230 | 232 |
| 231 void registerHandle(ResourcePtrBase* h); | 233 void registerHandle(ResourcePtrBase* h); |
| 232 void unregisterHandle(ResourcePtrBase* h); | 234 void unregisterHandle(ResourcePtrBase* h); |
| 233 | 235 |
| 234 bool canReuseRedirectChain(); | 236 bool canReuseRedirectChain(); |
| 235 bool mustRevalidateDueToCacheHeaders(); | 237 bool mustRevalidateDueToCacheHeaders(); |
| 236 bool canUseCacheValidator(); | 238 bool canUseCacheValidator(); |
| 237 bool isCacheValidator() const { return m_resourceToRevalidate; } | 239 bool isCacheValidator() const { return !m_revalidatingRequest.isNull(); } |
| 238 Resource* resourceToRevalidate() const { return m_resourceToRevalidate; } | |
| 239 void setResourceToRevalidate(Resource*); | |
| 240 bool hasCacheControlNoStoreHeader(); | 240 bool hasCacheControlNoStoreHeader(); |
| 241 bool hasVaryHeader() const; | 241 bool hasVaryHeader() const; |
| 242 virtual bool mustRefetchDueToIntegrityMetadata(const FetchRequest& request)
const { return false; } | 242 virtual bool mustRefetchDueToIntegrityMetadata(const FetchRequest& request)
const { return false; } |
| 243 | 243 |
| 244 double currentAge() const; | 244 double currentAge() const; |
| 245 double freshnessLifetime(); | 245 double freshnessLifetime(); |
| 246 double stalenessLifetime(); | 246 double stalenessLifetime(); |
| 247 | 247 |
| 248 bool isPurgeable() const; | 248 bool isPurgeable() const; |
| 249 bool wasPurged() const; | 249 bool wasPurged() const; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 267 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK | 267 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
| 268 void assertAlive() const { RELEASE_ASSERT(!m_deleted); } | 268 void assertAlive() const { RELEASE_ASSERT(!m_deleted); } |
| 269 #else | 269 #else |
| 270 void assertAlive() const { } | 270 void assertAlive() const { } |
| 271 #endif | 271 #endif |
| 272 | 272 |
| 273 protected: | 273 protected: |
| 274 virtual void checkNotify(); | 274 virtual void checkNotify(); |
| 275 virtual void finishOnePart(); | 275 virtual void finishOnePart(); |
| 276 | 276 |
| 277 virtual void destroyDecodedDataForFailedRevalidation() { } |
| 278 |
| 277 // Normal resource pointers will silently switch what Resource* they referen
ce when we | 279 // Normal resource pointers will silently switch what Resource* they referen
ce when we |
| 278 // successfully revalidated the resource. We need a way to guarantee that th
e Resource | 280 // successfully revalidated the resource. We need a way to guarantee that th
e Resource |
| 279 // that received the 304 response survives long enough to switch everything
over to the | 281 // that received the 304 response survives long enough to switch everything
over to the |
| 280 // revalidatedresource. The normal mechanisms for keeping a Resource alive e
xternally | 282 // revalidatedresource. The normal mechanisms for keeping a Resource alive e
xternally |
| 281 // (ResourcePtrs and ResourceClients registering themselves) don't work in t
his case, so | 283 // (ResourcePtrs and ResourceClients registering themselves) don't work in t
his case, so |
| 282 // have a separate internal protector). | 284 // have a separate internal protector). |
| 283 class InternalResourcePtr { | 285 class InternalResourcePtr { |
| 284 public: | 286 public: |
| 285 explicit InternalResourcePtr(Resource* resource) | 287 explicit InternalResourcePtr(Resource* resource) |
| 286 : m_resource(resource) | 288 : m_resource(resource) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 297 Resource* m_resource; | 299 Resource* m_resource; |
| 298 }; | 300 }; |
| 299 | 301 |
| 300 void incrementProtectorCount() { m_protectorCount++; } | 302 void incrementProtectorCount() { m_protectorCount++; } |
| 301 void decrementProtectorCount() { m_protectorCount--; } | 303 void decrementProtectorCount() { m_protectorCount--; } |
| 302 | 304 |
| 303 void setEncodedSize(size_t); | 305 void setEncodedSize(size_t); |
| 304 void setDecodedSize(size_t); | 306 void setDecodedSize(size_t); |
| 305 void didAccessDecodedData(); | 307 void didAccessDecodedData(); |
| 306 | 308 |
| 307 void clearResourceToRevalidate(); | |
| 308 void updateResponseAfterRevalidation(const ResourceResponse& validatingRespo
nse); | |
| 309 | |
| 310 void finishPendingClients(); | 309 void finishPendingClients(); |
| 311 | 310 |
| 312 HashCountedSet<ResourceClient*> m_clients; | 311 HashCountedSet<ResourceClient*> m_clients; |
| 313 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback; | 312 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback; |
| 313 HashCountedSet<ResourceClient*> m_finishedClients; |
| 314 | 314 |
| 315 class ResourceCallback : public NoBaseWillBeGarbageCollectedFinalized<Resour
ceCallback> { | 315 class ResourceCallback : public NoBaseWillBeGarbageCollectedFinalized<Resour
ceCallback> { |
| 316 public: | 316 public: |
| 317 static ResourceCallback* callbackHandler(); | 317 static ResourceCallback* callbackHandler(); |
| 318 DECLARE_TRACE(); | 318 DECLARE_TRACE(); |
| 319 void schedule(Resource*); | 319 void schedule(Resource*); |
| 320 void cancel(Resource*); | 320 void cancel(Resource*); |
| 321 bool isScheduled(Resource*) const; | 321 bool isScheduled(Resource*) const; |
| 322 private: | 322 private: |
| 323 ResourceCallback(); | 323 ResourceCallback(); |
| 324 void runTask(); | 324 void runTask(); |
| 325 OwnPtr<CancellableTaskFactory> m_callbackTaskFactory; | 325 OwnPtr<CancellableTaskFactory> m_callbackTaskFactory; |
| 326 WillBeHeapHashSet<RawPtrWillBeMember<Resource>> m_resourcesWithPendingCl
ients; | 326 WillBeHeapHashSet<RawPtrWillBeMember<Resource>> m_resourcesWithPendingCl
ients; |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 bool hasClient(ResourceClient* client) { return m_clients.contains(client) |
| m_clientsAwaitingCallback.contains(client); } | 329 bool hasClient(ResourceClient* client) { return m_clients.contains(client) |
| m_clientsAwaitingCallback.contains(client) || m_finishedClients.contains(clien
t); } |
| 330 | 330 |
| 331 struct RedirectPair { | 331 struct RedirectPair { |
| 332 ALLOW_ONLY_INLINE_ALLOCATION(); | 332 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 333 public: | 333 public: |
| 334 explicit RedirectPair(const ResourceRequest& request, const ResourceResp
onse& redirectResponse) | 334 explicit RedirectPair(const ResourceRequest& request, const ResourceResp
onse& redirectResponse) |
| 335 : m_request(request) | 335 : m_request(request) |
| 336 , m_redirectResponse(redirectResponse) | 336 , m_redirectResponse(redirectResponse) |
| 337 { | 337 { |
| 338 } | 338 } |
| 339 | 339 |
| 340 ResourceRequest m_request; | 340 ResourceRequest m_request; |
| 341 ResourceResponse m_redirectResponse; | 341 ResourceResponse m_redirectResponse; |
| 342 }; | 342 }; |
| 343 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain;
} | 343 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain;
} |
| 344 | 344 |
| 345 virtual bool isSafeToUnlock() const { return false; } | 345 virtual bool isSafeToUnlock() const { return false; } |
| 346 virtual void destroyDecodedDataIfPossible() { } | 346 virtual void destroyDecodedDataIfPossible() { } |
| 347 | 347 |
| 348 void markClientsFinished(); |
| 349 |
| 348 ResourceRequest m_resourceRequest; | 350 ResourceRequest m_resourceRequest; |
| 351 ResourceRequest m_revalidatingRequest; |
| 349 AtomicString m_accept; | 352 AtomicString m_accept; |
| 350 PersistentWillBeMember<ResourceLoader> m_loader; | 353 PersistentWillBeMember<ResourceLoader> m_loader; |
| 351 ResourceLoaderOptions m_options; | 354 ResourceLoaderOptions m_options; |
| 352 | 355 |
| 353 ResourceResponse m_response; | 356 ResourceResponse m_response; |
| 354 double m_responseTimestamp; | 357 double m_responseTimestamp; |
| 355 | 358 |
| 356 RefPtr<SharedBuffer> m_data; | 359 RefPtr<SharedBuffer> m_data; |
| 357 Timer<Resource> m_cancelTimer; | 360 Timer<Resource> m_cancelTimer; |
| 358 | 361 |
| 359 private: | 362 private: |
| 360 class CacheHandler; | 363 class CacheHandler; |
| 361 bool addClientToSet(ResourceClient*); | |
| 362 void cancelTimerFired(Timer<Resource>*); | 364 void cancelTimerFired(Timer<Resource>*); |
| 363 | 365 |
| 364 void switchClientsToRevalidatedResource(); | 366 void switchClientsToRevalidatedResource(); |
| 365 void revalidationSucceeded(const ResourceResponse&); | 367 void revalidationSucceeded(const ResourceResponse&); |
| 366 void revalidationFailed(); | 368 void revalidationFailed(); |
| 367 | 369 |
| 368 bool unlock(); | 370 bool unlock(); |
| 369 | 371 |
| 370 bool hasRightHandleCountApartFromCache(unsigned targetCount) const; | 372 bool hasRightHandleCountApartFromCache(unsigned targetCount) const; |
| 371 | 373 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 unsigned m_status : 3; // Status | 405 unsigned m_status : 3; // Status |
| 404 | 406 |
| 405 unsigned m_wasPurged : 1; | 407 unsigned m_wasPurged : 1; |
| 406 | 408 |
| 407 unsigned m_needsSynchronousCacheHit : 1; | 409 unsigned m_needsSynchronousCacheHit : 1; |
| 408 | 410 |
| 409 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK | 411 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
| 410 bool m_deleted; | 412 bool m_deleted; |
| 411 #endif | 413 #endif |
| 412 | 414 |
| 413 // 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 | |
| 414 // using HTTP If-Modified-Since/If-None-Match headers. If the response is 30
4 all clients of this resource are moved | |
| 415 // to to be clients of m_resourceToRevalidate and the resource is deleted. I
f not, the field is zeroed and this | |
| 416 // resources becomes normal resource load. | |
| 417 RawPtrWillBeMember<Resource> m_resourceToRevalidate; | |
| 418 | |
| 419 // If this field is non-null, the resource has a proxy for checking whether
it is still up to date (see m_resourceToRevalidate). | |
| 420 RawPtrWillBeMember<Resource> m_proxyResource; | |
| 421 | |
| 422 // These handles will need to be updated to point to the m_resourceToRevalid
ate in case we get 304 response. | |
| 423 HashSet<ResourcePtrBase*> m_handlesToRevalidate; | |
| 424 | |
| 425 // Ordered list of all redirects followed while fetching this resource. | 415 // Ordered list of all redirects followed while fetching this resource. |
| 426 Vector<RedirectPair> m_redirectChain; | 416 Vector<RedirectPair> m_redirectChain; |
| 427 }; | 417 }; |
| 428 | 418 |
| 429 class ResourceFactory { | 419 class ResourceFactory { |
| 430 STACK_ALLOCATED(); | 420 STACK_ALLOCATED(); |
| 431 public: | 421 public: |
| 432 virtual Resource* create(const ResourceRequest&, const String&) const = 0; | 422 virtual Resource* create(const ResourceRequest&, const String&) const = 0; |
| 433 Resource::Type type() const { return m_type; } | 423 Resource::Type type() const { return m_type; } |
| 434 | 424 |
| 435 protected: | 425 protected: |
| 436 ResourceFactory(Resource::Type type) : m_type(type) { } | 426 ResourceFactory(Resource::Type type) : m_type(type) { } |
| 437 | 427 |
| 438 Resource::Type m_type; | 428 Resource::Type m_type; |
| 439 }; | 429 }; |
| 440 | 430 |
| 441 #if !LOG_DISABLED | 431 #if !LOG_DISABLED |
| 442 // Intended to be used in LOG statements. | 432 // Intended to be used in LOG statements. |
| 443 const char* ResourceTypeName(Resource::Type); | 433 const char* ResourceTypeName(Resource::Type); |
| 444 #endif | 434 #endif |
| 445 | 435 |
| 446 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ | 436 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
| 447 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ | 437 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ |
| 448 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource
>& ptr) { return to##typeName##Resource(ptr.get()); } | 438 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource
>& ptr) { return to##typeName##Resource(ptr.get()); } |
| 449 | 439 |
| 450 } | 440 } |
| 451 | 441 |
| 452 #endif | 442 #endif |
| OLD | NEW |