void WorkerScriptLoader::loadAsynchronously( ExecutionContext& executionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy, WebAddressSpace creationAddressSpace, std::unique_ptr<WTF::Closure> responseCallback, std::unique_ptr<WTF::Closure> finishedCallback) { DCHECK(responseCallback || finishedCallback); m_responseCallback = std::move(responseCallback); m_finishedCallback = std::move(finishedCallback); m_url = url; ResourceRequest request(createResourceRequest(creationAddressSpace)); ThreadableLoaderOptions options; options.crossOriginRequestPolicy = crossOriginRequestPolicy; ResourceLoaderOptions resourceLoaderOptions; resourceLoaderOptions.allowCredentials = AllowStoredCredentials; // During create, callbacks may happen which could remove the last reference // to this object, while some of the callchain assumes that the client and // loader wouldn't be deleted within callbacks. // (E.g. see crbug.com/524694 for why we can't easily remove this protect) RefPtr<WorkerScriptLoader> protect(this); m_needToCancel = true; m_threadableLoader = ThreadableLoader::create(executionContext, this, options, resourceLoaderOptions); m_threadableLoader->start(request); if (m_failed) notifyFinished(); }
CFURLRequestRef ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse) { // If the protocols of the new request and the current request match, this is not an HSTS redirect and we don't need to synthesize a redirect response. if (!originalRedirectResponse) { RetainPtr<CFStringRef> newScheme = adoptCF(CFURLCopyScheme(CFURLRequestGetURL(cfRequest))); if (CFStringCompare(newScheme.get(), m_originalScheme.get(), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { CFRetain(cfRequest); return cfRequest; } } RefPtr<ResourceHandleCFURLConnectionDelegateWithOperationQueue> protector(this); dispatch_async(dispatch_get_main_queue(), ^{ if (!protector->hasHandle()) { continueWillSendRequest(nullptr); return; } LOG(Network, "CFNet - ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data()); RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse); ASSERT(redirectResponse); ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get()); m_handle->willSendRequest(request, redirectResponse.get()); });
CFURLRequestRef ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse) { // If the protocols of the new request and the current request match, this is not an HSTS redirect and we don't need to synthesize a redirect response. if (!originalRedirectResponse) { RetainPtr<CFStringRef> newScheme = adoptCF(CFURLCopyScheme(CFURLRequestGetURL(cfRequest))); if (CFStringCompare(newScheme.get(), m_originalScheme.get(), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { CFRetain(cfRequest); return cfRequest; } } ASSERT(!isMainThread()); // FIXME: The block implicitly copies protector object, which is wasteful. We should just call ref(), // capture "this" by pointer value, and use a C++ lambda to prevent other unintentional capturing. RefPtr<ResourceHandleCFURLConnectionDelegateWithOperationQueue> protectedThis(this); dispatch_async(dispatch_get_main_queue(), ^{ if (!protectedThis->hasHandle()) { continueWillSendRequest(nullptr); return; } LOG(Network, "CFNet - ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data()); RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse); ASSERT(redirectResponse); ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get()); m_handle->willSendRequest(request, redirectResponse.get()); });
void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRedirectPolicy crossOriginRedirectPolicy) { m_url = url; OwnPtr<ResourceRequest> request(createResourceRequest()); if (!request) return; ASSERT(scriptExecutionContext->isWorkerContext()); WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerContext*>(scriptExecutionContext), *request, *this, AllowStoredCredentials, crossOriginRedirectPolicy); }
void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRedirectPolicy crossOriginRedirectPolicy, WorkerScriptLoaderClient* client) { ASSERT(client); m_client = client; m_url = url; OwnPtr<ResourceRequest> request(createResourceRequest()); if (!request) return; m_threadableLoader = ThreadableLoader::create(scriptExecutionContext, this, *request, DoNotSendLoadCallbacks, DoNotSniffContent, AllowStoredCredentials, crossOriginRedirectPolicy); }
void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy, WorkerScriptLoaderClient* client) { ASSERT(client); m_client = client; m_url = url; OwnPtr<ResourceRequest> request(createResourceRequest()); if (!request) return; ThreadableLoaderOptions options; options.allowCredentials = true; options.crossOriginRequestPolicy = crossOriginRequestPolicy; m_threadableLoader = ThreadableLoader::create(scriptExecutionContext, this, *request, options); }
void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy) { m_url = url; OwnPtr<ResourceRequest> request(createResourceRequest()); if (!request) return; ASSERT(scriptExecutionContext->isWorkerContext()); ThreadableLoaderOptions options; options.allowCredentials = true; options.crossOriginRequestPolicy = crossOriginRequestPolicy; WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerContext*>(scriptExecutionContext), *request, *this, options); }
void WorkerScriptLoader::loadSynchronously(ExecutionContext& executionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy, WebAddressSpace creationAddressSpace) { m_url = url; ResourceRequest request(createResourceRequest(creationAddressSpace)); SECURITY_DCHECK(executionContext.isWorkerGlobalScope()); ThreadableLoaderOptions options; options.crossOriginRequestPolicy = crossOriginRequestPolicy; // FIXME: Should we add EnforceScriptSrcDirective here? options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy; ResourceLoaderOptions resourceLoaderOptions; resourceLoaderOptions.allowCredentials = AllowStoredCredentials; WorkerThreadableLoader::loadResourceSynchronously(toWorkerGlobalScope(executionContext), request, *this, options, resourceLoaderOptions); }
void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecutionContext, const URL& url, CrossOriginRequestPolicy crossOriginRequestPolicy) { m_url = url; std::unique_ptr<ResourceRequest> request(createResourceRequest()); if (!request) return; ASSERT_WITH_SECURITY_IMPLICATION(scriptExecutionContext->isWorkerGlobalScope()); ThreadableLoaderOptions options; options.setAllowCredentials(AllowStoredCredentials); options.crossOriginRequestPolicy = crossOriginRequestPolicy; options.setSendLoadCallbacks(SendCallbacks); WorkerThreadableLoader::loadResourceSynchronously(toWorkerGlobalScope(scriptExecutionContext), *request, *this, options); }
void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy, WorkerScriptLoaderClient* client) { ASSERT(client); m_client = client; m_url = url; OwnPtr<ResourceRequest> request(createResourceRequest()); if (!request) return; ThreadableLoaderOptions options; options.allowCredentials = AllowStoredCredentials; options.crossOriginRequestPolicy = crossOriginRequestPolicy; options.sendLoadCallbacks = SendCallbacks; // During create, callbacks may happen which remove the last reference to this object. RefPtr<WorkerScriptLoader> protect(this); m_threadableLoader = ThreadableLoader::create(scriptExecutionContext, this, *request, options); }
void WorkerScriptLoader::loadSynchronously(ExecutionContext& executionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy) { m_url = url; OwnPtr<ResourceRequest> request(createResourceRequest()); if (!request) return; ASSERT_WITH_SECURITY_IMPLICATION(executionContext.isWorkerGlobalScope()); ThreadableLoaderOptions options; options.crossOriginRequestPolicy = crossOriginRequestPolicy; // FIXME: Should we add EnforceScriptSrcDirective here? options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy; ResourceLoaderOptions resourceLoaderOptions; resourceLoaderOptions.allowCredentials = AllowStoredCredentials; WorkerThreadableLoader::loadResourceSynchronously(toWorkerGlobalScope(executionContext), *request, *this, options, resourceLoaderOptions); }
CFURLRequestRef ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse) { RefPtr<ResourceHandleCFURLConnectionDelegateWithOperationQueue> protector(this); dispatch_async(dispatch_get_main_queue(), ^{ if (!protector->hasHandle()) { continueWillSendRequest(nullptr); return; } LOG(Network, "CFNet - ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data()); RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse); if (!redirectResponse) { m_handle->continueWillSendRequest(cfRequest); return; } ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get()); m_handle->willSendRequest(request, redirectResponse.get()); });
CFURLRequestRef SynchronousResourceHandleCFURLConnectionDelegate::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse) { RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse); if (!redirectResponse) { CFRetain(cfRequest); return cfRequest; } LOG(Network, "CFNet - SynchronousResourceHandleCFURLConnectionDelegate::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data()); ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get()); auto newRequest = m_handle->willSendRequest(WTFMove(request), redirectResponse.get()); if (newRequest.isNull()) return nullptr; auto newCFRequest = newRequest.cfURLRequest(UpdateHTTPBody); CFRetain(newCFRequest); return newCFRequest; }