int NetworkManager::startJob(int playerId, const String& pageGroupName, PassRefPtr<ResourceHandle> job, const ResourceRequest& request, BlackBerry::Platform::NetworkStreamFactory* streamFactory, Frame* frame, int deferLoadingCount, int redirectCount, bool rereadCookies)
{
    // Make sure the ResourceHandle doesn't go out of scope while calling callbacks.
    RefPtr<ResourceHandle> guardJob(job);

    KURL url = request.url();

    // Only load the initial url once.
    bool isInitial = (url == m_initialURL);
    if (isInitial)
        m_initialURL = KURL();

    // Always reread cookies on a redirect
    if (redirectCount)
        rereadCookies = true;

    BlackBerry::Platform::NetworkRequest platformRequest;
    request.initializePlatformRequest(platformRequest, frame->loader() && frame->loader()->client() && static_cast<FrameLoaderClientBlackBerry*>(frame->loader()->client())->cookiesEnabled(), isInitial, rereadCookies);

    // GURL and KURL consider valid URLs differently, for example http:// is parsed as
    // http:/ by KURL and considered valid, while GURL considers it invalid.
    if (!platformRequest.url().is_valid())
        return BlackBerry::Platform::FilterStream::StatusErrorInvalidUrl;

    const String& documentUrl = frame->document()->url().string();
    if (!documentUrl.isEmpty())
        platformRequest.setReferrer(documentUrl);

    platformRequest.setSecurityOrigin(frame->document()->securityOrigin()->toRawString());

    // Attach any applicable auth credentials to the NetworkRequest.
    setAuthCredentials(platformRequest, guardJob->getInternal()->m_hostWebChallenge);
    setAuthCredentials(platformRequest, guardJob->getInternal()->m_proxyWebChallenge);

    if (!request.overrideContentType().isEmpty())
        platformRequest.setOverrideContentType(request.overrideContentType());

    NetworkJob* networkJob = new NetworkJob;
    networkJob->initialize(playerId, pageGroupName, url, platformRequest, guardJob, streamFactory, frame, deferLoadingCount, redirectCount);

    // Make sure we have only one NetworkJob for one ResourceHandle.
    ASSERT(!findJobForHandle(guardJob));

    m_jobs.append(networkJob);

    switch (networkJob->streamOpen()) {
    case BlackBerry::Platform::FilterStream::ResultOk:
        return BlackBerry::Platform::FilterStream::StatusSuccess;
    case BlackBerry::Platform::FilterStream::ResultNotReady:
        return BlackBerry::Platform::FilterStream::StatusErrorNotReady;
    case BlackBerry::Platform::FilterStream::ResultNotHandled:
    default:
        // This should never happen.
        break;
    }

    ASSERT_NOT_REACHED();
    return BlackBerry::Platform::FilterStream::StatusErrorConnectionFailed;
}
Beispiel #2
0
bool NetworkManager::startJob(int playerId, const String& pageGroupName, PassRefPtr<ResourceHandle> job, const ResourceRequest& request, BlackBerry::Platform::NetworkStreamFactory* streamFactory, Frame* frame, int deferLoadingCount, int redirectCount)
{
    // Make sure the ResourceHandle doesn't go out of scope while calling callbacks.
    RefPtr<ResourceHandle> guardJob(job);

    KURL url = request.url();

    // Only load the initial url once.
    bool isInitial = (url == m_initialURL);
    if (isInitial)
        m_initialURL = KURL();

    BlackBerry::Platform::NetworkRequest platformRequest;
    request.initializePlatformRequest(platformRequest, frame->loader() && frame->loader()->client() && static_cast<FrameLoaderClientBlackBerry*>(frame->loader()->client())->cookiesEnabled(), isInitial, redirectCount);

    const String& documentUrl = frame->document()->url().string();
    if (!documentUrl.isEmpty()) {
        platformRequest.setReferrer(documentUrl);
    }

    platformRequest.setSecurityOrigin(frame->document()->securityOrigin()->toRawString());

    // Attach any applicable auth credentials to the NetworkRequest.
    AuthenticationChallenge& challenge = guardJob->getInternal()->m_currentWebChallenge;
    if (!challenge.isNull()) {
        Credential credential = challenge.proposedCredential();
        const ProtectionSpace& protectionSpace = challenge.protectionSpace();

        String username = credential.user();
        String password = credential.password();

        BlackBerry::Platform::NetworkRequest::AuthType authType = BlackBerry::Platform::NetworkRequest::AuthTypeNone;
        switch (protectionSpace.serverType()) {
        case ProtectionSpaceServerHTTP:
            authType = BlackBerry::Platform::NetworkRequest::AuthTypeHTTP;
            break;
        case ProtectionSpaceServerHTTPS:
            authType = BlackBerry::Platform::NetworkRequest::AuthTypeHTTPS;
            break;
        case ProtectionSpaceServerFTP:
            authType = BlackBerry::Platform::NetworkRequest::AuthTypeFTP;
            break;
        case ProtectionSpaceServerFTPS:
            authType = BlackBerry::Platform::NetworkRequest::AuthTypeFTPS;
            break;
        case ProtectionSpaceProxyHTTP:
            authType = BlackBerry::Platform::NetworkRequest::AuthTypeProxyHTTP;
            break;
        case ProtectionSpaceProxyHTTPS:
            authType = BlackBerry::Platform::NetworkRequest::AuthTypeProxyHTTPS;
            break;
        case ProtectionSpaceProxyFTP:
            authType = BlackBerry::Platform::NetworkRequest::AuthTypeProxyFTP;
            break;
        default:
            ASSERT_NOT_REACHED();
            break;
        }

        BlackBerry::Platform::NetworkRequest::AuthScheme authScheme = BlackBerry::Platform::NetworkRequest::AuthSchemeNone;
        switch (protectionSpace.authenticationScheme()) {
        case ProtectionSpaceAuthenticationSchemeDefault:
            authScheme = BlackBerry::Platform::NetworkRequest::AuthSchemeDefault;
            break;
        case ProtectionSpaceAuthenticationSchemeHTTPBasic:
            authScheme = BlackBerry::Platform::NetworkRequest::AuthSchemeHTTPBasic;
            break;
        case ProtectionSpaceAuthenticationSchemeHTTPDigest:
            authScheme = BlackBerry::Platform::NetworkRequest::AuthSchemeHTTPDigest;
            break;
        case ProtectionSpaceAuthenticationSchemeNegotiate:
            authScheme = BlackBerry::Platform::NetworkRequest::AuthSchemeNegotiate;
            break;
        case ProtectionSpaceAuthenticationSchemeNTLM:
            authScheme = BlackBerry::Platform::NetworkRequest::AuthSchemeNTLM;
            break;
        default:
            ASSERT_NOT_REACHED();
            break;
        }

        if (authType != BlackBerry::Platform::NetworkRequest::AuthTypeNone && authScheme != BlackBerry::Platform::NetworkRequest::AuthSchemeNone)
            platformRequest.setCredentials(username.utf8().data(), password.utf8().data(), authType, authScheme);
    }

    if (!request.overrideContentType().isEmpty())
        platformRequest.setOverrideContentType(request.overrideContentType().latin1().data());

    NetworkJob* networkJob = new NetworkJob;
    if (!networkJob)
        return false;
    if (!networkJob->initialize(playerId, pageGroupName, url, platformRequest, guardJob, streamFactory, frame, deferLoadingCount, redirectCount)) {
        delete networkJob;
        return false;
    }

    // Make sure we have only one NetworkJob for one ResourceHandle.
    ASSERT(!findJobForHandle(guardJob));

    m_jobs.append(networkJob);

    int result = networkJob->streamOpen();
    if (result)
        return false;

    return true;
}