Title: [272138] trunk/Source/WebKit
Revision
272138
Author
[email protected]
Date
2021-02-01 02:29:36 -0800 (Mon, 01 Feb 2021)

Log 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:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (272137 => 272138)


--- trunk/Source/WebKit/ChangeLog	2021-02-01 10:28:32 UTC (rev 272137)
+++ trunk/Source/WebKit/ChangeLog	2021-02-01 10:29:36 UTC (rev 272138)
@@ -1,3 +1,23 @@
+2021-02-01  Carlos Garcia Campos  <[email protected]>
+
+        [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:
+
 2021-01-29  Darin Adler  <[email protected]>
 
         Check activeDocumentLoader() for null consistently everywhere

Modified: trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp (272137 => 272138)


--- trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2021-02-01 10:28:32 UTC (rev 272137)
+++ trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2021-02-01 10:29:36 UTC (rev 272138)
@@ -113,6 +113,9 @@
         return;
     }
 
+    if (m_currentRequest.url().protocolIsData())
+        return;
+
     if (!m_currentRequest.url().protocolIsInHTTPFamily()) {
         scheduleFailure(InvalidURLFailure);
         return;
@@ -191,6 +194,7 @@
 
     stopTimeout();
     m_pendingResult = nullptr;
+    m_pendingDataURLResult = WTF::nullopt;
     m_file = nullptr;
     m_inputStream = nullptr;
     m_multipartInputStream = nullptr;
@@ -241,6 +245,24 @@
         return;
     }
 
+    if (m_currentRequest.url().protocolIsData() && !m_cancellable) {
+        m_cancellable = adoptGRef(g_cancellable_new());
+        DataURLDecoder::decode(m_currentRequest.url(), { }, DataURLDecoder::Mode::Legacy, [this, protectedThis = WTFMove(protectedThis)](auto decodeResult) mutable {
+            if (m_state == State::Canceling || m_state == State::Completed || !m_client) {
+                clearRequest();
+                return;
+            }
+
+            if (m_state == State::Suspended) {
+                m_pendingDataURLResult = WTFMove(decodeResult);
+                return;
+            }
+
+            didReadDataURL(WTFMove(decodeResult));
+        });
+        return;
+    }
+
     if (m_pendingResult) {
         GRefPtr<GAsyncResult> pendingResult = WTFMove(m_pendingResult);
         if (m_inputStream)
@@ -257,7 +279,8 @@
                 readFileCallback(m_file.get(), pendingResult.get(), protectedThis.leakRef());
         } else
             ASSERT_NOT_REACHED();
-    }
+    } else if (m_currentRequest.url().protocolIsData())
+        didReadDataURL(WTFMove(m_pendingDataURLResult));
 }
 
 void NetworkDataTaskSoup::cancel()
@@ -1297,5 +1320,23 @@
     dispatchDidReceiveResponse();
 }
 
+void NetworkDataTaskSoup::didReadDataURL(Optional<DataURLDecoder::Result>&& result)
+{
+    if (g_cancellable_is_cancelled(m_cancellable.get())) {
+        didFail(cancelledError(m_currentRequest));
+        return;
+    }
+
+    if (!result) {
+        didFail(internalError(m_currentRequest.url()));
+        return;
+    }
+
+    m_response = ResourceResponse::dataURLResponse(m_currentRequest.url(), result.value());
+    auto bytes = SharedBuffer::create(WTFMove(result->data))->createGBytes();
+    m_inputStream = adoptGRef(g_memory_input_stream_new_from_bytes(bytes.get()));
+    dispatchDidReceiveResponse();
+}
+
 } // namespace WebKit
 

Modified: trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.h (272137 => 272138)


--- trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.h	2021-02-01 10:28:32 UTC (rev 272137)
+++ trunk/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.h	2021-02-01 10:29:36 UTC (rev 272138)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "NetworkDataTask.h"
+#include <WebCore/DataURLDecoder.h>
 #include <WebCore/FrameIdentifier.h>
 #include <WebCore/NetworkLoadMetrics.h>
 #include <WebCore/PageIdentifier.h>
@@ -142,6 +143,8 @@
     static void enumerateFileChildrenCallback(GFile*, GAsyncResult*, NetworkDataTaskSoup*);
     void didReadFile(GRefPtr<GInputStream>&&);
 
+    void didReadDataURL(Optional<WebCore::DataURLDecoder::Result>&&);
+
     WebCore::FrameIdentifier m_frameID;
     WebCore::PageIdentifier m_pageID;
     State m_state { State::Suspended };
@@ -152,6 +155,7 @@
     GRefPtr<SoupMultipartInputStream> m_multipartInputStream;
     GRefPtr<GCancellable> m_cancellable;
     GRefPtr<GAsyncResult> m_pendingResult;
+    Optional<WebCore::DataURLDecoder::Result> m_pendingDataURLResult;
     WebCore::ProtectionSpace m_protectionSpaceForPersistentStorage;
     WebCore::Credential m_credentialForPersistentStorage;
     WebCore::ResourceRequest m_currentRequest;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to