Esempio n. 1
0
WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, WorkerLoaderProxy& loaderProxy, const String& taskMode,
    const ResourceRequest& request, const ThreadableLoaderOptions& options, const String& outgoingReferrer,
    const SecurityOrigin* securityOrigin, const ContentSecurityPolicy* contentSecurityPolicy)
    : m_workerClientWrapper(workerClientWrapper)
    , m_loaderProxy(loaderProxy)
    , m_taskMode(taskMode.isolatedCopy())
{
    ASSERT(m_workerClientWrapper.get());

    auto* requestData = request.copyData().release();
    auto* optionsCopy = options.isolatedCopy().release();

    ASSERT(securityOrigin);
    ASSERT(contentSecurityPolicy);
    auto* contentSecurityPolicyCopy = std::make_unique<ContentSecurityPolicy>(*securityOrigin).release();
    contentSecurityPolicyCopy->copyStateFrom(contentSecurityPolicy);

    StringCapture capturedOutgoingReferrer(outgoingReferrer);
    m_loaderProxy.postTaskToLoader([this, requestData, optionsCopy, contentSecurityPolicyCopy, capturedOutgoingReferrer](ScriptExecutionContext& context) {
        ASSERT(isMainThread());
        Document& document = downcast<Document>(context);

        auto request = ResourceRequest::adopt(std::unique_ptr<CrossThreadResourceRequestData>(requestData));
        request->setHTTPReferrer(capturedOutgoingReferrer.string());

        auto options = std::unique_ptr<ThreadableLoaderOptions>(optionsCopy);

        // FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
        // will return a 0 value. Either this should return 0 or the other code path should do a callback with
        // a failure.
        m_mainThreadLoader = DocumentThreadableLoader::create(document, *this, *request, *options, std::unique_ptr<ContentSecurityPolicy>(contentSecurityPolicyCopy));
        ASSERT(m_mainThreadLoader);
    });
}
WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, WorkerLoaderProxy& loaderProxy, const String& taskMode,
                                                           const ResourceRequest& request, const ThreadableLoaderOptions& options, const String& outgoingReferrer)
    : m_workerClientWrapper(workerClientWrapper)
    , m_loaderProxy(loaderProxy)
    , m_taskMode(taskMode.isolatedCopy())
{
    ASSERT(m_workerClientWrapper.get());

    CrossThreadResourceRequestData* requestData = request.copyData().leakPtr();
    StringCapture capturedOutgoingReferrer(outgoingReferrer);
    m_loaderProxy.postTaskToLoader([this, requestData, options, capturedOutgoingReferrer](ScriptExecutionContext& context) {
        ASSERT(isMainThread());
        Document& document = downcast<Document>(context);

        OwnPtr<ResourceRequest> request = ResourceRequest::adopt(adoptPtr(requestData));
        request->setHTTPReferrer(capturedOutgoingReferrer.string());

        // FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
        // will return a 0 value. Either this should return 0 or the other code path should do a callback with
        // a failure.
        m_mainThreadLoader = DocumentThreadableLoader::create(document, *this, *request, options);
        ASSERT(m_mainThreadLoader);
    });
}