Changeset 77408 in webkit


Ignore:
Timestamp:
Feb 2, 2011 1:19:41 PM (13 years ago)
Author:
Martin Robinson
Message:

2011-02-02 Dan Winship <danw@gnome.org>

Reviewed by Martin Robinson.

[GTK] remove old data: URI handler, fix the SoupRequest-based one
to pass tests
https://bugs.webkit.org/show_bug.cgi?id=50885

  • platform/network/soup/ResourceHandleSoup.cpp: (WebCore::sendRequestCallback): Do content-type sniffing here for non-HTTP requests. (WebCore::startHTTPRequest): Rename to match WebKit style. (WebCore::ResourceHandle::start): Pass everything except HTTP to startNonHTTPRequest, letting the SoupRequester decide whether it's supported or not. (WebCore::startNonHTTPRequest): Remove some old pre-SoupRequester code that was a no-op for file: URIs, but would break some data: URIs.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r77407 r77408  
     12011-02-02  Dan Winship  <danw@gnome.org>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] remove old data: URI handler, fix the SoupRequest-based one
     6        to pass tests
     7        https://bugs.webkit.org/show_bug.cgi?id=50885
     8
     9        * platform/network/soup/ResourceHandleSoup.cpp:
     10        (WebCore::sendRequestCallback): Do content-type sniffing here for
     11        non-HTTP requests.
     12        (WebCore::startHTTPRequest): Rename to match WebKit style.
     13        (WebCore::ResourceHandle::start): Pass everything except HTTP to
     14        startNonHTTPRequest, letting the SoupRequester decide whether it's
     15        supported or not.
     16        (WebCore::startNonHTTPRequest): Remove some old pre-SoupRequester
     17        code that was a no-op for file: URIs, but would break some data:
     18        URIs.
     19
    1202011-02-02  Dimitri Glazkov  <dglazkov@chromium.org>
    221
  • trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp

    r77399 r77408  
    130130static void readCallback(GObject*, GAsyncResult*, gpointer);
    131131static void closeCallback(GObject*, GAsyncResult*, gpointer);
    132 static bool startGio(ResourceHandle*, KURL);
     132static bool startNonHTTPRequest(ResourceHandle*, KURL);
    133133
    134134ResourceHandleInternal::~ResourceHandleInternal()
     
    298298}
    299299
    300 // This callback will not be called if the content sniffer is disabled in startHttp.
     300// This callback will not be called if the content sniffer is disabled in startHTTPRequest.
    301301static void contentSniffedCallback(SoupMessage* msg, const char* sniffedType, GHashTable *params, gpointer data)
    302302{
     
    345345
    346346    client->didReceiveData(handle.get(), chunk->data, chunk->length, false);
    347 }
    348 
    349 static gboolean parseDataUrl(gpointer callbackData)
    350 {
    351     ResourceHandle* handle = static_cast<ResourceHandle*>(callbackData);
    352     ResourceHandleClient* client = handle->client();
    353     ResourceHandleInternal* d = handle->getInternal();
    354     if (d->m_cancelled)
    355         return false;
    356 
    357     d->m_idleHandler = 0;
    358 
    359     ASSERT(client);
    360     if (!client)
    361         return false;
    362 
    363     String url = handle->firstRequest().url().string();
    364     ASSERT(url.startsWith("data:", false));
    365 
    366     int index = url.find(',');
    367     if (index == -1) {
    368         client->cannotShowURL(handle);
    369         return false;
    370     }
    371 
    372     String mediaType = url.substring(5, index - 5);
    373 
    374     bool isBase64 = mediaType.endsWith(";base64", false);
    375     if (isBase64)
    376         mediaType = mediaType.left(mediaType.length() - 7);
    377 
    378     if (mediaType.isEmpty())
    379         mediaType = "text/plain;charset=US-ASCII";
    380 
    381     String mimeType = extractMIMETypeFromMediaType(mediaType);
    382     String charset = extractCharsetFromMediaType(mediaType);
    383 
    384     ASSERT(d->m_response.isNull());
    385 
    386     d->m_response.setURL(handle->firstRequest().url());
    387     d->m_response.setMimeType(mimeType);
    388 
    389     // For non base64 encoded data we have to convert to UTF-16 early
    390     // due to limitations in KURL
    391     d->m_response.setTextEncodingName(isBase64 ? charset : "UTF-16");
    392     client->didReceiveResponse(handle, d->m_response);
    393 
    394     // The load may be cancelled, and the client may be destroyed
    395     // by any of the client reporting calls, so we check, and bail
    396     // out in either of those cases.
    397     if (d->m_cancelled || !handle->client())
    398         return false;
    399 
    400     SoupSession* session = handle->defaultSession();
    401     ensureSessionIsInitialized(session);
    402     SoupRequester* requester = SOUP_REQUESTER(soup_session_get_feature(session, SOUP_TYPE_REQUESTER));
    403     GOwnPtr<GError> error;
    404     d->m_soupRequest = adoptGRef(soup_requester_request(requester, handle->firstRequest().url().string().utf8().data(), &error.outPtr()));
    405     if (error) {
    406         d->m_soupRequest = 0;
    407         client->didFinishLoading(handle, 0);
    408         return false;
    409     }
    410 
    411     d->m_inputStream = adoptGRef(soup_request_send(d->m_soupRequest.get(), 0, &error.outPtr()));
    412     if (error) {
    413         d->m_inputStream = 0;
    414         client->didFinishLoading(handle, 0);
    415         return false;
    416     }
    417 
    418     d->m_buffer = static_cast<char*>(g_slice_alloc0(READ_BUFFER_SIZE));
    419     d->m_total = 0;
    420 
    421     g_object_set_data(G_OBJECT(d->m_inputStream.get()), "webkit-resource", handle);
    422     // balanced by a deref() in cleanupSoupRequestOperation, which should always run
    423     handle->ref();
    424 
    425     d->m_cancellable = adoptGRef(g_cancellable_new());
    426     g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT,
    427                               d->m_cancellable.get(), readCallback, GINT_TO_POINTER(!isBase64));
    428 
    429     return false;
    430 }
    431 
    432 static bool startData(ResourceHandle* handle, String urlString)
    433 {
    434     ASSERT(handle);
    435 
    436     ResourceHandleInternal* d = handle->getInternal();
    437 
    438     // If parseDataUrl is called synchronously the job is not yet effectively started
    439     // and webkit won't never know that the data has been parsed even didFinishLoading is called.
    440     d->m_idleHandler = g_timeout_add(0, parseDataUrl, handle);
    441     return true;
    442347}
    443348
     
    555460    g_object_set_data(G_OBJECT(d->m_inputStream.get()), "webkit-resource", handle.get());
    556461
    557     // Ensure a response is sent for any protocols that don't explicitly support responses
    558     // through got-headers signal or content sniffing.
    559     // (e.g. file and GIO based protocol).
    560     if (!handle->shouldContentSniff() && d->m_response.isNull()) {
     462    // If not using SoupMessage we need to call didReceiveResponse now.
     463    // (This will change later when SoupRequest supports content sniffing.)
     464    if (!d->m_soupMessage) {
    561465        d->m_response.setURL(handle->firstRequest().url());
    562         d->m_response.setMimeType(soup_request_get_content_type(d->m_soupRequest.get()));
     466        const gchar* contentType = soup_request_get_content_type(d->m_soupRequest.get());
     467        d->m_response.setMimeType(extractMIMETypeFromMediaType(contentType));
     468        d->m_response.setTextEncodingName(extractCharsetFromMediaType(contentType));
    563469        d->m_response.setExpectedContentLength(soup_request_get_content_length(d->m_soupRequest.get()));
    564470        client->didReceiveResponse(handle.get(), d->m_response);
     
    577483}
    578484
    579 static bool startHttp(ResourceHandle* handle)
     485static bool startHTTPRequest(ResourceHandle* handle)
    580486{
    581487    ASSERT(handle);
     
    719625    d->m_context = context;
    720626
    721     if (equalIgnoringCase(protocol, "data"))
    722         return startData(this, urlString);
    723 
    724627    if (equalIgnoringCase(protocol, "http") || equalIgnoringCase(protocol, "https")) {
    725         if (startHttp(this))
     628        if (startHTTPRequest(this))
    726629            return true;
    727630    }
    728631
    729     if (equalIgnoringCase(protocol, "file") || equalIgnoringCase(protocol, "ftp") || equalIgnoringCase(protocol, "ftps")) {
    730         // FIXME: should we be doing any other protocols here?
    731         if (startGio(this, url))
    732             return true;
    733     }
     632    if (startNonHTTPRequest(this, url))
     633        return true;
    734634
    735635    // Error must not be reported immediately
     
    881781}
    882782
    883 static bool startGio(ResourceHandle* handle, KURL url)
     783static bool startNonHTTPRequest(ResourceHandle* handle, KURL url)
    884784{
    885785    ASSERT(handle);
     
    893793    ResourceHandleInternal* d = handle->getInternal();
    894794
    895     // GIO doesn't know how to handle refs and queries, so remove them
    896     // TODO: use KURL.fileSystemPath after KURLGtk and FileSystemGtk are
    897     // using GIO internally, and providing URIs instead of file paths
    898     url.removeFragmentIdentifier();
    899     url.setQuery(String());
    900     url.removePort();
    901795    CString urlStr = url.string().utf8();
    902796
Note: See TracChangeset for help on using the changeset viewer.