Skip to content

Commit

Permalink
Make topOrigin optional in URLKeepingBlobAlive
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=256499
rdar://problem/109067113

Reviewed by Chris Dumez.

The top origin SecurityOriginData is not always required for keeping a Blob
alive. In the case where the Blob URL is the Blob's internal URL, there is not
an associated top origin. Therefore, we only set the top origin for Blob URLs
that are created by script where the top origin is well defined.

* Source/WebCore/fileapi/Blob.cpp:
(WebCore::Blob::handle const):
* Source/WebCore/fileapi/URLKeepingBlobAlive.cpp:
(WebCore::URLKeepingBlobAlive::URLKeepingBlobAlive):
(WebCore::URLKeepingBlobAlive::clear):
(WebCore::URLKeepingBlobAlive::isolatedCopy const):
* Source/WebCore/fileapi/URLKeepingBlobAlive.h:
(WebCore::URLKeepingBlobAlive::topOrigin const):
* Source/WebCore/page/SecurityOriginData.h:
(WebCore::SecurityOriginDataMarkableTraits::isEmptyValue):
(WebCore::SecurityOriginDataMarkableTraits::emptyValue):

Canonical link: https://commits.webkit.org/265788@main
  • Loading branch information
sysrqb authored and Matthew Finkel committed Jul 6, 2023
1 parent 970cd63 commit 0e157e8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/fileapi/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ const char* Blob::activeDOMObjectName() const

URLKeepingBlobAlive Blob::handle() const
{
return { m_internalURL, m_topOrigin };
return { m_internalURL };
}

WebCoreOpaqueRoot root(Blob* blob)
Expand Down
7 changes: 4 additions & 3 deletions Source/WebCore/fileapi/URLKeepingBlobAlive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
#include "URLKeepingBlobAlive.h"

#include "ThreadableBlobRegistry.h"
#include <wtf/CrossThreadCopier.h>

namespace WebCore {

URLKeepingBlobAlive::URLKeepingBlobAlive(const URL& url, const SecurityOriginData& topOrigin)
URLKeepingBlobAlive::URLKeepingBlobAlive(const URL& url, const std::optional<SecurityOriginData>& topOrigin)
: m_url(url)
, m_topOrigin(topOrigin)
{
Expand All @@ -46,7 +47,7 @@ void URLKeepingBlobAlive::clear()
{
unregisterBlobURLHandleIfNecessary();
m_url = { };
m_topOrigin = { };
m_topOrigin = std::nullopt;
}

URLKeepingBlobAlive& URLKeepingBlobAlive::operator=(URLKeepingBlobAlive&& other)
Expand Down Expand Up @@ -74,7 +75,7 @@ void URLKeepingBlobAlive::unregisterBlobURLHandleIfNecessary()

URLKeepingBlobAlive URLKeepingBlobAlive::isolatedCopy() const
{
return { m_url.isolatedCopy(), m_topOrigin.isolatedCopy() };
return { m_url.isolatedCopy(), crossThreadCopy(m_topOrigin) };
}

} // namespace WebCore
6 changes: 3 additions & 3 deletions Source/WebCore/fileapi/URLKeepingBlobAlive.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace WebCore {
class URLKeepingBlobAlive {
public:
URLKeepingBlobAlive() = default;
URLKeepingBlobAlive(const URL&, const SecurityOriginData&);
URLKeepingBlobAlive(const URL&, const std::optional<SecurityOriginData>& = std::nullopt);
WEBCORE_EXPORT ~URLKeepingBlobAlive();

URLKeepingBlobAlive(URLKeepingBlobAlive&&) = default;
Expand All @@ -46,7 +46,7 @@ class URLKeepingBlobAlive {
operator const URL&() const { return m_url; }
const URL& url() const { return m_url; }
bool isEmpty() const { return m_url.isEmpty(); }
const SecurityOriginData& topOrigin() const { return m_topOrigin; }
std::optional<SecurityOriginData> topOrigin() const { return m_topOrigin; }

void clear();

Expand All @@ -58,7 +58,7 @@ class URLKeepingBlobAlive {
void unregisterBlobURLHandleIfNecessary();

URL m_url;
SecurityOriginData m_topOrigin;
Markable<SecurityOriginData, SecurityOriginDataMarkableTraits> m_topOrigin;
};

} // namespace WebCore
4 changes: 4 additions & 0 deletions Source/WebCore/page/SecurityOriginData.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ struct SecurityOriginDataHash {
static const bool safeToCompareToEmptyOrDeleted = false;
};

struct SecurityOriginDataMarkableTraits {
static bool isEmptyValue(const SecurityOriginData& value) { return value.isNull(); }
static SecurityOriginData emptyValue() { return { }; }
};
} // namespace WebCore

namespace WTF {
Expand Down

0 comments on commit 0e157e8

Please sign in to comment.