Example #1
0
void WebRequest::handleDataURL(GURL url)
{
    OwnPtr<std::string> data(new std::string);
    std::string mimeType;
    std::string charset;

    if (net::DataURL::Parse(url, &mimeType, &charset, data.get())) {
        // PopulateURLResponse from chrome implementation
        // weburlloader_impl.cc
        m_loadState = Response;
        OwnPtr<WebResponse> webResponse(new WebResponse(url.spec(), mimeType, data->size(), charset, 200));
        m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, webResponse.release()));

        if (!data->empty()) {
            m_loadState = GotData;
            m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                    m_urlLoader.get(), &WebUrlLoaderClient::didReceiveDataUrl, data.release()));
        }
    } else {
        // handle the failed case
    }

    finish(true);
}
Example #2
0
void WebRequest::finish(bool success)
{
    m_runnableFactory.RevokeAll();
    ASSERT(m_loadState < Finished, "(%p) called finish on an already finished WebRequest (%d) (%s)", this, m_loadState, m_url.c_str());
    if (m_loadState >= Finished)
        return;
#ifdef LOG_REQUESTS
    time_t finish;
    time(&finish);
    finish = finish - m_startTime;
    struct tm * timeinfo;
    char buffer[80];
    timeinfo = localtime(&finish);
    strftime(buffer, 80, "Time: %M:%S",timeinfo);
    android_printLog(ANDROID_LOG_DEBUG, "KM", "(%p) finish (%d) (%s) (%d) (%s)", this, --remaining, buffer, success, m_url.c_str());
#endif

    // Make sure WebUrlLoaderClient doesn't delete us in the middle of this method.
    scoped_refptr<WebRequest> guard(this);

    m_loadState = Finished;
    if (success) {
        m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                m_urlLoader.get(), &WebUrlLoaderClient::didFinishLoading));
    } else {
        if (m_interceptResponse == NULL) {
            OwnPtr<WebResponse> webResponse(new WebResponse(m_request.get()));
            m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                    m_urlLoader.get(), &WebUrlLoaderClient::didFail, webResponse.release()));
        } else {
            OwnPtr<WebResponse> webResponse(new WebResponse(m_url, m_interceptResponse->mimeType(), 0,
                    m_interceptResponse->encoding(), m_interceptResponse->status()));
            m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                    m_urlLoader.get(), &WebUrlLoaderClient::didFail, webResponse.release()));
        }
    }
    m_networkBuffer = 0;
    m_request = 0;
    m_urlLoader = 0;
}
Example #3
0
// Called upon a server-initiated redirect.  The delegate may call the
// request's Cancel method to prevent the redirect from being followed.
// Since there may be multiple chained redirects, there may also be more
// than one redirect call.
//
// When this function is called, the request will still contain the
// original URL, the destination of the redirect is provided in 'new_url'.
// If the delegate does not cancel the request and |*defer_redirect| is
// false, then the redirect will be followed, and the request's URL will be
// changed to the new URL.  Otherwise if the delegate does not cancel the
// request and |*defer_redirect| is true, then the redirect will be
// followed once FollowDeferredRedirect is called on the URLRequest.
//
// The caller must set |*defer_redirect| to false, so that delegates do not
// need to set it if they are happy with the default behavior of not
// deferring redirect.
void WebRequest::OnReceivedRedirect(net::URLRequest* newRequest, const GURL& newUrl, bool* deferRedirect)
{
    ASSERT(m_loadState < Response, "Redirect after receiving response");
    ASSERT(newRequest && newRequest->status().is_success(), "Invalid redirect");

    OwnPtr<WebResponse> webResponse(new WebResponse(newRequest));
    webResponse->setUrl(newUrl.spec());
    m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
            m_urlLoader.get(), &WebUrlLoaderClient::willSendRequest, webResponse.release()));

    // Defer the redirect until followDeferredRedirect() is called.
    *deferRedirect = true;
}
Example #4
0
// After calling Start(), the delegate will receive an OnResponseStarted
// callback when the request has completed.  If an error occurred, the
// request->status() will be set.  On success, all redirects have been
// followed and the final response is beginning to arrive.  At this point,
// meta data about the response is available, including for example HTTP
// response headers if this is a request for a HTTP resource.
void WebRequest::OnResponseStarted(net::URLRequest* request)
{
    ASSERT(m_loadState == Started, "Got response after receiving response");

    m_loadState = Response;
    if (request && request->status().is_success()) {
        OwnPtr<WebResponse> webResponse(new WebResponse(request));
        m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, webResponse.release()));

        // Start reading the response
        startReading();
    } else {
        finish(false);
    }
}
Example #5
0
void WebRequest::handleInterceptedURL()
{
    m_loadState = Response;

    const std::string& mime = m_interceptResponse->mimeType();
    // Get the MIME type from the URL. "text/html" is a last resort, hopefully overridden.
    std::string mimeType("text/html");
    if (mime == "") {
        // Gmail appends the MIME to the end of the URL, with a ? separator.
        size_t mimeTypeIndex = m_url.find_last_of('?');
        if (mimeTypeIndex != std::string::npos) {
            mimeType.assign(m_url.begin() + mimeTypeIndex + 1, m_url.end());
        } else {
            // Get the MIME type from the file extension, if any.
            FilePath path(m_url);
            net::GetMimeTypeFromFile(path, &mimeType);
        }
    } else {
        // Set from the intercept response.
        mimeType = mime;
    }


    OwnPtr<WebResponse> webResponse(new WebResponse(m_url, mimeType, 0, m_interceptResponse->encoding(), m_interceptResponse->status()));
    m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
            m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, webResponse.release()));

    do {
        // data is deleted in WebUrlLoaderClient::didReceiveAndroidFileData
        // data is sent to the webcore thread
        OwnPtr<std::vector<char> > data(new std::vector<char>);
        data->reserve(kInitialReadBufSize);

        // Read returns false on error and size of 0 on eof.
        if (!m_interceptResponse->readStream(data.get()) || data->size() == 0)
            break;

        m_loadState = GotData;
        m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                m_urlLoader.get(), &WebUrlLoaderClient::didReceiveAndroidFileData, data.release()));
    } while (true);

    finish(m_interceptResponse->status() == 200);
}
Example #6
0
void WebRequest::finish(bool success)
{
    m_runnableFactory.RevokeAll();
    ASSERT(m_loadState < Finished, "(%p) called finish on an already finished WebRequest (%d) (%s)", this, m_loadState, m_url.c_str());
    if (m_loadState >= Finished)
        return;
#ifdef LOG_REQUESTS
    time_t finish;
    time(&finish);
    finish = finish - m_startTime;
    struct tm * timeinfo;
    char buffer[80];
    timeinfo = localtime(&finish);
    strftime(buffer, 80, "Time: %M:%S",timeinfo);
    android_printLog(ANDROID_LOG_DEBUG, "KM", "(%p) finish (%d) (%s) (%d) (%s)", this, --remaining, buffer, success, m_url.c_str());
#endif
    // SAMSUNG CHANGES : add_network_log
    LOGIFDEBUG("finish(%d) url(%s) isMainFrame(%d) isMainResource(%d)",success, m_url.c_str(), m_isMainFrame, m_isMainResource);

    // Make sure WebUrlLoaderClient doesn't delete us in the middle of this method.
    scoped_refptr<WebRequest> guard(this);

    // SAMSUNG CHANGE : reduce events in main thread >>
#if _USE_SAMSUNG_PERFORMANCE_IMPROVE_
    // send remaining data before close the connection
    if (m_BytesInBuffer > 0)
        sendDataReceivedEvent(true);
    // SAMSUNG CHANGE : reduce events in main thread <<
#endif
    m_loadState = Finished;
    if (success) {
        //SAMSUNG_CHANGES >>
        if(m_rssSniffingEnabled)
        {
            if( m_ShouldSniffFeed) { 
                m_ShouldSniffFeed = false;
                m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                        m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, m_webResponse.release()));
            }
        }
        //SAMSUNG_CHANGES <<
        m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                m_urlLoader.get(), &WebUrlLoaderClient::didFinishLoading));
    } else {
        if (m_interceptResponse == NULL) {
            //SAMSUNG_CHANGES >>
            if(m_rssSniffingEnabled)
            {
	        if( m_ShouldSniffFeed) { 
                    m_ShouldSniffFeed = false;
                        m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                                m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, m_webResponse.release()));
	        }
            }
            //SAMSUNG_CHANGES <<
            OwnPtr<WebResponse> webResponse(new WebResponse(m_request.get()));
            m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                    m_urlLoader.get(), &WebUrlLoaderClient::didFail, webResponse.release()));
        } else {
            OwnPtr<WebResponse> webResponse(new WebResponse(m_url, m_interceptResponse->mimeType(), 0,
                    m_interceptResponse->encoding(), m_interceptResponse->status()));
            m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                    m_urlLoader.get(), &WebUrlLoaderClient::didFail, webResponse.release()));
        }
    }
    m_networkBuffer = 0;
    m_request = 0;
    m_urlLoader = 0;
}