Changeset 207459 in webkit
- Timestamp:
- Oct 18, 2016 5:30:40 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207458 r207459 1 2016-10-18 Youenn Fablet <youenn@apple.com> 2 3 CachedResourceLoader should not need to remove fragment identifier 4 https://bugs.webkit.org/show_bug.cgi?id=163015 5 6 Reviewed by Darin Adler. 7 8 No expected change for non-window port. 9 For window port, CachedResourceLoader will strip the fragment identifier of the URL passed to subresourceForURL 10 before querying the memory cache. 11 12 Removing the fragment identifier from the request stored in CachedResourceRequest. 13 The fragment identifier is stored in a separate field. 14 15 This allows CachedResourceLoader to not care about fragment identifier. 16 CachedResource can then get access to it. 17 18 * loader/cache/CachedResource.cpp: 19 (WebCore::CachedResource::CachedResource): 20 (WebCore::CachedResource::finishRequestInitialization): Deleted. 21 * loader/cache/CachedResource.h: 22 * loader/cache/CachedResourceLoader.cpp: 23 (WebCore::CachedResourceLoader::cachedResource): 24 Updated the method taking a const String& to strip the fragment identifier if needed. 25 Updated the method taking a const URL& to assert if the fragment identifier is present. 26 (WebCore::CachedResourceLoader::requestUserCSSStyleSheet): 27 (WebCore::CachedResourceLoader::requestResource): 28 * loader/cache/CachedResourceRequest.cpp: 29 (WebCore::CachedResourceRequest::CachedResourceRequest): 30 (WebCore::CachedResourceRequest::splitFragmentIdentifierFromRequestURL): 31 * loader/cache/CachedResourceRequest.h: 32 (WebCore::CachedResourceRequest::releaseFragmentIdentifier): 33 (WebCore::CachedResourceRequest::clearFragmentIdentifier): 34 * loader/cache/MemoryCache.cpp: 35 (WebCore::MemoryCache::shouldRemoveFragmentIdentifier): 36 (WebCore::MemoryCache::removeFragmentIdentifierIfNeeded): 37 (WebCore::MemoryCache::revalidationSucceeded): 38 (WebCore::MemoryCache::resourceForRequest): 39 * loader/cache/MemoryCache.h: 40 1 41 2016-10-18 Antti Koivisto <antti@apple.com> 2 42 -
trunk/Source/WebCore/loader/cache/CachedResource.cpp
r207281 r207459 122 122 , m_loadPriority(defaultPriorityForResourceType(type)) 123 123 , m_responseTimestamp(std::chrono::system_clock::now()) 124 , m_fragmentIdentifierForRequest(request.releaseFragmentIdentifier()) 124 125 , m_origin(request.releaseOrigin()) 125 126 , m_type(type) … … 128 129 129 130 setLoadPriority(request.priority()); 130 finishRequestInitialization(); 131 #ifndef NDEBUG 132 cachedResourceLeakCounter.increment(); 133 #endif 131 134 132 135 // FIXME: We should have a better way of checking for Navigation loads, maybe FetchMode::Options::Navigate. … … 139 142 } 140 143 144 // FIXME: For this constructor, we should probably mandate that the URL has no fragment identifier. 141 145 CachedResource::CachedResource(const URL& url, Type type, SessionID sessionID) 142 146 : m_resourceRequest(url) … … 144 148 , m_sessionID(sessionID) 145 149 , m_responseTimestamp(std::chrono::system_clock::now()) 150 , m_fragmentIdentifierForRequest(CachedResourceRequest::splitFragmentIdentifierFromRequestURL(m_resourceRequest)) 146 151 , m_type(type) 147 152 , m_status(Cached) 148 153 { 149 154 ASSERT(sessionID.isValid()); 150 finishRequestInitialization();151 }152 153 void CachedResource::finishRequestInitialization()154 {155 155 #ifndef NDEBUG 156 156 cachedResourceLeakCounter.increment(); 157 157 #endif 158 159 if (!m_resourceRequest.url().hasFragmentIdentifier())160 return;161 URL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceRequest.url());162 if (urlForCache.hasFragmentIdentifier())163 return;164 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier();165 m_resourceRequest.setURL(urlForCache);166 158 } 167 159 -
trunk/Source/WebCore/loader/cache/CachedResource.h
r206994 r207459 303 303 class Callback; 304 304 305 void finishRequestInitialization();306 307 305 bool addClientToSet(CachedResourceClient&); 308 306 -
trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp
r207331 r207459 149 149 } 150 150 151 CachedResource* CachedResourceLoader::cachedResource(const String& resourceURL) const 151 CachedResource* CachedResourceLoader::cachedResource(const String& resourceURL) const 152 152 { 153 153 ASSERT(!resourceURL.isNull()); 154 URL url = m_document->completeURL(resourceURL); 155 return cachedResource(url); 156 } 157 158 CachedResource* CachedResourceLoader::cachedResource(const URL& resourceURL) const 159 { 160 URL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); 161 return m_documentResources.get(url).get(); 154 return cachedResource(MemoryCache::removeFragmentIdentifierIfNeeded(m_document->completeURL(resourceURL))); 155 } 156 157 CachedResource* CachedResourceLoader::cachedResource(const URL& url) const 158 { 159 ASSERT(!MemoryCache::shouldRemoveFragmentIdentifier(url)); 160 return m_documentResources.get(url).get(); 162 161 } 163 162 … … 657 656 658 657 LOG(ResourceLoading, "CachedResourceLoader::requestResource '%s', charset '%s', priority=%d, forPreload=%u", url.stringCenterEllipsizedToLength().latin1().data(), request.charset().latin1().data(), request.priority() ? static_cast<int>(request.priority().value()) : -1, forPreload == ForPreload::Yes); 659 660 // If only the fragment identifiers differ, it is the same resource.661 url = MemoryCache::removeFragmentIdentifierIfNeeded(url);662 658 663 659 if (!url.isValid()) { -
trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp
r207330 r207459 43 43 , m_options(options) 44 44 , m_priority(priority) 45 { 45 , m_fragmentIdentifier(splitFragmentIdentifierFromRequestURL(m_resourceRequest)) 46 { 47 } 48 49 String CachedResourceRequest::splitFragmentIdentifierFromRequestURL(ResourceRequest& request) 50 { 51 if (!MemoryCache::shouldRemoveFragmentIdentifier(request.url())) 52 return { }; 53 URL url = request.url(); 54 String fragmentIdentifier = url.fragmentIdentifier(); 55 url.removeFragmentIdentifier(); 56 request.setURL(url); 57 return fragmentIdentifier; 46 58 } 47 59 -
trunk/Source/WebCore/loader/cache/CachedResourceRequest.h
r207281 r207459 79 79 SecurityOrigin* origin() const { return m_origin.get(); } 80 80 81 String&& releaseFragmentIdentifier() { return WTFMove(m_fragmentIdentifier); } 82 void clearFragmentIdentifier() { m_fragmentIdentifier = { }; } 83 84 static String splitFragmentIdentifierFromRequestURL(ResourceRequest&); 85 81 86 private: 82 87 ResourceRequest m_resourceRequest; … … 87 92 AtomicString m_initiatorName; 88 93 RefPtr<SecurityOrigin> m_origin; 94 String m_fragmentIdentifier; 89 95 }; 90 96 -
trunk/Source/WebCore/loader/cache/MemoryCache.cpp
r206867 r207459 90 90 } 91 91 92 bool MemoryCache::shouldRemoveFragmentIdentifier(const URL& originalURL) 93 { 94 if (!originalURL.hasFragmentIdentifier()) 95 return false; 96 // Strip away fragment identifier from HTTP URLs. 97 // Data URLs must be unmodified. For file and custom URLs clients may expect resources 98 // to be unique even when they differ by the fragment identifier only. 99 return originalURL.protocolIsInHTTPFamily(); 100 } 101 92 102 URL MemoryCache::removeFragmentIdentifierIfNeeded(const URL& originalURL) 93 103 { 94 if (!originalURL.hasFragmentIdentifier()) 95 return originalURL; 96 // Strip away fragment identifier from HTTP URLs. 97 // Data URLs must be unmodified. For file and custom URLs clients may expect resources 98 // to be unique even when they differ by the fragment identifier only. 99 if (!originalURL.protocolIsInHTTPFamily()) 104 if (!shouldRemoveFragmentIdentifier(originalURL)) 100 105 return originalURL; 101 106 URL url = originalURL; … … 155 160 if (delta) 156 161 adjustSize(resource.hasClients(), delta); 157 162 158 163 revalidatingResource.switchClientsToRevalidatedResource(); 159 164 ASSERT(!revalidatingResource.m_deleted); … … 172 177 CachedResource* MemoryCache::resourceForRequest(const ResourceRequest& request, SessionID sessionID) 173 178 { 179 // FIXME: Change all clients to make sure HTTP(s) URLs have no fragment identifiers before calling here. 180 // CachedResourceLoader is now doing this. Add an assertion once all other clients are doing it too. 174 181 auto* resources = sessionResourceMap(sessionID); 175 182 if (!resources) -
trunk/Source/WebCore/loader/cache/MemoryCache.h
r206635 r207459 98 98 void remove(CachedResource&); 99 99 100 static URL removeFragmentIdentifierIfNeeded(const URL& originalURL); 101 100 static bool shouldRemoveFragmentIdentifier(const URL&); 101 static URL removeFragmentIdentifierIfNeeded(const URL&); 102 102 103 void revalidationSucceeded(CachedResource& revalidatingResource, const ResourceResponse&); 103 104 void revalidationFailed(CachedResource& revalidatingResource); … … 106 107 void forEachSessionResource(SessionID, const std::function<void(CachedResource&)>&); 107 108 void destroyDecodedDataForAllImages(); 108 109 // Sets the cache's memory capacities, in bytes. These will hold only approximately, 109 110 // Sets the cache's memory capacities, in bytes. These will hold only approximately, 110 111 // since the decoded cost of resources like scripts and stylesheets is not known. 111 112 // - minDeadBytes: The maximum number of bytes that dead resources should consume when the cache is under pressure. … … 121 122 WEBCORE_EXPORT void evictResources(); 122 123 WEBCORE_EXPORT void evictResources(SessionID); 123 124 124 125 void prune(); 125 126 void pruneSoon();
Note: See TracChangeset
for help on using the changeset viewer.