Skip to content
Permalink
Browse files
Add WTF::UUID class which is natively a 128-bit integer
https://bugs.webkit.org/show_bug.cgi?id=234571

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (Refactor, covered by existing tests)

* Modules/notifications/NotificationData.h:
(WebCore::NotificationData::decode):

Source/WebKit:

Notifications - which are UUID identified - are now addressed by a UUID object instead of a v4 UUID string.

* NetworkProcess/Notifications/NetworkNotificationManager.cpp:
(WebKit::NetworkNotificationManager::cancelNotification):
(WebKit::NetworkNotificationManager::clearNotifications):
(WebKit::NetworkNotificationManager::didDestroyNotification):
* NetworkProcess/Notifications/NetworkNotificationManager.h:

* Scripts/webkit/messages.py:
(forward_declarations_and_headers_for_replies):
(headers_for_type):

* Shared/Notifications/NotificationManagerMessageHandler.h:
* Shared/Notifications/NotificationManagerMessageHandler.messages.in:

* UIProcess/API/C/WKNotification.cpp:
(WKNotificationCopyCoreIDForTesting):
* UIProcess/API/C/WKNotification.h:

* UIProcess/API/C/WKNotificationManager.cpp:
(WKNotificationManagerProviderDidClickNotification_b):
* UIProcess/API/C/WKNotificationManager.h:

* UIProcess/Notifications/WebNotification.h:
(WebKit::WebNotification::coreNotificationID const):

* UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp:
(WebKit::WebNotificationManagerMessageHandler::cancelNotification):
(WebKit::WebNotificationManagerMessageHandler::clearNotifications):
(WebKit::WebNotificationManagerMessageHandler::didDestroyNotification):
* UIProcess/Notifications/WebNotificationManagerMessageHandler.h:

* UIProcess/Notifications/WebNotificationManagerProxy.cpp:
(WebKit::WebNotificationManagerProxy::cancel):
(WebKit::WebNotificationManagerProxy::didDestroyNotification):
(WebKit::pageIDsMatch):
(WebKit::pageAndNotificationIDsMatch):
(WebKit::WebNotificationManagerProxy::clearNotifications):
(WebKit::WebNotificationManagerProxy::providerDidClickNotification):
(WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
* UIProcess/Notifications/WebNotificationManagerProxy.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::cancelNotification):
(WebKit::WebPageProxy::clearNotifications):
(WebKit::WebPageProxy::didDestroyNotification):
* UIProcess/WebPageProxy.h:

* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
(WKBundleCopyWebNotificationID):
* WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:

* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::webNotificationID):
* WebProcess/InjectedBundle/InjectedBundle.h:

* WebProcess/Notifications/WebNotificationManager.cpp:
(WebKit::WebNotificationManager::didShowNotification):
(WebKit::WebNotificationManager::didClickNotification):
(WebKit::WebNotificationManager::didCloseNotifications):
* WebProcess/Notifications/WebNotificationManager.h:
* WebProcess/Notifications/WebNotificationManager.messages.in:

Source/WTF:

This patch adds a new WTF::UUID class.

For now, it is simply a wrapper around a 128-bit integer, and creating a new one primes that integer with
cryptographically random data.

It can be encoded/decoded as well as used as a HashKey.

And it will be a great utility to use as a unique object identifier for objects that logically exist
in multiple processes.

On that note, it also changes "UUIDIdentifier" to use this new UUID class instead of a v4 UUID string.

* wtf/Identified.h:
(WTF::UUIDIdentified::UUIDIdentified):

* wtf/UUID.cpp:
(WTF::UUID::UUID):
(WTF::UUID::toVector const):
(WTF::UUID::hash const):

* wtf/UUID.h:
(WTF::UUID::create):
(WTF::UUID::UUID):
(WTF::UUID::operator== const):
(WTF::UUID::data const):
(WTF::UUID::isHashTableDeletedValue const):
(WTF::UUIDHash::hash):
(WTF::UUIDHash::equal):
(WTF::HashTraits<UUID>::emptyValue):
(WTF::HashTraits<UUID>::constructDeletedValue):
(WTF::HashTraits<UUID>::isDeletedValue):
(WTF::UUID::encode const):
(WTF::UUID::decode):

Tools:

Notifications - which are UUID identified - are now addressed by a UUID object instead of a v4 UUID string.

The way our C-API vends that UUID object is through a data object, so change WKTR to account for that.

* WebKitTestRunner/DataFunctions.h: Copied from Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.h.
(WTR::dataValue):
(WTR::dataToUUID):
(WTR::uuidToData):

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::postSimulateWebNotificationClick):
(WTR::postPageMessage):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::simulateWebNotificationClick):
* WebKitTestRunner/TestController.h:

* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):

* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:

* WebKitTestRunner/WebNotificationProvider.cpp:
(WTR::WebNotificationProvider::showWebNotification):
(WTR::WebNotificationProvider::closeWebNotification):
(WTR::WebNotificationProvider::removeNotificationManager):
(WTR::WebNotificationProvider::simulateWebNotificationClick):
(WTR::WebNotificationProvider::reset):
* WebKitTestRunner/WebNotificationProvider.h:



Canonical link: https://commits.webkit.org/245547@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287412 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
beidson committed Dec 23, 2021
1 parent d7b41ac commit 1d870675f20530009e4052654f392239f2f68d17
Showing 40 changed files with 442 additions and 101 deletions.
@@ -1,3 +1,44 @@
2021-12-23 Brady Eidson <beidson@apple.com>

Add WTF::UUID class which is natively a 128-bit integer
https://bugs.webkit.org/show_bug.cgi?id=234571

Reviewed by Alex Christensen.

This patch adds a new WTF::UUID class.

For now, it is simply a wrapper around a 128-bit integer, and creating a new one primes that integer with
cryptographically random data.

It can be encoded/decoded as well as used as a HashKey.

And it will be a great utility to use as a unique object identifier for objects that logically exist
in multiple processes.

On that note, it also changes "UUIDIdentifier" to use this new UUID class instead of a v4 UUID string.

* wtf/Identified.h:
(WTF::UUIDIdentified::UUIDIdentified):

* wtf/UUID.cpp:
(WTF::UUID::UUID):
(WTF::UUID::toVector const):
(WTF::UUID::hash const):

* wtf/UUID.h:
(WTF::UUID::create):
(WTF::UUID::UUID):
(WTF::UUID::operator== const):
(WTF::UUID::data const):
(WTF::UUID::isHashTableDeletedValue const):
(WTF::UUIDHash::hash):
(WTF::UUIDHash::equal):
(WTF::HashTraits<UUID>::emptyValue):
(WTF::HashTraits<UUID>::constructDeletedValue):
(WTF::HashTraits<UUID>::isDeletedValue):
(WTF::UUID::encode const):
(WTF::UUID::decode):

2021-12-23 Sihui Liu <sihui_liu@apple.com>

Ensure file handles used in FileSystemAccess API are closed
@@ -106,22 +106,14 @@ class ThreadSafeIdentified : public IdentifiedBase<uint64_t, T> {
};

template <typename T>
class UUIDIdentified : public IdentifiedBase<String, T> {
class UUIDIdentified : public IdentifiedBase<UUID, T> {
protected:
UUIDIdentified()
: IdentifiedBase<String, T>(createCanonicalUUIDString())
: IdentifiedBase<UUID, T>(UUID::create())
{
}

UUIDIdentified(const UUIDIdentified& other)
: IdentifiedBase<String, T>(other.isolatedCopy())
{
}

explicit UUIDIdentified(const String& identifier)
: IdentifiedBase<String, T>(identifier.isolatedCopy())
{
}
UUIDIdentified(const UUIDIdentified&) = default;
};

} // namespace WTF
@@ -42,6 +42,17 @@

namespace WTF {

UUID::UUID()
{
static_assert(sizeof(m_data) == 16);
cryptographicallyRandomValues(reinterpret_cast<unsigned char*>(&m_data), 16);
}

unsigned UUID::hash() const
{
return StringHasher::hashMemory(reinterpret_cast<const unsigned char*>(&m_data), 16);
}

String createCanonicalUUIDString()
{
unsigned randomData[4];
@@ -30,12 +30,100 @@

#pragma once

#include <wtf/Int128.h>
#include <wtf/text/WTFString.h>

namespace WTF {

class StringView;

class UUID {
WTF_MAKE_FAST_ALLOCATED;
public:
static UUID create()
{
return UUID { };
}

explicit UUID(Span<const uint8_t, 16> span)
{
memcpy(&m_data, span.data(), 16);
}

explicit UUID(UInt128Impl&& data)
: m_data(data)
{
}

UUID(const UUID&) = default;

Span<const uint8_t, 16> toSpan() const
{
return Span<const uint8_t, 16> { reinterpret_cast<const uint8_t*>(&m_data), 16 };
}

UUID& operator=(const UUID&) = default;
bool operator==(const UUID& other) const { return m_data == other.m_data; }

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<UUID> decode(Decoder&);

explicit UUID(HashTableDeletedValueType)
: m_data(1)
{
}

explicit UUID(HashTableEmptyValueType)
: m_data(0)
{
}

bool isHashTableDeletedValue() const { return m_data == 1; }
WTF_EXPORT_PRIVATE unsigned hash() const;

private:
WTF_EXPORT_PRIVATE UUID();

UInt128Impl m_data;
};

struct UUIDHash {
static unsigned hash(const UUID& key) { return key.hash(); }
static bool equal(const UUID& a, const UUID& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};

template<> struct HashTraits<UUID> : GenericHashTraits<UUID> {
static UUID emptyValue() { return UUID { HashTableEmptyValue }; }
static void constructDeletedValue(UUID& slot) { slot = UUID { HashTableDeletedValue }; }
static bool isDeletedValue(const UUID& value) { return value.isHashTableDeletedValue(); }
};
template<> struct DefaultHash<UUID> : UUIDHash { };

template<class Encoder>
void UUID::encode(Encoder& encoder) const
{
encoder << UInt128High64(m_data) << UInt128Low64(m_data);
}

template<class Decoder>
std::optional<UUID> UUID::decode(Decoder& decoder)
{
std::optional<uint64_t> high;
decoder >> high;
if (!high)
return std::nullopt;

std::optional<uint64_t> low;
decoder >> low;
if (!low)
return std::nullopt;

return { UUID {
MakeUInt128(*high, *low),
} };
}

// Creates a UUID that consists of 32 hexadecimal digits and returns its canonical form.
// The canonical form is displayed in 5 groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters.
// The hexadecimal values "a" through "f" are output as lower case characters.
@@ -52,5 +140,6 @@ WTF_EXPORT_PRIVATE bool isVersion4UUID(StringView);

}

using WTF::UUID;
using WTF::createCanonicalUUIDString;
using WTF::bootSessionUUIDString;
@@ -1,3 +1,15 @@
2021-12-23 Brady Eidson <beidson@apple.com>

Add WTF::UUID class which is natively a 128-bit integer
https://bugs.webkit.org/show_bug.cgi?id=234571

Reviewed by Alex Christensen.

No new tests (Refactor, covered by existing tests)

* Modules/notifications/NotificationData.h:
(WebCore::NotificationData::decode):

2021-12-23 Sam Weinig <weinig@apple.com>

Encapsulate gradient color stops into a self contained class
@@ -26,6 +26,7 @@
#pragma once

#include <optional>
#include <wtf/UUID.h>
#include <wtf/text/WTFString.h>

namespace WebCore {
@@ -43,7 +44,7 @@ struct NotificationData {
String language;
WebCore::NotificationDirection direction;
String originString;
String notificationID;
UUID notificationID;
};

template<class Encoder>
@@ -90,7 +91,7 @@ std::optional<NotificationData> NotificationData::decode(Decoder& decoder)
if (!originString)
return std::nullopt;

std::optional<String> notificationID;
std::optional<UUID> notificationID;
decoder >> notificationID;
if (!notificationID)
return std::nullopt;
@@ -1,3 +1,73 @@
2021-12-23 Brady Eidson <beidson@apple.com>

Add WTF::UUID class which is natively a 128-bit integer
https://bugs.webkit.org/show_bug.cgi?id=234571

Reviewed by Alex Christensen.

Notifications - which are UUID identified - are now addressed by a UUID object instead of a v4 UUID string.

* NetworkProcess/Notifications/NetworkNotificationManager.cpp:
(WebKit::NetworkNotificationManager::cancelNotification):
(WebKit::NetworkNotificationManager::clearNotifications):
(WebKit::NetworkNotificationManager::didDestroyNotification):
* NetworkProcess/Notifications/NetworkNotificationManager.h:

* Scripts/webkit/messages.py:
(forward_declarations_and_headers_for_replies):
(headers_for_type):

* Shared/Notifications/NotificationManagerMessageHandler.h:
* Shared/Notifications/NotificationManagerMessageHandler.messages.in:

* UIProcess/API/C/WKNotification.cpp:
(WKNotificationCopyCoreIDForTesting):
* UIProcess/API/C/WKNotification.h:

* UIProcess/API/C/WKNotificationManager.cpp:
(WKNotificationManagerProviderDidClickNotification_b):
* UIProcess/API/C/WKNotificationManager.h:

* UIProcess/Notifications/WebNotification.h:
(WebKit::WebNotification::coreNotificationID const):

* UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp:
(WebKit::WebNotificationManagerMessageHandler::cancelNotification):
(WebKit::WebNotificationManagerMessageHandler::clearNotifications):
(WebKit::WebNotificationManagerMessageHandler::didDestroyNotification):
* UIProcess/Notifications/WebNotificationManagerMessageHandler.h:

* UIProcess/Notifications/WebNotificationManagerProxy.cpp:
(WebKit::WebNotificationManagerProxy::cancel):
(WebKit::WebNotificationManagerProxy::didDestroyNotification):
(WebKit::pageIDsMatch):
(WebKit::pageAndNotificationIDsMatch):
(WebKit::WebNotificationManagerProxy::clearNotifications):
(WebKit::WebNotificationManagerProxy::providerDidClickNotification):
(WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
* UIProcess/Notifications/WebNotificationManagerProxy.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::cancelNotification):
(WebKit::WebPageProxy::clearNotifications):
(WebKit::WebPageProxy::didDestroyNotification):
* UIProcess/WebPageProxy.h:

* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
(WKBundleCopyWebNotificationID):
* WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:

* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::webNotificationID):
* WebProcess/InjectedBundle/InjectedBundle.h:

* WebProcess/Notifications/WebNotificationManager.cpp:
(WebKit::WebNotificationManager::didShowNotification):
(WebKit::WebNotificationManager::didClickNotification):
(WebKit::WebNotificationManager::didCloseNotifications):
* WebProcess/Notifications/WebNotificationManager.h:
* WebProcess/Notifications/WebNotificationManager.messages.in:

2021-12-23 Sihui Liu <sihui_liu@apple.com>

Ensure file handles used in FileSystemAccess API are closed
@@ -114,19 +114,19 @@ void NetworkNotificationManager::showNotification(const WebCore::NotificationDat
// sendMessageWithReply<WebPushD::MessageType::EchoTwice>(WTFMove(completionHandler), String("FIXME: Do useful work here"));
}

void NetworkNotificationManager::cancelNotification(const String&)
void NetworkNotificationManager::cancelNotification(const UUID&)
{
if (!m_connection)
return;
}

void NetworkNotificationManager::clearNotifications(const Vector<String>&)
void NetworkNotificationManager::clearNotifications(const Vector<UUID>&)
{
if (!m_connection)
return;
}

void NetworkNotificationManager::didDestroyNotification(const String&)
void NetworkNotificationManager::didDestroyNotification(const UUID&)
{
if (!m_connection)
return;
@@ -60,9 +60,9 @@ class NetworkNotificationManager : public NotificationManagerMessageHandler {

void requestSystemNotificationPermission(const String& originString, CompletionHandler<void(bool)>&&) final;
void showNotification(const WebCore::NotificationData&) final;
void cancelNotification(const String& notificationID) final;
void clearNotifications(const Vector<String>& notificationIDs) final;
void didDestroyNotification(const String& notificationID) final;
void cancelNotification(const UUID& notificationID) final;
void clearNotifications(const Vector<UUID>& notificationIDs) final;
void didDestroyNotification(const UUID& notificationID) final;

void maybeSendConnectionConfiguration() const;

@@ -457,6 +457,7 @@ def forward_declarations_and_headers_for_replies(receiver):
'MachSendRight',
'MediaTime',
'String',
'UUID',
])

no_forward_declaration_types = types_that_cannot_be_forward_declared()
@@ -751,6 +752,7 @@ def headers_for_type(type):
'Seconds': ['<wtf/Seconds.h>'],
'String': ['<wtf/text/WTFString.h>'],
'URL': ['<wtf/URLHash.h>'],
'UUID': ['<wtf/UUID.h>'],
'WallTime': ['<wtf/WallTime.h>'],
'WebCore::ArcData': ['<WebCore/InlinePathData.h>'],
'WebCore::AutoplayEventFlags': ['<WebCore/AutoplayEvent.h>'],
@@ -28,6 +28,7 @@
#include "MessageReceiver.h"
#include "WebPageProxyIdentifier.h"
#include <WebCore/NotificationDirection.h>
#include <wtf/UUID.h>

namespace WebCore {
struct NotificationData;
@@ -41,9 +42,9 @@ class NotificationManagerMessageHandler : public IPC::MessageReceiver {

virtual void requestSystemNotificationPermission(const String& securityOrigin, CompletionHandler<void(bool)>&&) = 0;
virtual void showNotification(const WebCore::NotificationData&) = 0;
virtual void cancelNotification(const String& notificationID) = 0;
virtual void clearNotifications(const Vector<String>& notificationIDs) = 0;
virtual void didDestroyNotification(const String& notificationID) = 0;
virtual void cancelNotification(const UUID& notificationID) = 0;
virtual void clearNotifications(const Vector<UUID>& notificationIDs) = 0;
virtual void didDestroyNotification(const UUID& notificationID) = 0;

private:
// IPC::MessageReceiver
@@ -23,7 +23,7 @@
messages -> NotificationManagerMessageHandler NotRefCounted {
RequestSystemNotificationPermission(String originIdentifier) -> (bool allowed) Async
ShowNotification(struct WebCore::NotificationData notificationData)
CancelNotification(String notificationID)
ClearNotifications(Vector<String> notificationIDs)
DidDestroyNotification(String notificationID)
CancelNotification(UUID notificationID)
ClearNotifications(Vector<UUID> notificationIDs)
DidDestroyNotification(UUID notificationID)
}

0 comments on commit 1d87067

Please sign in to comment.