Ejemplo 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);
    });
}
Ejemplo n.º 2
0
void MemoryCache::removeRequestFromSessionCaches(ScriptExecutionContext& context, const ResourceRequest& request)
{
    if (is<WorkerGlobalScope>(context)) {
        CrossThreadResourceRequestData* requestData = request.copyData().release();
        downcast<WorkerGlobalScope>(context).thread().workerLoaderProxy().postTaskToLoader([requestData] (ScriptExecutionContext& context) {
            auto request(ResourceRequest::adopt(std::unique_ptr<CrossThreadResourceRequestData>(requestData)));
            MemoryCache::removeRequestFromSessionCaches(context, *request);
        });
        return;
    }

    auto& memoryCache = MemoryCache::singleton();
    for (auto& resources : memoryCache.m_sessionResources) {
        if (CachedResource* resource = memoryCache.resourceForRequestImpl(request, *resources.value))
            memoryCache.remove(*resource);
    }
}
Ejemplo n.º 3
0
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);
    });
}
Ejemplo n.º 4
0
TEST(ResourceRequestTest, CrossThreadResourceRequestData) {
  ResourceRequest original;
  original.setURL(KURL(ParsedURLString, "http://www.example.com/test.htm"));
  original.setCachePolicy(WebCachePolicy::UseProtocolCachePolicy);
  original.setTimeoutInterval(10);
  original.setFirstPartyForCookies(
      KURL(ParsedURLString, "http://www.example.com/first_party.htm"));
  original.setRequestorOrigin(SecurityOrigin::create(
      KURL(ParsedURLString, "http://www.example.com/first_party.htm")));
  original.setHTTPMethod(HTTPNames::GET);
  original.setHTTPHeaderField(AtomicString("Foo"), AtomicString("Bar"));
  original.setHTTPHeaderField(AtomicString("Piyo"), AtomicString("Fuga"));
  original.setPriority(ResourceLoadPriorityLow, 20);

  RefPtr<EncodedFormData> originalBody(EncodedFormData::create("Test Body"));
  original.setHTTPBody(originalBody);
  original.setAllowStoredCredentials(false);
  original.setReportUploadProgress(false);
  original.setHasUserGesture(false);
  original.setDownloadToFile(false);
  original.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::None);
  original.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
  original.setFetchCredentialsMode(
      WebURLRequest::FetchCredentialsModeSameOrigin);
  original.setRequestorID(30);
  original.setRequestorProcessID(40);
  original.setAppCacheHostID(50);
  original.setRequestContext(WebURLRequest::RequestContextAudio);
  original.setFrameType(WebURLRequest::FrameTypeNested);
  original.setHTTPReferrer(
      Referrer("http://www.example.com/referrer.htm", ReferrerPolicyDefault));

  EXPECT_STREQ("http://www.example.com/test.htm",
               original.url().getString().utf8().data());
  EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, original.getCachePolicy());
  EXPECT_EQ(10, original.timeoutInterval());
  EXPECT_STREQ("http://www.example.com/first_party.htm",
               original.firstPartyForCookies().getString().utf8().data());
  EXPECT_STREQ("www.example.com",
               original.requestorOrigin()->host().utf8().data());
  EXPECT_STREQ("GET", original.httpMethod().utf8().data());
  EXPECT_STREQ("Bar", original.httpHeaderFields().get("Foo").utf8().data());
  EXPECT_STREQ("Fuga", original.httpHeaderFields().get("Piyo").utf8().data());
  EXPECT_EQ(ResourceLoadPriorityLow, original.priority());
  EXPECT_STREQ("Test Body",
               original.httpBody()->flattenToString().utf8().data());
  EXPECT_FALSE(original.allowStoredCredentials());
  EXPECT_FALSE(original.reportUploadProgress());
  EXPECT_FALSE(original.hasUserGesture());
  EXPECT_FALSE(original.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::None,
            original.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, original.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin,
            original.fetchCredentialsMode());
  EXPECT_EQ(30, original.requestorID());
  EXPECT_EQ(40, original.requestorProcessID());
  EXPECT_EQ(50, original.appCacheHostID());
  EXPECT_EQ(WebURLRequest::RequestContextAudio, original.requestContext());
  EXPECT_EQ(WebURLRequest::FrameTypeNested, original.frameType());
  EXPECT_STREQ("http://www.example.com/referrer.htm",
               original.httpReferrer().utf8().data());
  EXPECT_EQ(ReferrerPolicyDefault, original.getReferrerPolicy());

  std::unique_ptr<CrossThreadResourceRequestData> data1(original.copyData());
  ResourceRequest copy1(data1.get());

  EXPECT_STREQ("http://www.example.com/test.htm",
               copy1.url().getString().utf8().data());
  EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, copy1.getCachePolicy());
  EXPECT_EQ(10, copy1.timeoutInterval());
  EXPECT_STREQ("http://www.example.com/first_party.htm",
               copy1.firstPartyForCookies().getString().utf8().data());
  EXPECT_STREQ("www.example.com",
               copy1.requestorOrigin()->host().utf8().data());
  EXPECT_STREQ("GET", copy1.httpMethod().utf8().data());
  EXPECT_STREQ("Bar", copy1.httpHeaderFields().get("Foo").utf8().data());
  EXPECT_EQ(ResourceLoadPriorityLow, copy1.priority());
  EXPECT_STREQ("Test Body", copy1.httpBody()->flattenToString().utf8().data());
  EXPECT_FALSE(copy1.allowStoredCredentials());
  EXPECT_FALSE(copy1.reportUploadProgress());
  EXPECT_FALSE(copy1.hasUserGesture());
  EXPECT_FALSE(copy1.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::None, copy1.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, copy1.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin,
            copy1.fetchCredentialsMode());
  EXPECT_EQ(30, copy1.requestorID());
  EXPECT_EQ(40, copy1.requestorProcessID());
  EXPECT_EQ(50, copy1.appCacheHostID());
  EXPECT_EQ(WebURLRequest::RequestContextAudio, copy1.requestContext());
  EXPECT_EQ(WebURLRequest::FrameTypeNested, copy1.frameType());
  EXPECT_STREQ("http://www.example.com/referrer.htm",
               copy1.httpReferrer().utf8().data());
  EXPECT_EQ(ReferrerPolicyDefault, copy1.getReferrerPolicy());

  copy1.setAllowStoredCredentials(true);
  copy1.setReportUploadProgress(true);
  copy1.setHasUserGesture(true);
  copy1.setDownloadToFile(true);
  copy1.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All);
  copy1.setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS);
  copy1.setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeInclude);

  std::unique_ptr<CrossThreadResourceRequestData> data2(copy1.copyData());
  ResourceRequest copy2(data2.get());
  EXPECT_TRUE(copy2.allowStoredCredentials());
  EXPECT_TRUE(copy2.reportUploadProgress());
  EXPECT_TRUE(copy2.hasUserGesture());
  EXPECT_TRUE(copy2.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::All, copy2.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, copy1.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeInclude,
            copy1.fetchCredentialsMode());
}
Ejemplo n.º 5
0
CrossThreadCopierBase<false, false, ResourceRequest>::Type CrossThreadCopierBase<false, false, ResourceRequest>::copy(const ResourceRequest& request)
{
    return request.copyData();
}
TEST(ResourceRequestTest, CrossThreadResourceRequestData)
{
    ResourceRequest original;
    original.setURL(KURL(ParsedURLString, "http://www.example.com/test.htm"));
    original.setCachePolicy(UseProtocolCachePolicy);
    original.setTimeoutInterval(10);
    original.setFirstPartyForCookies(KURL(ParsedURLString, "http://www.example.com/first_party.htm"));
    original.setHTTPMethod(AtomicString("GET", AtomicString::ConstructFromLiteral));
    original.setHTTPHeaderField(AtomicString("Foo"), AtomicString("Bar"));
    original.setHTTPHeaderField(AtomicString("Piyo"), AtomicString("Fuga"));
    original.setPriority(ResourceLoadPriorityLow, 20);

    RefPtr<FormData> originalBody(FormData::create("Test Body"));
    original.setHTTPBody(originalBody);
    original.setAllowStoredCredentials(false);
    original.setReportUploadProgress(false);
    original.setHasUserGesture(false);
    original.setDownloadToFile(false);
    original.setSkipServiceWorker(false);
    original.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
    original.setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeSameOrigin);
    original.setRequestorID(30);
    original.setRequestorProcessID(40);
    original.setAppCacheHostID(50);
    original.setRequestContext(WebURLRequest::RequestContextAudio);
    original.setFrameType(WebURLRequest::FrameTypeNested);
    original.setHTTPReferrer(Referrer("http://www.example.com/referrer.htm", ReferrerPolicyDefault));

    EXPECT_STREQ("http://www.example.com/test.htm", original.url().string().utf8().data());
    EXPECT_EQ(UseProtocolCachePolicy, original.cachePolicy());
    EXPECT_EQ(10, original.timeoutInterval());
    EXPECT_STREQ("http://www.example.com/first_party.htm", original.firstPartyForCookies().string().utf8().data());
    EXPECT_STREQ("GET", original.httpMethod().utf8().data());
    EXPECT_STREQ("Bar", original.httpHeaderFields().get("Foo").utf8().data());
    EXPECT_STREQ("Fuga", original.httpHeaderFields().get("Piyo").utf8().data());
    EXPECT_EQ(ResourceLoadPriorityLow, original.priority());
    EXPECT_STREQ("Test Body", original.httpBody()->flattenToString().utf8().data());
    EXPECT_FALSE(original.allowStoredCredentials());
    EXPECT_FALSE(original.reportUploadProgress());
    EXPECT_FALSE(original.hasUserGesture());
    EXPECT_FALSE(original.downloadToFile());
    EXPECT_FALSE(original.skipServiceWorker());
    EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, original.fetchRequestMode());
    EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, original.fetchCredentialsMode());
    EXPECT_EQ(30, original.requestorID());
    EXPECT_EQ(40, original.requestorProcessID());
    EXPECT_EQ(50, original.appCacheHostID());
    EXPECT_EQ(WebURLRequest::RequestContextAudio, original.requestContext());
    EXPECT_EQ(WebURLRequest::FrameTypeNested, original.frameType());
    EXPECT_STREQ("http://www.example.com/referrer.htm", original.httpReferrer().utf8().data());
    EXPECT_EQ(ReferrerPolicyDefault, original.referrerPolicy());

    OwnPtr<CrossThreadResourceRequestData> data1(original.copyData());
    OwnPtr<ResourceRequest> copy1(ResourceRequest::adopt(data1.release()));

    EXPECT_STREQ("http://www.example.com/test.htm", copy1->url().string().utf8().data());
    EXPECT_EQ(UseProtocolCachePolicy, copy1->cachePolicy());
    EXPECT_EQ(10, copy1->timeoutInterval());
    EXPECT_STREQ("http://www.example.com/first_party.htm", copy1->firstPartyForCookies().string().utf8().data());
    EXPECT_STREQ("GET", copy1->httpMethod().utf8().data());
    EXPECT_STREQ("Bar", copy1->httpHeaderFields().get("Foo").utf8().data());
    EXPECT_EQ(ResourceLoadPriorityLow, copy1->priority());
    EXPECT_STREQ("Test Body", copy1->httpBody()->flattenToString().utf8().data());
    EXPECT_FALSE(copy1->allowStoredCredentials());
    EXPECT_FALSE(copy1->reportUploadProgress());
    EXPECT_FALSE(copy1->hasUserGesture());
    EXPECT_FALSE(copy1->downloadToFile());
    EXPECT_FALSE(copy1->skipServiceWorker());
    EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, copy1->fetchRequestMode());
    EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, copy1->fetchCredentialsMode());
    EXPECT_EQ(30, copy1->requestorID());
    EXPECT_EQ(40, copy1->requestorProcessID());
    EXPECT_EQ(50, copy1->appCacheHostID());
    EXPECT_EQ(WebURLRequest::RequestContextAudio, copy1->requestContext());
    EXPECT_EQ(WebURLRequest::FrameTypeNested, copy1->frameType());
    EXPECT_STREQ("http://www.example.com/referrer.htm", copy1->httpReferrer().utf8().data());
    EXPECT_EQ(ReferrerPolicyDefault, copy1->referrerPolicy());

    copy1->setAllowStoredCredentials(true);
    copy1->setReportUploadProgress(true);
    copy1->setHasUserGesture(true);
    copy1->setDownloadToFile(true);
    copy1->setSkipServiceWorker(true);
    copy1->setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS);
    copy1->setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeInclude);

    OwnPtr<CrossThreadResourceRequestData> data2(copy1->copyData());
    OwnPtr<ResourceRequest> copy2(ResourceRequest::adopt(data2.release()));
    EXPECT_TRUE(copy2->allowStoredCredentials());
    EXPECT_TRUE(copy2->reportUploadProgress());
    EXPECT_TRUE(copy2->hasUserGesture());
    EXPECT_TRUE(copy2->downloadToFile());
    EXPECT_TRUE(copy2->skipServiceWorker());
    EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, copy1->fetchRequestMode());
    EXPECT_EQ(WebURLRequest::FetchCredentialsModeInclude, copy1->fetchCredentialsMode());
}
Ejemplo n.º 7
0
CrossThreadCopier<ResourceRequest>::Type
CrossThreadCopier<ResourceRequest>::copy(const ResourceRequest& request) {
  return passed(request.copyData());
}