Skip to content

Commit d10d760

Browse files
committed
Fix remaining smart pointer errors in webpushd
https://bugs.webkit.org/show_bug.cgi?id=299368 Reviewed by NOBODY (OOPS!). Note: The remaining RetainPtrCtorAdoptCheckerExpectations error for _WKMockUserNotificationCenter.mm is a false positive due to the checker not recognizing _init* (llvm/llvm-project#160569). * Source/WebKit/SaferCPPExpectations/UnretainedCallArgsCheckerExpectations: Ditto. * Source/WebKit/webpushd/MockPushServiceConnection.mm: (WebPushD::MockPushServiceConnection::subscribe): Use nil to turn off false positive warning. * Source/WebKit/webpushd/WebPushDaemon.h: Make m_userNotificationCenterClass a RetainPtr. * Source/WebKit/webpushd/WebPushDaemon.mm: (WebPushD::WebPushDaemon::handleIncomingPush): Ditto. (WebPushD::WebPushDaemon::subscribeToPushService): Ditto. (WebPushD::WebPushDaemon::showNotification): Ditto. Also wrap an arg in a RetainPtr. (WebPushD::WebPushDaemon::getNotifications): Make m_userNotificationCenterClass a RetainPtr. (WebPushD::WebPushDaemon::cancelNotification): Ditto. (WebPushD::WebPushDaemon::getPushPermissionState): Ditto. (WebPushD::WebPushDaemon::requestPushPermission): Ditto. (WebPushD::WebPushDaemon::setAppBadge): Ditto. (WebPushD::WebPushDaemon::getAppBadgeForTesting): Ditto. * Source/WebKit/webpushd/WebPushDaemonMain.mm: Use a RetainPtr for the result of NSSearchPathForDirectoriesInDomains. (WebKit::getWebPushDirectoryPathWithMigrationIfNecessary): * Source/WebKit/webpushd/_WKMockUserNotificationCenter.mm: (+[_WKMockUserNotificationCenter _internalInitWithBundleIdentifier:]): Use a retainPtr for a DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL arg, which calls dispatch_queue_attr_make_with_autorelease_frequency.
1 parent 1730c14 commit d10d760

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

Source/WebKit/SaferCPPExpectations/UnretainedCallArgsCheckerExpectations

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,3 @@ WebProcess/WebPage/mac/PageBannerMac.mm
161161
WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm
162162
WebProcess/WebPage/mac/WebPageMac.mm
163163
WebProcess/cocoa/WebProcessCocoa.mm
164-
webpushd/MockPushServiceConnection.mm
165-
webpushd/WebPushDaemon.mm
166-
webpushd/WebPushDaemonMain.mm
167-
webpushd/_WKMockUserNotificationCenter.mm

Source/WebKit/webpushd/MockPushServiceConnection.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
{
5353
auto alwaysRejectedKey = base64URLDecode("BEAxaUMo1s8tjORxJfnSSvWhYb4u51kg1hWT2s_9gpV7Zxar1pF_2BQ8AncuAdS2BoLhN4qaxzBy2CwHE8BBzWg"_s).value();
5454
if (vapidPublicKey == alwaysRejectedKey) {
55-
handler({ }, [NSError errorWithDomain:@"WebPush" code:-1 userInfo:nil]);
55+
handler(nil, [NSError errorWithDomain:@"WebPush" code:-1 userInfo:nil]);
5656
return;
5757
}
5858

Source/WebKit/webpushd/WebPushDaemon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class WebPushDaemon final : public CanMakeCheckedPtr<WebPushDaemon> {
175175
StdList<PotentialSilentPush> m_potentialSilentPushes;
176176

177177
#if HAVE(FULL_FEATURED_USER_NOTIFICATIONS)
178-
Class m_userNotificationCenterClass;
178+
RetainPtr<Class> m_userNotificationCenterClass;
179179
#endif // HAVE(FULL_FEATURED_USER_NOTIFICATIONS)
180180

181181
#if PLATFORM(IOS)

Source/WebKit/webpushd/WebPushDaemon.mm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ static void tryCloseRequestConnection(xpc_object_t request)
524524
// FIXME(rdar://134509619): Move APNS topics to appropriate enabled/ignored list so that we
525525
// don't get push events for web clips without the appropriate permissions.
526526
RetainPtr notificationCenterBundleIdentifier = platformNotificationCenterBundleIdentifier(identifier.pushPartition);
527-
RetainPtr center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
527+
RetainPtr center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
528528
auto blockPtr = makeBlockPtr([identifier = crossThreadCopy(identifier), message = WTFMove(message)](UNNotificationSettings *settings) mutable {
529529
auto status = settings.authorizationStatus;
530530
if (status != UNAuthorizationStatusAuthorized) {
@@ -849,7 +849,7 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
849849

850850
#if PLATFORM(IOS) && HAVE(FULL_FEATURED_USER_NOTIFICATIONS)
851851
RetainPtr notificationCenterBundleIdentifier = platformNotificationCenterBundleIdentifier(identifier.pushPartition);
852-
RetainPtr center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
852+
RetainPtr center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
853853
UNNotificationSettings *settings = [center notificationSettings];
854854
if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {
855855
WEBPUSHDAEMON_RELEASE_LOG(Push, "Cannot subscribe because web clip origin %{sensitive}s does not have correct permissions", origin.toString().utf8().data());
@@ -1036,10 +1036,10 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
10361036
content.get().subtitle = adoptNS([[NSString alloc] initWithFormat:WEB_UI_STRING("from %@", "Web Push Notification string to indicate the name of the Web App/Web Site a notification was sent from, such as 'from Wikipedia'").createNSString().get(), notificationSourceForDisplay]).get();
10371037
ALLOW_NONLITERAL_FORMAT_END
10381038

1039-
content.get().userInfo = notificationData.dictionaryRepresentation();
1039+
content.get().userInfo = retainPtr(notificationData.dictionaryRepresentation()).get();
10401040

10411041
RetainPtr request = [UNNotificationRequest requestWithIdentifier:notificationData.notificationID.toString().createNSString().get() content:content.get() trigger:nil];
1042-
RetainPtr<UNUserNotificationCenter> center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
1042+
RetainPtr<UNUserNotificationCenter> center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
10431043
if (!center)
10441044
RELEASE_LOG_ERROR(Push, "Failed to instantiate UNUserNotificationCenter center");
10451045

@@ -1070,7 +1070,7 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
10701070
auto identifier = WTFMove(*maybeIdentifier);
10711071

10721072
auto placeholderBundleIdentifier = platformNotificationCenterBundleIdentifier(identifier.pushPartition);
1073-
RetainPtr center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:placeholderBundleIdentifier.get()]);
1073+
RetainPtr center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:placeholderBundleIdentifier.get()]);
10741074

10751075
auto blockPtr = makeBlockPtr([identifier = crossThreadCopy(identifier), registrationURL = crossThreadCopy(registrationURL), tag = crossThreadCopy(tag), completionHandler = WTFMove(completionHandler)](NSArray<UNNotification *> *notifications) mutable {
10761076
ensureOnMainRunLoop([identifier = crossThreadCopy(identifier), notifications = RetainPtr { notifications }, registrationURL = crossThreadCopy(WTFMove(registrationURL)), tag = crossThreadCopy(WTFMove(tag)), completionHandler = WTFMove(completionHandler)] mutable {
@@ -1105,7 +1105,7 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
11051105
auto identifier = WTFMove(*maybeIdentifier);
11061106

11071107
auto placeholderBundleIdentifier = platformNotificationCenterBundleIdentifier(identifier.pushPartition);
1108-
RetainPtr center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:placeholderBundleIdentifier.get()]);
1108+
RetainPtr center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:placeholderBundleIdentifier.get()]);
11091109

11101110
RetainPtr identifiers = @[ notificationID.toString().createNSString().get() ];
11111111
[center removePendingNotificationRequestsWithIdentifiers:identifiers.get()];
@@ -1138,7 +1138,7 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
11381138
#endif
11391139

11401140
RetainPtr notificationCenterBundleIdentifier = platformNotificationCenterBundleIdentifier(identifier.pushPartition);
1141-
RetainPtr center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
1141+
RetainPtr center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
11421142

11431143
auto blockPtr = makeBlockPtr([originString = crossThreadCopy(origin.toString()), replySender = WTFMove(replySender)](UNNotificationSettings *settings) mutable {
11441144
auto permissionState = [](UNAuthorizationStatus status) {
@@ -1185,7 +1185,7 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
11851185
#endif
11861186

11871187
RetainPtr notificationCenterBundleIdentifier = platformNotificationCenterBundleIdentifier(identifier.pushPartition);
1188-
RetainPtr center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
1188+
RetainPtr center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:notificationCenterBundleIdentifier.get()]);
11891189
UNAuthorizationOptions options = UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound;
11901190

11911191
auto blockPtr = makeBlockPtr([originString = crossThreadCopy(origin.toString()), replySender = WTFMove(replySender)](BOOL granted, NSError *error) mutable {
@@ -1233,7 +1233,7 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
12331233
state.get().badgeValue = appBadge ? [NSNumber numberWithUnsignedLongLong:*appBadge] : nil;
12341234
#elif PLATFORM(MAC)
12351235
String bundleIdentifier = identifier.pushPartition.isEmpty() ? connection.hostAppCodeSigningIdentifier() : identifier.pushPartition;
1236-
RetainPtr center = adoptNS([[m_userNotificationCenterClass alloc] initWithBundleIdentifier:bundleIdentifier.createNSString().get()]);
1236+
RetainPtr center = adoptNS([[m_userNotificationCenterClass.get() alloc] initWithBundleIdentifier:bundleIdentifier.createNSString().get()]);
12371237
if (!center)
12381238
return;
12391239

@@ -1258,7 +1258,7 @@ static bool connectionMatchesPendingPushMessage(const PushClientConnection& conn
12581258
UNUSED_PARAM(connection);
12591259
completionHandler(std::nullopt);
12601260
#else
1261-
RELEASE_ASSERT(m_userNotificationCenterClass == _WKMockUserNotificationCenter.class);
1261+
RELEASE_ASSERT(m_userNotificationCenterClass.get() == _WKMockUserNotificationCenter.class);
12621262

12631263
String bundleIdentifier = connection.pushPartitionIfExists().isEmpty() ? connection.hostAppCodeSigningIdentifier() : connection.pushPartitionIfExists();
12641264
RetainPtr center = adoptNS([[_WKMockUserNotificationCenter alloc] initWithBundleIdentifier:bundleIdentifier.createNSString().get()]);

Source/WebKit/webpushd/WebPushDaemonMain.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ static void applySandbox()
120120

121121
static String getWebPushDirectoryPathWithMigrationIfNecessary()
122122
{
123+
RetainPtr paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
124+
String libraryPath = paths.get()[0];
123125
#if PLATFORM(MAC) && !ENABLE(RELOCATABLE_WEBPUSHD)
124-
String libraryPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];
125126
String oldPath = FileSystem::pathByAppendingComponents(libraryPath, std::initializer_list<StringView>({ "WebKit"_s, "WebPush"_s }));
126127

127128
RetainPtr containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.apple.webkit.webpushd"];
@@ -143,7 +144,6 @@ static String getWebPushDirectoryPathWithMigrationIfNecessary()
143144

144145
return newPath;
145146
#else
146-
String libraryPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];
147147
return FileSystem::pathByAppendingComponents(libraryPath, std::initializer_list<StringView>({ "WebKit"_s, "WebPush"_s }));
148148
#endif
149149
}

Source/WebKit/webpushd/_WKMockUserNotificationCenter.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ - (instancetype)_internalInitWithBundleIdentifier:(NSString *)bundleIdentifier
6060
if (!self)
6161
return nil;
6262

63-
m_queue = adoptOSObject(dispatch_queue_create(nullptr, DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL));
63+
m_queue = adoptOSObject(dispatch_queue_create(nullptr, retainPtr(DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL).get()));
6464
m_bundleIdentifier = bundleIdentifier;
6565
m_notifications = adoptNS([[NSMutableArray alloc] init]);
6666

0 commit comments

Comments
 (0)