void XMLHttpRequest::loadRequestSynchronously(ResourceRequest& request, ExceptionCode& ec) { ASSERT(!m_async); Vector<char> data; ResourceError error; ResourceResponse response; { // avoid deadlock in case the loader wants to use JS on a background thread KJS::JSLock::DropAllLocks dropLocks; if (m_doc->frame()) m_identifier = m_doc->frame()->loader()->loadResourceSynchronously(request, error, response, data); } m_loader = 0; // 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() || request.url().isLocalFile() || response.httpStatusCode() > 0) { processSyncLoadResults(data, response, ec); return; } if (error.isCancellation()) { abortError(); ec = XMLHttpRequestException::ABORT_ERR; return; } networkError(); ec = XMLHttpRequestException::NETWORK_ERR; }
void XMLHttpRequest::loadRequestSynchronously(ResourceRequest& request, ExceptionCode& ec) { ASSERT(!m_async); Vector<char> data; ResourceError error; ResourceResponse response; unsigned long identifier = ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), request, error, response, data); m_loader = 0; // 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() || request.url().isLocalFile() || response.httpStatusCode() > 0) { processSyncLoadResults(identifier, data, response, ec); return; } if (error.isCancellation()) { abortError(); ec = XMLHttpRequestException::ABORT_ERR; return; } networkError(); ec = XMLHttpRequestException::NETWORK_ERR; }
void EventSource::didFailAccessControlCheck(const ResourceError& error) { String message = "EventSource cannot load " + error.failingURL() + ". " + error.localizedDescription(); executionContext()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); abortConnectionAttempt(); }
void FetchManager::Loader::didFailAccessControlCheck(const ResourceError& error) { if (error.isCancellation() || error.isTimeout() || error.domain() != errorDomainBlinkInternal) failed(String()); else failed("Fetch API cannot load " + error.failingURL() + ". " + error.localizedDescription()); }
ResourceError cancelledError(const ResourceRequest& request) { ResourceError error = ResourceError("QtNetwork", QNetworkReply::OperationCanceledError, request.url().string(), QCoreApplication::translate("QWebFrame", "Request cancelled", 0, QCoreApplication::UnicodeUTF8)); error.setIsCancellation(true); return error; }
WebCore::ResourceError FrameLoaderClientQt::cancelledError(const WebCore::ResourceRequest& request) { ResourceError error = ResourceError("QtNetwork", QNetworkReply::OperationCanceledError, request.url().prettyURL(), QCoreApplication::translate("QWebFrame", "Request cancelled", 0, QCoreApplication::UnicodeUTF8)); error.setIsCancellation(true); return error; }
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 webkitDownloadFailed(WebKitDownload* download, const ResourceError& resourceError) { GUniquePtr<GError> webError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()), toWebKitError(resourceError.errorCode()), resourceError.localizedDescription().utf8().data())); if (download->priv->timer) g_timer_stop(download->priv->timer.get()); g_signal_emit(download, signals[FAILED], 0, webError.get()); g_signal_emit(download, signals[FINISHED], 0, NULL); }
bool ArgumentCoder<ResourceError>::decodePlatformData(ArgumentDecoder& decoder, ResourceError& resourceError) { PlatformCertificateInfo certificateInfo; if (!decoder.decode(certificateInfo)) return false; resourceError.setCertificate(certificateInfo.certificate()); resourceError.setTLSErrors(certificateInfo.tlsErrors()); return true; }
bool WebFrameLoaderClient::shouldFallBack(const ResourceError& error) { if (error.errorCode() == WebURLErrorCancelled && error.domain() == String(WebURLErrorDomain)) return false; if (error.errorCode() == WebKitErrorPlugInWillHandleLoad && error.domain() == String(WebKitErrorDomain)) return false; return true; }
WebURLError::operator ResourceError() const { if (!reason) return ResourceError(); CString spec = unreachableURL.spec(); ResourceError resourceError = ResourceError(domain, reason, String::fromUTF8(spec.data(), spec.length()), localizedDescription); resourceError.setIsCancellation(isCancellation); resourceError.setStaleCopyInCache(staleCopyInCache); return resourceError; }
WebURLError::operator ResourceError() const { if (!reason) return ResourceError(); ResourceError resourceError = ResourceError( domain, reason, unreachableURL.string(), localizedDescription); resourceError.setIsCancellation(isCancellation); resourceError.setStaleCopyInCache(staleCopyInCache); resourceError.setWasIgnoredByHandler(wasIgnoredByHandler); return resourceError; }
void FrameLoaderClientBlackBerry::dispatchDidFailProvisionalLoad(const ResourceError& error) { if (isMainFrame()) { m_loadError = error; m_webPagePrivate->setLoadState(WebPagePrivate::Failed); if (error.domain() == ResourceError::platformErrorDomain && (error.errorCode() == BlackBerry::Platform::FilterStream::StatusErrorAlreadyHandled)) { // Error has already been displayed by client. return; } if (error.domain().isEmpty() && !error.errorCode() && error.failingURL().isEmpty() && error.localizedDescription().isEmpty()) { // Don't try to display empty errors returned from the unimplemented error functions in FrameLoaderClientBlackBerry - there's nothing to display anyway. return; } } if (m_webPagePrivate->m_dumpRenderTree) m_webPagePrivate->m_dumpRenderTree->didFailProvisionalLoadForFrame(m_frame); if (!isMainFrame()) return; String errorPage = m_webPagePrivate->m_client->getErrorPage(error.errorCode() , error.localizedDescription().isEmpty() ? "" : error.localizedDescription().utf8().data() , error.failingURL().isEmpty() ? "" : error.failingURL().utf8().data()); // Make sure we're still in the provisionalLoad state - getErrorPage runs a // nested event loop while it's waiting for client resources to load so // there's a small window for the user to hit stop. if (m_frame->loader()->provisionalDocumentLoader()) { SubstituteData errorData(utf8Buffer(errorPage), "text/html", "utf-8", KURL(KURL(), error.failingURL())); ResourceRequest originalRequest = m_frame->loader()->provisionalDocumentLoader()->originalRequest(); // Loading using SubstituteData will replace the original request with our // error data. This must be done within dispatchDidFailProvisionalLoad, // and do NOT call stopAllLoaders first, because the loader checks the // provisionalDocumentLoader to decide the load type; if called any other // way, the error page is added to the end of the history instead of // replacing the failed load. // // If this comes from a back/forward navigation, we need to save the current viewstate // to original historyitem, and prevent the restore of view state to the error page. if (isBackForwardLoadType(m_frame->loader()->loadType())) { m_frame->loader()->history()->saveScrollPositionAndViewStateToItem(m_frame->loader()->history()->currentItem()); ASSERT(m_frame->loader()->history()->provisionalItem()); m_frame->loader()->history()->provisionalItem()->viewState().shouldSaveViewState = false; } m_loadingErrorPage = true; m_frame->loader()->load(originalRequest, errorData, false); } }
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 ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& vector) { LOG(Network, "ResourceHandle::loadResourceSynchronously:%s allowStoredCredentials:%u", request.url().string().utf8().data(), storedCredentials); ASSERT(!request.isEmpty()); ASSERT(response.isNull()); ASSERT(error.isNull()); OwnPtr<WebCoreSynchronousLoaderClient> client = WebCoreSynchronousLoaderClient::create(response, error); client->setAllowStoredCredentials(storedCredentials == AllowStoredCredentials); RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(request, client.get(), false /*defersLoading*/, true /*shouldContentSniff*/)); handle->d->m_storageSession = context->storageSession(); if (handle->d->m_scheduledFailureType != NoFailure) { error = context->blockedError(request); return; } handle->createCFURLConnection(storedCredentials == AllowStoredCredentials, shouldRelaxThirdPartyCookiePolicy(context, request.url()), ResourceHandle::shouldContentSniffURL(request.url())); CFURLConnectionScheduleWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode()); CFURLConnectionScheduleDownloadWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode()); CFURLConnectionStart(handle->connection()); while (!client->isDone()) CFRunLoopRunInMode(synchronousLoadRunLoopMode(), UINT_MAX, true); CFURLConnectionCancel(handle->connection()); if (error.isNull() && response.mimeType().isNull()) setDefaultMIMEType(response.cfURLResponse()); RetainPtr<CFDataRef> data = client->data(); if (!error.isNull()) { response = ResourceResponse(request.url(), String(), 0, String(), String()); CFErrorRef cfError = error; CFStringRef domain = CFErrorGetDomain(cfError); // FIXME: Return the actual response for failed authentication. if (domain == kCFErrorDomainCFNetwork) response.setHTTPStatusCode(CFErrorGetCode(cfError)); else response.setHTTPStatusCode(404); } if (data) { ASSERT(vector.isEmpty()); vector.append(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get())); } }
void InspectorConsoleAgent::didFailLoading(unsigned long identifier, const ResourceError& error) { if (!m_inspectorAgent->enabled()) return; if (error.isCancellation()) // Report failures only. return; String message = "Failed to load resource"; if (!error.localizedDescription().isEmpty()) message += ": " + error.localizedDescription(); addConsoleMessage(adoptPtr(new ConsoleMessage(OtherMessageSource, NetworkErrorMessageType, ErrorMessageLevel, message, error.failingURL(), identifier))); }
WebURLError::operator ResourceError() const { if (!reason) return ResourceError(); CString spec = unreachableURL.spec(); ResourceError resourceError = ResourceError(domain, reason, String::fromUTF8(spec.data(), spec.length()), String()); resourceError.setIsCancellation(isCancellation); return resourceError; }
void ArgumentCoder<ResourceError>::encode(ArgumentEncoder* encoder, const ResourceError& resourceError) { encoder->encode(resourceError.domain()); encoder->encode(resourceError.errorCode()); encoder->encode(resourceError.failingURL()); encoder->encode(resourceError.localizedDescription()); #if USE(CFNETWORK) encoder->encode(PlatformCertificateInfo(resourceError.certificate())); #endif }
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 InspectorConsoleAgent::didFailLoading(unsigned long requestIdentifier, DocumentLoader*, const ResourceError& error) { if (error.isCancellation()) // Report failures only. return; StringBuilder message; message.appendLiteral("Failed to load resource"); if (!error.localizedDescription().isEmpty()) { message.appendLiteral(": "); message.append(error.localizedDescription()); } addMessageToConsole(NetworkMessageSource, LogMessageType, ErrorMessageLevel, message.toString(), error.failingURL(), 0, 0, 0, requestIdentifier); }
void InspectorConsoleAgent::didFailLoading(unsigned long identifier, const ResourceError& error) { if (!developerExtrasEnabled()) return; if (error.isCancellation()) // Report failures only. return; String message = "Failed to load resource"; if (!error.localizedDescription().isEmpty()) message += ": " + error.localizedDescription(); String requestId = IdentifiersFactory::requestId(identifier); addConsoleMessage(adoptPtr(new ConsoleMessage(NetworkMessageSource, LogMessageType, ErrorMessageLevel, message, error.failingURL(), requestId))); }
ResourceError ResourceError::timeoutError(const String& failingURL) { // FIXME: This should probably either be integrated into Errors(Gtk/EFL).h or the // networking errors from those files should be moved here. // Use the same value as in NSURLError.h static const int timeoutError = -1001; static const char* const errorDomain = "WebKitNetworkError"; ResourceError error = ResourceError(errorDomain, timeoutError, failingURL, "Request timed out"); error.setIsTimeout(true); return error; }
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()); }
/*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 InspectorResourceAgent::didFailLoading(unsigned long identifier, DocumentLoader* loader, const ResourceError& error) { String requestId = IdentifiersFactory::requestId(identifier); if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) { Frame* frame = loader ? loader->frame() : 0; if (frame && frame->loader()->documentLoader() && frame->document()) m_resourcesData->addResourceSharedBuffer(requestId, frame->loader()->documentLoader()->mainResourceData(), frame->document()->inputEncoding()); } bool canceled = error.isCancellation(); m_frontend->loadingFailed(requestId, currentTime(), error.localizedDescription(), canceled ? &canceled : 0); }
void FrameConsole::didFailLoading(unsigned long requestIdentifier, const ResourceError& error) { if (error.isCancellation()) // Report failures only. return; StringBuilder message; message.appendLiteral("Failed to load resource"); if (!error.localizedDescription().isEmpty()) { message.appendLiteral(": "); message.append(error.localizedDescription()); } RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(NetworkMessageSource, ErrorMessageLevel, message.toString(), error.failingURL()); consoleMessage->setRequestIdentifier(requestIdentifier); messageStorage()->reportMessage(consoleMessage.release()); }
void FrameConsole::didFailLoading(unsigned long requestIdentifier, const ResourceError& error) { if (error.isCancellation()) // Report failures only. return; StringBuilder message; message.append("Failed to load resource"); if (!error.localizedDescription().isEmpty()) { message.append(": "); message.append(error.localizedDescription()); } addMessageToStorage(ConsoleMessage::createForRequest( NetworkMessageSource, ErrorMessageLevel, message.toString(), error.failingURL(), requestIdentifier)); }
void FrameLoaderClientEfl::dispatchDidFailLoad(const ResourceError& err) { ewk_frame_load_error(m_frame, err.domain().utf8().data(), err.errorCode(), err.isCancellation(), err.localizedDescription().utf8().data(), err.failingURL().utf8().data()); ewk_frame_load_finished(m_frame, err.domain().utf8().data(), err.errorCode(), err.isCancellation(), err.localizedDescription().utf8().data(), err.failingURL().utf8().data()); }
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()); OwnPtr<SynchronousLoaderClient> client = SynchronousLoaderClient::create(); client->setAllowStoredCredentials(storedCredentials == AllowStoredCredentials); RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(context, request, client.get(), 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(); else { response = ResourceResponse(request.url(), String(), 0, String(), String()); // FIXME: ResourceHandleMac also handles authentication errors by setting code to 401. CFNet version should probably do the same. if (error.domain() == String(kCFErrorDomainCFNetwork)) response.setHTTPStatusCode(error.errorCode()); else response.setHTTPStatusCode(404); } data.swap(client->mutableData()); }
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()); } } }