| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 class ResourceFetcher; | 52 class ResourceFetcher; |
| 53 class ResourceTimingInfo; | 53 class ResourceTimingInfo; |
| 54 class InspectorResource; | 54 class InspectorResource; |
| 55 class ResourceLoader; | 55 class ResourceLoader; |
| 56 class SecurityOrigin; | 56 class SecurityOrigin; |
| 57 class SharedBuffer; | 57 class SharedBuffer; |
| 58 | 58 |
| 59 // A resource that is held in the cache. Classes who want to use this object sho
uld derive | 59 // A resource that is held in the cache. Classes who want to use this object sho
uld derive |
| 60 // from ResourceClient, to get the function calls in case the requested data has
arrived. | 60 // from ResourceClient, to get the function calls in case the requested data has
arrived. |
| 61 // This class also does the actual communication with the loader to obtain the r
esource from the network. | 61 // This class also does the actual communication with the loader to obtain the r
esource from the network. |
| 62 class CORE_EXPORT Resource : public RefCountedWillBeGarbageCollectedFinalized<Re
source> { | 62 class CORE_EXPORT Resource : public GarbageCollectedFinalized<Resource> { |
| 63 WTF_MAKE_NONCOPYABLE(Resource); | 63 WTF_MAKE_NONCOPYABLE(Resource); |
| 64 USING_FAST_MALLOC_WITH_TYPE_NAME_WILL_BE_REMOVED(blink::Resource); | |
| 65 friend class InspectorResource; | 64 friend class InspectorResource; |
| 66 | 65 |
| 67 public: | 66 public: |
| 68 enum Type { | 67 enum Type { |
| 69 MainResource, | 68 MainResource, |
| 70 Image, | 69 Image, |
| 71 CSSStyleSheet, | 70 CSSStyleSheet, |
| 72 Script, | 71 Script, |
| 73 Font, | 72 Font, |
| 74 Raw, | 73 Raw, |
| 75 SVGDocument, | 74 SVGDocument, |
| 76 XSLStyleSheet, | 75 XSLStyleSheet, |
| 77 LinkPrefetch, | 76 LinkPrefetch, |
| 78 LinkPreload, | 77 LinkPreload, |
| 79 TextTrack, | 78 TextTrack, |
| 80 ImportResource, | 79 ImportResource, |
| 81 Media, // Audio or video file requested by a HTML5 media element | 80 Media, // Audio or video file requested by a HTML5 media element |
| 82 Manifest | 81 Manifest |
| 83 }; | 82 }; |
| 84 | 83 |
| 85 enum Status { | 84 enum Status { |
| 86 Unknown, // let cache decide what to do with it | 85 Unknown, // let cache decide what to do with it |
| 87 Pending, // only partially loaded | 86 Pending, // only partially loaded |
| 88 Cached, // regular case | 87 Cached, // regular case |
| 89 LoadError, | 88 LoadError, |
| 90 DecodeError | 89 DecodeError |
| 91 }; | 90 }; |
| 92 | 91 |
| 93 // Exposed for testing. | 92 // Exposed for testing. |
| 94 static PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest& reques
t, Type type) | 93 static RawPtr<Resource> create(const ResourceRequest& request, Type type) |
| 95 { | 94 { |
| 96 return adoptRefWillBeNoop(new Resource(request, type)); | 95 return (new Resource(request, type)); |
| 97 } | 96 } |
| 98 virtual ~Resource(); | 97 virtual ~Resource(); |
| 99 | 98 |
| 100 virtual void removedFromMemoryCache(); | 99 virtual void removedFromMemoryCache(); |
| 101 DECLARE_VIRTUAL_TRACE(); | 100 DECLARE_VIRTUAL_TRACE(); |
| 102 | 101 |
| 103 virtual void load(ResourceFetcher*, const ResourceLoaderOptions&); | 102 virtual void load(ResourceFetcher*, const ResourceLoaderOptions&); |
| 104 | 103 |
| 105 virtual void setEncoding(const String&) { } | 104 virtual void setEncoding(const String&) { } |
| 106 virtual String encoding() const { return String(); } | 105 virtual String encoding() const { return String(); } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 248 |
| 250 // Used by the MemoryCache to reduce the memory consumption of the entry. | 249 // Used by the MemoryCache to reduce the memory consumption of the entry. |
| 251 void prune(); | 250 void prune(); |
| 252 | 251 |
| 253 virtual void onMemoryDump(WebMemoryDumpLevelOfDetail, WebProcessMemoryDump*)
const; | 252 virtual void onMemoryDump(WebMemoryDumpLevelOfDetail, WebProcessMemoryDump*)
const; |
| 254 | 253 |
| 255 static const char* resourceTypeToString(Type, const FetchInitiatorInfo&); | 254 static const char* resourceTypeToString(Type, const FetchInitiatorInfo&); |
| 256 static const char* resourceTypeName(Type); | 255 static const char* resourceTypeName(Type); |
| 257 | 256 |
| 258 // TODO(japhet): Remove once oilpan ships, it doesn't need the WeakPtr. | 257 // TODO(japhet): Remove once oilpan ships, it doesn't need the WeakPtr. |
| 259 WeakPtrWillBeRawPtr<Resource> asWeakPtr(); | 258 RawPtr<Resource> asWeakPtr(); |
| 260 | 259 |
| 261 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK | 260 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
| 262 void assertAlive() const { RELEASE_ASSERT(!m_deleted); } | 261 void assertAlive() const { RELEASE_ASSERT(!m_deleted); } |
| 263 #else | 262 #else |
| 264 void assertAlive() const { } | 263 void assertAlive() const { } |
| 265 #endif | 264 #endif |
| 266 | 265 |
| 267 protected: | 266 protected: |
| 268 Resource(const ResourceRequest&, Type); | 267 Resource(const ResourceRequest&, Type); |
| 269 | 268 |
| 270 virtual void checkNotify(); | 269 virtual void checkNotify(); |
| 271 virtual void finishOnePart(); | 270 virtual void finishOnePart(); |
| 272 | 271 |
| 273 virtual void destroyDecodedDataForFailedRevalidation() { } | 272 virtual void destroyDecodedDataForFailedRevalidation() { } |
| 274 | 273 |
| 275 void setEncodedSize(size_t); | 274 void setEncodedSize(size_t); |
| 276 void setDecodedSize(size_t); | 275 void setDecodedSize(size_t); |
| 277 void didAccessDecodedData(); | 276 void didAccessDecodedData(); |
| 278 | 277 |
| 279 void finishPendingClients(); | 278 void finishPendingClients(); |
| 280 | 279 |
| 281 HashCountedSet<ResourceClient*> m_clients; | 280 HashCountedSet<ResourceClient*> m_clients; |
| 282 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback; | 281 HashCountedSet<ResourceClient*> m_clientsAwaitingCallback; |
| 283 HashCountedSet<ResourceClient*> m_finishedClients; | 282 HashCountedSet<ResourceClient*> m_finishedClients; |
| 284 | 283 |
| 285 class ResourceCallback : public NoBaseWillBeGarbageCollectedFinalized<Resour
ceCallback> { | 284 class ResourceCallback : public GarbageCollectedFinalized<ResourceCallback>
{ |
| 286 public: | 285 public: |
| 287 static ResourceCallback* callbackHandler(); | 286 static ResourceCallback* callbackHandler(); |
| 288 DECLARE_TRACE(); | 287 DECLARE_TRACE(); |
| 289 void schedule(Resource*); | 288 void schedule(Resource*); |
| 290 void cancel(Resource*); | 289 void cancel(Resource*); |
| 291 bool isScheduled(Resource*) const; | 290 bool isScheduled(Resource*) const; |
| 292 private: | 291 private: |
| 293 ResourceCallback(); | 292 ResourceCallback(); |
| 294 void runTask(); | 293 void runTask(); |
| 295 OwnPtr<CancellableTaskFactory> m_callbackTaskFactory; | 294 OwnPtr<CancellableTaskFactory> m_callbackTaskFactory; |
| 296 WillBeHeapHashSet<RefPtrWillBeMember<Resource>> m_resourcesWithPendingCl
ients; | 295 HeapHashSet<Member<Resource>> m_resourcesWithPendingClients; |
| 297 }; | 296 }; |
| 298 | 297 |
| 299 bool hasClient(ResourceClient* client) { return m_clients.contains(client) |
| m_clientsAwaitingCallback.contains(client) || m_finishedClients.contains(clien
t); } | 298 bool hasClient(ResourceClient* client) { return m_clients.contains(client) |
| m_clientsAwaitingCallback.contains(client) || m_finishedClients.contains(clien
t); } |
| 300 | 299 |
| 301 struct RedirectPair { | 300 struct RedirectPair { |
| 302 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 301 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 303 public: | 302 public: |
| 304 explicit RedirectPair(const ResourceRequest& request, const ResourceResp
onse& redirectResponse) | 303 explicit RedirectPair(const ResourceRequest& request, const ResourceResp
onse& redirectResponse) |
| 305 : m_request(request) | 304 : m_request(request) |
| 306 , m_redirectResponse(redirectResponse) | 305 , m_redirectResponse(redirectResponse) |
| 307 { | 306 { |
| 308 } | 307 } |
| 309 | 308 |
| 310 ResourceRequest m_request; | 309 ResourceRequest m_request; |
| 311 ResourceResponse m_redirectResponse; | 310 ResourceResponse m_redirectResponse; |
| 312 }; | 311 }; |
| 313 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain;
} | 312 const Vector<RedirectPair>& redirectChain() const { return m_redirectChain;
} |
| 314 | 313 |
| 315 virtual bool isSafeToUnlock() const { return false; } | 314 virtual bool isSafeToUnlock() const { return false; } |
| 316 virtual void destroyDecodedDataIfPossible() { } | 315 virtual void destroyDecodedDataIfPossible() { } |
| 317 | 316 |
| 318 void markClientsFinished(); | 317 void markClientsFinished(); |
| 319 | 318 |
| 320 // Returns the memory dump name used for tracing. See Resource::onMemoryDump
. | 319 // Returns the memory dump name used for tracing. See Resource::onMemoryDump
. |
| 321 String getMemoryDumpName() const; | 320 String getMemoryDumpName() const; |
| 322 | 321 |
| 323 ResourceRequest m_resourceRequest; | 322 ResourceRequest m_resourceRequest; |
| 324 ResourceRequest m_revalidatingRequest; | 323 ResourceRequest m_revalidatingRequest; |
| 325 AtomicString m_accept; | 324 AtomicString m_accept; |
| 326 PersistentWillBeMember<ResourceLoader> m_loader; | 325 Member<ResourceLoader> m_loader; |
| 327 ResourceLoaderOptions m_options; | 326 ResourceLoaderOptions m_options; |
| 328 | 327 |
| 329 ResourceResponse m_response; | 328 ResourceResponse m_response; |
| 330 double m_responseTimestamp; | 329 double m_responseTimestamp; |
| 331 | 330 |
| 332 RefPtr<SharedBuffer> m_data; | 331 RefPtr<SharedBuffer> m_data; |
| 333 Timer<Resource> m_cancelTimer; | 332 Timer<Resource> m_cancelTimer; |
| 334 | 333 |
| 335 private: | 334 private: |
| 336 class CacheHandler; | 335 class CacheHandler; |
| 337 void cancelTimerFired(Timer<Resource>*); | 336 void cancelTimerFired(Timer<Resource>*); |
| 338 | 337 |
| 339 void switchClientsToRevalidatedResource(); | 338 void switchClientsToRevalidatedResource(); |
| 340 void revalidationSucceeded(const ResourceResponse&); | 339 void revalidationSucceeded(const ResourceResponse&); |
| 341 void revalidationFailed(); | 340 void revalidationFailed(); |
| 342 | 341 |
| 343 bool unlock(); | 342 bool unlock(); |
| 344 | 343 |
| 345 void setCachedMetadata(unsigned dataTypeID, const char*, size_t, CachedMetad
ataHandler::CacheType); | 344 void setCachedMetadata(unsigned dataTypeID, const char*, size_t, CachedMetad
ataHandler::CacheType); |
| 346 void clearCachedMetadata(CachedMetadataHandler::CacheType); | 345 void clearCachedMetadata(CachedMetadataHandler::CacheType); |
| 347 CachedMetadata* cachedMetadata(unsigned dataTypeID) const; | 346 CachedMetadata* cachedMetadata(unsigned dataTypeID) const; |
| 348 | 347 |
| 349 String m_fragmentIdentifierForRequest; | 348 String m_fragmentIdentifierForRequest; |
| 350 | 349 |
| 351 #if !ENABLE(OILPAN) | 350 #if !ENABLE(OILPAN) |
| 352 WeakPtrFactory<Resource> m_weakPtrFactory; | 351 WeakPtrFactory<Resource> m_weakPtrFactory; |
| 353 #endif | 352 #endif |
| 354 | 353 |
| 355 RefPtr<CachedMetadata> m_cachedMetadata; | 354 RefPtr<CachedMetadata> m_cachedMetadata; |
| 356 OwnPtrWillBeMember<CacheHandler> m_cacheHandler; | 355 Member<CacheHandler> m_cacheHandler; |
| 357 | 356 |
| 358 ResourceError m_error; | 357 ResourceError m_error; |
| 359 | 358 |
| 360 double m_loadFinishTime; | 359 double m_loadFinishTime; |
| 361 | 360 |
| 362 unsigned long m_identifier; | 361 unsigned long m_identifier; |
| 363 | 362 |
| 364 size_t m_encodedSize; | 363 size_t m_encodedSize; |
| 365 size_t m_decodedSize; | 364 size_t m_decodedSize; |
| 366 unsigned m_preloadCount; | 365 unsigned m_preloadCount; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 382 bool m_deleted; | 381 bool m_deleted; |
| 383 #endif | 382 #endif |
| 384 | 383 |
| 385 // Ordered list of all redirects followed while fetching this resource. | 384 // Ordered list of all redirects followed while fetching this resource. |
| 386 Vector<RedirectPair> m_redirectChain; | 385 Vector<RedirectPair> m_redirectChain; |
| 387 }; | 386 }; |
| 388 | 387 |
| 389 class ResourceFactory { | 388 class ResourceFactory { |
| 390 STACK_ALLOCATED(); | 389 STACK_ALLOCATED(); |
| 391 public: | 390 public: |
| 392 virtual PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest&, cons
t String&) const = 0; | 391 virtual RawPtr<Resource> create(const ResourceRequest&, const String&) const
= 0; |
| 393 Resource::Type type() const { return m_type; } | 392 Resource::Type type() const { return m_type; } |
| 394 | 393 |
| 395 protected: | 394 protected: |
| 396 ResourceFactory(Resource::Type type) : m_type(type) { } | 395 ResourceFactory(Resource::Type type) : m_type(type) { } |
| 397 | 396 |
| 398 Resource::Type m_type; | 397 Resource::Type m_type; |
| 399 }; | 398 }; |
| 400 | 399 |
| 401 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ | 400 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
| 402 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ | 401 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ |
| 403 inline typeName##Resource* to##typeName##Resource(const RefPtrWillBeRawPtr<R
esource>& ptr) { return to##typeName##Resource(ptr.get()); } | 402 inline typeName##Resource* to##typeName##Resource(const RawPtr<Resource>& pt
r) { return to##typeName##Resource(ptr.get()); } |
| 404 | 403 |
| 405 } // namespace blink | 404 } // namespace blink |
| 406 | 405 |
| 407 #endif | 406 #endif |
| OLD | NEW |