⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourcehandlecfnet.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    CFRunLoopRun();    return 0;}CFRunLoopRef ResourceHandle::loaderRunLoop(){    if (!loaderRL) {        createThread(runLoaderThread, 0, "CFNetwork::Loader");        while (loaderRL == 0) {            // FIXME: sleep 10? that can't be right...            Sleep(10);        }    }    return loaderRL;}static CFURLRequestRef makeFinalRequest(const ResourceRequest& request, bool shouldContentSniff){    CFMutableURLRequestRef newRequest = CFURLRequestCreateMutableCopy(kCFAllocatorDefault, request.cfURLRequest());        if (!shouldContentSniff)        wkSetCFURLRequestShouldContentSniff(newRequest, false);    RetainPtr<CFMutableDictionaryRef> sslProps;    if (allowsAnyHTTPSCertificateHosts().contains(request.url().host().lower())) {        sslProps.adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));        CFDictionaryAddValue(sslProps.get(), kCFStreamSSLAllowsAnyRoot, kCFBooleanTrue);        CFDictionaryAddValue(sslProps.get(), kCFStreamSSLAllowsExpiredRoots, kCFBooleanTrue);    }    HashMap<String, RetainPtr<CFDataRef> >::iterator clientCert = clientCerts().find(request.url().host().lower());    if (clientCert != clientCerts().end()) {        if (!sslProps)            sslProps.adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));        wkSetClientCertificateInSSLProperties(sslProps.get(), (clientCert->second).get());    }    if (sslProps)        CFURLRequestSetSSLProperties(newRequest, sslProps.get());    if (CFHTTPCookieStorageRef cookieStorage = currentCookieStorage()) {        CFURLRequestSetHTTPCookieStorage(newRequest, cookieStorage);        CFURLRequestSetHTTPCookieStorageAcceptPolicy(newRequest, CFHTTPCookieStorageGetCookieAcceptPolicy(cookieStorage));    }    return newRequest;}bool ResourceHandle::start(Frame* frame){    // If we are no longer attached to a Page, this must be an attempted load from an    // onUnload handler, so let's just block it.    if (!frame->page())        return false;    RetainPtr<CFURLRequestRef> request(AdoptCF, makeFinalRequest(d->m_request, d->m_shouldContentSniff));    CFURLConnectionClient_V3 client = { 3, this, 0, 0, 0, willSendRequest, didReceiveResponse, didReceiveData, NULL, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge, didSendBodyData, shouldUseCredentialStorageCallback, 0};    d->m_connection.adoptCF(CFURLConnectionCreate(0, request.get(), reinterpret_cast<CFURLConnectionClient*>(&client)));    CFURLConnectionScheduleWithCurrentMessageQueue(d->m_connection.get());    CFURLConnectionScheduleDownloadWithRunLoop(d->m_connection.get(), loaderRunLoop(), kCFRunLoopDefaultMode);    CFURLConnectionStart(d->m_connection.get());    LOG(Network, "CFNet - Starting URL %s (handle=%p, conn=%p)", d->m_request.url().string().utf8().data(), this, d->m_connection);    return true;}void ResourceHandle::cancel(){    if (d->m_connection) {        CFURLConnectionCancel(d->m_connection.get());        d->m_connection = 0;    }}PassRefPtr<SharedBuffer> ResourceHandle::bufferedData(){    ASSERT_NOT_REACHED();    return 0;}bool ResourceHandle::supportsBufferedData(){    return false;}bool ResourceHandle::shouldUseCredentialStorage(){    LOG(Network, "CFNet - shouldUseCredentialStorage()");    if (client())        return client()->shouldUseCredentialStorage(this);    return false;}void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge){    LOG(Network, "CFNet - didReceiveAuthenticationChallenge()");    ASSERT(!d->m_currentCFChallenge);    ASSERT(d->m_currentWebChallenge.isNull());    // Since CFURLConnection networking relies on keeping a reference to the original CFURLAuthChallengeRef,    // we make sure that is actually present    ASSERT(challenge.cfURLAuthChallengeRef());            d->m_currentCFChallenge = challenge.cfURLAuthChallengeRef();    d->m_currentWebChallenge = AuthenticationChallenge(d->m_currentCFChallenge, this);        if (client())        client()->didReceiveAuthenticationChallenge(this, d->m_currentWebChallenge);}void ResourceHandle::receivedCredential(const AuthenticationChallenge& challenge, const Credential& credential){    LOG(Network, "CFNet - receivedCredential()");    ASSERT(!challenge.isNull());    ASSERT(challenge.cfURLAuthChallengeRef());    if (challenge != d->m_currentWebChallenge)        return;    CFURLCredentialRef cfCredential = createCF(credential);    CFURLConnectionUseCredential(d->m_connection.get(), cfCredential, challenge.cfURLAuthChallengeRef());    CFRelease(cfCredential);    clearAuthentication();}void ResourceHandle::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& challenge){    LOG(Network, "CFNet - receivedRequestToContinueWithoutCredential()");    ASSERT(!challenge.isNull());    ASSERT(challenge.cfURLAuthChallengeRef());    if (challenge != d->m_currentWebChallenge)        return;    CFURLConnectionUseCredential(d->m_connection.get(), 0, challenge.cfURLAuthChallengeRef());    clearAuthentication();}void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challenge){    LOG(Network, "CFNet - receivedCancellation()");    if (challenge != d->m_currentWebChallenge)        return;    if (client())        client()->receivedCancellation(this, challenge);}CFURLConnectionRef ResourceHandle::connection() const{    return d->m_connection.get();}CFURLConnectionRef ResourceHandle::releaseConnectionForDownload(){    LOG(Network, "CFNet - Job %p releasing connection %p for download", this, d->m_connection.get());    return d->m_connection.releaseRef();}void ResourceHandle::loadResourceSynchronously(const ResourceRequest& request, ResourceError& error, ResourceResponse& response, Vector<char>& vector, Frame*){    ASSERT(!request.isEmpty());    CFURLResponseRef cfResponse = 0;    CFErrorRef cfError = 0;    RetainPtr<CFURLRequestRef> cfRequest(AdoptCF, makeFinalRequest(request, true));    CFDataRef data = CFURLConnectionSendSynchronousRequest(cfRequest.get(), &cfResponse, &cfError, request.timeoutInterval());    if (cfError) {        error = cfError;        CFRelease(cfError);        response = ResourceResponse(request.url(), String(), 0, String(), String());        response.setHTTPStatusCode(404);    } else {        response = cfResponse;        if (cfResponse)            CFRelease(cfResponse);    }    if (data) {        ASSERT(vector.isEmpty());        vector.append(CFDataGetBytePtr(data), CFDataGetLength(data));        CFRelease(data);    }}void ResourceHandle::setHostAllowsAnyHTTPSCertificate(const String& host){    allowsAnyHTTPSCertificateHosts().add(host.lower());}void ResourceHandle::setClientCertificate(const String& host, CFDataRef cert){    clientCerts().set(host.lower(), cert);}void ResourceHandle::setDefersLoading(bool defers){    if (!d->m_connection)        return;    if (defers)        CFURLConnectionHalt(d->m_connection.get());    else        CFURLConnectionResume(d->m_connection.get());}bool ResourceHandle::loadsBlocked(){    return false;}bool ResourceHandle::willLoadFromCache(ResourceRequest& request){    request.setCachePolicy(ReturnCacheDataDontLoad);        CFURLResponseRef cfResponse = 0;    CFErrorRef cfError = 0;    RetainPtr<CFURLRequestRef> cfRequest(AdoptCF, makeFinalRequest(request, true));    RetainPtr<CFDataRef> data(AdoptCF, CFURLConnectionSendSynchronousRequest(cfRequest.get(), &cfResponse, &cfError, request.timeoutInterval()));    bool cached = cfResponse && !cfError;    if (cfError)        CFRelease(cfError);    if (cfResponse)        CFRelease(cfResponse);    return cached;}} // namespace WebCore

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -