Skip to content

Commit

Permalink
Use UUID::createVersion4Weak for Document constructor
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267897
rdar://121405807

Reviewed by Ryosuke Niwa.

We do not need cryptographically random values here. Use UUID::createVersion4Weak.

* Source/WTF/wtf/UUID.cpp:
(WTF::createVersion4UUIDString):
* Source/WTF/wtf/UUID.h:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::originIdentifierForPasteboard const):
(WebCore::Document::didInsertAttachmentElement):
* Source/WebCore/platform/ScriptExecutionContextIdentifier.h:
(WebCore::ProcessQualified<WTF::UUID>::generate):

Canonical link: https://commits.webkit.org/273344@main
  • Loading branch information
Constellation committed Jan 23, 2024
1 parent 0ec51a7 commit bf3c42a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Source/WTF/wtf/UUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ String createVersion4UUIDString()
return makeString(UUID::createVersion4());
}

String createVersion4UUIDStringWeak()
{
return makeString(UUID::createVersion4Weak());
}

String bootSessionUUIDString()
{
#if OS(DARWIN)
Expand Down
2 changes: 2 additions & 0 deletions Source/WTF/wtf/UUID.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ template<> struct DefaultHash<UUID> : UUIDHash { };
// 9, A, or B for y.

WTF_EXPORT_PRIVATE String createVersion4UUIDString();
WTF_EXPORT_PRIVATE String createVersion4UUIDStringWeak();

WTF_EXPORT_PRIVATE String bootSessionUUIDString();
WTF_EXPORT_PRIVATE bool isVersion4UUID(StringView);
Expand Down Expand Up @@ -210,4 +211,5 @@ class StringTypeAdapter<UUID> {
}

using WTF::createVersion4UUIDString;
using WTF::createVersion4UUIDStringWeak;
using WTF::bootSessionUUIDString;
4 changes: 2 additions & 2 deletions Source/WebCore/dom/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7182,7 +7182,7 @@ String Document::originIdentifierForPasteboard() const
if (origin != "null"_s)
return origin;
if (!m_uniqueIdentifier)
m_uniqueIdentifier = makeString("null:"_s, WTF::UUID::createVersion4());
m_uniqueIdentifier = makeString("null:"_s, WTF::UUID::createVersion4Weak());
return m_uniqueIdentifier;
}

Expand Down Expand Up @@ -9653,7 +9653,7 @@ void Document::didInsertAttachmentElement(HTMLAttachmentElement& attachment)
bool previousIdentifierIsNotUnique = !previousIdentifier.isEmpty() && m_attachmentIdentifierToElementMap.contains(previousIdentifier);
if (identifier.isEmpty() || previousIdentifierIsNotUnique) {
previousIdentifier = identifier;
identifier = createVersion4UUIDString();
identifier = createVersion4UUIDStringWeak();
attachment.setUniqueIdentifier(identifier);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/ScriptExecutionContextIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace WebCore {
template <>
class ProcessQualified<WTF::UUID> {
public:
static ProcessQualified generate() { return { WTF::UUID::createVersion4(), Process::identifier() }; }
static ProcessQualified generate() { return { WTF::UUID::createVersion4Weak(), Process::identifier() }; }

ProcessQualified()
: m_object(WTF::UUID::emptyValue)
Expand Down

0 comments on commit bf3c42a

Please sign in to comment.