Source/WTF/ChangeLog

 12021-12-22 Brady Eidson <beidson@apple.com>
 2
 3 Add WTF::UUID class which is natively a 128-bit integer
 4 https://bugs.webkit.org/show_bug.cgi?id=234571
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This patch adds a new WTF::UUID class.
 9
 10 For now, it is simply a wrapper around a 128-bit integer, and creating a new one primes that integer with
 11 cryptographically random data.
 12
 13 It can be encoded/decoded as well as used as a HashKey.
 14
 15 And it will be a great utility to use as a unique object identifier for objects that logically exist
 16 in multiple processes.
 17
 18 On that note, it also changes "UUIDIdentifier" to use this new UUID class instead of a v4 UUID string.
 19
 20 * wtf/Identified.h:
 21 (WTF::UUIDIdentified::UUIDIdentified):
 22
 23 * wtf/UUID.cpp:
 24 (WTF::UUID::UUID):
 25 (WTF::UUID::toVector const):
 26 (WTF::UUID::hash const):
 27
 28 * wtf/UUID.h:
 29 (WTF::UUID::create):
 30 (WTF::UUID::UUID):
 31 (WTF::UUID::operator== const):
 32 (WTF::UUID::data const):
 33 (WTF::UUID::isHashTableDeletedValue const):
 34 (WTF::UUIDHash::hash):
 35 (WTF::UUIDHash::equal):
 36 (WTF::HashTraits<UUID>::emptyValue):
 37 (WTF::HashTraits<UUID>::constructDeletedValue):
 38 (WTF::HashTraits<UUID>::isDeletedValue):
 39 (WTF::UUID::encode const):
 40 (WTF::UUID::decode):
 41
1422021-12-21 Brady Eidson <beidson@apple.com>
243
344 Make Notification identifiers be a UUID string instead of a uint64_t

Source/WTF/wtf/Identified.h

@@private:
106106};
107107
108108template <typename T>
109 class UUIDIdentified : public IdentifiedBase<String, T> {
 109class UUIDIdentified : public IdentifiedBase<UUID, T> {
110110protected:
111111 UUIDIdentified()
112  : IdentifiedBase<String, T>(createCanonicalUUIDString())
 112 : IdentifiedBase<UUID, T>(UUID::create())
113113 {
114114 }
115115
116  UUIDIdentified(const UUIDIdentified& other)
117  : IdentifiedBase<String, T>(other.isolatedCopy())
118  {
119  }
120 
121  explicit UUIDIdentified(const String& identifier)
122  : IdentifiedBase<String, T>(identifier.isolatedCopy())
123  {
124  }
 116 UUIDIdentified(const UUIDIdentified&) = default;
125117};
126118
127119} // namespace WTF

Source/WTF/wtf/UUID.cpp

4242
4343namespace WTF {
4444
 45UUID::UUID()
 46{
 47 static_assert(sizeof(m_data) == 16);
 48 cryptographicallyRandomValues(reinterpret_cast<unsigned char*>(&m_data), 16);
 49}
 50
 51unsigned UUID::hash() const
 52{
 53 uint64_t numbers[2];
 54 numbers[0] = UInt128High64(m_data);
 55 numbers[1] = UInt128Low64(m_data);
 56
 57 return StringHasher::hashMemory(numbers, 16);
 58}
 59
4560String createCanonicalUUIDString()
4661{
4762 unsigned randomData[4];

Source/WTF/wtf/UUID.h

3030
3131#pragma once
3232
 33#include <wtf/Int128.h>
3334#include <wtf/text/WTFString.h>
3435
3536namespace WTF {
3637
3738class StringView;
3839
 40class UUID {
 41WTF_MAKE_FAST_ALLOCATED;
 42public:
 43 static UUID create()
 44 {
 45 return UUID { };
 46 }
 47
 48 explicit UUID(Span<const uint8_t, 16> span)
 49 {
 50 memcpy(&m_data, span.data(), 16);
 51 }
 52
 53 explicit UUID(UInt128Impl&& data)
 54 : m_data(data)
 55 {
 56 }
 57
 58 UUID(const UUID&) = default;
 59
 60 Span<const uint8_t, 16> toSpan() const
 61 {
 62 return Span<const uint8_t, 16> { reinterpret_cast<const uint8_t*>(&m_data), 16 };
 63 }
 64
 65 UUID& operator=(const UUID&) = default;
 66 bool operator==(const UUID& other) const { return m_data == other.m_data; }
 67
 68 template<class Encoder> void encode(Encoder&) const;
 69 template<class Decoder> static std::optional<UUID> decode(Decoder&);
 70
 71 explicit UUID(HashTableDeletedValueType)
 72 : m_data(1)
 73 {
 74 }
 75
 76 explicit UUID(HashTableEmptyValueType)
 77 : m_data(0)
 78 {
 79 }
 80
 81 bool isHashTableDeletedValue() const { return m_data == 1; }
 82 WTF_EXPORT_PRIVATE unsigned hash() const;
 83
 84private:
 85 WTF_EXPORT_PRIVATE UUID();
 86
 87 UInt128Impl m_data;
 88};
 89
 90struct UUIDHash {
 91 static unsigned hash(const UUID& key) { return key.hash(); }
 92 static bool equal(const UUID& a, const UUID& b) { return a == b; }
 93 static const bool safeToCompareToEmptyOrDeleted = true;
 94};
 95
 96template<> struct HashTraits<UUID> : GenericHashTraits<UUID> {
 97 static UUID emptyValue() { return UUID { HashTableEmptyValue }; }
 98 static void constructDeletedValue(UUID& slot) { slot = UUID { HashTableDeletedValue }; }
 99 static bool isDeletedValue(const UUID& value) { return value.isHashTableDeletedValue(); }
 100};
 101template<> struct DefaultHash<UUID> : UUIDHash { };
 102
 103template<class Encoder>
 104void UUID::encode(Encoder& encoder) const
 105{
 106 encoder << UInt128High64(m_data) << UInt128Low64(m_data);
 107}
 108
 109template<class Decoder>
 110std::optional<UUID> UUID::decode(Decoder& decoder)
 111{
 112 std::optional<uint64_t> high;
 113 decoder >> high;
 114 if (!high)
 115 return std::nullopt;
 116
 117 std::optional<uint64_t> low;
 118 decoder >> low;
 119 if (!low)
 120 return std::nullopt;
 121
 122 return { UUID {
 123 MakeUInt128(*high, *low),
 124 } };
 125}
 126
39127// Creates a UUID that consists of 32 hexadecimal digits and returns its canonical form.
40128// 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.
41129// The hexadecimal values "a" through "f" are output as lower case characters.

@@WTF_EXPORT_PRIVATE bool isVersion4UUID(StringView);
52140
53141}
54142
 143using WTF::UUID;
55144using WTF::createCanonicalUUIDString;
56145using WTF::bootSessionUUIDString;

Source/WebCore/ChangeLog

 12021-12-22 Brady Eidson <beidson@apple.com>
 2
 3 Add WTF::UUID class which is natively a 128-bit integer
 4 https://bugs.webkit.org/show_bug.cgi?id=234571
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 No new tests (Refactor, covered by existing tests)
 9
 10 * Modules/notifications/NotificationData.h:
 11 (WebCore::NotificationData::decode):
 12
1132021-12-21 Brady Eidson <beidson@apple.com>
214
315 Make Notification identifiers be a UUID string instead of a uint64_t

Source/WebCore/Modules/notifications/NotificationData.h

2626#pragma once
2727
2828#include <optional>
 29#include <wtf/UUID.h>
2930#include <wtf/text/WTFString.h>
3031
3132namespace WebCore {

@@struct NotificationData {
4344 String language;
4445 WebCore::NotificationDirection direction;
4546 String originString;
46  String notificationID;
 47 UUID notificationID;
4748};
4849
4950template<class Encoder>

@@std::optional<NotificationData> NotificationData::decode(Decoder& decoder)
9091 if (!originString)
9192 return std::nullopt;
9293
93  std::optional<String> notificationID;
 94 std::optional<UUID> notificationID;
9495 decoder >> notificationID;
9596 if (!notificationID)
9697 return std::nullopt;

Source/WebKit/ChangeLog

 12021-12-22 Brady Eidson <beidson@apple.com>
 2
 3 Add WTF::UUID class which is natively a 128-bit integer
 4 https://bugs.webkit.org/show_bug.cgi?id=234571
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Notifications - which are UUID identified - are now addressed by a UUID object instead of a v4 UUID string.
 9
 10 * NetworkProcess/Notifications/NetworkNotificationManager.cpp:
 11 (WebKit::NetworkNotificationManager::cancelNotification):
 12 (WebKit::NetworkNotificationManager::clearNotifications):
 13 (WebKit::NetworkNotificationManager::didDestroyNotification):
 14 * NetworkProcess/Notifications/NetworkNotificationManager.h:
 15
 16 * Scripts/webkit/messages.py:
 17 (forward_declarations_and_headers_for_replies):
 18 (headers_for_type):
 19
 20 * Shared/Notifications/NotificationManagerMessageHandler.h:
 21 * Shared/Notifications/NotificationManagerMessageHandler.messages.in:
 22
 23 * UIProcess/API/C/WKNotification.cpp:
 24 (WKNotificationCopyCoreIDForTesting):
 25 * UIProcess/API/C/WKNotification.h:
 26
 27 * UIProcess/API/C/WKNotificationManager.cpp:
 28 (WKNotificationManagerProviderDidClickNotification_b):
 29 * UIProcess/API/C/WKNotificationManager.h:
 30
 31 * UIProcess/Notifications/WebNotification.h:
 32 (WebKit::WebNotification::coreNotificationID const):
 33
 34 * UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp:
 35 (WebKit::WebNotificationManagerMessageHandler::cancelNotification):
 36 (WebKit::WebNotificationManagerMessageHandler::clearNotifications):
 37 (WebKit::WebNotificationManagerMessageHandler::didDestroyNotification):
 38 * UIProcess/Notifications/WebNotificationManagerMessageHandler.h:
 39
 40 * UIProcess/Notifications/WebNotificationManagerProxy.cpp:
 41 (WebKit::WebNotificationManagerProxy::cancel):
 42 (WebKit::WebNotificationManagerProxy::didDestroyNotification):
 43 (WebKit::pageIDsMatch):
 44 (WebKit::pageAndNotificationIDsMatch):
 45 (WebKit::WebNotificationManagerProxy::clearNotifications):
 46 (WebKit::WebNotificationManagerProxy::providerDidClickNotification):
 47 (WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
 48 * UIProcess/Notifications/WebNotificationManagerProxy.h:
 49
 50 * UIProcess/WebPageProxy.cpp:
 51 (WebKit::WebPageProxy::cancelNotification):
 52 (WebKit::WebPageProxy::clearNotifications):
 53 (WebKit::WebPageProxy::didDestroyNotification):
 54 * UIProcess/WebPageProxy.h:
 55
 56 * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
 57 (WKBundleCopyWebNotificationID):
 58 * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
 59
 60 * WebProcess/InjectedBundle/InjectedBundle.cpp:
 61 (WebKit::InjectedBundle::webNotificationID):
 62 * WebProcess/InjectedBundle/InjectedBundle.h:
 63
 64 * WebProcess/Notifications/WebNotificationManager.cpp:
 65 (WebKit::WebNotificationManager::didShowNotification):
 66 (WebKit::WebNotificationManager::didClickNotification):
 67 (WebKit::WebNotificationManager::didCloseNotifications):
 68 * WebProcess/Notifications/WebNotificationManager.h:
 69 * WebProcess/Notifications/WebNotificationManager.messages.in:
 70
1712021-12-21 Brady Eidson <beidson@apple.com>
272
373 Make Notification identifiers be a UUID string instead of a uint64_t

Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp

@@void NetworkNotificationManager::showNotification(const WebCore::NotificationDat
114114// sendMessageWithReply<WebPushD::MessageType::EchoTwice>(WTFMove(completionHandler), String("FIXME: Do useful work here"));
115115}
116116
117 void NetworkNotificationManager::cancelNotification(const String&)
 117void NetworkNotificationManager::cancelNotification(const UUID&)
118118{
119119 if (!m_connection)
120120 return;
121121}
122122
123 void NetworkNotificationManager::clearNotifications(const Vector<String>&)
 123void NetworkNotificationManager::clearNotifications(const Vector<UUID>&)
124124{
125125 if (!m_connection)
126126 return;
127127}
128128
129 void NetworkNotificationManager::didDestroyNotification(const String&)
 129void NetworkNotificationManager::didDestroyNotification(const UUID&)
130130{
131131 if (!m_connection)
132132 return;

Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h

@@private:
6060
6161 void requestSystemNotificationPermission(const String& originString, CompletionHandler<void(bool)>&&) final;
6262 void showNotification(const WebCore::NotificationData&) final;
63  void cancelNotification(const String& notificationID) final;
64  void clearNotifications(const Vector<String>& notificationIDs) final;
65  void didDestroyNotification(const String& notificationID) final;
 63 void cancelNotification(const UUID& notificationID) final;
 64 void clearNotifications(const Vector<UUID>& notificationIDs) final;
 65 void didDestroyNotification(const UUID& notificationID) final;
6666
6767 void maybeSendConnectionConfiguration() const;
6868

Source/WebKit/Scripts/webkit/messages.py

@@def forward_declarations_and_headers_for_replies(receiver):
457457 'MachSendRight',
458458 'MediaTime',
459459 'String',
 460 'UUID',
460461 ])
461462
462463 no_forward_declaration_types = types_that_cannot_be_forward_declared()

@@def headers_for_type(type):
751752 'Seconds': ['<wtf/Seconds.h>'],
752753 'String': ['<wtf/text/WTFString.h>'],
753754 'URL': ['<wtf/URLHash.h>'],
 755 'UUID': ['<wtf/UUID.h>'],
754756 'WallTime': ['<wtf/WallTime.h>'],
755757 'WebCore::ArcData': ['<WebCore/InlinePathData.h>'],
756758 'WebCore::AutoplayEventFlags': ['<WebCore/AutoplayEvent.h>'],

Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.h

2828#include "MessageReceiver.h"
2929#include "WebPageProxyIdentifier.h"
3030#include <WebCore/NotificationDirection.h>
 31#include <wtf/UUID.h>
3132
3233namespace WebCore {
3334struct NotificationData;

@@public:
4142
4243 virtual void requestSystemNotificationPermission(const String& securityOrigin, CompletionHandler<void(bool)>&&) = 0;
4344 virtual void showNotification(const WebCore::NotificationData&) = 0;
44  virtual void cancelNotification(const String& notificationID) = 0;
45  virtual void clearNotifications(const Vector<String>& notificationIDs) = 0;
46  virtual void didDestroyNotification(const String& notificationID) = 0;
 45 virtual void cancelNotification(const UUID& notificationID) = 0;
 46 virtual void clearNotifications(const Vector<UUID>& notificationIDs) = 0;
 47 virtual void didDestroyNotification(const UUID& notificationID) = 0;
4748
4849private:
4950 // IPC::MessageReceiver

Source/WebKit/Shared/Notifications/NotificationManagerMessageHandler.messages.in

2323messages -> NotificationManagerMessageHandler NotRefCounted {
2424 RequestSystemNotificationPermission(String originIdentifier) -> (bool allowed) Async
2525 ShowNotification(struct WebCore::NotificationData notificationData)
26  CancelNotification(String notificationID)
27  ClearNotifications(Vector<String> notificationIDs)
28  DidDestroyNotification(String notificationID)
 26 CancelNotification(UUID notificationID)
 27 ClearNotifications(Vector<UUID> notificationIDs)
 28 DidDestroyNotification(UUID notificationID)
2929}

Source/WebKit/UIProcess/API/C/WKNotification.cpp

2828
2929#include "APISecurityOrigin.h"
3030#include "WKAPICast.h"
 31#include "WKData.h"
3132#include "WKString.h"
3233#include "WebNotification.h"
3334#include <WebCore/NotificationDirection.h>

@@uint64_t WKNotificationGetID(WKNotificationRef notification)
8889 return toImpl(notification)->notificationID();
8990}
9091
91 WKStringRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification)
 92WKDataRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification)
9293{
93  return toCopiedAPI(toImpl(notification)->coreNotificationID());
 94 auto identifier = toImpl(notification)->coreNotificationID();
 95 auto span = identifier.toSpan();
 96 return WKDataCreate(span.data(), span.size());
9497}

Source/WebKit/UIProcess/API/C/WKNotification.h

@@WK_EXPORT WKStringRef WKNotificationCopyLang(WKNotificationRef notification);
4242WK_EXPORT WKStringRef WKNotificationCopyDir(WKNotificationRef notification);
4343WK_EXPORT WKSecurityOriginRef WKNotificationGetSecurityOrigin(WKNotificationRef notification);
4444WK_EXPORT uint64_t WKNotificationGetID(WKNotificationRef notification);
45 WK_EXPORT WKStringRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification);
 45WK_EXPORT WKDataRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification);
4646
4747#ifdef __cplusplus
4848}

Source/WebKit/UIProcess/API/C/WKNotificationManager.cpp

2727#include "WKNotificationManager.h"
2828
2929#include "APIArray.h"
 30#include "APIData.h"
3031#include "WKAPICast.h"
3132#include "WebNotification.h"
3233#include "WebNotificationManagerProxy.h"

@@void WKNotificationManagerProviderDidClickNotification(WKNotificationManagerRef
5455 toImpl(managerRef)->providerDidClickNotification(notificationID);
5556}
5657
57 void WKNotificationManagerProviderDidClickNotification_b(WKNotificationManagerRef managerRef, WKStringRef notificationID)
 58void WKNotificationManagerProviderDidClickNotification_b(WKNotificationManagerRef managerRef, WKDataRef identifier)
5859{
59  toImpl(managerRef)->providerDidClickNotification(toWTFString(notificationID));
 60 auto span = toImpl(identifier)->dataReference();
 61 if (span.size() != 16)
 62 return;
 63
 64 toImpl(managerRef)->providerDidClickNotification(UUID { Span<const uint8_t, 16> { span.data(), 16 } });
6065}
6166
6267void WKNotificationManagerProviderDidCloseNotifications(WKNotificationManagerRef managerRef, WKArrayRef notificationIDs)

Source/WebKit/UIProcess/API/C/WKNotificationManager.h

@@WK_EXPORT void WKNotificationManagerSetProvider(WKNotificationManagerRef manager
3838
3939WK_EXPORT void WKNotificationManagerProviderDidShowNotification(WKNotificationManagerRef managerRef, uint64_t notificationID);
4040WK_EXPORT void WKNotificationManagerProviderDidClickNotification(WKNotificationManagerRef managerRef, uint64_t notificationID);
41 WK_EXPORT void WKNotificationManagerProviderDidClickNotification_b(WKNotificationManagerRef managerRef, WKStringRef notificationID);
 41WK_EXPORT void WKNotificationManagerProviderDidClickNotification_b(WKNotificationManagerRef managerRef, WKDataRef notificationID);
4242WK_EXPORT void WKNotificationManagerProviderDidCloseNotifications(WKNotificationManagerRef managerRef, WKArrayRef notificationIDs);
4343WK_EXPORT void WKNotificationManagerProviderDidUpdateNotificationPolicy(WKNotificationManagerRef managerRef, WKSecurityOriginRef origin, bool allowed);
4444WK_EXPORT void WKNotificationManagerProviderDidRemoveNotificationPolicies(WKNotificationManagerRef managerRef, WKArrayRef origins);

Source/WebKit/UIProcess/Notifications/WebNotification.h

@@public:
5555 API::SecurityOrigin* origin() const { return m_origin.get(); }
5656
5757 uint64_t notificationID() const { return identifier(); }
58  const String& coreNotificationID() const { return m_coreNotificationID; }
 58 const UUID& coreNotificationID() const { return m_coreNotificationID; }
5959
6060 WebPageProxyIdentifier pageIdentifier() const { return m_pageIdentifier; }
6161

@@private:
6969 String m_lang;
7070 WebCore::NotificationDirection m_dir;
7171 RefPtr<API::SecurityOrigin> m_origin;
72  String m_coreNotificationID;
 72 UUID m_coreNotificationID;
7373
7474 WebPageProxyIdentifier m_pageIdentifier;
7575};

Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.cpp

@@void WebNotificationManagerMessageHandler::showNotification(const WebCore::Notif
4545 m_webPageProxy.showNotification(data);
4646}
4747
48 void WebNotificationManagerMessageHandler::cancelNotification(const String& notificationID)
 48void WebNotificationManagerMessageHandler::cancelNotification(const UUID& notificationID)
4949{
5050 m_webPageProxy.cancelNotification(notificationID);
5151}
5252
53 void WebNotificationManagerMessageHandler::clearNotifications(const Vector<String>& notificationIDs)
 53void WebNotificationManagerMessageHandler::clearNotifications(const Vector<UUID>& notificationIDs)
5454{
5555 m_webPageProxy.clearNotifications(notificationIDs);
5656}
5757
58 void WebNotificationManagerMessageHandler::didDestroyNotification(const String& notificationID)
 58void WebNotificationManagerMessageHandler::didDestroyNotification(const UUID& notificationID)
5959{
6060 m_webPageProxy.didDestroyNotification(notificationID);
6161}

Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.h

@@private:
3838
3939 void requestSystemNotificationPermission(const String&, CompletionHandler<void(bool)>&&) final;
4040 void showNotification(const WebCore::NotificationData&) final;
41  void cancelNotification(const String& notificationID) final;
42  void clearNotifications(const Vector<String>& notificationIDs) final;
43  void didDestroyNotification(const String& notificationID) final;
 41 void cancelNotification(const UUID& notificationID) final;
 42 void clearNotifications(const Vector<UUID>& notificationIDs) final;
 43 void didDestroyNotification(const UUID& notificationID) final;
4444
4545 WebPageProxy& m_webPageProxy;
4646};

Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp

@@void WebNotificationManagerProxy::show(WebPageProxy* webPage, const WebCore::Not
9696 m_provider->show(*webPage, notification.get());
9797}
9898
99 void WebNotificationManagerProxy::cancel(WebPageProxy* webPage, const String& pageNotificationID)
 99void WebNotificationManagerProxy::cancel(WebPageProxy* webPage, const UUID& pageNotificationID)
100100{
101101 if (auto webNotification = m_notifications.get(pageNotificationID))
102102 m_provider->cancel(*webNotification);
103103}
104104
105 void WebNotificationManagerProxy::didDestroyNotification(WebPageProxy* webPage, const String& pageNotificationID)
 105void WebNotificationManagerProxy::didDestroyNotification(WebPageProxy* webPage, const UUID& pageNotificationID)
106106{
107107 if (auto webNotification = m_notifications.take(pageNotificationID)) {
108108 m_globalNotificationMap.remove(webNotification->notificationID());

@@void WebNotificationManagerProxy::didDestroyNotification(WebPageProxy* webPage,
110110 }
111111}
112112
113 static bool pageIDsMatch(WebPageProxyIdentifier pageID, const String&, WebPageProxyIdentifier desiredPageID, const Vector<String>&)
 113static bool pageIDsMatch(WebPageProxyIdentifier pageID, const UUID&, WebPageProxyIdentifier desiredPageID, const Vector<UUID>&)
114114{
115115 return pageID == desiredPageID;
116116}
117117
118 static bool pageAndNotificationIDsMatch(WebPageProxyIdentifier pageID, const String& pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<String>& desiredPageNotificationIDs)
 118static bool pageAndNotificationIDsMatch(WebPageProxyIdentifier pageID, const UUID& pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<UUID>& desiredPageNotificationIDs)
119119{
120120 return pageID == desiredPageID && desiredPageNotificationIDs.contains(pageNotificationID);
121121}
122122
123123void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage)
124124{
125  clearNotifications(webPage, Vector<String>(), pageIDsMatch);
 125 clearNotifications(webPage, Vector<UUID>(), pageIDsMatch);
126126}
127127
128 void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<String>& pageNotificationIDs)
 128void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<UUID>& pageNotificationIDs)
129129{
130130 clearNotifications(webPage, pageNotificationIDs, pageAndNotificationIDsMatch);
131131}
132132
133 void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<String>& pageNotificationIDs, NotificationFilterFunction filterFunction)
 133void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, const Vector<UUID>& pageNotificationIDs, NotificationFilterFunction filterFunction)
134134{
135135 auto targetPageProxyID = webPage->identifier();
136136

@@void WebNotificationManagerProxy::clearNotifications(WebPageProxy* webPage, cons
139139
140140 for (auto notification : m_notifications.values()) {
141141 auto pageProxyID = notification->pageIdentifier();
142  String coreNotificationID = notification->coreNotificationID();
 142 auto coreNotificationID = notification->coreNotificationID();
143143 if (!filterFunction(pageProxyID, coreNotificationID, targetPageProxyID, pageNotificationIDs))
144144 continue;
145145

@@void WebNotificationManagerProxy::providerDidClickNotification(uint64_t globalNo
193193 webPage->process().send(Messages::WebNotificationManager::DidClickNotification(it->value), 0);
194194}
195195
196 void WebNotificationManagerProxy::providerDidClickNotification(const String& coreNotificationID)
 196void WebNotificationManagerProxy::providerDidClickNotification(const UUID& coreNotificationID)
197197{
198198 auto notification = m_notifications.get(coreNotificationID);
199199 if (!notification)

@@void WebNotificationManagerProxy::providerDidClickNotification(const String& cor
208208
209209void WebNotificationManagerProxy::providerDidCloseNotifications(API::Array* globalNotificationIDs)
210210{
211  HashMap<WebPageProxy*, Vector<String>> pageNotificationIDs;
 211 HashMap<WebPageProxy*, Vector<UUID>> pageNotificationIDs;
212212
213213 size_t size = globalNotificationIDs->size();
214214 for (size_t i = 0; i < size; ++i) {
215  // The passed array might have uint64_t identifiers or String identifiers.
 215 // The passed array might have uint64_t identifiers or UUID data identifiers.
216216 // Handle both.
217217
218  String coreNotificationID;
 218 std::optional<UUID> coreNotificationID;
219219 auto* intValue = globalNotificationIDs->at<API::UInt64>(i);
220220 if (intValue) {
221221 auto it = m_globalNotificationMap.find(intValue->value());

@@void WebNotificationManagerProxy::providerDidCloseNotifications(API::Array* glob
224224
225225 coreNotificationID = it->value;
226226 } else {
227  auto* stringValue = globalNotificationIDs->at<API::String>(i);
228  if (!stringValue)
 227 auto* dataValue = globalNotificationIDs->at<API::Data>(i);
 228 if (!dataValue)
229229 continue;
230230
231  coreNotificationID = stringValue->string();
 231 auto span = dataValue->dataReference();
 232 if (span.size() != 16)
 233 continue;
 234
 235 coreNotificationID = UUID { Span<const uint8_t, 16> { span.data(), 16 } };
232236 }
233237
234  ASSERT(!coreNotificationID.isEmpty());
 238 ASSERT(coreNotificationID);
235239
236  auto notification = m_notifications.take(coreNotificationID);
 240 auto notification = m_notifications.take(*coreNotificationID);
237241 if (!notification)
238242 continue;
239243
240244 if (WebPageProxy* webPage = WebProcessProxy::webPage(notification->pageIdentifier())) {
241245 auto pageIt = pageNotificationIDs.find(webPage);
242246 if (pageIt == pageNotificationIDs.end()) {
243  Vector<String> newVector;
 247 Vector<UUID> newVector;
244248 newVector.reserveInitialCapacity(size);
245249 pageIt = pageNotificationIDs.add(webPage, WTFMove(newVector)).iterator;
246250 }

Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.h

3131#include "WebPageProxyIdentifier.h"
3232#include <WebCore/NotificationClient.h>
3333#include <wtf/HashMap.h>
 34#include <wtf/UUID.h>
3435#include <wtf/text/StringHash.h>
3536
3637namespace WebCore {

@@public:
6061 HashMap<String, bool> notificationPermissions();
6162
6263 void show(WebPageProxy*, const WebCore::NotificationData&);
63  void cancel(WebPageProxy*, const String& pageNotificationID);
 64 void cancel(WebPageProxy*, const UUID& pageNotificationID);
6465 void clearNotifications(WebPageProxy*);
65  void clearNotifications(WebPageProxy*, const Vector<String>& pageNotificationIDs);
66  void didDestroyNotification(WebPageProxy*, const String& pageNotificationID);
 66 void clearNotifications(WebPageProxy*, const Vector<UUID>& pageNotificationIDs);
 67 void didDestroyNotification(WebPageProxy*, const UUID& pageNotificationID);
6768
6869 void providerDidShowNotification(uint64_t notificationID);
6970 void providerDidClickNotification(uint64_t notificationID);
70  void providerDidClickNotification(const String& notificationID);
 71 void providerDidClickNotification(const UUID& notificationID);
7172 void providerDidCloseNotifications(API::Array* notificationIDs);
7273 void providerDidUpdateNotificationPolicy(const API::SecurityOrigin*, bool allowed);
7374 void providerDidRemoveNotificationPolicies(API::Array* origins);

@@public:
7879private:
7980 explicit WebNotificationManagerProxy(WebProcessPool*);
8081
81  typedef bool (*NotificationFilterFunction)(WebPageProxyIdentifier pageID, const String& pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<String>& desiredPageNotificationIDs);
82  void clearNotifications(WebPageProxy*, const Vector<String>& pageNotificationIDs, NotificationFilterFunction);
 82 typedef bool (*NotificationFilterFunction)(WebPageProxyIdentifier pageID, const UUID& pageNotificationID, WebPageProxyIdentifier desiredPageID, const Vector<UUID>& desiredPageNotificationIDs);
 83 void clearNotifications(WebPageProxy*, const Vector<UUID>& pageNotificationIDs, NotificationFilterFunction);
8384
8485 // WebContextSupplement
8586 void processPoolDestroyed() override;

@@private:
8889
8990 std::unique_ptr<API::NotificationProvider> m_provider;
9091
91  HashMap<uint64_t, String> m_globalNotificationMap;
92  HashMap<String, Ref<WebNotification>> m_notifications;
 92 HashMap<uint64_t, UUID> m_globalNotificationMap;
 93 HashMap<UUID, Ref<WebNotification>> m_notifications;
9394};
9495
9596} // namespace WebKit

Source/WebKit/UIProcess/WebPageProxy.cpp

@@void WebPageProxy::showNotification(const WebCore::NotificationData& notificatio
87428742 m_process->processPool().supplement<WebNotificationManagerProxy>()->show(this, notificationData);
87438743}
87448744
8745 void WebPageProxy::cancelNotification(const String& notificationID)
 8745void WebPageProxy::cancelNotification(const UUID& notificationID)
87468746{
87478747 m_process->processPool().supplement<WebNotificationManagerProxy>()->cancel(this, notificationID);
87488748}
87498749
8750 void WebPageProxy::clearNotifications(const Vector<String>& notificationIDs)
 8750void WebPageProxy::clearNotifications(const Vector<UUID>& notificationIDs)
87518751{
87528752 m_process->processPool().supplement<WebNotificationManagerProxy>()->clearNotifications(this, notificationIDs);
87538753}
87548754
8755 void WebPageProxy::didDestroyNotification(const String& notificationID)
 8755void WebPageProxy::didDestroyNotification(const UUID& notificationID)
87568756{
87578757 m_process->processPool().supplement<WebNotificationManagerProxy>()->didDestroyNotification(this, notificationID);
87588758}

Source/WebKit/UIProcess/WebPageProxy.h

@@public:
20322032#endif
20332033
20342034 void showNotification(const WebCore::NotificationData&);
2035  void cancelNotification(const String& notificationID);
2036  void clearNotifications(const Vector<String>& notificationIDs);
2037  void didDestroyNotification(const String& notificationID);
 2035 void cancelNotification(const UUID& notificationID);
 2036 void clearNotifications(const Vector<UUID>& notificationIDs);
 2037 void didDestroyNotification(const UUID& notificationID);
20382038
20392039 void requestCookieConsent(CompletionHandler<void(WebCore::CookieConsentDecisionResult)>&&);
20402040 void classifyModalContainerControls(Vector<String>&& texts, CompletionHandler<void(Vector<WebCore::ModalContainerControlType>&&)>&&);

Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp

3434#include "WKAPICast.h"
3535#include "WKBundleAPICast.h"
3636#include "WKBundlePrivate.h"
 37#include "WKData.h"
3738#include "WKMutableArray.h"
3839#include "WKMutableDictionary.h"
3940#include "WKNumber.h"

@@void WKBundleRemoveAllWebNotificationPermissions(WKBundleRef bundleRef, WKBundle
206207 WebKit::toImpl(bundleRef)->removeAllWebNotificationPermissions(WebKit::toImpl(pageRef));
207208}
208209
209 WKStringRef WKBundleCopyWebNotificationID(WKBundleRef bundleRef, JSContextRef context, JSValueRef notification)
 210WKDataRef WKBundleCopyWebNotificationID(WKBundleRef bundleRef, JSContextRef context, JSValueRef notification)
210211{
211212 auto identifier = WebKit::toImpl(bundleRef)->webNotificationID(context, notification);
212213 if (!identifier)
213214 return nullptr;
214215
215  return WebKit::toCopiedAPI(*identifier);
 216 auto span = identifier->toSpan();
 217 return WKDataCreate(span.data(), span.size());
216218}
217219
218220void WKBundleSetTabKeyCyclesThroughElements(WKBundleRef bundleRef, WKBundlePageRef pageRef, bool enabled)

Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h

@@WK_EXPORT bool WKBundleIsPageBoxVisible(WKBundleRef bundle, WKBundleFrameRef fra
5252WK_EXPORT void WKBundleSetUserStyleSheetLocationForTesting(WKBundleRef bundle, WKStringRef location);
5353WK_EXPORT void WKBundleSetWebNotificationPermission(WKBundleRef bundle, WKBundlePageRef page, WKStringRef originStringRef, bool allowed);
5454WK_EXPORT void WKBundleRemoveAllWebNotificationPermissions(WKBundleRef bundle, WKBundlePageRef page);
55 WK_EXPORT WKStringRef WKBundleCopyWebNotificationID(WKBundleRef bundle, JSContextRef context, JSValueRef notification);
 55WK_EXPORT WKDataRef WKBundleCopyWebNotificationID(WKBundleRef bundle, JSContextRef context, JSValueRef notification);
5656WK_EXPORT WKDataRef WKBundleCreateWKDataFromUInt8Array(WKBundleRef bundle, JSContextRef context, JSValueRef data);
5757WK_EXPORT void WKBundleSetAsynchronousSpellCheckingEnabledForTesting(WKBundleRef bundleRef, bool enabled);
5858// Returns array of dictionaries. Dictionary keys are document identifiers, values are document URLs.

Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp

@@void InjectedBundle::removeAllWebNotificationPermissions(WebPage* page)
310310#endif
311311}
312312
313 std::optional<String> InjectedBundle::webNotificationID(JSContextRef jsContext, JSValueRef jsNotification)
 313std::optional<UUID> InjectedBundle::webNotificationID(JSContextRef jsContext, JSValueRef jsNotification)
314314{
315315#if ENABLE(NOTIFICATIONS)
316316 WebCore::Notification* notification = JSNotification::toWrapped(toJS(jsContext)->vm(), toJS(toJS(jsContext), jsNotification));

Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h

3434#include <WebCore/UserScriptTypes.h>
3535#include <wtf/RefPtr.h>
3636#include <wtf/RetainPtr.h>
 37#include <wtf/UUID.h>
3738#include <wtf/text/WTFString.h>
3839
3940#if USE(GLIB)

@@public:
106107 void setUserStyleSheetLocation(const String&);
107108 void setWebNotificationPermission(WebPage*, const String& originString, bool allowed);
108109 void removeAllWebNotificationPermissions(WebPage*);
109  std::optional<String> webNotificationID(JSContextRef, JSValueRef);
 110 std::optional<UUID> webNotificationID(JSContextRef, JSValueRef);
110111 Ref<API::Data> createWebDataFromUint8Array(JSContextRef, JSValueRef);
111112
112113 typedef HashMap<uint64_t, String> DocumentIDToURLMap;

Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp

@@void WebNotificationManager::didDestroyNotification(Notification& notification,
183183#endif
184184}
185185
186 void WebNotificationManager::didShowNotification(const String& notificationID)
 186void WebNotificationManager::didShowNotification(const UUID& notificationID)
187187{
188188#if ENABLE(NOTIFICATIONS)
189189 RefPtr<Notification> notification = m_notificationIDMap.get(notificationID);

@@void WebNotificationManager::didShowNotification(const String& notificationID)
196196#endif
197197}
198198
199 void WebNotificationManager::didClickNotification(const String& notificationID)
 199void WebNotificationManager::didClickNotification(const UUID& notificationID)
200200{
201201#if ENABLE(NOTIFICATIONS)
202202 RefPtr<Notification> notification = m_notificationIDMap.get(notificationID);

@@void WebNotificationManager::didClickNotification(const String& notificationID)
211211#endif
212212}
213213
214 void WebNotificationManager::didCloseNotifications(const Vector<String>& notificationIDs)
 214void WebNotificationManager::didCloseNotifications(const Vector<UUID>& notificationIDs)
215215{
216216#if ENABLE(NOTIFICATIONS)
217217 size_t count = notificationIDs.size();

Source/WebKit/WebProcess/Notifications/WebNotificationManager.h

3232#include <wtf/HashMap.h>
3333#include <wtf/Noncopyable.h>
3434#include <wtf/RefPtr.h>
 35#include <wtf/UUID.h>
3536#include <wtf/Vector.h>
3637#include <wtf/text/StringHash.h>
3738

@@private:
7576 // Implemented in generated WebNotificationManagerMessageReceiver.cpp
7677 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
7778
78  void didShowNotification(const String& notificationID);
79  void didClickNotification(const String& notificationID);
80  void didCloseNotifications(const Vector<String>& notificationIDs);
 79 void didShowNotification(const UUID& notificationID);
 80 void didClickNotification(const UUID& notificationID);
 81 void didCloseNotifications(const Vector<UUID>& notificationIDs);
8182 void didRemoveNotificationDecisions(const Vector<String>& originStrings);
8283
8384 WebProcess& m_process;
8485
8586#if ENABLE(NOTIFICATIONS)
86  typedef HashMap<String, RefPtr<WebCore::Notification>> NotificationIDMap;
 87 typedef HashMap<UUID, RefPtr<WebCore::Notification>> NotificationIDMap;
8788 NotificationIDMap m_notificationIDMap;
8889
8990 HashMap<String, bool> m_permissionsMap;

Source/WebKit/WebProcess/Notifications/WebNotificationManager.messages.in

2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2222
2323messages -> WebNotificationManager NotRefCounted {
24  DidShowNotification(String notificationID);
25  DidClickNotification(String notificationID);
26  DidCloseNotifications(Vector<String> notificationIDs);
 24 DidShowNotification(UUID notificationID);
 25 DidClickNotification(UUID notificationID);
 26 DidCloseNotifications(Vector<UUID> notificationIDs);
2727 DidUpdateNotificationDecision(String originString, bool allowed);
2828 DidRemoveNotificationDecisions(Vector<String> originStrings);
2929}

Tools/ChangeLog

 12021-12-22 Brady Eidson <beidson@apple.com>
 2
 3 Add WTF::UUID class which is natively a 128-bit integer
 4 https://bugs.webkit.org/show_bug.cgi?id=234571
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Notifications - which are UUID identified - are now addressed by a UUID object instead of a v4 UUID string.
 9
 10 The way our C-API vends that UUID object is through a data object, so change WKTR to account for that.
 11
 12 * WebKitTestRunner/DataFunctions.h: Copied from Source/WebKit/UIProcess/Notifications/WebNotificationManagerMessageHandler.h.
 13 (WTR::dataValue):
 14 (WTR::dataToUUID):
 15 (WTR::uuidToData):
 16
 17 * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
 18 (WTR::InjectedBundle::postSimulateWebNotificationClick):
 19 (WTR::postPageMessage):
 20 * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
 21
 22 * WebKitTestRunner/TestController.cpp:
 23 (WTR::TestController::simulateWebNotificationClick):
 24 * WebKitTestRunner/TestController.h:
 25
 26 * WebKitTestRunner/TestInvocation.cpp:
 27 (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
 28
 29 * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
 30
 31 * WebKitTestRunner/WebNotificationProvider.cpp:
 32 (WTR::WebNotificationProvider::showWebNotification):
 33 (WTR::WebNotificationProvider::closeWebNotification):
 34 (WTR::WebNotificationProvider::removeNotificationManager):
 35 (WTR::WebNotificationProvider::simulateWebNotificationClick):
 36 (WTR::WebNotificationProvider::reset):
 37 * WebKitTestRunner/WebNotificationProvider.h:
 38
1392021-12-21 Brady Eidson <beidson@apple.com>
240
341 Make Notification identifiers be a UUID string instead of a uint64_t

Tools/WebKitTestRunner/DataFunctions.h

 1/*
 2 * Copyright (C) 2021 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#include <WebKit/WKData.h>
 29#include <WebKit/WKRetainPtr.h>
 30#include <wtf/UUID.h>
 31
 32namespace WTR {
 33
 34WKDataRef dataValue(WKTypeRef);
 35UUID dataToUUID(WKDataRef);
 36WKRetainPtr<WKDataRef> uuidToData(const UUID&);
 37
 38inline WKDataRef dataValue(WKTypeRef value)
 39{
 40 return value && WKGetTypeID(value) == WKDataGetTypeID() ? static_cast<WKDataRef>(value) : nullptr;
 41}
 42
 43inline UUID dataToUUID(WKDataRef data)
 44{
 45 RELEASE_ASSERT(WKDataGetSize(data) == 16);
 46 return UUID { Span<const uint8_t, 16> { WKDataGetBytes(data), 16 } };
 47}
 48
 49inline WKRetainPtr<WKDataRef> uuidToData(const UUID& uuid)
 50{
 51 auto span = uuid.toSpan();
 52 return adoptWK(WKDataCreate(span.data(), span.size()));
 53}
 54
 55} // namespace WTR

Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

@@void InjectedBundle::postSetViewSize(double width, double height)
663663 WKBundlePagePostSynchronousMessageForTesting(page()->page(), toWK("SetViewSize").get(), body.get(), 0);
664664}
665665
666 void InjectedBundle::postSimulateWebNotificationClick(WKStringRef notificationID)
 666void InjectedBundle::postSimulateWebNotificationClick(WKDataRef notificationID)
667667{
668668 postPageMessage("SimulateWebNotificationClick", notificationID);
669669}

@@void postPageMessage(const char* name, WKStringRef value)
941941 WKBundlePagePostMessage(page, toWK(name).get(), value);
942942}
943943
 944void postPageMessage(const char* name, WKDataRef value)
 945{
 946 if (auto page = InjectedBundle::singleton().pageRef())
 947 WKBundlePagePostMessage(page, toWK(name).get(), value);
 948}
 949
944950void postSynchronousPageMessage(const char* name)
945951{
946952 postSynchronousPageMessage(name, WKRetainPtr<WKTypeRef> { });

Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

@@public:
9494 void postSetBackingScaleFactor(double);
9595 void postSetWindowIsKey(bool);
9696 void postSetViewSize(double width, double height);
97  void postSimulateWebNotificationClick(WKStringRef notificationID);
 97 void postSimulateWebNotificationClick(WKDataRef notificationID);
9898 void postSetAddsVisitedLinks(bool);
9999
100100 // Geolocation.

@@void postPageMessage(const char* name);
228228void postPageMessage(const char* name, bool value);
229229void postPageMessage(const char* name, const char* value);
230230void postPageMessage(const char* name, WKStringRef value);
 231void postPageMessage(const char* name, WKDataRef value);
231232void postPageMessage(const char* name, const void* value) = delete;
232233
233234void postSynchronousPageMessage(const char* name);

Tools/WebKitTestRunner/TestController.cpp

@@void TestController::didRemoveNavigationGestureSnapshot(WKPageRef)
23462346 m_currentInvocation->didRemoveSwipeSnapshot();
23472347}
23482348
2349 void TestController::simulateWebNotificationClick(WKStringRef notificationID)
 2349void TestController::simulateWebNotificationClick(WKDataRef notificationID)
23502350{
23512351 m_webNotificationProvider.simulateWebNotificationClick(mainWebView()->page(), notificationID);
23522352}

Tools/WebKitTestRunner/TestController.h

@@public:
125125 bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
126126 void setBeforeUnloadReturnValue(bool value) { m_beforeUnloadReturnValue = value; }
127127
128  void simulateWebNotificationClick(WKStringRef notificationID);
 128 void simulateWebNotificationClick(WKDataRef notificationID);
129129
130130 // Geolocation.
131131 void setGeolocationPermission(bool);

Tools/WebKitTestRunner/TestInvocation.cpp

2727#include "config.h"
2828#include "TestInvocation.h"
2929
 30#include "DataFunctions.h"
3031#include "DictionaryFunctions.h"
3132#include "PlatformWebView.h"
3233#include "TestController.h"

@@void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName
390391 }
391392
392393 if (WKStringIsEqualToUTF8CString(messageName, "SimulateWebNotificationClick")) {
393  WKStringRef notificationID = stringValue(messageBody);
 394 WKDataRef notificationID = dataValue(messageBody);
394395 TestController::singleton().simulateWebNotificationClick(notificationID);
395396 return;
396397 }

Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj

327327 4430AE171F82C4EE0099915A /* GeneratedTouchesDebugWindow.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GeneratedTouchesDebugWindow.mm; sourceTree = "<group>"; };
328328 4430AE181F82C4EF0099915A /* GeneratedTouchesDebugWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedTouchesDebugWindow.h; sourceTree = "<group>"; };
329329 49AEEF692407278200C87E4C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 330 510E2F3827741F8300809333 /* DataFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataFunctions.h; sourceTree = "<group>"; };
330331 5322FB4113FDA0CD0041ABCC /* CyclicRedundancyCheck.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CyclicRedundancyCheck.cpp; sourceTree = "<group>"; };
331332 5322FB4213FDA0CD0041ABCC /* CyclicRedundancyCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CyclicRedundancyCheck.h; sourceTree = "<group>"; };
332333 5322FB4413FDA0EA0041ABCC /* PixelDumpSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PixelDumpSupport.cpp; sourceTree = "<group>"; };

942943 isa = PBXGroup;
943944 children = (
944945 378D442213346D00006A777B /* config.h */,
 946 510E2F3827741F8300809333 /* DataFunctions.h */,
945947 9338D1BE250BD9DD00E827F6 /* DictionaryFunctions.h */,
946948 BC99A4841208901A007E9F08 /* StringFunctions.h */,
947949 9B36A270209453A0003E0651 /* WhatToDump.h */,

Tools/WebKitTestRunner/WebNotificationProvider.cpp

2626#include "config.h"
2727#include "WebNotificationProvider.h"
2828
 29#include "DataFunctions.h"
2930#include "StringFunctions.h"
3031#include <WebKit/WKMutableArray.h>
3132#include <WebKit/WKNotification.h>

@@void WebNotificationProvider::showWebNotification(WKPageRef page, WKNotification
9596 uint64_t identifier = WKNotificationGetID(notification);
9697 auto coreIdentifier = adoptWK(WKNotificationCopyCoreIDForTesting(notification));
9798
98  auto addResult = m_owningManager.set(toWTFString(coreIdentifier.get()), notificationManager);
 99 auto addResult = m_owningManager.set(dataToUUID(coreIdentifier.get()), notificationManager);
99100 ASSERT_UNUSED(addResult, addResult.isNewEntry);
100101
101102 WKNotificationManagerProviderDidShowNotification(notificationManager, identifier);

@@void WebNotificationProvider::showWebNotification(WKPageRef page, WKNotification
103104
104105void WebNotificationProvider::closeWebNotification(WKNotificationRef notification)
105106{
106  auto identifier = toWTFString(adoptWK(WKNotificationCopyCoreIDForTesting(notification)).get());
 107 auto identifier = adoptWK(WKNotificationCopyCoreIDForTesting(notification));
107108
108  auto notificationManager = m_owningManager.take(identifier);
 109 auto notificationManager = m_owningManager.take(dataToUUID(identifier.get()));
109110 ASSERT(notificationManager);
110111 ASSERT(m_knownManagers.contains(notificationManager));
111112

@@void WebNotificationProvider::removeNotificationManager(WKNotificationManagerRef
126127 auto protectedManager = m_knownManagers.take(manager);
127128 ASSERT(protectedManager);
128129
129  auto toRemove = Vector<String> { };
 130 auto toRemove = Vector<UUID> { };
130131 for (auto& iterator : m_owningManager) {
131132 if (iterator.value != manager)
132133 continue;

@@void WebNotificationProvider::removeNotificationManager(WKNotificationManagerRef
135136
136137 auto array = adoptWK(WKMutableArrayCreate());
137138 for (auto& identifier : toRemove) {
138  WKArrayAppendItem(array.get(), toWK(identifier).get());
 139 WKArrayAppendItem(array.get(), uuidToData(identifier).get());
139140 m_owningManager.remove(identifier);
140141 }
141142

@@WKDictionaryRef WebNotificationProvider::notificationPermissions()
148149 return WKMutableDictionaryCreate();
149150}
150151
151 void WebNotificationProvider::simulateWebNotificationClick(WKPageRef, WKStringRef notificationID)
 152void WebNotificationProvider::simulateWebNotificationClick(WKPageRef, WKDataRef notificationID)
152153{
153  auto identifier = toWTFString(notificationID);
 154 auto identifier = dataToUUID(notificationID);
154155 ASSERT(m_owningManager.contains(identifier));
155156
156157 WKNotificationManagerProviderDidClickNotification_b(m_owningManager.get(identifier), notificationID);

@@void WebNotificationProvider::reset()
160161{
161162 for (auto iterator : m_owningManager) {
162163 auto array = adoptWK(WKMutableArrayCreate());
163  WKArrayAppendItem(array.get(), toWK(iterator.key).get());
 164 WKArrayAppendItem(array.get(), uuidToData(iterator.key).get());
164165 WKNotificationManagerProviderDidCloseNotifications(iterator.value, array.get());
165166 }
166167

Tools/WebKitTestRunner/WebNotificationProvider.h

3131#include <WebKit/WKRetainPtr.h>
3232#include <wtf/HashMap.h>
3333#include <wtf/HashSet.h>
 34#include <wtf/UUID.h>
3435#include <wtf/text/StringHash.h>
3536
3637namespace WTR {

@@public:
4748 void removeNotificationManager(WKNotificationManagerRef);
4849 WKDictionaryRef notificationPermissions();
4950
50  void simulateWebNotificationClick(WKPageRef, WKStringRef notificationID);
 51 void simulateWebNotificationClick(WKPageRef, WKDataRef notificationID);
5152 void reset();
5253
5354private:
5455 HashSet<WKRetainPtr<WKNotificationManagerRef>> m_knownManagers;
55  HashMap<String, WKNotificationManagerRef> m_owningManager;
 56 HashMap<UUID, WKNotificationManagerRef> m_owningManager;
5657};
5758
5859}