void ResourceLoader::cancel(const ResourceError& error) { if (m_reachedTerminalState) return; if (!error.isNull()) didCancel(error); else didCancel(cancelledError()); }
static xmlDocPtr docLoaderFunc(const xmlChar* uri, xmlDictPtr, int options, void* ctxt, xsltLoadType type) { if (!globalProcessor) return 0; switch (type) { case XSLT_LOAD_DOCUMENT: { xsltTransformContextPtr context = (xsltTransformContextPtr)ctxt; xmlChar* base = xmlNodeGetBase(context->document->doc, context->node); URL url(URL(ParsedURLString, reinterpret_cast<const char*>(base)), reinterpret_cast<const char*>(uri)); xmlFree(base); ResourceError error; ResourceResponse response; Vector<char> data; bool requestAllowed = globalCachedResourceLoader->frame() && globalCachedResourceLoader->document()->securityOrigin()->canRequest(url); if (requestAllowed) { globalCachedResourceLoader->frame()->loader().loadResourceSynchronously(url, AllowStoredCredentials, DoNotAskClientForCrossOriginCredentials, error, response, data); if (error.isNull()) requestAllowed = globalCachedResourceLoader->document()->securityOrigin()->canRequest(response.url()); else data.clear(); } if (!requestAllowed) { data.clear(); globalCachedResourceLoader->printAccessDeniedMessage(url); } PageConsole* console = 0; Frame* frame = globalProcessor->xslStylesheet()->ownerDocument()->frame(); if (frame && frame->page()) console = &frame->page()->console(); xmlSetStructuredErrorFunc(console, XSLTProcessor::parseErrorFunc); xmlSetGenericErrorFunc(console, XSLTProcessor::genericErrorFunc); // We don't specify an encoding here. Neither Gecko nor WinIE respects // the encoding specified in the HTTP headers. xmlDocPtr doc = xmlReadMemory(data.data(), data.size(), (const char*)uri, 0, options); xmlSetStructuredErrorFunc(0, 0); xmlSetGenericErrorFunc(0, 0); return doc; } case XSLT_LOAD_STYLESHEET: return globalProcessor->xslStylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri); default: break; } return 0; }
void ResourceLoadNotifier::dispatchDidFail(DocumentLoader* loader, unsigned long identifier, const ResourceError& error) { if (Page* page = m_frame->page()) page->progress()->completeProgress(identifier); if (!error.isNull()) m_frame->loader()->client()->dispatchDidFailLoading(loader, identifier, error); InspectorInstrumentation::didFailLoading(m_frame, identifier, loader, error); }
void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) { RefPtr<DocumentLoader> protect(this); ResourceError error = resourceError.isNull() ? ResourceError::cancelledError(m_request.url()) : resourceError; if (mainResourceLoader()) mainResourceLoader()->cancel(error); mainReceivedError(error); }
void ResourceLoadNotifier::didFailToLoad(ResourceLoader* loader, const ResourceError& error) { if (Page* page = m_frame.page()) page->progress().completeProgress(loader->identifier()); if (!error.isNull()) m_frame.loader().client().dispatchDidFailLoading(loader->documentLoader(), loader->identifier(), error); InspectorInstrumentation::didFailLoading(&m_frame, loader->documentLoader(), loader->identifier(), error); }
void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, SecurityCheckPolicy securityCheck) { // Any credential should have been removed from the cross-site requests. const KURL& requestURL = request.url(); ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); if (m_async) { // Don't sniff content or send load callbacks for the preflight request. bool sendLoadCallbacks = m_options.sendLoadCallbacks && !m_actualRequest; bool sniffContent = m_options.sniffContent && !m_actualRequest; // Keep buffering the data for the preflight request. bool shouldBufferData = m_options.shouldBufferData || m_actualRequest; // Clear the loader so that any callbacks from SubresourceLoader::create will not have the old loader. m_loader = 0; m_loader = resourceLoadScheduler()->scheduleSubresourceLoad(m_document->frame(), this, request, ResourceLoadPriorityMedium, securityCheck, sendLoadCallbacks, sniffContent, m_optionalOutgoingReferrer, shouldBufferData); return; } // FIXME: ThreadableLoaderOptions.sniffContent is not supported for synchronous requests. StoredCredentials storedCredentials = m_options.allowCredentials ? AllowStoredCredentials : DoNotAllowStoredCredentials; Vector<char> data; ResourceError error; ResourceResponse response; unsigned long identifier = std::numeric_limits<unsigned long>::max(); if (m_document->frame()) identifier = m_document->frame()->loader()->loadResourceSynchronously(request, storedCredentials, error, response, data); // No exception for file:/// resources, see <rdar://problem/4962298>. // Also, if we have an HTTP response, then it wasn't a network error in fact. if (!error.isNull() && !requestURL.isLocalFile() && response.httpStatusCode() <= 0) { m_client->didFail(error); return; } // FIXME: FrameLoader::loadSynchronously() does not tell us whether a redirect happened or not, so we guess by comparing the // request and response URLs. This isn't a perfect test though, since a server can serve a redirect to the same URL that was // requested. Also comparing the request and response URLs as strings will fail if the requestURL still has its credentials. if (requestURL != response.url() && !isAllowedRedirect(response.url())) { m_client->didFailRedirectCheck(); return; } didReceiveResponse(0, response); const char* bytes = static_cast<const char*>(data.data()); int len = static_cast<int>(data.size()); didReceiveData(0, bytes, len); didFinishLoading(identifier, 0.0); }
void ResourceLoader::cancel(const ResourceError& error) { // If the load has already completed - succeeded, failed, or previously cancelled - do nothing. if (m_reachedTerminalState) return; ResourceError nonNullError = error.isNull() ? cancelledError() : error; // willCancel() and didFailToLoad() both call out to clients that might do // something causing the last reference to this object to go away. RefPtr<ResourceLoader> protector(this); // If we re-enter cancel() from inside willCancel(), we want to pick up from where we left // off without re-running willCancel() if (!m_calledWillCancel) { m_calledWillCancel = true; willCancel(nonNullError); } // If we re-enter cancel() from inside didFailToLoad(), we want to pick up from where we // left off without redoing any of this work. if (!m_cancelled) { m_cancelled = true; if (FormData* data = m_request.httpBody()) data->removeGeneratedFilesIfNeeded(); if (m_handle) m_handle->clearAuthentication(); m_documentLoader->cancelPendingSubstituteLoad(this); if (m_handle) { m_handle->cancel(); m_handle = 0; } if (m_options.sendLoadCallbacks == SendCallbacks && m_identifier && !m_notifiedLoadComplete) { ActionLogScope log_scope( String::format("cancel_fail:%s", m_request.url().lastPathComponent().ascii().data()).ascii().data()); frameLoader()->notifier()->didFailToLoad(this, nonNullError); } } // If cancel() completed from within the call to willCancel() or didFailToLoad(), // we don't want to redo didCancel() or releasesResources(). if (m_reachedTerminalState) return; didCancel(nonNullError); releaseResources(); }
void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) { RefPtr<DocumentLoader> protect(this); ResourceError error = resourceError.isNull() ? frameLoader()->cancelledError(m_request) : resourceError; m_dataLoadTimer.stop(); if (mainResourceLoader()) mainResourceLoader()->cancel(error); mainReceivedError(error); }
void DocumentLoader::mainReceivedError(const ResourceError& error, bool isComplete) { ASSERT(!error.isNull()); m_applicationCacheHost->failedLoadingMainResource(); if (!frameLoader()) return; setMainDocumentError(error); if (isComplete) frameLoader()->mainReceivedCompleteError(this, error); }
void FrameLoaderClientAndroid::setMainDocumentError(DocumentLoader* docLoader, const ResourceError& error) { ASSERT(m_frame); if (m_manualLoader) { m_manualLoader->didFail(error); m_manualLoader = NULL; m_hasSentResponseToPlugin = false; } else { if (!error.isNull() && error.errorCode() >= InternalErrorLast) m_webFrame->reportError(error.errorCode(), error.localizedDescription(), error.failingURL()); } }
void DocumentLoader::mainReceivedError(const ResourceError& error) { ASSERT(!error.isNull()); ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || InspectorInstrumentation::isDebuggerPaused(m_frame)); m_applicationCacheHost->failedLoadingMainResource(); if (!frameLoader()) return; setMainDocumentError(error); clearMainResourceLoader(); frameLoader()->receivedMainResourceError(this, error); clearMainResourceHandle(); }
void ArgumentCoder<ResourceError>::encode(ArgumentEncoder* encoder, const ResourceError& resourceError) { bool errorIsNull = resourceError.isNull(); encoder->encode(errorIsNull); if (errorIsNull) return; encoder->encode(resourceError.domain()); encoder->encode(resourceError.errorCode()); encoder->encode(resourceError.failingURL()); encoder->encode(resourceError.localizedDescription()); }
void ResourceLoadNotifier::didFailToLoad(ResourceLoader* loader, const ResourceError& error) { if (Page* page = m_frame.page()) page->progress().completeProgress(loader->identifier()); // Notifying the FrameLoaderClient may cause the frame to be destroyed. Ref<Frame> protect(m_frame); if (!error.isNull()) m_frame.loader().client().dispatchDidFailLoading(loader->documentLoader(), loader->identifier(), error); InspectorInstrumentation::didFailLoading(&m_frame, loader->documentLoader(), loader->identifier(), error); }
void DocumentLoader::mainReceivedError(const ResourceError& error) { ASSERT(!error.isNull()); m_applicationCacheHost->failedLoadingMainResource(); if (!frameLoader()) return; setMainDocumentError(error); clearMainResourceLoader(); frameLoader()->receivedMainResourceError(error); }
void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data) { LOG(Network, "ResourceHandle::platformLoadResourceSynchronously:%s allowStoredCredentials:%u", request.url().string().utf8().data(), storedCredentials); ASSERT(!request.isEmpty()); ASSERT(response.isNull()); ASSERT(error.isNull()); SynchronousLoaderClient client; client.setAllowStoredCredentials(storedCredentials == AllowStoredCredentials); RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(context, request, &client, false /*defersLoading*/, true /*shouldContentSniff*/)); handle->d->m_storageSession = context->storageSession().platformSession(); if (handle->d->m_scheduledFailureType != NoFailure) { error = context->blockedError(request); return; } handle->createCFURLConnection(storedCredentials == AllowStoredCredentials, ResourceHandle::shouldContentSniffURL(request.url()), SchedulingBehavior::Synchronous, handle->client()->connectionProperties(handle.get()).get()); CFURLConnectionScheduleWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode()); CFURLConnectionScheduleDownloadWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode()); CFURLConnectionStart(handle->connection()); while (!client.isDone()) CFRunLoopRunInMode(synchronousLoadRunLoopMode(), UINT_MAX, true); error = client.error(); CFURLConnectionCancel(handle->connection()); if (error.isNull()) response = client.response(); data.swap(client.mutableData()); }
void ResourceLoadNotifier::sendRemainingDelegateMessages(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response, const char* data, int dataLength, int encodedDataLength, const ResourceError& error) { if (!response.isNull()) dispatchDidReceiveResponse(loader, identifier, response); if (dataLength > 0) dispatchDidReceiveData(loader, identifier, data, dataLength, encodedDataLength); if (error.isNull()) dispatchDidFinishLoading(loader, identifier, 0); else dispatchDidFail(loader, identifier, error); }
void ResourceLoadNotifier::sendRemainingDelegateMessages(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response, int length, const ResourceError& error) { if (!response.isNull()) dispatchDidReceiveResponse(loader, identifier, response); if (length > 0) dispatchDidReceiveContentLength(loader, identifier, length); if (error.isNull()) dispatchDidFinishLoading(loader, identifier, 0); else m_frame->loader()->client()->dispatchDidFailLoading(loader, identifier, error); }
void ResourceLoadNotifier::didFailToLoad(ResourceLoader* loader, const ResourceError& error) { if (Page* page = m_frame->page()) page->progress()->completeProgress(loader->identifier()); if (!error.isNull()) m_frame->loader()->client()->dispatchDidFailLoading(loader->documentLoader(), loader->identifier(), error); #if ENABLE(INSPECTOR) if (Page* page = m_frame->page()) page->inspectorController()->didFailLoading(loader->identifier(), error); #endif }
/*this function shows an error message in a popup*/ void FrameLoaderClientWebUI::dispatchDidFailProvisionalLoad(const ResourceError& error) { if (!(error.isNull())) { char errorCode[2]; sprintf(errorCode, "%i", error.errorCode()); String description = error.localizedDescription().deprecatedString().ascii(); description = description.replace("'","\\'"); executeJS(m_frame, "errorLoad('" + String(error.domain().deprecatedString().ascii()) + "','" + String(errorCode) + "','" + String(error.failingURL().deprecatedString().ascii()) + "','" + description + "')"); } m_loadFailed = true; }
void ResourceLoader::cancel(const ResourceError& error) { // If the load has already completed - succeeded, failed, or previously cancelled - do nothing. if (m_reachedTerminalState) return; ResourceError nonNullError = error.isNull() ? cancelledError() : error; // willCancel() and didFailToLoad() both call out to clients that might do // something causing the last reference to this object to go away. Ref<ResourceLoader> protect(*this); // If we re-enter cancel() from inside willCancel(), we want to pick up from where we left // off without re-running willCancel() if (m_cancellationStatus == NotCancelled) { m_cancellationStatus = CalledWillCancel; willCancel(nonNullError); } // If we re-enter cancel() from inside didFailToLoad(), we want to pick up from where we // left off without redoing any of this work. if (m_cancellationStatus == CalledWillCancel) { m_cancellationStatus = Cancelled; if (m_handle) m_handle->clearAuthentication(); m_documentLoader->cancelPendingSubstituteLoad(this); if (m_handle) { m_handle->cancel(); m_handle = 0; } cleanupForError(nonNullError); } // If cancel() completed from within the call to willCancel() or didFailToLoad(), // we don't want to redo didCancel() or releasesResources(). if (m_reachedTerminalState) return; didCancel(nonNullError); if (m_cancellationStatus == FinishedCancel) return; m_cancellationStatus = FinishedCancel; releaseResources(); }
bool ResourceError::compare(const ResourceError& a, const ResourceError& b) { if (a.isNull() && b.isNull()) return true; if (a.isNull() || b.isNull()) return false; if (a.domain() != b.domain()) return false; if (a.errorCode() != b.errorCode()) return false; if (a.failingURL() != b.failingURL()) return false; if (a.localizedDescription() != b.localizedDescription()) return false; if (a.isCancellation() != b.isCancellation()) return false; if (a.isAccessCheck() != b.isAccessCheck()) return false; if (a.isTimeout() != b.isTimeout()) return false; if (a.staleCopyInCache() != b.staleCopyInCache()) return false; if (a.wasIgnoredByHandler() != b.wasIgnoredByHandler()) return false; return true; }
void NetworkResourceLoader::didFailLoading(const ResourceError& error) { ASSERT(!error.isNull()); #if ENABLE(NETWORK_CACHE) m_cacheEntryForValidation = nullptr; #endif if (isSynchronous()) { m_synchronousLoadData->error = error; sendReplyToSynchronousRequest(*m_synchronousLoadData, nullptr); } else send(Messages::WebResourceLoader::DidFailResourceLoad(error)); cleanup(); }
void ApplicationCacheHost::maybeLoadFallbackSynchronously(const ResourceRequest& request, ResourceError& error, ResourceResponse& response, Vector<char>& data) { // If normal loading results in a redirect to a resource with another origin (indicative of a captive portal), or a 4xx or 5xx status code or equivalent, // or if there were network errors (but not if the user canceled the download), then instead get, from the cache, the resource of the fallback entry // corresponding to the matched namespace. if ((!error.isNull() && !error.isCancellation()) || response.httpStatusCode() / 100 == 4 || response.httpStatusCode() / 100 == 5 || !protocolHostAndPortAreEqual(request.url(), response.url())) { ApplicationCacheResource* resource; if (getApplicationCacheFallbackResource(request, resource)) { response = resource->response(); data.clear(); data.append(resource->data()->data(), resource->data()->size()); } } }
void ArgumentCoder<ResourceError>::encodePlatformData(ArgumentEncoder& encoder, const ResourceError& resourceError) { bool errorIsNull = resourceError.isNull(); encoder << errorIsNull; if (errorIsNull) return; encoder << resourceError.domain(); encoder << resourceError.errorCode(); encoder << resourceError.failingURL().string(); encoder << resourceError.localizedDescription(); encoder << resourceError.isCancellation(); encoder << resourceError.isTimeout(); encoder << CertificateInfo(resourceError); }
void ApplicationCacheHost::maybeLoadFallbackSynchronously(const ResourceRequest& request, ResourceError& error, ResourceResponse& response, RefPtr<SharedBuffer>& data) { // If normal loading results in a redirect to a resource with another origin (indicative of a captive portal), or a 4xx or 5xx status code or equivalent, // or if there were network errors (but not if the user canceled the download), then instead get, from the cache, the resource of the fallback entry // corresponding to the matched namespace. if ((!error.isNull() && !error.isCancellation()) || response.httpStatusCode() / 100 == 4 || response.httpStatusCode() / 100 == 5 || !protocolHostAndPortAreEqual(request.url(), response.url())) { ApplicationCacheResource* resource; if (getApplicationCacheFallbackResource(request, resource)) { response = resource->response(); // FIXME: Clients proably do not need a copy of the SharedBuffer. // Remove the call to copy() once we ensure SharedBuffer will not be modified. data = resource->data().copy(); } } }
void DocumentThreadableLoader::cancelWithError(const ResourceError& error) { RefPtr<DocumentThreadableLoader> protect(this); // Cancel can re-enter and m_resource might be null here as a result. if (m_client && resource()) { ResourceError errorForCallback = error; if (errorForCallback.isNull()) { // FIXME: This error is sent to the client in didFail(), so it should not be an internal one. Use FrameLoaderClient::cancelledError() instead. errorForCallback = ResourceError(errorDomainBlinkInternal, 0, resource()->url().string(), "Load cancelled"); errorForCallback.setIsCancellation(true); } m_client->didFail(errorForCallback); } clearResource(); m_client = 0; }
void NetworkResourceLoader::didFailLoading(const ResourceError& error) { RELEASE_LOG_IF_ALLOWED("didFailLoading: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ", isTimeout = %d, isCancellation = %d, errCode = %d)", m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier, error.isTimeout(), error.isCancellation(), error.errorCode()); ASSERT(!error.isNull()); #if ENABLE(NETWORK_CACHE) m_cacheEntryForValidation = nullptr; #endif if (isSynchronous()) { m_synchronousLoadData->error = error; sendReplyToSynchronousRequest(*m_synchronousLoadData, nullptr); } else if (auto* connection = messageSenderConnection()) connection->send(Messages::WebResourceLoader::DidFailResourceLoad(error), messageSenderDestinationID()); cleanup(); }
void NetworkResourceLoader::didFailLoading(const ResourceError& error) { NETWORKRESOURCELOADER_LOG_ALWAYS("Failed loading network resource: loader = %p, pageID = %llu, frameID = %llu, isMainResource = %d, isSynchronous = %d, isTimeout = %d, isCancellation = %d, errCode = %d", this, m_parameters.webPageID, m_parameters.webFrameID, isMainResource(), isSynchronous(), error.isTimeout(), error.isCancellation(), error.errorCode()); ASSERT(!error.isNull()); #if ENABLE(NETWORK_CACHE) m_cacheEntryForValidation = nullptr; #endif if (isSynchronous()) { m_synchronousLoadData->error = error; sendReplyToSynchronousRequest(*m_synchronousLoadData, nullptr); } else send(Messages::WebResourceLoader::DidFailResourceLoad(error)); cleanup(); }
void ArgumentCoder<ResourceError>::encode(ArgumentEncoder& encoder, const ResourceError& resourceError) { if (kShouldSerializeWebCoreData) { bool errorIsNull = resourceError.isNull(); encoder << errorIsNull; if (errorIsNull) return; encoder << resourceError.domain(); encoder << resourceError.errorCode(); encoder << resourceError.failingURL(); encoder << resourceError.localizedDescription(); encoder << resourceError.isCancellation(); encoder << resourceError.isTimeout(); } encodePlatformData(encoder, resourceError); }
void DocumentLoader::mainReceivedError(const ResourceError& error) { ASSERT(!error.isNull()); if (m_identifierForLoadWithoutResourceLoader) { ASSERT(!mainResourceLoader()); frameLoader()->client()->dispatchDidFailLoading(this, m_identifierForLoadWithoutResourceLoader, error); } ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); m_applicationCacheHost->failedLoadingMainResource(); if (!frameLoader()) return; setMainDocumentError(error); clearMainResourceLoader(); frameLoader()->receivedMainResourceError(error); clearMainResourceHandle(); }