Changeset 146239 in webkit
- Timestamp:
- Mar 19, 2013 12:39:44 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r146238 r146239 1 2013-03-19 Nate Chapin <japhet@chromium.org> 2 3 Merge MainResourceLoader's SubstituteData loading + others into DocumentLoader 4 https://bugs.webkit.org/show_bug.cgi?id=112722 5 6 Part of the ongoing effort to merge MainResourceLoader entirely 7 into DocumentLoader. 8 9 Reviewed by Antti Koivisto. 10 11 No new tests, refactor only. 12 13 * loader/DocumentLoader.cpp: 14 (WebCore::DocumentLoader::mainReceivedError): Moved from MainResourceLoader::receivedError 15 and the failure case in MainResourceLoader::notifyFinished. 16 (WebCore::DocumentLoader::stopLoading): 17 (WebCore::DocumentLoader::finishedLoading): 18 (WebCore::DocumentLoader::handleSubstituteDataLoadNow): Moved from MainResourceLoader. 19 (WebCore::DocumentLoader::startDataLoadTimer): Moved from MainResourceLoader. 20 (WebCore::DocumentLoader::handleSubstituteDataLoadSoon): Moved from MainResourceLoader. 21 (WebCore::DocumentLoader::willSendRequest): 22 (WebCore::DocumentLoader::continueAfterNavigationPolicy): 23 (WebCore::DocumentLoader::responseReceived): 24 (WebCore::DocumentLoader::receivedData): 25 (WebCore::DocumentLoader::startLoadingMainResource): Most of MainResourceLoader::load 26 moved here. 27 (WebCore::DocumentLoader::cancelMainResourceLoad): MainResourceLoader::cancel 28 moved here. 29 * loader/DocumentLoader.h: 30 * loader/MainResourceLoader.cpp: 31 (WebCore::MainResourceLoader::notifyFinished): 32 (WebCore::MainResourceLoader::reportMemoryUsage): 33 (WebCore::MainResourceLoader::load): 34 (WebCore::MainResourceLoader::identifier): 35 * loader/MainResourceLoader.h: 36 1 37 2013-03-19 Ryosuke Niwa <rniwa@webkit.org> 2 38 -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r146216 r146239 52 52 #include "MemoryCache.h" 53 53 #include "Page.h" 54 #include "ProgressTracker.h" 54 55 #include "ResourceBuffer.h" 55 56 #include "SchemeRegistry.h" … … 113 114 , m_didCreateGlobalHistoryEntry(false) 114 115 , m_timeOfLastDataReceived(0.0) 116 , m_identifierForLoadWithoutResourceLoader(0) 117 , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow) 115 118 , m_waitingForContentPolicy(false) 116 119 , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this))) … … 217 220 { 218 221 ASSERT(!error.isNull()); 222 if (m_applicationCacheHost->maybeLoadFallbackForMainError(request(), error)) 223 return; 224 225 if (m_identifierForLoadWithoutResourceLoader) { 226 ASSERT(!mainResourceLoader()); 227 frameLoader()->client()->dispatchDidFailLoading(this, m_identifierForLoadWithoutResourceLoader, error); 228 } 229 230 // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. 231 // See <rdar://problem/6304600> for more details. 232 #if !USE(CF) 233 ASSERT(!m_frame->page()->defersLoading()); 234 #endif 219 235 220 236 m_applicationCacheHost->failedLoadingMainResource(); … … 279 295 if (m_mainResourceLoader) 280 296 // Stop the main resource loader and let it send the cancelled message. 281 m_mainResourceLoader->cancel(frameLoader->cancelledError(m_request));297 cancelMainResourceLoad(frameLoader->cancelledError(m_request)); 282 298 else if (!m_subresourceLoaders.isEmpty()) 283 299 // The main resource loader already finished loading. Set the cancelled error on the … … 325 341 RefPtr<DocumentLoader> protect(this); 326 342 327 if (m_ mainResourceLoader && m_mainResourceLoader->identifierForLoadWithoutResourceLoader()) {328 frameLoader()->notifier()->dispatchDidFinishLoading(this, m_ mainResourceLoader->identifier(), finishTime);329 m_ mainResourceLoader->clearIdentifierForLoadWithoutResourceLoader();343 if (m_identifierForLoadWithoutResourceLoader) { 344 frameLoader()->notifier()->dispatchDidFinishLoading(this, m_identifierForLoadWithoutResourceLoader, finishTime); 345 m_identifierForLoadWithoutResourceLoader = 0; 330 346 } 331 347 … … 388 404 389 405 return false; 406 } 407 408 void DocumentLoader::handleSubstituteDataLoadNow(DocumentLoaderTimer*) 409 { 410 KURL url = m_substituteData.responseURL(); 411 if (url.isEmpty()) 412 url = m_request.url(); 413 ResourceResponse response(url, m_substituteData.mimeType(), m_substituteData.content()->size(), m_substituteData.textEncoding(), ""); 414 responseReceived(response); 415 } 416 417 void DocumentLoader::startDataLoadTimer() 418 { 419 m_dataLoadTimer.startOneShot(0); 420 421 #if HAVE(RUNLOOP_TIMER) 422 if (SchedulePairHashSet* scheduledPairs = m_frame->page()->scheduledRunLoopPairs()) 423 m_dataLoadTimer.schedule(*scheduledPairs); 424 #endif 425 } 426 427 void DocumentLoader::handleSubstituteDataLoadSoon() 428 { 429 if (deferMainResourceDataLoad()) 430 startDataLoadTimer(); 431 else 432 handleSubstituteDataLoadNow(0); 390 433 } 391 434 … … 443 486 m_applicationCacheHost->maybeLoadMainResourceForRedirect(newRequest, m_substituteData); 444 487 if (m_substituteData.isValid()) 445 m_ mainResourceLoader->takeIdentifierFromResourceLoader();488 m_identifierForLoadWithoutResourceLoader = mainResourceLoader()->identifier(); 446 489 } 447 490 … … 459 502 } 460 503 461 void DocumentLoader::continueAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue)504 void DocumentLoader::continueAfterNavigationPolicy(const ResourceRequest&, bool shouldContinue) 462 505 { 463 506 if (!shouldContinue) … … 478 521 m_mainResourceLoader->clearResource(); 479 522 resourceLoader->setSendCallbackPolicy(SendCallbacks); 480 m_mainResourceLoader->handleSubstituteDataLoadSoon(request);523 handleSubstituteDataLoadSoon(); 481 524 } 482 525 } … … 505 548 if (it != response.httpHeaderFields().end()) { 506 549 String content = it->value; 507 unsigned long identifier = m_ mainResourceLoader->identifier();550 unsigned long identifier = m_identifierForLoadWithoutResourceLoader ? m_identifierForLoadWithoutResourceLoader : mainResourceLoader()->identifier(); 508 551 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, response.url(), identifier)) { 509 552 InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame, this, identifier, response); … … 531 574 setResponse(response); 532 575 533 if (m_ mainResourceLoader->identifierForLoadWithoutResourceLoader())534 frameLoader()->notifier()->dispatchDidReceiveResponse(this, m_ mainResourceLoader->identifierForLoadWithoutResourceLoader(), m_response, 0);576 if (m_identifierForLoadWithoutResourceLoader) 577 frameLoader()->notifier()->dispatchDidReceiveResponse(this, m_identifierForLoadWithoutResourceLoader, m_response, 0); 535 578 536 579 ASSERT(!m_waitingForContentPolicy); … … 781 824 #endif 782 825 783 if (m_ mainResourceLoader->identifierForLoadWithoutResourceLoader())784 frameLoader()->notifier()->dispatchDidReceiveData(this, m_ mainResourceLoader->identifier(), data, length, -1);826 if (m_identifierForLoadWithoutResourceLoader) 827 frameLoader()->notifier()->dispatchDidReceiveData(this, m_identifierForLoadWithoutResourceLoader, data, length, -1); 785 828 786 829 m_applicationCacheHost->mainResourceDataReceived(data, length, -1, false); … … 1312 1355 m_applicationCacheHost->maybeLoadMainResource(m_request, m_substituteData); 1313 1356 1357 if (m_substituteData.isValid()) { 1358 m_identifierForLoadWithoutResourceLoader = m_frame->page()->progress()->createUniqueIdentifier(); 1359 frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, this, m_request); 1360 frameLoader()->notifier()->dispatchWillSendRequest(this, m_identifierForLoadWithoutResourceLoader, m_request, ResourceResponse()); 1361 handleSubstituteDataLoadSoon(); 1362 return; 1363 } 1364 1365 ResourceRequest request(m_request); 1314 1366 m_mainResourceLoader->load(m_request); 1315 1367 … … 1321 1373 m_applicationCacheHost = adoptPtr(new ApplicationCacheHost(this)); 1322 1374 maybeLoadEmpty(); 1323 } 1375 return; 1376 } 1377 1378 if (!mainResourceLoader()) { 1379 m_identifierForLoadWithoutResourceLoader = m_frame->page()->progress()->createUniqueIdentifier(); 1380 frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, this, request); 1381 frameLoader()->notifier()->dispatchWillSendRequest(this, m_identifierForLoadWithoutResourceLoader, request, ResourceResponse()); 1382 } 1383 1384 // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those. 1385 if (mainResourceLoader()) 1386 request = mainResourceLoader()->originalRequest(); 1387 // If there was a fragment identifier on m_request, the cache will have stripped it. m_request should include 1388 // the fragment identifier, so add that back in. 1389 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) 1390 request.setURL(m_request.url()); 1391 setRequest(request); 1324 1392 } 1325 1393 … … 1327 1395 { 1328 1396 ASSERT(!error.isNull()); 1329 1397 RefPtr<DocumentLoader> protect(this); 1398 1399 m_dataLoadTimer.stop(); 1330 1400 if (m_waitingForContentPolicy) { 1331 1401 frameLoader()->policyChecker()->cancelCheck(); … … 1333 1403 m_waitingForContentPolicy = false; 1334 1404 } 1335 m_mainResourceLoader->cancel(error); 1405 1406 if (mainResourceLoader()) 1407 mainResourceLoader()->cancel(error); 1408 1409 mainReceivedError(error); 1336 1410 } 1337 1411 -
trunk/Source/WebCore/loader/DocumentLoader.h
r146216 r146239 46 46 #include <wtf/Vector.h> 47 47 48 #if HAVE(RUNLOOP_TIMER) 49 #include "RunLoopTimer.h" 50 #endif 51 48 52 namespace WTF { 49 53 class SchedulePair; … … 292 296 ResourceError interruptedForPolicyChangeError() const; 293 297 298 #if HAVE(RUNLOOP_TIMER) 299 typedef RunLoopTimer<DocumentLoader> DocumentLoaderTimer; 300 #else 301 typedef Timer<DocumentLoader> DocumentLoaderTimer; 302 #endif 303 void handleSubstituteDataLoadSoon(); 304 void handleSubstituteDataLoadNow(DocumentLoaderTimer*); 305 void startDataLoadTimer(); 306 294 307 void deliverSubstituteResourcesAfterDelay(); 295 308 void substituteResourceDeliveryTimerFired(Timer<DocumentLoader>*); … … 376 389 377 390 double m_timeOfLastDataReceived; 378 391 unsigned long m_identifierForLoadWithoutResourceLoader; 392 393 DocumentLoaderTimer m_dataLoadTimer; 379 394 bool m_waitingForContentPolicy; 380 395 381 396 RefPtr<IconLoadDecisionCallback> m_iconLoadDecisionCallback; 382 397 RefPtr<IconDataCallback> m_iconDataCallback; -
trunk/Source/WebCore/loader/MainResourceLoader.cpp
r146216 r146239 67 67 68 68 MainResourceLoader::MainResourceLoader(DocumentLoader* documentLoader) 69 : m_dataLoadTimer(this, &MainResourceLoader::handleSubstituteDataLoadNow) 70 , m_documentLoader(documentLoader) 71 , m_identifierForLoadWithoutResourceLoader(0) 69 : m_documentLoader(documentLoader) 72 70 { 73 71 } … … 81 79 { 82 80 return adoptRef(new MainResourceLoader(documentLoader)); 83 }84 85 void MainResourceLoader::receivedError(const ResourceError& error)86 {87 // Calling receivedMainResourceError will likely result in the last reference to this object to go away.88 RefPtr<MainResourceLoader> protect(this);89 RefPtr<Frame> protectFrame(m_documentLoader->frame());90 91 if (m_identifierForLoadWithoutResourceLoader) {92 ASSERT(!loader());93 frameLoader()->client()->dispatchDidFailLoading(documentLoader(), m_identifierForLoadWithoutResourceLoader, error);94 }95 96 // It is important that we call DocumentLoader::mainReceivedError before calling97 // ResourceLoadNotifier::didFailToLoad because mainReceivedError clears out the relevant98 // document loaders. Also, mainReceivedError ends up calling a FrameLoadDelegate method99 // and didFailToLoad calls a ResourceLoadDelegate method and they need to be in the correct order.100 documentLoader()->mainReceivedError(error);101 }102 103 void MainResourceLoader::cancel()104 {105 cancel(ResourceError());106 }107 108 void MainResourceLoader::cancel(const ResourceError& error)109 {110 RefPtr<MainResourceLoader> protect(this);111 ResourceError resourceError = error.isNull() ? frameLoader()->cancelledError(request()) : error;112 113 m_dataLoadTimer.stop();114 if (loader())115 loader()->cancel(resourceError);116 117 clearResource();118 receivedError(resourceError);119 81 } 120 82 … … 178 140 } 179 141 #endif 180 181 const ResourceError& error = m_resource->resourceError(); 182 if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainError(request(), error)) 183 return; 184 185 // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred. 186 // See <rdar://problem/6304600> for more details. 187 #if !USE(CF) 188 ASSERT(!defersLoading()); 189 #endif 190 191 receivedError(error); 142 m_documentLoader->mainReceivedError(m_resource->resourceError()); 192 143 } 193 144 … … 197 148 info.addMember(m_resource, "resource"); 198 149 info.addMember(m_initialRequest, "initialRequest"); 199 info.addMember(m_dataLoadTimer, "dataLoadTimer");200 150 info.addMember(m_documentLoader, "documentLoader"); 201 }202 203 void MainResourceLoader::handleSubstituteDataLoadNow(MainResourceLoaderTimer*)204 {205 RefPtr<MainResourceLoader> protect(this);206 207 KURL url = m_documentLoader->substituteData().responseURL();208 if (url.isEmpty())209 url = m_initialRequest.url();210 211 // Clear the initial request here so that subsequent entries into the212 // loader will not think there's still a deferred load left to do.213 m_initialRequest = ResourceRequest();214 215 ResourceResponse response(url, m_documentLoader->substituteData().mimeType(), m_documentLoader->substituteData().content()->size(), m_documentLoader->substituteData().textEncoding(), "");216 responseReceived(0, response);217 }218 219 void MainResourceLoader::startDataLoadTimer()220 {221 m_dataLoadTimer.startOneShot(0);222 223 #if HAVE(RUNLOOP_TIMER)224 if (SchedulePairHashSet* scheduledPairs = m_documentLoader->frame()->page()->scheduledRunLoopPairs())225 m_dataLoadTimer.schedule(*scheduledPairs);226 #endif227 }228 229 void MainResourceLoader::handleSubstituteDataLoadSoon(const ResourceRequest& r)230 {231 m_initialRequest = r;232 233 if (m_documentLoader->deferMainResourceDataLoad())234 startDataLoadTimer();235 else236 handleSubstituteDataLoadNow(0);237 151 } 238 152 239 153 void MainResourceLoader::load(const ResourceRequest& initialRequest) 240 154 { 241 RefPtr<MainResourceLoader> protect(this);242 155 ResourceRequest request(initialRequest); 243 244 if (m_documentLoader->substituteData().isValid()) {245 m_identifierForLoadWithoutResourceLoader = m_documentLoader->frame()->page()->progress()->createUniqueIdentifier();246 frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, documentLoader(), request);247 frameLoader()->notifier()->dispatchWillSendRequest(documentLoader(), m_identifierForLoadWithoutResourceLoader, request, ResourceResponse());248 handleSubstituteDataLoadSoon(request);249 return;250 }251 156 252 157 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, … … 258 163 return; 259 164 } 260 if (!loader()) {261 m_identifierForLoadWithoutResourceLoader = m_documentLoader->frame()->page()->progress()->createUniqueIdentifier();262 frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, documentLoader(), request);263 frameLoader()->notifier()->dispatchWillSendRequest(documentLoader(), m_identifierForLoadWithoutResourceLoader, request, ResourceResponse());264 }265 165 m_resource->addClient(this); 266 267 // A bunch of headers are set when the underlying ResourceLoader is created, and DocumentLoader::m_request needs to include those.268 if (loader())269 request = loader()->originalRequest();270 // If there was a fragment identifier on initialRequest, the cache will have stripped it. DocumentLoader::m_request should include271 // the fragment identifier, so add that back in.272 if (equalIgnoringFragmentIdentifier(initialRequest.url(), request.url()))273 request.setURL(initialRequest.url());274 documentLoader()->setRequest(request);275 166 } 276 167 … … 299 190 unsigned long MainResourceLoader::identifier() const 300 191 { 301 ASSERT(!m_identifierForLoadWithoutResourceLoader || !loader() || !loader()->identifier());302 if (m_identifierForLoadWithoutResourceLoader)303 return m_identifierForLoadWithoutResourceLoader;304 192 if (ResourceLoader* resourceLoader = loader()) 305 193 return resourceLoader->identifier(); -
trunk/Source/WebCore/loader/MainResourceLoader.h
r146216 r146239 37 37 #include <wtf/Forward.h> 38 38 39 #if HAVE(RUNLOOP_TIMER)40 #include <wtf/RunLoopTimer.h>41 #else42 #include "Timer.h"43 #endif44 45 39 namespace WebCore { 46 40 … … 54 48 55 49 void load(const ResourceRequest&); 56 void cancel();57 void cancel(const ResourceError&);58 50 ResourceLoader* loader() const; 59 51 PassRefPtr<ResourceBuffer> resourceData(); … … 62 54 void setDataBufferingPolicy(DataBufferingPolicy); 63 55 64 #if HAVE(RUNLOOP_TIMER)65 typedef RunLoopTimer<MainResourceLoader> MainResourceLoaderTimer;66 #else67 typedef Timer<MainResourceLoader> MainResourceLoaderTimer;68 #endif69 70 56 CachedRawResource* cachedMainResource() { return m_resource.get(); } 71 unsigned long identifierForLoadWithoutResourceLoader() const { return m_identifierForLoadWithoutResourceLoader; }72 void clearIdentifierForLoadWithoutResourceLoader() { m_identifierForLoadWithoutResourceLoader = 0; }73 57 74 58 unsigned long identifier() const; … … 76 60 void reportMemoryUsage(MemoryObjectInfo*) const; 77 61 78 void takeIdentifierFromResourceLoader() { m_identifierForLoadWithoutResourceLoader = identifier(); }79 void handleSubstituteDataLoadSoon(const ResourceRequest&);80 62 void clearResource(); 81 63 … … 87 69 virtual void dataReceived(CachedResource*, const char* data, int dataLength) OVERRIDE; 88 70 virtual void notifyFinished(CachedResource*) OVERRIDE; 89 90 void handleSubstituteDataLoadNow(MainResourceLoaderTimer*);91 92 void startDataLoadTimer();93 94 void receivedError(const ResourceError&);95 96 #if PLATFORM(QT)97 void substituteMIMETypeFromPluginDatabase(const ResourceResponse&);98 #endif99 71 100 72 FrameLoader* frameLoader() const; … … 109 81 ResourceRequest m_initialRequest; 110 82 111 MainResourceLoaderTimer m_dataLoadTimer;112 83 RefPtr<DocumentLoader> m_documentLoader; 113 114 unsigned long m_identifierForLoadWithoutResourceLoader;115 84 }; 116 85
Note: See TracChangeset
for help on using the changeset viewer.