Skip to content

Commit

Permalink
Apply patch. rdar://124939608
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Robson committed Apr 9, 2024
1 parent 9192181 commit 726257d
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 4 deletions.
4 changes: 4 additions & 0 deletions LayoutTests/http/tests/media/video-src-mp4-blob-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

EVENT(loadedmetadata)
END OF TEST

21 changes: 21 additions & 0 deletions LayoutTests/http/tests/media/video-src-mp4-blob.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<script src=../../media-resources/video-test.js></script>
<script>
async function runTest() {
findMediaElement();
const file = "white.mp4"
const resp = await fetch(file);
const blob = await resp.blob();
const blobUrl = URL.createObjectURL(blob);
waitForEventAndEnd('loadedmetadata');
waitForEventAndFail('error');
video.src = blobUrl;
}
</script>
</head>
<body onload="runTest()">
<video></video>
</body>
</html>
4 changes: 4 additions & 0 deletions LayoutTests/http/tests/media/video-src-webm-blob-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

EVENT(loadedmetadata)
END OF TEST

21 changes: 21 additions & 0 deletions LayoutTests/http/tests/media/video-src-webm-blob.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<script src=../../media-resources/video-test.js></script>
<script>
async function runTest() {
findMediaElement();
const file = "white.webm"
const resp = await fetch(file);
const blob = await resp.blob();
const blobUrl = URL.createObjectURL(blob);
waitForEventAndEnd('loadedmetadata');
waitForEventAndFail('error');
video.src = blobUrl;
}
</script>
</head>
<body onload="runTest()">
<video></video>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

EVENT(loadedmetadata)
END OF TEST

20 changes: 20 additions & 0 deletions LayoutTests/http/tests/media/video-srcobject-webm-blob.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<script src=../../media-resources/video-test.js></script>
<script>
async function runTest() {
findMediaElement();
const file = "white.webm"
const resp = await fetch(file);
const blob = await resp.blob();
waitForEventAndEnd('loadedmetadata');
waitForEventAndFail('error');
video.srcObject = blob;
}
</script>
</head>
<body onload="runTest()">
<video></video>
</body>
</html>
Binary file modified LayoutTests/http/tests/media/white.webm
Binary file not shown.
2 changes: 2 additions & 0 deletions LayoutTests/platform/mac-wk1/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@ media/now-playing-status-without-media.html [ Skip ]
# WebM not supported in WK1 on macOS.
http/tests/media/cross-origin-webm-video.html [ Skip ]
http/tests/media/video-webm-stall.html
http/tests/media/video-src-webm-blob.html [ Failure ]
http/tests/media/video-srcobject-webm-blob.html [ Failure ]
media/W3C/video/canPlayType/canPlayType_codecs_order_1.html [ Failure ]
media/W3C/video/canPlayType/canPlayType_supported_but_no_codecs_parameter_1.html [ Failure ]
media/W3C/video/canPlayType/canPlayType_two_implies_one_1.html [ Failure ]
Expand Down
13 changes: 13 additions & 0 deletions Source/WebCore/fileapi/ThreadableBlobRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ void ThreadableBlobRegistry::registerInternalBlobURLForSlice(const URL& newURL,
});
}

String ThreadableBlobRegistry::blobType(const URL& url)
{
if (isMainThread())
return blobRegistry().blobType(url);

String result;
callOnMainThreadAndWait([url = url.isolatedCopy(), &result] {
result = blobRegistry().blobType(url).isolatedCopy();
});
return result;

}

unsigned long long ThreadableBlobRegistry::blobSize(const URL& url)
{
if (isMainThread())
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/fileapi/ThreadableBlobRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ThreadableBlobRegistry {
static void registerBlobURLHandle(const URL&, const std::optional<SecurityOriginData>& topOrigin);
static void unregisterBlobURLHandle(const URL&, const std::optional<SecurityOriginData>& topOrigin);

WEBCORE_EXPORT static String blobType(const URL&);
WEBCORE_EXPORT static unsigned long long blobSize(const URL&);

// Returns the origin for the given blob URL. This is because we are not able to embed the unique security origin or the origin of file URL
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ void HTMLMediaElement::loadNextSourceChild()
loadResource(mediaURL, contentType, keySystem);
}

void HTMLMediaElement::loadResource(const URL& initialURL, ContentType& contentType, const String& keySystem)
void HTMLMediaElement::loadResource(const URL& initialURL, const ContentType& contentType, const String& keySystem)
{
ASSERT(initialURL.isEmpty() || isSafeToLoadURL(initialURL, Complain));

Expand Down Expand Up @@ -1684,11 +1684,11 @@ void HTMLMediaElement::loadResource(const URL& initialURL, ContentType& contentT
m_blobURLForReading = { BlobURL::createPublicURL(&document().securityOrigin()), document().topOrigin().data() };
ThreadableBlobRegistry::registerBlobURL(&document().securityOrigin(), document().policyContainer(), m_blobURLForReading, m_blob->url());

if (!m_player->load(m_blobURLForReading, contentType, keySystem, !!m_remotePlaybackConfiguration))
if (!m_player->load(m_blobURLForReading, contentType.isEmpty() ? ContentType { m_blob->type() } : contentType, keySystem, !!m_remotePlaybackConfiguration))
mediaLoadingFailed(MediaPlayer::NetworkState::FormatError);
}

if (!loadAttempted && !m_player->load(url, contentType, keySystem, !!m_remotePlaybackConfiguration))
if (!loadAttempted && !m_player->load(url, url.protocolIsBlob() && contentType.isEmpty() ? ContentType { ThreadableBlobRegistry::blobType(url) } : contentType, keySystem, !!m_remotePlaybackConfiguration))
mediaLoadingFailed(MediaPlayer::NetworkState::FormatError);

mediaPlayerRenderingModeChanged();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ class HTMLMediaElement
virtual void scheduleResizeEventIfSizeChanged(const FloatSize&) { }

void selectMediaResource();
void loadResource(const URL&, ContentType&, const String& keySystem);
void loadResource(const URL&, const ContentType&, const String& keySystem);
void scheduleNextSourceChild();
void loadNextSourceChild();
void userCancelledLoad();
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/network/BlobRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class WEBCORE_EXPORT BlobRegistry {
virtual void registerBlobURLHandle(const URL&, const std::optional<SecurityOriginData>& topOrigin) = 0;
virtual void unregisterBlobURLHandle(const URL&, const std::optional<SecurityOriginData>& topOrigin) = 0;

virtual String blobType(const URL&) = 0;

virtual unsigned long long blobSize(const URL&) = 0;

virtual void writeBlobsToTemporaryFilesForIndexedDB(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&) = 0;
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/platform/network/BlobRegistryImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ BlobData* BlobRegistryImpl::getBlobDataFromURL(const URL& url, const std::option
return blobData;
}

String BlobRegistryImpl::blobType(const URL& url)
{
ASSERT(isMainThread());
if (RefPtr data = getBlobDataFromURL(url))
return data->contentType();
return emptyString();
}

unsigned long long BlobRegistryImpl::blobSize(const URL& url)
{
ASSERT(isMainThread());
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/network/BlobRegistryImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class WEBCORE_EXPORT BlobRegistryImpl {
void registerBlobURLHandle(const URL&, const std::optional<WebCore::SecurityOriginData>& topOrigin);
void unregisterBlobURLHandle(const URL&, const std::optional<WebCore::SecurityOriginData>& topOrigin);

String blobType(const URL&);
unsigned long long blobSize(const URL&);

void writeBlobsToTemporaryFilesForIndexedDB(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,12 @@ void NetworkConnectionToWebProcess::unregisterBlobURLHandle(const URL& url, cons
session->blobRegistry().unregisterBlobURLHandle(url, topOrigin);
}

void NetworkConnectionToWebProcess::blobType(const URL& url, CompletionHandler<void(String)>&& completionHandler)
{
auto* session = networkSession();
completionHandler(session ? session->blobRegistry().blobType(url) : emptyString());
}

void NetworkConnectionToWebProcess::blobSize(const URL& url, CompletionHandler<void(uint64_t)>&& completionHandler)
{
auto* session = networkSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class NetworkConnectionToWebProcess
void registerBlobURL(const URL&, const URL& srcURL, WebCore::PolicyContainer&&, const std::optional<WebCore::SecurityOriginData>& topOrigin);
void registerInternalBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, const String& fileBackedPath, const String& contentType);
void registerInternalBlobURLForSlice(const URL&, const URL& srcURL, int64_t start, int64_t end, const String& contentType);
void blobType(const URL&, CompletionHandler<void(String)>&&);
void blobSize(const URL&, CompletionHandler<void(uint64_t)>&&);
void unregisterBlobURL(const URL&, const std::optional<WebCore::SecurityOriginData>& topOrigin);
void writeBlobsToTemporaryFilesForIndexedDB(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
RegisterInternalBlobURLOptionallyFileBacked(URL url, URL srcURL, String fileBackedPath, String contentType)
RegisterInternalBlobURLForSlice(URL url, URL srcURL, int64_t start, int64_t end, String contentType)
UnregisterBlobURL(URL url, std::optional<WebCore::SecurityOriginData> topOrigin)
BlobType(URL url) -> (String result) Synchronous
BlobSize(URL url) -> (uint64_t resultSize) Synchronous
WriteBlobsToTemporaryFilesForIndexedDB(Vector<String> blobURLs) -> (Vector<String> fileNames)
RegisterBlobURLHandle(URL url, std::optional<WebCore::SecurityOriginData> topOrigin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ BlobRegistry* NetworkProcessPlatformStrategies::createBlobRegistry()
void registerInternalBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, RefPtr<BlobDataFileReference>&&, const String& contentType) final { ASSERT_NOT_REACHED(); }
void registerInternalBlobURLForSlice(const URL&, const URL& srcURL, long long start, long long end, const String& contentType) final { ASSERT_NOT_REACHED(); }
void unregisterBlobURL(const URL&, const std::optional<WebCore::SecurityOriginData>&) final { ASSERT_NOT_REACHED(); }
String blobType(const URL&) final { ASSERT_NOT_REACHED(); return emptyString(); }
unsigned long long blobSize(const URL&) final { ASSERT_NOT_REACHED(); return 0; }
void writeBlobsToTemporaryFilesForIndexedDB(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&) final { ASSERT_NOT_REACHED(); }
void registerBlobURLHandle(const URL&, const std::optional<WebCore::SecurityOriginData>&) final { ASSERT_NOT_REACHED(); }
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/WebProcess/FileAPI/BlobRegistryProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ void BlobRegistryProxy::unregisterBlobURLHandle(const URL& url, const std::optio
WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::UnregisterBlobURLHandle(url, topOrigin), 0);
}

String BlobRegistryProxy::blobType(const URL& url)
{
auto sendResult = WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::BlobType(url), 0);
auto [result] = sendResult.takeReplyOr(emptyString());
return result;
}

unsigned long long BlobRegistryProxy::blobSize(const URL& url)
{
auto sendResult = WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::BlobSize(url), 0);
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/WebProcess/FileAPI/BlobRegistryProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class BlobRegistryProxy final : public WebCore::BlobRegistry {
void registerInternalBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, RefPtr<WebCore::BlobDataFileReference>&&, const String& contentType) final;
void unregisterBlobURL(const URL&, const std::optional<WebCore::SecurityOriginData>& topOrigin) final;
void registerInternalBlobURLForSlice(const URL&, const URL& srcURL, long long start, long long end, const String& contentType) final;
String blobType(const URL&) final;
unsigned long long blobSize(const URL&) final;
void writeBlobsToTemporaryFilesForIndexedDB(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&) final;
void registerBlobURLHandle(const URL&, const std::optional<WebCore::SecurityOriginData>& topOrigin) final;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
void registerInternalBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, RefPtr<BlobDataFileReference>&& reference, const String& contentType) final { m_blobRegistry.registerInternalBlobURLOptionallyFileBacked(url, srcURL, WTFMove(reference), contentType, { }); }
void registerInternalBlobURLForSlice(const URL& url, const URL& srcURL, long long start, long long end, const String& contentType) final { m_blobRegistry.registerInternalBlobURLForSlice(url, srcURL, start, end, contentType); }
void unregisterBlobURL(const URL& url, const std::optional<WebCore::SecurityOriginData>& topOrigin) final { m_blobRegistry.unregisterBlobURL(url, topOrigin); }
String blobType(const URL& url) final { return m_blobRegistry.blobType(url); }
unsigned long long blobSize(const URL& url) final { return m_blobRegistry.blobSize(url); }
void writeBlobsToTemporaryFilesForIndexedDB(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&& completionHandler) final { m_blobRegistry.writeBlobsToTemporaryFilesForIndexedDB(blobURLs, WTFMove(completionHandler)); }
void registerBlobURLHandle(const URL& url, const std::optional<SecurityOriginData>& topOrigin) final { m_blobRegistry.registerBlobURLHandle(url, topOrigin); }
Expand Down

0 comments on commit 726257d

Please sign in to comment.