Changeset 207405 in webkit


Ignore:
Timestamp:
Oct 17, 2016 3:52:02 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[SOUP] Downloads should always sniff contents
https://bugs.webkit.org/show_bug.cgi?id=163538

Reviewed by Michael Catanzaro.

Source/WebKit2:

It's quite common that downloads have weird filenames with no extension, so it would be better if the loader
sniff the contents to guess the mime type.

  • NetworkProcess/Downloads/soup/DownloadSoup.cpp:

(WebKit::Download::startNetworkLoad): Pass true for shouldContentSniff parameter of ResourceHandle::create().

Tools:

Add a test case to check that the MIME type is correctly guessed for downloads.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:

(writeNextChunk):
(serverCallback):
(testDownloadMIMEType):
(beforeAll):
(writeNextChunkIdle): Deleted.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r207404 r207405  
     12016-10-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Downloads should always sniff contents
     4        https://bugs.webkit.org/show_bug.cgi?id=163538
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        It's quite common that downloads have weird filenames with no extension, so it would be better if the loader
     9        sniff the contents to guess the mime type.
     10
     11        * NetworkProcess/Downloads/soup/DownloadSoup.cpp:
     12        (WebKit::Download::startNetworkLoad): Pass true for shouldContentSniff parameter of ResourceHandle::create().
     13
    1142016-10-17  Carlos Garcia Campos  <cgarcia@igalia.com>
    215
  • trunk/Source/WebKit2/NetworkProcess/Downloads/soup/DownloadSoup.cpp

    r206439 r207405  
    213213    ASSERT(!m_resourceHandle);
    214214    m_downloadClient = std::make_unique<DownloadClient>(*this);
    215     m_resourceHandle = ResourceHandle::create(0, m_request, m_downloadClient.get(), false, false);
     215    m_resourceHandle = ResourceHandle::create(0, m_request, m_downloadClient.get(), false, true);
    216216    didStart();
    217217}
  • trunk/Tools/ChangeLog

    r207399 r207405  
     12016-10-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Downloads should always sniff contents
     4        https://bugs.webkit.org/show_bug.cgi?id=163538
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add a test case to check that the MIME type is correctly guessed for downloads.
     9
     10        * TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
     11        (writeNextChunk):
     12        (serverCallback):
     13        (testDownloadMIMEType):
     14        (beforeAll):
     15        (writeNextChunkIdle): Deleted.
     16
    1172016-10-16  Daniel Bates  <dabates@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp

    r185502 r207405  
    389389}
    390390
    391 static gboolean writeNextChunkIdle(SoupMessage* message)
    392 {
    393     soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, "chunk", 5);
    394     return FALSE;
    395 }
    396 
    397391static void writeNextChunk(SoupMessage* message)
    398392{
    399     g_timeout_add(100, reinterpret_cast<GSourceFunc>(writeNextChunkIdle), message);
     393    /* We need a big enough chunk for the sniffer to not block the load */
     394    static const char* chunk = "Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
     395        "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
     396        "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
     397        "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
     398        "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
     399        "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
     400        "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!";
     401    soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, chunk, strlen(chunk));
    400402}
    401403
     
    418420    }
    419421
     422    if (g_str_equal(path, "/unknown"))
     423        path = "/test.pdf";
     424
    420425    GUniquePtr<char> filePath(g_build_filename(Test::getResourcesDir().data(), path, nullptr));
    421426    char* contents;
     
    611616    g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
    612617    test->cancelDownloadAndWaitUntilFinished();
     618}
     619
     620static void testDownloadMIMEType(DownloadTest* test, gconstpointer)
     621{
     622    GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/unknown")));
     623    g_assert(!webkit_download_get_web_view(download.get()));
     624
     625    Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
     626    g_assert_cmpint(events.size(), ==, 5);
     627    g_assert_cmpint(events[0], ==, DownloadTest::Started);
     628    g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse);
     629    g_assert_cmpint(events[2], ==, DownloadTest::CreatedDestination);
     630    g_assert_cmpint(events[3], ==, DownloadTest::ReceivedData);
     631    g_assert_cmpint(events[4], ==, DownloadTest::Finished);
     632    events.clear();
     633
     634    WebKitURIRequest* request = webkit_download_get_request(download.get());
     635    WEBKIT_IS_URI_REQUEST(request);
     636    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/unknown"));
     637
     638    WebKitURIResponse* response = webkit_download_get_response(download.get());
     639    WEBKIT_IS_URI_RESPONSE(response);
     640    g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "application/pdf");
     641
     642    g_assert(webkit_download_get_destination(download.get()));
     643    g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1);
     644    test->checkDestinationAndDeleteFile(download.get(), kServerSuggestedFilename);
    613645}
    614646
     
    626658    WebViewDownloadTest::add("WebKitWebView", "download-uri", testWebViewDownloadURI);
    627659    PolicyResponseDownloadTest::add("Downloads", "policy-decision-download", testPolicyResponseDownload);
     660    DownloadTest::add("Downloads", "mime-type", testDownloadMIMEType);
    628661}
    629662
Note: See TracChangeset for help on using the changeset viewer.