| 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 | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 6 rights reserved. | 6 rights reserved. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "platform/wtf/Allocator.h" | 41 #include "platform/wtf/Allocator.h" |
| 42 #include "platform/wtf/AutoReset.h" | 42 #include "platform/wtf/AutoReset.h" |
| 43 #include "platform/wtf/HashCountedSet.h" | 43 #include "platform/wtf/HashCountedSet.h" |
| 44 #include "platform/wtf/HashSet.h" | 44 #include "platform/wtf/HashSet.h" |
| 45 #include "platform/wtf/text/AtomicString.h" | 45 #include "platform/wtf/text/AtomicString.h" |
| 46 #include "platform/wtf/text/WTFString.h" | 46 #include "platform/wtf/text/WTFString.h" |
| 47 #include "public/platform/WebDataConsumerHandle.h" | 47 #include "public/platform/WebDataConsumerHandle.h" |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 class FetchContext; |
| 51 class FetchParameters; | 52 class FetchParameters; |
| 52 class ResourceClient; | 53 class ResourceClient; |
| 53 class ResourceFetcher; | 54 class ResourceFetcher; |
| 54 class ResourceTimingInfo; | 55 class ResourceTimingInfo; |
| 55 class ResourceLoader; | 56 class ResourceLoader; |
| 56 class SecurityOrigin; | 57 class SecurityOrigin; |
| 57 | 58 |
| 58 // A resource that is held in the cache. Classes who want to use this object | 59 // A resource that is held in the cache. Classes who want to use this object |
| 59 // should derive from ResourceClient, to get the function calls in case the | 60 // should derive from ResourceClient, to get the function calls in case the |
| 60 // requested data has arrived. This class also does the actual communication | 61 // requested data has arrived. This class also does the actual communication |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 kMarkAsReferenced, | 93 kMarkAsReferenced, |
| 93 kDontMarkAsReferenced, | 94 kDontMarkAsReferenced, |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 // Used by reloadIfLoFiOrPlaceholderImage(). | 97 // Used by reloadIfLoFiOrPlaceholderImage(). |
| 97 enum ReloadLoFiOrPlaceholderPolicy { | 98 enum ReloadLoFiOrPlaceholderPolicy { |
| 98 kReloadIfNeeded, | 99 kReloadIfNeeded, |
| 99 kReloadAlways, | 100 kReloadAlways, |
| 100 }; | 101 }; |
| 101 | 102 |
| 103 class ResourceCallback { |
| 104 public: |
| 105 virtual ~ResourceCallback() {} |
| 106 virtual void Schedule(Resource*) = 0; |
| 107 virtual void Cancel(Resource*) = 0; |
| 108 virtual bool IsScheduled(Resource*) const = 0; |
| 109 }; |
| 110 |
| 102 virtual ~Resource(); | 111 virtual ~Resource(); |
| 103 | 112 |
| 104 DECLARE_VIRTUAL_TRACE(); | 113 DECLARE_VIRTUAL_TRACE(); |
| 105 | 114 |
| 106 virtual void SetEncoding(const String&) {} | 115 virtual void SetEncoding(const String&) {} |
| 107 virtual String Encoding() const { return String(); } | 116 virtual String Encoding() const { return String(); } |
| 108 virtual void AppendData(const char*, size_t); | 117 virtual void AppendData(const char*, size_t); |
| 109 virtual void GetError(const ResourceError&); | 118 virtual void GetError(const ResourceError&); |
| 110 virtual void SetCORSFailed() {} | 119 virtual void SetCORSFailed() {} |
| 111 | 120 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // If this Resource is ImageResource and has the Lo-Fi response headers or is | 341 // If this Resource is ImageResource and has the Lo-Fi response headers or is |
| 333 // a placeholder, reload the full original image with the Lo-Fi state set to | 342 // a placeholder, reload the full original image with the Lo-Fi state set to |
| 334 // off and optionally bypassing the cache. | 343 // off and optionally bypassing the cache. |
| 335 virtual void ReloadIfLoFiOrPlaceholderImage(ResourceFetcher*, | 344 virtual void ReloadIfLoFiOrPlaceholderImage(ResourceFetcher*, |
| 336 ReloadLoFiOrPlaceholderPolicy) {} | 345 ReloadLoFiOrPlaceholderPolicy) {} |
| 337 | 346 |
| 338 static const char* ResourceTypeToString( | 347 static const char* ResourceTypeToString( |
| 339 Type, | 348 Type, |
| 340 const AtomicString& fetch_initiator_name); | 349 const AtomicString& fetch_initiator_name); |
| 341 | 350 |
| 351 void FinishPendingClients(); |
| 352 |
| 342 protected: | 353 protected: |
| 343 Resource(const ResourceRequest&, Type, const ResourceLoaderOptions&); | 354 Resource(const ResourceRequest&, |
| 355 Type, |
| 356 const ResourceLoaderOptions&, |
| 357 FetchContext* = nullptr); |
| 344 | 358 |
| 345 virtual void CheckNotify(); | 359 virtual void CheckNotify(); |
| 346 | 360 |
| 347 void MarkClientFinished(ResourceClient*); | 361 void MarkClientFinished(ResourceClient*); |
| 348 | 362 |
| 349 virtual bool HasClientsOrObservers() const { | 363 virtual bool HasClientsOrObservers() const { |
| 350 return !clients_.IsEmpty() || !clients_awaiting_callback_.IsEmpty() || | 364 return !clients_.IsEmpty() || !clients_awaiting_callback_.IsEmpty() || |
| 351 !finished_clients_.IsEmpty(); | 365 !finished_clients_.IsEmpty(); |
| 352 } | 366 } |
| 353 virtual void DestroyDecodedDataForFailedRevalidation() {} | 367 virtual void DestroyDecodedDataForFailedRevalidation() {} |
| 354 | 368 |
| 355 void SetEncodedSize(size_t); | 369 void SetEncodedSize(size_t); |
| 356 void SetDecodedSize(size_t); | 370 void SetDecodedSize(size_t); |
| 357 | 371 |
| 358 void FinishPendingClients(); | |
| 359 | |
| 360 virtual void DidAddClient(ResourceClient*); | 372 virtual void DidAddClient(ResourceClient*); |
| 361 void WillAddClientOrObserver(PreloadReferencePolicy); | 373 void WillAddClientOrObserver(PreloadReferencePolicy); |
| 362 | 374 |
| 363 void DidRemoveClientOrObserver(); | 375 void DidRemoveClientOrObserver(); |
| 364 virtual void AllClientsAndObserversRemoved(); | 376 virtual void AllClientsAndObserversRemoved(); |
| 365 | 377 |
| 366 bool HasClient(ResourceClient* client) const { | 378 bool HasClient(ResourceClient* client) const { |
| 367 return clients_.Contains(client) || | 379 return clients_.Contains(client) || |
| 368 clients_awaiting_callback_.Contains(client) || | 380 clients_awaiting_callback_.Contains(client) || |
| 369 finished_clients_.Contains(client); | 381 finished_clients_.Contains(client); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 : AutoReset(&resource->is_add_remove_client_prohibited_, true) {} | 416 : AutoReset(&resource->is_add_remove_client_prohibited_, true) {} |
| 405 }; | 417 }; |
| 406 | 418 |
| 407 class RevalidationStartForbiddenScope : public AutoReset<bool> { | 419 class RevalidationStartForbiddenScope : public AutoReset<bool> { |
| 408 public: | 420 public: |
| 409 RevalidationStartForbiddenScope(Resource* resource) | 421 RevalidationStartForbiddenScope(Resource* resource) |
| 410 : AutoReset(&resource->is_revalidation_start_forbidden_, true) {} | 422 : AutoReset(&resource->is_revalidation_start_forbidden_, true) {} |
| 411 }; | 423 }; |
| 412 | 424 |
| 413 private: | 425 private: |
| 414 class ResourceCallback; | |
| 415 class CachedMetadataHandlerImpl; | 426 class CachedMetadataHandlerImpl; |
| 416 class ServiceWorkerResponseCachedMetadataHandler; | 427 class ServiceWorkerResponseCachedMetadataHandler; |
| 417 | 428 |
| 418 void CancelTimerFired(TimerBase*); | 429 void CancelTimerFired(TimerBase*); |
| 419 | 430 |
| 420 void RevalidationSucceeded(const ResourceResponse&); | 431 void RevalidationSucceeded(const ResourceResponse&); |
| 421 void RevalidationFailed(); | 432 void RevalidationFailed(); |
| 422 | 433 |
| 423 size_t CalculateOverheadSize() const; | 434 size_t CalculateOverheadSize() const; |
| 424 | 435 |
| 425 String ReasonNotDeletable() const; | 436 String ReasonNotDeletable() const; |
| 426 | 437 |
| 438 ResourceCallback& GetResourceCallback(); |
| 439 |
| 427 // MemoryCoordinatorClient overrides: | 440 // MemoryCoordinatorClient overrides: |
| 428 void OnPurgeMemory() override; | 441 void OnPurgeMemory() override; |
| 429 | 442 |
| 430 Member<CachedMetadataHandlerImpl> cache_handler_; | 443 Member<CachedMetadataHandlerImpl> cache_handler_; |
| 431 RefPtr<SecurityOrigin> fetcher_security_origin_; | 444 RefPtr<SecurityOrigin> fetcher_security_origin_; |
| 432 | 445 |
| 433 ResourceError error_; | 446 ResourceError error_; |
| 434 | 447 |
| 435 double load_finish_time_; | 448 double load_finish_time_; |
| 436 | 449 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 484 |
| 472 HeapHashCountedSet<WeakMember<ResourceClient>> clients_; | 485 HeapHashCountedSet<WeakMember<ResourceClient>> clients_; |
| 473 HeapHashCountedSet<WeakMember<ResourceClient>> clients_awaiting_callback_; | 486 HeapHashCountedSet<WeakMember<ResourceClient>> clients_awaiting_callback_; |
| 474 HeapHashCountedSet<WeakMember<ResourceClient>> finished_clients_; | 487 HeapHashCountedSet<WeakMember<ResourceClient>> finished_clients_; |
| 475 | 488 |
| 476 ResourceLoaderOptions options_; | 489 ResourceLoaderOptions options_; |
| 477 | 490 |
| 478 double response_timestamp_; | 491 double response_timestamp_; |
| 479 | 492 |
| 480 TaskRunnerTimer<Resource> cancel_timer_; | 493 TaskRunnerTimer<Resource> cancel_timer_; |
| 494 Member<FetchContext> fetch_context_; |
| 481 | 495 |
| 482 ResourceRequest resource_request_; | 496 ResourceRequest resource_request_; |
| 483 Member<ResourceLoader> loader_; | 497 Member<ResourceLoader> loader_; |
| 484 ResourceResponse response_; | 498 ResourceResponse response_; |
| 485 | 499 |
| 486 RefPtr<SharedBuffer> data_; | 500 RefPtr<SharedBuffer> data_; |
| 487 }; | 501 }; |
| 488 | 502 |
| 489 class ResourceFactory { | 503 class ResourceFactory { |
| 490 STACK_ALLOCATED(); | 504 STACK_ALLOCATED(); |
| 491 | 505 |
| 492 public: | 506 public: |
| 493 virtual Resource* Create(const ResourceRequest&, | 507 virtual Resource* Create(const ResourceRequest&, |
| 494 const ResourceLoaderOptions&, | 508 const ResourceLoaderOptions&, |
| 495 const String&) const = 0; | 509 const String&, |
| 510 FetchContext*) const = 0; |
| 496 Resource::Type GetType() const { return type_; } | 511 Resource::Type GetType() const { return type_; } |
| 497 | 512 |
| 498 protected: | 513 protected: |
| 499 explicit ResourceFactory(Resource::Type type) : type_(type) {} | 514 explicit ResourceFactory(Resource::Type type) : type_(type) {} |
| 500 | 515 |
| 501 Resource::Type type_; | 516 Resource::Type type_; |
| 502 }; | 517 }; |
| 503 | 518 |
| 504 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ | 519 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
| 505 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, \ | 520 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, \ |
| 506 resource->GetType() == Resource::k##typeName, \ | 521 resource->GetType() == Resource::k##typeName, \ |
| 507 resource.GetType() == Resource::k##typeName); | 522 resource.GetType() == Resource::k##typeName); |
| 508 | 523 |
| 509 } // namespace blink | 524 } // namespace blink |
| 510 | 525 |
| 511 #endif | 526 #endif |
| OLD | NEW |