⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 272138 in webkit


Ignore:
Timestamp:
Feb 1, 2021, 2:29:36 AM (6 years ago)
Author:
Carlos Garcia Campos
Message:

[SOUP] Add support for data URLs in the network process
​https://bugs.webkit.org/show_bug.cgi?id=221127

Reviewed by Adrian Perez de Castro.

In r271879 I removed the support for data URLs in the network process for soup, assuming data URLs were always
loaded from the web process, but that's not the case for downloads. I think we should not go to the network
process for downloads either, but for now it's easier to fix this regression by supporting data URLs in the
network process again. Fixes http/tests/security/anchor-download-allow-data.html.

  • NetworkProcess/soup/NetworkDataTaskSoup.cpp:

(WebKit::NetworkDataTaskSoup::createRequest): Return early if it's a data URL.
(WebKit::NetworkDataTaskSoup::clearRequest): Clear the pending data URL result.
(WebKit::NetworkDataTaskSoup::resume): Start a data URL decode task if it's a new data URL request, or complete
the pending one.
(WebKit::NetworkDataTaskSoup::didReadDataURL): Complete the data URL request.

  • NetworkProcess/soup/NetworkDataTaskSoup.h:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r272122 r272138  
     12021-02-01  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Add support for data URLs in the network process
     4        https://bugs.webkit.org/show_bug.cgi?id=221127
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        In r271879 I removed the support for data URLs in the network process for soup, assuming data URLs were always
     9        loaded from the web process, but that's not the case for downloads. I think we should not go to the network
     10        process for downloads either, but for now it's easier to fix this regression by supporting data URLs in the
     11        network process again. Fixes http/tests/security/anchor-download-allow-data.html.
     12
     13        * NetworkProcess/soup/NetworkDataTaskSoup.cpp:
     14        (WebKit::NetworkDataTaskSoup::createRequest): Return early if it's a data URL.
     15        (WebKit::NetworkDataTaskSoup::clearRequest): Clear the pending data URL result.
     16        (WebKit::NetworkDataTaskSoup::resume): Start a data URL decode task if it's a new data URL request, or complete
     17        the pending one.
     18        (WebKit::NetworkDataTaskSoup::didReadDataURL): Complete the data URL request.
     19        * NetworkProcess/soup/NetworkDataTaskSoup.h:
     20
    1212021-01-29  Darin Adler  <darin@apple.com>
    222
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp

    r272010 r272138  
    114114    }
    115115
     116    if (m_currentRequest.url().protocolIsData())
     117        return;
     118
    116119    if (!m_currentRequest.url().protocolIsInHTTPFamily()) {
    117120        scheduleFailure(InvalidURLFailure);
    … …  
    192195    stopTimeout();
    193196    m_pendingResult = nullptr;
     197    m_pendingDataURLResult = WTF::nullopt;
    194198    m_file = nullptr;
    195199    m_inputStream = nullptr;
    … …  
    239243        g_file_query_info_async(m_file.get(), G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE,
    240244            G_FILE_QUERY_INFO_NONE, RunLoopSourcePriority::AsyncIONetwork, m_cancellable.get(), reinterpret_cast<GAsyncReadyCallback>(fileQueryInfoCallback), protectedThis.leakRef());
     245        return;
     246    }
     247
     248    if (m_currentRequest.url().protocolIsData() && !m_cancellable) {
     249        m_cancellable = adoptGRef(g_cancellable_new());
     250        DataURLDecoder::decode(m_currentRequest.url(), { }, DataURLDecoder::Mode::Legacy, [this, protectedThis = WTFMove(protectedThis)](auto decodeResult) mutable {
     251            if (m_state == State::Canceling || m_state == State::Completed || !m_client) {
     252                clearRequest();
     253                return;
     254            }
     255
     256            if (m_state == State::Suspended) {
     257                m_pendingDataURLResult = WTFMove(decodeResult);
     258                return;
     259            }
     260
     261            didReadDataURL(WTFMove(decodeResult));
     262        });
    241263        return;
    242264    }
    … …  
    258280        } else
    259281            ASSERT_NOT_REACHED();
    260     }
     282    } else if (m_currentRequest.url().protocolIsData())
     283        didReadDataURL(WTFMove(m_pendingDataURLResult));
    261284}
    262285
    … …  
    12981321}
    12991322
     1323void NetworkDataTaskSoup::didReadDataURL(Optional<DataURLDecoder::Result>&& result)
     1324{
     1325    if (g_cancellable_is_cancelled(m_cancellable.get())) {
     1326        didFail(cancelledError(m_currentRequest));
     1327        return;
     1328    }
     1329
     1330    if (!result) {
     1331        didFail(internalError(m_currentRequest.url()));
     1332        return;
     1333    }
     1334
     1335    m_response = ResourceResponse::dataURLResponse(m_currentRequest.url(), result.value());
     1336    auto bytes = SharedBuffer::create(WTFMove(result->data))->createGBytes();
     1337    m_inputStream = adoptGRef(g_memory_input_stream_new_from_bytes(bytes.get()));
     1338    dispatchDidReceiveResponse();
     1339}
     1340
    13001341} // namespace WebKit
    13011342
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.h

    r272010 r272138  
    2727
    2828#include "NetworkDataTask.h"
     29#include <WebCore/DataURLDecoder.h>
    2930#include <WebCore/FrameIdentifier.h>
    3031#include <WebCore/NetworkLoadMetrics.h>
    … …  
    143144    void didReadFile(GRefPtr<GInputStream>&&);
    144145
     146    void didReadDataURL(Optional<WebCore::DataURLDecoder::Result>&&);
     147
    145148    WebCore::FrameIdentifier m_frameID;
    146149    WebCore::PageIdentifier m_pageID;
    … …  
    153156    GRefPtr<GCancellable> m_cancellable;
    154157    GRefPtr<GAsyncResult> m_pendingResult;
     158    Optional<WebCore::DataURLDecoder::Result> m_pendingDataURLResult;
    155159    WebCore::ProtectionSpace m_protectionSpaceForPersistentStorage;
    156160    WebCore::Credential m_credentialForPersistentStorage;
Note: See TracChangeset for help on using the changeset viewer.