Changeset 250899 in webkit


Ignore:
Timestamp:
Oct 9, 2019 12:42:05 AM (5 years ago)
Author:
Carlos Garcia Campos
Message:

REGRESSION(r250597): [GTK][WPE] 2.27.1 shows HTML content as text/plain in custom protocols when passing a charset in content type
https://bugs.webkit.org/show_bug.cgi?id=202633

Reviewed by Žan Doberšek.

Source/WebKit:

This is a regression of the switch to use the new custom protocols implementation. Before r250597, we extracted
the mime type and charset from content type in the network process, but we are now sending the response directly
from the UI process, so we need to do that when building our response. Rename the mime_type parameter as
content_type to avoid confusion, since it's documented as the content type.

  • UIProcess/API/glib/WebKitURISchemeRequest.cpp:

(webkitURISchemeRequestReadCallback):
(webkit_uri_scheme_request_finish):

  • UIProcess/API/gtk/WebKitURISchemeRequest.h:
  • UIProcess/API/wpe/WebKitURISchemeRequest.h:

Tools:

Add a test case.

  • TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebContext.cpp:

(testWebContextURIScheme):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r250898 r250899  
     12019-10-09  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        REGRESSION(r250597): [GTK][WPE] 2.27.1 shows HTML content as text/plain in custom protocols when passing a charset in content type
     4        https://bugs.webkit.org/show_bug.cgi?id=202633
     5
     6        Reviewed by Žan Doberšek.
     7
     8        This is a regression of the switch to use the new custom protocols implementation. Before r250597, we extracted
     9        the mime type and charset from content type in the network process, but we are now sending the response directly
     10        from the UI process, so we need to do that when building our response. Rename the mime_type parameter as
     11        content_type to avoid confusion, since it's documented as the content type.
     12
     13        * UIProcess/API/glib/WebKitURISchemeRequest.cpp:
     14        (webkitURISchemeRequestReadCallback):
     15        (webkit_uri_scheme_request_finish):
     16        * UIProcess/API/gtk/WebKitURISchemeRequest.h:
     17        * UIProcess/API/wpe/WebKitURISchemeRequest.h:
     18
    1192019-10-09  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitURISchemeRequest.cpp

    r250597 r250899  
    2828#include "WebPageProxy.h"
    2929#include <WebCore/GUniquePtrSoup.h>
     30#include <WebCore/HTTPParsers.h>
    3031#include <WebCore/ResourceError.h>
    3132#include <WebCore/URLSoup.h>
     
    7071    char readBuffer[gReadBufferSize];
    7172    uint64_t bytesRead;
    72     CString mimeType;
     73    CString contentType;
    7374};
    7475
     
    179180
    180181    if (!priv->bytesRead) {
    181         ResourceResponse response(priv->task->request().url(), String::fromUTF8(priv->mimeType.data()), priv->streamLength, emptyString());
     182        ResourceResponse response(priv->task->request().url(), extractMIMETypeFromMediaType(priv->contentType.data()), priv->streamLength, emptyString());
     183        response.setTextEncodingName(extractCharsetFromMediaType(priv->contentType.data()));
    182184        priv->task->didReceiveResponse(response);
    183185    }
     
    199201 * @stream: a #GInputStream to read the contents of the request
    200202 * @stream_length: the length of the stream or -1 if not known
    201  * @mime_type: (allow-none): the content type of the stream or %NULL if not known
     203 * @content_type: (allow-none): the content type of the stream or %NULL if not known
    202204 *
    203205 * Finish a #WebKitURISchemeRequest by setting the contents of the request and its mime type.
    204206 */
    205 void webkit_uri_scheme_request_finish(WebKitURISchemeRequest* request, GInputStream* inputStream, gint64 streamLength, const gchar* mimeType)
     207void webkit_uri_scheme_request_finish(WebKitURISchemeRequest* request, GInputStream* inputStream, gint64 streamLength, const gchar* contentType)
    206208{
    207209    g_return_if_fail(WEBKIT_IS_URI_SCHEME_REQUEST(request));
     
    214216    request->priv->cancellable = adoptGRef(g_cancellable_new());
    215217    request->priv->bytesRead = 0;
    216     request->priv->mimeType = mimeType;
     218    request->priv->contentType = contentType;
    217219    g_input_stream_read_async(inputStream, request->priv->readBuffer, gReadBufferSize, RunLoopSourcePriority::AsyncIONetwork, request->priv->cancellable.get(),
    218220        reinterpret_cast<GAsyncReadyCallback>(webkitURISchemeRequestReadCallback), g_object_ref(request));
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitURISchemeRequest.h

    r150130 r250899  
    7676                                        GInputStream           *stream,
    7777                                        gint64                  stream_length,
    78                                         const gchar            *mime_type);
     78                                        const gchar            *content_type);
    7979
    8080WEBKIT_API void
  • trunk/Source/WebKit/UIProcess/API/wpe/WebKitURISchemeRequest.h

    r218553 r250899  
    7777                                        GInputStream           *stream,
    7878                                        gint64                  stream_length,
    79                                         const gchar            *mime_type);
     79                                        const gchar            *content_type);
    8080
    8181WEBKIT_API void
  • trunk/Tools/ChangeLog

    r250887 r250899  
     12019-10-09  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        REGRESSION(r250597): [GTK][WPE] 2.27.1 shows HTML content as text/plain in custom protocols when passing a charset in content type
     4        https://bugs.webkit.org/show_bug.cgi?id=202633
     5
     6        Reviewed by Žan Doberšek.
     7
     8        Add a test case.
     9
     10        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebContext.cpp:
     11        (testWebContextURIScheme):
     12
    1132019-10-08  Jiewen Tan  <jiewen_tan@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebContext.cpp

    r250597 r250899  
    305305    test->waitUntilLoadFinished();
    306306    g_assert_true(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed));
     307
     308    static const char* charsetHTML = "<html><body><p id='emoji'>🙂</p></body></html>";
     309    test->registerURISchemeHandler("charset", charsetHTML, -1, "text/html; charset=\"UTF-8\"");
     310    test->loadURI("charset:test");
     311    test->waitUntilLoadFinished();
     312    mainResourceDataSize = 0;
     313    mainResourceData = test->mainResourceData(mainResourceDataSize);
     314    g_assert_cmpint(mainResourceDataSize, ==, strlen(charsetHTML));
     315    g_assert_cmpint(strncmp(mainResourceData, charsetHTML, mainResourceDataSize), ==, 0);
     316    GUniqueOutPtr<GError> error;
     317    auto* javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.getElementById('emoji').innerText", &error.outPtr());
     318    g_assert_nonnull(javascriptResult);
     319    g_assert_no_error(error.get());
     320    GUniquePtr<char> emoji(WebViewTest::javascriptResultToCString(javascriptResult));
     321    g_assert_cmpstr(emoji.get(), ==, "🙂");
    307322
    308323    test->registerURISchemeHandler("empty", nullptr, 0, "text/html");
Note: See TracChangeset for help on using the changeset viewer.