diff options
Diffstat (limited to 'Source/WebCore/loader/ThreadableLoader.cpp')
-rw-r--r-- | Source/WebCore/loader/ThreadableLoader.cpp | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/Source/WebCore/loader/ThreadableLoader.cpp b/Source/WebCore/loader/ThreadableLoader.cpp index 8a3a98576..a316da496 100644 --- a/Source/WebCore/loader/ThreadableLoader.cpp +++ b/Source/WebCore/loader/ThreadableLoader.cpp @@ -31,10 +31,11 @@ #include "config.h" #include "ThreadableLoader.h" +#include "CachedResourceRequestInitiators.h" #include "Document.h" #include "DocumentThreadableLoader.h" +#include "ResourceError.h" #include "ScriptExecutionContext.h" -#include "SecurityOrigin.h" #include "WorkerGlobalScope.h" #include "WorkerRunLoop.h" #include "WorkerThreadableLoader.h" @@ -42,36 +43,75 @@ namespace WebCore { ThreadableLoaderOptions::ThreadableLoaderOptions() - : preflightPolicy(ConsiderPreflight) - , crossOriginRequestPolicy(DenyCrossOriginRequests) { + mode = FetchOptions::Mode::SameOrigin; } ThreadableLoaderOptions::~ThreadableLoaderOptions() { } -PassRefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext* context, ThreadableLoaderClient* client, const ResourceRequest& request, const ThreadableLoaderOptions& options) +ThreadableLoaderOptions::ThreadableLoaderOptions(const ResourceLoaderOptions& baseOptions, PreflightPolicy preflightPolicy, ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement, String&& initiator, ResponseFilteringPolicy filteringPolicy) + : ResourceLoaderOptions(baseOptions) + , preflightPolicy(preflightPolicy) + , contentSecurityPolicyEnforcement(contentSecurityPolicyEnforcement) + , initiator(WTFMove(initiator)) + , filteringPolicy(filteringPolicy) { - ASSERT(client); - ASSERT(context); +} + +RefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext& context, ThreadableLoaderClient& client, ResourceRequest&& request, const ThreadableLoaderOptions& options, String&& referrer) +{ + if (is<WorkerGlobalScope>(context)) + return WorkerThreadableLoader::create(downcast<WorkerGlobalScope>(context), client, WorkerRunLoop::defaultMode(), WTFMove(request), options, referrer); - if (context->isWorkerGlobalScope()) - return WorkerThreadableLoader::create(static_cast<WorkerGlobalScope*>(context), client, WorkerRunLoop::defaultMode(), request, options); + return DocumentThreadableLoader::create(downcast<Document>(context), client, WTFMove(request), options, WTFMove(referrer)); +} - return DocumentThreadableLoader::create(toDocument(context), client, request, options); +void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext& context, ResourceRequest&& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options) +{ + if (is<WorkerGlobalScope>(context)) + WorkerThreadableLoader::loadResourceSynchronously(downcast<WorkerGlobalScope>(context), WTFMove(request), client, options); + else + DocumentThreadableLoader::loadResourceSynchronously(downcast<Document>(context), WTFMove(request), client, options); + context.didLoadResourceSynchronously(); } -void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options) +void ThreadableLoader::logError(ScriptExecutionContext& context, const ResourceError& error, const String& initiator) { - ASSERT(context); + // FIXME: extend centralized logging to other clients than fetch, at least XHR and EventSource. + if (initiator != cachedResourceRequestInitiators().fetch) + return; - if (context->isWorkerGlobalScope()) { - WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerGlobalScope*>(context), request, client, options); + if (error.isCancellation()) return; + + // FIXME: Some errors are returned with null URLs. This leads to poor console messages. We should do better for these errors. + if (error.failingURL().isNull()) + return; + + // We further reduce logging to some errors. + // FIXME: Log more errors when making so do not make some layout tests flaky. + if (error.domain() != errorDomainWebKitInternal && !error.isAccessControl()) + return; + + const char* messageStart; + if (initiator == cachedResourceRequestInitiators().fetch) + messageStart = "Fetch API cannot load "; + else + messageStart = "Cannot load "; + + const char* messageMiddle = ". "; + String description = error.localizedDescription(); + if (description.isEmpty()) { + // FIXME: We should probably define default description error message for all error types. + if (error.isAccessControl()) + messageMiddle = ASCIILiteral(" due to access control checks."); + else + messageMiddle = "."; } - DocumentThreadableLoader::loadResourceSynchronously(toDocument(context), request, client, options); + context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString(messageStart, error.failingURL().string(), messageMiddle, description)); } } // namespace WebCore |