bool MainResourceLoader::loadNow(ResourceRequest& r) { bool shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument(r.url()); ASSERT(!m_handle); ASSERT(shouldLoadEmptyBeforeRedirect || !defersLoading()); // Send this synthetic delegate callback since clients expect it, and // we no longer send the callback from within NSURLConnection for // initial requests. willSendRequest(r, ResourceResponse()); ASSERT(!deletionHasBegun()); // <rdar://problem/4801066> // willSendRequest() is liable to make the call to frameLoader() return NULL, so we need to check that here if (!frameLoader()) return false; const KURL& url = r.url(); bool shouldLoadEmpty = shouldLoadAsEmptyDocument(url) && !m_substituteData.isValid(); if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && defersLoading()) return true; resourceLoadScheduler()->addMainResourceLoad(this); if (m_substituteData.isValid()) handleSubstituteDataLoadSoon(r); else if (shouldLoadEmpty || frameLoader()->client()->representationExistsForURLScheme(url.protocol())) handleEmptyLoad(url, !shouldLoadEmpty); else m_handle = ResourceHandle::create(m_frame->loader()->networkingContext(), r, this, false, true); return false; }
void MainResourceLoader::load(const ResourceRequest& initialRequest, const SubstituteData& substituteData) { // It appears that it is possible for this load to be cancelled and derefenced by the DocumentLoader // in willSendRequest() if loadNow() is called. RefPtr<MainResourceLoader> protect(this); m_substituteData = substituteData; ASSERT(documentLoader()->timing()->navigationStart()); ASSERT(!documentLoader()->timing()->fetchStart()); documentLoader()->timing()->markFetchStart(); ResourceRequest request(initialRequest); // Send this synthetic delegate callback since clients expect it, and // we no longer send the callback from within NSURLConnection for // initial requests. willSendRequest(request, ResourceResponse()); ASSERT(!deletionHasBegun()); // willSendRequest() may lead to our DocumentLoader being detached or cancelling the load via nulling the ResourceRequest. if (!documentLoader()->frame() || request.isNull()) return; documentLoader()->applicationCacheHost()->maybeLoadMainResource(request, m_substituteData); if (m_substituteData.isValid()) { m_identifierForLoadWithoutResourceLoader = m_documentLoader->frame()->page()->progress()->createUniqueIdentifier(); frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, documentLoader(), request); frameLoader()->notifier()->dispatchWillSendRequest(documentLoader(), m_identifierForLoadWithoutResourceLoader, request, ResourceResponse()); handleSubstituteDataLoadSoon(request); return; } DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, (SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForCrossOriginCredentials, SkipSecurityCheck)); CachedResourceRequest cachedResourceRequest(request, mainResourceLoadOptions); m_resource = documentLoader()->cachedResourceLoader()->requestMainResource(cachedResourceRequest); if (!m_resource) { documentLoader()->setRequest(ResourceRequest()); return; } if (!loader()) { m_identifierForLoadWithoutResourceLoader = m_documentLoader->frame()->page()->progress()->createUniqueIdentifier(); frameLoader()->notifier()->assignIdentifierToInitialRequest(m_identifierForLoadWithoutResourceLoader, documentLoader(), request); frameLoader()->notifier()->dispatchWillSendRequest(documentLoader(), m_identifierForLoadWithoutResourceLoader, request, ResourceResponse()); } m_resource->addClient(this); // A bunch of headers are set when the underlying ResourceLoader is created, and DocumentLoader::m_request needs to include those. if (loader()) request = loader()->originalRequest(); // If there was a fragment identifier on initialRequest, the cache will have stripped it. DocumentLoader::m_request should include // the fragment identifier, so add that back in. if (equalIgnoringFragmentIdentifier(initialRequest.url(), request.url())) request.setURL(initialRequest.url()); documentLoader()->setRequest(request); }
void DocumentLoader::startLoadingMainResource() { m_mainDocumentError = ResourceError(); timing()->markNavigationStart(); ASSERT(!m_mainResource); ASSERT(!m_loadingMainResource); m_loadingMainResource = true; if (maybeLoadEmpty()) return; ASSERT(timing()->navigationStart()); ASSERT(!timing()->fetchStart()); timing()->markFetchStart(); willSendRequest(m_request, ResourceResponse()); // willSendRequest() may lead to our Frame being detached or cancelling the load via nulling the ResourceRequest. if (!m_frame || m_request.isNull()) return; m_applicationCacheHost->willStartLoadingMainResource(m_request); prepareSubframeArchiveLoadIfNeeded(); if (m_substituteData.isValid()) { m_identifierForLoadWithoutResourceLoader = createUniqueIdentifier(); frameLoader()->notifier()->dispatchWillSendRequest(this, m_identifierForLoadWithoutResourceLoader, m_request, ResourceResponse()); handleSubstituteDataLoadSoon(); return; } ResourceRequest request(m_request); DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, (SendCallbacks, SniffContent, DoNotBufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientForCrossOriginCredentials, SkipSecurityCheck, CheckContentSecurityPolicy, UseDefaultOriginRestrictionsForType)); CachedResourceRequest cachedResourceRequest(request, cachedResourceRequestInitiators().document, mainResourceLoadOptions); m_mainResource = m_cachedResourceLoader->requestMainResource(cachedResourceRequest); if (!m_mainResource) { setRequest(ResourceRequest()); // If the load was aborted by clearing m_request, it's possible the ApplicationCacheHost // is now in a state where starting an empty load will be inconsistent. Replace it with // a new ApplicationCacheHost. m_applicationCacheHost = adoptPtr(new ApplicationCacheHost(this)); maybeLoadEmpty(); return; } m_mainResource->addClient(this); // A bunch of headers are set when the underlying ResourceLoader is created, and m_request needs to include those. if (mainResourceLoader()) request = mainResourceLoader()->originalRequest(); // If there was a fragment identifier on m_request, the cache will have stripped it. m_request should include // the fragment identifier, so add that back in. if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) request.setURL(m_request.url()); setRequest(request); }
void MainResourceLoader::continueAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue) { if (!shouldContinue) stopLoadingForPolicyChange(); else if (m_substituteData.isValid()) { // A redirect resulted in loading substitute data. ASSERT(documentLoader()->timing()->redirectCount()); handle()->cancel(); handleSubstituteDataLoadSoon(request); } deref(); // balances ref in willSendRequest }
void MainResourceLoader::load(const ResourceRequest& initialRequest, const SubstituteData& substituteData) { // It appears that it is possible for this load to be cancelled and derefenced by the DocumentLoader // in willSendRequest() if loadNow() is called. RefPtr<MainResourceLoader> protect(this); m_substituteData = substituteData; ASSERT(documentLoader()->timing()->navigationStart()); ASSERT(!documentLoader()->timing()->fetchStart()); documentLoader()->timing()->markFetchStart(); ResourceRequest request(initialRequest); // Send this synthetic delegate callback since clients expect it, and // we no longer send the callback from within NSURLConnection for // initial requests. willSendRequest(request, ResourceResponse()); ASSERT(!deletionHasBegun()); // willSendRequest() may lead to our DocumentLoader being detached or cancelling the load via nulling the ResourceRequest. if (!documentLoader()->frame() || request.isNull()) return; documentLoader()->applicationCacheHost()->maybeLoadMainResource(request, m_substituteData); if (m_substituteData.isValid()) { handleSubstituteDataLoadSoon(request); return; } DEFINE_STATIC_LOCAL(ResourceLoaderOptions, mainResourceLoadOptions, (SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForCrossOriginCredentials, SkipSecurityCheck)); CachedResourceRequest cachedResourceRequest(request, mainResourceLoadOptions); m_resource = documentLoader()->cachedResourceLoader()->requestMainResource(cachedResourceRequest); if (!m_resource) { documentLoader()->setRequest(ResourceRequest()); return; } m_resource->addClient(this); // We need to wait until after requestMainResource() is called to setRequest(), because there are a bunch of headers set when // the underlying ResourceLoader is created, and DocumentLoader::m_request needs to include those. However, the cache will // strip the fragment identifier (which DocumentLoader::m_request should also include), so add that back in. if (loader()) request = loader()->originalRequest(); documentLoader()->setRequest(request); }
void MainResourceLoader::loadNow(ResourceRequest& r) { ASSERT(!m_handle); ASSERT(!defersLoading()); #if USE(PLATFORM_STRATEGIES) platformStrategies()->loaderStrategy()->resourceLoadScheduler()->addMainResourceLoad(this); #else resourceLoadScheduler()->addMainResourceLoad(this); #endif if (m_substituteData.isValid()) handleSubstituteDataLoadSoon(r); else m_handle = ResourceHandle::create(m_frame->loader()->networkingContext(), r, this, false, true); return; }
void MainResourceLoader::continueAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue) { if (!shouldContinue) stopLoadingForPolicyChange(); else if (m_substituteData.isValid()) { // A redirect resulted in loading substitute data. ASSERT(documentLoader()->timing()->redirectCount()); // We need to remove our reference to the CachedResource in favor of a SubstituteData load. // This will probably trigger the cancellation of the CachedResource's underlying ResourceLoader, though there is a // small chance that the resource is being loaded by a different Frame, preventing the ResourceLoader from being cancelled. // If the ResourceLoader is indeed cancelled, it would normally send resource load callbacks. // However, from an API perspective, this isn't a cancellation. Therefore, sever our relationship with the network load via clearResource(), // but prevent the ResourceLoader from sending ResourceLoadNotifier callbacks. RefPtr<ResourceLoader> resourceLoader = loader(); ASSERT(resourceLoader->shouldSendResourceLoadCallbacks()); resourceLoader->setSendCallbackPolicy(DoNotSendCallbacks); clearResource(); resourceLoader->setSendCallbackPolicy(SendCallbacks); handleSubstituteDataLoadSoon(request); } deref(); // balances ref in willSendRequest }